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;
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);

View File

@ -456,6 +456,7 @@ protected:
wxWeakRef<NotifyingSelectedRegion> mpSelectedRegion{};
TrackFactory *mFactory;
const TrackList *inputTracks() const { return mTracks; }
const AudacityProject *FindProject() const;
std::shared_ptr<TrackList> 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

View File

@ -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;

View File

@ -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);

View File

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

View File

@ -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<FloatingPointValidator<double>>(
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);

View File

@ -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

View File

@ -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 >()