Audacity 3.2.0
LoadCommands.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 LoadCommands.cpp
6
7 Dominic Mazzoni
8 James Crook
9
10**************************************************************************/
17#include "LoadCommands.h"
18#include "AudacityCommand.h"
19#include "ModuleManager.h"
20#include "PluginInterface.h"
21
22#include "Prefs.h"
23
24namespace {
25bool sInitialized = false;
26}
27
31
32 using Entries = std::vector< Entry >;
33 static Entries &Registry()
34 {
35 static Entries result;
36 return result;
37 }
38};
39
42{
43 wxASSERT( !sInitialized );
44 Entry::Registry().emplace_back( Entry{ name, factory } );
45}
46
47// ============================================================================
48// Module registration entry point
49//
50// This is the symbol that Audacity looks for when the module is built as a
51// dynamic library.
52//
53// When the module is builtin to Audacity, we use the same function, but it is
54// declared static so as not to clash with other builtin modules.
55// ============================================================================
57{
58 // Create and register the importer
59 // Trust the module manager not to leak this
60 return std::make_unique<BuiltinCommandsModule>();
61}
62
63// ============================================================================
64// Register this as a builtin module
65// ============================================================================
66DECLARE_BUILTIN_PROVIDER(BuiltinsCommandBuiltin);
67
69//
70// BuiltinCommandsModule
71//
73
75{
76}
77
79{
80}
81
82// ============================================================================
83// ComponentInterface implementation
84// ============================================================================
85
87{
88 return {};
89}
90
92{
93 return XO("Builtin Commands");
94}
95
97{
98 return XO("The Audacity Team");
99}
100
102{
103 // This "may" be different if this were to be maintained as a separate DLL
104 return AUDACITY_VERSION_STRING;
105}
106
108{
109 return XO("Provides builtin commands to Audacity");
110}
111
112// ============================================================================
113// PluginProvider implementation
114// ============================================================================
115
117{
118 for ( const auto &entry : Entry::Registry() ) {
119 auto path = wxString(BUILTIN_GENERIC_COMMAND_PREFIX)
120 + entry.name.Internal();
121 mCommands[ path ] = &entry;
122 }
123 sInitialized = true;
124 return true;
125}
126
128{
129 // Nothing to do here
130 return;
131}
132
134{
135 // Commands are not enabled and disabled in EffectsPrefs
136 return {};
137}
138
140{
141 static FileExtensions empty;
142 return empty;
143}
144
146{
147 TranslatableString ignoredErrMsg;
148 for (const auto &pair : mCommands)
149 {
150 const auto &path = pair.first;
151 if (!pm.IsPluginRegistered(path, &pair.second->name.Msgid()))
152 {
153 // No checking of error ?
154 // Uses Generic Registration, not Default.
155 // Registers as TypeGeneric, not TypeEffect.
156 DiscoverPluginsAtPath(path, ignoredErrMsg,
158 }
159 }
160}
161
163{
164 // Not really libraries
166 for ( const auto &pair : mCommands )
167 names.push_back( pair.first );
168 return names;
169}
170
172 const PluginPath & path, TranslatableString &errMsg,
173 const RegistrationCallback &callback)
174{
175 // At most one
176 errMsg = {};
177 auto Command = Instantiate(path);
178 if (Command)
179 {
180 if (callback){
181 callback(this, Command.get());
182 }
183 return 1;
184 }
185
186 errMsg = XO("Unknown built-in command name");
187 return 0;
188}
189
190std::unique_ptr<ComponentInterface>
192{
193 // Acquires a resource for the application.
194 return Instantiate(path);
195}
196
198{
199 return mCommands.find( path ) != mCommands.end();
200}
201
202// ============================================================================
203// BuiltinCommandsModule implementation
204// ============================================================================
205
206std::unique_ptr<AudacityCommand> BuiltinCommandsModule::Instantiate(const PluginPath & path)
207{
208 wxASSERT(path.StartsWith(BUILTIN_GENERIC_COMMAND_PREFIX));
209 auto iter = mCommands.find( path );
210 if ( iter != mCommands.end() )
211 return iter->second->factory();
212
213 wxASSERT( false );
214 return nullptr;
215}
#define BUILTIN_GENERIC_COMMAND_PREFIX
const TranslatableString name
Definition: Distortion.cpp:76
XO("Cut/Copy/Paste")
std::vector< PluginPath > PluginPaths
Definition: Identifier.h:215
wxString PluginPath
type alias for identifying a Plugin supplied by a module, each module defining its own interpretation...
Definition: Identifier.h:214
static ProjectFileIORegistry::AttributeWriterEntry entry
DECLARE_BUILTIN_PROVIDER(BuiltinsCommandBuiltin)
DECLARE_PROVIDER_ENTRY(AudacityModule)
static bool sInitialized
Definition: LoadEffects.cpp:23
static TranslatableStrings names
Definition: TagsEditor.cpp:153
std::function< std::unique_ptr< AudacityCommand >() > Factory
Definition: LoadCommands.h:36
ComponentInterfaceSymbol GetSymbol() const override
wxString GetVersion() const override
PluginPath GetPath() const override
EffectFamilySymbol GetOptionalFamilySymbol() override
A symbol identifying the family of plug-ins provided by this.
CommandHash mCommands
Definition: LoadCommands.h:87
void Terminate() override
Called just prior to deletion to allow releasing any resources.
VendorSymbol GetVendor() const override
bool Initialize() override
Called immediately after creation. Let provider initialize.
unsigned DiscoverPluginsAtPath(const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback) override
const FileExtensions & GetFileExtensions() override
File types associated with this protocol.
static void DoRegistration(const ComponentInterfaceSymbol &name, const Factory &factory)
virtual ~BuiltinCommandsModule()
bool CheckPluginExist(const PluginPath &path) const override
Performs plugin/module existence check, still plugin may fail to load. Implementation should avoid lo...
void AutoRegisterPlugins(PluginManagerInterface &pm) override
Called so that a provider of a static set of plug-ins can register them.
TranslatableString GetDescription() const override
PluginPaths FindModulePaths(PluginManagerInterface &pm) override
std::unique_ptr< AudacityCommand > Instantiate(const PluginPath &path)
std::unique_ptr< ComponentInterface > LoadPlugin(const PluginPath &path) override
Load the plug-in at a path reported by DiscoverPluginsAtPath.
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
static const PluginID & AudacityCommandRegistrationCallback(PluginProvider *provider, ComponentInterface *ident)
virtual bool IsPluginRegistered(const PluginPath &path, const TranslatableString *pName=nullptr)=0
Was the plugin registry already populated for a path (maybe from loading the config file)?
std::function< const PluginID &(PluginProvider *, ComponentInterface *) > RegistrationCallback
Further expand a path reported by FindModulePaths.
Holds a msgid for the translation catalog; may also bind format arguments.
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
constexpr auto Command
Definition: MenuRegistry.h:456
static RegisteredToolbarFactory factory
ComponentInterfaceSymbol name
static Entries & Registry()
std::vector< Entry > Entries
Factory factory