Audacity 3.2.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
EffectAndCommandPluginManager Class Reference

#include <EffectAndCommandPluginManager.h>

Collaboration diagram for EffectAndCommandPluginManager:
[legend]

Classes

struct  UnsetBatchProcessing
 A custom deleter for std::unique_ptr. More...
 

Public Types

using DialogInvoker = std::function< bool(Effect &, EffectSettings &, std::shared_ptr< EffectInstance > &)>
 

Public Member Functions

bool DoAudacityCommand (const PluginID &ID, const CommandContext &, bool shouldPrompt=true)
 
void GetCommandDefinition (const PluginID &ID, const CommandContext &context, int flags)
 
wxString GetEffectParameters (const PluginID &ID)
 
bool SetEffectParameters (const PluginID &ID, const wxString &params)
 
bool PromptUser (const PluginID &ID, AudacityProject &project, DialogInvoker dialogInvoker)
 Shows an effect or command dialog so the user can specify settings for later. More...
 
BatchProcessingScope SetBatchProcessing (const PluginID &ID)
 Begin a scope that ends when the returned object is destroyed. More...
 

Static Public Member Functions

static EffectAndCommandPluginManagerGet ()
 

Private Types

using BatchProcessingScope = std::unique_ptr< EffectAndCommandPluginManager, UnsetBatchProcessing >
 
using AudacityCommandMap = std::unordered_map< wxString, AudacityCommand * >
 

Private Member Functions

void BatchProcessingOn (const PluginID &ID)
 
void BatchProcessingOff (const PluginID &ID)
 
ManualPageID GetCommandUrl (const PluginID &ID)
 
TranslatableString GetCommandTip (const PluginID &ID)
 
AudacityCommandGetAudacityCommand (const PluginID &ID)
 

Private Attributes

AudacityCommandMap mCommands
 

Detailed Description

Definition at line 35 of file EffectAndCommandPluginManager.h.

Member Typedef Documentation

◆ AudacityCommandMap

using EffectAndCommandPluginManager::AudacityCommandMap = std::unordered_map<wxString, AudacityCommand*>
private

Definition at line 89 of file EffectAndCommandPluginManager.h.

◆ BatchProcessingScope

Definition at line 72 of file EffectAndCommandPluginManager.h.

◆ DialogInvoker

using EffectAndCommandPluginManager::DialogInvoker = std::function<bool( Effect&, EffectSettings&, std::shared_ptr<EffectInstance>&)>

Definition at line 40 of file EffectAndCommandPluginManager.h.

Member Function Documentation

◆ BatchProcessingOff()

void EffectAndCommandPluginManager::BatchProcessingOff ( const PluginID ID)
private

Definition at line 160 of file EffectAndCommandPluginManager.cpp.

161{
162 if (auto effect = EffectManager::Get().GetEffect(ID))
163 effect->UnsetBatchProcessing();
164 else if (auto command = GetAudacityCommand(ID))
165 command->SetBatchProcessing(false);
166}
AudacityCommand * GetAudacityCommand(const PluginID &ID)
static EffectManager & Get()

References EffectManager::Get(), and GetAudacityCommand().

Referenced by EffectAndCommandPluginManager::UnsetBatchProcessing::operator()().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BatchProcessingOn()

void EffectAndCommandPluginManager::BatchProcessingOn ( const PluginID ID)
private

Definition at line 152 of file EffectAndCommandPluginManager.cpp.

153{
154 if (auto effect = EffectManager::Get().GetEffect(ID))
155 effect->SetBatchProcessing();
156 else if (auto command = GetAudacityCommand(ID))
157 command->SetBatchProcessing(true);
158}

References EffectManager::Get(), and GetAudacityCommand().

Referenced by SetBatchProcessing().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoAudacityCommand()

bool EffectAndCommandPluginManager::DoAudacityCommand ( const PluginID ID,
const CommandContext context,
bool  shouldPrompt = true 
)

Run a command given the plugin ID

Definition at line 26 of file EffectAndCommandPluginManager.cpp.

30{
33
34 if (!command)
35 {
36 return false;
37 }
38
39 bool res = command->DoAudacityCommand(context, shouldPrompt);
40
41 return res;
42}
Base class for command in Audacity.
bool DoAudacityCommand(const CommandContext &context, bool shouldPrompt=true)
void SetSkipStateFlag(bool flag)

References AudacityCommand::DoAudacityCommand(), EffectManager::Get(), GetAudacityCommand(), and EffectManager::SetSkipStateFlag().

Referenced by CommandDispatch::DoAudacityCommand().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Get()

EffectAndCommandPluginManager & EffectAndCommandPluginManager::Get ( )
static

Definition at line 20 of file EffectAndCommandPluginManager.cpp.

Referenced by MacroCommands::ApplyEffectCommand(), HelpCommand::ApplyInner(), CommandDispatch::DoAudacityCommand(), MacroCommands::GetCurrentParamsFor(), MacroCommands::PromptForParamsFor(), and GetInfoCommand::SendCommands().

Here is the caller graph for this function:

◆ GetAudacityCommand()

AudacityCommand * EffectAndCommandPluginManager::GetAudacityCommand ( const PluginID ID)
private

Definition at line 45 of file EffectAndCommandPluginManager.cpp.

46{
47 // Must have a "valid" ID
48 if (ID.empty())
49 {
50 return NULL;
51 }
52
53 if (mCommands.find(ID) == mCommands.end())
54 {
55 // This will instantiate the command if it hasn't already been done
56 auto command =
57 dynamic_cast<AudacityCommand*>(PluginManager::Get().Load(ID));
58 if (command)
59 {
60 command->Init();
61 mCommands[ID] = command;
62 return command;
63 }
64
66 XO("Attempting to initialize the following command failed:\n\n%s\n\nMore information may be available in 'Help > Diagnostics > Show Log'")
67 .Format(PluginManager::Get().GetName(ID)),
69 XO("Command failed to initialize")));
70
71 return NULL;
72 }
73
74 return mCommands[ID];
75}
XO("Cut/Copy/Paste")
virtual bool Init()
Abstract base class used in importing a file.
ComponentInterface * Load(const PluginID &ID)
static PluginManager & Get()
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
Definition: BasicUI.h:287
MessageBoxOptions && Caption(TranslatableString caption_) &&
Definition: BasicUI.h:101

References BasicUI::MessageBoxOptions::Caption(), PluginManager::Get(), AudacityCommand::Init(), PluginManager::Load(), mCommands, BasicUI::ShowMessageBox(), and XO().

Referenced by BatchProcessingOff(), BatchProcessingOn(), DoAudacityCommand(), GetCommandDefinition(), GetCommandTip(), GetCommandUrl(), GetEffectParameters(), PromptUser(), and SetEffectParameters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCommandDefinition()

void EffectAndCommandPluginManager::GetCommandDefinition ( const PluginID ID,
const CommandContext context,
int  flags 
)

Definition at line 100 of file EffectAndCommandPluginManager.cpp.

102{
103 const EffectSettingsManager* effect = nullptr;
105 AudacityCommand* command = nullptr;
106
107 if (auto [edi, pSettings] =
108 EffectManager::Get().GetEffectAndDefaultSettings(ID);
109 edi)
110 {
111 effect = &edi->GetDefinition();
112 assert(pSettings); // postcondition
113 settings = pSettings;
114 }
115 else
116 command = GetAudacityCommand(ID);
117 if (!effect && !command)
118 return;
119
120 ConstSettingsVisitor NullShuttle;
121
122 // Test if it defines any parameters at all.
123 bool bHasParams = command ? command->VisitSettings(NullShuttle) :
124 effect->VisitSettings(NullShuttle, *settings);
125 if ((flags == 0) && !bHasParams)
126 return;
127
128 // This is capturing the output context into the shuttle.
129 ShuttleGetDefinition S(*context.pOutput.get()->mStatusTarget.get());
130 S.StartStruct();
131 // using GET to expose a CommandID to the user!
132 // Macro command details are one place that we do expose Identifier
133 // to (more sophisticated) users
134 const auto& pm = PluginManager::Get();
135 S.AddItem(pm.GetCommandIdentifier(ID).GET(), "id");
136 S.AddItem(pm.GetName(ID).Translation(), "name");
137 if (bHasParams)
138 {
139 S.StartField("params");
140 S.StartArray();
141 command ? command->VisitSettings(S) : effect->VisitSettings(S, *settings);
142 S.EndArray();
143 S.EndField();
144 }
145 // use GET() to expose some details to macro programming users
146 S.AddItem(GetCommandUrl(ID).GET(), "url");
147 // The tip is a translated string!
148 S.AddItem(GetCommandTip(ID).Translation(), "tip");
149 S.EndStruct();
150}
#define S(N)
Definition: ToChars.cpp:64
static Settings & settings()
Definition: TrackInfo.cpp:51
virtual bool VisitSettings(SettingsVisitor &)
std::unique_ptr< CommandOutputTargets > pOutput
ManualPageID GetCommandUrl(const PluginID &ID)
TranslatableString GetCommandTip(const PluginID &ID)
EffectSettingsManager is an EffectDefinitionInterface that adds a factory function for EffectSettings...
virtual bool VisitSettings(SettingsVisitor &visitor, EffectSettings &settings)
Visitor of effect or command parameters. This is a base class with lots of virtual functions that do ...
SettingsVisitor that retrieves a JSON format definition of a command's parameters.
Externalized state of a plug-in.

References EffectManager::Get(), PluginManager::Get(), GetAudacityCommand(), GetCommandTip(), GetCommandUrl(), CommandContext::pOutput, S, settings(), AudacityCommand::VisitSettings(), and EffectSettingsManager::VisitSettings().

Referenced by HelpCommand::ApplyInner(), and GetInfoCommand::SendCommands().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCommandTip()

TranslatableString EffectAndCommandPluginManager::GetCommandTip ( const PluginID ID)
private

Definition at line 89 of file EffectAndCommandPluginManager.cpp.

90{
91 if (auto pEff = EffectManager::Get().GetEffect(ID))
92 return pEff->GetDefinition().GetDescription();
94 if (pCom)
95 return pCom->GetDescription();
96
97 return {};
98}
virtual TranslatableString GetDescription() const override

References EffectManager::Get(), GetAudacityCommand(), and AudacityCommand::GetDescription().

Referenced by GetCommandDefinition().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCommandUrl()

ManualPageID EffectAndCommandPluginManager::GetCommandUrl ( const PluginID ID)
private

Definition at line 77 of file EffectAndCommandPluginManager.cpp.

78{
79 if (auto pEff = EffectManager::Get().GetEffect(ID))
80 return pEff->GetDefinition().ManualPage();
82 if (pCom)
83 return pCom->ManualPage();
84
85 return wxEmptyString;
86}
virtual ManualPageID ManualPage()

References EffectManager::Get(), GetAudacityCommand(), and AudacityCommand::ManualPage().

Referenced by GetCommandDefinition().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetEffectParameters()

wxString EffectAndCommandPluginManager::GetEffectParameters ( const PluginID ID)

Support for batch commands

Definition at line 169 of file EffectAndCommandPluginManager.cpp.

170{
172 if (auto effect = pair.first)
173 {
174 assert(pair.second); // postcondition
175 wxString parms;
176
177 effect->SaveSettingsAsString(*pair.second, parms);
178
179 // Some effects don't have automatable parameters and will not return
180 // anything, so try to get the active preset (current or factory).
181 if (parms.empty())
182 {
184 }
185
186 return parms;
187 }
188
189 AudacityCommand* command = GetAudacityCommand(ID);
190
191 if (command)
192 {
193 wxString parms;
194
195 command->SaveSettingsAsString(parms);
196
197 // Some effects don't have automatable parameters and will not return
198 // anything, so try to get the active preset (current or factory).
199 if (parms.empty())
200 {
202 }
203
204 return parms;
205 }
206 return wxEmptyString;
207}
bool SaveSettingsAsString(wxString &parms)
std::pair< EffectPlugin *, EffectSettings * > GetEffectAndDefaultSettings(const PluginID &ID)
wxString GetDefaultPreset(const PluginID &ID)

References EffectManager::Get(), GetAudacityCommand(), EffectManager::GetDefaultPreset(), EffectManager::GetEffectAndDefaultSettings(), and AudacityCommand::SaveSettingsAsString().

Referenced by MacroCommands::GetCurrentParamsFor(), and MacroCommands::PromptForParamsFor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PromptUser()

bool EffectAndCommandPluginManager::PromptUser ( const PluginID ID,
AudacityProject project,
DialogInvoker  dialogInvoker 
)

Shows an effect or command dialog so the user can specify settings for later.

It is used when defining a macro. It does not invoke the effect or command.

Show the effect dialog, only so that the user can choose settings, for instance to define a macro.

Definition at line 253 of file EffectAndCommandPluginManager.cpp.

255{
256 bool result = false;
257 if (auto effect = dynamic_cast<Effect*>(EffectManager::Get().GetEffect(ID)))
258 {
259 auto empty = TrackList::Create(nullptr);
260 auto pEffectBase = dynamic_cast<EffectBase*>(effect);
261 if (pEffectBase)
262 // This allows effects to call Init() safely
263 pEffectBase->SetTracks(empty.get());
264 Finally Do([&] {
265 // reverse the side-effect
266 if (pEffectBase)
267 pEffectBase->SetTracks(nullptr);
268 });
269
270 std::shared_ptr<EffectInstance> pInstance;
273 if (const auto pSettings = EffectManager::Get().GetDefaultSettings(ID))
274 result = dialogInvoker(*effect, *pSettings, pInstance);
275 return result;
276 }
277
278 AudacityCommand* command = GetAudacityCommand(ID);
279
280 if (command)
281 {
282 result = command->PromptUser(project);
283 return result;
284 }
285
286 return result;
287}
const auto project
virtual bool PromptUser(AudacityProject &)
Base class for many of the effects in Audacity.
Definition: EffectBase.h:33
void SetTracks(TrackList *pTracks)
Definition: EffectBase.cpp:43
Base class for many of the effects in Audacity.
Definition: Effect.h:26
static TrackListHolder Create(AudacityProject *pOwner)
Definition: Track.cpp:330
"finally" as in The C++ Programming Language, 4th ed., p. 358 Useful for defining ad-hoc RAII actions...
Definition: MemoryX.h:175

References TrackList::Create(), EffectManager::Get(), GetAudacityCommand(), project, AudacityCommand::PromptUser(), and EffectBase::SetTracks().

Referenced by MacroCommands::PromptForParamsFor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetBatchProcessing()

BatchProcessingScope EffectAndCommandPluginManager::SetBatchProcessing ( const PluginID ID)
inline

Begin a scope that ends when the returned object is destroyed.

Within this scope, "batch" (i.e. macro) processing happens, and Effects that are not yet stateless may change their state temporarily, but it is restored afterward

Definition at line 82 of file EffectAndCommandPluginManager.h.

83 {
85 return BatchProcessingScope { this, { ID } };
86 }
std::unique_ptr< EffectAndCommandPluginManager, UnsetBatchProcessing > BatchProcessingScope

References BatchProcessingOn().

Referenced by MacroCommands::ApplyEffectCommand(), and MacroCommands::PromptForParamsFor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetEffectParameters()

bool EffectAndCommandPluginManager::SetEffectParameters ( const PluginID ID,
const wxString &  params 
)

Definition at line 210 of file EffectAndCommandPluginManager.cpp.

212{
214 if (auto effect = pair.first)
215 {
216 assert(pair.second); // postcondition
217 auto& settings = *pair.second;
219
220 // Check first for what GetDefaultPreset() might have written
221 if (eap.HasEntry(wxT("Use Preset")))
222 {
223 return effect
224 ->LoadSettingsFromString(eap.Read(wxT("Use Preset")), settings)
225 .has_value();
226 }
227
228 return effect->LoadSettingsFromString(params, settings).has_value();
229 }
230 AudacityCommand* command = GetAudacityCommand(ID);
231
232 if (command)
233 {
234 // Set defaults (if not initialised) before setting values.
235 command->Init();
237
238 // Check first for what GetDefaultPreset() might have written
239 if (eap.HasEntry(wxT("Use Preset")))
240 {
241 return command->LoadSettingsFromString(eap.Read(wxT("Use Preset")));
242 }
243
244 return command->LoadSettingsFromString(params);
245 }
246 return false;
247}
wxT("CloseDown"))
EffectDistortionSettings params
bool LoadSettingsFromString(const wxString &parms)
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the SettingsVis...

References EffectManager::Get(), GetAudacityCommand(), EffectManager::GetEffectAndDefaultSettings(), CommandParameters::HasEntry(), AudacityCommand::Init(), AudacityCommand::LoadSettingsFromString(), params, settings(), and wxT().

Here is the call graph for this function:

Member Data Documentation

◆ mCommands

AudacityCommandMap EffectAndCommandPluginManager::mCommands
private

Definition at line 96 of file EffectAndCommandPluginManager.h.

Referenced by GetAudacityCommand().


The documentation for this class was generated from the following files: