Audacity 3.2.0
ModuleInterface.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 ModuleInterface.h
6
7 Leland Lucius
8
9 Copyright (c) 2014, Audacity Team
10 All rights reserved.
11
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions
14 are met:
15
16 1. Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
18
19 2. Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the distribution.
22
23 3. Neither the name of the copyright holder nor the names of its
24 contributors may be used to endorse or promote products derived from
25 this software without specific prior written permission.
26
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 POSSIBILITY OF SUCH DAMAGE.
39
40**********************************************************************/
41
42#ifndef __AUDACITY_MODULEINTERFACE_H__
43#define __AUDACITY_MODULEINTERFACE_H__
44
45#include <functional>
46#include <memory>
47#include "Identifier.h"
48#include "ComponentInterface.h"
50
51using PluginID = wxString;
52using PluginIDs = wxArrayString;
53// Incomplete type not defined in libraries -- TODO clean that up:
55
56// ============================================================================
57//
58// Don't even think about adding module types, like effect, importer, etc. in
59// here. The module interface should not have to change when new types of
60// plugins are added to Audacity.
61//
62// In addition a single module may want to provide multiple plugin types.
63// ============================================================================
64
65// ============================================================================
71// ============================================================================
72
73class COMPONENTS_API ModuleInterface /* not final */
74 : public ComponentInterface
75{
76public:
78
79 // Called immediately after creation to give the instance a chance to
80 // initialize. Return "true" if initialziation was successful.
81 virtual bool Initialize() = 0;
82
83 // Called just prior to deletion to allow releasing any resources.
84 virtual void Terminate() = 0;
85
86 // A symbol identifying the family of plugin provided by this module;
87 // if it is not empty, then the family as a whole can be enabled or
88 // disabled by the user in Preferences
90
91 // "Paths" returned by FindPluginPaths() and passed back to
92 // DiscoverPluginsAtPath() have module-specific meaning.
93 // They are not necessarily file system paths to existent files that
94 // could be placed in any folder and queried for
95 // plugin information.
96 // This function returns nonempty only when that is the case, and lists
97 // the possible extensions of such files (an empty string in a nonempty
98 // array means any file is a candidate).
99 virtual const FileExtensions &GetFileExtensions() = 0;
100
101 // Returns empty, or else, where to copy a plug-in file or bundle.
102 // Drag-and-drop is supported only if GetFileExtensions() returns nonempty and
103 // this function returns nonempty.
104 virtual FilePath InstallPath() = 0;
105
106 // Modules providing a single or static set of plugins may use
107 // AutoRegisterPlugins() to register those plugins.
108 virtual bool AutoRegisterPlugins(PluginManagerInterface & pluginManager) = 0;
109
110 // For modules providing an interface to other dynamically loaded plugins,
111 // the module returns a list of path names that will be presented to the
112 // user as "New" for enablement.
114
115 // Once the user selects desired paths from FindPluginPaths(),
116 // a call to DiscoverPluginsAtPath()
117 // will be made to request registration of one or more plugins. If the module must create
118 // an instance of the plugin to register it, then the instance should be deleted
119 // after registration.
120 // May discover more than one plug-in at the path, and
121 // may call-back with paths not equal to path (perhaps appending
122 // other information to it).
123 // Error message does not need to mention the path and may be nonempty
124 // even if some plugins are also discovered successfully.
125 // Return value is the number of plugins found.
127 std::function<
129 virtual unsigned DiscoverPluginsAtPath(
130 const PluginPath & path, TranslatableString &errMsg,
131 const RegistrationCallback &callback )
132 = 0;
133
134 // For modules providing an interface to other dynamically loaded plugins,
135 // the module returns true if the plugin is still valid, otherwise false.
136 virtual bool IsPluginValid(const PluginPath & path, bool bFast) = 0;
137
138 // When appropriate, CreateInstance() will be called to instantiate the plugin.
139 virtual std::unique_ptr<ComponentInterface>
140 CreateInstance(const PluginPath & path) = 0;
141};
142
143// ----------------------------------------------------------------------------
144// Since there may be multiple embedded modules, the module entry function will
145// be declared static so as not to interfere with other modules during link.
146// ----------------------------------------------------------------------------
147#define DECLARE_MODULE_ENTRY(name) \
148static ModuleInterface * name()
149
150// ----------------------------------------------------------------------------
151// This will create a class and instance that will register the module entry
152// point during Audacity startup. At the appropriate time, the entry point
153// will be called to create the module instance.
154// ----------------------------------------------------------------------------
155
156// ----------------------------------------------------------------------------
157// Provides the base for embedded module registration. If used, a Register()
158// method must be supplied explicitly.
159// ----------------------------------------------------------------------------
160
161#define DECLARE_BUILTIN_MODULE_BASE(name) \
162class name \
163{ \
164public: \
165 name() {Register();} \
166 ~name() {Unregister();} \
167 void Register(); \
168 void Unregister(); \
169}; \
170static name name ## _instance;
171
172// ----------------------------------------------------------------------------
173// Provides the full embedded module registration process. Nothing further is
174// required (other than supplying the module entry point function).
175// ----------------------------------------------------------------------------
176#define DECLARE_BUILTIN_MODULE(name) \
177DECLARE_BUILTIN_MODULE_BASE(name) \
178void name::Register() \
179{ \
180 RegisterProvider(AudacityModule); \
181} \
182void name::Unregister() \
183{ \
184 UnregisterProvider(AudacityModule); \
185}
186
187#endif // __AUDACITY_MODULEINTERFACE_H__
wxString PluginID
Definition: EffectManager.h:30
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
wxArrayString PluginIDs
Definition: Menus.h:33
wxString FilePath
Definition: Project.h:20
ComponentInterface provides name / vendor / version functions to identify plugins....
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
virtual ~ModuleInterface()
virtual PluginPaths FindPluginPaths(PluginManagerInterface &pluginManager)=0
virtual const FileExtensions & GetFileExtensions()=0
virtual unsigned DiscoverPluginsAtPath(const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback)=0
std::function< const PluginID &(ModuleInterface *, ComponentInterface *) > RegistrationCallback
virtual FilePath InstallPath()=0
virtual std::unique_ptr< ComponentInterface > CreateInstance(const PluginPath &path)=0
virtual bool AutoRegisterPlugins(PluginManagerInterface &pluginManager)=0
virtual bool IsPluginValid(const PluginPath &path, bool bFast)=0
virtual bool Initialize()=0
virtual EffectFamilySymbol GetOptionalFamilySymbol()=0
virtual void Terminate()=0
Holds a msgid for the translation catalog; may also bind format arguments.
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.