diff --git a/lib-src/mod-nyq-bench/NyqBench.cpp b/lib-src/mod-nyq-bench/NyqBench.cpp index 3cd8bb225..6ecad8a0e 100755 --- a/lib-src/mod-nyq-bench/NyqBench.cpp +++ b/lib-src/mod-nyq-bench/NyqBench.cpp @@ -31,6 +31,7 @@ #include "Project.h" #include "ShuttleGui.h" #include "effects/EffectManager.h" +#include "effects/EffectUI.h" #include "effects/nyquist/Nyquist.h" #include "../images/AudacityLogo.xpm" #include "../../src/commands/CommandContext.h" @@ -1403,7 +1404,7 @@ void NyqBench::OnGo(wxCommandEvent & e) mRunning = true; UpdateWindowUI(); - EffectManager::DoEffect(ID, CommandContext(*p), 0); + EffectUI::DoEffect(ID, CommandContext(*p), 0); mRunning = false; UpdateWindowUI(); diff --git a/src/BatchCommands.cpp b/src/BatchCommands.cpp index f39441fd5..cc8278199 100644 --- a/src/BatchCommands.cpp +++ b/src/BatchCommands.cpp @@ -796,7 +796,7 @@ bool MacroCommands::ApplyEffectCommand( EffectManager::kDontRepeatLast); else // and apply the effect... - res = EffectManager::DoEffect(ID, + res = EffectUI::DoEffect(ID, Context, EffectManager::kConfigured | EffectManager::kSkipState | @@ -831,7 +831,7 @@ bool MacroCommands::HandleTextualCommand( CommandManager &commandManager, { if (em.GetCommandIdentifier(plug->GetID()) == Str) { - return EffectManager::DoEffect( + return EffectUI::DoEffect( plug->GetID(), context, EffectManager::kConfigured); } diff --git a/src/effects/EffectManager.cpp b/src/effects/EffectManager.cpp index 1d1fe3dc7..da426e795 100644 --- a/src/effects/EffectManager.cpp +++ b/src/effects/EffectManager.cpp @@ -91,14 +91,13 @@ void EffectManager::UnregisterEffect(const PluginID & ID) mEffects.erase(id); } -/// DoEffect() takes a PluginID and has the EffectManager execute the associated -/// effect. +/// DoEffect() takes a PluginID and executes the associated effect. /// /// At the moment flags are used only to indicate whether to prompt for // parameters, whether to save the state to history and whether to allow /// 'Repeat Last Effect'. -/* static */ bool EffectManager::DoEffect( +/* static */ bool EffectUI::DoEffect( const PluginID & ID, const CommandContext &context, unsigned flags ) { AudacityProject &project = context.project; @@ -157,9 +156,26 @@ void EffectManager::UnregisterEffect(const PluginID & ID) EffectManager & em = EffectManager::Get(); - success = em.DoEffect(ID, &window, context.project, rate, - &tracks, &trackFactory, selectedRegion, - (flags & EffectManager::kConfigured) == 0); + em.SetSkipStateFlag( false ); + if (auto effect = em.GetEffect(ID)) { +#if defined(EXPERIMENTAL_EFFECTS_RACK) + if (effect->SupportsRealtime()) + { + EffectRack::Get( context.project ).Add(effect); + } +#endif + success = effect->DoEffect(&window, + rate, + &tracks, + &trackFactory, + selectedRegion, + (flags & EffectManager::kConfigured) == 0 + ? DialogFactory + : nullptr + ); + } + else + success = false; if (!success) return false; @@ -227,43 +243,6 @@ void EffectManager::UnregisterEffect(const PluginID & ID) return true; } -bool EffectManager::DoEffect(const PluginID & ID, - wxWindow *parent, - AudacityProject &project, - double projectRate, - TrackList *list, - TrackFactory *trackFactory, - NotifyingSelectedRegion &selectedRegion, - bool shouldPrompt /* = true */) - -{ - this->SetSkipStateFlag(false); - Effect *effect = GetEffect(ID); - - if (!effect) - { - return false; - } - -#if defined(EXPERIMENTAL_EFFECTS_RACK) - if (effect->SupportsRealtime()) - { - EffectRack::Get( project ).Add(effect); - } -#else - (void)project; -#endif - - bool res = effect->DoEffect( parent, - projectRate, - list, - trackFactory, - selectedRegion, - shouldPrompt ? EffectUI::DialogFactory : nullptr ); - - return res; -} - bool EffectManager::DoAudacityCommand(const PluginID & ID, const CommandContext &context, wxWindow *parent, diff --git a/src/effects/EffectManager.h b/src/effects/EffectManager.h index 12264feab..d206971ab 100644 --- a/src/effects/EffectManager.h +++ b/src/effects/EffectManager.h @@ -71,9 +71,6 @@ public: // them by index number, usually when the user selects one from a menu. // public: - static bool DoEffect( - const PluginID & ID, const CommandContext &context, unsigned flags ); - EffectManager(); virtual ~EffectManager(); @@ -83,19 +80,6 @@ public: const PluginID & RegisterEffect(Effect *f); void UnregisterEffect(const PluginID & ID); - /** Run an effect given the plugin ID */ - // Returns true on success. Will only operate on tracks that - // have the "selected" flag set to true, which is consistent with - // Audacity's standard UI. - bool DoEffect(const PluginID & ID, - wxWindow *parent, - AudacityProject &project, - double projectRate, - TrackList *list, - TrackFactory *factory, - NotifyingSelectedRegion &selectedRegion, - bool shouldPrompt = true); - TranslatableString GetEffectFamilyName(const PluginID & ID); TranslatableString GetVendorName(const PluginID & ID); @@ -150,12 +134,12 @@ public: const PluginID & GetEffectByIdentifier(const CommandID & strTarget); -private: /** Return an effect by its ID. */ Effect *GetEffect(const PluginID & ID); - AudacityCommand *GetAudacityCommand(const PluginID & ID); private: + AudacityCommand *GetAudacityCommand(const PluginID & ID); + EffectMap mEffects; AudacityCommandMap mCommands; EffectOwnerMap mHostEffects; diff --git a/src/effects/EffectUI.cpp b/src/effects/EffectUI.cpp index e938b132b..874e8441c 100644 --- a/src/effects/EffectUI.cpp +++ b/src/effects/EffectUI.cpp @@ -310,7 +310,7 @@ void EffectRack::OnApply(wxCommandEvent & WXUNUSED(evt)) { if (mPowerState[i]) { - if (!EffectManager::DoEffect(mEffects[i]->GetID(), + if (!EffectUI::DoEffect(mEffects[i]->GetID(), *project, EffectManager::kConfigured)) // If any effect fails (or throws), then stop. @@ -1195,7 +1195,7 @@ void EffectUIHost::OnApply(wxCommandEvent & evt) // This is absolute hackage...but easy and I can't think of another way just now. // // It should callback to the EffectManager to kick off the processing - EffectManager::DoEffect(mEffect->GetID(), context, + EffectUI::DoEffect(mEffect->GetID(), context, EffectManager::kConfigured); } diff --git a/src/effects/EffectUI.h b/src/effects/EffectUI.h index 27ae66dfc..36e262ec3 100644 --- a/src/effects/EffectUI.h +++ b/src/effects/EffectUI.h @@ -212,9 +212,20 @@ private: DECLARE_EVENT_TABLE() }; +struct CommandContext; + namespace EffectUI { + wxDialog *DialogFactory( wxWindow *parent, EffectHostInterface *pHost, EffectUIClientInterface *client); + + /** Run an effect given the plugin ID */ + // Returns true on success. Will only operate on tracks that + // have the "selected" flag set to true, which is consistent with + // Audacity's standard UI. + bool DoEffect( + const PluginID & ID, const CommandContext &context, unsigned flags ); + } #endif // __AUDACITY_EFFECTUI_H__ diff --git a/src/effects/lv2/LoadLV2.cpp b/src/effects/lv2/LoadLV2.cpp index 55f5c4a5a..16a8c8c3b 100755 --- a/src/effects/lv2/LoadLV2.cpp +++ b/src/effects/lv2/LoadLV2.cpp @@ -34,7 +34,6 @@ Functions that find and load all LV2 plugins on the system. #include #include -#include "../EffectManager.h" #include "../../Internat.h" #include "LV2Effect.h" diff --git a/src/menus/PluginMenus.cpp b/src/menus/PluginMenus.cpp index 6d3895894..cccd769ef 100644 --- a/src/menus/PluginMenus.cpp +++ b/src/menus/PluginMenus.cpp @@ -17,6 +17,7 @@ #include "../commands/ScreenshotCommand.h" #include "../effects/Contrast.h" #include "../effects/EffectManager.h" +#include "../effects/EffectUI.h" #include "../effects/RealtimeEffectManager.h" #include "../prefs/EffectsPrefs.h" @@ -423,7 +424,7 @@ void OnManageGenerators(const CommandContext &context) void OnEffect(const CommandContext &context) { // using GET to interpret parameter as a PluginID - EffectManager::DoEffect(context.parameter.GET(), context, 0); + EffectUI::DoEffect(context.parameter.GET(), context, 0); } void OnManageEffects(const CommandContext &context) @@ -437,7 +438,7 @@ void OnRepeatLastEffect(const CommandContext &context) auto lastEffect = MenuManager::Get(context.project).mLastEffect; if (!lastEffect.empty()) { - EffectManager::DoEffect( + EffectUI::DoEffect( lastEffect, context, EffectManager::kConfigured ); } } diff --git a/src/menus/TrackMenus.cpp b/src/menus/TrackMenus.cpp index d497e626c..496fcddfb 100644 --- a/src/menus/TrackMenus.cpp +++ b/src/menus/TrackMenus.cpp @@ -28,6 +28,7 @@ #include "../commands/CommandContext.h" #include "../commands/CommandManager.h" #include "../effects/EffectManager.h" +#include "../effects/EffectUI.h" #include "../tracks/playabletrack/wavetrack/ui/WaveTrackControls.h" #include "../widgets/ASlider.h" #include "../widgets/AudacityMessageBox.h" @@ -688,7 +689,7 @@ void OnNewTimeTrack(const CommandContext &context) void OnStereoToMono(const CommandContext &context) { - EffectManager::DoEffect( + EffectUI::DoEffect( EffectManager::Get().GetEffectByIdentifier(wxT("StereoToMono")), context, EffectManager::kConfigured);