Audacity  3.0.3
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 <functional>
15 #include <vector>
16 #include <wx/filename.h> // member variable
17 #include "Identifier.h"
18 #include "SampleFormat.h"
19 #include "../widgets/wxPanelWrapper.h" // to inherit
20 #include "FileNames.h" // for FileTypes
21 
22 #include "Registry.h"
23 
24 class wxArrayString;
25 class FileDialogWrapper;
26 class wxFileCtrlEvent;
27 class wxMemoryDC;
28 class wxSimplebook;
29 class wxStaticText;
30 class AudacityProject;
31 class WaveTrack;
32 class Tags;
33 class TrackList;
34 class MixerSpec;
35 class ProgressDialog;
36 class ShuttleGui;
37 class Mixer;
38 using WaveTrackConstArray = std::vector < std::shared_ptr < const WaveTrack > >;
39 namespace BasicUI{ enum class ProgressResult : unsigned; }
40 class wxFileNameWrapper;
41 
42 class AUDACITY_DLL_API FormatInfo
43 {
44  public:
46  FormatInfo( const FormatInfo & ) = default;
47  FormatInfo &operator = ( const FormatInfo & ) = default;
48  //FormatInfo( FormatInfo && ) = default;
49  //FormatInfo &operator = ( FormatInfo && ) = default;
51 
52  wxString mFormat;
54  // wxString mExtension;
57  unsigned mMaxChannels;
59 };
60 
61 //----------------------------------------------------------------------------
62 // ExportPlugin
63 //----------------------------------------------------------------------------
64 class AUDACITY_DLL_API ExportPlugin /* not final */
65 {
66 public:
68 
69  ExportPlugin();
70  virtual ~ExportPlugin();
71 
72  int AddFormat();
73  void SetFormat(const wxString & format, int index);
74  void SetDescription(const TranslatableString & description, int index);
75  void AddExtension(const FileExtension &extension, int index);
76  void SetExtensions(FileExtensions extensions, int index);
77  void SetMask(FileNames::FileTypes mask, int index);
78  void SetMaxChannels(unsigned maxchannels, unsigned index);
79  void SetCanMetaData(bool canmetadata, int index);
80 
81  virtual int GetFormatCount();
82  virtual wxString GetFormat(int index);
83  TranslatableString GetDescription(int index);
86  virtual FileExtension GetExtension(int index = 0);
89  virtual FileExtensions GetExtensions(int index = 0);
90  FileNames::FileTypes GetMask(int index);
91  virtual unsigned GetMaxChannels(int index);
92  virtual bool GetCanMetaData(int index);
93 
94  virtual bool IsExtension(const FileExtension & ext, int index);
95 
96  virtual bool DisplayOptions(wxWindow *parent, int format = 0);
97 
98  virtual void OptionsCreate(ShuttleGui &S, int format) = 0;
99 
100  virtual bool CheckFileName(wxFileName &filename, int format = 0);
103  virtual int SetNumExportChannels() { return -1; }
104 
127  std::unique_ptr<ProgressDialog> &pDialog,
128  unsigned channels,
129  const wxFileNameWrapper &fName,
130  bool selectedOnly,
131  double t0,
132  double t1,
133  MixerSpec *mixerSpec = NULL,
134  const Tags *metadata = NULL,
135  int subformat = 0) = 0;
136 
137 protected:
138  std::unique_ptr<Mixer> CreateMixer(const TrackList &tracks,
139  bool selectionOnly,
140  double startTime, double stopTime,
141  unsigned numOutChannels, size_t outBufferSize, bool outInterleaved,
142  double outRate, sampleFormat outFormat,
143  MixerSpec *mixerSpec);
144 
145  // Create or recycle a dialog.
146  static void InitProgress(std::unique_ptr<ProgressDialog> &pDialog,
147  const TranslatableString &title, const TranslatableString &message);
148  static void InitProgress(std::unique_ptr<ProgressDialog> &pDialog,
149  const wxFileNameWrapper &title, const TranslatableString &message);
150 
151 private:
152  std::vector<FormatInfo> mFormatInfos;
153 };
154 
155 using ExportPluginArray = std::vector < std::unique_ptr< ExportPlugin > > ;
156 
157 //----------------------------------------------------------------------------
158 // Exporter
159 //----------------------------------------------------------------------------
160 
161 // For a file suffix change from the options.
162 wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API,
163  AUDACITY_FILE_SUFFIX_EVENT, wxCommandEvent);
164 
165 class AUDACITY_DLL_API Exporter final : public wxEvtHandler
166 {
167 public:
168 
170  std::function< std::unique_ptr< ExportPlugin >() >;
171 
172  // Objects of this type are statically constructed in files implementing
173  // subclasses of ExportPlugin
174  // Register factories, not plugin objects themselves, which allows them
175  // to have some fresh state variables each time export begins again
176  // and to compute translated strings for the current locale
177  struct AUDACITY_DLL_API RegisteredExportPlugin{
179  const Identifier &id, // an internal string naming the plug-in
180  const ExportPluginFactory&,
181  const Registry::Placement &placement = { wxEmptyString, {} } );
182  };
183 
184  static bool DoEditMetadata(AudacityProject &project,
185  const TranslatableString &title,
186  const TranslatableString &shortUndoDescription, bool force);
187 
188  Exporter( AudacityProject &project );
189  virtual ~Exporter();
190 
191  void SetFileDialogTitle( const TranslatableString & DialogTitle );
192  void SetDefaultFormat( const FileExtension & Format ){ mFormatName = Format;};
193 
194  bool Process(bool selectedOnly,
195  double t0, double t1);
196  bool Process(unsigned numChannels,
197  const FileExtension &type, const wxString & filename,
198  bool selectedOnly, double t0, double t1);
199 
200  void DisplayOptions(int index);
201  int FindFormatIndex(int exportindex);
202 
203  const ExportPluginArray &GetPlugins();
204 
205  // Auto Export from Timer Recording
206  bool ProcessFromTimerRecording(bool selectedOnly,
207  double t0,
208  double t1,
209  wxFileName fnFile,
210  int iFormat,
211  int iSubFormat,
212  int iFilterIndex);
213  bool SetAutoExportOptions();
214  int GetAutoExportFormat();
215  int GetAutoExportSubFormat();
216  int GetAutoExportFilterIndex();
217  wxFileName GetAutoExportFileName();
218  void OnExtensionChanged(wxCommandEvent &evt);
219  void OnHelp(wxCommandEvent &evt);
220 
221 private:
222  bool ExamineTracks();
223  bool GetFilename();
224  bool CheckFilename();
225  bool CheckMix(bool prompt = true);
226  bool ExportTracks();
227 
228  static void CreateUserPaneCallback(wxWindow *parent, wxUIntPtr userdata);
229  void CreateUserPane(wxWindow *parent);
230  void OnFilterChanged(wxFileCtrlEvent & evt);
231 
232 private:
237  std::unique_ptr<MixerSpec> mMixerSpec;
238 
240 
241  wxFileName mFilename;
242  wxFileName mActualName;
243 
244  double mT0;
245  double mT1;
247  int mFormat;
250  unsigned mNumLeft;
251  unsigned mNumRight;
252  unsigned mNumMono;
253  unsigned mChannels;
255 
256  wxSimplebook *mBook;
257 
258  DECLARE_EVENT_TABLE()
259 };
260 
261 //----------------------------------------------------------------------------
262 // ExportMixerPanel
263 //----------------------------------------------------------------------------
264 class ExportMixerPanel final : public wxPanelWrapper
265 {
266 public:
267  ExportMixerPanel( wxWindow *parent, wxWindowID id,
268  MixerSpec *mixerSpec, wxArrayString trackNames,
269  const wxPoint& pos = wxDefaultPosition,
270  const wxSize& size = wxDefaultSize);
271  virtual ~ExportMixerPanel();
272 
273  void OnMouseEvent(wxMouseEvent & event);
274  void OnPaint(wxPaintEvent & event);
275 
276 private:
277  std::unique_ptr<wxBitmap> mBitmap;
278  wxRect mEnvRect;
279  int mWidth;
280  int mHeight;
284  int mSelectedTrack, mSelectedChannel;
285  wxArrayString mTrackNames;
286  int mBoxWidth, mChannelHeight, mTrackHeight;
287 
288  void SetFont( wxMemoryDC &memDC, const wxString &text, int width, int height );
289  double Distance( wxPoint &a, wxPoint &b );
290  bool IsOnLine( wxPoint p, wxPoint la, wxPoint lb );
291 
292  DECLARE_EVENT_TABLE()
293 };
294 
295 //----------------------------------------------------------------------------
296 // ExportMixerDialog
297 //----------------------------------------------------------------------------
298 class ExportMixerDialog final : public wxDialogWrapper
299 {
300 public:
301  // constructors and destructors
302  ExportMixerDialog( const TrackList * tracks, bool selectedOnly, unsigned maxNumChannels,
303  wxWindow *parent, wxWindowID id, const TranslatableString &title,
304  const wxPoint& pos = wxDefaultPosition,
305  const wxSize& size = wxDefaultSize,
306  long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );
307  virtual ~ExportMixerDialog();
308 
309  MixerSpec* GetMixerSpec() { return mMixerSpec.get(); }
310 
311 private:
312  wxStaticText *mChannelsText;
313  std::unique_ptr<MixerSpec> mMixerSpec;
314  wxArrayString mTrackNames;
315 
316 private:
317  void OnOk( wxCommandEvent &event );
318  void OnCancel( wxCommandEvent &event );
319  void OnMixerPanelHelp( wxCommandEvent &event );
320  void OnSlider( wxCommandEvent &event );
321  void OnSize( wxSizeEvent &event );
322 
323 private:
324  DECLARE_EVENT_TABLE()
325 };
326 
329 
333 AUDACITY_DLL_API void ShowExportErrorDialog(wxString ErrorCode,
335  const TranslatableString& caption = AudacityExportCaptionStr());
336 
337 AUDACITY_DLL_API
339 
340 #endif
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
WaveTrackConstArray
std::vector< std::shared_ptr< const WaveTrack > > WaveTrackConstArray
Definition: AudioIO.h:49
FormatInfo::~FormatInfo
~FormatInfo()
Definition: Export.h:50
ExportMixerDialog::mChannelsText
wxStaticText * mChannelsText
Definition: Export.h:312
ExportPlugin::SetNumExportChannels
virtual int SetNumExportChannels()
Exporter plug-ins may override this to specify the number of channels in exported file....
Definition: Export.h:103
ExportMixerPanel::mTrackNames
wxArrayString mTrackNames
Definition: Export.h:285
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
FormatInfo::mExtensions
FileExtensions mExtensions
Definition: Export.h:55
wxFileNameWrapper
Definition: wxFileNameWrapper.h:21
FormatInfo::mFormat
wxString mFormat
Definition: Export.h:52
wxPanelWrapper
Definition: wxPanelWrapper.h:41
Tags
ID3 Tags (for MP3)
Definition: Tags.h:74
Format
Abstract base class used in importing a file.
TrackList
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1280
Exporter::mChannels
unsigned mChannels
Definition: Export.h:253
Exporter
Definition: Export.h:166
BasicUI::ProgressResult
ProgressResult
Definition: BasicUI.h:145
Exporter::mActualName
wxFileName mActualName
Definition: Export.h:242
ExportMixerPanel::mBitmap
std::unique_ptr< wxBitmap > mBitmap
Definition: Export.h:277
ExportMixerPanel::mChannelRects
ArrayOf< wxRect > mChannelRects
Definition: Export.h:282
wxDECLARE_EXPORTED_EVENT
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API, AUDACITY_FILE_SUFFIX_EVENT, wxCommandEvent)
ExportMixerPanel::mTrackHeight
int mTrackHeight
Definition: Export.h:286
Exporter::mFormat
int mFormat
Definition: Export.h:247
ExportPlugin::mFormatInfos
std::vector< FormatInfo > mFormatInfos
Definition: Export.h:152
Exporter::mFilename
wxFileName mFilename
Definition: Export.h:241
OnSize
static void OnSize(wxSizeEvent &evt)
Definition: VSTEffect.cpp:2784
ExportMixerPanel::mMixerSpec
MixerSpec * mMixerSpec
Definition: Export.h:281
wxArrayStringEx
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Definition: wxArrayStringEx.h:18
Registry::Placement
Definition: Registry.h:219
Exporter::mSelectedOnly
bool mSelectedOnly
Definition: Export.h:254
ExportPlugin::Export
virtual ProgressResult Export(AudacityProject *project, std::unique_ptr< ProgressDialog > &pDialog, unsigned channels, const wxFileNameWrapper &fName, bool selectedOnly, double t0, double t1, MixerSpec *mixerSpec=NULL, const Tags *metadata=NULL, int subformat=0)=0
called to export audio into a file.
Identifier
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
Exporter::mNumSelected
int mNumSelected
Definition: Export.h:249
FileExtension
wxString FileExtension
File extension, not including any leading dot.
Definition: Identifier.h:224
ExportMixerDialog
Dialog for advanced mixing.
Definition: Export.h:299
ExportPluginArray
std::vector< std::unique_ptr< ExportPlugin > > ExportPluginArray
Definition: Export.h:155
Exporter::mSubFormat
int mSubFormat
Definition: Export.h:248
ProgressDialog
ProgressDialog Class.
Definition: ProgressDialog.h:51
Exporter::mFormatName
FileExtension mFormatName
Definition: Export.h:233
Exporter::mMixerSpec
std::unique_ptr< MixerSpec > mMixerSpec
Definition: Export.h:237
FormatInfo::mMaxChannels
unsigned mMaxChannels
Definition: Export.h:57
ExportMixerPanel
Panel that displays mixing for advanced mixing option.
Definition: Export.h:265
AudacityExportCaptionStr
AUDACITY_DLL_API TranslatableString AudacityExportCaptionStr()
Definition: Export.cpp:1502
ExportMixerPanel::mTrackRects
ArrayOf< wxRect > mTrackRects
Definition: Export.h:283
Exporter::mPlugins
ExportPluginArray mPlugins
Definition: Export.h:239
Exporter::mDialog
FileDialogWrapper * mDialog
Definition: Export.h:234
Exporter::mT1
double mT1
Definition: Export.h:245
Identifier.h
format
int format
Definition: ExportPCM.cpp:56
ExportMixerDialog::mTrackNames
wxArrayString mTrackNames
Definition: Export.h:314
Exporter::mT0
double mT0
Definition: Export.h:244
title
static const auto title
Definition: UpdateNoticeDialog.cpp:23
ExportMixerDialog::GetMixerSpec
MixerSpec * GetMixerSpec()
Definition: Export.h:309
Registry.h
sampleFormat
sampleFormat
Definition: SampleFormat.h:29
wxDialogWrapper
Definition: wxPanelWrapper.h:81
Exporter::RegisteredExportPlugin
Definition: Export.h:177
ExportMixerPanel::mHeight
int mHeight
Definition: Export.h:280
ExportMixerPanel::mWidth
int mWidth
Definition: Export.h:279
BasicUI
Definition: Export.h:39
FileDialogWrapper
Definition: wxPanelWrapper.h:165
FormatInfo::FormatInfo
FormatInfo()
Definition: Export.h:45
Exporter::mFileDialogTitle
TranslatableString mFileDialogTitle
Definition: Export.h:235
FormatInfo::mDescription
TranslatableString mDescription
Definition: Export.h:53
Exporter::mBook
wxSimplebook * mBook
Definition: Export.h:256
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
FormatInfo::FormatInfo
FormatInfo(const FormatInfo &)=default
FileNames.h
ExportMixerPanel::mSelectedTrack
int mSelectedTrack
Definition: Export.h:284
Exporter::mFilterIndex
int mFilterIndex
Definition: Export.h:246
FileNames::FileTypes
std::vector< FileType > FileTypes
Definition: FileNames.h:76
Exporter::mNumMono
unsigned mNumMono
Definition: Export.h:252
FormatInfo::mMask
FileNames::FileTypes mMask
Definition: Export.h:56
MixerSpec
Class used with Mixer.
Definition: Mix.h:55
ExportPlugin
Definition: Export.h:65
FormatInfo
Definition: Export.h:43
ShowExportErrorDialog
AUDACITY_DLL_API void ShowExportErrorDialog(wxString ErrorCode, TranslatableString message=AudacityExportMessageStr(), const TranslatableString &caption=AudacityExportCaptionStr())
Definition: Export.cpp:1519
Mixer
Functions for doing the mixdown of the tracks.
Definition: Mix.h:76
AudacityExportMessageStr
AUDACITY_DLL_API TranslatableString AudacityExportMessageStr()
Definition: Export.cpp:1506
SampleFormat.h
Exporter::SetDefaultFormat
void SetDefaultFormat(const FileExtension &Format)
Definition: Export.h:192
Exporter::ExportPluginFactory
std::function< std::unique_ptr< ExportPlugin >() > ExportPluginFactory
Definition: Export.h:170
ArrayOf< wxRect >
ExportMixerPanel::mEnvRect
wxRect mEnvRect
Definition: Export.h:278
ShowDiskFullExportErrorDialog
AUDACITY_DLL_API void ShowDiskFullExportErrorDialog(const wxFileNameWrapper &fileName)
Definition: Export.cpp:1531
Exporter::mNumRight
unsigned mNumRight
Definition: Export.h:251
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631
FormatInfo::mCanMetaData
bool mCanMetaData
Definition: Export.h:58
Exporter::mNumLeft
unsigned mNumLeft
Definition: Export.h:250
ExportMixerDialog::mMixerSpec
std::unique_ptr< MixerSpec > mMixerSpec
Definition: Export.h:313
Exporter::mProject
AudacityProject * mProject
Definition: Export.h:236