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
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
191{
192 // bFast is unused as checking in the list is fast.
193 static_cast<void>(bFast); // avoid unused variable warning
194 return mCommands.find( path ) != mCommands.end();
195}
196
197std::unique_ptr<ComponentInterface>
199{
200 // Acquires a resource for the application.
201 return Instantiate(path);
202}
203
204// ============================================================================
205// BuiltinCommandsModule implementation
206// ============================================================================
207
208std::unique_ptr<AudacityCommand> BuiltinCommandsModule::Instantiate(const PluginPath & path)
209{
210 wxASSERT(path.StartsWith(BUILTIN_GENERIC_COMMAND_PREFIX));
211 auto iter = mCommands.find( path );
212 if ( iter != mCommands.end() )
213 return iter->second->factory();
214
215 wxASSERT( false );
216 return nullptr;
217}
#define BUILTIN_GENERIC_COMMAND_PREFIX
static RegisteredToolbarFactory factory
const TranslatableString name
Definition: Distortion.cpp:82
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
#define XO(s)
Definition: Internat.h:31
DECLARE_BUILTIN_PROVIDER(BuiltinsCommandBuiltin)
DECLARE_PROVIDER_ENTRY(AudacityModule)
static bool sInitialized
Definition: LoadEffects.cpp:23
#define safenew
Definition: MemoryX.h:10
static ProjectFileIORegistry::AttributeWriterEntry entry
static TranslatableStrings names
Definition: TagsEditor.cpp:151
Internal module to auto register all built in commands. It is closely modelled on BuiltinEffectsModul...
Definition: LoadCommands.h:31
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.
bool IsPluginValid(const PluginPath &path, bool bFast) override
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()
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.
std::unique_ptr< CommandItem > Command(const CommandID &name, const TranslatableString &label_in, void(Handler::*pmf)(const CommandContext &), CommandFlag flags, const CommandManager::Options &options={}, CommandHandlerFinder finder=FinderScope::DefaultFinder())
ComponentInterfaceSymbol name
static Entries & Registry()
std::vector< Entry > Entries
Factory factory