1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-04 09:39:42 +02:00

ExportPlugins managed with smart pointers

This commit is contained in:
Paul Licameli 2016-03-31 00:46:22 -04:00
parent 1108c1376c
commit 456c8fb01e
18 changed files with 98 additions and 115 deletions

View File

@ -75,7 +75,6 @@
//----------------------------------------------------------------------------
#include <wx/arrimpl.cpp>
WX_DEFINE_USER_EXPORTED_OBJARRAY(ExportPluginArray);
WX_DEFINE_USER_EXPORTED_OBJARRAY(FormatInfoArray);
ExportPlugin::ExportPlugin()
@ -112,11 +111,6 @@ int ExportPlugin::GetFormatCount()
return mFormatInfos.Count();
}
void ExportPlugin::Destroy()
{
delete this;
}
/**
* @param index The plugin to set the format for (range 0 to one less than the
* count of formats)
@ -299,11 +293,6 @@ Exporter::Exporter()
Exporter::~Exporter()
{
for (size_t i = 0; i < mPlugins.GetCount(); i++) {
mPlugins[i]->Destroy();
}
mPlugins.Clear();
if (mMixerSpec) {
delete mMixerSpec;
}
@ -318,9 +307,9 @@ void Exporter::SetFileDialogTitle( const wxString & DialogTitle )
int Exporter::FindFormatIndex(int exportindex)
{
int c = 0;
for (size_t i = 0; i < mPlugins.GetCount(); i++)
for (const auto &pPlugin : mPlugins)
{
for (int j = 0; j < mPlugins[i]->GetFormatCount(); j++)
for (int j = 0; j < pPlugin->GetFormatCount(); j++)
{
if (exportindex == c) return j;
c++;
@ -329,12 +318,12 @@ int Exporter::FindFormatIndex(int exportindex)
return 0;
}
void Exporter::RegisterPlugin(ExportPlugin *ExportPlugin)
void Exporter::RegisterPlugin(movable_ptr<ExportPlugin> &&ExportPlugin)
{
mPlugins.Add(ExportPlugin);
mPlugins.push_back(std::move(ExportPlugin));
}
const ExportPluginArray Exporter::GetPlugins()
const ExportPluginArray &Exporter::GetPlugins()
{
return mPlugins;
}
@ -399,10 +388,12 @@ bool Exporter::Process(AudacityProject *project, int numChannels,
mT1 = t1;
mActualName = mFilename;
for (size_t i = 0; i < mPlugins.GetCount(); i++) {
for (int j = 0; j < mPlugins[i]->GetFormatCount(); j++)
int i = -1;
for (const auto &pPlugin : mPlugins) {
++i;
for (int j = 0; j < pPlugin->GetFormatCount(); j++)
{
if (mPlugins[i]->GetFormat(j).IsSameAs(type, false))
if (pPlugin->GetFormat(j).IsSameAs(type, false))
{
mFormat = i;
mSubFormat = j;
@ -508,15 +499,19 @@ bool Exporter::GetFilename()
mFilterIndex = 0;
for (size_t i = 0; i < mPlugins.GetCount(); i++) {
for (int j = 0; j < mPlugins[i]->GetFormatCount(); j++)
{
maskString += mPlugins[i]->GetMask(j) + wxT("|");
if (mPlugins[i]->GetFormat(j) == defaultFormat) {
mFormat = i;
mSubFormat = j;
{
int i = -1;
for (const auto &pPlugin : mPlugins) {
++i;
for (int j = 0; j < pPlugin->GetFormatCount(); j++)
{
maskString += pPlugin->GetMask(j) + wxT("|");
if (mPlugins[i]->GetFormat(j) == defaultFormat) {
mFormat = i;
mSubFormat = j;
}
if (mFormat == -1) mFilterIndex++;
}
if (mFormat == -1) mFilterIndex++;
}
}
if (mFormat == -1)
@ -561,9 +556,11 @@ bool Exporter::GetFilename()
mFilterIndex = fd.GetFilterIndex();
int c = 0;
for (size_t i = 0; i < mPlugins.GetCount(); i++)
int i = -1;
for (const auto &pPlugin : mPlugins)
{
for (int j = 0; j < mPlugins[i]->GetFormatCount(); j++)
++i;
for (int j = 0; j < pPlugin->GetFormatCount(); j++)
{
if (mFilterIndex == c)
{
@ -713,9 +710,11 @@ void Exporter::DisplayOptions(int index)
{
int c = 0;
int mf = -1, msf = -1;
for (size_t i = 0; i < mPlugins.GetCount(); i++)
int i = -1;
for (const auto &pPlugin : mPlugins)
{
for (int j = 0; j < mPlugins[i]->GetFormatCount(); j++)
++i;
for (int j = 0; j < pPlugin->GetFormatCount(); j++)
{
if (index == c)
{
@ -856,11 +855,11 @@ void Exporter::CreateUserPane(wxWindow *parent)
mBook = safenew wxSimplebook(S.GetParent());
S.AddWindow(mBook, wxEXPAND);
for (size_t i = 0; i < mPlugins.GetCount(); i++)
for (const auto &pPlugin : mPlugins)
{
for (int j = 0; j < mPlugins[i]->GetFormatCount(); j++)
for (int j = 0; j < pPlugin->GetFormatCount(); j++)
{
mBook->AddPage(mPlugins[i]->OptionsCreate(mBook, j), wxEmptyString);
mBook->AddPage(pPlugin->OptionsCreate(mBook, j), wxEmptyString);
}
}
}

View File

@ -11,6 +11,8 @@
#ifndef __AUDACITY_EXPORT__
#define __AUDACITY_EXPORT__
#include "../MemoryX.h"
#include <vector>
#include <wx/dialog.h>
#include <wx/dynarray.h>
#include <wx/filename.h>
@ -57,7 +59,6 @@ public:
ExportPlugin();
virtual ~ExportPlugin();
virtual void Destroy();
int AddFormat();
void SetFormat(const wxString & format, int index);
@ -126,7 +127,7 @@ private:
FormatInfoArray mFormatInfos;
};
WX_DECLARE_USER_EXPORTED_OBJARRAY(ExportPlugin *, ExportPluginArray, AUDACITY_DLL_API);
using ExportPluginArray = std::vector < movable_ptr< ExportPlugin > > ;
WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxWindow *, WindowPtrArray, class AUDACITY_DLL_API);
//----------------------------------------------------------------------------
@ -140,7 +141,7 @@ public:
virtual ~Exporter();
void SetFileDialogTitle( const wxString & DialogTitle );
void RegisterPlugin(ExportPlugin *plugin);
void RegisterPlugin(movable_ptr<ExportPlugin> &&plugin);
bool Process(AudacityProject *project, bool selectedOnly,
double t0, double t1);
@ -151,7 +152,7 @@ public:
void DisplayOptions(int index);
int FindFormatIndex(int exportindex);
const ExportPluginArray GetPlugins();
const ExportPluginArray &GetPlugins();
// Auto Export from Timer Recording
bool ProcessFromTimerRecording(AudacityProject *project,

View File

@ -279,7 +279,6 @@ class ExportCL final : public ExportPlugin
public:
ExportCL();
void Destroy();
// Required
wxWindow *OptionsCreate(wxWindow *parent, int format);
@ -306,11 +305,6 @@ ExportCL::ExportCL()
SetDescription(_("(external program)"),0);
}
void ExportCL::Destroy()
{
delete this;
}
int ExportCL::Export(AudacityProject *project,
int channels,
const wxString &fName,
@ -538,8 +532,8 @@ wxWindow *ExportCL::OptionsCreate(wxWindow *parent, int format)
return safenew ExportCLOptions(parent, format);
}
ExportPlugin *New_ExportCL()
movable_ptr<ExportPlugin> New_ExportCL()
{
return new ExportCL();
return make_movable<ExportCL>();
}

View File

@ -11,6 +11,7 @@
#ifndef __AUDACITY_EXPORTCL__
#define __AUDACITY_EXPORTCL__
#include "../MemoryX.h"
// forward declaration of the ExportPlugin class from Export.h
class ExportPlugin;
@ -18,6 +19,6 @@ class ExportPlugin;
* factory method New_ExportCL() which creates a NEW ExportCL object and
* returns a pointer to it. The rest of the class declaration is in ExportCL.cpp
*/
ExportPlugin *New_ExportCL();
movable_ptr<ExportPlugin> New_ExportCL();
#endif

View File

@ -95,7 +95,7 @@ class ExportFFmpeg final : public ExportPlugin
public:
ExportFFmpeg();
void Destroy();
~ExportFFmpeg() override;
/// Callback, called from GetFilename
bool CheckFileName(wxFileName &filename, int format = 0);
@ -182,7 +182,7 @@ ExportFFmpeg::ExportFFmpeg()
mSampleRate = 0;
mSupportsUTF8 = true;
PickFFmpegLibs(); // DropFFmpegLibs() call is in ExportFFmpeg::Destroy()
PickFFmpegLibs(); // DropFFmpegLibs() call is in ExportFFmpeg destructor
int avfver = FFmpegLibsInst->ValidLibsLoaded() ? avformat_version() : 0;
int newfmt;
// Adds export types from the export type list
@ -235,10 +235,9 @@ ExportFFmpeg::ExportFFmpeg()
}
}
void ExportFFmpeg::Destroy()
ExportFFmpeg::~ExportFFmpeg()
{
DropFFmpegLibs();
delete this;
}
bool ExportFFmpeg::CheckFileName(wxFileName & WXUNUSED(filename), int WXUNUSED(format))
@ -1014,9 +1013,9 @@ wxWindow *ExportFFmpeg::OptionsCreate(wxWindow *parent, int format)
return ExportPlugin::OptionsCreate(parent, format);
}
ExportPlugin *New_ExportFFmpeg()
movable_ptr<ExportPlugin> New_ExportFFmpeg()
{
return new ExportFFmpeg();
return make_movable<ExportFFmpeg>();
}
#endif

View File

@ -11,12 +11,13 @@ LRN
#ifndef __AUDACITY_EXPORTFFMPEG__
#define __AUDACITY_EXPORTFFMPEG__
#include "../MemoryX.h"
class ExportPlugin;
/** The only part of this class which is publically accessible is the
* factory method New_ExportFFmpeg() which creates a NEW ExportFFmpeg object and
* returns a pointer to it. The rest of the class declaration is in ExportFFmpeg.cpp
*/
ExportPlugin *New_ExportFFmpeg();
movable_ptr<ExportPlugin> New_ExportFFmpeg();
#endif

View File

@ -178,7 +178,6 @@ class ExportFLAC final : public ExportPlugin
public:
ExportFLAC();
void Destroy();
// Required
@ -213,11 +212,6 @@ ExportFLAC::ExportFLAC()
SetDescription(_("FLAC Files"),0);
}
void ExportFLAC::Destroy()
{
delete this;
}
int ExportFLAC::Export(AudacityProject *project,
int numChannels,
const wxString &fName,
@ -403,9 +397,9 @@ bool ExportFLAC::GetMetadata(AudacityProject *project, const Tags *tags)
return true;
}
ExportPlugin *New_ExportFLAC()
movable_ptr<ExportPlugin> New_ExportFLAC()
{
return new ExportFLAC();
return make_movable<ExportFLAC>();
}
#endif // USE_LIBFLAC

View File

@ -11,13 +11,14 @@
#ifndef __AUDACITY_EXPORTFLAC__
#define __AUDACITY_EXPORTFLAC__
#include "../MemoryX.h"
class ExportPlugin;
/* The only part of this class which is publically accessible is the
* factory method New_ExportFLAC() which creates a NEW ExportFLAC object and
* returns a pointer to it. The rest of the class declaration is in ExportFLAC.cpp
*/
ExportPlugin *New_ExportFLAC();
movable_ptr<ExportPlugin> New_ExportFLAC();
#endif

View File

@ -169,7 +169,6 @@ class ExportMP2 final : public ExportPlugin
public:
ExportMP2();
void Destroy();
// Required
@ -204,11 +203,6 @@ ExportMP2::ExportMP2()
SetDescription(_("MP2 Files"),0);
}
void ExportMP2::Destroy()
{
delete this;
}
int ExportMP2::Export(AudacityProject *project,
int channels, const wxString &fName,
bool selectionOnly, double t0, double t1, MixerSpec *mixerSpec, const Tags *metadata,
@ -443,9 +437,9 @@ void ExportMP2::AddFrame(struct id3_tag *tp, const wxString & n, const wxString
}
#endif
ExportPlugin *New_ExportMP2()
movable_ptr<ExportPlugin> New_ExportMP2()
{
return new ExportMP2();
return make_movable<ExportMP2>();
}
#endif // #ifdef USE_LIBTWOLAME

View File

@ -12,13 +12,14 @@
#ifndef __AUDACITY_EXPORTMP2__
#define __AUDACITY_EXPORTMP2__
#include "../MemoryX.h"
class ExportPlugin;
/** The only part of this class which is publically accessible is the
* factory method New_ExportMP2() which creates a NEW ExportMP2 object and
* returns a pointer to it. The rest of the class declaration is in ExportMP2.cpp
*/
ExportPlugin *New_ExportMP2();
movable_ptr<ExportPlugin> New_ExportMP2();
#endif

View File

@ -1581,7 +1581,6 @@ class ExportMP3 final : public ExportPlugin
public:
ExportMP3();
void Destroy();
bool CheckFileName(wxFileName & filename, int format);
// Required
@ -1620,11 +1619,6 @@ ExportMP3::ExportMP3()
SetDescription(_("MP3 Files"),0);
}
void ExportMP3::Destroy()
{
delete this;
}
bool ExportMP3::CheckFileName(wxFileName & WXUNUSED(filename), int WXUNUSED(format))
{
#ifndef DISABLE_DYNAMIC_LOADING_LAME
@ -2103,9 +2097,9 @@ void ExportMP3::AddFrame(struct id3_tag *tp, const wxString & n, const wxString
}
#endif
ExportPlugin *New_ExportMP3()
movable_ptr<ExportPlugin> New_ExportMP3()
{
return new ExportMP3();
return make_movable<ExportMP3>();
}
//----------------------------------------------------------------------------

View File

@ -13,13 +13,14 @@
/* --------------------------------------------------------------------------*/
#include "../MemoryX.h"
class ExportPlugin;
class wxString;
class wxWindow;
/** Factory method New_ExportMP3() which creates a NEW ExportMP3 object and
* returns a pointer to it. The rest of the class declaration is in ExportMP3.cpp
*/
ExportPlugin *New_ExportMP3();
movable_ptr<ExportPlugin> New_ExportMP3();
//----------------------------------------------------------------------------
// Get MP3 library versioqn

View File

@ -110,7 +110,9 @@ ExportMultiple::ExportMultiple(AudacityProject *project)
mProject = project;
mTracks = project->GetTracks();
mPlugins = mExporter.GetPlugins();
// Construct an array of non-owning pointers
for (const auto &plugin : mExporter.GetPlugins())
mPlugins.push_back(plugin.get());
this->CountTracksAndLabels();
@ -223,17 +225,23 @@ void ExportMultiple::PopulateOrExchange(ShuttleGui& S)
mPluginIndex = -1;
mFilterIndex = 0;
for (size_t i = 0; i < mPlugins.GetCount(); i++) {
for (int j = 0; j < mPlugins[i]->GetFormatCount(); j++)
{
int i = -1;
for (const auto &pPlugin : mPlugins)
{
formats.Add(mPlugins[i]->GetDescription(j));
if (mPlugins[i]->GetFormat(j) == defaultFormat) {
mPluginIndex = i;
mSubFormatIndex = j;
++i;
for (int j = 0; j < pPlugin->GetFormatCount(); j++)
{
formats.Add(mPlugins[i]->GetDescription(j));
if (mPlugins[i]->GetFormat(j) == defaultFormat) {
mPluginIndex = i;
mSubFormatIndex = j;
}
if (mPluginIndex == -1) mFilterIndex++;
}
if (mPluginIndex == -1) mFilterIndex++;
}
}
if (mPluginIndex == -1)
{
mPluginIndex = 0;
@ -270,11 +278,11 @@ void ExportMultiple::PopulateOrExchange(ShuttleGui& S)
if (!mBook)
{
mBook = safenew wxSimplebook(S.GetParent(), OptionsID, wxDefaultPosition, wxDefaultSize, wxBORDER_STATIC);
for (size_t i = 0; i < mPlugins.GetCount(); i++)
for (const auto &pPlugin : mPlugins)
{
for (int j = 0; j < mPlugins[i]->GetFormatCount(); j++)
for (int j = 0; j < pPlugin->GetFormatCount(); j++)
{
mBook->AddPage(mPlugins[i]->OptionsCreate(mBook, j), wxEmptyString);
mBook->AddPage(pPlugin->OptionsCreate(mBook, j), wxEmptyString);
}
}
mBook->ChangeSelection(mFormat->GetSelection());
@ -431,9 +439,11 @@ void ExportMultiple::OnOptions(wxCommandEvent& WXUNUSED(event))
if (sel != wxNOT_FOUND)
{
size_t c = 0;
for (size_t i = 0; i < mPlugins.GetCount(); i++)
int i = -1;
for (const auto &pPlugin : mPlugins)
{
for (int j = 0; j < mPlugins[i]->GetFormatCount(); j++)
++i;
for (int j = 0; j < pPlugin->GetFormatCount(); j++)
{
if ((size_t)sel == c)
{
@ -531,9 +541,12 @@ void ExportMultiple::OnExport(wxCommandEvent& WXUNUSED(event))
mFilterIndex = mFormat->GetSelection();
if (mFilterIndex != wxNOT_FOUND)
{
for (size_t c = 0, i = 0; i < mPlugins.GetCount(); i++)
size_t c = 0;
int i = -1;
for (const auto &pPlugin : mPlugins)
{
for (int j = 0; j < mPlugins[i]->GetFormatCount(); j++, c++)
++i;
for (int j = 0; j < pPlugin->GetFormatCount(); j++, c++)
{
if ((size_t)mFilterIndex == c)
{ // this is the selected format. Store the plug-in and sub-format

View File

@ -103,7 +103,7 @@ private:
private:
Exporter mExporter;
ExportPluginArray mPlugins; /**< Array of references to available exporter
std::vector<ExportPlugin*> mPlugins; /**< Array of references to available exporter
plug-ins */
AudacityProject *mProject;
TrackList *mTracks; /**< The list of tracks in the project that is

View File

@ -128,7 +128,6 @@ class ExportOGG final : public ExportPlugin
public:
ExportOGG();
void Destroy();
// Required
wxWindow *OptionsCreate(wxWindow *parent, int format) override;
@ -159,11 +158,6 @@ ExportOGG::ExportOGG()
SetDescription(_("Ogg Vorbis Files"),0);
}
void ExportOGG::Destroy()
{
delete this;
}
int ExportOGG::Export(AudacityProject *project,
int numChannels,
const wxString &fName,
@ -362,9 +356,9 @@ bool ExportOGG::FillComment(AudacityProject *project, vorbis_comment *comment, c
return true;
}
ExportPlugin *New_ExportOGG()
movable_ptr<ExportPlugin> New_ExportOGG()
{
return new ExportOGG();
return make_movable<ExportOGG>();
}
#endif // USE_LIBVORBIS

View File

@ -11,13 +11,14 @@
#ifndef __AUDACITY_EXPORTOGG__
#define __AUDACITY_EXPORTOGG__
#include "../MemoryX.h"
class ExportPlugin;
/** The only part of this class which is publically accessible is the
* factory method New_ExportOGG() which creates a NEW ExportOGG object and
* returns a pointer to it. The rest of the class declaration is in ExportOGG.cpp
*/
ExportPlugin *New_ExportOGG();
movable_ptr<ExportPlugin> New_ExportOGG();
#endif

View File

@ -308,7 +308,6 @@ class ExportPCM final : public ExportPlugin
public:
ExportPCM();
void Destroy();
// Required
@ -378,11 +377,6 @@ ExportPCM::ExportPCM()
SetMaxChannels(255, format);
}
void ExportPCM::Destroy()
{
delete this;
}
/**
*
* @param subformat Control whether we are doing a "preset" export to a popular
@ -915,7 +909,7 @@ bool ExportPCM::CheckFileName(wxFileName &filename, int format)
return ExportPlugin::CheckFileName(filename, format);
}
ExportPlugin *New_ExportPCM()
movable_ptr<ExportPlugin> New_ExportPCM()
{
return new ExportPCM();
return make_movable<ExportPCM>();
}

View File

@ -11,13 +11,14 @@
#ifndef __AUDACITY_EXPORTPCM__
#define __AUDACITY_EXPORTPCM__
#include "../MemoryX.h"
class ExportPlugin;
/** The only part of this class which is publically accessible is the
* factory method New_ExportPCM() which creates a NEW ExportPCM object and
* returns a pointer to it. The rest of the class declaration is in ExportPCM.cpp
*/
ExportPlugin *New_ExportPCM();
movable_ptr<ExportPlugin> New_ExportPCM();
#endif