diff --git a/src/Menus.cpp b/src/Menus.cpp index de87903eb..7a04047da 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -4567,18 +4567,12 @@ bool AudacityProject::DoEffect(const PluginID & ID, const CommandContext &WXUNUS auto nTracksOriginally = GetTrackCount(); TrackListIterator iter(GetTracks()); Track *t = iter.First(); - WaveTrack *newTrack{}; wxWindow *focus = wxWindow::FindFocus(); bool success = false; auto cleanup = finally( [&] { if (!success) { - if (newTrack) { - mTracks->Remove(newTrack); - mTrackPanel->Refresh(false); - } - // For now, we're limiting realtime preview to a single effect, so // make sure the menus reflect that fact that one may have just been // opened. @@ -4587,7 +4581,6 @@ bool AudacityProject::DoEffect(const PluginID & ID, const CommandContext &WXUNUS } ); - //double prevEndTime = mTracks->GetEndTime(); int count = 0; bool clean = true; while (t) { @@ -4598,15 +4591,6 @@ bool AudacityProject::DoEffect(const PluginID & ID, const CommandContext &WXUNUS t = iter.Next(); } - if (count == 0) { - // No tracks were selected... - if (type == EffectTypeGenerate) { - // Create a NEW track for the generated audio... - newTrack = static_cast(mTracks->Add(mTrackFactory->NewWaveTrack())); - newTrack->SetSelected(true); - } - } - EffectManager & em = EffectManager::Get(); success = em.DoEffect(ID, this, mRate, diff --git a/src/effects/Effect.cpp b/src/effects/Effect.cpp index ccb88407d..f1b5e5334 100644 --- a/src/effects/Effect.cpp +++ b/src/effects/Effect.cpp @@ -1172,16 +1172,41 @@ bool Effect::DoEffect(wxWindow *parent, mFactory = factory; mProjectRate = projectRate; mTracks = list; - + + // Update track/group counts + CountWaveTracks(); + bool isSelection = false; mDuration = 0.0; - if (GetType() == EffectTypeGenerate) { GetPrivateConfig(GetCurrentSettingsGroup(), wxT("LastUsedDuration"), mDuration, GetDefaultDuration()); } + WaveTrack *newTrack{}; + bool success = false; + auto oldDuration = mDuration; + + auto cleanup = finally( [&] { + if (!success) { + if (newTrack) { + mTracks->Remove(newTrack); + } + // LastUsedDuration may have been modified by Preview. + SetDuration(oldDuration); + } + + End(); + ReplaceProcessedTracks( false ); + } ); + + wxLogDebug("EFFECT TYPE IS: %s", GetPath()); + if ((GetType() == EffectTypeGenerate) && (mNumTracks == 0) && GetPath() != NYQUIST_EFFECTS_PROMPT_ID) { + newTrack = static_cast(mTracks->Add(mFactory->NewWaveTrack())); + newTrack->SetSelected(true); + } + mT0 = selectedRegion->t0(); mT1 = selectedRegion->t1(); if (mT1 > mT0) @@ -1192,10 +1217,9 @@ bool Effect::DoEffect(wxWindow *parent, double quantMT0 = QUANTIZED_TIME(mT0, mProjectRate); double quantMT1 = QUANTIZED_TIME(mT1, mProjectRate); mDuration = quantMT1 - quantMT0; - mT1 = mT0 + mDuration; - isSelection = true; } + mT1 = mT0 + mDuration; mDurationFormat = isSelection ? NumericConverter::TimeAndSampleFormat() @@ -1228,13 +1252,6 @@ bool Effect::DoEffect(wxWindow *parent, return false; } - auto cleanup = finally( [&] { - End(); - - // In case of failed effect, be sure to free memory. - ReplaceProcessedTracks( false ); - } ); - bool returnVal = true; bool skipFlag = CheckWhetherSkipEffect(); if (skipFlag == false) @@ -1255,6 +1272,7 @@ bool Effect::DoEffect(wxWindow *parent, selectedRegion->setTimes(mT0, mT1); } + success = returnVal; return returnVal; } @@ -2587,7 +2605,6 @@ void Effect::Preview(bool dryOnly) mT1 -= mT0; mT0 = 0.0; - // Update track/group counts CountWaveTracks(); diff --git a/src/effects/nyquist/Nyquist.cpp b/src/effects/nyquist/Nyquist.cpp index d8c47cc17..49f8adc41 100644 --- a/src/effects/nyquist/Nyquist.cpp +++ b/src/effects/nyquist/Nyquist.cpp @@ -565,6 +565,10 @@ bool NyquistEffect::Init() if (!mIsPrompt && !mExternal) { + //TODO: (bugs): + // 1) If there is more than one plug-in with the same name, GetModificationTime may pick the wrong one. + // 2) If the ;type is changed after the effect has been registered, the plug-in will appear in the wrong menu. + //TODO: If we want to auto-add parameters from spectral selection, //we will need to modify this test. //Note that removing it stops the caching of parameter values, @@ -593,8 +597,6 @@ bool NyquistEffect::CheckWhetherSkipEffect() static void RegisterFunctions(); - - bool NyquistEffect::Process() { // Check for reentrant Nyquist commands. @@ -1024,7 +1026,6 @@ bool NyquistEffect::TransferDataFromWindow() { return TransferDataFromPromptWindow(); } - return TransferDataFromEffectWindow(); } diff --git a/src/effects/nyquist/Nyquist.h b/src/effects/nyquist/Nyquist.h index 40df21b0d..3a4f32bcf 100644 --- a/src/effects/nyquist/Nyquist.h +++ b/src/effects/nyquist/Nyquist.h @@ -111,7 +111,7 @@ public: bool SetAutomationParameters(CommandParameters & parms) override; // Effect implementation - + bool Init() override; bool CheckWhetherSkipEffect() override; bool Process() override;