1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-19 17:40:15 +02:00

Drag-and-drop checks file extensions first for plug-in candidates...

... Avoids big delays in drag-and-drop importation caused by
765ca0c8136134a1d65bfad0ea39682a83d3d984
This commit is contained in:
Paul Licameli 2018-01-01 10:29:26 -05:00
parent 2cdf931e5a
commit 3c9cdac778
13 changed files with 63 additions and 13 deletions

View File

@ -87,12 +87,15 @@ public:
// DiscoverPluginsAtPath() have module-specific meaning. // DiscoverPluginsAtPath() have module-specific meaning.
// They are not necessarily file system paths to existent files that // They are not necessarily file system paths to existent files that
// could be placed in any folder and queried for // could be placed in any folder and queried for
// plugin information. This function returns true when that is the case. // plugin information.
virtual bool PathsAreFiles() = 0; // This function returns nonempty only when that is the case, and lists
// the possible extensions of such files (an empty string in a nonempty
// array means any file is a candidate).
virtual wxArrayString FileExtensions() = 0;
// Returns empty, or else, where to copy a plug-in file or bundle. // Returns empty, or else, where to copy a plug-in file or bundle.
// Drag-and-drop is supported only if PathsAreFiles() is true and this // Drag-and-drop is supported only if FileExtensions() returns nonempty and
// function returns nonempty. // this function returns nonempty.
virtual wxString InstallPath() = 0; virtual wxString InstallPath() = 0;
// Modules providing a single or static set of plugins may use // Modules providing a single or static set of plugins may use

View File

@ -1750,6 +1750,7 @@ void PluginManager::Terminate()
bool PluginManager::DropFile(const wxString &fileName) bool PluginManager::DropFile(const wxString &fileName)
{ {
auto &mm = ModuleManager::Get(); auto &mm = ModuleManager::Get();
const wxFileName src{ fileName };
for (const PluginDescriptor *plug = GetFirstPlugin(PluginTypeModule); for (const PluginDescriptor *plug = GetFirstPlugin(PluginTypeModule);
plug; plug;
@ -1758,7 +1759,9 @@ bool PluginManager::DropFile(const wxString &fileName)
auto module = static_cast<ModuleInterface *> auto module = static_cast<ModuleInterface *>
(mm.CreateProviderInstance(plug->GetID(), plug->GetPath())); (mm.CreateProviderInstance(plug->GetID(), plug->GetPath()));
const auto &ff = module->InstallPath(); const auto &ff = module->InstallPath();
if (!ff.empty() && module->PathsAreFiles()) { auto extensions = module->FileExtensions();
if (!ff.empty() &&
make_iterator_range(extensions).contains(src.GetExt())) {
wxString errMsg; wxString errMsg;
// Do dry-run test of the file format // Do dry-run test of the file format
unsigned nPlugIns = unsigned nPlugIns =
@ -1770,7 +1773,6 @@ bool PluginManager::DropFile(const wxString &fileName)
// actions should not be tried. // actions should not be tried.
// Find path to copy it // Find path to copy it
const wxFileName src{ fileName };
wxFileName dst; wxFileName dst;
dst.AssignDir( ff ); dst.AssignDir( ff );
dst.SetFullName( src.GetFullName() ); dst.SetFullName( src.GetFullName() );

View File

@ -41,7 +41,7 @@ public:
bool Initialize() override; bool Initialize() override;
void Terminate() override; void Terminate() override;
bool PathsAreFiles() override { return false; } wxArrayString FileExtensions() override { return {}; }
wxString InstallPath() override { return {}; } wxString InstallPath() override { return {}; }
bool AutoRegisterPlugins(PluginManagerInterface & pm) override; bool AutoRegisterPlugins(PluginManagerInterface & pm) override;

View File

@ -351,6 +351,13 @@ void VSTEffectsModule::Terminate()
return; return;
} }
wxArrayString VSTEffectsModule::FileExtensions()
{
static const wxString ext[] = { _T("vst") };
static const wxArrayString result{ sizeof(ext)/sizeof(*ext), ext };
return result;
}
wxString VSTEffectsModule::InstallPath() wxString VSTEffectsModule::InstallPath()
{ {
// Not yet ready for VST drag-and-drop... // Not yet ready for VST drag-and-drop...

View File

@ -391,7 +391,7 @@ public:
bool Initialize() override; bool Initialize() override;
void Terminate() override; void Terminate() override;
bool PathsAreFiles() override { return true; } wxArrayString FileExtensions() override;
wxString InstallPath() override; wxString InstallPath() override;
bool AutoRegisterPlugins(PluginManagerInterface & pm) override; bool AutoRegisterPlugins(PluginManagerInterface & pm) override;

View File

@ -140,6 +140,13 @@ wxString AudioUnitEffectsModule::GetDescription()
// ModuleInterface implementation // ModuleInterface implementation
// ============================================================================ // ============================================================================
wxArrayString AudioUnitEffectsModule::FileExtensions()
{
static const wxString ext[] = { _T("au") };
static const wxArrayString result{ sizeof(ext)/sizeof(*ext), ext };
return result;
}
bool AudioUnitEffectsModule::Initialize() bool AudioUnitEffectsModule::Initialize()
{ {
// Nothing to do here // Nothing to do here

View File

@ -243,7 +243,7 @@ public:
bool Initialize() override; bool Initialize() override;
void Terminate() override; void Terminate() override;
bool PathsAreFiles() override { return false; } wxArrayString FileExtensions() override;
wxString InstallPath() override { return {}; } wxString InstallPath() override { return {}; }
bool AutoRegisterPlugins(PluginManagerInterface & pm) override; bool AutoRegisterPlugins(PluginManagerInterface & pm) override;

View File

@ -155,6 +155,30 @@ void LadspaEffectsModule::Terminate()
return; return;
} }
wxArrayString LadspaEffectsModule::FileExtensions()
{
static const wxString ext[] = {
#ifdef __WXMSW__
{ _T("dll") }
#else
{ _T("so") }
#ifdef __WXMAC__
// Is it correct that these are candidate plug-in files too for macOs?
, { _T("dylib") }
#endif
#endif
};
static const wxArrayString result{ sizeof(ext)/sizeof(*ext), ext };
return result;
}
wxString LadspaEffectsModule::InstallPath() wxString LadspaEffectsModule::InstallPath()
{ {
// To do: better choice // To do: better choice

View File

@ -223,7 +223,7 @@ public:
bool Initialize() override; bool Initialize() override;
void Terminate() override; void Terminate() override;
bool PathsAreFiles() override { return true; } wxArrayString FileExtensions() override;
wxString InstallPath() override; wxString InstallPath() override;
bool AutoRegisterPlugins(PluginManagerInterface & pm) override; bool AutoRegisterPlugins(PluginManagerInterface & pm) override;

View File

@ -88,7 +88,7 @@ public:
bool Initialize() override; bool Initialize() override;
void Terminate() override; void Terminate() override;
bool PathsAreFiles() override { return false; } wxArrayString FileExtensions() override { return {}; }
wxString InstallPath() override { return {}; } wxString InstallPath() override { return {}; }
bool AutoRegisterPlugins(PluginManagerInterface & pm) override; bool AutoRegisterPlugins(PluginManagerInterface & pm) override;

View File

@ -160,6 +160,13 @@ void NyquistEffectsModule::Terminate()
return; return;
} }
wxArrayString NyquistEffectsModule::FileExtensions()
{
static const wxString ext[] = { _T("ny") };
static const wxArrayString result{ sizeof(ext)/sizeof(*ext), ext };
return result;
}
wxString NyquistEffectsModule::InstallPath() wxString NyquistEffectsModule::InstallPath()
{ {
return FileNames::PlugInDir(); return FileNames::PlugInDir();

View File

@ -38,7 +38,7 @@ public:
bool Initialize() override; bool Initialize() override;
void Terminate() override; void Terminate() override;
bool PathsAreFiles() override { return true; } wxArrayString FileExtensions() override;
wxString InstallPath() override; wxString InstallPath() override;
bool AutoRegisterPlugins(PluginManagerInterface & pm) override; bool AutoRegisterPlugins(PluginManagerInterface & pm) override;

View File

@ -42,7 +42,7 @@ public:
bool Initialize() override; bool Initialize() override;
void Terminate() override; void Terminate() override;
bool PathsAreFiles() override { return false; } wxArrayString FileExtensions() override { return {}; }
wxString InstallPath() override { return {}; } wxString InstallPath() override { return {}; }
bool AutoRegisterPlugins(PluginManagerInterface & pm) override; bool AutoRegisterPlugins(PluginManagerInterface & pm) override;