mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-02 17:23:18 +02:00
ImportFileHandles
This commit is contained in:
parent
83e9e7de97
commit
e6e7b73043
@ -363,8 +363,6 @@ bool Importer::Import(const wxString &fName,
|
||||
AudacityProject *pProj = GetActiveProject();
|
||||
pProj->mbBusyImporting = true;
|
||||
|
||||
ImportFileHandle *inFile = NULL;
|
||||
|
||||
wxString extension = fName.AfterLast(wxT('.'));
|
||||
|
||||
// This list is used to call plugins in correct order
|
||||
@ -533,18 +531,17 @@ bool Importer::Import(const wxString &fName,
|
||||
ImportPlugin *plugin = importPluginNode->GetData();
|
||||
// Try to open the file with this plugin (probe it)
|
||||
wxLogMessage(wxT("Opening with %s"),plugin->GetPluginStringID().c_str());
|
||||
inFile = plugin->Open(fName);
|
||||
auto inFile = plugin->Open(fName);
|
||||
if ( (inFile != NULL) && (inFile->GetStreamCount() > 0) )
|
||||
{
|
||||
wxLogMessage(wxT("Open(%s) succeeded"),(const char *) fName.c_str());
|
||||
// File has more than one stream - display stream selector
|
||||
if (inFile->GetStreamCount() > 1)
|
||||
{
|
||||
ImportStreamDialog ImportDlg(inFile, NULL, -1, _("Select stream(s) to import"));
|
||||
ImportStreamDialog ImportDlg(inFile.get(), NULL, -1, _("Select stream(s) to import"));
|
||||
|
||||
if (ImportDlg.ShowModal() == wxID_CANCEL)
|
||||
{
|
||||
delete inFile;
|
||||
pProj->mbBusyImporting = false;
|
||||
return false;
|
||||
}
|
||||
@ -557,8 +554,6 @@ bool Importer::Import(const wxString &fName,
|
||||
|
||||
res = inFile->Import(trackFactory, tracks, tags);
|
||||
|
||||
delete inFile;
|
||||
|
||||
if (res == eProgressSuccess || res == eProgressStopped)
|
||||
{
|
||||
// LOF ("list-of-files") has different semantics
|
||||
|
@ -183,7 +183,7 @@ public:
|
||||
wxString GetPluginFormatDescription();
|
||||
|
||||
///! Probes the file and opens it if appropriate
|
||||
ImportFileHandle *Open(const wxString &Filename) override;
|
||||
std::unique_ptr<ImportFileHandle> Open(const wxString &Filename) override;
|
||||
};
|
||||
|
||||
///! Does acual import, returned by FFmpegImportPlugin::Open
|
||||
@ -293,9 +293,9 @@ wxString FFmpegImportPlugin::GetPluginFormatDescription()
|
||||
return DESC;
|
||||
}
|
||||
|
||||
ImportFileHandle *FFmpegImportPlugin::Open(const wxString &filename)
|
||||
std::unique_ptr<ImportFileHandle> FFmpegImportPlugin::Open(const wxString &filename)
|
||||
{
|
||||
FFmpegImportFileHandle *handle = new FFmpegImportFileHandle(filename);
|
||||
auto handle = std::make_unique<FFmpegImportFileHandle>(filename);
|
||||
|
||||
//Check if we're loading explicitly supported format
|
||||
wxString extension = filename.AfterLast(wxT('.'));
|
||||
@ -322,18 +322,16 @@ ImportFileHandle *FFmpegImportPlugin::Open(const wxString &filename)
|
||||
}
|
||||
if (!FFmpegLibsInst->ValidLibsLoaded())
|
||||
{
|
||||
delete handle;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Open the file for import
|
||||
bool success = handle->Init();
|
||||
if (!success) {
|
||||
delete handle;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return handle;
|
||||
return std::move(handle);
|
||||
}
|
||||
|
||||
|
||||
|
@ -138,7 +138,7 @@ class FLACImportPlugin final : public ImportPlugin
|
||||
|
||||
wxString GetPluginStringID() { return wxT("libflac"); }
|
||||
wxString GetPluginFormatDescription();
|
||||
ImportFileHandle *Open(const wxString &Filename) override;
|
||||
std::unique_ptr<ImportFileHandle> Open(const wxString &Filename) override;
|
||||
};
|
||||
|
||||
|
||||
@ -290,7 +290,7 @@ wxString FLACImportPlugin::GetPluginFormatDescription()
|
||||
}
|
||||
|
||||
|
||||
ImportFileHandle *FLACImportPlugin::Open(const wxString &filename)
|
||||
std::unique_ptr<ImportFileHandle> FLACImportPlugin::Open(const wxString &filename)
|
||||
{
|
||||
// First check if it really is a FLAC file
|
||||
|
||||
@ -318,15 +318,14 @@ ImportFileHandle *FLACImportPlugin::Open(const wxString &filename)
|
||||
}
|
||||
|
||||
// Open the file for import
|
||||
FLACImportFileHandle *handle = new FLACImportFileHandle(filename);
|
||||
auto handle = std::make_unique<FLACImportFileHandle>(filename);
|
||||
|
||||
bool success = handle->Init();
|
||||
if (!success) {
|
||||
delete handle;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return handle;
|
||||
return std::move(handle);
|
||||
}
|
||||
|
||||
|
||||
|
@ -193,7 +193,7 @@ public:
|
||||
wxArrayString GetSupportedExtensions();
|
||||
|
||||
///! Probes the file and opens it if appropriate
|
||||
ImportFileHandle *Open(wxString Filename);
|
||||
std::unique_ptr<ImportFileHandle> Open(const wxString &Filename) override;
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
@ -349,19 +349,17 @@ GStreamerImportPlugin::GetSupportedExtensions()
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Open the file and return an importer "file handle"
|
||||
ImportFileHandle *
|
||||
GStreamerImportPlugin::Open(wxString filename)
|
||||
std::unique_ptr<ImportFileHandle> GStreamerImportPlugin::Open(const wxString &filename)
|
||||
{
|
||||
GStreamerImportFileHandle *handle = new GStreamerImportFileHandle(filename);
|
||||
auto handle = std::make_unique<GStreamerImportFileHandle>(filename);
|
||||
|
||||
// Initialize the handle
|
||||
if (!handle->Init())
|
||||
{
|
||||
delete handle;
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return handle;
|
||||
return std::move(handle);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
@ -113,7 +113,7 @@ public:
|
||||
|
||||
wxString GetPluginStringID() { return wxT("lof"); }
|
||||
wxString GetPluginFormatDescription();
|
||||
ImportFileHandle *Open(const wxString &Filename) override;
|
||||
std::unique_ptr<ImportFileHandle> Open(const wxString &Filename) override;
|
||||
};
|
||||
|
||||
|
||||
@ -181,7 +181,7 @@ wxString LOFImportPlugin::GetPluginFormatDescription()
|
||||
return DESC;
|
||||
}
|
||||
|
||||
ImportFileHandle *LOFImportPlugin::Open(const wxString &filename)
|
||||
std::unique_ptr<ImportFileHandle> LOFImportPlugin::Open(const wxString &filename)
|
||||
{
|
||||
// Check if it is a binary file
|
||||
wxFile binaryFile;
|
||||
@ -216,7 +216,7 @@ ImportFileHandle *LOFImportPlugin::Open(const wxString &filename)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return new LOFImportFileHandle(filename, file);
|
||||
return std::make_unique<LOFImportFileHandle>(filename, file);
|
||||
}
|
||||
|
||||
wxString LOFImportFileHandle::GetFileDescription()
|
||||
|
@ -114,7 +114,7 @@ public:
|
||||
|
||||
wxString GetPluginStringID() { return wxT("libmad"); }
|
||||
wxString GetPluginFormatDescription();
|
||||
ImportFileHandle *Open(const wxString &Filename) override;
|
||||
std::unique_ptr<ImportFileHandle> Open(const wxString &Filename) override;
|
||||
};
|
||||
|
||||
class MP3ImportFileHandle final : public ImportFileHandle
|
||||
@ -176,7 +176,7 @@ wxString MP3ImportPlugin::GetPluginFormatDescription()
|
||||
return DESC;
|
||||
}
|
||||
|
||||
ImportFileHandle *MP3ImportPlugin::Open(const wxString &Filename)
|
||||
std::unique_ptr<ImportFileHandle> MP3ImportPlugin::Open(const wxString &Filename)
|
||||
{
|
||||
wxFile *file = new wxFile(Filename);
|
||||
|
||||
@ -188,7 +188,7 @@ ImportFileHandle *MP3ImportPlugin::Open(const wxString &Filename)
|
||||
/* There's no way to tell if this is a valid mp3 file before actually
|
||||
* decoding, so we return a valid FileHandle. */
|
||||
|
||||
return new MP3ImportFileHandle(file, Filename);
|
||||
return std::make_unique<MP3ImportFileHandle>(file, Filename);
|
||||
}
|
||||
|
||||
wxString MP3ImportFileHandle::GetFileDescription()
|
||||
|
@ -92,7 +92,7 @@ public:
|
||||
|
||||
wxString GetPluginStringID() { return wxT("liboggvorbis"); }
|
||||
wxString GetPluginFormatDescription();
|
||||
ImportFileHandle *Open(const wxString &Filename) override;
|
||||
std::unique_ptr<ImportFileHandle> Open(const wxString &Filename) override;
|
||||
};
|
||||
|
||||
|
||||
@ -171,7 +171,7 @@ wxString OggImportPlugin::GetPluginFormatDescription()
|
||||
return DESC;
|
||||
}
|
||||
|
||||
ImportFileHandle *OggImportPlugin::Open(const wxString &filename)
|
||||
std::unique_ptr<ImportFileHandle> OggImportPlugin::Open(const wxString &filename)
|
||||
{
|
||||
// Suppress some compiler warnings about unused global variables in the library header
|
||||
wxUnusedVar(OV_CALLBACKS_DEFAULT);
|
||||
@ -219,7 +219,7 @@ ImportFileHandle *OggImportPlugin::Open(const wxString &filename)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return new OggImportFileHandle(filename, file, vorbisFile);
|
||||
return std::make_unique<OggImportFileHandle>(filename, file, vorbisFile);
|
||||
}
|
||||
|
||||
wxString OggImportFileHandle::GetFileDescription()
|
||||
|
@ -82,7 +82,7 @@ public:
|
||||
|
||||
wxString GetPluginStringID() { return wxT("libsndfile"); }
|
||||
wxString GetPluginFormatDescription();
|
||||
ImportFileHandle *Open(const wxString &Filename) override;
|
||||
std::unique_ptr<ImportFileHandle> Open(const wxString &Filename) override;
|
||||
};
|
||||
|
||||
|
||||
@ -120,7 +120,7 @@ wxString PCMImportPlugin::GetPluginFormatDescription()
|
||||
return DESC;
|
||||
}
|
||||
|
||||
ImportFileHandle *PCMImportPlugin::Open(const wxString &filename)
|
||||
std::unique_ptr<ImportFileHandle> PCMImportPlugin::Open(const wxString &filename)
|
||||
{
|
||||
SF_INFO info;
|
||||
SNDFILE *file = NULL;
|
||||
@ -180,7 +180,7 @@ ImportFileHandle *PCMImportPlugin::Open(const wxString &filename)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return new PCMImportFileHandle(filename, file, info);
|
||||
return std::make_unique<PCMImportFileHandle>(filename, file, info);
|
||||
}
|
||||
|
||||
PCMImportFileHandle::PCMImportFileHandle(wxString name,
|
||||
|
@ -103,7 +103,7 @@ public:
|
||||
// Open the given file, returning true if it is in a recognized
|
||||
// format, false otherwise. This puts the importer into the open
|
||||
// state.
|
||||
virtual ImportFileHandle *Open(const wxString &Filename) = 0;
|
||||
virtual std::unique_ptr<ImportFileHandle> Open(const wxString &Filename) = 0;
|
||||
|
||||
virtual ~ImportPlugin() { }
|
||||
|
||||
|
@ -111,7 +111,7 @@ class QTImportPlugin final : public ImportPlugin
|
||||
wxString GetPluginStringID() { return wxT("quicktime"); }
|
||||
|
||||
wxString GetPluginFormatDescription();
|
||||
ImportFileHandle *Open(const wxString & Filename);
|
||||
std::unique_ptr<ImportFileHandle> Open(const wxString & Filename) override;
|
||||
|
||||
private:
|
||||
bool mInitialized;
|
||||
@ -172,7 +172,7 @@ wxString QTImportPlugin::GetPluginFormatDescription()
|
||||
return DESC;
|
||||
}
|
||||
|
||||
ImportFileHandle *QTImportPlugin::Open(const wxString & Filename)
|
||||
std::unique_ptr<ImportFileHandle> QTImportPlugin::Open(const wxString & Filename)
|
||||
{
|
||||
OSErr err;
|
||||
FSRef inRef;
|
||||
@ -209,7 +209,7 @@ ImportFileHandle *QTImportPlugin::Open(const wxString & Filename)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return new QTImportFileHandle(Filename, theMovie);
|
||||
return std::make_unique<QTImportFileHandle>(Filename, theMovie);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user