diff --git a/src/effects/Effect.cpp b/src/effects/Effect.cpp index 41b2b853d..16feab557 100644 --- a/src/effects/Effect.cpp +++ b/src/effects/Effect.cpp @@ -115,8 +115,12 @@ Effect::Effect() mUIDebug = false; - AudacityProject *p = GetActiveProject(); - mProjectRate = p ? ProjectSettings::Get( *p ).GetRate() : 44100; + // PRL: I think this initialization of mProjectRate doesn't matter + // because it is always reassigned in DoEffect before it is used + gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"), + &mProjectRate, + AudioIOBase::GetOptimalSupportedSampleRate()); + mIsBatch = false; } @@ -706,7 +710,7 @@ NumericFormatSymbol Effect::GetDurationFormat() NumericFormatSymbol Effect::GetSelectionFormat() { - return ProjectSettings::Get( *GetActiveProject() ).GetSelectionFormat(); + return ProjectSettings::Get( *FindProject() ).GetSelectionFormat(); } void Effect::SetDuration(double seconds) @@ -1770,7 +1774,7 @@ bool Effect::ProcessTrack(int count, if (rc && isGenerator) { - AudacityProject *p = GetActiveProject(); + auto pProject = FindProject(); // PRL: this code was here and could not have been the right // intent, mixing time and sampleCount values: @@ -1790,7 +1794,7 @@ bool Effect::ProcessTrack(int count, // Transfer the data from the temporary tracks to the actual ones genLeft->Flush(); // mT1 gives us the NEW selection. We want to replace up to GetSel1(). - auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion; + auto &selectedRegion = ViewInfo::Get( *pProject ).selectedRegion; left->ClearAndPaste(mT0, selectedRegion.t1(), genLeft.get(), true, true, nullptr /* &warper */); @@ -2183,6 +2187,11 @@ void Effect::ReplaceProcessedTracks(const bool bGoodResult) nEffectsDone++; } +const AudacityProject *Effect::FindProject() const +{ + return inputTracks()->GetOwner(); +} + void Effect::CountWaveTracks() { mNumTracks = mTracks->Selected< const WaveTrack >().size(); @@ -2341,7 +2350,7 @@ void Effect::Preview(bool dryOnly) t1 = std::min(mT0 + previewLen, mT1); // Start audio playing - AudioIOStartStreamOptions options { ::GetActiveProject(), rate }; + AudioIOStartStreamOptions options { pProject, rate }; int token = gAudioIO->StartStream(tracks, mT0, t1, options); diff --git a/src/effects/Effect.h b/src/effects/Effect.h index 7bfa1c7f8..b68edb2f1 100644 --- a/src/effects/Effect.h +++ b/src/effects/Effect.h @@ -456,6 +456,7 @@ protected: wxWeakRef mpSelectedRegion{}; TrackFactory *mFactory; const TrackList *inputTracks() const { return mTracks; } + const AudacityProject *FindProject() const; std::shared_ptr mOutputTracks; // used only if CopyInputTracks() is called. double mT0; double mT1; @@ -477,7 +478,6 @@ protected: // Used only by the base Effect class // private: - void CommonInit(); void CountWaveTracks(); // Driver for client effects diff --git a/src/effects/Equalization.cpp b/src/effects/Equalization.cpp index 996fc62e4..cbea44915 100644 --- a/src/effects/Equalization.cpp +++ b/src/effects/Equalization.cpp @@ -620,7 +620,7 @@ bool EffectEqualization::Init() double rate = 0.0; auto trackRange = - TrackList::Get( *GetActiveProject() ).Selected< const WaveTrack >(); + TrackList::Get( *FindProject() ).Selected< const WaveTrack >(); if (trackRange) { rate = (*(trackRange.first++)) -> GetRate(); ++selcount; @@ -739,7 +739,7 @@ void EffectEqualization::PopulateOrExchange(ShuttleGui & S) mHiFreq = (t ? t->GetRate() - : ProjectSettings::Get( *GetActiveProject() ).GetRate()) + : ProjectSettings::Get( *FindProject() ).GetRate()) / 2.0; mLoFreq = loFreqI; diff --git a/src/effects/Generator.cpp b/src/effects/Generator.cpp index 5be73c8ed..ff0064798 100644 --- a/src/effects/Generator.cpp +++ b/src/effects/Generator.cpp @@ -62,7 +62,7 @@ bool Generator::Process() if (GetDuration() > 0.0) { - AudacityProject *p = GetActiveProject(); + auto pProject = FindProject(); // Create a temporary track WaveTrack::Holder tmp( mFactory->NewWaveTrack(track->GetSampleFormat(), @@ -79,7 +79,8 @@ bool Generator::Process() tmp->Flush(); StepTimeWarper warper{ mT0+GetDuration(), GetDuration()-(mT1-mT0) }; - const auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion; + const auto &selectedRegion = + ViewInfo::Get( *pProject ).selectedRegion; track->ClearAndPaste( selectedRegion.t0(), selectedRegion.t1(), &*tmp, true, false, &warper); diff --git a/src/effects/ScienFilter.cpp b/src/effects/ScienFilter.cpp index adc6735ec..4aa76b7e8 100644 --- a/src/effects/ScienFilter.cpp +++ b/src/effects/ScienFilter.cpp @@ -334,7 +334,7 @@ bool EffectScienFilter::Init() mNyquist = (t ? t->GetRate() - : ProjectSettings::Get( *GetActiveProject() ).GetRate()) + : ProjectSettings::Get( *FindProject() ).GetRate()) / 2.0; } diff --git a/src/effects/ToneGen.cpp b/src/effects/ToneGen.cpp index 94b2e393a..102e70eb4 100644 --- a/src/effects/ToneGen.cpp +++ b/src/effects/ToneGen.cpp @@ -266,7 +266,7 @@ bool EffectToneGen::DefineParams( ShuttleParams & S ){ S.SHUTTLE_ENUM_PARAM( mInterpolation, Interp, kInterStrings, nInterpolations ); -// double freqMax = (GetActiveProject() ? GetActiveProject()->GetRate() : 44100.0) / 2.0; +// double freqMax = (FindProject() ? FindProject()->GetRate() : 44100.0) / 2.0; // mFrequency[1] = TrapDouble(mFrequency[1], MIN_EndFreq, freqMax); @@ -323,8 +323,8 @@ bool EffectToneGen::SetAutomationParameters(CommandParameters & parms) mInterpolation = Interp; double freqMax = - (GetActiveProject() - ? ProjectSettings::Get( *GetActiveProject() ).GetRate() + (FindProject() + ? ProjectSettings::Get( *FindProject() ).GetRate() : 44100.0) / 2.0; mFrequency[1] = TrapDouble(mFrequency[1], MIN_EndFreq, freqMax); @@ -373,7 +373,7 @@ void EffectToneGen::PopulateOrExchange(ShuttleGui & S) 6, &mFrequency[0], NumValidatorStyle::NO_TRAILING_ZEROES, MIN_StartFreq, - ProjectSettings::Get( *GetActiveProject() ).GetRate() / 2.0 + ProjectSettings::Get( *FindProject() ).GetRate() / 2.0 ) .AddTextBox( {}, wxT(""), 12); } @@ -386,7 +386,7 @@ void EffectToneGen::PopulateOrExchange(ShuttleGui & S) 6, &mFrequency[1], NumValidatorStyle::NO_TRAILING_ZEROES, MIN_EndFreq, - ProjectSettings::Get( *GetActiveProject() ).GetRate() / 2.0 + ProjectSettings::Get( *FindProject() ).GetRate() / 2.0 ) .AddTextBox( {}, wxT(""), 12); } @@ -430,7 +430,7 @@ void EffectToneGen::PopulateOrExchange(ShuttleGui & S) t = S.Validator>( 6, &mFrequency[0], NumValidatorStyle::NO_TRAILING_ZEROES, MIN_Frequency, - ProjectSettings::Get( *GetActiveProject() ).GetRate() / 2.0 + ProjectSettings::Get( *FindProject() ).GetRate() / 2.0 ) .AddTextBox(XO("Frequency (Hz):"), wxT(""), 12); diff --git a/src/effects/TruncSilence.cpp b/src/effects/TruncSilence.cpp index 1d4f8ac2f..a2cba89c4 100644 --- a/src/effects/TruncSilence.cpp +++ b/src/effects/TruncSilence.cpp @@ -329,7 +329,7 @@ bool EffectTruncSilence::ProcessIndependently() { unsigned nGroups = 0; - const auto &settings = ProjectSettings::Get( *::GetActiveProject() ); + const auto &settings = ProjectSettings::Get( *FindProject() ); const bool syncLock = settings.IsSyncLocked(); // Check if it's permissible diff --git a/src/effects/nyquist/Nyquist.cpp b/src/effects/nyquist/Nyquist.cpp index 1e53463a5..7ac052607 100644 --- a/src/effects/nyquist/Nyquist.cpp +++ b/src/effects/nyquist/Nyquist.cpp @@ -543,7 +543,7 @@ bool NyquistEffect::Init() // selected track(s) - (but don't apply to Nyquist Prompt). if (!mIsPrompt && mIsSpectral) { - AudacityProject *project = GetActiveProject(); + auto *project = FindProject(); bool bAllowSpectralEditing = true; for ( auto t : @@ -665,7 +665,7 @@ bool NyquistEffect::Process() if (mVersion >= 4) { - AudacityProject *project = GetActiveProject(); + auto project = FindProject(); mProps = wxEmptyString; @@ -957,7 +957,7 @@ finish: else{ ReplaceProcessedTracks(false); // Do not use the results. // Selection is to be set to whatever it is in the project. - AudacityProject *project = GetActiveProject(); + auto project = FindProject(); if (project) { auto &selectedRegion = ViewInfo::Get( *project ).selectedRegion; mT0 = selectedRegion.t0(); @@ -1693,7 +1693,7 @@ double NyquistEffect::GetCtrlValue(const wxString &s) * parsed on each run so that the correct value for "half-srate" may * be determined. * - AudacityProject *project = GetActiveProject(); + auto project = FindProject(); if (project && s.IsSameAs(wxT("half-srate"), false)) { auto rate = TrackList::Get( *project ).Selected< const WaveTrack >()