30#include "../ShuttleGetDefinition.h"
31#include "../commands/CommandContext.h"
32#include "../commands/AudacityCommand.h"
60 std::unique_ptr<EffectPlugin> uEffect)
62 auto pEffect = uEffect.get();
114 return effect->GetDefinition().GetFamily().Msgid();
125 return effect->GetDefinition().GetVendor().Msgid();
148 return pEff->GetDefinition().ManualPage();
153 return wxEmptyString;
159 return pEff->GetDefinition().GetDescription();
175 effect = &edi->GetDefinition();
181 if ( !effect && !command )
187 bool bHasParams = command
190 if ( (flags == 0) && !bHasParams )
202 S.StartField(
"params" );
222 return effect->GetDefinition().IsHiddenFromMenus();
251 if (
auto effect = pair.first) {
255 effect->SaveSettingsAsString(*pair.second, parms);
284 return wxEmptyString;
292 if (
auto effect = pair.first) {
300 return effect->LoadSettingsFromString(
301 eap.Read(
wxT(
"Use Preset")),
settings).has_value();
304 return effect->LoadSettingsFromString(
params,
settings).has_value();
337 auto pEffectBase =
dynamic_cast<EffectBase*
>(effect);
344 pEffectBase->SetTracks(
nullptr);
347 std::shared_ptr<EffectInstance> pInstance;
355 *std::make_shared<SimpleEffectSettingsAccess>(*pSettings),
356 effect->IsBatchProcessing() ) != 0;
389 std::sort( presets.begin(), presets.end() );
403 effect->GetDefinition().GetFactoryPresets().size() > 0 ||
408#include <wx/choice.h>
409#include <wx/listbox.h>
426 wxString GetSelected()
const;
427 void SetSelected(
const wxString & parms);
433 void OnType(wxCommandEvent & evt);
434 void OnOk(wxCommandEvent & evt);
435 void OnCancel(wxCommandEvent & evt);
445 DECLARE_EVENT_TABLE()
454 EVT_CHOICE(
ID_Type, EffectPresetsDialog::OnType)
455 EVT_LISTBOX_DCLICK(wxID_ANY, EffectPresetsDialog::OnOk)
456 EVT_BUTTON(wxID_OK, EffectPresetsDialog::OnOk)
457 EVT_BUTTON(wxID_CANCEL, EffectPresetsDialog::OnCancel)
465 S.StartVerticalLay();
470 S.AddPrompt(
XXO(
"Type:"));
471 mType =
S.Id(
ID_Type).AddChoice( {}, {}, 0 );
473 S.AddPrompt(
XXO(
"&Preset:"));
475 .Style( wxLB_SINGLE | wxLB_NEEDED_SB )
480 S.AddStandardButtons();
485 mFactoryPresets = effect->GetDefinition().GetFactoryPresets();
487 if (mUserPresets.size() > 0)
489 mType->Append(
_(
"User Presets"));
492 if (mFactoryPresets.size() > 0)
494 mType->Append(
_(
"Factory Presets"));
499 mType->Append(
_(
"Current Settings"));
504 mType->Append(
_(
"Factory Defaults"));
510EffectPresetsDialog::~EffectPresetsDialog()
514wxString EffectPresetsDialog::GetSelected()
const
519void EffectPresetsDialog::SetSelected(
const wxString & parms)
525 SetPrefix(
XO(
"User Presets"),
preset);
530 SetPrefix(
XO(
"Factory Presets"),
preset);
534 SetPrefix(
XO(
"Current Settings"), wxEmptyString);
538 SetPrefix(
XO(
"Factory Defaults"), wxEmptyString);
542void EffectPresetsDialog::SetPrefix(
547 if (type ==
XO(
"User Presets"))
550 for (
const auto &
preset : mUserPresets)
552 mPresets->Enable(
true);
553 mPresets->SetStringSelection(prefix);
554 if (mPresets->GetSelection() == wxNOT_FOUND)
556 mPresets->SetSelection(0);
559 + mPresets->GetStringSelection();
561 else if (type ==
XO(
"Factory Presets"))
564 for (
size_t i = 0, cnt = mFactoryPresets.size(); i < cnt; i++)
566 auto label = mFactoryPresets[i];
571 mPresets->Append(
label);
573 mPresets->Enable(
true);
574 mPresets->SetStringSelection(prefix);
575 if (mPresets->GetSelection() == wxNOT_FOUND)
577 mPresets->SetSelection(0);
580 + mPresets->GetStringSelection();
582 else if (type ==
XO(
"Current Settings"))
585 mPresets->Enable(
false);
588 else if (type ==
XO(
"Factory Defaults"))
591 mPresets->Enable(
false);
596void EffectPresetsDialog::UpdateUI()
598 int selected = mType->GetSelection();
599 if (selected == wxNOT_FOUND)
602 mType->SetSelection(selected);
604 wxString type = mType->GetString(selected);
606 if (type ==
_(
"User Presets"))
608 selected = mPresets->GetSelection();
609 if (selected == wxNOT_FOUND)
615 for (
const auto &
preset : mUserPresets)
617 mPresets->Enable(
true);
618 mPresets->SetSelection(selected);
620 + mPresets->GetString(selected);
622 else if (type ==
_(
"Factory Presets"))
624 selected = mPresets->GetSelection();
625 if (selected == wxNOT_FOUND)
631 for (
size_t i = 0, cnt = mFactoryPresets.size(); i < cnt; i++)
633 auto label = mFactoryPresets[i];
638 mPresets->Append(
label);
640 mPresets->Enable(
true);
641 mPresets->SetSelection(selected);
643 + mPresets->GetString(selected);
645 else if (type ==
_(
"Current Settings"))
648 mPresets->Enable(
false);
651 else if (type ==
_(
"Factory Defaults"))
654 mPresets->Enable(
false);
659void EffectPresetsDialog::OnType(wxCommandEvent & WXUNUSED(evt))
664void EffectPresetsDialog::OnOk(wxCommandEvent & WXUNUSED(evt))
671void EffectPresetsDialog::OnCancel(wxCommandEvent & WXUNUSED(evt))
673 mSelection = wxEmptyString;
687 return wxEmptyString;
699 EffectPresetsDialog dlg(parent, effect);
702 dlg.SetSize(dlg.GetMinSize());
703 dlg.CenterOnParent();
707 preset = dlg.GetSelected();
733 return wxEmptyString;
760 effect->SetBatchProcessing();
762 command->SetBatchProcessing(
true);
768 effect->UnsetBatchProcessing();
770 command->SetBatchProcessing(
false);
783std::pair<EffectPlugin *, EffectSettings *>
788 return {results.effect, &results.settings};
790 return {
nullptr,
nullptr};
801 constexpr auto InitializedKey = L
"Initialized";
802 if (
bool haveDefaults{};
804 InitializedKey, haveDefaults,
false),
809 if (
bool haveCurrent{};
811 InitializedKey, haveCurrent,
false),
817 InitializedKey,
true);
823std::pair<ComponentInterface *, EffectSettings>
828 auto settings = result->MakeSettings();
830 return { result, std::move(
settings) };
832 return {
nullptr, {} };
856 if (
auto effect =
dynamic_cast<EffectPlugin *
>(component))
862"Attempting to initialize the following effect failed:\n\n%s\n\nMore information may be available in 'Help > Diagnostics > Show Log'")
864 XO(
"Effect failed to initialize"));
892"Attempting to initialize the following command failed:\n\n%s\n\nMore information may be available in 'Help > Diagnostics > Show Log'")
894 XO(
"Command failed to initialize"));
906 if (strTarget.
empty())
915 auto &ID = plug.GetID();
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
EffectDistortionSettings params
const TranslatableString name
RegistryPath UserPresetsGroup(const RegistryPath &name)
Compute part of a registry path, given a name which may be empty.
const RegistryPath & FactoryDefaultsGroup()
Component of a configuration key path, for default state of MakeSettings()
const RegistryPath & CurrentSettingsGroup()
Component of a configuration key path, for last-used destructive settings.
static bool HasFactoryDefaults(EffectPlugin &host)
static bool HasCurrentSettings(EffectPlugin &host)
static RegistryPaths GetUserPresets(EffectPlugin &host)
std::function< DialogFactoryResults(wxWindow &parent, EffectBase &, EffectUIServices &, EffectSettingsAccess &) > EffectDialogFactory
Type of function that creates a dialog for an effect.
XXO("&Cut/Copy/Paste Toolbar")
std::vector< RegistryPath > RegistryPaths
@ PluginTypeAudacityCommand
static const AttachedProjectObjects::RegisteredFactory manager
EffectReverbSettings preset
declares abstract base class Track, TrackList, and iterators over TrackList
static Settings & settings()
Base class for command in Audacity.
bool LoadSettingsFromString(const wxString &parms)
bool SaveSettingsAsString(wxString &parms)
virtual bool VisitSettings(SettingsVisitor &)
virtual bool PromptUser(wxWindow *parent)
virtual ManualPageID ManualPage()
bool DoAudacityCommand(wxWindow *parent, const CommandContext &context, bool shouldPrompt=true)
virtual TranslatableString GetDescription() const override
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
std::unique_ptr< CommandOutputTargets > pOutput
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the SettingsVis...
virtual bool HasEntry(const wxString &strName) const override
bool GetParameters(wxString &parms)
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
const wxString & Internal() const
const TranslatableString & Msgid() const
Base class for many of the effects in Audacity.
void SetTracks(TrackList *pTracks)
static Identifier GetSquashedName(const Identifier &ident)
A utility that strips spaces and CamelCases a name.
Base class for many of the effects in Audacity.
EffectManager is the class that handles effects and effect categories.
bool SupportsAutomation(const PluginID &ID)
ComponentInterfaceSymbol GetCommandSymbol(const PluginID &ID)
ManualPageID GetCommandUrl(const PluginID &ID)
CommandID GetCommandIdentifier(const PluginID &ID)
bool HasPresets(const PluginID &ID)
void BatchProcessingOff(const PluginID &ID)
AudacityCommand * GetAudacityCommand(const PluginID &ID)
void SetSkipStateFlag(bool flag)
EffectPlugin * GetEffect(const PluginID &ID)
void GetCommandDefinition(const PluginID &ID, const CommandContext &context, int flags)
static const EffectInstanceFactory * GetInstanceFactory(const PluginID &ID)
void BatchProcessingOn(const PluginID &ID)
std::pair< EffectPlugin *, EffectSettings * > GetEffectAndDefaultSettings(const PluginID &ID)
static EffectManager & Get()
EffectSettings * GetDefaultSettings(const PluginID &ID)
TranslatableString GetCommandName(const PluginID &ID)
TranslatableString GetVendorName(const PluginID &ID)
wxString GetDefaultPreset(const PluginID &ID)
bool DoAudacityCommand(const PluginID &ID, const CommandContext &, wxWindow *parent, bool shouldPrompt=true)
const PluginID & RegisterEffect(std::unique_ptr< EffectPlugin > uEffect)
Here solely for the purpose of Nyquist Workbench until a better solution is devised.
bool SetEffectParameters(const PluginID &ID, const wxString ¶ms)
wxString GetPreset(const PluginID &ID, const wxString ¶ms, wxWindow *parent)
TranslatableString GetEffectFamilyName(const PluginID &ID)
TranslatableString GetCommandTip(const PluginID &ID)
void UnregisterEffect(const PluginID &ID)
Used only by Nyquist Workbench module.
EffectAndDefaultSettings & DoGetEffect(const PluginID &ID)
wxString GetEffectParameters(const PluginID &ID)
AudacityCommandMap mCommands
bool IsHidden(const PluginID &ID)
const PluginID & GetEffectByIdentifier(const CommandID &strTarget)
TranslatableString GetCommandDescription(const PluginID &ID)
bool PromptUser(const PluginID &ID, const EffectDialogFactory &factory, wxWindow &parent)
Shows an effect or command dialog so the user can specify settings for later.
Factory of instances of an effect.
static const wxString kUserPresetIdent
static const wxString kFactoryPresetIdent
virtual const EffectSettingsManager & GetDefinition() const =0
static const wxString kCurrentSettingsIdent
static const wxString kFactoryDefaultsIdent
EffectSettingsManager is an EffectDefinitionInterface that adds a factory function for EffectSettings...
virtual bool VisitSettings(SettingsVisitor &visitor, EffectSettings &settings)
virtual int ShowHostInterface(EffectBase &plugin, wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false)
bool IsEffectAutomatable() const
PluginManager maintains a list of all plug ins. That covers modules, effects, generators,...
ComponentInterface * Load(const PluginID &ID)
void UnregisterPlugin(const PluginID &ID)
Range PluginsOfType(int type)
const PluginDescriptor * GetPlugin(const PluginID &ID) const
void RegisterPlugin(PluginDescriptor &&desc)
const ComponentInterfaceSymbol & GetSymbol(const PluginID &ID)
static PluginManager & Get()
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.
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
static TrackListHolder Create(AudacityProject *pOwner)
Holds a msgid for the translation catalog; may also bind format arguments.
wxString Translation() const
RegistryPaths mFactoryPresets
RegistryPaths mUserPresets
bool GetConfigSubgroups(const EffectDefinitionInterface &ident, PluginSettings::ConfigurationType type, const RegistryPath &group, RegistryPaths &subgroups)
bool SetConfig(const EffectDefinitionInterface &ident, ConfigurationType type, const RegistryPath &group, const RegistryPath &key, const Value &value)
bool HasConfigGroup(const EffectDefinitionInterface &ident, PluginSettings::ConfigurationType type, const RegistryPath &group)
bool GetConfig(const EffectDefinitionInterface &ident, ConfigurationType type, const RegistryPath &group, const RegistryPath &key, Value &var, const Value &defval)
THEME_RESOURCES_API void Load()
std::pair< ComponentInterface *, EffectSettings > LoadComponent(const PluginID &ID)
void InitializePreset(EffectSettingsManager &manager, EffectSettings &settings)
static RegisteredToolbarFactory factory
Externalized state of a plug-in.
"finally" as in The C++ Programming Language, 4th ed., p. 358 Useful for defining ad-hoc RAII actions...