From 2ea5741e2e2671eac6bf8177381264141fa3b228 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sat, 24 Mar 2018 00:10:50 -0400 Subject: [PATCH] Redo format setting choices in Quality preferences --- include/audacity/Types.h | 4 +-- src/AudioIO.cpp | 4 +-- src/Project.cpp | 10 +++---- src/Sequence.cpp | 2 +- src/import/ImportFLAC.cpp | 4 +-- src/import/ImportMP3.cpp | 4 +-- src/import/ImportOGG.cpp | 4 +-- src/import/ImportPCM.cpp | 4 +-- src/import/ImportRaw.cpp | 4 +-- src/ondemand/ODDecodeFlacTask.cpp | 3 +-- src/prefs/QualityPrefs.cpp | 43 ++++++++++++++++++++++++------- src/prefs/QualityPrefs.h | 5 ++-- 12 files changed, 58 insertions(+), 33 deletions(-) diff --git a/include/audacity/Types.h b/include/audacity/Types.h index 63f028964..1bf2ead26 100644 --- a/include/audacity/Types.h +++ b/include/audacity/Types.h @@ -184,12 +184,12 @@ inline size_t limitSampleBufferSize( size_t bufferSize, sampleCount limit ) // ---------------------------------------------------------------------------- // Supported sample formats // ---------------------------------------------------------------------------- -typedef enum +enum sampleFormat : unsigned { int16Sample = 0x00020001, int24Sample = 0x00040001, floatSample = 0x0004000F -} sampleFormat; +}; // ---------------------------------------------------------------------------- // Provide the number of bytes a specific sample will take diff --git a/src/AudioIO.cpp b/src/AudioIO.cpp index 876e7ca6a..a01302cf7 100644 --- a/src/AudioIO.cpp +++ b/src/AudioIO.cpp @@ -447,6 +447,7 @@ TimeTrack and AudioIOListener and whether the playback is looped. #include "WaveTrack.h" #include "AutoRecovery.h" +#include "prefs/QualityPrefs.h" #include "toolbars/ControlToolBar.h" #include "widgets/Meter.h" #include "widgets/ErrorDialog.h" @@ -1825,8 +1826,7 @@ void AudioIO::StartMonitoring(double sampleRate) bool success; long captureChannels; - sampleFormat captureFormat = (sampleFormat) - gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleFormat"), floatSample); + auto captureFormat = QualityPrefs::SampleFormatChoice(); gPrefs->Read(wxT("/AudioIO/RecordChannels"), &captureChannels, 2L); gPrefs->Read(wxT("/AudioIO/SWPlaythrough"), &mSoftwarePlaythrough, false); int playbackChannels = 0; diff --git a/src/Project.cpp b/src/Project.cpp index 47ce77cac..a6c6b73fb 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -166,6 +166,8 @@ scroll information. It also has some status flags. #include "commands/CommandType.h" #include "commands/CommandContext.h" +#include "prefs/QualityPrefs.h" + #include "../images/AudacityLogoAlpha.xpm" std::shared_ptr AudacityProject::msClipboard{ TrackList::Create() }; @@ -917,8 +919,7 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id, mViewInfo(0.0, 1.0, ZoomInfo::GetDefaultZoom()), mbLoadedFromAup( false ), mRate((double) gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"), AudioIO::GetOptimalSupportedSampleRate())), - mDefaultFormat((sampleFormat) gPrefs-> - Read(wxT("/SamplingRate/DefaultProjectSampleFormat"), floatSample)), + mDefaultFormat(QualityPrefs::SampleFormatChoice()), mSnapTo(gPrefs->Read(wxT("/SnapTo"), SNAP_OFF)), mSelectionFormat(gPrefs->Read(wxT("/SelectionFormat"), wxT(""))), mFrequencySelectionFormatName(gPrefs->Read(wxT("/FrequencySelectionFormatName"), wxT(""))), @@ -1305,7 +1306,7 @@ void AudacityProject::UpdatePrefsVariables() // gPrefs->Read(wxT("/GUI/UpdateSpectrogram"), &mViewInfo.bUpdateSpectrogram, true); gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"), &mRate, AudioIO::GetOptimalSupportedSampleRate()); - mDefaultFormat = (sampleFormat) gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleFormat"), floatSample); + mDefaultFormat = QualityPrefs::SampleFormatChoice(); gPrefs->Read(wxT("/AudioIO/SeekShortPeriod"), &mSeekShort, 1.0); gPrefs->Read(wxT("/AudioIO/SeekLongPeriod"), &mSeekLong, 15.0); @@ -5887,8 +5888,7 @@ wxString AudacityProject::GetHoursMinsString(int iMinutes) int AudacityProject::GetEstimatedRecordingMinsLeftOnDisk(long lCaptureChannels) { // Obtain the current settings - sampleFormat oCaptureFormat = (sampleFormat) - gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleFormat"), floatSample); + auto oCaptureFormat = QualityPrefs::SampleFormatChoice(); if (lCaptureChannels == 0) { gPrefs->Read(wxT("/AudioIO/RecordChannels"), &lCaptureChannels, 2L); } diff --git a/src/Sequence.cpp b/src/Sequence.cpp index 586cedc1e..66d2f28cc 100644 --- a/src/Sequence.cpp +++ b/src/Sequence.cpp @@ -1040,7 +1040,7 @@ void Sequence::WriteXML(XMLWriter &xmlFile) const xmlFile.StartTag(wxT("sequence")); xmlFile.WriteAttr(wxT("maxsamples"), mMaxSamples); - xmlFile.WriteAttr(wxT("sampleformat"), mSampleFormat); + xmlFile.WriteAttr(wxT("sampleformat"), (size_t)mSampleFormat); xmlFile.WriteAttr(wxT("numsamples"), mNumSamples.as_long_long() ); for (b = 0; b < mBlock.size(); b++) { diff --git a/src/import/ImportFLAC.cpp b/src/import/ImportFLAC.cpp index a65f3af58..20e1f2ffa 100644 --- a/src/import/ImportFLAC.cpp +++ b/src/import/ImportFLAC.cpp @@ -42,6 +42,7 @@ #include "ImportPlugin.h" #include "../Tags.h" +#include "../prefs/QualityPrefs.h" #include "../Experimental.h" @@ -350,8 +351,7 @@ FLACImportFileHandle::FLACImportFileHandle(const wxString & name) mStreamInfoDone(false), mUpdateResult(ProgressResult::Success) { - mFormat = (sampleFormat) - gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleFormat"), floatSample); + mFormat = QualityPrefs::SampleFormatChoice(); mFile = std::make_unique(this); } diff --git a/src/import/ImportMP3.cpp b/src/import/ImportMP3.cpp index 7eb2ae402..42bca3f08 100644 --- a/src/import/ImportMP3.cpp +++ b/src/import/ImportMP3.cpp @@ -45,6 +45,7 @@ #include "ImportPlugin.h" #include "../Internat.h" #include "../Tags.h" +#include "../prefs/QualityPrefs.h" #define DESC _("MP3 files") @@ -498,8 +499,7 @@ enum mad_flow output_cb(void *_data, if(data->channels.empty()) { data->channels.resize(channels); - sampleFormat format = (sampleFormat) gPrefs-> - Read(wxT("/SamplingRate/DefaultProjectSampleFormat"), floatSample); + auto format = QualityPrefs::SampleFormatChoice(); for(auto &channel: data->channels) { channel = data->trackFactory->NewWaveTrack(format, samplerate); diff --git a/src/import/ImportOGG.cpp b/src/import/ImportOGG.cpp index a9bc28130..587b1c92f 100644 --- a/src/import/ImportOGG.cpp +++ b/src/import/ImportOGG.cpp @@ -42,6 +42,7 @@ #include "../Prefs.h" #include "../Internat.h" #include "../Tags.h" +#include "../prefs/QualityPrefs.h" #define DESC _("Ogg Vorbis files") @@ -108,8 +109,7 @@ public: mVorbisFile(std::move(vorbisFile)) , mStreamUsage{ static_cast(mVorbisFile->links) } { - mFormat = (sampleFormat) - gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleFormat"), floatSample); + mFormat = QualityPrefs::SampleFormatChoice(); for (int i = 0; i < mVorbisFile->links; i++) { diff --git a/src/import/ImportPCM.cpp b/src/import/ImportPCM.cpp index 5af23a99f..bacec2f36 100644 --- a/src/import/ImportPCM.cpp +++ b/src/import/ImportPCM.cpp @@ -38,6 +38,7 @@ #include "../ondemand/ODManager.h" #include "../ondemand/ODComputeSummaryTask.h" +#include "../prefs/QualityPrefs.h" //If OD is enabled, he minimum number of samples a file has to use it. //Otherwise, we use the older PCMAliasBlockFile method since it should be fast enough. @@ -204,8 +205,7 @@ PCMImportFileHandle::PCMImportFileHandle(wxString name, // the quality of the original file. // - mFormat = (sampleFormat) - gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleFormat"), floatSample); + mFormat = QualityPrefs::SampleFormatChoice(); if (mFormat != floatSample && sf_subtype_more_than_16_bits(mInfo.format)) diff --git a/src/import/ImportRaw.cpp b/src/import/ImportRaw.cpp index bad27c063..0981d10d9 100644 --- a/src/import/ImportRaw.cpp +++ b/src/import/ImportRaw.cpp @@ -34,6 +34,7 @@ and sample size to help you importing data of an unknown format. #include "../ShuttleGui.h" #include "../UserException.h" #include "../WaveTrack.h" +#include "../prefs/QualityPrefs.h" #include #include @@ -193,8 +194,7 @@ void ImportRaw(wxWindow *parent, const wxString &fileName, // the quality of the original file. // - format = (sampleFormat) - gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleFormat"), floatSample); + format = QualityPrefs::SampleFormatChoice(); if (format != floatSample && sf_subtype_more_than_16_bits(encoding)) diff --git a/src/ondemand/ODDecodeFlacTask.cpp b/src/ondemand/ODDecodeFlacTask.cpp index a6cade170..d3362d60e 100644 --- a/src/ondemand/ODDecodeFlacTask.cpp +++ b/src/ondemand/ODDecodeFlacTask.cpp @@ -225,8 +225,7 @@ bool ODFlacDecoder::ReadHeader() { mFormat = int16Sample;//start with the smallest and move up in the metadata_callback. //we want to use the native flac type for quick conversion. - /* (sampleFormat) - gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleFormat"), floatSample);*/ + /* QualityPrefs::SampleFormatChoice(); */ mFile = std::make_unique(this); diff --git a/src/prefs/QualityPrefs.cpp b/src/prefs/QualityPrefs.cpp index 9b1ebd927..01a77989d 100644 --- a/src/prefs/QualityPrefs.cpp +++ b/src/prefs/QualityPrefs.cpp @@ -30,6 +30,33 @@ #define ID_SAMPLE_RATE_CHOICE 7001 +////////// + +static const IdentInterfaceSymbol choicesFormat[] = { + { wxT("Format16Bit"), XO("16-bit") }, + { wxT("Format24Bit"), XO("24-bit") }, + { wxT("Format32BitFloat"), XO("32-bit float") } +}; +static const size_t nChoicesFormat = WXSIZEOF( choicesFormat ); +static const int intChoicesFormat[] = { + int16Sample, + int24Sample, + floatSample +}; +static_assert( nChoicesFormat == WXSIZEOF(intChoicesFormat), "size mismatch" ); + +static const size_t defaultChoiceFormat = 2; // floatSample + +static EncodedEnumSetting formatSetting{ + wxT("/SamplingRate/DefaultProjectSampleFormatChoice"), + choicesFormat, nChoicesFormat, defaultChoiceFormat, + + intChoicesFormat, + wxT("/SamplingRate/DefaultProjectSampleFormat"), +}; + +////////// + BEGIN_EVENT_TABLE(QualityPrefs, PrefsPanel) EVT_CHOICE(ID_SAMPLE_RATE_CHOICE, QualityPrefs::OnSampleRateChoice) END_EVENT_TABLE() @@ -102,11 +129,6 @@ void QualityPrefs::GetNamesAndLabels() // The label for the 'Other...' case can be any value at all. mSampleRateLabels.push_back(44100); // If chosen, this value will be overwritten - //------------- Sample Format Names - mSampleFormatNames.Add(wxT("16-bit")); mSampleFormatLabels.push_back(int16Sample); - mSampleFormatNames.Add(wxT("24-bit")); mSampleFormatLabels.push_back(int24Sample); - mSampleFormatNames.Add(wxT("32-bit float")); mSampleFormatLabels.push_back(floatSample); - //------------- Converter Names int numConverters = Resample::GetNumMethods(); for (int i = 0; i < numConverters; i++) { @@ -149,10 +171,7 @@ void QualityPrefs::PopulateOrExchange(ShuttleGui & S) S.EndHorizontalLay(); S.TieChoice(_("Default Sample &Format:"), - wxT("/SamplingRate/DefaultProjectSampleFormat"), - floatSample, - mSampleFormatNames, - mSampleFormatLabels); + formatSetting); } S.EndMultiColumn(); } @@ -239,3 +258,9 @@ PrefsPanel *QualityPrefsFactory::operator () (wxWindow *parent, wxWindowID winid wxASSERT(parent); // to justify safenew return safenew QualityPrefs(parent, winid); } + +sampleFormat QualityPrefs::SampleFormatChoice() +{ + return (sampleFormat)formatSetting.ReadInt(); +} + diff --git a/src/prefs/QualityPrefs.h b/src/prefs/QualityPrefs.h index ecbfed018..b4029e4de 100644 --- a/src/prefs/QualityPrefs.h +++ b/src/prefs/QualityPrefs.h @@ -22,6 +22,7 @@ #include "PrefsPanel.h" class ShuttleGui; +enum sampleFormat : unsigned; class QualityPrefs final : public PrefsPanel { @@ -33,6 +34,8 @@ class QualityPrefs final : public PrefsPanel wxString HelpPageName() override; void PopulateOrExchange(ShuttleGui & S) override; + static sampleFormat SampleFormatChoice(); + private: void Populate(); void GetNamesAndLabels(); @@ -42,8 +45,6 @@ class QualityPrefs final : public PrefsPanel std::vector mDitherLabels; wxArrayString mSampleRateNames; std::vector mSampleRateLabels; - wxArrayString mSampleFormatNames; - std::vector mSampleFormatLabels; wxArrayString mConverterNames; std::vector mConverterLabels;