1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-04-30 07:39:42 +02:00

Use Settings for default sample rate and format...

... The first is an example of a Setting with a computed default value.

Also making a new file to hold them, separate from the GUI that changes them
in QualityPrefs; fewer things depend on QualityPrefs
This commit is contained in:
Paul Licameli 2021-05-15 14:39:26 -04:00
parent 8c04ed3990
commit f1de843246
13 changed files with 107 additions and 65 deletions

View File

@ -466,7 +466,7 @@ time warp info and AudioIOListener and whether the playback is looped.
#include "WaveTrack.h"
#include "effects/RealtimeEffectManager.h"
#include "prefs/QualityPrefs.h"
#include "prefs/QualitySettings.h"
#include "prefs/RecordingPrefs.h"
#include "widgets/MeterPanelBase.h"
#include "widgets/AudacityMessageBox.h"
@ -1445,7 +1445,7 @@ void AudioIO::StartMonitoring( const AudioIOStartStreamOptions &options )
return;
bool success;
auto captureFormat = QualityPrefs::SampleFormatChoice();
auto captureFormat = QualitySettings::SampleFormatChoice();
auto captureChannels = AudioIORecordChannels.Read();
gPrefs->Read(wxT("/AudioIO/SWPlaythrough"), &mSoftwarePlaythrough, false);
int playbackChannels = 0;

View File

@ -718,6 +718,8 @@ list( APPEND SOURCES
prefs/PrefsPanel.h
prefs/QualityPrefs.cpp
prefs/QualityPrefs.h
prefs/QualitySettings.cpp
prefs/QualitySettings.h
prefs/RecordingPrefs.cpp
prefs/RecordingPrefs.h
prefs/SpectrogramSettings.cpp

View File

@ -36,7 +36,7 @@ Paul Licameli split from AudacityProject.cpp
#include "wxFileNameWrapper.h"
#include "import/Import.h"
#include "import/ImportMIDI.h"
#include "prefs/QualityPrefs.h"
#include "prefs/QualitySettings.h"
#include "toolbars/MixerToolBar.h"
#include "toolbars/SelectionBar.h"
#include "toolbars/SpectralSelectionBar.h"
@ -1052,7 +1052,7 @@ int ProjectManager::GetEstimatedRecordingMinsLeftOnDisk(long lCaptureChannels) {
auto &project = mProject;
// Obtain the current settings
auto oCaptureFormat = QualityPrefs::SampleFormatChoice();
auto oCaptureFormat = QualitySettings::SampleFormatChoice();
if (lCaptureChannels == 0)
lCaptureChannels = AudioIORecordChannels.Read();

View File

@ -14,6 +14,7 @@ Paul Licameli split from AudacityProject.cpp
#include "AudioIOBase.h"
#include "Project.h"
#include "prefs/QualitySettings.h"
#include "widgets/NumericTextCtrl.h"
#include "prefs/TracksBehaviorsPrefs.h"
@ -67,15 +68,17 @@ ProjectSettings::ProjectSettings(AudacityProject &project)
}
, mSnapTo( gPrefs->Read(wxT("/SnapTo"), SNAP_OFF) )
{
if (!gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"), &mRate,
AudioIOBase::GetOptimalSupportedSampleRate())) {
int intRate;
if ( !QualitySettings::DefaultSampleRate.Read( &intRate ) ) {
// The default given above can vary with host/devices. So unless there is
// an entry for the default sample rate in audacity.cfg, Audacity can open
// with a rate which is different from the rate with which it closed.
// See bug 1879.
gPrefs->Write(wxT("/SamplingRate/DefaultProjectSampleRate"), mRate);
QualitySettings::DefaultSampleRate.Write( mRate );
gPrefs->Flush();
}
else
mRate = intRate;
gPrefs->Read(wxT("/GUI/SyncLockTracks"), &mIsSyncLocked, false);
bool multiToolActive = false;
@ -110,8 +113,7 @@ void ProjectSettings::UpdatePrefs()
// The DefaultProjectSample rate is the rate for new projects.
// Do not change this project's rate, unless there are no tracks.
if( TrackList::Get( *this ).size() == 0){
gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"), &mRate,
AudioIOBase::GetOptimalSupportedSampleRate());
mRate = QualityDefaultSampleRate.Read();
// If necessary, we change this rate in the selection toolbar too.
auto bar = SelectionBar::Get( *this );
bar.SetRate( mRate );

View File

@ -51,7 +51,7 @@ from the project that will own the track.
#include "Prefs.h"
#include "effects/TimeWarper.h"
#include "prefs/QualityPrefs.h"
#include "prefs/QualitySettings.h"
#include "prefs/SpectrogramSettings.h"
#include "prefs/TracksPrefs.h"
#include "prefs/TracksBehaviorsPrefs.h"
@ -85,7 +85,7 @@ WaveTrack::Holder WaveTrackFactory::DuplicateWaveTrack(const WaveTrack &orig)
WaveTrack::Holder WaveTrackFactory::NewWaveTrack(sampleFormat format, double rate)
{
if (format == (sampleFormat)0)
format = QualityPrefs::SampleFormatChoice();
format = QualitySettings::SampleFormatChoice();
if (rate == 0)
rate = mSettings.GetRate();
return std::make_shared<WaveTrack> ( mpFactory, format, rate );

View File

@ -33,6 +33,7 @@
#include "../ProjectAudioManager.h"
#include "../ProjectFileIO.h"
#include "../ProjectSettings.h"
#include "../prefs/QualitySettings.h"
#include "../ShuttleGui.h"
#include "../Shuttle.h"
#include "../ViewInfo.h"
@ -112,9 +113,8 @@ Effect::Effect()
// PRL: I think this initialization of mProjectRate doesn't matter
// because it is always reassigned in DoEffect before it is used
// STF: but can't call AudioIOBase::GetOptimalSupportedSampleRate() here.
gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"),
&mProjectRate,
44100);
// (Which is called to compute the default-default value.) (Bug 2280)
mProjectRate = QualitySettings::DefaultSampleRate.ReadWithDefault(44100);
mIsBatch = false;
}

View File

@ -13,7 +13,7 @@ Paul Licameli split from Import.cpp
#include <wx/filename.h>
#include "../WaveTrack.h"
#include "../widgets/ProgressDialog.h"
#include "../prefs/QualityPrefs.h"
#include "../prefs/QualitySettings.h"
ImportPlugin::ImportPlugin(FileExtensions supportedExtensions):
mExtensions( std::move( supportedExtensions ) )
@ -54,7 +54,7 @@ void ImportFileHandle::CreateProgress()
sampleFormat ImportFileHandle::ChooseFormat(sampleFormat effectiveFormat)
{
// Consult user preference
auto defaultFormat = QualityPrefs::SampleFormatChoice();
auto defaultFormat = QualitySettings::SampleFormatChoice();
// Don't choose format narrower than effective or default
auto format = std::max(effectiveFormat, defaultFormat);

View File

@ -27,7 +27,7 @@
#include "../commands/CommandManager.h"
#include "../effects/EffectManager.h"
#include "../effects/EffectUI.h"
#include "../prefs/QualityPrefs.h"
#include "../prefs/QualitySettings.h"
#include "../tracks/playabletrack/wavetrack/ui/WaveTrackControls.h"
#include "../widgets/ASlider.h"
#include "../widgets/AudacityMessageBox.h"
@ -52,7 +52,7 @@ void DoMixAndRender
auto &tracks = TrackList::Get( project );
auto &trackFactory = WaveTrackFactory::Get( project );
auto rate = settings.GetRate();
auto defaultFormat = QualityPrefs::SampleFormatChoice();
auto defaultFormat = QualitySettings::SampleFormatChoice();
auto &trackPanel = TrackPanel::Get( project );
auto &window = ProjectWindow::Get( project );
@ -609,7 +609,7 @@ void OnNewWaveTrack(const CommandContext &context)
auto &trackFactory = WaveTrackFactory::Get( project );
auto &window = ProjectWindow::Get( project );
auto defaultFormat = QualityPrefs::SampleFormatChoice();
auto defaultFormat = QualitySettings::SampleFormatChoice();
auto rate = settings.GetRate();
@ -633,7 +633,7 @@ void OnNewStereoTrack(const CommandContext &context)
auto &trackFactory = WaveTrackFactory::Get( project );
auto &window = ProjectWindow::Get( project );
auto defaultFormat = QualityPrefs::SampleFormatChoice();
auto defaultFormat = QualitySettings::SampleFormatChoice();
auto rate = settings.GetRate();
SelectUtilities::SelectNone( project );

View File

@ -17,6 +17,7 @@
#include "QualityPrefs.h"
#include "QualitySettings.h"
#include <wx/choice.h>
#include <wx/defs.h>
@ -30,26 +31,6 @@
#define ID_SAMPLE_RATE_CHOICE 7001
//////////
static EnumSetting< sampleFormat > formatSetting{
wxT("/SamplingRate/DefaultProjectSampleFormatChoice"),
{
{ wxT("Format16Bit"), XO("16-bit") },
{ wxT("Format24Bit"), XO("24-bit") },
{ wxT("Format32BitFloat"), XO("32-bit float") }
},
2, // floatSample
// for migrating old preferences:
{
int16Sample,
int24Sample,
floatSample
},
wxT("/SamplingRate/DefaultProjectSampleFormat"),
};
//////////
BEGIN_EVENT_TABLE(QualityPrefs, PrefsPanel)
EVT_CHOICE(ID_SAMPLE_RATE_CHOICE, QualityPrefs::OnSampleRateChoice)
@ -85,9 +66,7 @@ void QualityPrefs::Populate()
{
// First any pre-processing for constructing the GUI.
GetNamesAndLabels();
gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"),
&mOtherSampleRateValue,
AudioIOBase::GetOptimalSupportedSampleRate());
mOtherSampleRateValue = QualitySettings::DefaultSampleRate.Read();
//------------------------- Main section --------------------
// Now construct the GUI itself.
@ -148,17 +127,17 @@ void QualityPrefs::PopulateOrExchange(ShuttleGui & S)
{
// First the choice...
// We make sure it uses the ID we want, so that we get changes
S.Id(ID_SAMPLE_RATE_CHOICE);
// We make sure we have a pointer to it, so that we can drive it.
mSampleRates = S.TieNumberAsChoice( {},
{wxT("/SamplingRate/DefaultProjectSampleRate"),
AudioIOBase::GetOptimalSupportedSampleRate()},
mSampleRateNames,
&mSampleRateLabels,
// If the value in Prefs isn't in the list, then we want
// the last item, 'Other...' to be shown.
mSampleRateNames.size() - 1
);
mSampleRates =
S
.Id(ID_SAMPLE_RATE_CHOICE)
.TieNumberAsChoice( {},
QualitySettings::DefaultSampleRate,
mSampleRateNames,
&mSampleRateLabels,
// If the value in Prefs isn't in the list, then we want
// the last item, 'Other...' to be shown.
mSampleRateNames.size() - 1 );
// Now do the edit box...
mOtherSampleRate = S.TieNumericTextBox( {},
@ -167,8 +146,9 @@ void QualityPrefs::PopulateOrExchange(ShuttleGui & S)
}
S.EndHorizontalLay();
S.TieChoice(XXO("Default Sample &Format:"),
formatSetting);
S
.TieChoice( XXO("Default Sample &Format:"),
QualitySettings::SampleFormatSetting );
}
S.EndMultiColumn();
}
@ -223,7 +203,7 @@ bool QualityPrefs::Commit()
// The complex compound control may have value 'other' in which case the
// value in prefs comes from the second field.
if (mOtherSampleRate->IsEnabled()) {
gPrefs->Write(wxT("/SamplingRate/DefaultProjectSampleRate"), mOtherSampleRateValue);
QualitySettings::DefaultSampleRate.Write( mOtherSampleRateValue );
gPrefs->Flush();
}
@ -243,8 +223,3 @@ PrefsPanel::Registration sAttachment{ "Quality",
};
}
sampleFormat QualityPrefs::SampleFormatChoice()
{
return formatSetting.ReadEnum();
}

View File

@ -37,8 +37,6 @@ class AUDACITY_DLL_API QualityPrefs final : public PrefsPanel
wxString HelpPageName() override;
void PopulateOrExchange(ShuttleGui & S) override;
static sampleFormat SampleFormatChoice();
private:
void Populate();
void GetNamesAndLabels();

View File

@ -0,0 +1,41 @@
/**********************************************************************
Audacity: A Digital Audio Editor
QualitySettings.cpp
Paul Licameli split from QualityPrefs.cpp
**********************************************************************/
#include "QualitySettings.h"
#include "AudioIOBase.h"
#include "Internat.h"
IntSetting QualitySettings::DefaultSampleRate{
L"/SamplingRate/DefaultProjectSampleRate",
AudioIOBase::GetOptimalSupportedSampleRate
};
EnumSetting< sampleFormat > QualitySettings::SampleFormatSetting{
L"/SamplingRate/DefaultProjectSampleFormatChoice",
{
{ L"Format16Bit", XO("16-bit") },
{ L"Format24Bit", XO("24-bit") },
{ L"Format32BitFloat", XO("32-bit float") }
},
2, // floatSample
// for migrating old preferences:
{
int16Sample,
int24Sample,
floatSample
},
L"/SamplingRate/DefaultProjectSampleFormat",
};
sampleFormat QualitySettings::SampleFormatChoice()
{
return SampleFormatSetting.ReadEnum();
}

View File

@ -0,0 +1,24 @@
/**********************************************************************
Audacity: A Digital Audio Editor
QualitySettings.h
Paul Licameli split from QualityPrefs.h
**********************************************************************/
#ifndef __AUDACITY_QUALITY_SETTINGS__
#define __AUDACITY_QUALITY_SETTINGS__
#include "Prefs.h" // for EnumSetting
class IntSetting;
namespace QualitySettings {
extern IntSetting DefaultSampleRate;
extern EnumSetting< sampleFormat > SampleFormatSetting;
extern sampleFormat SampleFormatChoice();
}
#endif

View File

@ -60,6 +60,7 @@ with changes in the SelectionBar.
#include "../ProjectSettings.h"
#include "../Snap.h"
#include "../ViewInfo.h"
#include "../prefs/QualitySettings.h"
#include "../AllThemeResources.h"
#if wxUSE_ACCESSIBILITY
@ -123,8 +124,7 @@ SelectionBar::SelectionBar( AudacityProject &project )
// Refer to bug #462 for a scenario where the division-by-zero causes
// Audacity to fail.
// We expect mRate to be set from the project later.
mRate = (double) gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"),
AudioIOBase::GetOptimalSupportedSampleRate());
mRate = (double) QualitySettings::DefaultSampleRate.Read();
// Selection mode of 0 means showing 'start' and 'end' only.
mSelectionMode = gPrefs->ReadLong(wxT("/SelectionToolbarMode"), 0);