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