mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-11 22:27:42 +02:00
Eliminate GetActiveProject in EffectUI.cpp, with some behavior changes
This commit is contained in:
commit
79bc14b2cf
@ -142,7 +142,8 @@ class AUDACITY_DLL_API EffectClientInterface /* not final */ : public EffectDef
|
||||
{
|
||||
public:
|
||||
using EffectDialogFactory = std::function<
|
||||
wxDialog* ( wxWindow*, EffectHostInterface*, EffectUIClientInterface* )
|
||||
wxDialog* ( wxWindow &parent,
|
||||
EffectHostInterface*, EffectUIClientInterface* )
|
||||
>;
|
||||
|
||||
virtual ~EffectClientInterface() {};
|
||||
@ -179,7 +180,7 @@ public:
|
||||
virtual bool RealtimeProcessEnd() = 0;
|
||||
|
||||
virtual bool ShowInterface(
|
||||
wxWindow *parent, const EffectDialogFactory &factory,
|
||||
wxWindow &parent, const EffectDialogFactory &factory,
|
||||
bool forceModal = false
|
||||
) = 0;
|
||||
// Some effects will use define params to define what parameters they take.
|
||||
|
@ -218,7 +218,7 @@ void MacroCommandDialog::OnEditParams(wxCommandEvent & WXUNUSED(event))
|
||||
auto command = mInternalCommandName;
|
||||
wxString params = mParameters->GetValue();
|
||||
|
||||
params = MacroCommands::PromptForParamsFor(command, params, this).Trim();
|
||||
params = MacroCommands::PromptForParamsFor(command, params, *this).Trim();
|
||||
|
||||
mParameters->SetValue(params);
|
||||
mParameters->Refresh();
|
||||
|
@ -438,7 +438,8 @@ wxString MacroCommands::GetCurrentParamsFor(const CommandID & command)
|
||||
return EffectManager::Get().GetEffectParameters(ID);
|
||||
}
|
||||
|
||||
wxString MacroCommands::PromptForParamsFor(const CommandID & command, const wxString & params, wxWindow *parent)
|
||||
wxString MacroCommands::PromptForParamsFor(
|
||||
const CommandID & command, const wxString & params, wxWindow &parent)
|
||||
{
|
||||
const PluginID & ID =
|
||||
EffectManager::Get().GetEffectByIdentifier(command);
|
||||
|
@ -95,7 +95,8 @@ class MacroCommands final {
|
||||
static wxArrayStringEx GetNamesOfDefaultMacros();
|
||||
|
||||
static wxString GetCurrentParamsFor(const CommandID & command);
|
||||
static wxString PromptForParamsFor(const CommandID & command, const wxString & params, wxWindow *parent);
|
||||
static wxString PromptForParamsFor(
|
||||
const CommandID & command, const wxString & params, wxWindow &parent);
|
||||
static wxString PromptForPresetFor(const CommandID & command, const wxString & params, wxWindow *parent);
|
||||
|
||||
// These commands do depend on the command list.
|
||||
|
@ -1104,7 +1104,7 @@ void MacrosWindow::OnEditCommandParams(wxCommandEvent & WXUNUSED(event))
|
||||
auto command = mMacroCommands.GetCommand(item);
|
||||
wxString params = mMacroCommands.GetParams(item);
|
||||
|
||||
params = MacroCommands::PromptForParamsFor(command, params, this).Trim();
|
||||
params = MacroCommands::PromptForParamsFor(command, params, *this).Trim();
|
||||
Raise();
|
||||
|
||||
mMacroCommands.DeleteFromMacro(item);
|
||||
|
@ -215,7 +215,7 @@ bool EffectChangePitch::Process()
|
||||
proxy.mProxyEffectName = XO("High Quality Pitch Change");
|
||||
proxy.setParameters(1.0, pitchRatio);
|
||||
|
||||
return Delegate(proxy, mUIParent, nullptr);
|
||||
return Delegate(proxy, *mUIParent, nullptr);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
@ -200,7 +200,7 @@ bool EffectChangeTempo::Process()
|
||||
EffectSBSMS proxy;
|
||||
proxy.mProxyEffectName = XO("High Quality Tempo Change");
|
||||
proxy.setParameters(tempoRatio, 1.0);
|
||||
success = Delegate(proxy, mUIParent, nullptr);
|
||||
success = Delegate(proxy, *mUIParent, nullptr);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
@ -478,7 +478,7 @@ bool Effect::RealtimeProcessEnd()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Effect::ShowInterface(wxWindow *parent,
|
||||
bool Effect::ShowInterface(wxWindow &parent,
|
||||
const EffectDialogFactory &factory, bool forceModal)
|
||||
{
|
||||
if (!IsInteractive())
|
||||
@ -1091,7 +1091,7 @@ void Effect::SetBatchProcessing(bool start)
|
||||
}
|
||||
}
|
||||
|
||||
bool Effect::DoEffect(wxWindow *parent,
|
||||
bool Effect::DoEffect(wxWindow &parent,
|
||||
double projectRate,
|
||||
TrackList *list,
|
||||
TrackFactory *factory,
|
||||
@ -1214,7 +1214,7 @@ bool Effect::DoEffect(wxWindow *parent,
|
||||
}
|
||||
|
||||
bool Effect::Delegate(
|
||||
Effect &delegate, wxWindow *parent, const EffectDialogFactory &factory )
|
||||
Effect &delegate, wxWindow &parent, const EffectDialogFactory &factory )
|
||||
{
|
||||
NotifyingSelectedRegion region;
|
||||
region.setTimes( mT0, mT1 );
|
||||
|
@ -142,7 +142,7 @@ class AUDACITY_DLL_API Effect /* not final */ : public wxEvtHandler,
|
||||
size_t numSamples) override;
|
||||
bool RealtimeProcessEnd() override;
|
||||
|
||||
bool ShowInterface( wxWindow *parent,
|
||||
bool ShowInterface( wxWindow &parent,
|
||||
const EffectDialogFactory &factory, bool forceModal = false) override;
|
||||
|
||||
bool GetAutomationParameters(CommandParameters & parms) override;
|
||||
@ -255,12 +255,12 @@ class AUDACITY_DLL_API Effect /* not final */ : public wxEvtHandler,
|
||||
// have the "selected" flag set to true, which is consistent with
|
||||
// Audacity's standard UI.
|
||||
// Create a user interface only if the supplied function is not null.
|
||||
/* not virtual */ bool DoEffect(wxWindow *parent, double projectRate, TrackList *list,
|
||||
/* not virtual */ bool DoEffect(wxWindow &parent, double projectRate, TrackList *list,
|
||||
TrackFactory *factory, NotifyingSelectedRegion &selectedRegion,
|
||||
const EffectDialogFactory &dialogFactory );
|
||||
|
||||
bool Delegate( Effect &delegate,
|
||||
wxWindow *parent, const EffectDialogFactory &factory );
|
||||
wxWindow &parent, const EffectDialogFactory &factory );
|
||||
|
||||
virtual bool IsHidden();
|
||||
|
||||
|
@ -326,7 +326,7 @@ bool EffectManager::SetEffectParameters(const PluginID & ID, const wxString & pa
|
||||
|
||||
bool EffectManager::PromptUser(
|
||||
const PluginID & ID,
|
||||
const EffectClientInterface::EffectDialogFactory &factory, wxWindow *parent)
|
||||
const EffectClientInterface::EffectDialogFactory &factory, wxWindow &parent)
|
||||
{
|
||||
bool result = false;
|
||||
Effect *effect = GetEffect(ID);
|
||||
@ -342,7 +342,7 @@ bool EffectManager::PromptUser(
|
||||
|
||||
if (command)
|
||||
{
|
||||
result = command->PromptUser(parent);
|
||||
result = command->PromptUser(&parent);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ public:
|
||||
bool SetEffectParameters(const PluginID & ID, const wxString & params);
|
||||
bool PromptUser( const PluginID & ID,
|
||||
const EffectClientInterface::EffectDialogFactory &factory,
|
||||
wxWindow *parent );
|
||||
wxWindow &parent );
|
||||
bool HasPresets(const PluginID & ID);
|
||||
wxString GetPreset(const PluginID & ID, const wxString & params, wxWindow * parent);
|
||||
wxString GetDefaultPreset(const PluginID & ID);
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "Effect.h"
|
||||
#include "EffectManager.h"
|
||||
#include "../ProjectHistory.h"
|
||||
#include "../ProjectWindowBase.h"
|
||||
#include "../TrackPanelAx.h"
|
||||
#include "RealtimeEffectManager.h"
|
||||
|
||||
@ -377,7 +378,7 @@ void EffectRack::OnEditor(wxCommandEvent & evt)
|
||||
}
|
||||
|
||||
auto pEffect = mEffects[index];
|
||||
pEffect->ShowInterface( GetParent(), EffectUI::DialogFactory,
|
||||
pEffect->ShowInterface( *GetParent(), EffectUI::DialogFactory,
|
||||
pEffect->IsBatchProcessing() );
|
||||
}
|
||||
|
||||
@ -716,6 +717,7 @@ EVT_MENU_RANGE(kFactoryPresetsID, kFactoryPresetsID + 999, EffectUIHost::OnFacto
|
||||
END_EVENT_TABLE()
|
||||
|
||||
EffectUIHost::EffectUIHost(wxWindow *parent,
|
||||
AudacityProject &project,
|
||||
Effect *effect,
|
||||
EffectUIClientInterface *client)
|
||||
: wxDialogWrapper(parent, wxID_ANY, effect->GetName(),
|
||||
@ -735,7 +737,7 @@ EffectUIHost::EffectUIHost(wxWindow *parent,
|
||||
mCommand = NULL;
|
||||
mClient = client;
|
||||
|
||||
mProject = GetActiveProject();
|
||||
mProject = &project;
|
||||
|
||||
mInitialized = false;
|
||||
mSupportsRealtime = false;
|
||||
@ -749,6 +751,7 @@ EffectUIHost::EffectUIHost(wxWindow *parent,
|
||||
}
|
||||
|
||||
EffectUIHost::EffectUIHost(wxWindow *parent,
|
||||
AudacityProject &project,
|
||||
AudacityCommand *command,
|
||||
EffectUIClientInterface *client)
|
||||
: wxDialogWrapper(parent, wxID_ANY, XO("Some Command") /*command->GetName()*/,
|
||||
@ -768,7 +771,7 @@ EffectUIHost::EffectUIHost(wxWindow *parent,
|
||||
mCommand = command;
|
||||
mClient = client;
|
||||
|
||||
mProject = GetActiveProject();
|
||||
mProject = &project;
|
||||
|
||||
mInitialized = false;
|
||||
mSupportsRealtime = false;
|
||||
@ -1128,6 +1131,8 @@ void EffectUIHost::OnClose(wxCloseEvent & WXUNUSED(evt))
|
||||
|
||||
void EffectUIHost::OnApply(wxCommandEvent & evt)
|
||||
{
|
||||
auto &project = *mProject;
|
||||
|
||||
// On wxGTK (wx2.8.12), the default action is still executed even if
|
||||
// the button is disabled. This appears to affect all wxDialogs, not
|
||||
// just our Effects dialogs. So, this is a only temporary workaround
|
||||
@ -1143,14 +1148,14 @@ void EffectUIHost::OnApply(wxCommandEvent & evt)
|
||||
mEffect &&
|
||||
mEffect->GetType() != EffectTypeGenerate &&
|
||||
mEffect->GetType() != EffectTypeTool &&
|
||||
ViewInfo::Get( *mProject ).selectedRegion.isPoint())
|
||||
ViewInfo::Get( project ).selectedRegion.isPoint())
|
||||
{
|
||||
auto flags = AlwaysEnabledFlag;
|
||||
bool allowed =
|
||||
MenuManager::Get(*mProject).ReportIfActionNotAllowed(
|
||||
mEffect->GetName(),
|
||||
flags,
|
||||
WaveTracksSelectedFlag | TimeSelectedFlag);
|
||||
MenuManager::Get( project ).ReportIfActionNotAllowed(
|
||||
mEffect->GetName(),
|
||||
flags,
|
||||
WaveTracksSelectedFlag | TimeSelectedFlag);
|
||||
if (!allowed)
|
||||
return;
|
||||
}
|
||||
@ -1191,7 +1196,6 @@ void EffectUIHost::OnApply(wxCommandEvent & evt)
|
||||
auto cleanup = finally( [&] { mApplyBtn->Enable(); } );
|
||||
|
||||
if( mEffect ) {
|
||||
auto &project = *GetActiveProject();
|
||||
CommandContext context( project );
|
||||
// This is absolute hackage...but easy and I can't think of another way just now.
|
||||
//
|
||||
@ -1203,7 +1207,7 @@ void EffectUIHost::OnApply(wxCommandEvent & evt)
|
||||
if( mCommand )
|
||||
// PRL: I don't like the global and would rather pass *mProject!
|
||||
// But I am preserving old behavior
|
||||
mCommand->Apply( CommandContext{ *GetActiveProject() } );
|
||||
mCommand->Apply( CommandContext{ project } );
|
||||
}
|
||||
|
||||
void EffectUIHost::DoCancel()
|
||||
@ -1812,15 +1816,22 @@ void EffectUIHost::CleanupRealtime()
|
||||
}
|
||||
}
|
||||
|
||||
wxDialog *EffectUI::DialogFactory( wxWindow *parent, EffectHostInterface *pHost,
|
||||
wxDialog *EffectUI::DialogFactory( wxWindow &parent, EffectHostInterface *pHost,
|
||||
EffectUIClientInterface *client)
|
||||
{
|
||||
auto pEffect = dynamic_cast< Effect* >( pHost );
|
||||
if ( ! pEffect )
|
||||
return nullptr;
|
||||
|
||||
// Make sure there is an associated project, whose lifetime will
|
||||
// govern the lifetime of the dialog, even when the dialog is
|
||||
// non-modal, as for realtime effects
|
||||
auto project = FindProjectFromWindow(&parent);
|
||||
if ( !project )
|
||||
return nullptr;
|
||||
|
||||
Destroy_ptr<EffectUIHost> dlg{
|
||||
safenew EffectUIHost{ parent, pEffect, client} };
|
||||
safenew EffectUIHost{ &parent, *project, pEffect, client} };
|
||||
|
||||
if (dlg->Initialize())
|
||||
{
|
||||
@ -1913,7 +1924,7 @@ wxDialog *EffectUI::DialogFactory( wxWindow *parent, EffectHostInterface *pHost,
|
||||
EffectRack::Get( context.project ).Add(effect);
|
||||
}
|
||||
#endif
|
||||
success = effect->DoEffect(&window,
|
||||
success = effect->DoEffect(window,
|
||||
rate,
|
||||
&tracks,
|
||||
&trackFactory,
|
||||
|
@ -120,9 +120,11 @@ class EffectUIHost final : public wxDialogWrapper,
|
||||
public:
|
||||
// constructors and destructors
|
||||
EffectUIHost(wxWindow *parent,
|
||||
AudacityProject &project,
|
||||
Effect *effect,
|
||||
EffectUIClientInterface *client);
|
||||
EffectUIHost(wxWindow *parent,
|
||||
AudacityProject &project,
|
||||
AudacityCommand *command,
|
||||
EffectUIClientInterface *client);
|
||||
virtual ~EffectUIHost();
|
||||
@ -216,7 +218,7 @@ class CommandContext;
|
||||
|
||||
namespace EffectUI {
|
||||
|
||||
wxDialog *DialogFactory( wxWindow *parent, EffectHostInterface *pHost,
|
||||
wxDialog *DialogFactory( wxWindow &parent, EffectHostInterface *pHost,
|
||||
EffectUIClientInterface *client);
|
||||
|
||||
/** Run an effect given the plugin ID */
|
||||
|
@ -210,7 +210,7 @@ public:
|
||||
~Settings() {}
|
||||
|
||||
bool PromptUser(EffectNoiseReduction *effect,
|
||||
wxWindow *parent, bool bHasProfile, bool bAllowTwiddleSettings);
|
||||
wxWindow &parent, bool bHasProfile, bool bAllowTwiddleSettings);
|
||||
bool PrefsIO(bool read);
|
||||
bool Validate(EffectNoiseReduction *effect) const;
|
||||
|
||||
@ -460,7 +460,7 @@ bool EffectNoiseReduction::CheckWhetherSkipEffect()
|
||||
}
|
||||
|
||||
bool EffectNoiseReduction::ShowInterface(
|
||||
wxWindow *parent, const EffectDialogFactory &, bool forceModal)
|
||||
wxWindow &parent, const EffectDialogFactory &, bool forceModal)
|
||||
{
|
||||
// to do: use forceModal correctly
|
||||
|
||||
@ -474,11 +474,11 @@ bool EffectNoiseReduction::ShowInterface(
|
||||
}
|
||||
|
||||
bool EffectNoiseReduction::Settings::PromptUser
|
||||
(EffectNoiseReduction *effect, wxWindow *parent,
|
||||
(EffectNoiseReduction *effect, wxWindow &parent,
|
||||
bool bHasProfile, bool bAllowTwiddleSettings)
|
||||
{
|
||||
EffectNoiseReduction::Dialog dlog
|
||||
(effect, this, parent, bHasProfile, bAllowTwiddleSettings);
|
||||
(effect, this, &parent, bHasProfile, bAllowTwiddleSettings);
|
||||
|
||||
dlog.CentreOnParent();
|
||||
dlog.ShowModal();
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
|
||||
// using Effect::TrackProgress;
|
||||
|
||||
bool ShowInterface( wxWindow *parent,
|
||||
bool ShowInterface( wxWindow &parent,
|
||||
const EffectDialogFactory &factory, bool forceModal = false) override;
|
||||
|
||||
bool Init() override;
|
||||
|
@ -150,10 +150,10 @@ bool EffectNoiseRemoval::CheckWhetherSkipEffect()
|
||||
}
|
||||
|
||||
bool EffectNoiseRemoval::ShowInterface(
|
||||
wxWindow *parent, const EffectDialogFactory &, bool forceModal /* forceModal */ )
|
||||
wxWindow &parent, const EffectDialogFactory &, bool forceModal /* forceModal */ )
|
||||
{
|
||||
// to do: use forceModal correctly
|
||||
NoiseRemovalDialog dlog(this, parent);
|
||||
NoiseRemovalDialog dlog(this, &parent);
|
||||
dlog.mSensitivity = mSensitivity;
|
||||
dlog.mGain = -mNoiseGain;
|
||||
dlog.mFreq = mFreqSmoothingHz;
|
||||
|
@ -53,7 +53,7 @@ public:
|
||||
|
||||
// Effect implementation
|
||||
|
||||
bool ShowInterface( wxWindow *parent,
|
||||
bool ShowInterface( wxWindow &parent,
|
||||
const EffectDialogFactory &factory, bool forceModal = false) override;
|
||||
bool Init() override;
|
||||
bool CheckWhetherSkipEffect() override;
|
||||
|
@ -1602,7 +1602,7 @@ bool VSTEffect::RealtimeProcessEnd()
|
||||
/// all provide the information (kn0ck0ut is one).
|
||||
///
|
||||
bool VSTEffect::ShowInterface(
|
||||
wxWindow *parent, const EffectDialogFactory &factory, bool forceModal)
|
||||
wxWindow &parent, const EffectDialogFactory &factory, bool forceModal)
|
||||
{
|
||||
if (mDialog)
|
||||
{
|
||||
|
@ -151,7 +151,7 @@ class VSTEffect final : public wxEvtHandler,
|
||||
size_t numSamples) override;
|
||||
bool RealtimeProcessEnd() override;
|
||||
|
||||
bool ShowInterface( wxWindow *parent,
|
||||
bool ShowInterface( wxWindow &parent,
|
||||
const EffectDialogFactory &factory, bool forceModal = false) override;
|
||||
|
||||
bool GetAutomationParameters(CommandParameters & parms) override;
|
||||
|
@ -1429,7 +1429,7 @@ bool AudioUnitEffect::RealtimeProcessEnd()
|
||||
}
|
||||
|
||||
bool AudioUnitEffect::ShowInterface(
|
||||
wxWindow *parent, const EffectDialogFactory &factory, bool forceModal)
|
||||
wxWindow &parent, const EffectDialogFactory &factory, bool forceModal)
|
||||
{
|
||||
if (mDialog)
|
||||
{
|
||||
|
@ -101,7 +101,7 @@ public:
|
||||
size_t numSamples) override;
|
||||
bool RealtimeProcessEnd() override;
|
||||
|
||||
bool ShowInterface( wxWindow *parent,
|
||||
bool ShowInterface( wxWindow &parent,
|
||||
const EffectDialogFactory &factory, bool forceModal = false) override;
|
||||
|
||||
bool GetAutomationParameters(CommandParameters & parms) override;
|
||||
|
@ -1071,7 +1071,7 @@ bool LadspaEffect::RealtimeProcessEnd()
|
||||
}
|
||||
|
||||
bool LadspaEffect::ShowInterface(
|
||||
wxWindow *parent, const EffectDialogFactory &factory, bool forceModal)
|
||||
wxWindow &parent, const EffectDialogFactory &factory, bool forceModal)
|
||||
{
|
||||
if (mDialog)
|
||||
{
|
||||
|
@ -99,7 +99,7 @@ public:
|
||||
size_t numSamples) override;
|
||||
bool RealtimeProcessEnd() override;
|
||||
|
||||
bool ShowInterface( wxWindow *parent,
|
||||
bool ShowInterface( wxWindow &parent,
|
||||
const EffectDialogFactory &factory, bool forceModal = false) override;
|
||||
|
||||
bool GetAutomationParameters(CommandParameters & parms) override;
|
||||
|
@ -1440,7 +1440,7 @@ bool LV2Effect::RealtimeProcessEnd()
|
||||
}
|
||||
|
||||
bool LV2Effect::ShowInterface(
|
||||
wxWindow *parent, const EffectDialogFactory &factory, bool forceModal)
|
||||
wxWindow &parent, const EffectDialogFactory &factory, bool forceModal)
|
||||
{
|
||||
if (mDialog)
|
||||
{
|
||||
|
@ -305,7 +305,7 @@ public:
|
||||
size_t RealtimeProcess(int group, float **inbuf, float **outbuf, size_t numSamples) override;
|
||||
bool RealtimeProcessEnd() override;
|
||||
|
||||
bool ShowInterface( wxWindow *parent,
|
||||
bool ShowInterface( wxWindow &parent,
|
||||
const EffectDialogFactory &factory, bool forceModal = false) override;
|
||||
|
||||
bool GetAutomationParameters(CommandParameters & parms) override;
|
||||
|
@ -977,7 +977,7 @@ finish:
|
||||
}
|
||||
|
||||
bool NyquistEffect::ShowInterface(
|
||||
wxWindow *parent, const EffectDialogFactory &factory, bool forceModal)
|
||||
wxWindow &parent, const EffectDialogFactory &factory, bool forceModal)
|
||||
{
|
||||
// Show the normal (prompt or effect) interface
|
||||
bool res = Effect::ShowInterface(parent, factory, forceModal);
|
||||
|
@ -99,7 +99,7 @@ public:
|
||||
bool Init() override;
|
||||
bool CheckWhetherSkipEffect() override;
|
||||
bool Process() override;
|
||||
bool ShowInterface( wxWindow *parent,
|
||||
bool ShowInterface( wxWindow &parent,
|
||||
const EffectDialogFactory &factory, bool forceModal = false) override;
|
||||
void PopulateOrExchange(ShuttleGui & S) override;
|
||||
bool TransferDataToWindow() override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user