Skip to content

Commit

Permalink
Drag-and-drop checks file extensions first for plug-in candidates...
Browse files Browse the repository at this point in the history
... Avoids big delays in drag-and-drop importation caused by
765ca0c
  • Loading branch information
Paul-Licameli committed Jan 1, 2018
1 parent 2cdf931 commit 3c9cdac
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 13 deletions.
11 changes: 7 additions & 4 deletions include/audacity/ModuleInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,15 @@ class ModuleInterface /* not final */ : public IdentInterface
// 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
Expand Down
6 changes: 4 additions & 2 deletions src/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -1758,7 +1759,9 @@ bool PluginManager::DropFile(const wxString &fileName)
auto module = static_cast<ModuleInterface *>
(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 =
Expand All @@ -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() );
Expand Down
2 changes: 1 addition & 1 deletion src/effects/LoadEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class BuiltinEffectsModule final : public ModuleInterface
bool Initialize() override;
void Terminate() override;

bool PathsAreFiles() override { return false; }
wxArrayString FileExtensions() override { return {}; }
wxString InstallPath() override { return {}; }

bool AutoRegisterPlugins(PluginManagerInterface & pm) override;
Expand Down
7 changes: 7 additions & 0 deletions src/effects/VST/VSTEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
2 changes: 1 addition & 1 deletion src/effects/VST/VSTEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class VSTEffectsModule final : public ModuleInterface
bool Initialize() override;
void Terminate() override;

bool PathsAreFiles() override { return true; }
wxArrayString FileExtensions() override;
wxString InstallPath() override;

bool AutoRegisterPlugins(PluginManagerInterface & pm) override;
Expand Down
7 changes: 7 additions & 0 deletions src/effects/audiounits/AudioUnitEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/effects/audiounits/AudioUnitEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class AudioUnitEffectsModule final : public ModuleInterface
bool Initialize() override;
void Terminate() override;

bool PathsAreFiles() override { return false; }
wxArrayString FileExtensions() override;
wxString InstallPath() override { return {}; }

bool AutoRegisterPlugins(PluginManagerInterface & pm) override;
Expand Down
24 changes: 24 additions & 0 deletions src/effects/ladspa/LadspaEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/effects/ladspa/LadspaEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class LadspaEffectsModule final : public ModuleInterface
bool Initialize() override;
void Terminate() override;

bool PathsAreFiles() override { return true; }
wxArrayString FileExtensions() override;
wxString InstallPath() override;

bool AutoRegisterPlugins(PluginManagerInterface & pm) override;
Expand Down
2 changes: 1 addition & 1 deletion src/effects/lv2/LoadLV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class LV2EffectsModule final : public ModuleInterface
bool Initialize() override;
void Terminate() override;

bool PathsAreFiles() override { return false; }
wxArrayString FileExtensions() override { return {}; }
wxString InstallPath() override { return {}; }

bool AutoRegisterPlugins(PluginManagerInterface & pm) override;
Expand Down
7 changes: 7 additions & 0 deletions src/effects/nyquist/LoadNyquist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/effects/nyquist/LoadNyquist.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class NyquistEffectsModule final : public ModuleInterface
bool Initialize() override;
void Terminate() override;

bool PathsAreFiles() override { return true; }
wxArrayString FileExtensions() override;
wxString InstallPath() override;

bool AutoRegisterPlugins(PluginManagerInterface & pm) override;
Expand Down
2 changes: 1 addition & 1 deletion src/effects/vamp/LoadVamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class VampEffectsModule final : public ModuleInterface
bool Initialize() override;
void Terminate() override;

bool PathsAreFiles() override { return false; }
wxArrayString FileExtensions() override { return {}; }
wxString InstallPath() override { return {}; }

bool AutoRegisterPlugins(PluginManagerInterface & pm) override;
Expand Down

0 comments on commit 3c9cdac

Please sign in to comment.