diff --git a/src/import/Import.cpp b/src/import/Import.cpp index 9f2537868..216ee21fd 100644 --- a/src/import/Import.cpp +++ b/src/import/Import.cpp @@ -38,6 +38,7 @@ and ImportLOF.cpp. #include "../Audacity.h" #include "Import.h" +#include #include "ImportPlugin.h" #include @@ -62,8 +63,6 @@ and ImportLOF.cpp. #include "ImportGStreamer.h" #include "../Prefs.h" -WX_DEFINE_LIST(ImportPluginList); -WX_DEFINE_LIST(UnusableImportPluginList); WX_DEFINE_OBJARRAY(ExtImportItems); // ============================================================================ @@ -125,9 +124,7 @@ bool Importer::Initialize() bool Importer::Terminate() { WriteImportItems(); - mImportPluginList->DeleteContents(true); delete mImportPluginList; - mUnusableImportPluginList->DeleteContents(true);//JKC delete mUnusableImportPluginList; return true; @@ -135,10 +132,8 @@ bool Importer::Terminate() void Importer::GetSupportedImportFormats(FormatList *formatList) { - ImportPluginList::compatibility_iterator importPluginNode = mImportPluginList->GetFirst(); - while(importPluginNode) + for(const auto &importPlugin : *mImportPluginList) { - ImportPlugin *importPlugin = importPluginNode->GetData(); #ifdef __AUDACITY_OLD_STD__ formatList->push_back(Format{importPlugin->GetPluginFormatDescription(), importPlugin->GetSupportedExtensions()}); @@ -146,7 +141,6 @@ void Importer::GetSupportedImportFormats(FormatList *formatList) formatList->emplace_back(importPlugin->GetPluginFormatDescription(), importPlugin->GetSupportedExtensions()); #endif - importPluginNode = importPluginNode->GetNext(); } } @@ -165,7 +159,6 @@ void Importer::ReadImportItems() wxString item_name; wxString item_value; ExtImportItem *new_item; - ImportPluginList::compatibility_iterator importPluginNode; if (this->mExtImportItems != NULL) delete this->mExtImportItems; @@ -229,29 +222,27 @@ void Importer::ReadImportItems() /* Find corresponding filter object for each filter ID */ for (size_t i = 0; i < new_item->filters.Count(); i++) { - for (importPluginNode = mImportPluginList->GetFirst(); - importPluginNode; importPluginNode = importPluginNode->GetNext()) + bool found = false; + for (const auto &importPlugin : *mImportPluginList) { - ImportPlugin *importPlugin = importPluginNode->GetData(); if (importPlugin->GetPluginStringID().Cmp(new_item->filters[i]) == 0) { - new_item->filter_objects.Add (importPlugin); + new_item->filter_objects.Add (importPlugin.get()); + found = true; break; } } /* IDs that do not have corresponding filters, will be shown as-is */ - if (!importPluginNode) + if (!found) new_item->filter_objects.Add (NULL); } /* Find all filter objects that are not present in the filter list */ - for (importPluginNode = mImportPluginList->GetFirst(); - importPluginNode; importPluginNode = importPluginNode->GetNext()) + for (const auto &importPlugin : *mImportPluginList) { bool found = false; - ImportPlugin *importPlugin = importPluginNode->GetData(); for (size_t i = 0; i < new_item->filter_objects.Count(); i++) { - if (importPlugin == new_item->filter_objects[i]) + if (importPlugin.get() == new_item->filter_objects[i]) { found = true; break; @@ -264,7 +255,7 @@ void Importer::ReadImportItems() if (new_item->divider < 0) index = new_item->filters.Count(); new_item->filters.Insert(importPlugin->GetPluginStringID(),index); - new_item->filter_objects.Insert (importPlugin, index); + new_item->filter_objects.Insert (importPlugin.get(), index); if (new_item->divider >= 0) new_item->divider++; } @@ -337,18 +328,15 @@ void Importer::WriteImportItems() ExtImportItem *Importer::CreateDefaultImportItem() { ExtImportItem *new_item; - ImportPluginList::compatibility_iterator importPluginNode; new_item = new ExtImportItem(); new_item->extensions.Add(wxT("*")); new_item->mime_types.Add(wxT("*")); - for (importPluginNode = mImportPluginList->GetFirst(); - importPluginNode; importPluginNode = importPluginNode->GetNext()) + for (const auto &importPlugin : *mImportPluginList) { - ImportPlugin *importPlugin = importPluginNode->GetData(); new_item->filters.Add (importPlugin->GetPluginStringID()); - new_item->filter_objects.Add (importPlugin); + new_item->filter_objects.Add (importPlugin.get()); } new_item->divider = -1; return new_item; @@ -366,12 +354,13 @@ bool Importer::Import(const wxString &fName, wxString extension = fName.AfterLast(wxT('.')); + using ImportPluginPtrs = std::vector< ImportPlugin* >; + // This list is used to call plugins in correct order - ImportPluginList importPlugins; - ImportPluginList::compatibility_iterator importPluginNode; + ImportPluginPtrs importPlugins; // This list is used to remember plugins that should have been compatible with the file. - ImportPluginList compatiblePlugins; + ImportPluginPtrs compatiblePlugins; // If user explicitly selected a filter, // then we should try importing via corresponding plugin first @@ -389,17 +378,14 @@ bool Importer::Import(const wxString &fName, if (usersSelectionOverrides) { - importPluginNode = mImportPluginList->GetFirst(); - while (importPluginNode) + for (const auto &plugin : *mImportPluginList) { - ImportPlugin *plugin = importPluginNode->GetData(); if (plugin->GetPluginFormatDescription().CompareTo(type) == 0) { // This plugin corresponds to user-selected filter, try it first. wxLogDebug(wxT("Inserting %s"),plugin->GetPluginStringID().c_str()); - importPlugins.Insert(plugin); + importPlugins.insert(importPlugins.begin(), plugin.get()); } - importPluginNode = importPluginNode->GetNext(); } } @@ -455,13 +441,12 @@ bool Importer::Import(const wxString &fName, if (!(item->filter_objects[j])) continue; wxLogDebug(wxT("Inserting %s"),item->filter_objects[j]->GetPluginStringID().c_str()); - importPlugins.Append(item->filter_objects[j]); + importPlugins.push_back(item->filter_objects[j]); } } } // Add all plugins that support the extension - importPluginNode = mImportPluginList->GetFirst(); // Here we rely on the fact that the first plugin in mImportPluginList is libsndfile. // We want to save this for later insertion ahead of libmad, if libmad supports the extension. @@ -469,14 +454,14 @@ bool Importer::Import(const wxString &fName, // 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 = importPluginNode->GetData(); + ImportPlugin *libsndfilePlugin = mImportPluginList->begin()->get(); wxASSERT(libsndfilePlugin->GetPluginStringID().IsSameAs(wxT("libsndfile"))); - while (importPluginNode) + for (const auto &plugin : *mImportPluginList) { - ImportPlugin *plugin = importPluginNode->GetData(); // Make sure its not already in the list - if (importPlugins.Find(plugin) == NULL) + if (importPlugins.end() == + std::find(importPlugins.begin(), importPlugins.end(), plugin.get())) { if (plugin->SupportsExtension(extension)) { @@ -491,45 +476,40 @@ bool Importer::Import(const wxString &fName, if (plugin->GetPluginStringID().IsSameAs(wxT("libmad"))) { // Make sure libsndfile is not already in the list - if (importPlugins.Find(libsndfilePlugin) == NULL) + if (importPlugins.end() == + std::find(importPlugins.begin(), importPlugins.end(), libsndfilePlugin)) { wxLogDebug(wxT("Appending %s"),libsndfilePlugin->GetPluginStringID().c_str()); - importPlugins.Append(libsndfilePlugin); + importPlugins.push_back(libsndfilePlugin); } } wxLogDebug(wxT("Appending %s"),plugin->GetPluginStringID().c_str()); - importPlugins.Append(plugin); + importPlugins.push_back(plugin.get()); } } - - importPluginNode = importPluginNode->GetNext(); } // Add remaining plugins, except for libmad, which should not be used as a fallback for anything. // Otherwise, if FFmpeg (libav) has not been installed, libmad will still be there near the // end of the preference list importPlugins, where it will claim success importing FFmpeg file // formats unsuitable for it, and produce distorted results. - importPluginNode = mImportPluginList->GetFirst(); - while (importPluginNode) + for (const auto &plugin : *mImportPluginList) { - ImportPlugin *plugin = importPluginNode->GetData(); if (!(plugin->GetPluginStringID().IsSameAs(wxT("libmad")))) { // Make sure its not already in the list - if (importPlugins.Find(plugin) == NULL) + if (importPlugins.end() == + std::find(importPlugins.begin(), importPlugins.end(), plugin.get())) { wxLogDebug(wxT("Appending %s"),plugin->GetPluginStringID().c_str()); - importPlugins.Append(plugin); + importPlugins.push_back(plugin.get()); } } - - importPluginNode = importPluginNode->GetNext(); } - importPluginNode = importPlugins.GetFirst(); - while(importPluginNode) + // Try the import plugins, in the permuted sequences just determined + for (const auto plugin : importPlugins) { - ImportPlugin *plugin = importPluginNode->GetData(); // Try to open the file with this plugin (probe it) wxLogMessage(wxT("Opening with %s"),plugin->GetPluginStringID().c_str()); auto inFile = plugin->Open(fName); @@ -583,18 +563,14 @@ bool Importer::Import(const wxString &fName, // that may recognize the extension, so we allow the loop to // continue. } - importPluginNode = importPluginNode->GetNext(); } wxLogError(wxT("Importer::Import: Opening failed.")); // None of our plugins can handle this file. It might be that // Audacity supports this format, but support was not compiled in. // If so, notify the user of this fact - UnusableImportPluginList::compatibility_iterator unusableImporterNode - = mUnusableImportPluginList->GetFirst(); - while(unusableImporterNode) + for (const auto &unusableImportPlugin : *mUnusableImportPluginList) { - UnusableImportPlugin *unusableImportPlugin = unusableImporterNode->GetData(); if( unusableImportPlugin->SupportsExtension(extension) ) { errorMessage.Printf(_("This version of Audacity was not compiled with %s support."), @@ -603,7 +579,6 @@ bool Importer::Import(const wxString &fName, pProj->mbBusyImporting = false; return false; } - unusableImporterNode = unusableImporterNode->GetNext(); } /* warnings for unsupported data types */ @@ -617,7 +592,7 @@ bool Importer::Import(const wxString &fName, } #endif - if (compatiblePlugins.GetCount() <= 0) + if (compatiblePlugins.empty()) { // if someone has sent us a .cda file, send them away if (extension.IsSameAs(wxT("cda"), false)) { @@ -715,15 +690,12 @@ bool Importer::Import(const wxString &fName, // We DO have a plugin for this file, but import failed. wxString pluglist = wxEmptyString; - importPluginNode = compatiblePlugins.GetFirst(); - while(importPluginNode) + for (const auto &plugin : compatiblePlugins) { - ImportPlugin *plugin = importPluginNode->GetData(); if (pluglist == wxEmptyString) pluglist = plugin->GetPluginFormatDescription(); else pluglist = pluglist + wxT(", ") + plugin->GetPluginFormatDescription(); - importPluginNode = importPluginNode->GetNext(); } errorMessage.Printf(_("Audacity recognized the type of the file '%s'.\nImporters supposedly supporting such files are:\n%s,\nbut none of them understood this file format."),fName.c_str(), pluglist.c_str()); diff --git a/src/import/Import.h b/src/import/Import.h index d4cbc3752..310e07cb4 100644 --- a/src/import/Import.h +++ b/src/import/Import.h @@ -12,6 +12,7 @@ #define _IMPORT_ #include "ImportRaw.h" // defines TrackHolders +#include "ImportForwards.h" #include #include #include @@ -85,9 +86,6 @@ class ExtImportItem wxArrayString mime_types; }; -class ImportPluginList; -class UnusableImportPluginList; - class Importer { public: Importer(); diff --git a/src/import/ImportFFmpeg.cpp b/src/import/ImportFFmpeg.cpp index 07b2118f2..1d5641d32 100644 --- a/src/import/ImportFFmpeg.cpp +++ b/src/import/ImportFFmpeg.cpp @@ -286,7 +286,7 @@ private: void GetFFmpegImportPlugin(ImportPluginList &importPluginList, UnusableImportPluginList &WXUNUSED(unusableImportPluginList)) { - importPluginList.push_back( new FFmpegImportPlugin ); + importPluginList.push_back( make_movable() ); } diff --git a/src/import/ImportFLAC.cpp b/src/import/ImportFLAC.cpp index 51ae08f74..3934dda76 100644 --- a/src/import/ImportFLAC.cpp +++ b/src/import/ImportFLAC.cpp @@ -59,10 +59,10 @@ static const wxChar *exts[] = void GetFLACImportPlugin(ImportPluginList &importPluginList, UnusableImportPluginList &unusableImportPluginList) { - UnusableImportPlugin* flacIsUnsupported = - new UnusableImportPlugin(DESC, wxArrayString(WXSIZEOF(exts), exts)); - - unusableImportPluginList.push_back( flacIsUnsupported ); + unusableImportPluginList.push_back( + make_movable + (DESC, wxArrayString(WXSIZEOF(exts), exts)); + ); } #else /* USE_LIBFLAC */ @@ -285,7 +285,7 @@ FLAC__StreamDecoderWriteStatus MyFLACFile::write_callback(const FLAC__Frame *fra void GetFLACImportPlugin(ImportPluginList &importPluginList, UnusableImportPluginList &WXUNUSED(unusableImportPluginList)) { - importPluginList.push_back( new FLACImportPlugin ); + importPluginList.push_back( make_movable() ); } diff --git a/src/import/ImportForwards.h b/src/import/ImportForwards.h index 79f266b3a..f05256761 100644 --- a/src/import/ImportForwards.h +++ b/src/import/ImportForwards.h @@ -9,13 +9,15 @@ #ifndef __AUDACITY_IMPORT_FORWARDS__ #define __AUDACITY_IMPORT_FORWARDS__ -#include +#include #include "../MemoryX.h" class ImportPlugin; class UnusableImportPlugin; -WX_DECLARE_LIST(ImportPlugin, ImportPluginList); -WX_DECLARE_LIST(UnusableImportPlugin, UnusableImportPluginList); +using ImportPluginList = + std::vector< movable_ptr >; +using UnusableImportPluginList = + std::vector< movable_ptr >; #endif diff --git a/src/import/ImportGStreamer.cpp b/src/import/ImportGStreamer.cpp index e760feadb..cd93ba5c6 100644 --- a/src/import/ImportGStreamer.cpp +++ b/src/import/ImportGStreamer.cpp @@ -300,7 +300,7 @@ GetGStreamerImportPlugin(ImportPluginList &importPluginList, return; // Add to list of importers - importPluginList.push_back( plug.release() ); + importPluginList.push_back( std::move(plug) ); } // ============================================================================ diff --git a/src/import/ImportLOF.cpp b/src/import/ImportLOF.cpp index f92c3d0f8..6fc4346e7 100644 --- a/src/import/ImportLOF.cpp +++ b/src/import/ImportLOF.cpp @@ -178,7 +178,7 @@ LOFImportFileHandle::LOFImportFileHandle void GetLOFImportPlugin(ImportPluginList &importPluginList, UnusableImportPluginList & WXUNUSED(unusableImportPluginList)) { - importPluginList.push_back( new LOFImportPlugin ); + importPluginList.push_back( make_movable() ); } wxString LOFImportPlugin::GetPluginFormatDescription() diff --git a/src/import/ImportMP3.cpp b/src/import/ImportMP3.cpp index cacec2346..56bd6b555 100644 --- a/src/import/ImportMP3.cpp +++ b/src/import/ImportMP3.cpp @@ -59,10 +59,10 @@ static const wxChar *exts[] = void GetMP3ImportPlugin(ImportPluginList &importPluginList, UnusableImportPluginList &unusableImportPluginList) { - UnusableImportPlugin* mp3IsUnsupported = - new UnusableImportPlugin(DESC, wxArrayString(WXSIZEOF(exts), exts)); - - unusableImportPluginList.push_back( mp3IsUnsupported ); + unusableImportPluginList.push_back( + make_movable + (DESC, wxArrayString(WXSIZEOF(exts), exts)) + ); } #else /* USE_LIBMAD */ @@ -156,7 +156,7 @@ private: void GetMP3ImportPlugin(ImportPluginList &importPluginList, UnusableImportPluginList & WXUNUSED(unusableImportPluginList)) { - importPluginList.push_back( new MP3ImportPlugin ); + importPluginList.push_back( make_movable() ); } /* The MAD callbacks */ diff --git a/src/import/ImportOGG.cpp b/src/import/ImportOGG.cpp index 81c13ef03..adde0a638 100644 --- a/src/import/ImportOGG.cpp +++ b/src/import/ImportOGG.cpp @@ -58,10 +58,10 @@ static const wxChar *exts[] = void GetOGGImportPlugin(ImportPluginList &importPluginList, UnusableImportPluginList &unusableImportPluginList) { - UnusableImportPlugin* oggIsUnsupported = - new UnusableImportPlugin(DESC, wxArrayString(WXSIZEOF(exts), exts)); - - unusableImportPluginList.push_back( oggIsUnsupported ); + unusableImportPluginList.push_back( + make_movable + (DESC, wxArrayString(WXSIZEOF(exts), exts)) + ); } #else /* USE_LIBVORBIS */ @@ -163,7 +163,7 @@ private: void GetOGGImportPlugin(ImportPluginList &importPluginList, UnusableImportPluginList & WXUNUSED(unusableImportPluginList)) { - importPluginList.push_back( new OggImportPlugin ); + importPluginList.push_back( make_movable() ); } wxString OggImportPlugin::GetPluginFormatDescription() diff --git a/src/import/ImportPCM.cpp b/src/import/ImportPCM.cpp index 180a98cbf..3bd7ebc6e 100644 --- a/src/import/ImportPCM.cpp +++ b/src/import/ImportPCM.cpp @@ -116,7 +116,7 @@ private: void GetPCMImportPlugin(ImportPluginList & importPluginList, UnusableImportPluginList & WXUNUSED(unusableImportPluginList)) { - importPluginList.push_back( new PCMImportPlugin ); + importPluginList.push_back( make_movable() ); } wxString PCMImportPlugin::GetPluginFormatDescription() diff --git a/src/import/ImportQT.cpp b/src/import/ImportQT.cpp index 3168d039a..60732065b 100644 --- a/src/import/ImportQT.cpp +++ b/src/import/ImportQT.cpp @@ -30,10 +30,10 @@ static const wxChar *exts[] = void GetQTImportPlugin(ImportPluginList &importPluginList, UnusableImportPluginList &unusableImportPluginList) { - UnusableImportPlugin* qtIsUnsupported = - new UnusableImportPlugin(DESC, wxArrayString(WXSIZEOF(exts), exts)); - - unusableImportPluginList.push_back( qtIsUnsupported ); + unusableImportPluginList.push_back( + make_movable + (DESC, wxArrayString(WXSIZEOF(exts), exts)) + ); } #else /* USE_QUICKTIME */ @@ -165,7 +165,7 @@ class QTImportFileHandle final : public ImportFileHandle void GetQTImportPlugin(ImportPluginList &importPluginList, UnusableImportPluginList &unusableImportPluginList) { - importPluginList.push_back( new QTImportPlugin ); + importPluginList.push_back( make_movable() ); } wxString QTImportPlugin::GetPluginFormatDescription()