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

Rewrite the path through NyquistEffect, in the case that...

... you use the prompt, and you enter a complete script with control comments
that are reinterpreted to put up a second dialog.

This simplifies Effect::Delegate() and avoids mutual recursion of ShowInterface
with DoEffect.
This commit is contained in:
Paul Licameli 2020-01-08 15:39:27 -05:00
parent e8c8db8b33
commit 66fd95f3d6
6 changed files with 27 additions and 26 deletions

View File

@ -215,7 +215,7 @@ bool EffectChangePitch::Process()
proxy.mProxyEffectName = XO("High Quality Pitch Change"); proxy.mProxyEffectName = XO("High Quality Pitch Change");
proxy.setParameters(1.0, pitchRatio); proxy.setParameters(1.0, pitchRatio);
return Delegate(proxy, *mUIParent, nullptr); return Delegate( proxy );
} }
else else
#endif #endif

View File

@ -200,7 +200,7 @@ bool EffectChangeTempo::Process()
EffectSBSMS proxy; EffectSBSMS proxy;
proxy.mProxyEffectName = XO("High Quality Tempo Change"); proxy.mProxyEffectName = XO("High Quality Tempo Change");
proxy.setParameters(tempoRatio, 1.0); proxy.setParameters(tempoRatio, 1.0);
success = Delegate(proxy, *mUIParent, nullptr); success = Delegate( proxy );
} }
else else
#endif #endif

View File

@ -1218,14 +1218,13 @@ bool Effect::DoEffect(double projectRate,
return returnVal; return returnVal;
} }
bool Effect::Delegate( bool Effect::Delegate( Effect &delegate )
Effect &delegate, wxWindow &parent, const EffectDialogFactory &factory )
{ {
NotifyingSelectedRegion region; NotifyingSelectedRegion region;
region.setTimes( mT0, mT1 ); region.setTimes( mT0, mT1 );
return delegate.DoEffect( mProjectRate, mTracks, mFactory, return delegate.DoEffect(
region, &parent, factory ); mProjectRate, mTracks, mFactory, region );
} }
// All legacy effects should have this overridden // All legacy effects should have this overridden

View File

@ -261,8 +261,7 @@ class AUDACITY_DLL_API Effect /* not final */ : public wxEvtHandler,
wxWindow *pParent = nullptr, wxWindow *pParent = nullptr,
const EffectDialogFactory &dialogFactory = {} ); const EffectDialogFactory &dialogFactory = {} );
bool Delegate( Effect &delegate, bool Delegate( Effect &delegate );
wxWindow &parent, const EffectDialogFactory &factory );
virtual bool IsHidden(); virtual bool IsHidden();

View File

@ -523,6 +523,8 @@ bool NyquistEffect::SetAutomationParameters(CommandParameters & parms)
bool NyquistEffect::Init() bool NyquistEffect::Init()
{ {
mDelegate.reset();
// When Nyquist Prompt spawns an effect GUI, Init() is called for Nyquist Prompt, // When Nyquist Prompt spawns an effect GUI, Init() is called for Nyquist Prompt,
// and then again for the spawned (mExternal) effect. // and then again for the spawned (mExternal) effect.
@ -596,17 +598,21 @@ bool NyquistEffect::Init()
return true; return true;
} }
bool NyquistEffect::CheckWhetherSkipEffect()
{
// If we're a prompt and we have controls, then we've already processed
// the audio, so skip further processing.
return (mIsPrompt && mControls.size() > 0);
}
static void RegisterFunctions(); static void RegisterFunctions();
bool NyquistEffect::Process() bool NyquistEffect::Process()
{ {
if (mDelegate)
{
mProgress->Hide();
auto &effect = *mDelegate;
auto result = Delegate( effect );
mT0 = effect.mT0;
mT1 = effect.mT1;
mDelegate.reset();
return result;
}
// Check for reentrant Nyquist commands. // Check for reentrant Nyquist commands.
// I'm choosing to mark skipped Nyquist commands as successful even though // I'm choosing to mark skipped Nyquist commands as successful even though
// they are skipped. The reason is that when Nyquist calls out to a chain, // they are skipped. The reason is that when Nyquist calls out to a chain,
@ -626,10 +632,6 @@ bool NyquistEffect::Process()
EffectManager & em = EffectManager::Get(); EffectManager & em = EffectManager::Get();
em.SetSkipStateFlag(false); em.SetSkipStateFlag(false);
if (mExternal) {
mProgress->Hide();
}
mOutputTime = 0; mOutputTime = 0;
mCount = 0; mCount = 0;
mProgressIn = 0; mProgressIn = 0;
@ -992,14 +994,14 @@ bool NyquistEffect::ShowInterface(
return res; return res;
} }
NyquistEffect effect(NYQUIST_WORKER_ID); // Come here only in case the user entered a script into the Nyquist
// prompt window that included the magic comments that specify controls.
// Interpret those comments and put up a second dialog.
mDelegate = std::make_unique< NyquistEffect >( NYQUIST_WORKER_ID );
auto &effect = *mDelegate;
effect.SetCommand(mInputCmd); effect.SetCommand(mInputCmd);
effect.mDebug = (mUIResultID == eDebugID); effect.mDebug = (mUIResultID == eDebugID);
bool result = Delegate(effect, parent, factory); return effect.ShowInterface( parent, factory, forceModal );
mT0 = effect.mT0;
mT1 = effect.mT1;
return result;
} }
void NyquistEffect::PopulateOrExchange(ShuttleGui & S) void NyquistEffect::PopulateOrExchange(ShuttleGui & S)

View File

@ -97,7 +97,6 @@ public:
// Effect implementation // Effect implementation
bool Init() override; bool Init() override;
bool CheckWhetherSkipEffect() override;
bool Process() override; bool Process() override;
bool ShowInterface( wxWindow &parent, bool ShowInterface( wxWindow &parent,
const EffectDialogFactory &factory, bool forceModal = false) override; const EffectDialogFactory &factory, bool forceModal = false) override;
@ -189,6 +188,8 @@ private:
private: private:
std::unique_ptr<NyquistEffect> mDelegate;
wxString mXlispPath; wxString mXlispPath;
wxFileName mFileName; ///< Name of the Nyquist script file this effect is loaded from wxFileName mFileName; ///< Name of the Nyquist script file this effect is loaded from