29#include <wx/tokenzr.h>
48#define REGVERKEY wxString(wxT("/pluginregistryversion"))
49#define REGROOT wxString(wxT("/pluginregistry/"))
52#define SETVERKEY wxString(wxT("/pluginsettingsversion"))
53#define SETVERCUR wxString(wxT("1.0"))
54#define SETROOT wxString(wxT("/pluginsettings/"))
56#define KEY_ID wxT("ID")
57#define KEY_PATH wxT("Path")
58#define KEY_SYMBOL wxT("Symbol")
59#define KEY_NAME wxT("Name")
60#define KEY_VENDOR wxT("Vendor")
61#define KEY_VERSION wxT("Version")
62#define KEY_DESCRIPTION wxT("Description")
63#define KEY_LASTUPDATED wxT("LastUpdated")
64#define KEY_ENABLED wxT("Enabled")
65#define KEY_VALID wxT("Valid")
66#define KEY_PROVIDERID wxT("ProviderID")
67#define KEY_EFFECTTYPE wxT("EffectType")
68#define KEY_EFFECTFAMILY wxT("EffectFamily")
69#define KEY_EFFECTDEFAULT wxT("EffectDefault")
70#define KEY_EFFECTINTERACTIVE wxT("EffectInteractive")
71#define KEY_EFFECTREALTIME wxT("EffectRealtime")
72#define KEY_EFFECTAUTOMATABLE wxT("EffectAutomatable")
73#define KEY_EFFECTTYPE_NONE wxT("None")
74#define KEY_EFFECTTYPE_ANALYZE wxT("Analyze")
75#define KEY_EFFECTTYPE_GENERATE wxT("Generate")
76#define KEY_EFFECTTYPE_PROCESS wxT("Process")
77#define KEY_EFFECTTYPE_TOOL wxT("Tool")
78#define KEY_EFFECTTYPE_HIDDEN wxT("Hidden")
79#define KEY_IMPORTERIDENT wxT("ImporterIdent")
81#define KEY_IMPORTEREXTENSIONS wxT("ImporterExtensions")
114 switch (
desc.GetPluginType() ) {
118 auto family =
desc.GetEffectFamily();
119 if ( family.empty() )
122 return wxT(
'/') + family + wxT(
"/Enable");
138 if (
auto &descriptor = pair.second; descriptor.GetPath() == path) {
140 descriptor.SetSymbol(
141 { descriptor.GetSymbol().
Internal(), *pName });
224 paths.push_back(ff.GetFullPath());
229#if defined(__WXMAC__)
236 ff.AppendDir(wxT(
"plug-ins"));
237 paths.push_back(ff.GetPath());
240 for (
const auto &filePath : pathList)
243 const wxString path{ ff.GetFullPath() };
244 if (paths.Index(path, wxFileName::IsCaseSensitive()) == wxNOT_FOUND)
246 paths.push_back(path);
251 for (
size_t i = 0, cnt = paths.size(); i < cnt; i++)
253 ff = paths[i] + wxFILE_SEP_PATH + pattern;
254 wxDir::GetAllFiles(ff.GetPath(), &files, ff.GetFullName(), directories ? wxDIR_DEFAULT : wxDIR_FILES);
346 auto &plug = pair.second;
347 const wxString & plugPath = plug.GetPath();
352 plug.SetValid(mm.
IsPluginValid(plug.GetProviderID(), plugPath,
true));
355 plug.SetEnabled(
false);
397 mm.DiscoverProviders();
398 for (
const auto &[
id, module] : mm.Providers()) {
401 module->AutoRegisterPlugins(*
this);
412 auto&
desc = p.second;
426 const wxFileName src{ fileName };
430 (mm.CreateProviderInstance(plug.GetID(), plug.GetPath()));
435 const auto &extensions = module->GetFileExtensions();
437 extensions.Index(src.GetExt(),
false) != wxNOT_FOUND ) {
441 module->DiscoverPluginsAtPath(fileName, errMsg, {});
451 dst.SetFullName( src.GetFullName() );
452 if ( dst.Exists() ) {
455 XO(
"Overwrite the plug-in file %s?")
456 .
Format( dst.GetFullPath() ),
459 .ButtonStyle(Button::YesNo)));
466 auto dstPath = dst.GetFullPath();
467 if ( src.FileExists() )
470 src.GetFullPath(), dstPath, true );
480 XO(
"Plug-in file is in use. Failed to overwrite") );
485 std::vector<PluginID> ids;
486 std::vector<wxString>
names;
487 nPlugIns = module->DiscoverPluginsAtPath(dstPath, errMsg,
495 names.push_back(
ident->GetSymbol().Translation() );
501 XO(
"Failed to register:\n%s").
Format( errMsg ) );
506 if (
auto nIds = ids.size()) {
510 "Enable this plug-in?\n",
511 "Enable these plug-ins?\n",
521 .ButtonStyle(Button::YesNo)));
522 for (
const auto &
id : ids)
540 auto ®istry = *pRegistry;
544 if (!registry.HasGroup(
REGROOT))
550 registry.DeleteAll();
566 wxString cfgPath =
REGROOT + group + wxCONFIG_PATH_SEPARATOR;
567 wxArrayString groupsToDelete;
569 registry.SetPath(cfgPath);
570 for (
bool cont = registry.GetFirstGroup(groupName, groupIndex);
572 registry.SetPath(cfgPath),
573 cont = registry.GetNextGroup(groupName, groupIndex))
575 registry.SetPath(groupName);
576 wxString effectSymbol = registry.Read(
KEY_SYMBOL,
"");
577 wxString effectVersion = registry.Read(
KEY_VERSION,
"");
589 }
else if ((effectSymbol ==
"Sample Data Export") && (effectVersion ==
"n/a")) {
590 groupsToDelete.push_back(cfgPath + groupName);
592 }
else if ((effectSymbol ==
"Sample Data Import") && (effectVersion ==
"n/a")) {
593 groupsToDelete.push_back(cfgPath + groupName);
600 for (
unsigned int i = 0; i < groupsToDelete.size(); i++) {
601 registry.DeleteGroup(groupsToDelete[i]);
603 registry.SetPath(
"");
632 wxFileName exeFn{ fullExePath };
634 exeFn.SetName(wxString{});
635 while(exeFn.GetDirCount() && !exeFn.GetDirs().back().EndsWith(
".app"))
636 exeFn.RemoveLastDir();
638 const auto goodPath = exeFn.GetPath();
640 if(exeFn.GetDirCount())
641 exeFn.RemoveLastDir();
642 const auto possiblyBadPath = exeFn.GetPath();
644 auto AcceptPath = [&](
const wxString &path) {
645 if (!path.StartsWith(possiblyBadPath))
648 if (path.StartsWith(goodPath))
654 auto AcceptPath = [](
const wxString&){
return true; };
662 wxString cfgPath =
REGROOT + group + wxCONFIG_PATH_SEPARATOR;
665 for (
bool cont = pRegistry->
GetFirstGroup(groupName, groupIndex);
681 plug.
SetID(groupName);
694 pRegistry->Read(
KEY_PATH, &strVal, wxEmptyString);
695 if (!AcceptPath(strVal))
759 pRegistry->Read(
KEY_VALID, &boolVal,
false);
843 wxStringTokenizer tkr(strVal, wxT(
":"));
844 while (tkr.HasMoreTokens())
846 extensions.push_back(tkr.GetNextToken());
882 auto ®istry = *pRegistry;
885 registry.DeleteAll();
919 auto & plug = pair.second;
921 if (plug.GetPluginType() != type)
928 pRegistry->Write(
KEY_PATH, plug.GetPath());
931 pRegistry->Write(
KEY_SYMBOL, plug.GetSymbol().Internal());
935 pRegistry->Write(
KEY_NAME, plug.GetSymbol().Msgid().MSGID());
937 pRegistry->Write(
KEY_VERSION, plug.GetUntranslatedVersion());
938 pRegistry->Write(
KEY_VENDOR, plug.GetVendor());
943 pRegistry->Write(
KEY_VALID, plug.IsValid());
979 const auto & extensions = plug.GetImporterExtensions();
981 for (
size_t i = 0, cnt = extensions.size(); i < cnt; i++)
983 strExt += extensions[i] + wxT(
":");
985 strExt.RemoveLast(1);
1001 std::unique_ptr<EffectDefinitionInterface> effect,
PluginType type)
1019 return plug.
GetID();
1031 return pair.second.GetPluginType() == type; });
1039 return &iter->second;
1050 if (!all && !(plug.IsValid() && plug.IsEnabled()))
1052 auto plugType = plug.GetPluginType();
1058 if (!(setting.empty() ||
gPrefs->Read( setting,
true )))
1076, mPluginType{ type }
1084, mEffectType{ type }
1100 return iter->second.IsEnabled();
1108 iter->second.SetEnabled(enable);
1118 return iter->second.GetSymbol();
1124 return it->second.get();
1128 auto&
desc = it->second;
1136 auto result = pluginInterface.get();
1147 wxArrayString pathIndex;
1149 auto &plug = pair.second;
1153 pathIndex.push_back(plug.GetPath().BeforeFirst(wxT(
';')));
1165 std::vector<std::pair<wxString, wxString>> newPaths;
1167 auto &plug = pair.second;
1168 const PluginID & plugID = plug.GetID();
1169 const wxString & plugPath = plug.GetPath();
1180 plug.SetEnabled(
false);
1181 plug.SetValid(
false);
1187 const auto paths = provider->FindModulePaths(*
this);
1188 for (
size_t i = 0, cnt = paths.size(); i < cnt; i++)
1190 wxString path = paths[i].BeforeFirst(wxT(
';'));
1192 newPaths.push_back(std::make_pair(plugID, path));
1199 plug.SetValid(mm.
IsPluginValid(plug.GetProviderID(), plugPath,
false));
1200 if (!plug.IsValid())
1201 plug.SetEnabled(
false);
1215 return wxString::Format(wxT(
"%s_%s_%s_%s_%s"),
1225 return wxString::Format(wxT(
"%s_%s_%s_%s_%s"),
1246 auto strings = wxSplit(ID,
'_');
1247 if (strings.size() == 5)
1262 str = wxT(
"Placeholder");
1268 str = wxT(
"Effect");
1271 str = wxT(
"Generic");
1274 str = wxT(
"Exporter");
1277 str = wxT(
"Importer");
1339 bool res =
settings->HasGroup(group);
1343 wxString oldPath =
settings->GetPath();
1354 if (group.empty() || !
HasGroup(group))
1368 subgroups.push_back(
name);
1387 const auto visitor = [&](
const auto var){
1388 const auto pVar = &var.get();
1390 using Type =
typename decltype(var)::type;
1391 const auto pDefval =
1392 std::get_if<std::reference_wrapper<const Type>>(&defval);
1393 if constexpr( std::is_same_v<Type, float> ) {
1396 *pVar =
static_cast<float>(temp);
1404 return Visit(visitor, var);
1412 const auto visitor = [&](
const auto value){
1415 return Visit(visitor, value);
1444 wxCONFIG_PATH_SEPARATOR +
1445 (shared ? wxT(
"shared") : wxT(
"private")) +
1446 wxCONFIG_PATH_SEPARATOR;
1456 wxFileName ff(group);
1457 if (!ff.GetName().empty())
1459 path += ff.GetFullPath(wxPATH_UNIX) + wxCONFIG_PATH_SEPARATOR;
1469 auto path =
Group(type, ID, group);
1482 if (ID.StartsWith(wxT(
"base64:")))
1484 wxString
id = ID.Mid(7);
1486 id = wxString::FromUTF8(buf.get(),
Base64::Decode(
id, buf.get()));
1490 const wxCharBuffer & buf = ID.ToUTF8();
@ Internal
Indicates internal failure from Audacity.
Toolkit-neutral facade for basic user interface services.
static const AudacityProject::AttachedObjects::RegisteredFactory key
const TranslatableString name
const TranslatableString desc
wxString PluginPath
type alias for identifying a Plugin supplied by a module, each module defining its own interpretation...
std::vector< RegistryPath > RegistryPaths
#define XPC(sing, plur, n, c)
auto Visit(Visitor &&vis, Variant &&var)
Mimic some of std::visit, for the case of one visitor only.
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
static CommandHandlerObject & ident(AudacityProject &project)
@ PluginTypeAudacityCommand
bool Regver_lt(const PluginRegistryVersion ®ver1, const PluginRegistryVersion ®ver2)
bool Regver_le(const PluginRegistryVersion ®ver1, const PluginRegistryVersion ®ver2)
wxString PluginRegistryVersion
Type of plugin registry version information.
#define KEY_EFFECTAUTOMATABLE
#define KEY_IMPORTEREXTENSIONS
#define KEY_EFFECTTYPE_TOOL
#define KEY_IMPORTERIDENT
#define KEY_EFFECTTYPE_GENERATE
#define KEY_EFFECTTYPE_PROCESS
#define KEY_EFFECTINTERACTIVE
#define KEY_EFFECTTYPE_HIDDEN
static PluginManager::FileConfigFactory sFactory
#define KEY_EFFECTREALTIME
#define KEY_EFFECTTYPE_NONE
#define KEY_EFFECTTYPE_ANALYZE
#define KEY_EFFECTDEFAULT
#define NYQUIST_PROMPT_ID
Generalized interface for discovery of plug-ins for one protocol.
static const AttachedProjectObjects::RegisteredFactory manager
static Settings & settings()
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
ComponentInterface provides name / vendor / version functions to identify plugins....
virtual PluginPath GetPath() const =0
virtual VendorSymbol GetVendor() const =0
TranslatableString GetName() const
virtual ComponentInterfaceSymbol GetSymbol() const =0
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
const wxString & Internal() const
const TranslatableString & Msgid() const
EffectDefinitionInterface is a ComponentInterface that adds some basic read-only information about ef...
virtual EffectType GetClassification() const
Determines which menu it appears in; default same as GetType().
virtual bool IsDefault() const =0
Whether the effect sorts "above the line" in the menus.
virtual bool IsInteractive() const =0
Whether the effect needs a dialog for entry of settings.
virtual bool SupportsAutomation() const =0
Whether the effect has any automatable controls.
virtual RealtimeSince RealtimeSupport() const =0
Since which version of Audacity has the effect supported realtime?
virtual EffectFamilySymbol GetFamily() const =0
Report identifier and user-visible name of the effect protocol.
virtual bool DeleteEntry(const wxString &key, bool bDeleteGroupIfEmpty=true) wxOVERRIDE
virtual bool GetNextGroup(wxString &str, long &lIndex) const wxOVERRIDE
virtual bool DeleteGroup(const wxString &key) wxOVERRIDE
virtual bool GetFirstGroup(wxString &str, long &lIndex) const wxOVERRIDE
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
virtual const wxString & GetPath() const wxOVERRIDE
virtual void SetPath(const wxString &strPath) wxOVERRIDE
An explicitly nonlocalized string, not meant for the user to see.
static ModuleManager & Get()
static PluginID GetID(PluginProvider *provider)
static wxString GetPluginTypeString()
PluginProvider * CreateProviderInstance(const PluginID &provider, const PluginPath &path)
bool IsProviderValid(const PluginID &provider, const PluginPath &path)
bool IsPluginValid(const PluginID &provider, const PluginPath &path, bool bFast)
void SetEnabled(bool enable)
void SetEffectLegacy(bool legacy)
void SetImporterExtensions(FileExtensions extensions)
const ComponentInterfaceSymbol & GetSymbol() const
PluginType GetPluginType() const
void SetVendor(const wxString &vendor)
void SetImporterIdentifier(const wxString &identifier)
wxString GetEffectFamily() const
void SetPath(const PluginPath &path)
void SetValid(bool valid)
const wxString & GetID() const
const wxString & GetVendor() const
void SetSymbol(const ComponentInterfaceSymbol &symbol)
void SetProviderID(const PluginID &providerID)
void SetID(const PluginID &ID)
void SetEffectType(EffectType type)
void SetEffectFamily(const wxString &family)
void SetPluginType(PluginType type)
void SetEffectAutomatable(bool automatable)
void SetEffectDefault(bool dflt)
void SetEffectInteractive(bool interactive)
void SetRealtimeSupport(EffectDefinitionInterface::RealtimeSince realtime)
void SetVersion(const wxString &version)
void DeserializeRealtimeSupport(const wxString &value)
for deserialization
void Advance(bool incrementing)
Iterator(PluginManager &manager)
Iterates all, even disabled.
const PluginManager & mPm
PluginMap::iterator mIterator
PluginManager maintains a list of all plug ins. That covers modules, effects, generators,...
static PluginID OldGetID(const EffectDefinitionInterface *effect)
bool GetConfigSubgroups(ConfigurationType type, const PluginID &ID, const RegistryPath &group, RegistryPaths &subgroups) override
bool HasConfigGroup(ConfigurationType type, const PluginID &ID, const RegistryPath &group)
bool IsPluginEnabled(const PluginID &ID)
bool GetConfigValue(ConfigurationType type, const PluginID &ID, const RegistryPath &group, const RegistryPath &key, ConfigReference var, ConfigConstReference defval) override
std::function< std::unique_ptr< FileConfig >(const FilePath &localFilename) > FileConfigFactory
PluginRegistryVersion mRegver
void SaveGroup(FileConfig *pRegistry, PluginType type)
void Initialize(FileConfigFactory factory)
bool IsPluginRegistered(const PluginPath &path, const TranslatableString *pSymbol) override
Was the plugin registry already populated for a path (maybe from loading the config file)?
bool IsPluginLoaded(const wxString &ID) const
void LoadGroup(FileConfig *pRegistry, PluginType type)
RegistryPath Group(ConfigurationType type, const PluginID &ID, const RegistryPath &group)
bool HasConfigValue(ConfigurationType type, const PluginID &ID, const RegistryPath &group, const RegistryPath &key) override
void Save()
Save to preferences.
void UnregisterPlugin(const PluginID &ID)
void FindFilesInPathList(const wxString &pattern, const FilePaths &pathList, FilePaths &files, bool directories=false) override
bool GetSubgroups(const RegistryPath &group, RegistryPaths &subgroups)
std::vector< std::pair< wxString, wxString > > CheckPluginUpdates()
Ensures that all currently registered plugins still exist and scans for new ones.
FileConfig * GetSettings()
static Identifier GetEffectNameFromID(const PluginID &ID)
static PluginID GetID(PluginProvider *provider)
bool HasGroup(const RegistryPath &group)
void Load()
Load from preferences.
Range PluginsOfType(int type)
PluginDescriptor & CreatePlugin(const PluginID &id, ComponentInterface *ident, PluginType type)
const PluginRegistryVersion & GetRegistryVersion() const override
RegistryPath Key(ConfigurationType type, const PluginID &ID, const RegistryPath &group, const RegistryPath &key)
static std::unique_ptr< PluginManager > mInstance
RegistryPath GetPluginEnabledSetting(const PluginID &ID) const
bool DropFile(const wxString &fileName)
const PluginDescriptor * GetPlugin(const PluginID &ID) const
void EnablePlugin(const PluginID &ID, bool enable)
void RegisterPlugin(PluginDescriptor &&desc)
bool RemoveConfig(ConfigurationType type, const PluginID &ID, const RegistryPath &group, const RegistryPath &key) override
std::unique_ptr< FileConfig > mSettings
PluginMap mRegisteredPlugins
wxString ConvertID(const PluginID &ID)
RegistryPath SettingsPath(ConfigurationType type, const PluginID &ID)
bool SetConfigValue(ConfigurationType type, const PluginID &ID, const RegistryPath &group, const RegistryPath &key, ConfigConstReference value) override
int GetPluginCount(PluginType type)
static wxString GetPluginTypeString(PluginType type)
bool RemoveConfigSubgroup(ConfigurationType type, const PluginID &ID, const RegistryPath &group) override
std::map< PluginID, std::unique_ptr< ComponentInterface > > mLoadedInterfaces
const ComponentInterfaceSymbol & GetSymbol(const PluginID &ID)
static PluginManager & Get()
static const PluginID & AudacityCommandRegistrationCallback(PluginProvider *provider, ComponentInterface *ident)
PluginSettings::ConfigReference ConfigReference
static const PluginID & DefaultRegistrationCallback(PluginProvider *provider, ComponentInterface *ident)
PluginSettings::ConfigConstReference ConfigConstReference
virtual EffectFamilySymbol GetOptionalFamilySymbol()=0
A symbol identifying the family of plug-ins provided by this.
virtual std::unique_ptr< ComponentInterface > LoadPlugin(const PluginPath &path)=0
Load the plug-in at a path reported by DiscoverPluginsAtPath.
virtual FilePath InstallPath()=0
Where plug-in files should be copied to install them.
Holds a msgid for the translation catalog; may also bind format arguments.
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
STRINGS_API wxString Encode(const void *in, int len)
STRINGS_API int Decode(const wxString &in, void *out)
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
FILES_API FilePath PlugInDir()
The user plug-in directory (not a system one)
FILES_API bool DoCopyFile(const FilePath &file1, const FilePath &file2, bool overwrite=true)
FILES_API FilePath PluginRegistry()
FILES_API FilePath PluginSettings()
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
MessageBoxOptions && Caption(TranslatableString caption_) &&