mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-23 17:30:17 +01:00
Settings objects used in AudioIOBase...
... Giving many examples of use of Settings objects. Many other rewrites like this should be made to eliminate as many direct uses of gPrefs as we can. Don't rely on long distance coincidences of literals for paths or defaults. For each of several paths like /AudioIO/Host, all uses of that path are replaced with use of a global Settings object defined in one place, in AudioIOBase. The object also gives the benefit of caching the last-read or written value. Other users of those preferences must then include "AudioIOBase.h" to make the dependency explicit at compile time. It should be checked that no other mentions of those paths remain in the source, and that there was no unintended change in default values. This also inverts dependency of AudioIOBase on RecordingPrefs, which is GUI for changing some of these settings.
This commit is contained in:
@@ -237,9 +237,6 @@ void DeviceToolBar::OnCaptureKey(wxCommandEvent &event)
|
||||
|
||||
void DeviceToolBar::UpdatePrefs()
|
||||
{
|
||||
wxString hostName;
|
||||
wxString devName;
|
||||
wxString sourceName;
|
||||
wxString desc;
|
||||
const std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps();
|
||||
const std::vector<DeviceSourceMap> &outMaps = DeviceManager::Instance()->GetOutputDeviceMaps();
|
||||
@@ -248,15 +245,15 @@ void DeviceToolBar::UpdatePrefs()
|
||||
int hostSelectionIndex = mHost->GetSelection();
|
||||
wxString oldHost = hostSelectionIndex >= 0 ? mHost->GetString(hostSelectionIndex) :
|
||||
wxT("");
|
||||
hostName = gPrefs->Read(wxT("/AudioIO/Host"), wxT(""));
|
||||
auto hostName = AudioIOHost.Read();
|
||||
|
||||
// if the prefs host name doesn't match the one displayed, it changed
|
||||
// in another project's DeviceToolBar, so we need to repopulate everything.
|
||||
if (oldHost != hostName)
|
||||
FillHostDevices();
|
||||
|
||||
devName = gPrefs->Read(wxT("/AudioIO/RecordingDevice"), wxT(""));
|
||||
sourceName = gPrefs->Read(wxT("/AudioIO/RecordingSource"), wxT(""));
|
||||
auto devName = AudioIORecordingDevice.Read();
|
||||
auto sourceName = AudioIORecordingSource.Read();
|
||||
if (sourceName.empty())
|
||||
desc = devName;
|
||||
else
|
||||
@@ -285,7 +282,7 @@ void DeviceToolBar::UpdatePrefs()
|
||||
}
|
||||
}
|
||||
|
||||
devName = gPrefs->Read(wxT("/AudioIO/PlaybackDevice"), wxT(""));
|
||||
devName = AudioIOPlaybackDevice.Read();
|
||||
sourceName = gPrefs->Read(wxT("/AudioIO/PlaybackSource"), wxT(""));
|
||||
if (sourceName.empty())
|
||||
desc = devName;
|
||||
@@ -315,9 +312,9 @@ void DeviceToolBar::UpdatePrefs()
|
||||
}
|
||||
}
|
||||
|
||||
long oldChannels, newChannels;
|
||||
long oldChannels;
|
||||
oldChannels = mInputChannels->GetSelection() + 1;
|
||||
gPrefs->Read(wxT("/AudioIO/RecordChannels"), &newChannels, 0);
|
||||
auto newChannels = AudioIORecordChannels.ReadWithDefault(0);
|
||||
if (newChannels > 0 && oldChannels != newChannels)
|
||||
mInputChannels->SetSelection(newChannels - 1);
|
||||
|
||||
@@ -432,7 +429,7 @@ void DeviceToolBar::FillHostDevices()
|
||||
const std::vector<DeviceSourceMap> &outMaps = DeviceManager::Instance()->GetOutputDeviceMaps();
|
||||
|
||||
//read what is in the prefs
|
||||
wxString host = gPrefs->Read(wxT("/AudioIO/Host"), wxT(""));
|
||||
auto host = AudioIOHost.Read();
|
||||
int foundHostIndex = -1;
|
||||
|
||||
// if the host is not in the hosts combo then we rescanned.
|
||||
@@ -482,7 +479,7 @@ void DeviceToolBar::FillHostDevices()
|
||||
mInput->Append(MakeDeviceSourceString(&device));
|
||||
if (host.empty()) {
|
||||
host = device.hostString;
|
||||
gPrefs->Write(wxT("/AudioIO/Host"), host);
|
||||
AudioIOHost.Write(host);
|
||||
mHost->SetStringSelection(host);
|
||||
}
|
||||
}
|
||||
@@ -496,7 +493,7 @@ void DeviceToolBar::FillHostDevices()
|
||||
mOutput->Append(MakeDeviceSourceString(&device));
|
||||
if (host.empty()) {
|
||||
host = device.hostString;
|
||||
gPrefs->Write(wxT("/AudioIO/Host"), host);
|
||||
AudioIOHost.Write(host);
|
||||
gPrefs->Flush();
|
||||
mHost->SetStringSelection(host);
|
||||
}
|
||||
@@ -512,12 +509,12 @@ void DeviceToolBar::FillHostDevices()
|
||||
void DeviceToolBar::FillInputChannels()
|
||||
{
|
||||
const std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps();
|
||||
wxString host = gPrefs->Read(wxT("/AudioIO/Host"), wxT(""));
|
||||
wxString device = gPrefs->Read(wxT("/AudioIO/RecordingDevice"), wxT(""));
|
||||
wxString source = gPrefs->Read(wxT("/AudioIO/RecordingSource"), wxT(""));
|
||||
long oldChannels = 2, newChannels;
|
||||
auto host = AudioIOHost.Read();
|
||||
auto device = AudioIORecordingDevice.Read();
|
||||
auto source = AudioIORecordingSource.Read();
|
||||
long newChannels;
|
||||
|
||||
gPrefs->Read(wxT("/AudioIO/RecordChannels"), &oldChannels);
|
||||
auto oldChannels = AudioIORecordChannels.Read();
|
||||
mInputChannels->Clear();
|
||||
for (auto & dev: inMaps) {
|
||||
if (source == dev.sourceString &&
|
||||
@@ -546,7 +543,7 @@ void DeviceToolBar::FillInputChannels()
|
||||
if (newChannels >= 1) {
|
||||
mInputChannels->SetSelection(newChannels - 1);
|
||||
}
|
||||
gPrefs->Write(wxT("/AudioIO/RecordChannels"), newChannels);
|
||||
AudioIORecordChannels.Write(newChannels);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -568,7 +565,7 @@ int DeviceToolBar::ChangeHost()
|
||||
int hostSelectionIndex;
|
||||
hostSelectionIndex = mHost->GetSelection();
|
||||
|
||||
wxString oldHost = gPrefs->Read(wxT("/AudioIO/Host"), wxT(""));
|
||||
auto oldHost = AudioIOHost.Read();
|
||||
wxString newHost = hostSelectionIndex >= 0 ? mHost->GetString(hostSelectionIndex) :
|
||||
oldHost;
|
||||
|
||||
@@ -576,7 +573,7 @@ int DeviceToolBar::ChangeHost()
|
||||
return 0;
|
||||
|
||||
//change the host and switch to correct devices.
|
||||
gPrefs->Write(wxT("/AudioIO/Host"), newHost);
|
||||
AudioIOHost.Write(newHost);
|
||||
gPrefs->Flush();
|
||||
|
||||
// populate the devices
|
||||
@@ -588,20 +585,19 @@ int DeviceToolBar::ChangeHost()
|
||||
void DeviceToolBar::SetDevices(const DeviceSourceMap *in, const DeviceSourceMap *out)
|
||||
{
|
||||
if (in) {
|
||||
gPrefs->Write(wxT("/AudioIO/RecordingDevice"), in->deviceString);
|
||||
gPrefs->Write(wxT("/AudioIO/RecordingSourceIndex"), in->sourceIndex);
|
||||
if (in->totalSources >= 1) {
|
||||
gPrefs->Write(wxT("/AudioIO/RecordingSource"), in->sourceString);
|
||||
} else {
|
||||
gPrefs->Write(wxT("/AudioIO/RecordingSource"), wxT(""));
|
||||
}
|
||||
AudioIORecordingDevice.Write(in->deviceString);
|
||||
AudioIORecordingSourceIndex.Write(in->sourceIndex);
|
||||
if (in->totalSources >= 1)
|
||||
AudioIORecordingSource.Write(in->sourceString);
|
||||
else
|
||||
AudioIORecordingSource.Reset();
|
||||
gPrefs->Flush();
|
||||
|
||||
FillInputChannels();
|
||||
}
|
||||
|
||||
if (out) {
|
||||
gPrefs->Write(wxT("/AudioIO/PlaybackDevice"), out->deviceString);
|
||||
AudioIOPlaybackDevice.Write(out->deviceString);
|
||||
if (out->totalSources >= 1) {
|
||||
gPrefs->Write(wxT("/AudioIO/PlaybackSource"), out->sourceString);
|
||||
} else {
|
||||
@@ -618,7 +614,7 @@ void DeviceToolBar::ChangeDevice(bool isInput)
|
||||
size_t i;
|
||||
|
||||
int selectionIndex = combo->GetSelection();
|
||||
wxString host = gPrefs->Read(wxT("/AudioIO/Host"), wxT(""));
|
||||
auto host = AudioIOHost.Read();
|
||||
const std::vector<DeviceSourceMap> &maps = isInput ? DeviceManager::Instance()->GetInputDeviceMaps()
|
||||
: DeviceManager::Instance()->GetOutputDeviceMaps();
|
||||
|
||||
@@ -652,7 +648,7 @@ void DeviceToolBar::OnChoice(wxCommandEvent &event)
|
||||
} else if (eventObject == mInputChannels) {
|
||||
int channelsSelectionIndex = mInputChannels->GetSelection();
|
||||
if (channelsSelectionIndex >= 0)
|
||||
gPrefs->Write(wxT("/AudioIO/RecordChannels"),channelsSelectionIndex + 1);
|
||||
AudioIORecordChannels.Write(channelsSelectionIndex + 1);
|
||||
} else if (eventObject == mInput) {
|
||||
ChangeDevice(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user