1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-26 09:28:07 +02:00

Eliminate uses of GetActiveProject in src/effects

This commit is contained in:
Paul Licameli 2019-05-21 14:38:43 -04:00
parent e2adccb461
commit 6a0aed3884
8 changed files with 33 additions and 23 deletions

View File

@ -115,8 +115,12 @@ Effect::Effect()
mUIDebug = false; mUIDebug = false;
AudacityProject *p = GetActiveProject(); // PRL: I think this initialization of mProjectRate doesn't matter
mProjectRate = p ? ProjectSettings::Get( *p ).GetRate() : 44100; // because it is always reassigned in DoEffect before it is used
gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"),
&mProjectRate,
AudioIOBase::GetOptimalSupportedSampleRate());
mIsBatch = false; mIsBatch = false;
} }
@ -706,7 +710,7 @@ NumericFormatSymbol Effect::GetDurationFormat()
NumericFormatSymbol Effect::GetSelectionFormat() NumericFormatSymbol Effect::GetSelectionFormat()
{ {
return ProjectSettings::Get( *GetActiveProject() ).GetSelectionFormat(); return ProjectSettings::Get( *FindProject() ).GetSelectionFormat();
} }
void Effect::SetDuration(double seconds) void Effect::SetDuration(double seconds)
@ -1770,7 +1774,7 @@ bool Effect::ProcessTrack(int count,
if (rc && isGenerator) if (rc && isGenerator)
{ {
AudacityProject *p = GetActiveProject(); auto pProject = FindProject();
// PRL: this code was here and could not have been the right // PRL: this code was here and could not have been the right
// intent, mixing time and sampleCount values: // 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 // Transfer the data from the temporary tracks to the actual ones
genLeft->Flush(); genLeft->Flush();
// mT1 gives us the NEW selection. We want to replace up to GetSel1(). // 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, left->ClearAndPaste(mT0,
selectedRegion.t1(), genLeft.get(), true, true, selectedRegion.t1(), genLeft.get(), true, true,
nullptr /* &warper */); nullptr /* &warper */);
@ -2183,6 +2187,11 @@ void Effect::ReplaceProcessedTracks(const bool bGoodResult)
nEffectsDone++; nEffectsDone++;
} }
const AudacityProject *Effect::FindProject() const
{
return inputTracks()->GetOwner();
}
void Effect::CountWaveTracks() void Effect::CountWaveTracks()
{ {
mNumTracks = mTracks->Selected< const WaveTrack >().size(); mNumTracks = mTracks->Selected< const WaveTrack >().size();
@ -2341,7 +2350,7 @@ void Effect::Preview(bool dryOnly)
t1 = std::min(mT0 + previewLen, mT1); t1 = std::min(mT0 + previewLen, mT1);
// Start audio playing // Start audio playing
AudioIOStartStreamOptions options { ::GetActiveProject(), rate }; AudioIOStartStreamOptions options { pProject, rate };
int token = int token =
gAudioIO->StartStream(tracks, mT0, t1, options); gAudioIO->StartStream(tracks, mT0, t1, options);

View File

@ -456,6 +456,7 @@ protected:
wxWeakRef<NotifyingSelectedRegion> mpSelectedRegion{}; wxWeakRef<NotifyingSelectedRegion> mpSelectedRegion{};
TrackFactory *mFactory; TrackFactory *mFactory;
const TrackList *inputTracks() const { return mTracks; } const TrackList *inputTracks() const { return mTracks; }
const AudacityProject *FindProject() const;
std::shared_ptr<TrackList> mOutputTracks; // used only if CopyInputTracks() is called. std::shared_ptr<TrackList> mOutputTracks; // used only if CopyInputTracks() is called.
double mT0; double mT0;
double mT1; double mT1;
@ -477,7 +478,6 @@ protected:
// Used only by the base Effect class // Used only by the base Effect class
// //
private: private:
void CommonInit();
void CountWaveTracks(); void CountWaveTracks();
// Driver for client effects // Driver for client effects

View File

@ -620,7 +620,7 @@ bool EffectEqualization::Init()
double rate = 0.0; double rate = 0.0;
auto trackRange = auto trackRange =
TrackList::Get( *GetActiveProject() ).Selected< const WaveTrack >(); TrackList::Get( *FindProject() ).Selected< const WaveTrack >();
if (trackRange) { if (trackRange) {
rate = (*(trackRange.first++)) -> GetRate(); rate = (*(trackRange.first++)) -> GetRate();
++selcount; ++selcount;
@ -739,7 +739,7 @@ void EffectEqualization::PopulateOrExchange(ShuttleGui & S)
mHiFreq = mHiFreq =
(t (t
? t->GetRate() ? t->GetRate()
: ProjectSettings::Get( *GetActiveProject() ).GetRate()) : ProjectSettings::Get( *FindProject() ).GetRate())
/ 2.0; / 2.0;
mLoFreq = loFreqI; mLoFreq = loFreqI;

View File

@ -62,7 +62,7 @@ bool Generator::Process()
if (GetDuration() > 0.0) if (GetDuration() > 0.0)
{ {
AudacityProject *p = GetActiveProject(); auto pProject = FindProject();
// Create a temporary track // Create a temporary track
WaveTrack::Holder tmp( WaveTrack::Holder tmp(
mFactory->NewWaveTrack(track->GetSampleFormat(), mFactory->NewWaveTrack(track->GetSampleFormat(),
@ -79,7 +79,8 @@ bool Generator::Process()
tmp->Flush(); tmp->Flush();
StepTimeWarper warper{ StepTimeWarper warper{
mT0+GetDuration(), GetDuration()-(mT1-mT0) }; mT0+GetDuration(), GetDuration()-(mT1-mT0) };
const auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion; const auto &selectedRegion =
ViewInfo::Get( *pProject ).selectedRegion;
track->ClearAndPaste( track->ClearAndPaste(
selectedRegion.t0(), selectedRegion.t1(), selectedRegion.t0(), selectedRegion.t1(),
&*tmp, true, false, &warper); &*tmp, true, false, &warper);

View File

@ -334,7 +334,7 @@ bool EffectScienFilter::Init()
mNyquist = mNyquist =
(t (t
? t->GetRate() ? t->GetRate()
: ProjectSettings::Get( *GetActiveProject() ).GetRate()) : ProjectSettings::Get( *FindProject() ).GetRate())
/ 2.0; / 2.0;
} }

View File

@ -266,7 +266,7 @@ bool EffectToneGen::DefineParams( ShuttleParams & S ){
S.SHUTTLE_ENUM_PARAM( mInterpolation, Interp, kInterStrings, nInterpolations ); 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); // mFrequency[1] = TrapDouble(mFrequency[1], MIN_EndFreq, freqMax);
@ -323,8 +323,8 @@ bool EffectToneGen::SetAutomationParameters(CommandParameters & parms)
mInterpolation = Interp; mInterpolation = Interp;
double freqMax = double freqMax =
(GetActiveProject() (FindProject()
? ProjectSettings::Get( *GetActiveProject() ).GetRate() ? ProjectSettings::Get( *FindProject() ).GetRate()
: 44100.0) : 44100.0)
/ 2.0; / 2.0;
mFrequency[1] = TrapDouble(mFrequency[1], MIN_EndFreq, freqMax); mFrequency[1] = TrapDouble(mFrequency[1], MIN_EndFreq, freqMax);
@ -373,7 +373,7 @@ void EffectToneGen::PopulateOrExchange(ShuttleGui & S)
6, &mFrequency[0], 6, &mFrequency[0],
NumValidatorStyle::NO_TRAILING_ZEROES, NumValidatorStyle::NO_TRAILING_ZEROES,
MIN_StartFreq, MIN_StartFreq,
ProjectSettings::Get( *GetActiveProject() ).GetRate() / 2.0 ProjectSettings::Get( *FindProject() ).GetRate() / 2.0
) )
.AddTextBox( {}, wxT(""), 12); .AddTextBox( {}, wxT(""), 12);
} }
@ -386,7 +386,7 @@ void EffectToneGen::PopulateOrExchange(ShuttleGui & S)
6, &mFrequency[1], 6, &mFrequency[1],
NumValidatorStyle::NO_TRAILING_ZEROES, NumValidatorStyle::NO_TRAILING_ZEROES,
MIN_EndFreq, MIN_EndFreq,
ProjectSettings::Get( *GetActiveProject() ).GetRate() / 2.0 ProjectSettings::Get( *FindProject() ).GetRate() / 2.0
) )
.AddTextBox( {}, wxT(""), 12); .AddTextBox( {}, wxT(""), 12);
} }
@ -430,7 +430,7 @@ void EffectToneGen::PopulateOrExchange(ShuttleGui & S)
t = S.Validator<FloatingPointValidator<double>>( t = S.Validator<FloatingPointValidator<double>>(
6, &mFrequency[0], NumValidatorStyle::NO_TRAILING_ZEROES, 6, &mFrequency[0], NumValidatorStyle::NO_TRAILING_ZEROES,
MIN_Frequency, MIN_Frequency,
ProjectSettings::Get( *GetActiveProject() ).GetRate() / 2.0 ProjectSettings::Get( *FindProject() ).GetRate() / 2.0
) )
.AddTextBox(XO("Frequency (Hz):"), wxT(""), 12); .AddTextBox(XO("Frequency (Hz):"), wxT(""), 12);

View File

@ -329,7 +329,7 @@ bool EffectTruncSilence::ProcessIndependently()
{ {
unsigned nGroups = 0; unsigned nGroups = 0;
const auto &settings = ProjectSettings::Get( *::GetActiveProject() ); const auto &settings = ProjectSettings::Get( *FindProject() );
const bool syncLock = settings.IsSyncLocked(); const bool syncLock = settings.IsSyncLocked();
// Check if it's permissible // Check if it's permissible

View File

@ -543,7 +543,7 @@ bool NyquistEffect::Init()
// selected track(s) - (but don't apply to Nyquist Prompt). // selected track(s) - (but don't apply to Nyquist Prompt).
if (!mIsPrompt && mIsSpectral) { if (!mIsPrompt && mIsSpectral) {
AudacityProject *project = GetActiveProject(); auto *project = FindProject();
bool bAllowSpectralEditing = true; bool bAllowSpectralEditing = true;
for ( auto t : for ( auto t :
@ -665,7 +665,7 @@ bool NyquistEffect::Process()
if (mVersion >= 4) if (mVersion >= 4)
{ {
AudacityProject *project = GetActiveProject(); auto project = FindProject();
mProps = wxEmptyString; mProps = wxEmptyString;
@ -957,7 +957,7 @@ finish:
else{ else{
ReplaceProcessedTracks(false); // Do not use the results. ReplaceProcessedTracks(false); // Do not use the results.
// Selection is to be set to whatever it is in the project. // Selection is to be set to whatever it is in the project.
AudacityProject *project = GetActiveProject(); auto project = FindProject();
if (project) { if (project) {
auto &selectedRegion = ViewInfo::Get( *project ).selectedRegion; auto &selectedRegion = ViewInfo::Get( *project ).selectedRegion;
mT0 = selectedRegion.t0(); 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 * parsed on each run so that the correct value for "half-srate" may
* be determined. * be determined.
* *
AudacityProject *project = GetActiveProject(); auto project = FindProject();
if (project && s.IsSameAs(wxT("half-srate"), false)) { if (project && s.IsSameAs(wxT("half-srate"), false)) {
auto rate = auto rate =
TrackList::Get( *project ).Selected< const WaveTrack >() TrackList::Get( *project ).Selected< const WaveTrack >()