2010-01-23 19:44:49 +00:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
Audacity: A Digital Audio Editor
|
|
|
|
|
|
|
|
ImportPlugin.h
|
|
|
|
|
|
|
|
Joshua Haberman
|
|
|
|
Leland Lucius
|
|
|
|
|
|
|
|
*******************************************************************//**
|
|
|
|
|
|
|
|
\file ImportPlugin.h
|
|
|
|
\brief
|
|
|
|
The interface that all file import "plugins" (if you want to call
|
|
|
|
them that) must implement. Defines ImportFileHandle, ImportPlugin,
|
|
|
|
UnusableImportPlugin, ImportPluginList and UnusableImportPluginList.
|
|
|
|
|
|
|
|
Since this is part of libaudacity, it must not use any GUI parts
|
|
|
|
of wxWidgets.
|
|
|
|
|
|
|
|
*//****************************************************************//**
|
|
|
|
|
|
|
|
\class ImportFileHandle
|
|
|
|
\brief Base class for FlacImportFileHandle, LOFImportFileHandle,
|
2014-06-03 20:30:19 +00:00
|
|
|
MP3ImportFileHandle, OggImportFileHandle and PCMImportFileHandle.
|
2010-01-23 19:44:49 +00:00
|
|
|
Gives API for sound file import.
|
|
|
|
|
|
|
|
*//****************************************************************//**
|
|
|
|
|
|
|
|
\class ImportPlugin
|
|
|
|
\brief Base class for FlacImportPlugin, LOFImportPlugin,
|
2014-06-03 20:30:19 +00:00
|
|
|
MP3ImportPlugin, OggImportPlugin and PCMImportPlugin.
|
2010-01-23 19:44:49 +00:00
|
|
|
Gives API for sound file import.
|
|
|
|
|
|
|
|
*//****************************************************************//**
|
|
|
|
|
|
|
|
\class UnusableImportPlugin
|
|
|
|
\brief Used in place of a real plug in for plug ins that have not
|
|
|
|
been compiled or are not available in this version of Audacity. Has
|
2014-06-03 20:30:19 +00:00
|
|
|
enough information to identify the file extensions that would be used,
|
2010-01-23 19:44:49 +00:00
|
|
|
but little else.
|
|
|
|
|
|
|
|
*//*******************************************************************/
|
|
|
|
|
|
|
|
#ifndef __AUDACITY_IMPORTER__
|
|
|
|
#define __AUDACITY_IMPORTER__
|
|
|
|
|
2021-05-09 15:16:56 +00:00
|
|
|
|
2018-11-11 02:40:37 +00:00
|
|
|
|
2019-03-07 16:29:42 +00:00
|
|
|
#include "audacity/Types.h"
|
2017-09-25 18:07:23 +00:00
|
|
|
#include "../Internat.h"
|
2020-06-13 15:34:59 +00:00
|
|
|
#include "../MemoryX.h"
|
2016-03-02 17:52:13 +00:00
|
|
|
|
2019-05-22 05:48:34 +00:00
|
|
|
class AudacityProject;
|
2019-03-31 20:12:07 +00:00
|
|
|
class ProgressDialog;
|
|
|
|
enum class ProgressResult : unsigned;
|
2020-08-22 23:44:49 +00:00
|
|
|
class WaveTrackFactory;
|
2010-01-23 19:44:49 +00:00
|
|
|
class Track;
|
|
|
|
class Tags;
|
|
|
|
|
|
|
|
class ImportFileHandle;
|
|
|
|
|
2020-09-28 12:50:18 +00:00
|
|
|
class AUDACITY_DLL_API ImportPlugin /* not final */
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2010-04-04 08:19:53 +00:00
|
|
|
// Get unique string ID of this plugin, usually it corresponds
|
|
|
|
// to the underlying library, i.e. "libsndfile", "libflac", "libav"
|
2016-02-13 15:43:16 +00:00
|
|
|
// These MUST NOT change across Audacity versions (but NEW IDs can
|
2010-04-04 08:19:53 +00:00
|
|
|
// be added).
|
|
|
|
virtual wxString GetPluginStringID() = 0;
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
// Get a description of the file type this importer can import.
|
|
|
|
// Examples: "Ogg Vorbis", "MP3", "Uncompressed PCM"
|
2019-12-13 15:49:57 +00:00
|
|
|
virtual TranslatableString GetPluginFormatDescription() = 0;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Get a list of extensions this plugin expects to be able to
|
|
|
|
// import. If a filename matches any of these extensions,
|
|
|
|
// this importer will get first dibs on importing it.
|
2020-09-29 12:54:22 +00:00
|
|
|
virtual FileExtensions GetSupportedExtensions();
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2020-09-29 12:54:22 +00:00
|
|
|
bool SupportsExtension(const FileExtension &extension);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Open the given file, returning true if it is in a recognized
|
|
|
|
// format, false otherwise. This puts the importer into the open
|
|
|
|
// state.
|
2019-05-22 05:48:34 +00:00
|
|
|
virtual std::unique_ptr<ImportFileHandle> Open(
|
|
|
|
const FilePath &Filename, AudacityProject*) = 0;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2020-09-29 12:54:22 +00:00
|
|
|
virtual ~ImportPlugin();
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2020-09-29 12:54:22 +00:00
|
|
|
ImportPlugin(FileExtensions supportedExtensions);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2019-03-07 16:29:42 +00:00
|
|
|
const FileExtensions mExtensions;
|
2010-01-23 19:44:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-06-13 15:34:59 +00:00
|
|
|
class WaveTrack;
|
|
|
|
using TrackHolders = std::vector< std::vector< std::shared_ptr<WaveTrack> > >;
|
|
|
|
|
2020-09-28 12:50:18 +00:00
|
|
|
class AUDACITY_DLL_API ImportFileHandle /* not final */
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-03-31 20:12:07 +00:00
|
|
|
ImportFileHandle(const FilePath & filename);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2019-03-23 15:36:49 +00:00
|
|
|
virtual ~ImportFileHandle();
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// The importer should call this to create the progress dialog and
|
|
|
|
// identify the filename being imported.
|
2019-03-23 15:36:49 +00:00
|
|
|
void CreateProgress();
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2019-12-13 15:49:57 +00:00
|
|
|
// This is similar to GetPluginFormatDescription, but if possible the
|
2010-01-23 19:44:49 +00:00
|
|
|
// importer will return a more specific description of the
|
|
|
|
// specific file that is open.
|
2019-12-13 15:49:57 +00:00
|
|
|
virtual TranslatableString GetFileDescription() = 0;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Return an estimate of how many bytes the file will occupy once
|
2016-09-05 18:59:03 +00:00
|
|
|
// imported. In principle this may exceed main memory, so don't use
|
|
|
|
// size_t.
|
|
|
|
using ByteCount = unsigned long long;
|
|
|
|
virtual ByteCount GetFileUncompressedBytes() = 0;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// do the actual import, creating whatever tracks are necessary with
|
2020-08-22 23:44:49 +00:00
|
|
|
// the WaveTrackFactory and calling the progress callback every iteration
|
2010-01-23 19:44:49 +00:00
|
|
|
// through the importing loop
|
2016-08-16 17:56:15 +00:00
|
|
|
// The given Tags structure may also be modified.
|
|
|
|
// In case of errors or exceptions, it is not necessary to leave outTracks
|
|
|
|
// or tags unmodified.
|
2018-09-19 15:47:50 +00:00
|
|
|
// If resulting outTracks is not empty,
|
|
|
|
// then each member of it must be a nonempty vector.
|
2020-08-22 23:44:49 +00:00
|
|
|
virtual ProgressResult Import(WaveTrackFactory *trackFactory, TrackHolders &outTracks,
|
2016-03-02 17:52:13 +00:00
|
|
|
Tags *tags) = 0;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Return number of elements in stream list
|
|
|
|
virtual wxInt32 GetStreamCount() = 0;
|
|
|
|
|
|
|
|
// Return stream descriptions list
|
2019-12-18 15:21:34 +00:00
|
|
|
virtual const TranslatableStrings &GetStreamInfo() = 0;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Set stream "import/don't import" flag
|
|
|
|
virtual void SetStreamUsage(wxInt32 StreamID, bool Use) = 0;
|
|
|
|
|
2020-12-03 19:57:07 +00:00
|
|
|
//! Choose appropriate format, which will not be narrower than the specified one
|
|
|
|
static sampleFormat ChooseFormat(sampleFormat effectiveFormat);
|
|
|
|
|
|
|
|
//! Build a wave track with appropriate format, which will not be narrower than the specified one
|
|
|
|
std::shared_ptr<WaveTrack> NewWaveTrack( WaveTrackFactory &trackFactory,
|
|
|
|
sampleFormat effectiveFormat, double rate);
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
protected:
|
2019-03-07 19:50:22 +00:00
|
|
|
FilePath mFilename;
|
2019-03-31 20:12:07 +00:00
|
|
|
std::unique_ptr<ProgressDialog> mProgress;
|
2010-01-23 19:44:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UnusableImportPlugin
|
|
|
|
{
|
|
|
|
public:
|
2019-03-07 16:29:42 +00:00
|
|
|
UnusableImportPlugin(
|
2019-12-13 15:49:57 +00:00
|
|
|
const TranslatableString &formatName, FileExtensions extensions):
|
2010-01-23 19:44:49 +00:00
|
|
|
mFormatName(formatName),
|
2019-03-07 16:29:42 +00:00
|
|
|
mExtensions( std::move( extensions ) )
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-12-13 15:49:57 +00:00
|
|
|
TranslatableString GetPluginFormatDescription()
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
|
|
|
return mFormatName;
|
|
|
|
}
|
|
|
|
|
2019-12-27 21:14:25 +00:00
|
|
|
bool SupportsExtension(const FileExtension &extension)
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
|
|
|
return mExtensions.Index(extension, false) != wxNOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-12-13 15:49:57 +00:00
|
|
|
TranslatableString mFormatName;
|
2019-03-07 16:29:42 +00:00
|
|
|
const FileExtensions mExtensions;
|
2010-01-23 19:44:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|