diff --git a/src/AudioIO.cpp b/src/AudioIO.cpp index 13a8aa1c0..f94961a08 100644 --- a/src/AudioIO.cpp +++ b/src/AudioIO.cpp @@ -923,8 +923,8 @@ void AudioIO::Init() int i = getRecordDevIndex(); const PaDeviceInfo *info = Pa_GetDeviceInfo(i); if (info) { - gPrefs->Write(wxT("/AudioIO/RecordingDevice"), DeviceName(info)); - gPrefs->Write(wxT("/AudioIO/Host"), HostName(info)); + AudioIORecordingDevice.Write(DeviceName(info)); + AudioIOHost.Write(HostName(info)); } } @@ -932,8 +932,8 @@ void AudioIO::Init() int i = getPlayDevIndex(); const PaDeviceInfo *info = Pa_GetDeviceInfo(i); if (info) { - gPrefs->Write(wxT("/AudioIO/PlaybackDevice"), DeviceName(info)); - gPrefs->Write(wxT("/AudioIO/Host"), HostName(info)); + AudioIOPlaybackDevice.Write(DeviceName(info)); + AudioIOHost.Write(HostName(info)); } } @@ -1277,8 +1277,7 @@ bool AudioIO::StartPortAudioStream(const AudioIOStartStreamOptions &options, PaStreamParameters playbackParameters{}; PaStreamParameters captureParameters{}; - double latencyDuration = DEFAULT_LATENCY_DURATION; - gPrefs->Read(wxT("/AudioIO/LatencyDuration"), &latencyDuration); + auto latencyDuration = AudioIOLatencyDuration.Read(); if( numPlaybackChannels > 0) { @@ -1446,9 +1445,8 @@ void AudioIO::StartMonitoring( const AudioIOStartStreamOptions &options ) return; bool success; - long captureChannels; auto captureFormat = QualityPrefs::SampleFormatChoice(); - gPrefs->Read(wxT("/AudioIO/RecordChannels"), &captureChannels, 2L); + auto captureChannels = AudioIORecordChannels.Read(); gPrefs->Read(wxT("/AudioIO/SWPlaythrough"), &mSoftwarePlaythrough, false); int playbackChannels = 0; @@ -1526,7 +1524,7 @@ int AudioIO::StartStream(const TransportTracks &tracks, #ifdef __WXGTK__ // Detect whether ALSA is the chosen host, and do the various involved MIDI // timing compensations only then. - mUsingAlsa = (gPrefs->Read(wxT("/AudioIO/Host"), wxT("")) == "ALSA"); + mUsingAlsa = (AudioIOHost.Read() == L"ALSA"); #endif gPrefs->Read(wxT("/AudioIO/SWPlaythrough"), &mSoftwarePlaythrough, false); @@ -1556,9 +1554,7 @@ int AudioIO::StartStream(const TransportTracks &tracks, mRecordingSchedule = {}; mRecordingSchedule.mPreRoll = preRoll; mRecordingSchedule.mLatencyCorrection = - (gPrefs->ReadDouble(wxT("/AudioIO/LatencyCorrection"), - DEFAULT_LATENCY_CORRECTION)) - / 1000.0; + AudioIOLatencyCorrection.Read() / 1000.0; mRecordingSchedule.mDuration = t1 - t0; if (options.pCrossfadeData) mRecordingSchedule.mCrossfadeData.swap( *options.pCrossfadeData ); @@ -2191,9 +2187,8 @@ void AudioIO::StopStream() // PortAudio callback can use the information that we are stopping to fade // out the audio. Give PortAudio callback a chance to do so. mAudioThreadFillBuffersLoopRunning = false; - long latency; - gPrefs->Read( wxT("/AudioIO/LatencyDuration"), &latency, DEFAULT_LATENCY_DURATION ); - // If we can gracefully fade out in 200ms, with the faded-out play buffers making it through + auto latency = static_cast(AudioIOLatencyDuration.Read()); + // If we can gracefully fade out in 200ms, with the faded-out play buffers making it through // the sound card, then do so. If we can't, don't wait around. Just stop quickly and accept // there will be a click. if( mbMicroFades && (latency < 150 )) diff --git a/src/AudioIOBase.cpp b/src/AudioIOBase.cpp index 3535cec32..2425e7fff 100644 --- a/src/AudioIOBase.cpp +++ b/src/AudioIOBase.cpp @@ -18,7 +18,6 @@ Paul Licameli split from AudioIO.cpp #include #include "Prefs.h" -#include "prefs/RecordingPrefs.h" #include "widgets/MeterPanelBase.h" #if USE_PORTMIXER @@ -185,7 +184,8 @@ void AudioIOBase::HandleDeviceChange() playbackParameters.suggestedLatency = Pa_GetDeviceInfo(playDeviceNum)->defaultLowOutputLatency; else - playbackParameters.suggestedLatency = DEFAULT_LATENCY_CORRECTION/1000.0; + playbackParameters.suggestedLatency = + AudioIOLatencyCorrection.GetDefault()/1000.0; PaStreamParameters captureParameters; @@ -197,7 +197,8 @@ void AudioIOBase::HandleDeviceChange() captureParameters.suggestedLatency = Pa_GetDeviceInfo(recDeviceNum)->defaultLowInputLatency; else - captureParameters.suggestedLatency = DEFAULT_LATENCY_CORRECTION/1000.0; + captureParameters.suggestedLatency = + AudioIOLatencyCorrection.GetDefault()/1000.0; // try opening for record and playback // Not really doing I/O so pass nullptr for the callback function @@ -257,15 +258,13 @@ void AudioIOBase::HandleDeviceChange() // Set input source #if USE_PORTMIXER - int sourceIndex; - if (gPrefs->Read(wxT("/AudioIO/RecordingSourceIndex"), &sourceIndex)) { - if (sourceIndex >= 0) { - //the current index of our source may be different because the stream - //is a combination of two devices, so update it. - sourceIndex = getRecordSourceIndex(mPortMixer); - if (sourceIndex >= 0) - SetMixer(sourceIndex); - } + auto sourceIndex = AudioIORecordingSourceIndex.Read(); // defaults to -1 + if (sourceIndex >= 0) { + //the current index of our source may be different because the stream + //is a combination of two devices, so update it. + sourceIndex = getRecordSourceIndex(mPortMixer); + if (sourceIndex >= 0) + SetMixer(sourceIndex); } #endif @@ -471,10 +470,9 @@ std::vector AudioIOBase::GetSupportedCaptureRates(int devIndex, double rat return supported; } - double latencyDuration = DEFAULT_LATENCY_DURATION; - long recordChannels = 1; - gPrefs->Read(wxT("/AudioIO/LatencyDuration"), &latencyDuration); - gPrefs->Read(wxT("/AudioIO/RecordChannels"), &recordChannels); + auto latencyDuration = AudioIOLatencyDuration.Read(); + // Why not defaulting to 2 as elsewhere? + auto recordChannels = AudioIORecordChannels.ReadWithDefault(1); // LLL: Remove when a proper method of determining actual supported // DirectSound rate is devised. @@ -583,7 +581,7 @@ int AudioIOBase::GetOptimalSupportedSampleRate() int AudioIOBase::getRecordSourceIndex(PxMixer *portMixer) { int i; - wxString sourceName = gPrefs->Read(wxT("/AudioIO/RecordingSource"), wxT("")); + auto sourceName = AudioIORecordingSource.Read(); int numSources = Px_GetNumInputSources(portMixer); for (i = 0; i < numSources; i++) { if (sourceName == wxString(wxSafeConvertMB2WX(Px_GetInputSourceName(portMixer, i)))) @@ -598,11 +596,9 @@ int AudioIOBase::getPlayDevIndex(const wxString &devNameArg) wxString devName(devNameArg); // if we don't get given a device, look up the preferences if (devName.empty()) - { - devName = gPrefs->Read(wxT("/AudioIO/PlaybackDevice"), wxT("")); - } + devName = AudioIOPlaybackDevice.Read(); - wxString hostName = gPrefs->Read(wxT("/AudioIO/Host"), wxT("")); + auto hostName = AudioIOHost.Read(); PaHostApiIndex hostCnt = Pa_GetHostApiCount(); PaHostApiIndex hostNum; for (hostNum = 0; hostNum < hostCnt; hostNum++) @@ -655,11 +651,9 @@ int AudioIOBase::getRecordDevIndex(const wxString &devNameArg) wxString devName(devNameArg); // if we don't get given a device, look up the preferences if (devName.empty()) - { - devName = gPrefs->Read(wxT("/AudioIO/RecordingDevice"), wxT("")); - } + devName = AudioIORecordingDevice.Read(); - wxString hostName = gPrefs->Read(wxT("/AudioIO/Host"), wxT("")); + auto hostName = AudioIOHost.Read(); PaHostApiIndex hostCnt = Pa_GetHostApiCount(); PaHostApiIndex hostNum; for (hostNum = 0; hostNum < hostCnt; hostNum++) @@ -732,8 +726,8 @@ wxString AudioIOBase::GetDeviceInfo() s << XO("Default recording device number: %d\n").Format( recDeviceNum ); s << XO("Default playback device number: %d\n").Format( playDeviceNum); - wxString recDevice = gPrefs->Read(wxT("/AudioIO/RecordingDevice"), wxT("")); - wxString playDevice = gPrefs->Read(wxT("/AudioIO/PlaybackDevice"), wxT("")); + auto recDevice = AudioIORecordingDevice.Read(); + auto playDevice = AudioIOPlaybackDevice.Read(); int j; // This gets info on all available audio devices (input and output) @@ -840,9 +834,9 @@ wxString AudioIOBase::GetDeviceInfo() playbackParameters.suggestedLatency = Pa_GetDeviceInfo(playDeviceNum)->defaultLowOutputLatency; } - else{ - playbackParameters.suggestedLatency = DEFAULT_LATENCY_CORRECTION/1000.0; - } + else + playbackParameters.suggestedLatency = + AudioIOLatencyCorrection.GetDefault()/1000.0; PaStreamParameters captureParameters; @@ -853,9 +847,10 @@ wxString AudioIOBase::GetDeviceInfo() if (Pa_GetDeviceInfo(recDeviceNum)){ captureParameters.suggestedLatency = Pa_GetDeviceInfo(recDeviceNum)->defaultLowInputLatency; - }else{ - captureParameters.suggestedLatency = DEFAULT_LATENCY_CORRECTION/1000.0; } + else + captureParameters.suggestedLatency = + AudioIOLatencyCorrection.GetDefault()/1000.0; // Not really doing I/O so pass nullptr for the callback function error = Pa_OpenStream(&stream, @@ -1060,3 +1055,20 @@ wxString AudioIOBase::GetMidiDeviceInfo() return o.GetString(); } #endif + +StringSetting AudioIOHost{ + L"/AudioIO/Host", L"" }; +DoubleSetting AudioIOLatencyCorrection{ + L"/AudioIO/LatencyCorrection", -130.0 }; +DoubleSetting AudioIOLatencyDuration{ + L"/AudioIO/LatencyDuration", 100.0 }; +StringSetting AudioIOPlaybackDevice{ + L"/AudioIO/PlaybackDevice", L"" }; +IntSetting AudioIORecordChannels{ + L"/AudioIO/RecordChannels", 2 }; +StringSetting AudioIORecordingDevice{ + L"/AudioIO/RecordingDevice", L"" }; +StringSetting AudioIORecordingSource{ + L"/AudioIO/RecordingSource", L"" }; +IntSetting AudioIORecordingSourceIndex{ + L"/AudioIO/RecordingSourceIndex", -1 }; diff --git a/src/AudioIOBase.h b/src/AudioIOBase.h index cc4bcdf5f..80734f52b 100644 --- a/src/AudioIOBase.h +++ b/src/AudioIOBase.h @@ -338,3 +338,14 @@ protected: }; #endif + +#include "Prefs.h" + +extern AUDACITY_DLL_API StringSetting AudioIOHost; +extern AUDACITY_DLL_API DoubleSetting AudioIOLatencyCorrection; +extern AUDACITY_DLL_API DoubleSetting AudioIOLatencyDuration; +extern AUDACITY_DLL_API StringSetting AudioIOPlaybackDevice; +extern AUDACITY_DLL_API IntSetting AudioIORecordChannels; +extern AUDACITY_DLL_API StringSetting AudioIORecordingDevice; +extern AUDACITY_DLL_API StringSetting AudioIORecordingSource; +extern AUDACITY_DLL_API IntSetting AudioIORecordingSourceIndex; diff --git a/src/ProjectAudioManager.cpp b/src/ProjectAudioManager.cpp index 61cd1cc7f..e04ad850c 100644 --- a/src/ProjectAudioManager.cpp +++ b/src/ProjectAudioManager.cpp @@ -389,8 +389,7 @@ WaveTrackArray ProjectAudioManager::ChooseExistingRecordingTracks( AudacityProject &proj, bool selectedOnly, double targetRate) { auto p = &proj; - size_t recordingChannels = - std::max(0L, gPrefs->Read(wxT("/AudioIO/RecordChannels"), 2)); + size_t recordingChannels = std::max(0, AudioIORecordChannels.Read()); bool strictRules = (recordingChannels <= 2); // Iterate over all wave tracks, or over selected wave tracks only. @@ -665,7 +664,7 @@ bool ProjectAudioManager::DoRecord(AudacityProject &project, auto &trackList = TrackList::Get( *p ); auto numTracks = trackList.Leaders< const WaveTrack >().size(); - auto recordingChannels = std::max(1L, gPrefs->Read(wxT("/AudioIO/RecordChannels"), 2)); + auto recordingChannels = std::max(1, AudioIORecordChannels.Read()); gPrefs->Read(wxT("/GUI/TrackNames/RecordingNameCustom"), &recordingNameCustom, false); gPrefs->Read(wxT("/GUI/TrackNames/TrackNumber"), &useTrackNumber, false); diff --git a/src/ProjectManager.cpp b/src/ProjectManager.cpp index 41b55274d..8e3235c0d 100644 --- a/src/ProjectManager.cpp +++ b/src/ProjectManager.cpp @@ -1053,9 +1053,8 @@ int ProjectManager::GetEstimatedRecordingMinsLeftOnDisk(long lCaptureChannels) { // Obtain the current settings auto oCaptureFormat = QualityPrefs::SampleFormatChoice(); - if (lCaptureChannels == 0) { - gPrefs->Read(wxT("/AudioIO/RecordChannels"), &lCaptureChannels, 2L); - } + if (lCaptureChannels == 0) + lCaptureChannels = AudioIORecordChannels.Read(); // Find out how much free space we have on disk wxLongLong lFreeSpace = ProjectFileIO::Get( project ).GetFreeDiskSpace(); diff --git a/src/menus/TransportMenus.cpp b/src/menus/TransportMenus.cpp index 64f08aa7f..aa91ca852 100644 --- a/src/menus/TransportMenus.cpp +++ b/src/menus/TransportMenus.cpp @@ -529,8 +529,8 @@ void OnPunchAndRoll(const CommandContext &context) auto tracks = ProjectAudioManager::ChooseExistingRecordingTracks(project, true, rateOfSelected); if (tracks.empty()) { - int recordingChannels = - std::max(0L, gPrefs->Read(wxT("/AudioIO/RecordChannels"), 2)); + auto recordingChannels = + std::max(0, AudioIORecordChannels.Read()); auto message = (recordingChannels == 1) ? XO("Please select in a mono track.") diff --git a/src/prefs/DevicePrefs.cpp b/src/prefs/DevicePrefs.cpp index 6d260cace..2951e84f9 100644 --- a/src/prefs/DevicePrefs.cpp +++ b/src/prefs/DevicePrefs.cpp @@ -24,6 +24,7 @@ other settings. #include "DevicePrefs.h" +#include "AudioIOBase.h" #include "RecordingPrefs.h" @@ -84,10 +85,10 @@ void DevicePrefs::Populate() GetNamesAndLabels(); // Get current setting for devices - mPlayDevice = gPrefs->Read(wxT("/AudioIO/PlaybackDevice"), wxT("")); - mRecordDevice = gPrefs->Read(wxT("/AudioIO/RecordingDevice"), wxT("")); - mRecordSource = gPrefs->Read(wxT("/AudioIO/RecordingSource"), wxT("")); - mRecordChannels = gPrefs->Read(wxT("/AudioIO/RecordChannels"), 2L); + mPlayDevice = AudioIOPlaybackDevice.Read(); + mRecordDevice = AudioIORecordingDevice.Read(); + mRecordSource = AudioIORecordingSource.Read(); + mRecordChannels = AudioIORecordChannels.Read(); //------------------------- Main section -------------------- // Now construct the GUI itself. @@ -137,7 +138,7 @@ void DevicePrefs::PopulateOrExchange(ShuttleGui & S) S.Id(HostID); mHost = S.TieChoice( XXO("&Host:"), { - wxT("/AudioIO/Host"), + AudioIOHost, { ByColumns, mHostNames, mHostLabels } } ); @@ -190,17 +191,14 @@ void DevicePrefs::PopulateOrExchange(ShuttleGui & S) w = S .NameSuffix(XO("milliseconds")) .TieNumericTextBox(XXO("&Buffer length:"), - {wxT("/AudioIO/LatencyDuration"), - DEFAULT_LATENCY_DURATION}, + AudioIOLatencyDuration, 9); S.AddUnits(XO("milliseconds")); w = S .NameSuffix(XO("milliseconds")) .TieNumericTextBox(XXO("&Latency compensation:"), - {wxT("/AudioIO/LatencyCorrection"), - DEFAULT_LATENCY_CORRECTION}, - 9); + AudioIOLatencyCorrection, 9); S.AddUnits(XO("milliseconds")); } S.EndThreeColumn(); @@ -396,28 +394,21 @@ bool DevicePrefs::Commit() map = (DeviceSourceMap *) mPlay->GetClientData( mPlay->GetSelection()); } - if (map) { - gPrefs->Write(wxT("/AudioIO/PlaybackDevice"), map->deviceString); - } + if (map) + AudioIOPlaybackDevice.Write(map->deviceString); map = NULL; if (mRecord->GetCount() > 0) { map = (DeviceSourceMap *) mRecord->GetClientData(mRecord->GetSelection()); } if (map) { - gPrefs->Write(wxT("/AudioIO/RecordingDevice"), - map->deviceString); - gPrefs->Write(wxT("/AudioIO/RecordingSourceIndex"), - map->sourceIndex); - if (map->totalSources >= 1) { - gPrefs->Write(wxT("/AudioIO/RecordingSource"), - map->sourceString); - } else { - gPrefs->Write(wxT("/AudioIO/RecordingSource"), - wxT("")); - } - gPrefs->Write(wxT("/AudioIO/RecordChannels"), - mChannels->GetSelection() + 1); + AudioIORecordingDevice.Write(map->deviceString); + AudioIORecordingSourceIndex.Write(map->sourceIndex); + if (map->totalSources >= 1) + AudioIORecordingSource.Write(map->sourceString); + else + AudioIORecordingSource.Reset(); + AudioIORecordChannels.Write(mChannels->GetSelection() + 1); } return true; diff --git a/src/prefs/RecordingPrefs.cpp b/src/prefs/RecordingPrefs.cpp index 77dccc81d..15eb589c3 100644 --- a/src/prefs/RecordingPrefs.cpp +++ b/src/prefs/RecordingPrefs.cpp @@ -20,6 +20,7 @@ #include "RecordingPrefs.h" +#include "AudioIOBase.h" #include #include @@ -269,11 +270,8 @@ bool RecordingPrefs::Commit() ShuttleGui S(this, eIsSavingToPrefs); PopulateOrExchange(S); - double latencyDuration = DEFAULT_LATENCY_DURATION; - gPrefs->Read(wxT("/AudioIO/LatencyDuration"), &latencyDuration); - if (latencyDuration < 0) { - gPrefs->Write(wxT("/AudioIO/LatencyDuration"), DEFAULT_LATENCY_DURATION); - } + if (AudioIOLatencyDuration.Read() < 0) + AudioIOLatencyDuration.Reset(); #ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT double targetpeak, deltapeak; diff --git a/src/prefs/RecordingPrefs.h b/src/prefs/RecordingPrefs.h index 2135f0f0e..79cb78296 100644 --- a/src/prefs/RecordingPrefs.h +++ b/src/prefs/RecordingPrefs.h @@ -30,9 +30,6 @@ class ShuttleGui; #define RECORDING_PREFS_PLUGIN_SYMBOL ComponentInterfaceSymbol{ XO("Recording") } -#define DEFAULT_LATENCY_DURATION 100.0 -#define DEFAULT_LATENCY_CORRECTION -130.0 - #define AUDIO_PRE_ROLL_KEY (wxT("/AudioIO/PreRoll")) #define DEFAULT_PRE_ROLL_SECONDS 5.0 diff --git a/src/toolbars/DeviceToolBar.cpp b/src/toolbars/DeviceToolBar.cpp index 8bd9c543a..451bfd2fb 100644 --- a/src/toolbars/DeviceToolBar.cpp +++ b/src/toolbars/DeviceToolBar.cpp @@ -237,9 +237,6 @@ void DeviceToolBar::OnCaptureKey(wxCommandEvent &event) void DeviceToolBar::UpdatePrefs() { - wxString hostName; - wxString devName; - wxString sourceName; wxString desc; const std::vector &inMaps = DeviceManager::Instance()->GetInputDeviceMaps(); const std::vector &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 &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 &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 &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); }