mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-31 16:09:28 +02:00
Reimplement import plugin registation without sequence numbers
This commit is contained in:
parent
a333b7d35a
commit
b1b8b034c8
@ -84,11 +84,33 @@ ImportPluginList &Importer::sImportPluginList()
|
||||
return theList;
|
||||
}
|
||||
|
||||
namespace {
|
||||
static const auto PathStart = wxT("Importers");
|
||||
|
||||
static Registry::GroupItem &sRegistry()
|
||||
{
|
||||
static Registry::TransparentGroupItem<> registry{ PathStart };
|
||||
return registry;
|
||||
}
|
||||
|
||||
struct ImporterItem final : Registry::SingleItem {
|
||||
ImporterItem( const Identifier &id, std::unique_ptr<ImportPlugin> pPlugin )
|
||||
: SingleItem{ id }
|
||||
, mpPlugin{ std::move( pPlugin ) }
|
||||
{}
|
||||
|
||||
std::unique_ptr<ImportPlugin> mpPlugin;
|
||||
};
|
||||
}
|
||||
|
||||
Importer::RegisteredImportPlugin::RegisteredImportPlugin(
|
||||
std::unique_ptr<ImportPlugin> pPlugin )
|
||||
const Identifier &id,
|
||||
std::unique_ptr<ImportPlugin> pPlugin,
|
||||
const Registry::Placement &placement )
|
||||
{
|
||||
if ( pPlugin )
|
||||
sImportPluginList().emplace_back( std::move( pPlugin ) );
|
||||
Registry::RegisterItem( sRegistry(), placement,
|
||||
std::make_unique< ImporterItem >( id, std::move( pPlugin ) ) );
|
||||
}
|
||||
|
||||
UnusableImportPluginList &Importer::sUnusableImportPluginList()
|
||||
@ -110,16 +132,29 @@ bool Importer::Initialize()
|
||||
// order is significant. If none match, they will all be tried
|
||||
// in the order defined here.
|
||||
|
||||
// They were pushed on the array at static initialization time in an
|
||||
// unspecified sequence. Sort according to the sequence numbers they
|
||||
// report to make the order determinate.
|
||||
auto &list = sImportPluginList();
|
||||
std::sort( list.begin(), list.end(),
|
||||
[]( const ImportPluginList::value_type &a,
|
||||
const ImportPluginList::value_type &b ){
|
||||
return a->SequenceNumber() < b->SequenceNumber();
|
||||
using namespace Registry;
|
||||
static OrderingPreferenceInitializer init{
|
||||
PathStart,
|
||||
{ {wxT(""), wxT("PCM,OGG,FLAC,MP3,LOF,FFmpeg") } }
|
||||
// QT and GStreamer are only conditionally compiled and would get
|
||||
// placed at the end if present
|
||||
};
|
||||
|
||||
static struct MyVisitor final : Visitor {
|
||||
MyVisitor()
|
||||
{
|
||||
// Once only, visit the registry to collect the plug-ins properly
|
||||
// sorted
|
||||
TransparentGroupItem<> top{ PathStart };
|
||||
Registry::Visit( *this, &top, &sRegistry() );
|
||||
}
|
||||
);
|
||||
|
||||
void Visit( SingleItem &item, const Path &path ) override
|
||||
{
|
||||
sImportPluginList().push_back(
|
||||
static_cast<ImporterItem&>( item ).mpPlugin.get() );
|
||||
}
|
||||
} visitor;
|
||||
|
||||
// Ordering of the unusable plugin list is not important.
|
||||
|
||||
@ -292,7 +327,7 @@ void Importer::ReadImportItems()
|
||||
{
|
||||
if (importPlugin->GetPluginStringID() == new_item->filters[i])
|
||||
{
|
||||
new_item->filter_objects.push_back(importPlugin.get());
|
||||
new_item->filter_objects.push_back(importPlugin);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@ -307,7 +342,7 @@ void Importer::ReadImportItems()
|
||||
bool found = false;
|
||||
for (size_t i = 0; i < new_item->filter_objects.size(); i++)
|
||||
{
|
||||
if (importPlugin.get() == new_item->filter_objects[i])
|
||||
if (importPlugin == new_item->filter_objects[i])
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
@ -323,7 +358,7 @@ void Importer::ReadImportItems()
|
||||
new_item->filters.begin() + index,
|
||||
importPlugin->GetPluginStringID());
|
||||
new_item->filter_objects.insert(
|
||||
new_item->filter_objects.begin() + index, importPlugin.get());
|
||||
new_item->filter_objects.begin() + index, importPlugin);
|
||||
if (new_item->divider >= 0)
|
||||
new_item->divider++;
|
||||
}
|
||||
@ -402,7 +437,7 @@ std::unique_ptr<ExtImportItem> Importer::CreateDefaultImportItem()
|
||||
for (const auto &importPlugin : sImportPluginList())
|
||||
{
|
||||
new_item->filters.push_back(importPlugin->GetPluginStringID());
|
||||
new_item->filter_objects.push_back(importPlugin.get());
|
||||
new_item->filter_objects.push_back(importPlugin);
|
||||
}
|
||||
new_item->divider = -1;
|
||||
return new_item;
|
||||
@ -462,7 +497,7 @@ bool Importer::Import( AudacityProject &project,
|
||||
{
|
||||
// This plugin corresponds to user-selected filter, try it first.
|
||||
wxLogDebug(wxT("Inserting %s"),plugin->GetPluginStringID());
|
||||
importPlugins.insert(importPlugins.begin(), plugin.get());
|
||||
importPlugins.insert(importPlugins.begin(), plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -532,14 +567,14 @@ bool Importer::Import( AudacityProject &project,
|
||||
// is not changed by user selection overrides or any other mechanism, but we include an assert
|
||||
// in case subsequent code revisions to the constructor should break this assumption that
|
||||
// libsndfile is first.
|
||||
ImportPlugin *libsndfilePlugin = sImportPluginList().begin()->get();
|
||||
ImportPlugin *libsndfilePlugin = *sImportPluginList().begin();
|
||||
wxASSERT(libsndfilePlugin->GetPluginStringID() == wxT("libsndfile"));
|
||||
|
||||
for (const auto &plugin : sImportPluginList())
|
||||
{
|
||||
// Make sure its not already in the list
|
||||
if (importPlugins.end() ==
|
||||
std::find(importPlugins.begin(), importPlugins.end(), plugin.get()))
|
||||
std::find(importPlugins.begin(), importPlugins.end(), plugin))
|
||||
{
|
||||
if (plugin->SupportsExtension(extension))
|
||||
{
|
||||
@ -562,7 +597,7 @@ bool Importer::Import( AudacityProject &project,
|
||||
}
|
||||
}
|
||||
wxLogDebug(wxT("Appending %s"),plugin->GetPluginStringID());
|
||||
importPlugins.push_back(plugin.get());
|
||||
importPlugins.push_back(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -577,10 +612,10 @@ bool Importer::Import( AudacityProject &project,
|
||||
{
|
||||
// Make sure its not already in the list
|
||||
if (importPlugins.end() ==
|
||||
std::find(importPlugins.begin(), importPlugins.end(), plugin.get()))
|
||||
std::find(importPlugins.begin(), importPlugins.end(), plugin))
|
||||
{
|
||||
wxLogDebug(wxT("Appending %s"),plugin->GetPluginStringID());
|
||||
importPlugins.push_back(plugin.get());
|
||||
importPlugins.push_back(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,8 @@
|
||||
#include "../widgets/wxPanelWrapper.h" // to inherit
|
||||
#include "../FileNames.h" // for FileType
|
||||
|
||||
#include "../commands/CommandManager.h" // for Registry::Placement
|
||||
|
||||
class wxArrayString;
|
||||
class wxListBox;
|
||||
class AudacityProject;
|
||||
@ -80,7 +82,10 @@ public:
|
||||
// Objects of this type are statically constructed in files implementing
|
||||
// subclasses of ImportPlugin
|
||||
struct RegisteredImportPlugin{
|
||||
RegisteredImportPlugin( std::unique_ptr<ImportPlugin> );
|
||||
RegisteredImportPlugin(
|
||||
const Identifier &id, // an internal string naming the plug-in
|
||||
std::unique_ptr<ImportPlugin>,
|
||||
const Registry::Placement &placement = { wxEmptyString, {} } );
|
||||
};
|
||||
|
||||
// Objects of this type are statically constructed in files, to identify
|
||||
|
@ -185,8 +185,6 @@ public:
|
||||
///! Probes the file and opens it if appropriate
|
||||
std::unique_ptr<ImportFileHandle> Open(
|
||||
const FilePath &Filename, AudacityProject*) override;
|
||||
|
||||
unsigned SequenceNumber() const override;
|
||||
};
|
||||
|
||||
///! Does acual import, returned by FFmpegImportPlugin::Open
|
||||
@ -335,12 +333,7 @@ std::unique_ptr<ImportFileHandle> FFmpegImportPlugin::Open(
|
||||
return std::move(handle);
|
||||
}
|
||||
|
||||
unsigned FFmpegImportPlugin::SequenceNumber() const
|
||||
{
|
||||
return 60;
|
||||
}
|
||||
|
||||
static Importer::RegisteredImportPlugin registered{
|
||||
static Importer::RegisteredImportPlugin registered{ "FFmpeg",
|
||||
std::make_unique< FFmpegImportPlugin >()
|
||||
};
|
||||
|
||||
|
@ -137,8 +137,6 @@ class FLACImportPlugin final : public ImportPlugin
|
||||
TranslatableString GetPluginFormatDescription() override;
|
||||
std::unique_ptr<ImportFileHandle> Open(
|
||||
const FilePath &Filename, AudacityProject*) override;
|
||||
|
||||
unsigned SequenceNumber() const override;
|
||||
};
|
||||
|
||||
|
||||
@ -334,12 +332,7 @@ std::unique_ptr<ImportFileHandle> FLACImportPlugin::Open(
|
||||
return std::move(handle);
|
||||
}
|
||||
|
||||
unsigned FLACImportPlugin::SequenceNumber() const
|
||||
{
|
||||
return 30;
|
||||
}
|
||||
|
||||
static Importer::RegisteredImportPlugin registered{
|
||||
static Importer::RegisteredImportPlugin registered{ "FLAC",
|
||||
std::make_unique< FLACImportPlugin >()
|
||||
};
|
||||
|
||||
|
@ -16,7 +16,7 @@ class ImportPlugin;
|
||||
class UnusableImportPlugin;
|
||||
|
||||
using ImportPluginList =
|
||||
std::vector< std::unique_ptr<ImportPlugin> >;
|
||||
std::vector< ImportPlugin * >;
|
||||
using UnusableImportPluginList =
|
||||
std::vector< std::unique_ptr<UnusableImportPlugin> >;
|
||||
|
||||
|
@ -249,8 +249,6 @@ public:
|
||||
///! Probes the file and opens it if appropriate
|
||||
std::unique_ptr<ImportFileHandle> Open(
|
||||
const wxString &Filename, AudacityProject*) override;
|
||||
|
||||
unsigned SequenceNumber() const override;
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
@ -261,7 +259,8 @@ public:
|
||||
// Instantiate GStreamerImportPlugin and add to the list of known importers
|
||||
|
||||
static
|
||||
Importer::RegisteredImportPlugin{ []() -> std::unique_ptr< ImportPlugin > {
|
||||
Importer::RegisteredImportPlugin{ "GStreamer",
|
||||
[]() -> std::unique_ptr< ImportPlugin > {
|
||||
wxLogMessage(_TS("Audacity is built against GStreamer version %d.%d.%d-%d"),
|
||||
GST_VERSION_MAJOR,
|
||||
GST_VERSION_MINOR,
|
||||
@ -1152,11 +1151,6 @@ GStreamerImportFileHandle::Import(TrackFactory *trackFactory,
|
||||
return updateResult;
|
||||
}
|
||||
|
||||
unsigned GStreamerImportPlugin::SequenceNumber() const
|
||||
{
|
||||
return 80;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Message handlers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -116,8 +116,6 @@ public:
|
||||
TranslatableString GetPluginFormatDescription() override;
|
||||
std::unique_ptr<ImportFileHandle> Open(
|
||||
const FilePath &Filename, AudacityProject *pProject) override;
|
||||
|
||||
unsigned SequenceNumber() const override;
|
||||
};
|
||||
|
||||
|
||||
@ -272,12 +270,7 @@ ProgressResult LOFImportFileHandle::Import(
|
||||
return ProgressResult::Success;
|
||||
}
|
||||
|
||||
unsigned LOFImportPlugin::SequenceNumber() const
|
||||
{
|
||||
return 50;
|
||||
}
|
||||
|
||||
static Importer::RegisteredImportPlugin registered{
|
||||
static Importer::RegisteredImportPlugin registered{ "LOF",
|
||||
std::make_unique< LOFImportPlugin >()
|
||||
};
|
||||
|
||||
|
@ -117,8 +117,6 @@ public:
|
||||
TranslatableString GetPluginFormatDescription() override;
|
||||
std::unique_ptr<ImportFileHandle> Open(
|
||||
const FilePath &Filename, AudacityProject*) override;
|
||||
|
||||
unsigned SequenceNumber() const override;
|
||||
};
|
||||
|
||||
class MP3ImportFileHandle final : public ImportFileHandle
|
||||
@ -257,12 +255,7 @@ ProgressResult MP3ImportFileHandle::Import(
|
||||
return privateData.updateResult;
|
||||
}
|
||||
|
||||
unsigned MP3ImportPlugin::SequenceNumber() const
|
||||
{
|
||||
return 40;
|
||||
}
|
||||
|
||||
static Importer::RegisteredImportPlugin registered{
|
||||
static Importer::RegisteredImportPlugin registered{ "MP3",
|
||||
std::make_unique< MP3ImportPlugin >()
|
||||
};
|
||||
|
||||
|
@ -91,8 +91,6 @@ public:
|
||||
TranslatableString GetPluginFormatDescription() override;
|
||||
std::unique_ptr<ImportFileHandle> Open(
|
||||
const FilePath &Filename, AudacityProject*) override;
|
||||
|
||||
unsigned SequenceNumber() const override;
|
||||
};
|
||||
|
||||
|
||||
@ -215,12 +213,7 @@ std::unique_ptr<ImportFileHandle> OggImportPlugin::Open(
|
||||
return std::make_unique<OggImportFileHandle>(filename, std::move(file), std::move(vorbisFile));
|
||||
}
|
||||
|
||||
unsigned OggImportPlugin::SequenceNumber() const
|
||||
{
|
||||
return 20;
|
||||
}
|
||||
|
||||
static Importer::RegisteredImportPlugin registered{
|
||||
static Importer::RegisteredImportPlugin registered{ "OGG",
|
||||
std::make_unique< OggImportPlugin >()
|
||||
};
|
||||
|
||||
|
@ -89,8 +89,6 @@ public:
|
||||
TranslatableString GetPluginFormatDescription() override;
|
||||
std::unique_ptr<ImportFileHandle> Open(
|
||||
const FilePath &Filename, AudacityProject*) override;
|
||||
|
||||
unsigned SequenceNumber() const override;
|
||||
};
|
||||
|
||||
|
||||
@ -192,12 +190,7 @@ std::unique_ptr<ImportFileHandle> PCMImportPlugin::Open(
|
||||
return std::make_unique<PCMImportFileHandle>(filename, std::move(file), info);
|
||||
}
|
||||
|
||||
unsigned PCMImportPlugin::SequenceNumber() const
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
|
||||
static Importer::RegisteredImportPlugin registered{
|
||||
static Importer::RegisteredImportPlugin registered{ "PCM",
|
||||
std::make_unique< PCMImportPlugin >()
|
||||
};
|
||||
|
||||
|
@ -96,8 +96,6 @@ public:
|
||||
virtual std::unique_ptr<ImportFileHandle> Open(
|
||||
const FilePath &Filename, AudacityProject*) = 0;
|
||||
|
||||
virtual unsigned SequenceNumber() const = 0;
|
||||
|
||||
virtual ~ImportPlugin() { }
|
||||
|
||||
protected:
|
||||
|
@ -125,8 +125,6 @@ class QTImportPlugin final : public ImportPlugin
|
||||
std::unique_ptr<ImportFileHandle> Open(
|
||||
const wxString & Filename, AudacityProject*) override;
|
||||
|
||||
unsigned SequenceNumber() const override;
|
||||
|
||||
private:
|
||||
bool mInitialized;
|
||||
};
|
||||
@ -222,12 +220,7 @@ std::unique_ptr<ImportFileHandle> QTImportPlugin::Open(
|
||||
return std::make_unique<QTImportFileHandle>(Filename, theMovie);
|
||||
}
|
||||
|
||||
unsigned QTImportPlugin::SequenceNumber() const
|
||||
{
|
||||
return 70;
|
||||
}
|
||||
|
||||
static Importer::RegisteredImportPlugin registered{
|
||||
static Importer::RegisteredImportPlugin registered{ "QT",
|
||||
std::make_unique< QTImportPlugin >()
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user