Skip to content

Commit

Permalink
Added using GODeviceNamePattern in the audio config
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg68 committed Jul 21, 2024
1 parent 97f3d6a commit d579835
Show file tree
Hide file tree
Showing 22 changed files with 535 additions and 288 deletions.
2 changes: 2 additions & 0 deletions src/grandorgue/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ combinations/model/GOGeneralCombination.cpp
combinations/GODivisionalSetter.cpp
combinations/GOSetter.cpp
config/GOAudioDeviceConfig.cpp
config/GOAudioDeviceNode.cpp
config/GOConfig.cpp
config/GODeviceNamePattern.cpp
config/GOMidiDeviceConfig.cpp
Expand Down Expand Up @@ -190,6 +191,7 @@ sound/scheduler/GOSoundTouchTask.cpp
sound/scheduler/GOSoundTremulantTask.cpp
sound/scheduler/GOSoundWindchestTask.cpp
sound/GOSoundAudioSection.cpp
sound/GOSoundDevInfo.cpp
sound/GOSoundEngine.cpp
sound/GOSoundFader.cpp
sound/GOSoundProvider.cpp
Expand Down
43 changes: 15 additions & 28 deletions src/grandorgue/config/GOAudioDeviceConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,18 @@
#include "config/GOConfigReader.h"
#include "config/GOConfigWriter.h"

static constexpr unsigned DEFAULT_LATENCY = 50;
const wxString GOAudioDeviceConfig::WX_AUDIO_DEVICES = wxT("AudioDevices");

GOAudioDeviceConfig::GOAudioDeviceConfig(
const wxString &name, unsigned desiredLatency, uint8_t channels)
: GODeviceNamePattern(name),
m_DesiredLatency(desiredLatency),
m_channels(channels) {
m_ChannelOutputs.resize(channels);
const GOAudioDeviceNode &node, uint8_t nChannels)
: GOAudioDeviceNode(node), m_NChannels(nChannels) {
ResizeChannels();
}

GOAudioDeviceConfig::GOAudioDeviceConfig()
: GOAudioDeviceConfig(wxEmptyString, DEFAULT_LATENCY, 0) {}

GOAudioDeviceConfig::GOAudioDeviceConfig(
const std::vector<wxString> &audioGroups)
: GOAudioDeviceConfig(wxEmptyString, DEFAULT_LATENCY, 2) {
: m_NChannels(2) {
ResizeChannels();
std::vector<GroupOutput> &leftOutput = m_ChannelOutputs[0];
std::vector<GroupOutput> &rightOutput = m_ChannelOutputs[1];
for (const auto &groupName : audioGroups) {
Expand All @@ -38,31 +33,24 @@ GOAudioDeviceConfig::GOAudioDeviceConfig(
}

static const wxString WX_DVICE_03D_FMT = wxT("Device%03d");
static const wxString WX_NAME = wxT("Name");
static const wxString WX_CHANNEL_COUNT = wxT("ChannelCount");
static const wxString WX_LATENCY = wxT("Latency");
static const wxString WX_CHANNEL_03D_FMT = wxT("Channel%03d");
static const wxString WX_GROUP_COUNT = wxT("GroupCount");
static const wxString WX_GROUP_03D_FMT = wxT("Group%03d");
static const wxString WX_NAME = wxT("Name");
static const wxString WX_LEFT = wxT("Left");
static const wxString WX_RIGHT = wxT("Right");

void GOAudioDeviceConfig::Load(GOConfigReader &cfg, unsigned deviceN) {
const wxString p0 = wxString::Format(WX_DVICE_03D_FMT, deviceN);

LoadNamePattern(cfg, WX_AUDIO_DEVICES, p0, WX_NAME);
m_DesiredLatency = cfg.ReadInteger(
CMBSetting,
WX_AUDIO_DEVICES,
p0 + WX_LATENCY,
0,
999,
false,
DEFAULT_LATENCY);
m_channels = (uint8_t)cfg.ReadInteger(
LoadDeviceNode(cfg, WX_AUDIO_DEVICES, p0);

m_NChannels = (uint8_t)cfg.ReadInteger(
CMBSetting, WX_AUDIO_DEVICES, p0 + WX_CHANNEL_COUNT, 0, 200);
m_ChannelOutputs.resize(m_channels);
for (uint8_t j = 0; j < m_channels; j++) {

ResizeChannels();
for (uint8_t j = 0; j < m_NChannels; j++) {
const wxString p1 = p0 + wxString::Format(WX_CHANNEL_03D_FMT, j + 1);
std::vector<GroupOutput> &groups = m_ChannelOutputs[j];
const unsigned groupCount = cfg.ReadInteger(
Expand All @@ -88,10 +76,9 @@ void GOAudioDeviceConfig::Load(GOConfigReader &cfg, unsigned deviceN) {
void GOAudioDeviceConfig::Save(GOConfigWriter &cfg, unsigned deviceN) const {
const wxString p0 = wxString::Format(WX_DVICE_03D_FMT, deviceN);

SaveNamePattern(cfg, WX_AUDIO_DEVICES, p0, WX_NAME);
cfg.WriteInteger(WX_AUDIO_DEVICES, p0 + WX_CHANNEL_COUNT, m_channels);
cfg.WriteInteger(WX_AUDIO_DEVICES, p0 + WX_LATENCY, m_DesiredLatency);
for (uint8_t j = 0; j < m_channels; j++) {
SaveDeviceNode(cfg, WX_AUDIO_DEVICES, p0);
cfg.WriteInteger(WX_AUDIO_DEVICES, p0 + WX_CHANNEL_COUNT, m_NChannels);
for (uint8_t j = 0; j < m_NChannels; j++) {
const wxString p1 = p0 + wxString::Format(WX_CHANNEL_03D_FMT, j + 1);
const std::vector<GroupOutput> &groups = m_ChannelOutputs[j];
const unsigned groupCount = groups.size();
Expand Down
18 changes: 9 additions & 9 deletions src/grandorgue/config/GOAudioDeviceConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

#include <wx/string.h>

#include "GODeviceNamePattern.h"
#include "GOAudioDeviceNode.h"

class GOConfigReader;
class GOConfigWriter;

class GOAudioDeviceConfig : public GODeviceNamePattern {
class GOAudioDeviceConfig : public GOAudioDeviceNode {
public:
// volume values in dB
static constexpr float MUTE_VOLUME = -121.0f;
Expand Down Expand Up @@ -52,26 +52,26 @@ class GOAudioDeviceConfig : public GODeviceNamePattern {
};

private:
uint8_t m_NChannels;
std::vector<std::vector<GroupOutput>> m_ChannelOutputs;
unsigned m_DesiredLatency;
uint8_t m_channels;

static float volumeFor(bool isForLeft, bool isLeft, float vol) {
return isLeft == isForLeft ? vol : MUTE_VOLUME;
}

void ResizeChannels() { m_ChannelOutputs.resize(m_NChannels); }

public:
GOAudioDeviceConfig(
const wxString &name, unsigned desiredLatency, uint8_t channels);
GOAudioDeviceConfig(const GOAudioDeviceNode &node, uint8_t nChannels);

// Creates en ampty config for future Load()
GOAudioDeviceConfig();
GOAudioDeviceConfig() {}

// Creates the config with default settings
GOAudioDeviceConfig(const std::vector<wxString> &audioGroups);

unsigned GetDesiredLatency() const { return m_DesiredLatency; }
uint8_t GetChannels() const { return m_channels; }
uint8_t GetChannels() const { return m_NChannels; }

const std::vector<std::vector<GroupOutput>> &GetChannelOututs() const {
return m_ChannelOutputs;
}
Expand Down
27 changes: 27 additions & 0 deletions src/grandorgue/config/GOAudioDeviceNode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2006 Milan Digital Audio LLC
* Copyright 2009-2024 GrandOrgue contributors (see AUTHORS)
* License GPL-2.0 or later
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
*/

#include "GOAudioDeviceNode.h"

#include "config/GOConfigReader.h"
#include "config/GOConfigWriter.h"

static const wxString WX_NAME = wxT("Name");
static const wxString WX_LATENCY = wxT("Latency");

void GOAudioDeviceNode::LoadDeviceNode(
GOConfigReader &cfg, const wxString &group, const wxString &prefix) {
LoadNamePattern(cfg, group, prefix, WX_NAME);
m_DesiredLatency = cfg.ReadInteger(
CMBSetting, group, prefix + WX_LATENCY, 0, 999, false, DEFAULT_LATENCY);
}

void GOAudioDeviceNode::SaveDeviceNode(
GOConfigWriter &cfg, const wxString &group, const wxString &prefix) const {
SaveNamePattern(cfg, group, prefix, WX_NAME);
cfg.WriteInteger(group, prefix + WX_LATENCY, m_DesiredLatency);
}
32 changes: 32 additions & 0 deletions src/grandorgue/config/GOAudioDeviceNode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2006 Milan Digital Audio LLC
* Copyright 2009-2024 GrandOrgue contributors (see AUTHORS)
* License GPL-2.0 or later
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
*/

#ifndef GOAUDIODEVICENODE_H
#define GOAUDIODEVICENODE_H

#include "GODeviceNamePattern.h"

class GOConfigReader;
class GOConfigWriter;

class GOAudioDeviceNode : public GODeviceNamePattern {
private:
static constexpr unsigned DEFAULT_LATENCY = 50;

unsigned m_DesiredLatency = DEFAULT_LATENCY;

public:
unsigned GetDesiredLatency() const { return m_DesiredLatency; }
void SetDesiredLatenct(unsigned value) { m_DesiredLatency = value; }

void LoadDeviceNode(
GOConfigReader &cfg, const wxString &group, const wxString &prefix);
void SaveDeviceNode(
GOConfigWriter &cfg, const wxString &group, const wxString &prefix) const;
};

#endif /* GOAUDIODEVICENODE_H */
4 changes: 0 additions & 4 deletions src/grandorgue/config/GOConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,6 @@ int GOConfig::GetStrictAudioGroupId(const wxString &str) {
return -1;
}

const std::vector<GOAudioDeviceConfig> &GOConfig::GetAudioDeviceConfig() {
return m_AudioDeviceConfig;
}

void GOConfig::SetAudioDeviceConfig(
const std::vector<GOAudioDeviceConfig> &config) {
if (!config.size())
Expand Down
4 changes: 3 additions & 1 deletion src/grandorgue/config/GOConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ class GOConfig : public GOSettingStore, public GOOrganList {
m_SoundPortsConfig = portsConfig;
}

const std::vector<GOAudioDeviceConfig> &GetAudioDeviceConfig();
std::vector<GOAudioDeviceConfig> &GetAudioDeviceConfig() {
return m_AudioDeviceConfig;
}
const unsigned GetTotalAudioChannels() const;
void SetAudioDeviceConfig(const std::vector<GOAudioDeviceConfig> &config);
unsigned GetDefaultLatency();
Expand Down
2 changes: 2 additions & 0 deletions src/grandorgue/config/GODeviceNamePattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class GODeviceNamePattern {

~GODeviceNamePattern();

bool IsFilled() const { return !m_LogicalName.IsEmpty(); }

const wxString &GetLogicalName() const { return m_LogicalName; }
void SetLogicalName(const wxString &name) { m_LogicalName = name; }

Expand Down
Loading

0 comments on commit d579835

Please sign in to comment.