Audacity 3.2.0
ImportPlugin.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 ImportPlugin.h
6
7 Joshua Haberman
8 Leland Lucius
9
10*******************************************************************//****************************************************************//****************************************************************//****************************************************************//*******************************************************************/
44
45#ifndef __AUDACITY_IMPORTER__
46#define __AUDACITY_IMPORTER__
47
48
49
50#include <memory>
51#include "audacity/Types.h"
52#include "Identifier.h"
53#include "Internat.h"
54#include "SampleFormat.h"
55#include "wxArrayStringEx.h"
56
57class AudacityProject;
58class ProgressDialog;
59namespace BasicUI{ enum class ProgressResult : unsigned; }
61class Track;
62class Tags;
63
65
66class AUDACITY_DLL_API ImportPlugin /* not final */
67{
68public:
69
70 // Get unique string ID of this plugin, usually it corresponds
71 // to the underlying library, i.e. "libsndfile", "libflac", "libav"
72 // These MUST NOT change across Audacity versions (but NEW IDs can
73 // be added).
74 virtual wxString GetPluginStringID() = 0;
75
76 // Get a description of the file type this importer can import.
77 // Examples: "Ogg Vorbis", "MP3", "Uncompressed PCM"
79
80 // Get a list of extensions this plugin expects to be able to
81 // import. If a filename matches any of these extensions,
82 // this importer will get first dibs on importing it.
83 virtual FileExtensions GetSupportedExtensions();
84
85 bool SupportsExtension(const FileExtension &extension);
86
87 // Open the given file, returning true if it is in a recognized
88 // format, false otherwise. This puts the importer into the open
89 // state.
90 virtual std::unique_ptr<ImportFileHandle> Open(
91 const FilePath &Filename, AudacityProject*) = 0;
92
93 virtual ~ImportPlugin();
94
95protected:
96
97 ImportPlugin(FileExtensions supportedExtensions);
98
100};
101
102
103class WaveTrack;
104using TrackHolders = std::vector< std::vector< std::shared_ptr<WaveTrack> > >;
105
106class AUDACITY_DLL_API ImportFileHandle /* not final */
107{
108public:
110
111 ImportFileHandle(const FilePath & filename);
112
113 virtual ~ImportFileHandle();
114
115 // The importer should call this to create the progress dialog and
116 // identify the filename being imported.
117 void CreateProgress();
118
119 // This is similar to GetPluginFormatDescription, but if possible the
120 // importer will return a more specific description of the
121 // specific file that is open.
123
124 // Return an estimate of how many bytes the file will occupy once
125 // imported. In principle this may exceed main memory, so don't use
126 // size_t.
127 using ByteCount = unsigned long long;
129
130 // Return number of elements in stream list
131 virtual wxInt32 GetStreamCount() = 0;
132
133 // Return stream descriptions list, before Import() is called
134 virtual const TranslatableStrings &GetStreamInfo() = 0;
135
136 // Set stream "import/don't import" flag, before Import() is called
137 virtual void SetStreamUsage(wxInt32 StreamID, bool Use) = 0;
138
139 // do the actual import, creating whatever tracks are necessary with
140 // the WaveTrackFactory and calling the progress callback every iteration
141 // through the importing loop
142 // The given Tags structure may also be modified.
143 // In case of errors or exceptions, it is not necessary to leave outTracks
144 // or tags unmodified.
145 // If resulting outTracks is not empty,
146 // then each member of it must be a nonempty vector.
147 virtual ProgressResult Import(WaveTrackFactory *trackFactory, TrackHolders &outTracks,
148 Tags *tags) = 0;
149
151 static sampleFormat ChooseFormat(sampleFormat effectiveFormat);
152
153protected:
155 std::shared_ptr<WaveTrack> NewWaveTrack( WaveTrackFactory &trackFactory,
156 sampleFormat effectiveFormat, double rate);
157
159 std::unique_ptr<ProgressDialog> mProgress;
160};
161
162
163
165{
166public:
168 const TranslatableString &formatName, FileExtensions extensions):
169 mFormatName(formatName),
170 mExtensions( std::move( extensions ) )
171 {
172 }
173
175 {
176 return mFormatName;
177 }
178
179 bool SupportsExtension(const FileExtension &extension)
180 {
181 return mExtensions.Index(extension, false) != wxNOT_FOUND;
182 }
183
184private:
187};
188
189#endif
wxString FileExtension
File extension, not including any leading dot.
Definition: Identifier.h:224
std::vector< std::vector< std::shared_ptr< WaveTrack > > > TrackHolders
Definition: Import.h:39
wxString FilePath
Definition: Project.h:20
sampleFormat
Definition: SampleFormat.h:29
std::vector< TranslatableString > TranslatableStrings
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
An ImportFileHandle for data.
Definition: ImportPlugin.h:107
virtual ByteCount GetFileUncompressedBytes()=0
virtual TranslatableString GetFileDescription()=0
FilePath mFilename
Definition: ImportPlugin.h:158
virtual wxInt32 GetStreamCount()=0
virtual ProgressResult Import(WaveTrackFactory *trackFactory, TrackHolders &outTracks, Tags *tags)=0
virtual const TranslatableStrings & GetStreamInfo()=0
unsigned long long ByteCount
Definition: ImportPlugin.h:127
virtual void SetStreamUsage(wxInt32 StreamID, bool Use)=0
std::unique_ptr< ProgressDialog > mProgress
Definition: ImportPlugin.h:159
Base class for FlacImportPlugin, LOFImportPlugin, MP3ImportPlugin, OggImportPlugin and PCMImportPlugi...
Definition: ImportPlugin.h:67
virtual TranslatableString GetPluginFormatDescription()=0
virtual wxString GetPluginStringID()=0
virtual ~ImportPlugin()
const FileExtensions mExtensions
Definition: ImportPlugin.h:99
virtual std::unique_ptr< ImportFileHandle > Open(const FilePath &Filename, AudacityProject *)=0
ProgressDialog Class.
ID3 Tags (for MP3)
Definition: Tags.h:73
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
Holds a msgid for the translation catalog; may also bind format arguments.
Used in place of a real plug in for plug ins that have not been compiled or are not available in this...
Definition: ImportPlugin.h:165
bool SupportsExtension(const FileExtension &extension)
Definition: ImportPlugin.h:179
UnusableImportPlugin(const TranslatableString &formatName, FileExtensions extensions)
Definition: ImportPlugin.h:167
TranslatableString GetPluginFormatDescription()
Definition: ImportPlugin.h:174
TranslatableString mFormatName
Definition: ImportPlugin.h:185
const FileExtensions mExtensions
Definition: ImportPlugin.h:186
Used to create or clone a WaveTrack, with appropriate context from the project that will own the trac...
Definition: WaveTrack.h:612
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
ProgressResult
Definition: BasicUI.h:145
STL namespace.