Audacity  2.2.2
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 *******************************************************************//****************************************************************//****************************************************************//****************************************************************//****************************************************************//****************************************************************//*******************************************************************/
54 
55 #ifndef __AUDACITY_IMPORTER__
56 #define __AUDACITY_IMPORTER__
57 
58 #include "../Audacity.h"
59 #include "../Internat.h"
60 #include <wx/filename.h>
61 #include "../MemoryX.h"
62 
63 #include "../widgets/ProgressDialog.h"
64 
65 #include "ImportRaw.h" // defines TrackHolders
66 
67 class TrackFactory;
68 class Track;
69 class Tags;
70 
71 class ImportFileHandle;
72 
73 class ImportPlugin /* not final */
74 {
75 public:
76 
77  // Get unique string ID of this plugin, usually it corresponds
78  // to the underlying library, i.e. "libsndfile", "libflac", "libav"
79  // These MUST NOT change across Audacity versions (but NEW IDs can
80  // be added).
81  virtual wxString GetPluginStringID() = 0;
82 
83  // Get a description of the file type this importer can import.
84  // Examples: "Ogg Vorbis", "MP3", "Uncompressed PCM"
85  virtual wxString GetPluginFormatDescription() = 0;
86 
87  // Get a list of extensions this plugin expects to be able to
88  // import. If a filename matches any of these extensions,
89  // this importer will get first dibs on importing it.
90  virtual wxArrayString GetSupportedExtensions()
91  {
92  return mExtensions;
93  }
94 
95  bool SupportsExtension(const wxString &extension)
96  {
97  // Case-insensitive check if extension is supported
98  return mExtensions.Index(extension, false) != wxNOT_FOUND;
99  }
100 
101  // Open the given file, returning true if it is in a recognized
102  // format, false otherwise. This puts the importer into the open
103  // state.
104  virtual std::unique_ptr<ImportFileHandle> Open(const wxString &Filename) = 0;
105 
106  virtual ~ImportPlugin() { }
107 
108 protected:
109 
110  ImportPlugin(wxArrayString supportedExtensions):
111  mExtensions(supportedExtensions)
112  {
113  }
114 
115  wxArrayString mExtensions;
116 };
117 
118 
119 class ImportFileHandle /* not final */
120 {
121 public:
122  ImportFileHandle(const wxString & filename)
123  : mFilename(filename),
124  mProgress{}
125  {
126  }
127 
129  {
130  }
131 
132  // The importer should call this to create the progress dialog and
133  // identify the filename being imported.
135  {
136  wxFileName ff(mFilename);
137  wxString title;
138 
139  title.Printf(_("Importing %s"), GetFileDescription());
140  mProgress.create(title, ff.GetFullName());
141  }
142 
143  // This is similar to GetImporterDescription, but if possible the
144  // importer will return a more specific description of the
145  // specific file that is open.
146  virtual wxString GetFileDescription() = 0;
147 
148  // Return an estimate of how many bytes the file will occupy once
149  // imported. In principle this may exceed main memory, so don't use
150  // size_t.
151  using ByteCount = unsigned long long;
152  virtual ByteCount GetFileUncompressedBytes() = 0;
153 
154  // do the actual import, creating whatever tracks are necessary with
155  // the TrackFactory and calling the progress callback every iteration
156  // through the importing loop
157  // The given Tags structure may also be modified.
158  // In case of errors or exceptions, it is not necessary to leave outTracks
159  // or tags unmodified.
160  virtual ProgressResult Import(TrackFactory *trackFactory, TrackHolders &outTracks,
161  Tags *tags) = 0;
162 
163  // Return number of elements in stream list
164  virtual wxInt32 GetStreamCount() = 0;
165 
166  // Return stream descriptions list
167  virtual const wxArrayString &GetStreamInfo() = 0;
168 
169  // Set stream "import/don't import" flag
170  virtual void SetStreamUsage(wxInt32 StreamID, bool Use) = 0;
171 
172 protected:
173  wxString mFilename;
175 };
176 
177 
178 
180 {
181 public:
182  UnusableImportPlugin(const wxString &formatName, wxArrayString extensions):
183  mFormatName(formatName),
184  mExtensions(extensions)
185  {
186  }
187 
189  {
190  return mFormatName;
191  }
192 
193  bool SupportsExtension(const wxString &extension)
194  {
195  return mExtensions.Index(extension, false) != wxNOT_FOUND;
196  }
197 
198 private:
199  wxString mFormatName;
200  wxArrayString mExtensions;
201 };
202 
203 #endif
virtual ~ImportPlugin()
Definition: ImportPlugin.h:106
ProgressResult
virtual wxArrayString GetSupportedExtensions()
Definition: ImportPlugin.h:90
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:179
An ImportFileHandle for data.
Definition: ImportPlugin.h:119
wxString GetPluginFormatDescription()
Definition: ImportPlugin.h:188
virtual void SetStreamUsage(wxInt32 StreamID, bool Use)=0
virtual wxString GetFileDescription()=0
virtual ProgressResult Import(TrackFactory *trackFactory, TrackHolders &outTracks, Tags *tags)=0
unsigned long long ByteCount
Definition: ImportPlugin.h:151
wxArrayString mExtensions
Definition: ImportPlugin.h:200
UnusableImportPlugin(const wxString &formatName, wxArrayString extensions)
Definition: ImportPlugin.h:182
ImportPlugin(wxArrayString supportedExtensions)
Definition: ImportPlugin.h:110
virtual ~ImportFileHandle()
Definition: ImportPlugin.h:128
bool SupportsExtension(const wxString &extension)
Definition: ImportPlugin.h:193
Used to create a WaveTrack, or a LabelTrack.. Implementation of the functions of this class are dispe...
Definition: Track.h:863
virtual wxInt32 GetStreamCount()=0
virtual const wxArrayString & GetStreamInfo()=0
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
ImportFileHandle(const wxString &filename)
Definition: ImportPlugin.h:122
Maybe< ProgressDialog > mProgress
Definition: ImportPlugin.h:174
ID3 Tags (for MP3)
Definition: Tags.h:70
Base class for FlacImportPlugin, LOFImportPlugin, MP3ImportPlugin, OggImportPlugin and PCMImportPlugi...
Definition: ImportPlugin.h:73
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
virtual ByteCount GetFileUncompressedBytes()=0
virtual wxString GetPluginFormatDescription()=0
virtual std::unique_ptr< ImportFileHandle > Open(const wxString &Filename)=0
virtual wxString GetPluginStringID()=0
std::vector< std::unique_ptr< WaveTrack >> TrackHolders
Definition: ImportRaw.h:24
wxString mFilename
Definition: ImportPlugin.h:173
void create(Args &&...args)
Definition: MemoryX.h:251
bool SupportsExtension(const wxString &extension)
Definition: ImportPlugin.h:95
wxArrayString mExtensions
Definition: ImportPlugin.h:115