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