Audacity  3.0.3
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
BuiltinCommandsModule Class Referencefinal

Internal module to auto register all built in commands. It is closely modelled on BuiltinEffectsModule. More...

#include <LoadCommands.h>

Inheritance diagram for BuiltinCommandsModule:
[legend]
Collaboration diagram for BuiltinCommandsModule:
[legend]

Classes

struct  Entry
 
struct  Registration
 

Public Types

using Factory = std::function< std::unique_ptr< AudacityCommand >() >
 
- Public Types inherited from ModuleInterface
using RegistrationCallback = std::function< const PluginID &(ModuleInterface *, ComponentInterface *) >
 

Public Member Functions

 BuiltinCommandsModule ()
 
virtual ~BuiltinCommandsModule ()
 
PluginPath GetPath () override
 
ComponentInterfaceSymbol GetSymbol () override
 
VendorSymbol GetVendor () override
 
wxString GetVersion () override
 
TranslatableString GetDescription () override
 
bool Initialize () override
 
void Terminate () override
 
EffectFamilySymbol GetOptionalFamilySymbol () override
 
const FileExtensionsGetFileExtensions () override
 
FilePath InstallPath () override
 
bool AutoRegisterPlugins (PluginManagerInterface &pm) override
 
PluginPaths FindPluginPaths (PluginManagerInterface &pm) override
 
unsigned DiscoverPluginsAtPath (const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback) override
 
bool IsPluginValid (const PluginPath &path, bool bFast) override
 
std::unique_ptr< ComponentInterfaceCreateInstance (const PluginPath &path) override
 
- Public Member Functions inherited from ModuleInterface
virtual ~ModuleInterface ()
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
TranslatableString GetName ()
 
virtual bool DefineParams (ShuttleParams &WXUNUSED(S))
 

Private Types

using CommandHash = std::unordered_map< wxString, const Entry * >
 

Private Member Functions

std::unique_ptr< AudacityCommandInstantiate (const PluginPath &path)
 

Static Private Member Functions

static void DoRegistration (const ComponentInterfaceSymbol &name, const Factory &factory)
 

Private Attributes

CommandHash mCommands
 

Detailed Description

Internal module to auto register all built in commands. It is closely modelled on BuiltinEffectsModule.

Definition at line 30 of file LoadCommands.h.

Member Typedef Documentation

◆ CommandHash

using BuiltinCommandsModule::CommandHash = std::unordered_map< wxString, const Entry* >
private

Definition at line 86 of file LoadCommands.h.

◆ Factory

using BuiltinCommandsModule::Factory = std::function< std::unique_ptr<AudacityCommand> () >

Definition at line 36 of file LoadCommands.h.

Constructor & Destructor Documentation

◆ BuiltinCommandsModule()

BuiltinCommandsModule::BuiltinCommandsModule ( )

Definition at line 73 of file LoadCommands.cpp.

74 {
75 }

◆ ~BuiltinCommandsModule()

BuiltinCommandsModule::~BuiltinCommandsModule ( )
virtual

Definition at line 77 of file LoadCommands.cpp.

78 {
79 }

Member Function Documentation

◆ AutoRegisterPlugins()

bool BuiltinCommandsModule::AutoRegisterPlugins ( PluginManagerInterface pm)
overridevirtual

Implements ModuleInterface.

Definition at line 144 of file LoadCommands.cpp.

145 {
146  TranslatableString ignoredErrMsg;
147  for (const auto &pair : mCommands)
148  {
149  const auto &path = pair.first;
150  if (!pm.IsPluginRegistered(path, &pair.second->name.Msgid()))
151  {
152  // No checking of error ?
153  // Uses Generic Registration, not Default.
154  // Registers as TypeGeneric, not TypeEffect.
155  DiscoverPluginsAtPath(path, ignoredErrMsg,
157  }
158  }
159 
160  // We still want to be called during the normal registration process
161  return false;
162 }

References PluginManagerInterface::AudacityCommandRegistrationCallback(), DiscoverPluginsAtPath(), PluginManagerInterface::IsPluginRegistered(), and mCommands.

Here is the call graph for this function:

◆ CreateInstance()

std::unique_ptr< ComponentInterface > BuiltinCommandsModule::CreateInstance ( const PluginPath path)
overridevirtual

Implements ModuleInterface.

Definition at line 198 of file LoadCommands.cpp.

199 {
200  // Acquires a resource for the application.
201  return Instantiate(path);
202 }

References Instantiate().

Here is the call graph for this function:

◆ DiscoverPluginsAtPath()

unsigned BuiltinCommandsModule::DiscoverPluginsAtPath ( const PluginPath path,
TranslatableString errMsg,
const RegistrationCallback callback 
)
overridevirtual

Implements ModuleInterface.

Definition at line 172 of file LoadCommands.cpp.

175 {
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 }

References MenuTable::Command(), Instantiate(), and XO.

Referenced by AutoRegisterPlugins().

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

◆ DoRegistration()

void BuiltinCommandsModule::DoRegistration ( const ComponentInterfaceSymbol name,
const Factory factory 
)
staticprivate

Definition at line 39 of file LoadCommands.cpp.

41 {
42  wxASSERT( !sInitialized );
43  Entry::Registry().emplace_back( Entry{ name, factory } );
44 }

References factory, name, BuiltinCommandsModule::Entry::Registry(), and sInitialized.

Here is the call graph for this function:

◆ FindPluginPaths()

PluginPaths BuiltinCommandsModule::FindPluginPaths ( PluginManagerInterface pm)
overridevirtual

Implements ModuleInterface.

Definition at line 164 of file LoadCommands.cpp.

165 {
167  for ( const auto &pair : mCommands )
168  names.push_back( pair.first );
169  return names;
170 }

References mCommands, and names.

◆ GetDescription()

TranslatableString BuiltinCommandsModule::GetDescription ( )
overridevirtual

Implements ComponentInterface.

Definition at line 106 of file LoadCommands.cpp.

107 {
108  return XO("Provides builtin commands to Audacity");
109 }

References XO.

◆ GetFileExtensions()

const FileExtensions & BuiltinCommandsModule::GetFileExtensions ( )
overridevirtual

Implements ModuleInterface.

Definition at line 138 of file LoadCommands.cpp.

139 {
140  static FileExtensions empty;
141  return empty;
142 }

◆ GetOptionalFamilySymbol()

EffectFamilySymbol BuiltinCommandsModule::GetOptionalFamilySymbol ( )
overridevirtual

Implements ModuleInterface.

Definition at line 132 of file LoadCommands.cpp.

133 {
134  // Commands are not enabled and disabled in EffectsPrefs
135  return {};
136 }

◆ GetPath()

PluginPath BuiltinCommandsModule::GetPath ( )
overridevirtual

Implements ComponentInterface.

Definition at line 85 of file LoadCommands.cpp.

86 {
87  return {};
88 }

◆ GetSymbol()

ComponentInterfaceSymbol BuiltinCommandsModule::GetSymbol ( )
overridevirtual

Implements ComponentInterface.

Definition at line 90 of file LoadCommands.cpp.

91 {
92  return XO("Builtin Commands");
93 }

References XO.

◆ GetVendor()

VendorSymbol BuiltinCommandsModule::GetVendor ( )
overridevirtual

Implements ComponentInterface.

Definition at line 95 of file LoadCommands.cpp.

96 {
97  return XO("The Audacity Team");
98 }

References XO.

◆ GetVersion()

wxString BuiltinCommandsModule::GetVersion ( )
overridevirtual

Implements ComponentInterface.

Definition at line 100 of file LoadCommands.cpp.

101 {
102  // This "may" be different if this were to be maintained as a separate DLL
103  return AUDACITY_VERSION_STRING;
104 }

◆ Initialize()

bool BuiltinCommandsModule::Initialize ( )
overridevirtual

Implements ModuleInterface.

Definition at line 115 of file LoadCommands.cpp.

116 {
117  for ( const auto &entry : Entry::Registry() ) {
118  auto path = wxString(BUILTIN_GENERIC_COMMAND_PREFIX)
119  + entry.name.Internal();
120  mCommands[ path ] = &entry;
121  }
122  sInitialized = true;
123  return true;
124 }

References BUILTIN_GENERIC_COMMAND_PREFIX, entry, mCommands, BuiltinCommandsModule::Entry::Registry(), and sInitialized.

Here is the call graph for this function:

◆ InstallPath()

FilePath BuiltinCommandsModule::InstallPath ( )
inlineoverridevirtual

Implements ModuleInterface.

Definition at line 61 of file LoadCommands.h.

61 { return {}; }

◆ Instantiate()

std::unique_ptr< AudacityCommand > BuiltinCommandsModule::Instantiate ( const PluginPath path)
private

Definition at line 208 of file LoadCommands.cpp.

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 }

References BUILTIN_GENERIC_COMMAND_PREFIX, and mCommands.

Referenced by CreateInstance(), and DiscoverPluginsAtPath().

Here is the caller graph for this function:

◆ IsPluginValid()

bool BuiltinCommandsModule::IsPluginValid ( const PluginPath path,
bool  bFast 
)
overridevirtual

Implements ModuleInterface.

Definition at line 190 of file LoadCommands.cpp.

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 }

References mCommands.

◆ Terminate()

void BuiltinCommandsModule::Terminate ( )
overridevirtual

Implements ModuleInterface.

Definition at line 126 of file LoadCommands.cpp.

127 {
128  // Nothing to do here
129  return;
130 }

Member Data Documentation

◆ mCommands

CommandHash BuiltinCommandsModule::mCommands
private

The documentation for this class was generated from the following files:
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
PluginManagerInterface::AudacityCommandRegistrationCallback
static const PluginID & AudacityCommandRegistrationCallback(ModuleInterface *provider, ComponentInterface *ident)
Definition: PluginManager.cpp:342
entry
static ProjectFileIORegistry::WriterEntry entry
Definition: ProjectSettings.cpp:193
XO
#define XO(s)
Definition: Internat.h:31
sInitialized
static bool sInitialized
Definition: LoadEffects.cpp:22
BuiltinCommandsModule::Entry::Registry
static Entries & Registry()
Definition: LoadCommands.cpp:32
wxArrayStringEx
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Definition: wxArrayStringEx.h:18
Entry
Definition: EditToolBar.cpp:225
BuiltinCommandsModule::Instantiate
std::unique_ptr< AudacityCommand > Instantiate(const PluginPath &path)
Definition: LoadCommands.cpp:208
PluginManagerInterface::IsPluginRegistered
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)?
factory
static RegisteredToolbarFactory factory
Definition: ControlToolBar.cpp:806
name
const TranslatableString name
Definition: Distortion.cpp:98
PluginPaths
std::vector< PluginPath > PluginPaths
Definition: Identifier.h:215
names
static TranslatableStrings names
Definition: Tags.cpp:744
MenuTable::Command
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())
Definition: CommandManager.h:675
BUILTIN_GENERIC_COMMAND_PREFIX
#define BUILTIN_GENERIC_COMMAND_PREFIX
Definition: AudacityCommand.h:30
BuiltinCommandsModule::DiscoverPluginsAtPath
unsigned DiscoverPluginsAtPath(const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback) override
Definition: LoadCommands.cpp:172
BuiltinCommandsModule::mCommands
CommandHash mCommands
Definition: LoadCommands.h:87