1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-17 16:40:07 +02: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:
Paul Licameli 2021-02-27 12:06:28 -05:00
parent 5fef82dccf
commit 8c04ed3990
10 changed files with 117 additions and 119 deletions

View File

@ -923,8 +923,8 @@ void AudioIO::Init()
int i = getRecordDevIndex(); int i = getRecordDevIndex();
const PaDeviceInfo *info = Pa_GetDeviceInfo(i); const PaDeviceInfo *info = Pa_GetDeviceInfo(i);
if (info) { if (info) {
gPrefs->Write(wxT("/AudioIO/RecordingDevice"), DeviceName(info)); AudioIORecordingDevice.Write(DeviceName(info));
gPrefs->Write(wxT("/AudioIO/Host"), HostName(info)); AudioIOHost.Write(HostName(info));
} }
} }
@ -932,8 +932,8 @@ void AudioIO::Init()
int i = getPlayDevIndex(); int i = getPlayDevIndex();
const PaDeviceInfo *info = Pa_GetDeviceInfo(i); const PaDeviceInfo *info = Pa_GetDeviceInfo(i);
if (info) { if (info) {
gPrefs->Write(wxT("/AudioIO/PlaybackDevice"), DeviceName(info)); AudioIOPlaybackDevice.Write(DeviceName(info));
gPrefs->Write(wxT("/AudioIO/Host"), HostName(info)); AudioIOHost.Write(HostName(info));
} }
} }
@ -1277,8 +1277,7 @@ bool AudioIO::StartPortAudioStream(const AudioIOStartStreamOptions &options,
PaStreamParameters playbackParameters{}; PaStreamParameters playbackParameters{};
PaStreamParameters captureParameters{}; PaStreamParameters captureParameters{};
double latencyDuration = DEFAULT_LATENCY_DURATION; auto latencyDuration = AudioIOLatencyDuration.Read();
gPrefs->Read(wxT("/AudioIO/LatencyDuration"), &latencyDuration);
if( numPlaybackChannels > 0) if( numPlaybackChannels > 0)
{ {
@ -1446,9 +1445,8 @@ void AudioIO::StartMonitoring( const AudioIOStartStreamOptions &options )
return; return;
bool success; bool success;
long captureChannels;
auto captureFormat = QualityPrefs::SampleFormatChoice(); auto captureFormat = QualityPrefs::SampleFormatChoice();
gPrefs->Read(wxT("/AudioIO/RecordChannels"), &captureChannels, 2L); auto captureChannels = AudioIORecordChannels.Read();
gPrefs->Read(wxT("/AudioIO/SWPlaythrough"), &mSoftwarePlaythrough, false); gPrefs->Read(wxT("/AudioIO/SWPlaythrough"), &mSoftwarePlaythrough, false);
int playbackChannels = 0; int playbackChannels = 0;
@ -1526,7 +1524,7 @@ int AudioIO::StartStream(const TransportTracks &tracks,
#ifdef __WXGTK__ #ifdef __WXGTK__
// Detect whether ALSA is the chosen host, and do the various involved MIDI // Detect whether ALSA is the chosen host, and do the various involved MIDI
// timing compensations only then. // timing compensations only then.
mUsingAlsa = (gPrefs->Read(wxT("/AudioIO/Host"), wxT("")) == "ALSA"); mUsingAlsa = (AudioIOHost.Read() == L"ALSA");
#endif #endif
gPrefs->Read(wxT("/AudioIO/SWPlaythrough"), &mSoftwarePlaythrough, false); gPrefs->Read(wxT("/AudioIO/SWPlaythrough"), &mSoftwarePlaythrough, false);
@ -1556,9 +1554,7 @@ int AudioIO::StartStream(const TransportTracks &tracks,
mRecordingSchedule = {}; mRecordingSchedule = {};
mRecordingSchedule.mPreRoll = preRoll; mRecordingSchedule.mPreRoll = preRoll;
mRecordingSchedule.mLatencyCorrection = mRecordingSchedule.mLatencyCorrection =
(gPrefs->ReadDouble(wxT("/AudioIO/LatencyCorrection"), AudioIOLatencyCorrection.Read() / 1000.0;
DEFAULT_LATENCY_CORRECTION))
/ 1000.0;
mRecordingSchedule.mDuration = t1 - t0; mRecordingSchedule.mDuration = t1 - t0;
if (options.pCrossfadeData) if (options.pCrossfadeData)
mRecordingSchedule.mCrossfadeData.swap( *options.pCrossfadeData ); mRecordingSchedule.mCrossfadeData.swap( *options.pCrossfadeData );
@ -2191,8 +2187,7 @@ void AudioIO::StopStream()
// PortAudio callback can use the information that we are stopping to fade // PortAudio callback can use the information that we are stopping to fade
// out the audio. Give PortAudio callback a chance to do so. // out the audio. Give PortAudio callback a chance to do so.
mAudioThreadFillBuffersLoopRunning = false; mAudioThreadFillBuffersLoopRunning = false;
long latency; auto latency = static_cast<long>(AudioIOLatencyDuration.Read());
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 // 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 // the sound card, then do so. If we can't, don't wait around. Just stop quickly and accept
// there will be a click. // there will be a click.

View File

@ -18,7 +18,6 @@ Paul Licameli split from AudioIO.cpp
#include <wx/txtstrm.h> #include <wx/txtstrm.h>
#include "Prefs.h" #include "Prefs.h"
#include "prefs/RecordingPrefs.h"
#include "widgets/MeterPanelBase.h" #include "widgets/MeterPanelBase.h"
#if USE_PORTMIXER #if USE_PORTMIXER
@ -185,7 +184,8 @@ void AudioIOBase::HandleDeviceChange()
playbackParameters.suggestedLatency = playbackParameters.suggestedLatency =
Pa_GetDeviceInfo(playDeviceNum)->defaultLowOutputLatency; Pa_GetDeviceInfo(playDeviceNum)->defaultLowOutputLatency;
else else
playbackParameters.suggestedLatency = DEFAULT_LATENCY_CORRECTION/1000.0; playbackParameters.suggestedLatency =
AudioIOLatencyCorrection.GetDefault()/1000.0;
PaStreamParameters captureParameters; PaStreamParameters captureParameters;
@ -197,7 +197,8 @@ void AudioIOBase::HandleDeviceChange()
captureParameters.suggestedLatency = captureParameters.suggestedLatency =
Pa_GetDeviceInfo(recDeviceNum)->defaultLowInputLatency; Pa_GetDeviceInfo(recDeviceNum)->defaultLowInputLatency;
else else
captureParameters.suggestedLatency = DEFAULT_LATENCY_CORRECTION/1000.0; captureParameters.suggestedLatency =
AudioIOLatencyCorrection.GetDefault()/1000.0;
// try opening for record and playback // try opening for record and playback
// Not really doing I/O so pass nullptr for the callback function // Not really doing I/O so pass nullptr for the callback function
@ -257,8 +258,7 @@ void AudioIOBase::HandleDeviceChange()
// Set input source // Set input source
#if USE_PORTMIXER #if USE_PORTMIXER
int sourceIndex; auto sourceIndex = AudioIORecordingSourceIndex.Read(); // defaults to -1
if (gPrefs->Read(wxT("/AudioIO/RecordingSourceIndex"), &sourceIndex)) {
if (sourceIndex >= 0) { if (sourceIndex >= 0) {
//the current index of our source may be different because the stream //the current index of our source may be different because the stream
//is a combination of two devices, so update it. //is a combination of two devices, so update it.
@ -266,7 +266,6 @@ void AudioIOBase::HandleDeviceChange()
if (sourceIndex >= 0) if (sourceIndex >= 0)
SetMixer(sourceIndex); SetMixer(sourceIndex);
} }
}
#endif #endif
// Determine mixer capabilities - if it doesn't support control of output // Determine mixer capabilities - if it doesn't support control of output
@ -471,10 +470,9 @@ std::vector<long> AudioIOBase::GetSupportedCaptureRates(int devIndex, double rat
return supported; return supported;
} }
double latencyDuration = DEFAULT_LATENCY_DURATION; auto latencyDuration = AudioIOLatencyDuration.Read();
long recordChannels = 1; // Why not defaulting to 2 as elsewhere?
gPrefs->Read(wxT("/AudioIO/LatencyDuration"), &latencyDuration); auto recordChannels = AudioIORecordChannels.ReadWithDefault(1);
gPrefs->Read(wxT("/AudioIO/RecordChannels"), &recordChannels);
// LLL: Remove when a proper method of determining actual supported // LLL: Remove when a proper method of determining actual supported
// DirectSound rate is devised. // DirectSound rate is devised.
@ -583,7 +581,7 @@ int AudioIOBase::GetOptimalSupportedSampleRate()
int AudioIOBase::getRecordSourceIndex(PxMixer *portMixer) int AudioIOBase::getRecordSourceIndex(PxMixer *portMixer)
{ {
int i; int i;
wxString sourceName = gPrefs->Read(wxT("/AudioIO/RecordingSource"), wxT("")); auto sourceName = AudioIORecordingSource.Read();
int numSources = Px_GetNumInputSources(portMixer); int numSources = Px_GetNumInputSources(portMixer);
for (i = 0; i < numSources; i++) { for (i = 0; i < numSources; i++) {
if (sourceName == wxString(wxSafeConvertMB2WX(Px_GetInputSourceName(portMixer, i)))) if (sourceName == wxString(wxSafeConvertMB2WX(Px_GetInputSourceName(portMixer, i))))
@ -598,11 +596,9 @@ int AudioIOBase::getPlayDevIndex(const wxString &devNameArg)
wxString devName(devNameArg); wxString devName(devNameArg);
// if we don't get given a device, look up the preferences // if we don't get given a device, look up the preferences
if (devName.empty()) if (devName.empty())
{ devName = AudioIOPlaybackDevice.Read();
devName = gPrefs->Read(wxT("/AudioIO/PlaybackDevice"), wxT(""));
}
wxString hostName = gPrefs->Read(wxT("/AudioIO/Host"), wxT("")); auto hostName = AudioIOHost.Read();
PaHostApiIndex hostCnt = Pa_GetHostApiCount(); PaHostApiIndex hostCnt = Pa_GetHostApiCount();
PaHostApiIndex hostNum; PaHostApiIndex hostNum;
for (hostNum = 0; hostNum < hostCnt; hostNum++) for (hostNum = 0; hostNum < hostCnt; hostNum++)
@ -655,11 +651,9 @@ int AudioIOBase::getRecordDevIndex(const wxString &devNameArg)
wxString devName(devNameArg); wxString devName(devNameArg);
// if we don't get given a device, look up the preferences // if we don't get given a device, look up the preferences
if (devName.empty()) if (devName.empty())
{ devName = AudioIORecordingDevice.Read();
devName = gPrefs->Read(wxT("/AudioIO/RecordingDevice"), wxT(""));
}
wxString hostName = gPrefs->Read(wxT("/AudioIO/Host"), wxT("")); auto hostName = AudioIOHost.Read();
PaHostApiIndex hostCnt = Pa_GetHostApiCount(); PaHostApiIndex hostCnt = Pa_GetHostApiCount();
PaHostApiIndex hostNum; PaHostApiIndex hostNum;
for (hostNum = 0; hostNum < hostCnt; 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 recording device number: %d\n").Format( recDeviceNum );
s << XO("Default playback device number: %d\n").Format( playDeviceNum); s << XO("Default playback device number: %d\n").Format( playDeviceNum);
wxString recDevice = gPrefs->Read(wxT("/AudioIO/RecordingDevice"), wxT("")); auto recDevice = AudioIORecordingDevice.Read();
wxString playDevice = gPrefs->Read(wxT("/AudioIO/PlaybackDevice"), wxT("")); auto playDevice = AudioIOPlaybackDevice.Read();
int j; int j;
// This gets info on all available audio devices (input and output) // This gets info on all available audio devices (input and output)
@ -840,9 +834,9 @@ wxString AudioIOBase::GetDeviceInfo()
playbackParameters.suggestedLatency = playbackParameters.suggestedLatency =
Pa_GetDeviceInfo(playDeviceNum)->defaultLowOutputLatency; Pa_GetDeviceInfo(playDeviceNum)->defaultLowOutputLatency;
} }
else{ else
playbackParameters.suggestedLatency = DEFAULT_LATENCY_CORRECTION/1000.0; playbackParameters.suggestedLatency =
} AudioIOLatencyCorrection.GetDefault()/1000.0;
PaStreamParameters captureParameters; PaStreamParameters captureParameters;
@ -853,9 +847,10 @@ wxString AudioIOBase::GetDeviceInfo()
if (Pa_GetDeviceInfo(recDeviceNum)){ if (Pa_GetDeviceInfo(recDeviceNum)){
captureParameters.suggestedLatency = captureParameters.suggestedLatency =
Pa_GetDeviceInfo(recDeviceNum)->defaultLowInputLatency; 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 // Not really doing I/O so pass nullptr for the callback function
error = Pa_OpenStream(&stream, error = Pa_OpenStream(&stream,
@ -1060,3 +1055,20 @@ wxString AudioIOBase::GetMidiDeviceInfo()
return o.GetString(); return o.GetString();
} }
#endif #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 };

View File

@ -338,3 +338,14 @@ protected:
}; };
#endif #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;

View File

@ -389,8 +389,7 @@ WaveTrackArray ProjectAudioManager::ChooseExistingRecordingTracks(
AudacityProject &proj, bool selectedOnly, double targetRate) AudacityProject &proj, bool selectedOnly, double targetRate)
{ {
auto p = &proj; auto p = &proj;
size_t recordingChannels = size_t recordingChannels = std::max(0, AudioIORecordChannels.Read());
std::max(0L, gPrefs->Read(wxT("/AudioIO/RecordChannels"), 2));
bool strictRules = (recordingChannels <= 2); bool strictRules = (recordingChannels <= 2);
// Iterate over all wave tracks, or over selected wave tracks only. // 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 &trackList = TrackList::Get( *p );
auto numTracks = trackList.Leaders< const WaveTrack >().size(); 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/RecordingNameCustom"), &recordingNameCustom, false);
gPrefs->Read(wxT("/GUI/TrackNames/TrackNumber"), &useTrackNumber, false); gPrefs->Read(wxT("/GUI/TrackNames/TrackNumber"), &useTrackNumber, false);

View File

@ -1053,9 +1053,8 @@ int ProjectManager::GetEstimatedRecordingMinsLeftOnDisk(long lCaptureChannels) {
// Obtain the current settings // Obtain the current settings
auto oCaptureFormat = QualityPrefs::SampleFormatChoice(); auto oCaptureFormat = QualityPrefs::SampleFormatChoice();
if (lCaptureChannels == 0) { if (lCaptureChannels == 0)
gPrefs->Read(wxT("/AudioIO/RecordChannels"), &lCaptureChannels, 2L); lCaptureChannels = AudioIORecordChannels.Read();
}
// Find out how much free space we have on disk // Find out how much free space we have on disk
wxLongLong lFreeSpace = ProjectFileIO::Get( project ).GetFreeDiskSpace(); wxLongLong lFreeSpace = ProjectFileIO::Get( project ).GetFreeDiskSpace();

View File

@ -529,8 +529,8 @@ void OnPunchAndRoll(const CommandContext &context)
auto tracks = auto tracks =
ProjectAudioManager::ChooseExistingRecordingTracks(project, true, rateOfSelected); ProjectAudioManager::ChooseExistingRecordingTracks(project, true, rateOfSelected);
if (tracks.empty()) { if (tracks.empty()) {
int recordingChannels = auto recordingChannels =
std::max(0L, gPrefs->Read(wxT("/AudioIO/RecordChannels"), 2)); std::max(0, AudioIORecordChannels.Read());
auto message = auto message =
(recordingChannels == 1) (recordingChannels == 1)
? XO("Please select in a mono track.") ? XO("Please select in a mono track.")

View File

@ -24,6 +24,7 @@ other settings.
#include "DevicePrefs.h" #include "DevicePrefs.h"
#include "AudioIOBase.h"
#include "RecordingPrefs.h" #include "RecordingPrefs.h"
@ -84,10 +85,10 @@ void DevicePrefs::Populate()
GetNamesAndLabels(); GetNamesAndLabels();
// Get current setting for devices // Get current setting for devices
mPlayDevice = gPrefs->Read(wxT("/AudioIO/PlaybackDevice"), wxT("")); mPlayDevice = AudioIOPlaybackDevice.Read();
mRecordDevice = gPrefs->Read(wxT("/AudioIO/RecordingDevice"), wxT("")); mRecordDevice = AudioIORecordingDevice.Read();
mRecordSource = gPrefs->Read(wxT("/AudioIO/RecordingSource"), wxT("")); mRecordSource = AudioIORecordingSource.Read();
mRecordChannels = gPrefs->Read(wxT("/AudioIO/RecordChannels"), 2L); mRecordChannels = AudioIORecordChannels.Read();
//------------------------- Main section -------------------- //------------------------- Main section --------------------
// Now construct the GUI itself. // Now construct the GUI itself.
@ -137,7 +138,7 @@ void DevicePrefs::PopulateOrExchange(ShuttleGui & S)
S.Id(HostID); S.Id(HostID);
mHost = S.TieChoice( XXO("&Host:"), mHost = S.TieChoice( XXO("&Host:"),
{ {
wxT("/AudioIO/Host"), AudioIOHost,
{ ByColumns, mHostNames, mHostLabels } { ByColumns, mHostNames, mHostLabels }
} }
); );
@ -190,17 +191,14 @@ void DevicePrefs::PopulateOrExchange(ShuttleGui & S)
w = S w = S
.NameSuffix(XO("milliseconds")) .NameSuffix(XO("milliseconds"))
.TieNumericTextBox(XXO("&Buffer length:"), .TieNumericTextBox(XXO("&Buffer length:"),
{wxT("/AudioIO/LatencyDuration"), AudioIOLatencyDuration,
DEFAULT_LATENCY_DURATION},
9); 9);
S.AddUnits(XO("milliseconds")); S.AddUnits(XO("milliseconds"));
w = S w = S
.NameSuffix(XO("milliseconds")) .NameSuffix(XO("milliseconds"))
.TieNumericTextBox(XXO("&Latency compensation:"), .TieNumericTextBox(XXO("&Latency compensation:"),
{wxT("/AudioIO/LatencyCorrection"), AudioIOLatencyCorrection, 9);
DEFAULT_LATENCY_CORRECTION},
9);
S.AddUnits(XO("milliseconds")); S.AddUnits(XO("milliseconds"));
} }
S.EndThreeColumn(); S.EndThreeColumn();
@ -396,28 +394,21 @@ bool DevicePrefs::Commit()
map = (DeviceSourceMap *) mPlay->GetClientData( map = (DeviceSourceMap *) mPlay->GetClientData(
mPlay->GetSelection()); mPlay->GetSelection());
} }
if (map) { if (map)
gPrefs->Write(wxT("/AudioIO/PlaybackDevice"), map->deviceString); AudioIOPlaybackDevice.Write(map->deviceString);
}
map = NULL; map = NULL;
if (mRecord->GetCount() > 0) { if (mRecord->GetCount() > 0) {
map = (DeviceSourceMap *) mRecord->GetClientData(mRecord->GetSelection()); map = (DeviceSourceMap *) mRecord->GetClientData(mRecord->GetSelection());
} }
if (map) { if (map) {
gPrefs->Write(wxT("/AudioIO/RecordingDevice"), AudioIORecordingDevice.Write(map->deviceString);
map->deviceString); AudioIORecordingSourceIndex.Write(map->sourceIndex);
gPrefs->Write(wxT("/AudioIO/RecordingSourceIndex"), if (map->totalSources >= 1)
map->sourceIndex); AudioIORecordingSource.Write(map->sourceString);
if (map->totalSources >= 1) { else
gPrefs->Write(wxT("/AudioIO/RecordingSource"), AudioIORecordingSource.Reset();
map->sourceString); AudioIORecordChannels.Write(mChannels->GetSelection() + 1);
} else {
gPrefs->Write(wxT("/AudioIO/RecordingSource"),
wxT(""));
}
gPrefs->Write(wxT("/AudioIO/RecordChannels"),
mChannels->GetSelection() + 1);
} }
return true; return true;

View File

@ -20,6 +20,7 @@
#include "RecordingPrefs.h" #include "RecordingPrefs.h"
#include "AudioIOBase.h"
#include <wx/defs.h> #include <wx/defs.h>
#include <wx/textctrl.h> #include <wx/textctrl.h>
@ -269,11 +270,8 @@ bool RecordingPrefs::Commit()
ShuttleGui S(this, eIsSavingToPrefs); ShuttleGui S(this, eIsSavingToPrefs);
PopulateOrExchange(S); PopulateOrExchange(S);
double latencyDuration = DEFAULT_LATENCY_DURATION; if (AudioIOLatencyDuration.Read() < 0)
gPrefs->Read(wxT("/AudioIO/LatencyDuration"), &latencyDuration); AudioIOLatencyDuration.Reset();
if (latencyDuration < 0) {
gPrefs->Write(wxT("/AudioIO/LatencyDuration"), DEFAULT_LATENCY_DURATION);
}
#ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT #ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
double targetpeak, deltapeak; double targetpeak, deltapeak;

View File

@ -30,9 +30,6 @@ class ShuttleGui;
#define RECORDING_PREFS_PLUGIN_SYMBOL ComponentInterfaceSymbol{ XO("Recording") } #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 AUDIO_PRE_ROLL_KEY (wxT("/AudioIO/PreRoll"))
#define DEFAULT_PRE_ROLL_SECONDS 5.0 #define DEFAULT_PRE_ROLL_SECONDS 5.0

View File

@ -237,9 +237,6 @@ void DeviceToolBar::OnCaptureKey(wxCommandEvent &event)
void DeviceToolBar::UpdatePrefs() void DeviceToolBar::UpdatePrefs()
{ {
wxString hostName;
wxString devName;
wxString sourceName;
wxString desc; wxString desc;
const std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps(); const std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps();
const std::vector<DeviceSourceMap> &outMaps = DeviceManager::Instance()->GetOutputDeviceMaps(); const std::vector<DeviceSourceMap> &outMaps = DeviceManager::Instance()->GetOutputDeviceMaps();
@ -248,15 +245,15 @@ void DeviceToolBar::UpdatePrefs()
int hostSelectionIndex = mHost->GetSelection(); int hostSelectionIndex = mHost->GetSelection();
wxString oldHost = hostSelectionIndex >= 0 ? mHost->GetString(hostSelectionIndex) : wxString oldHost = hostSelectionIndex >= 0 ? mHost->GetString(hostSelectionIndex) :
wxT(""); 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 // if the prefs host name doesn't match the one displayed, it changed
// in another project's DeviceToolBar, so we need to repopulate everything. // in another project's DeviceToolBar, so we need to repopulate everything.
if (oldHost != hostName) if (oldHost != hostName)
FillHostDevices(); FillHostDevices();
devName = gPrefs->Read(wxT("/AudioIO/RecordingDevice"), wxT("")); auto devName = AudioIORecordingDevice.Read();
sourceName = gPrefs->Read(wxT("/AudioIO/RecordingSource"), wxT("")); auto sourceName = AudioIORecordingSource.Read();
if (sourceName.empty()) if (sourceName.empty())
desc = devName; desc = devName;
else 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("")); sourceName = gPrefs->Read(wxT("/AudioIO/PlaybackSource"), wxT(""));
if (sourceName.empty()) if (sourceName.empty())
desc = devName; desc = devName;
@ -315,9 +312,9 @@ void DeviceToolBar::UpdatePrefs()
} }
} }
long oldChannels, newChannels; long oldChannels;
oldChannels = mInputChannels->GetSelection() + 1; oldChannels = mInputChannels->GetSelection() + 1;
gPrefs->Read(wxT("/AudioIO/RecordChannels"), &newChannels, 0); auto newChannels = AudioIORecordChannels.ReadWithDefault(0);
if (newChannels > 0 && oldChannels != newChannels) if (newChannels > 0 && oldChannels != newChannels)
mInputChannels->SetSelection(newChannels - 1); mInputChannels->SetSelection(newChannels - 1);
@ -432,7 +429,7 @@ void DeviceToolBar::FillHostDevices()
const std::vector<DeviceSourceMap> &outMaps = DeviceManager::Instance()->GetOutputDeviceMaps(); const std::vector<DeviceSourceMap> &outMaps = DeviceManager::Instance()->GetOutputDeviceMaps();
//read what is in the prefs //read what is in the prefs
wxString host = gPrefs->Read(wxT("/AudioIO/Host"), wxT("")); auto host = AudioIOHost.Read();
int foundHostIndex = -1; int foundHostIndex = -1;
// if the host is not in the hosts combo then we rescanned. // if the host is not in the hosts combo then we rescanned.
@ -482,7 +479,7 @@ void DeviceToolBar::FillHostDevices()
mInput->Append(MakeDeviceSourceString(&device)); mInput->Append(MakeDeviceSourceString(&device));
if (host.empty()) { if (host.empty()) {
host = device.hostString; host = device.hostString;
gPrefs->Write(wxT("/AudioIO/Host"), host); AudioIOHost.Write(host);
mHost->SetStringSelection(host); mHost->SetStringSelection(host);
} }
} }
@ -496,7 +493,7 @@ void DeviceToolBar::FillHostDevices()
mOutput->Append(MakeDeviceSourceString(&device)); mOutput->Append(MakeDeviceSourceString(&device));
if (host.empty()) { if (host.empty()) {
host = device.hostString; host = device.hostString;
gPrefs->Write(wxT("/AudioIO/Host"), host); AudioIOHost.Write(host);
gPrefs->Flush(); gPrefs->Flush();
mHost->SetStringSelection(host); mHost->SetStringSelection(host);
} }
@ -512,12 +509,12 @@ void DeviceToolBar::FillHostDevices()
void DeviceToolBar::FillInputChannels() void DeviceToolBar::FillInputChannels()
{ {
const std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps(); const std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps();
wxString host = gPrefs->Read(wxT("/AudioIO/Host"), wxT("")); auto host = AudioIOHost.Read();
wxString device = gPrefs->Read(wxT("/AudioIO/RecordingDevice"), wxT("")); auto device = AudioIORecordingDevice.Read();
wxString source = gPrefs->Read(wxT("/AudioIO/RecordingSource"), wxT("")); auto source = AudioIORecordingSource.Read();
long oldChannels = 2, newChannels; long newChannels;
gPrefs->Read(wxT("/AudioIO/RecordChannels"), &oldChannels); auto oldChannels = AudioIORecordChannels.Read();
mInputChannels->Clear(); mInputChannels->Clear();
for (auto & dev: inMaps) { for (auto & dev: inMaps) {
if (source == dev.sourceString && if (source == dev.sourceString &&
@ -546,7 +543,7 @@ void DeviceToolBar::FillInputChannels()
if (newChannels >= 1) { if (newChannels >= 1) {
mInputChannels->SetSelection(newChannels - 1); mInputChannels->SetSelection(newChannels - 1);
} }
gPrefs->Write(wxT("/AudioIO/RecordChannels"), newChannels); AudioIORecordChannels.Write(newChannels);
break; break;
} }
} }
@ -568,7 +565,7 @@ int DeviceToolBar::ChangeHost()
int hostSelectionIndex; int hostSelectionIndex;
hostSelectionIndex = mHost->GetSelection(); hostSelectionIndex = mHost->GetSelection();
wxString oldHost = gPrefs->Read(wxT("/AudioIO/Host"), wxT("")); auto oldHost = AudioIOHost.Read();
wxString newHost = hostSelectionIndex >= 0 ? mHost->GetString(hostSelectionIndex) : wxString newHost = hostSelectionIndex >= 0 ? mHost->GetString(hostSelectionIndex) :
oldHost; oldHost;
@ -576,7 +573,7 @@ int DeviceToolBar::ChangeHost()
return 0; return 0;
//change the host and switch to correct devices. //change the host and switch to correct devices.
gPrefs->Write(wxT("/AudioIO/Host"), newHost); AudioIOHost.Write(newHost);
gPrefs->Flush(); gPrefs->Flush();
// populate the devices // populate the devices
@ -588,20 +585,19 @@ int DeviceToolBar::ChangeHost()
void DeviceToolBar::SetDevices(const DeviceSourceMap *in, const DeviceSourceMap *out) void DeviceToolBar::SetDevices(const DeviceSourceMap *in, const DeviceSourceMap *out)
{ {
if (in) { if (in) {
gPrefs->Write(wxT("/AudioIO/RecordingDevice"), in->deviceString); AudioIORecordingDevice.Write(in->deviceString);
gPrefs->Write(wxT("/AudioIO/RecordingSourceIndex"), in->sourceIndex); AudioIORecordingSourceIndex.Write(in->sourceIndex);
if (in->totalSources >= 1) { if (in->totalSources >= 1)
gPrefs->Write(wxT("/AudioIO/RecordingSource"), in->sourceString); AudioIORecordingSource.Write(in->sourceString);
} else { else
gPrefs->Write(wxT("/AudioIO/RecordingSource"), wxT("")); AudioIORecordingSource.Reset();
}
gPrefs->Flush(); gPrefs->Flush();
FillInputChannels(); FillInputChannels();
} }
if (out) { if (out) {
gPrefs->Write(wxT("/AudioIO/PlaybackDevice"), out->deviceString); AudioIOPlaybackDevice.Write(out->deviceString);
if (out->totalSources >= 1) { if (out->totalSources >= 1) {
gPrefs->Write(wxT("/AudioIO/PlaybackSource"), out->sourceString); gPrefs->Write(wxT("/AudioIO/PlaybackSource"), out->sourceString);
} else { } else {
@ -618,7 +614,7 @@ void DeviceToolBar::ChangeDevice(bool isInput)
size_t i; size_t i;
int selectionIndex = combo->GetSelection(); 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() const std::vector<DeviceSourceMap> &maps = isInput ? DeviceManager::Instance()->GetInputDeviceMaps()
: DeviceManager::Instance()->GetOutputDeviceMaps(); : DeviceManager::Instance()->GetOutputDeviceMaps();
@ -652,7 +648,7 @@ void DeviceToolBar::OnChoice(wxCommandEvent &event)
} else if (eventObject == mInputChannels) { } else if (eventObject == mInputChannels) {
int channelsSelectionIndex = mInputChannels->GetSelection(); int channelsSelectionIndex = mInputChannels->GetSelection();
if (channelsSelectionIndex >= 0) if (channelsSelectionIndex >= 0)
gPrefs->Write(wxT("/AudioIO/RecordChannels"),channelsSelectionIndex + 1); AudioIORecordChannels.Write(channelsSelectionIndex + 1);
} else if (eventObject == mInput) { } else if (eventObject == mInput) {
ChangeDevice(true); ChangeDevice(true);
} }