29#include <wx/tokenzr.h>
49#define REGVERKEY wxString(wxT("/pluginregistryversion"))
50#define REGROOT wxString(wxT("/pluginregistry/"))
53#define SETVERKEY wxString(wxT("/pluginsettingsversion"))
54#define SETVERCUR wxString(wxT("1.0"))
55#define SETROOT wxString(wxT("/pluginsettings/"))
57#define KEY_ID wxT("ID")
58#define KEY_PATH wxT("Path")
59#define KEY_SYMBOL wxT("Symbol")
60#define KEY_NAME wxT("Name")
61#define KEY_VENDOR wxT("Vendor")
62#define KEY_VERSION wxT("Version")
63#define KEY_DESCRIPTION wxT("Description")
64#define KEY_LASTUPDATED wxT("LastUpdated")
65#define KEY_ENABLED wxT("Enabled")
66#define KEY_VALID wxT("Valid")
67#define KEY_PROVIDERID wxT("ProviderID")
68#define KEY_EFFECTTYPE wxT("EffectType")
69#define KEY_EFFECTFAMILY wxT("EffectFamily")
70#define KEY_EFFECTDEFAULT wxT("EffectDefault")
71#define KEY_EFFECTINTERACTIVE wxT("EffectInteractive")
72#define KEY_EFFECTREALTIME wxT("EffectRealtime")
73#define KEY_EFFECTAUTOMATABLE wxT("EffectAutomatable")
74#define KEY_EFFECTTYPE_NONE wxT("None")
75#define KEY_EFFECTTYPE_ANALYZE wxT("Analyze")
76#define KEY_EFFECTTYPE_GENERATE wxT("Generate")
77#define KEY_EFFECTTYPE_PROCESS wxT("Process")
78#define KEY_EFFECTTYPE_TOOL wxT("Tool")
79#define KEY_EFFECTTYPE_HIDDEN wxT("Hidden")
80#define KEY_IMPORTERIDENT wxT("ImporterIdent")
82#define KEY_IMPORTEREXTENSIONS wxT("ImporterExtensions")
115 switch (
desc.GetPluginType() ) {
119 auto family =
desc.GetEffectFamily();
120 if ( family.empty() )
123 return wxT(
'/') + family +
wxT(
"/Enable");
139 if (
auto &descriptor = pair.second; descriptor.GetPath() == path) {
141 descriptor.SetSymbol(
142 { descriptor.GetSymbol().
Internal(), *pName });
225 paths.push_back(ff.GetFullPath());
230#if defined(__WXMAC__)
237 ff.AppendDir(
wxT(
"plug-ins"));
238 paths.push_back(ff.GetPath());
241 for (
const auto &filePath : pathList)
244 const wxString path{ ff.GetFullPath() };
245 if (paths.Index(path, wxFileName::IsCaseSensitive()) == wxNOT_FOUND)
247 paths.push_back(path);
252 for (
size_t i = 0, cnt = paths.size(); i < cnt; i++)
254 ff = paths[i] + wxFILE_SEP_PATH + pattern;
255 wxDir::GetAllFiles(ff.GetPath(), &files, ff.GetFullName(), directories ? wxDIR_DEFAULT : wxDIR_FILES);
349 auto &pluginDesc = it->second;
350 const auto pluginType = pluginDesc.GetPluginType();
357 if(!moduleManager.
CheckPluginExist(pluginDesc.GetProviderID(), pluginDesc.GetPath()))
400 mm.DiscoverProviders();
401 for (
auto& [
id, module] : mm.Providers()) {
404 module->AutoRegisterPlugins(*
this);
415 auto&
desc = p.second;
429 const wxFileName src{ fileName };
433 (mm.CreateProviderInstance(plug.GetID(), plug.GetPath()));
438 const auto &extensions = module->GetFileExtensions();
440 extensions.Index(src.GetExt(),
false) != wxNOT_FOUND ) {
444 module->DiscoverPluginsAtPath(fileName, errMsg, {});
454 dst.SetFullName( src.GetFullName() );
455 if ( dst.Exists() ) {
458 XO(
"Overwrite the plug-in file %s?")
459 .
Format( dst.GetFullPath() ),
462 .ButtonStyle(Button::YesNo)));
469 auto dstPath = dst.GetFullPath();
470 if ( src.FileExists() )
473 src.GetFullPath(), dstPath, true );
483 XO(
"Plug-in file is in use. Failed to overwrite") );
488 std::vector<PluginID> ids;
489 std::vector<wxString>
names;
490 nPlugIns = module->DiscoverPluginsAtPath(dstPath, errMsg,
498 names.push_back(
ident->GetSymbol().Translation() );
504 XO(
"Failed to register:\n%s").
Format( errMsg ) );
509 if (
auto nIds = ids.size()) {
513 "Enable this plug-in?\n",
514 "Enable these plug-ins?\n",
524 .ButtonStyle(Button::YesNo)));
525 for (
const auto &
id : ids)
544 auto ®istry = *pRegistry;
548 if (!registry.HasGroup(
REGROOT))
568 wxString cfgPath =
REGROOT + group + wxCONFIG_PATH_SEPARATOR;
569 wxArrayString groupsToDelete;
571 auto cfgGroup = registry.BeginGroup(cfgPath);
572 for(
const auto& groupName : registry.GetChildGroups())
574 auto effectGroup = registry.BeginGroup(groupName);
575 wxString effectSymbol = registry.Read(
KEY_SYMBOL,
"");
576 wxString effectVersion = registry.Read(
KEY_VERSION,
"");
588 }
else if ((effectSymbol ==
"Sample Data Export") && (effectVersion ==
"n/a")) {
589 groupsToDelete.push_back(cfgPath + groupName);
591 }
else if ((effectSymbol ==
"Sample Data Import") && (effectVersion ==
"n/a")) {
592 groupsToDelete.push_back(cfgPath + groupName);
598 for (
unsigned int i = 0; i < groupsToDelete.size(); i++) {
599 registry.DeleteGroup(groupsToDelete[i]);
629 wxFileName exeFn{ fullExePath };
631 exeFn.SetName(wxString{});
632 while(exeFn.GetDirCount() && !exeFn.GetDirs().back().EndsWith(
".app"))
633 exeFn.RemoveLastDir();
635 const auto goodPath = exeFn.GetPath();
637 if(exeFn.GetDirCount())
638 exeFn.RemoveLastDir();
639 const auto possiblyBadPath = exeFn.GetPath();
641 auto AcceptPath = [&](
const wxString &path) {
642 if (!path.StartsWith(possiblyBadPath))
645 if (path.StartsWith(goodPath))
651 auto AcceptPath = [](
const wxString&){
return true; };
658 const auto cfgGroup = pRegistry->
BeginGroup(cfgPath);
662 const auto effectGroup = pRegistry->
BeginGroup(group);
671 plug.
SetID(groupName);
685 if (!AcceptPath(strVal))
833 wxStringTokenizer tkr(strVal,
wxT(
":"));
834 while (tkr.HasMoreTokens())
836 extensions.push_back(tkr.GetNextToken());
872 auto ®istry = *pRegistry;
914 auto & plug = pair.second;
916 if (plug.GetPluginType() != type)
930 pRegistry->
Write(
KEY_NAME, plug.GetSymbol().Msgid().MSGID());
974 const auto & extensions = plug.GetImporterExtensions();
976 for (
size_t i = 0, cnt = extensions.size(); i < cnt; i++)
978 strExt += extensions[i] +
wxT(
":");
980 strExt.RemoveLast(1);
996 std::unique_ptr<EffectDefinitionInterface> effect,
PluginType type)
1014 return plug.
GetID();
1026 return pair.second.GetPluginType() == type; });
1032 return &iter->second;
1036 return plug.
GetID() == ID;
1052 if (!all && !(plug.IsValid() && plug.IsEnabled()))
1054 auto plugType = plug.GetPluginType();
1060 if (!(setting.empty() ||
gPrefs->
Read( setting,
true )))
1078, mPluginType{ type }
1086, mEffectType{ type }
1102 return iter->second.IsEnabled();
1110 iter->second.SetEnabled(enable);
1120 return iter->second.GetSymbol();
1126 return it->second.get();
1130 auto&
desc = it->second;
1138 auto result = pluginInterface.get();
1152 const auto&
desc = it->second;
1153 const auto type =
desc.GetPluginType();
1169 provider->AutoRegisterPlugins(*
this);
1183 wxArrayString pathIndex;
1185 auto &plug = pair.second;
1189 pathIndex.push_back(plug.GetPath().BeforeFirst(
wxT(
';')));
1202 std::map<wxString, std::vector<wxString>> newPaths;
1203 for(
auto& [
id, provider] : moduleManager.Providers())
1205 const auto paths = provider->FindModulePaths(*
this);
1206 for(
const auto& path : paths)
1208 const auto modulePath = path.BeforeFirst(
';');
1211 return plug.
GetPath().BeforeFirst(
wxT(
';')) == modulePath;
1215 newPaths[modulePath].push_back(
id);
1230 return wxString::Format(
wxT(
"%s_%s_%s_%s_%s"),
1240 return wxString::Format(
wxT(
"%s_%s_%s_%s_%s"),
1261 auto strings = wxSplit(ID,
'_');
1262 if (strings.size() == 5)
1277 str =
wxT(
"Placeholder");
1307 if (provider ==
nullptr)
1309 wxLogWarning(
"Unable to find a provider for '%s'", providerID);
1313 if (provider->CheckPluginExist(plug.
GetPath()) ==
false)
1315 wxLogWarning(
"Plugin '%s' does not exist", plug.
GetID());
1377 auto group =
settings->BeginGroup(groupName);
1378 return !
settings->GetChildGroups().empty() || !
settings->GetChildKeys().empty();
1383 if (groupName.empty() || !
HasGroup(groupName))
1390 subgroups.push_back(
name);
1400template<
typename T>
class TD;
1408 const auto visitor = [&](
const auto var){
1409 const auto pVar = &var.get();
1411 using Type =
typename decltype(var)::type;
1412 const auto pDefval =
1413 std::get_if<std::reference_wrapper<const Type>>(&defval);
1418 return Visit(visitor, var);
1427 const auto visitor = [&](
const auto value){
1430 return Visit(visitor, value);
1459 wxCONFIG_PATH_SEPARATOR +
1460 (shared ?
wxT(
"shared") :
wxT(
"private")) +
1461 wxCONFIG_PATH_SEPARATOR;
1471 wxFileName ff(group);
1472 if (!ff.GetName().empty())
1474 path += ff.GetFullPath(wxPATH_UNIX) + wxCONFIG_PATH_SEPARATOR;
1484 auto path =
Group(type, ID, group);
1497 if (ID.StartsWith(
wxT(
"base64:")))
1499 wxString
id = ID.Mid(7);
1501 id = wxString::FromUTF8(buf.get(),
Base64::Decode(
id, buf.get()));
1505 const wxCharBuffer & buf = ID.ToUTF8();
@ Internal
Indicates internal failure from Audacity.
Toolkit-neutral facade for basic user interface services.
const TranslatableString name
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)
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
static PluginManager::ConfigFactory sFactory
#define KEY_EFFECTTYPE_GENERATE
#define KEY_EFFECTTYPE_PROCESS
#define KEY_EFFECTINTERACTIVE
#define KEY_EFFECTTYPE_HIDDEN
#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.
audacity::BasicSettings * gPrefs
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.
emulates std::visit for one visitor
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.
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 CheckPluginExist(const PluginID &providerId, const PluginPath &path)
CallbackReturn Publish(const PluginsChangedMessage &message)
Send a message to connected callbacks.
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)
const PluginPath & GetPath() const
void SetID(const PluginID &ID)
void SetEffectType(EffectType type)
void SetEffectFamily(const wxString &family)
void SetPluginType(PluginType type)
const wxString & GetProviderID() const
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::vector< PluginDescriptor > mEffectPluginsCleared
void ClearEffectPlugins()
PluginRegistryVersion mRegver
std::map< wxString, std::vector< wxString > > CheckPluginUpdates()
Ensures that all currently registered plugins still exist and scans for new ones.
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
RegistryPath Group(ConfigurationType type, const PluginID &ID, const RegistryPath &group)
bool HasConfigValue(ConfigurationType type, const PluginID &ID, const RegistryPath &group, const RegistryPath &key) override
std::function< std::unique_ptr< audacity::BasicSettings >(const FilePath &localFilename) > ConfigFactory
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)
static Identifier GetEffectNameFromID(const PluginID &ID)
static PluginID GetID(PluginProvider *provider)
bool HasGroup(const RegistryPath &group)
void LoadGroup(audacity::BasicSettings *pRegistry, PluginType type)
void Load()
Load from preferences.
Range PluginsOfType(int type)
PluginDescriptor & CreatePlugin(const PluginID &id, ComponentInterface *ident, PluginType type)
static bool IsPluginAvailable(const PluginDescriptor &plug)
const PluginRegistryVersion & GetRegistryVersion() const override
RegistryPath Key(ConfigurationType type, const PluginID &ID, const RegistryPath &group, const RegistryPath &key)
static std::unique_ptr< PluginManager > mInstance
void Initialize(ConfigFactory factory)
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
audacity::BasicSettings * GetSettings()
void SaveGroup(audacity::BasicSettings *pRegistry, PluginType type)
PluginMap mRegisteredPlugins
wxString ConvertID(const PluginID &ID)
std::unique_ptr< audacity::BasicSettings > mSettings
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)
void NotifyPluginsChanged()
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.
Base class for objects that provide facility to store data persistently, and access it with string ke...
virtual bool Flush() noexcept=0
virtual bool Exists(const wxString &key) const
Returns true if group or entry exists.
GroupScope BeginGroup(const wxString &prefix)
Appends a prefix to the current group or sets a new absolute path. Group that was set as current befo...
bool DeleteGroup(const wxString &key)
Deletes specified group if exists.
virtual bool Write(const wxString &key, bool value)=0
bool DeleteEntry(const wxString &key)
Deletes specified entry if exists.
virtual bool Read(const wxString &key, bool *value) const =0
virtual wxArrayString GetChildGroups() const =0
Returns all child groups within the current group.
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.
const TranslatableString desc
static RegisteredToolbarFactory factory
MessageBoxOptions && Caption(TranslatableString caption_) &&