mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-18 09:00:07 +02:00
Reimplement export plugin registation without sequence numbers
This commit is contained in:
parent
b1b8b034c8
commit
5165353dbe
@ -282,6 +282,24 @@ BEGIN_EVENT_TABLE(Exporter, wxEvtHandler)
|
|||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
const auto PathStart = wxT("Exporters");
|
||||||
|
|
||||||
|
static Registry::GroupItem &sRegistry()
|
||||||
|
{
|
||||||
|
static Registry::TransparentGroupItem<> registry{ PathStart };
|
||||||
|
return registry;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ExporterItem final : Registry::SingleItem {
|
||||||
|
ExporterItem(
|
||||||
|
const Identifier &id, const Exporter::ExportPluginFactory &factory )
|
||||||
|
: SingleItem{ id }
|
||||||
|
, mFactory{ factory }
|
||||||
|
{}
|
||||||
|
|
||||||
|
Exporter::ExportPluginFactory mFactory;
|
||||||
|
};
|
||||||
|
|
||||||
using ExportPluginFactories = std::vector< Exporter::ExportPluginFactory >;
|
using ExportPluginFactories = std::vector< Exporter::ExportPluginFactory >;
|
||||||
ExportPluginFactories &sFactories()
|
ExportPluginFactories &sFactories()
|
||||||
{
|
{
|
||||||
@ -291,15 +309,24 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Exporter::RegisteredExportPlugin::RegisteredExportPlugin(
|
Exporter::RegisteredExportPlugin::RegisteredExportPlugin(
|
||||||
const ExportPluginFactory &factory )
|
const Identifier &id,
|
||||||
|
const ExportPluginFactory &factory,
|
||||||
|
const Registry::Placement &placement )
|
||||||
{
|
{
|
||||||
if ( factory )
|
if ( factory )
|
||||||
sFactories().emplace_back( factory );
|
Registry::RegisterItem( sRegistry(), placement,
|
||||||
|
std::make_unique< ExporterItem >( id, factory ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
Exporter::Exporter( AudacityProject &project )
|
Exporter::Exporter( AudacityProject &project )
|
||||||
: mProject{ &project }
|
: mProject{ &project }
|
||||||
{
|
{
|
||||||
|
using namespace Registry;
|
||||||
|
static OrderingPreferenceInitializer init{
|
||||||
|
PathStart,
|
||||||
|
{ {wxT(""), wxT("PCM,MP3,OGG,FLAC,MP2,CommandLine,FFmpeg") } },
|
||||||
|
};
|
||||||
|
|
||||||
mMixerSpec = NULL;
|
mMixerSpec = NULL;
|
||||||
mBook = NULL;
|
mBook = NULL;
|
||||||
|
|
||||||
@ -307,15 +334,25 @@ Exporter::Exporter( AudacityProject &project )
|
|||||||
for ( const auto &factory : sFactories() )
|
for ( const auto &factory : sFactories() )
|
||||||
mPlugins.emplace_back( factory() );
|
mPlugins.emplace_back( factory() );
|
||||||
|
|
||||||
// The factories were pushed on the array at static initialization time in an
|
struct MyVisitor final : Visitor {
|
||||||
// unspecified sequence. Sort according to the sequence numbers the plugins
|
MyVisitor()
|
||||||
// report to make the order determinate.
|
{
|
||||||
std::sort( mPlugins.begin(), mPlugins.end(),
|
// visit the registry to collect the plug-ins properly
|
||||||
[]( const ExportPluginArray::value_type &a,
|
// sorted
|
||||||
const ExportPluginArray::value_type &b ){
|
TransparentGroupItem<> top{ PathStart };
|
||||||
return a->SequenceNumber() < b->SequenceNumber();
|
Registry::Visit( *this, &top, &sRegistry() );
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
void Visit( SingleItem &item, const Path &path ) override
|
||||||
|
{
|
||||||
|
mPlugins.emplace_back(
|
||||||
|
static_cast<ExporterItem&>( item ).mFactory() );
|
||||||
|
}
|
||||||
|
|
||||||
|
ExportPluginArray mPlugins;
|
||||||
|
} visitor;
|
||||||
|
|
||||||
|
mPlugins.swap( visitor.mPlugins );
|
||||||
|
|
||||||
SetFileDialogTitle( XO("Export Audio") );
|
SetFileDialogTitle( XO("Export Audio") );
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
#include "../widgets/wxPanelWrapper.h" // to inherit
|
#include "../widgets/wxPanelWrapper.h" // to inherit
|
||||||
#include "../FileNames.h" // for FileTypes
|
#include "../FileNames.h" // for FileTypes
|
||||||
|
|
||||||
|
#include "../commands/CommandManager.h" // for Registry::Placement
|
||||||
|
|
||||||
class wxArrayString;
|
class wxArrayString;
|
||||||
class FileDialogWrapper;
|
class FileDialogWrapper;
|
||||||
class wxFileCtrlEvent;
|
class wxFileCtrlEvent;
|
||||||
@ -132,8 +134,6 @@ public:
|
|||||||
const Tags *metadata = NULL,
|
const Tags *metadata = NULL,
|
||||||
int subformat = 0) = 0;
|
int subformat = 0) = 0;
|
||||||
|
|
||||||
virtual unsigned SequenceNumber() const = 0;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::unique_ptr<Mixer> CreateMixer(const TrackList &tracks,
|
std::unique_ptr<Mixer> CreateMixer(const TrackList &tracks,
|
||||||
bool selectionOnly,
|
bool selectionOnly,
|
||||||
@ -174,7 +174,10 @@ public:
|
|||||||
// to have some fresh state variables each time export begins again
|
// to have some fresh state variables each time export begins again
|
||||||
// and to compute translated strings for the current locale
|
// and to compute translated strings for the current locale
|
||||||
struct RegisteredExportPlugin{
|
struct RegisteredExportPlugin{
|
||||||
RegisteredExportPlugin( const ExportPluginFactory& );
|
RegisteredExportPlugin(
|
||||||
|
const Identifier &id, // an internal string naming the plug-in
|
||||||
|
const ExportPluginFactory&,
|
||||||
|
const Registry::Placement &placement = { wxEmptyString, {} } );
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool DoEditMetadata(AudacityProject &project,
|
static bool DoEditMetadata(AudacityProject &project,
|
||||||
|
@ -310,8 +310,6 @@ public:
|
|||||||
MixerSpec *mixerSpec = NULL,
|
MixerSpec *mixerSpec = NULL,
|
||||||
const Tags *metadata = NULL,
|
const Tags *metadata = NULL,
|
||||||
int subformat = 0) override;
|
int subformat = 0) override;
|
||||||
|
|
||||||
virtual unsigned SequenceNumber() const override { return 60; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ExportCL::ExportCL()
|
ExportCL::ExportCL()
|
||||||
@ -567,5 +565,6 @@ void ExportCL::OptionsCreate(ShuttleGui &S, int format)
|
|||||||
S.AddWindow( safenew ExportCLOptions{ S.GetParent(), format } );
|
S.AddWindow( safenew ExportCLOptions{ S.GetParent(), format } );
|
||||||
}
|
}
|
||||||
|
|
||||||
static Exporter::RegisteredExportPlugin
|
static Exporter::RegisteredExportPlugin sRegisteredPlugin{ "CommandLine",
|
||||||
sRegisteredPlugin{ []{ return std::make_unique< ExportCL >(); } };
|
[]{ return std::make_unique< ExportCL >(); }
|
||||||
|
};
|
||||||
|
@ -152,8 +152,6 @@ public:
|
|||||||
const Tags *metadata = NULL,
|
const Tags *metadata = NULL,
|
||||||
int subformat = 0) override;
|
int subformat = 0) override;
|
||||||
|
|
||||||
virtual unsigned SequenceNumber() const override { return 70; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
AVOutputFormat * mEncFormatDesc{}; // describes our output file to libavformat
|
AVOutputFormat * mEncFormatDesc{}; // describes our output file to libavformat
|
||||||
@ -1141,8 +1139,9 @@ void ExportFFmpeg::OptionsCreate(ShuttleGui &S, int format)
|
|||||||
ExportPlugin::OptionsCreate(S, format);
|
ExportPlugin::OptionsCreate(S, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Exporter::RegisteredExportPlugin
|
static Exporter::RegisteredExportPlugin sRegisteredPlugin{ "FFmpeg",
|
||||||
sRegisteredPlugin{ []{ return std::make_unique< ExportFFmpeg >(); } };
|
[]{ return std::make_unique< ExportFFmpeg >(); }
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -224,8 +224,6 @@ public:
|
|||||||
const Tags *metadata = NULL,
|
const Tags *metadata = NULL,
|
||||||
int subformat = 0) override;
|
int subformat = 0) override;
|
||||||
|
|
||||||
virtual unsigned SequenceNumber() const override { return 40; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool GetMetadata(AudacityProject *project, const Tags *tags);
|
bool GetMetadata(AudacityProject *project, const Tags *tags);
|
||||||
@ -474,8 +472,9 @@ bool ExportFLAC::GetMetadata(AudacityProject *project, const Tags *tags)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Exporter::RegisteredExportPlugin
|
static Exporter::RegisteredExportPlugin sRegisteredPlugin{ "FLAC",
|
||||||
sRegisteredPlugin{ []{ return std::make_unique< ExportFLAC >(); } };
|
[]{ return std::make_unique< ExportFLAC >(); }
|
||||||
|
};
|
||||||
|
|
||||||
#endif // USE_LIBFLAC
|
#endif // USE_LIBFLAC
|
||||||
|
|
||||||
|
@ -217,8 +217,6 @@ public:
|
|||||||
const Tags *metadata = NULL,
|
const Tags *metadata = NULL,
|
||||||
int subformat = 0) override;
|
int subformat = 0) override;
|
||||||
|
|
||||||
virtual unsigned SequenceNumber() const override { return 50; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int AddTags(AudacityProject *project, ArrayOf<char> &buffer, bool *endOfFile, const Tags *tags);
|
int AddTags(AudacityProject *project, ArrayOf<char> &buffer, bool *endOfFile, const Tags *tags);
|
||||||
@ -498,8 +496,9 @@ void ExportMP2::AddFrame(struct id3_tag *tp, const wxString & n, const wxString
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static Exporter::RegisteredExportPlugin
|
static Exporter::RegisteredExportPlugin sRegisteredPlugin{ "MP2",
|
||||||
sRegisteredPlugin{ []{ return std::make_unique< ExportMP2 >(); } };
|
[]{ return std::make_unique< ExportMP2 >(); }
|
||||||
|
};
|
||||||
|
|
||||||
#endif // #ifdef USE_LIBTWOLAME
|
#endif // #ifdef USE_LIBTWOLAME
|
||||||
|
|
||||||
|
@ -1687,8 +1687,6 @@ public:
|
|||||||
const Tags *metadata = NULL,
|
const Tags *metadata = NULL,
|
||||||
int subformat = 0) override;
|
int subformat = 0) override;
|
||||||
|
|
||||||
virtual unsigned SequenceNumber() const override { return 20; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int AskResample(int bitrate, int rate, int lowrate, int highrate);
|
int AskResample(int bitrate, int rate, int lowrate, int highrate);
|
||||||
@ -2199,8 +2197,9 @@ void ExportMP3::AddFrame(struct id3_tag *tp, const wxString & n, const wxString
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static Exporter::RegisteredExportPlugin
|
static Exporter::RegisteredExportPlugin sRegisteredPlugin{ "MP3",
|
||||||
sRegisteredPlugin{ []{ return std::make_unique< ExportMP3 >(); } };
|
[]{ return std::make_unique< ExportMP3 >(); }
|
||||||
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
// Return library version
|
// Return library version
|
||||||
|
@ -143,8 +143,6 @@ public:
|
|||||||
const Tags *metadata = NULL,
|
const Tags *metadata = NULL,
|
||||||
int subformat = 0) override;
|
int subformat = 0) override;
|
||||||
|
|
||||||
virtual unsigned SequenceNumber() const override { return 30; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool FillComment(AudacityProject *project, vorbis_comment *comment, const Tags *metadata);
|
bool FillComment(AudacityProject *project, vorbis_comment *comment, const Tags *metadata);
|
||||||
@ -398,8 +396,9 @@ bool ExportOGG::FillComment(AudacityProject *project, vorbis_comment *comment, c
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Exporter::RegisteredExportPlugin
|
static Exporter::RegisteredExportPlugin sRegisteredPlugin{ "OGG",
|
||||||
sRegisteredPlugin{ []{ return std::make_unique< ExportOGG >(); } };
|
[]{ return std::make_unique< ExportOGG >(); }
|
||||||
|
};
|
||||||
|
|
||||||
#endif // USE_LIBVORBIS
|
#endif // USE_LIBVORBIS
|
||||||
|
|
||||||
|
@ -342,8 +342,6 @@ public:
|
|||||||
FileExtension GetExtension(int index) override;
|
FileExtension GetExtension(int index) override;
|
||||||
bool CheckFileName(wxFileName &filename, int format) override;
|
bool CheckFileName(wxFileName &filename, int format) override;
|
||||||
|
|
||||||
virtual unsigned SequenceNumber() const override { return 10; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ReportTooBigError(wxWindow * pParent);
|
void ReportTooBigError(wxWindow * pParent);
|
||||||
ArrayOf<char> AdjustString(const wxString & wxStr, int sf_format);
|
ArrayOf<char> AdjustString(const wxString & wxStr, int sf_format);
|
||||||
@ -971,5 +969,6 @@ bool ExportPCM::CheckFileName(wxFileName &filename, int format)
|
|||||||
return ExportPlugin::CheckFileName(filename, format);
|
return ExportPlugin::CheckFileName(filename, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Exporter::RegisteredExportPlugin
|
static Exporter::RegisteredExportPlugin sRegisteredPlugin{ "PCM",
|
||||||
sRegisteredPlugin{ []{ return std::make_unique< ExportPCM >(); } };
|
[]{ return std::make_unique< ExportPCM >(); }
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user