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;
63class Tags;
64
66
67class AUDACITY_DLL_API ImportPlugin /* not final */
68{
69public:
70
71 // Get unique string ID of this plugin, usually it corresponds
72 // to the underlying library, i.e. "libsndfile", "libflac", "libav"
73 // These MUST NOT change across Audacity versions (but NEW IDs can
74 // be added).
75 virtual wxString GetPluginStringID() = 0;
76
77 // Get a description of the file type this importer can import.
78 // Examples: "Ogg Vorbis", "MP3", "Uncompressed PCM"
80
81 // Get a list of extensions this plugin expects to be able to
82 // import. If a filename matches any of these extensions,
83 // this importer will get first dibs on importing it.
84 virtual FileExtensions GetSupportedExtensions();
85
87
88 virtual TranslatableString FailureHint() const;
89
90 bool SupportsExtension(const FileExtension &extension);
91
92 // Open the given file, returning true if it is in a recognized
93 // format, false otherwise. This puts the importer into the open
94 // state.
95 virtual std::unique_ptr<ImportFileHandle> Open(
96 const FilePath &Filename, AudacityProject*) = 0;
97
98 virtual ~ImportPlugin();
99
100protected:
101
102 ImportPlugin(FileExtensions supportedExtensions);
103
105};
106
107
108class WaveTrack;
109using TrackHolders = std::vector< std::vector< std::shared_ptr<WaveTrack> > >;
110
111class AUDACITY_DLL_API ImportFileHandle /* not final */
112{
113public:
115
116 ImportFileHandle(const FilePath & filename);
117
118 virtual ~ImportFileHandle();
119
120 // The importer should call this to create the progress dialog and
121 // identify the filename being imported.
122 void CreateProgress();
123
124 // This is similar to GetPluginFormatDescription, but if possible the
125 // importer will return a more specific description of the
126 // specific file that is open.
128
129 // Return an estimate of how many bytes the file will occupy once
130 // imported. In principle this may exceed main memory, so don't use
131 // size_t.
132 using ByteCount = unsigned long long;
134
135 // Return number of elements in stream list
136 virtual wxInt32 GetStreamCount() = 0;
137
138 // Return stream descriptions list, before Import() is called
139 virtual const TranslatableStrings &GetStreamInfo() = 0;
140
141 // Set stream "import/don't import" flag, before Import() is called
142 virtual void SetStreamUsage(wxInt32 StreamID, bool Use) = 0;
143
144 // do the actual import, creating whatever tracks are necessary with
145 // the WaveTrackFactory and calling the progress callback every iteration
146 // through the importing loop
147 // The given Tags structure may also be modified.
148 // In case of errors or exceptions, it is not necessary to leave outTracks
149 // or tags unmodified.
150 // If resulting outTracks is not empty,
151 // then each member of it must be a nonempty vector.
152 virtual ProgressResult Import(WaveTrackFactory *trackFactory, TrackHolders &outTracks,
153 Tags *tags) = 0;
154
156 static sampleFormat ChooseFormat(sampleFormat effectiveFormat);
157
158protected:
160 std::shared_ptr<WaveTrack> NewWaveTrack( WaveTrackFactory &trackFactory,
161 sampleFormat effectiveFormat, double rate);
162
164 std::unique_ptr<ProgressDialog> mProgress;
165};
166
167
168
170{
171public:
173 const TranslatableString &formatName, FileExtensions extensions):
174 mFormatName(formatName),
175 mExtensions( std::move( extensions ) )
176 {
177 }
178
180 {
181 return mFormatName;
182 }
183
184 bool SupportsExtension(const FileExtension &extension)
185 {
186 return mExtensions.Index(extension, false) != wxNOT_FOUND;
187 }
188
189private:
192};
193
194#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:21
sampleFormat
The ordering of these values with operator < agrees with the order of increasing bit width.
Definition: SampleFormat.h:30
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:90
An ImportFileHandle for data.
Definition: ImportPlugin.h:112
virtual ByteCount GetFileUncompressedBytes()=0
virtual TranslatableString GetFileDescription()=0
FilePath mFilename
Definition: ImportPlugin.h:163
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:132
virtual void SetStreamUsage(wxInt32 StreamID, bool Use)=0
std::unique_ptr< ProgressDialog > mProgress
Definition: ImportPlugin.h:164
Base class for FlacImportPlugin, LOFImportPlugin, MP3ImportPlugin, OggImportPlugin and PCMImportPlugi...
Definition: ImportPlugin.h:68
virtual TranslatableString GetPluginFormatDescription()=0
virtual wxString GetPluginStringID()=0
virtual ~ImportPlugin()
const FileExtensions mExtensions
Definition: ImportPlugin.h:104
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:162
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:170
bool SupportsExtension(const FileExtension &extension)
Definition: ImportPlugin.h:184
UnusableImportPlugin(const TranslatableString &formatName, FileExtensions extensions)
Definition: ImportPlugin.h:172
TranslatableString GetPluginFormatDescription()
Definition: ImportPlugin.h:179
TranslatableString mFormatName
Definition: ImportPlugin.h:190
const FileExtensions mExtensions
Definition: ImportPlugin.h:191
Used to create or clone a WaveTrack, with appropriate context from the project that will own the trac...
Definition: WaveTrack.h:561
A Track that contains audio waveform data.
Definition: WaveTrack.h:51
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
ProgressResult
Definition: BasicUI.h:147
STL namespace.