Refactor: Move plugin file support handling to PluginFactory
This commit is contained in:
@@ -45,6 +45,8 @@ public:
|
||||
static void init();
|
||||
static void destroy();
|
||||
|
||||
// TODO: Remove me. Replace calls like `if( Engine::hasGUI() )` with
|
||||
// `if (gui)` (gui defined in "GuiApplication.h"
|
||||
static bool hasGUI();
|
||||
|
||||
// core
|
||||
@@ -89,12 +91,6 @@ public:
|
||||
}
|
||||
static void updateFramesPerTick();
|
||||
|
||||
static const QMap<QString, QString> & pluginFileHandling()
|
||||
{
|
||||
return s_pluginFileHandling;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
// small helper function which sets the pointer to NULL before actually deleting
|
||||
// the object it refers to
|
||||
@@ -118,10 +114,6 @@ private:
|
||||
|
||||
static Ladspa2LMMS * s_ladspaManager;
|
||||
|
||||
static QMap<QString, QString> s_pluginFileHandling;
|
||||
|
||||
static void initPluginFileHandling();
|
||||
|
||||
friend class GuiApplication;
|
||||
};
|
||||
|
||||
|
||||
@@ -38,13 +38,15 @@ class EXPORT PluginFactory
|
||||
public:
|
||||
struct PluginInfo
|
||||
{
|
||||
PluginInfo() : library(nullptr), descriptor(nullptr) {}
|
||||
const QString name() const;
|
||||
QFileInfo file;
|
||||
QLibrary* library;
|
||||
Plugin::Descriptor* descriptor;
|
||||
|
||||
bool isNull() const {return library == 0;}
|
||||
};
|
||||
typedef QList<PluginInfo> PluginInfoList;
|
||||
typedef QList<PluginInfo*> PluginInfoList;
|
||||
typedef QMultiMap<Plugin::PluginTypes, Plugin::Descriptor*> DescriptorMap;
|
||||
|
||||
PluginFactory();
|
||||
@@ -60,6 +62,8 @@ public:
|
||||
|
||||
/// Returns a list of all found plugins' PluginFactory::PluginInfo objects.
|
||||
const PluginInfoList& pluginInfos() const;
|
||||
/// Returns a plugin that support the given file extension
|
||||
const PluginInfo pluginSupportingExtension(const QString& ext);
|
||||
|
||||
/// Returns the PluginInfo object of the plugin with the given name.
|
||||
/// If the plugin is not found, an empty PluginInfo is returned (use
|
||||
@@ -76,6 +80,7 @@ public slots:
|
||||
private:
|
||||
DescriptorMap m_descriptors;
|
||||
PluginInfoList m_pluginInfos;
|
||||
QMap<QString, PluginInfo*> m_pluginByExt;
|
||||
|
||||
QHash<QString, QString> m_errors;
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@ Song * Engine::s_song = NULL;
|
||||
ProjectJournal * Engine::s_projectJournal = NULL;
|
||||
Ladspa2LMMS * Engine::s_ladspaManager = NULL;
|
||||
DummyTrackContainer * Engine::s_dummyTC = NULL;
|
||||
QMap<QString, QString> Engine::s_pluginFileHandling;
|
||||
|
||||
|
||||
|
||||
@@ -56,8 +55,6 @@ void Engine::init()
|
||||
// generate (load from file) bandlimited wavetables
|
||||
BandLimitedWave::generateWaves();
|
||||
|
||||
initPluginFileHandling();
|
||||
|
||||
s_projectJournal = new ProjectJournal;
|
||||
s_mixer = new Mixer;
|
||||
s_song = new Song;
|
||||
@@ -117,19 +114,3 @@ void Engine::updateFramesPerTick()
|
||||
s_framesPerTick = s_mixer->processingSampleRate() * 60.0f * 4 /
|
||||
DefaultTicksPerTact / s_song->getTempo();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Engine::initPluginFileHandling()
|
||||
{
|
||||
for (const Plugin::Descriptor* desc : pluginFactory->descriptors(Plugin::Instrument))
|
||||
{
|
||||
for(const QString& ext : QString(desc->supportedFileTypes).split(','))
|
||||
{
|
||||
s_pluginFileHandling[ext] = desc->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -97,17 +97,23 @@ const Plugin::DescriptorList PluginFactory::descriptors(Plugin::PluginTypes type
|
||||
return m_descriptors.values(type);
|
||||
}
|
||||
|
||||
const QList<PluginFactory::PluginInfo>& PluginFactory::pluginInfos() const
|
||||
const PluginFactory::PluginInfoList& PluginFactory::pluginInfos() const
|
||||
{
|
||||
return m_pluginInfos;
|
||||
}
|
||||
|
||||
const PluginFactory::PluginInfo PluginFactory::pluginSupportingExtension(const QString& ext)
|
||||
{
|
||||
PluginInfo* info = m_pluginByExt.value(ext, nullptr);
|
||||
return info == nullptr ? PluginInfo() : *info;
|
||||
}
|
||||
|
||||
const PluginFactory::PluginInfo PluginFactory::pluginInfo(const char* name) const
|
||||
{
|
||||
for (const PluginInfo& info : m_pluginInfos)
|
||||
for (const PluginInfo* info : m_pluginInfos)
|
||||
{
|
||||
if (qstrcmp(info.descriptor->name, name) == 0)
|
||||
return info;
|
||||
if (qstrcmp(info->descriptor->name, name) == 0)
|
||||
return *info;
|
||||
}
|
||||
return PluginInfo();
|
||||
}
|
||||
@@ -122,6 +128,7 @@ void PluginFactory::discoverPlugins()
|
||||
{
|
||||
DescriptorMap descriptors;
|
||||
PluginInfoList pluginInfos;
|
||||
m_pluginByExt.clear();
|
||||
|
||||
const QFileInfoList& files = QDir("plugins:").entryInfoList(nameFilters);
|
||||
|
||||
@@ -158,21 +165,33 @@ void PluginFactory::discoverPlugins()
|
||||
continue;
|
||||
}
|
||||
|
||||
PluginInfo info;
|
||||
info.file = file;
|
||||
info.library = library;
|
||||
info.descriptor = pluginDescriptor;
|
||||
PluginInfo* info = new PluginInfo;
|
||||
info->file = file;
|
||||
info->library = library;
|
||||
info->descriptor = pluginDescriptor;
|
||||
pluginInfos << info;
|
||||
|
||||
descriptors.insert(info.descriptor->type, info.descriptor);
|
||||
for (const QString& ext : QString(info->descriptor->supportedFileTypes).split(','))
|
||||
{
|
||||
m_pluginByExt.insert(ext, info);
|
||||
}
|
||||
|
||||
descriptors.insert(info->descriptor->type, info->descriptor);
|
||||
}
|
||||
|
||||
|
||||
for (PluginInfo& info : m_pluginInfos)
|
||||
for (PluginInfo* info : m_pluginInfos)
|
||||
{
|
||||
delete info.library;
|
||||
delete info->library;
|
||||
delete info;
|
||||
}
|
||||
m_pluginInfos = pluginInfos;
|
||||
m_descriptors = descriptors;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const QString PluginFactory::PluginInfo::name() const
|
||||
{
|
||||
return descriptor ? descriptor->name : QString();
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "MidiPort.h"
|
||||
#include "DataFile.h"
|
||||
#include "NotePlayHandle.h"
|
||||
#include "PluginFactory.h"
|
||||
#include "ProjectJournal.h"
|
||||
#include "TrackContainer.h"
|
||||
|
||||
@@ -134,8 +135,7 @@ PresetPreviewPlayHandle::PresetPreviewPlayHandle( const QString & _preset_file,
|
||||
if( i == NULL || !i->descriptor()->supportsFileType( ext ) )
|
||||
{
|
||||
i = s_previewTC->previewInstrumentTrack()->
|
||||
loadInstrument(
|
||||
Engine::pluginFileHandling()[ext] );
|
||||
loadInstrument(pluginFactory->pluginSupportingExtension(ext).name());
|
||||
}
|
||||
if( i != NULL )
|
||||
{
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "InstrumentTrack.h"
|
||||
#include "MainWindow.h"
|
||||
#include "DataFile.h"
|
||||
#include "PluginFactory.h"
|
||||
#include "PresetPreviewPlayHandle.h"
|
||||
#include "SamplePlayHandle.h"
|
||||
#include "Song.h"
|
||||
@@ -586,7 +587,7 @@ void FileBrowserTreeWidget::handleFile(FileItem * f, InstrumentTrack * it )
|
||||
!i->descriptor()->supportsFileType( e ) )
|
||||
{
|
||||
i = it->loadInstrument(
|
||||
Engine::pluginFileHandling()[e] );
|
||||
pluginFactory->pluginSupportingExtension(e).name() );
|
||||
}
|
||||
i->loadFile( f->fullName() );
|
||||
break;
|
||||
@@ -1019,7 +1020,7 @@ void FileItem::determineFileType( void )
|
||||
m_type = PresetFile;
|
||||
m_handling = LoadAsPreset;
|
||||
}
|
||||
else if( ext == "xiz" && Engine::pluginFileHandling().contains( ext ) )
|
||||
else if( ext == "xiz" && ! pluginFactory->pluginSupportingExtension(ext).isNull() )
|
||||
{
|
||||
m_type = PresetFile;
|
||||
m_handling = LoadByPlugin;
|
||||
@@ -1053,7 +1054,7 @@ void FileItem::determineFileType( void )
|
||||
}
|
||||
|
||||
if( m_handling == NotSupported &&
|
||||
!ext.isEmpty() && Engine::pluginFileHandling().contains( ext ) )
|
||||
!ext.isEmpty() && ! pluginFactory->pluginSupportingExtension(ext).isNull() )
|
||||
{
|
||||
m_handling = LoadByPlugin;
|
||||
// classify as sample if not classified by anything yet but can
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include "StringPairDrag.h"
|
||||
#include "Track.h"
|
||||
#include "GuiApplication.h"
|
||||
#include "PluginFactory.h"
|
||||
|
||||
|
||||
TrackContainerView::TrackContainerView( TrackContainer * _tc ) :
|
||||
@@ -352,8 +353,7 @@ void TrackContainerView::dropEvent( QDropEvent * _de )
|
||||
Track::create( Track::InstrumentTrack,
|
||||
m_tc ) );
|
||||
Instrument * i = it->loadInstrument(
|
||||
Engine::pluginFileHandling()[FileItem::extension(
|
||||
value )]);
|
||||
pluginFactory->pluginSupportingExtension(FileItem::extension(value)).name());
|
||||
i->loadFile( value );
|
||||
//it->toggledInstrumentTrackButton( true );
|
||||
_de->accept();
|
||||
|
||||
@@ -71,6 +71,7 @@
|
||||
#include "DataFile.h"
|
||||
#include "NotePlayHandle.h"
|
||||
#include "Pattern.h"
|
||||
#include "PluginFactory.h"
|
||||
#include "PluginView.h"
|
||||
#include "SamplePlayHandle.h"
|
||||
#include "Song.h"
|
||||
@@ -1558,7 +1559,7 @@ void InstrumentTrackWindow::dropEvent( QDropEvent* event )
|
||||
|
||||
if( !i->descriptor()->supportsFileType( ext ) )
|
||||
{
|
||||
i = m_track->loadInstrument( Engine::pluginFileHandling()[ext] );
|
||||
i = m_track->loadInstrument( pluginFactory->pluginSupportingExtension(ext).name() );
|
||||
}
|
||||
|
||||
i->loadFile( value );
|
||||
|
||||
Reference in New Issue
Block a user