Audacity  2.2.2
Export.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  Export.h
6 
7  Dominic Mazzoni
8 
9 **********************************************************************/
10 
11 #ifndef __AUDACITY_EXPORT__
12 #define __AUDACITY_EXPORT__
13 
14 #include "../MemoryX.h"
15 #include <vector>
16 #include <wx/dialog.h>
17 #include <wx/filename.h>
18 #include <wx/simplebook.h>
19 #include "../Tags.h"
20 #include "../SampleFormat.h"
21 #include "../widgets/wxPanelWrapper.h"
22 
23 class FileDialogWrapper;
24 class wxFileCtrlEvent;
25 class wxMemoryDC;
26 class wxStaticText;
27 class AudacityProject;
28 class DirManager;
29 class WaveTrack;
30 class TrackList;
31 class MixerSpec;
32 class ProgressDialog;
33 class TimeTrack;
34 class Mixer;
35 using WaveTrackConstArray = std::vector < std::shared_ptr < const WaveTrack > >;
36 enum class ProgressResult : unsigned;
37 
38 class AUDACITY_DLL_API FormatInfo
39 {
40  public:
42  FormatInfo( const FormatInfo & ) = default;
43  FormatInfo &operator = ( const FormatInfo & ) = default;
44  //FormatInfo( FormatInfo && ) = default;
45  //FormatInfo &operator = ( FormatInfo && ) = default;
47 
48  wxString mFormat;
49  wxString mDescription;
50  // wxString mExtension;
51  wxArrayString mExtensions;
52  wxString mMask;
53  unsigned mMaxChannels;
55 };
56 
57 //----------------------------------------------------------------------------
58 // ExportPlugin
59 //----------------------------------------------------------------------------
60 class AUDACITY_DLL_API ExportPlugin /* not final */
61 {
62 public:
63 
64  ExportPlugin();
65  virtual ~ExportPlugin();
66 
67  int AddFormat();
68  void SetFormat(const wxString & format, int index);
69  void SetDescription(const wxString & description, int index);
70  void AddExtension(const wxString &extension,int index);
71  void SetExtensions(const wxArrayString & extensions, int index);
72  void SetMask(const wxString & mask, int index);
73  void SetMaxChannels(unsigned maxchannels, unsigned index);
74  void SetCanMetaData(bool canmetadata, int index);
75 
76  virtual int GetFormatCount();
77  virtual wxString GetFormat(int index);
78  virtual wxString GetDescription(int index);
81  virtual wxString GetExtension(int index = 0);
84  virtual wxArrayString GetExtensions(int index = 0);
85  virtual wxString GetMask(int index);
86  virtual unsigned GetMaxChannels(int index);
87  virtual bool GetCanMetaData(int index);
88 
89  virtual bool IsExtension(const wxString & ext, int index);
90 
91  virtual bool DisplayOptions(wxWindow *parent, int format = 0);
92 
93  // Precondition: parent != NULL
94  virtual wxWindow *OptionsCreate(wxWindow *parent, int format) = 0;
95 
96  virtual bool CheckFileName(wxFileName &filename, int format = 0);
99  virtual int SetNumExportChannels() { return -1; }
100 
122  virtual ProgressResult Export(AudacityProject *project,
123  std::unique_ptr<ProgressDialog> &pDialog,
124  unsigned channels,
125  const wxString &fName,
126  bool selectedOnly,
127  double t0,
128  double t1,
129  MixerSpec *mixerSpec = NULL,
130  const Tags *metadata = NULL,
131  int subformat = 0) = 0;
132 
133 protected:
134  std::unique_ptr<Mixer> CreateMixer(const WaveTrackConstArray &inputTracks,
135  const TimeTrack *timeTrack,
136  double startTime, double stopTime,
137  unsigned numOutChannels, size_t outBufferSize, bool outInterleaved,
138  double outRate, sampleFormat outFormat,
139  bool highQuality = true, MixerSpec *mixerSpec = NULL);
140 
141  // Create or recycle a dialog.
142  static void InitProgress(std::unique_ptr<ProgressDialog> &pDialog,
143  const wxString &title, const wxString &message);
144 
145 private:
146  std::vector<FormatInfo> mFormatInfos;
147 };
148 
149 using ExportPluginArray = std::vector < std::unique_ptr< ExportPlugin > > ;
150 WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxWindow *, WindowPtrArray, class AUDACITY_DLL_API);
151 
152 //----------------------------------------------------------------------------
153 // Exporter
154 //----------------------------------------------------------------------------
155 class AUDACITY_DLL_API Exporter final : public wxEvtHandler
156 {
157 public:
158 
159  Exporter();
160  virtual ~Exporter();
161 
162  void SetFileDialogTitle( const wxString & DialogTitle );
163  void SetDefaultFormat( const wxString & Format ){ mFormatName = Format;};
164  void RegisterPlugin(std::unique_ptr<ExportPlugin> &&plugin);
165 
166  bool Process(AudacityProject *project, bool selectedOnly,
167  double t0, double t1);
168  bool Process(AudacityProject *project, unsigned numChannels,
169  const wxChar *type, const wxString & filename,
170  bool selectedOnly, double t0, double t1);
171 
172  void DisplayOptions(int index);
173  int FindFormatIndex(int exportindex);
174 
175  const ExportPluginArray &GetPlugins();
176 
177  // Auto Export from Timer Recording
178  bool ProcessFromTimerRecording(AudacityProject *project,
179  bool selectedOnly,
180  double t0,
181  double t1,
182  wxFileName fnFile,
183  int iFormat,
184  int iSubFormat,
185  int iFilterIndex);
186  bool SetAutoExportOptions(AudacityProject *project);
187  int GetAutoExportFormat();
188  int GetAutoExportSubFormat();
189  int GetAutoExportFilterIndex();
190  wxFileName GetAutoExportFileName();
191 
192 private:
193  bool ExamineTracks();
194  bool GetFilename();
195  bool CheckFilename();
196  bool CheckMix();
197  bool ExportTracks();
198 
199  static void CreateUserPaneCallback(wxWindow *parent, wxUIntPtr userdata);
200  void CreateUserPane(wxWindow *parent);
201  void OnFilterChanged(wxFileCtrlEvent & evt);
202 
203 private:
204  wxString mFormatName;
208  std::unique_ptr<MixerSpec> mMixerSpec;
209 
211 
212  wxFileName mFilename;
213  wxFileName mActualName;
214 
215  double mT0;
216  double mT1;
218  int mFormat;
221  unsigned mNumLeft;
222  unsigned mNumRight;
223  unsigned mNumMono;
224  unsigned mChannels;
226 
227  wxSimplebook *mBook;
228 
229  DECLARE_EVENT_TABLE()
230 };
231 
232 //----------------------------------------------------------------------------
233 // ExportMixerPanel
234 //----------------------------------------------------------------------------
235 class ExportMixerPanel final : public wxPanelWrapper
236 {
237 public:
238  ExportMixerPanel( wxWindow *parent, wxWindowID id,
239  MixerSpec *mixerSpec, wxArrayString trackNames,
240  const wxPoint& pos = wxDefaultPosition,
241  const wxSize& size = wxDefaultSize);
242  virtual ~ExportMixerPanel();
243 
244  void OnMouseEvent(wxMouseEvent & event);
245  void OnPaint(wxPaintEvent & event);
246 
247 private:
248  std::unique_ptr<wxBitmap> mBitmap;
249  wxRect mEnvRect;
250  int mWidth;
251  int mHeight;
256  wxArrayString mTrackNames;
258 
259  void SetFont( wxMemoryDC &memDC, const wxString &text, int width, int height );
260  double Distance( wxPoint &a, wxPoint &b );
261  bool IsOnLine( wxPoint p, wxPoint la, wxPoint lb );
262 
263  DECLARE_EVENT_TABLE()
264 };
265 
266 //----------------------------------------------------------------------------
267 // ExportMixerDialog
268 //----------------------------------------------------------------------------
269 class ExportMixerDialog final : public wxDialogWrapper
270 {
271 public:
272  // constructors and destructors
273  ExportMixerDialog( const TrackList * tracks, bool selectedOnly, unsigned maxNumChannels,
274  wxWindow *parent, wxWindowID id, const wxString &title,
275  const wxPoint& pos = wxDefaultPosition,
276  const wxSize& size = wxDefaultSize,
277  long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );
278  virtual ~ExportMixerDialog();
279 
280  MixerSpec* GetMixerSpec() { return mMixerSpec.get(); }
281 
282 private:
283  wxStaticText *mChannelsText;
284  std::unique_ptr<MixerSpec> mMixerSpec;
285  wxArrayString mTrackNames;
286 
287 private:
288  void OnOk( wxCommandEvent &event );
289  void OnCancel( wxCommandEvent &event );
290  void OnSlider( wxCommandEvent &event );
291  void OnSize( wxSizeEvent &event );
292 
293 private:
294  DECLARE_EVENT_TABLE()
295 };
296 #endif
A list of TrackListNode items.
Definition: Track.h:619
wxFileName mFilename
Definition: Export.h:212
virtual ~ExportMixerDialog()
Definition: Export.cpp:1348
std::unique_ptr< MixerSpec > mMixerSpec
Definition: Export.h:284
Creates and manages BlockFile objects.
Definition: DirManager.h:52
ProgressResult
Abstract base class used in importing a file.
Definition: Import.h:32
ProgressDialog Class.
FormatInfo & operator=(const FormatInfo &)=default
wxStaticText * mChannelsText
Definition: Export.h:283
std::vector< FormatInfo > mFormatInfos
Definition: Export.h:146
double mT1
Definition: Export.h:216
void SetDefaultFormat(const wxString &Format)
Definition: Export.h:163
int mSelectedChannel
Definition: Export.h:255
void OnSize(wxSizeEvent &event)
Definition: Export.cpp:1352
ArrayOf< wxRect > mTrackRects
Definition: Export.h:254
bool mSelectedOnly
Definition: Export.h:225
wxString mDescription
Definition: Export.h:49
int mSelectedTrack
Definition: Export.h:255
wxString mFormat
Definition: Export.h:48
std::vector< std::unique_ptr< ExportPlugin > > ExportPluginArray
Definition: Export.h:149
wxString mFormatName
Definition: Export.h:204
virtual int SetNumExportChannels()
Exporter plug-ins may override this to specify the number of channels in exported file...
Definition: Export.h:99
void OnCancel(wxCommandEvent &event)
Definition: Export.cpp:1376
std::unique_ptr< MixerSpec > mMixerSpec
Definition: Export.h:208
Main class to control the export function.
void SetFont(wxMemoryDC &memDC, const wxString &text, int width, int height)
Definition: Export.cpp:1039
unsigned mChannels
Definition: Export.h:224
unsigned mMaxChannels
Definition: Export.h:53
wxArrayString mTrackNames
Definition: Export.h:285
bool IsOnLine(wxPoint p, wxPoint la, wxPoint lb)
Definition: Export.cpp:1183
void OnMouseEvent(wxMouseEvent &event)
Definition: Export.cpp:1188
unsigned mNumRight
Definition: Export.h:222
AudacityProject * mProject
Definition: Export.h:207
MixerSpec * GetMixerSpec()
Definition: Export.h:280
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
A kind of Track used to 'warp time'.
Definition: TimeTrack.h:29
wxString mFileDialogTitle
Definition: Export.h:206
int format
Definition: ExportPCM.cpp:56
std::vector< std::shared_ptr< const WaveTrack > > WaveTrackConstArray
Definition: AudioIO.h:67
ExportMixerPanel(wxWindow *parent, wxWindowID id, MixerSpec *mixerSpec, wxArrayString trackNames, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Definition: Export.cpp:1017
wxArrayString mTrackNames
Definition: Export.h:256
sampleFormat
Definition: Types.h:188
unsigned mNumLeft
Definition: Export.h:221
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
int mSubFormat
Definition: Export.h:219
ExportPluginArray mPlugins
Definition: Export.h:210
FileDialogWrapper * mDialog
Definition: Export.h:205
virtual ~ExportMixerPanel()
Definition: Export.cpp:1034
wxSimplebook * mBook
Definition: Export.h:227
wxString mMask
Definition: Export.h:52
double Distance(wxPoint &a, wxPoint &b)
Definition: Export.cpp:1177
ID3 Tags (for MP3)
Definition: Tags.h:70
FormatInfo()
Definition: Export.h:41
std::unique_ptr< wxBitmap > mBitmap
Definition: Export.h:248
wxFileName mActualName
Definition: Export.h:213
bool mCanMetaData
Definition: Export.h:54
unsigned mNumMono
Definition: Export.h:223
~FormatInfo()
Definition: Export.h:46
void OnPaint(wxPaintEvent &event)
Definition: Export.cpp:1060
void OnSlider(wxCommandEvent &event)
Definition: Export.cpp:1359
ArrayOf< wxRect > mChannelRects
Definition: Export.h:253
double mT0
Definition: Export.h:215
ExportMixerDialog(const TrackList *tracks, bool selectedOnly, unsigned maxNumChannels, wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
Definition: Export.cpp:1261
int mFormat
Definition: Export.h:218
int mChannelHeight
Definition: Export.h:257
int mFilterIndex
Definition: Export.h:217
Dialog for advanced mixing.
Definition: Export.h:269
wxArrayString mExtensions
Definition: Export.h:51
WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxWindow *, WindowPtrArray, class AUDACITY_DLL_API)
wxRect mEnvRect
Definition: Export.h:249
void OnOk(wxCommandEvent &event)
Definition: Export.cpp:1371
Functions for doing the mixdown of the tracks.
Definition: Mix.h:80
int mTrackHeight
Definition: Export.h:257
int mNumSelected
Definition: Export.h:220
Panel that displays mixing for advanced mixing option.
Definition: Export.h:235
Class used with Mixer.
Definition: Mix.h:58
MixerSpec * mMixerSpec
Definition: Export.h:252