From 3c9cdac778db83388c0a15ea371a60dd54ef8b02 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Mon, 1 Jan 2018 10:29:26 -0500 Subject: [PATCH] Drag-and-drop checks file extensions first for plug-in candidates... ... Avoids big delays in drag-and-drop importation caused by 765ca0c8136134a1d65bfad0ea39682a83d3d984 --- include/audacity/ModuleInterface.h | 11 ++++++---- src/PluginManager.cpp | 6 ++++-- src/effects/LoadEffects.h | 2 +- src/effects/VST/VSTEffect.cpp | 7 +++++++ src/effects/VST/VSTEffect.h | 2 +- src/effects/audiounits/AudioUnitEffect.cpp | 7 +++++++ src/effects/audiounits/AudioUnitEffect.h | 2 +- src/effects/ladspa/LadspaEffect.cpp | 24 ++++++++++++++++++++++ src/effects/ladspa/LadspaEffect.h | 2 +- src/effects/lv2/LoadLV2.h | 2 +- src/effects/nyquist/LoadNyquist.cpp | 7 +++++++ src/effects/nyquist/LoadNyquist.h | 2 +- src/effects/vamp/LoadVamp.h | 2 +- 13 files changed, 63 insertions(+), 13 deletions(-) diff --git a/include/audacity/ModuleInterface.h b/include/audacity/ModuleInterface.h index b1ec9d11e..40d7cce18 100644 --- a/include/audacity/ModuleInterface.h +++ b/include/audacity/ModuleInterface.h @@ -87,12 +87,15 @@ public: // DiscoverPluginsAtPath() have module-specific meaning. // They are not necessarily file system paths to existent files that // could be placed in any folder and queried for - // plugin information. This function returns true when that is the case. - virtual bool PathsAreFiles() = 0; + // plugin information. + // 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. - // Drag-and-drop is supported only if PathsAreFiles() is true and this - // function returns nonempty. + // Drag-and-drop is supported only if FileExtensions() returns nonempty and + // this function returns nonempty. virtual wxString InstallPath() = 0; // Modules providing a single or static set of plugins may use diff --git a/src/PluginManager.cpp b/src/PluginManager.cpp index 8e8239cba..ba2cc5bfb 100644 --- a/src/PluginManager.cpp +++ b/src/PluginManager.cpp @@ -1750,6 +1750,7 @@ void PluginManager::Terminate() bool PluginManager::DropFile(const wxString &fileName) { auto &mm = ModuleManager::Get(); + const wxFileName src{ fileName }; for (const PluginDescriptor *plug = GetFirstPlugin(PluginTypeModule); plug; @@ -1758,7 +1759,9 @@ bool PluginManager::DropFile(const wxString &fileName) auto module = static_cast (mm.CreateProviderInstance(plug->GetID(), plug->GetPath())); 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; // Do dry-run test of the file format unsigned nPlugIns = @@ -1770,7 +1773,6 @@ bool PluginManager::DropFile(const wxString &fileName) // actions should not be tried. // Find path to copy it - const wxFileName src{ fileName }; wxFileName dst; dst.AssignDir( ff ); dst.SetFullName( src.GetFullName() ); diff --git a/src/effects/LoadEffects.h b/src/effects/LoadEffects.h index fbf15c4e4..52ec5aa4c 100644 --- a/src/effects/LoadEffects.h +++ b/src/effects/LoadEffects.h @@ -41,7 +41,7 @@ public: bool Initialize() override; void Terminate() override; - bool PathsAreFiles() override { return false; } + wxArrayString FileExtensions() override { return {}; } wxString InstallPath() override { return {}; } bool AutoRegisterPlugins(PluginManagerInterface & pm) override; diff --git a/src/effects/VST/VSTEffect.cpp b/src/effects/VST/VSTEffect.cpp index fd9405a4a..1664acf61 100644 --- a/src/effects/VST/VSTEffect.cpp +++ b/src/effects/VST/VSTEffect.cpp @@ -351,6 +351,13 @@ void VSTEffectsModule::Terminate() return; } +wxArrayString VSTEffectsModule::FileExtensions() +{ + static const wxString ext[] = { _T("vst") }; + static const wxArrayString result{ sizeof(ext)/sizeof(*ext), ext }; + return result; +} + wxString VSTEffectsModule::InstallPath() { // Not yet ready for VST drag-and-drop... diff --git a/src/effects/VST/VSTEffect.h b/src/effects/VST/VSTEffect.h index 9de346fbf..69443c652 100644 --- a/src/effects/VST/VSTEffect.h +++ b/src/effects/VST/VSTEffect.h @@ -391,7 +391,7 @@ public: bool Initialize() override; void Terminate() override; - bool PathsAreFiles() override { return true; } + wxArrayString FileExtensions() override; wxString InstallPath() override; bool AutoRegisterPlugins(PluginManagerInterface & pm) override; diff --git a/src/effects/audiounits/AudioUnitEffect.cpp b/src/effects/audiounits/AudioUnitEffect.cpp index 5009093e4..270e84477 100644 --- a/src/effects/audiounits/AudioUnitEffect.cpp +++ b/src/effects/audiounits/AudioUnitEffect.cpp @@ -140,6 +140,13 @@ wxString AudioUnitEffectsModule::GetDescription() // 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() { // Nothing to do here diff --git a/src/effects/audiounits/AudioUnitEffect.h b/src/effects/audiounits/AudioUnitEffect.h index 3b5c001b1..7f44e472e 100644 --- a/src/effects/audiounits/AudioUnitEffect.h +++ b/src/effects/audiounits/AudioUnitEffect.h @@ -243,7 +243,7 @@ public: bool Initialize() override; void Terminate() override; - bool PathsAreFiles() override { return false; } + wxArrayString FileExtensions() override; wxString InstallPath() override { return {}; } bool AutoRegisterPlugins(PluginManagerInterface & pm) override; diff --git a/src/effects/ladspa/LadspaEffect.cpp b/src/effects/ladspa/LadspaEffect.cpp index cc5167983..5c0bef31a 100644 --- a/src/effects/ladspa/LadspaEffect.cpp +++ b/src/effects/ladspa/LadspaEffect.cpp @@ -155,6 +155,30 @@ void LadspaEffectsModule::Terminate() 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() { // To do: better choice diff --git a/src/effects/ladspa/LadspaEffect.h b/src/effects/ladspa/LadspaEffect.h index 8e4918e10..7eb898788 100644 --- a/src/effects/ladspa/LadspaEffect.h +++ b/src/effects/ladspa/LadspaEffect.h @@ -223,7 +223,7 @@ public: bool Initialize() override; void Terminate() override; - bool PathsAreFiles() override { return true; } + wxArrayString FileExtensions() override; wxString InstallPath() override; bool AutoRegisterPlugins(PluginManagerInterface & pm) override; diff --git a/src/effects/lv2/LoadLV2.h b/src/effects/lv2/LoadLV2.h index b89bdab1a..e705fcc54 100644 --- a/src/effects/lv2/LoadLV2.h +++ b/src/effects/lv2/LoadLV2.h @@ -88,7 +88,7 @@ public: bool Initialize() override; void Terminate() override; - bool PathsAreFiles() override { return false; } + wxArrayString FileExtensions() override { return {}; } wxString InstallPath() override { return {}; } bool AutoRegisterPlugins(PluginManagerInterface & pm) override; diff --git a/src/effects/nyquist/LoadNyquist.cpp b/src/effects/nyquist/LoadNyquist.cpp index b65f4b68f..50dced7ce 100644 --- a/src/effects/nyquist/LoadNyquist.cpp +++ b/src/effects/nyquist/LoadNyquist.cpp @@ -160,6 +160,13 @@ void NyquistEffectsModule::Terminate() return; } +wxArrayString NyquistEffectsModule::FileExtensions() +{ + static const wxString ext[] = { _T("ny") }; + static const wxArrayString result{ sizeof(ext)/sizeof(*ext), ext }; + return result; +} + wxString NyquistEffectsModule::InstallPath() { return FileNames::PlugInDir(); diff --git a/src/effects/nyquist/LoadNyquist.h b/src/effects/nyquist/LoadNyquist.h index 5d208bacb..0bb566ce5 100644 --- a/src/effects/nyquist/LoadNyquist.h +++ b/src/effects/nyquist/LoadNyquist.h @@ -38,7 +38,7 @@ public: bool Initialize() override; void Terminate() override; - bool PathsAreFiles() override { return true; } + wxArrayString FileExtensions() override; wxString InstallPath() override; bool AutoRegisterPlugins(PluginManagerInterface & pm) override; diff --git a/src/effects/vamp/LoadVamp.h b/src/effects/vamp/LoadVamp.h index f7025751c..467a1e39f 100644 --- a/src/effects/vamp/LoadVamp.h +++ b/src/effects/vamp/LoadVamp.h @@ -42,7 +42,7 @@ public: bool Initialize() override; void Terminate() override; - bool PathsAreFiles() override { return false; } + wxArrayString FileExtensions() override { return {}; } wxString InstallPath() override { return {}; } bool AutoRegisterPlugins(PluginManagerInterface & pm) override;