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 "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
43namespace BasicUI
44{
45class ProgressDialog;
46}
47
48class AUDACITY_DLL_API FormatInfo
49{
50 public:
52 FormatInfo( const FormatInfo & ) = default;
53 FormatInfo &operator = ( const FormatInfo & ) = default;
54 //FormatInfo( FormatInfo && ) = default;
55 //FormatInfo &operator = ( FormatInfo && ) = default;
57
58 wxString mFormat;
60 // wxString mExtension;
63 unsigned mMaxChannels;
65};
66
67//----------------------------------------------------------------------------
68// ExportPlugin
69//----------------------------------------------------------------------------
70class AUDACITY_DLL_API ExportPlugin /* not final */
71{
72public:
74
76 virtual ~ExportPlugin();
77
78 int AddFormat();
79 void SetFormat(const wxString & format, int index);
80 void SetDescription(const TranslatableString & description, int index);
81 void AddExtension(const FileExtension &extension, int index);
82 void SetExtensions(FileExtensions extensions, int index);
83 void SetMask(FileNames::FileTypes mask, int index);
84 void SetMaxChannels(unsigned maxchannels, unsigned index);
85 void SetCanMetaData(bool canmetadata, int index);
86
87 virtual int GetFormatCount();
88 virtual wxString GetFormat(int index);
89 TranslatableString GetDescription(int index);
92 virtual FileExtension GetExtension(int index = 0);
95 virtual FileExtensions GetExtensions(int index = 0);
96 FileNames::FileTypes GetMask(int index);
97 virtual unsigned GetMaxChannels(int index);
98 virtual bool GetCanMetaData(int index);
99
100 virtual bool IsExtension(const FileExtension & ext, int index);
101
102 virtual bool DisplayOptions(wxWindow *parent, int format = 0);
103
104 virtual void OptionsCreate(ShuttleGui &S, int format) = 0;
105
106 virtual bool CheckFileName(wxFileName &filename, int format = 0);
109 virtual int SetNumExportChannels() { return -1; }
110
133 std::unique_ptr<BasicUI::ProgressDialog> &pDialog,
134 unsigned channels,
135 const wxFileNameWrapper &fName,
136 bool selectedOnly,
137 double t0,
138 double t1,
139 MixerSpec *mixerSpec = NULL,
140 const Tags *metadata = NULL,
141 int subformat = 0) = 0;
142
143protected:
144 std::unique_ptr<Mixer> CreateMixer(const TrackList &tracks,
145 bool selectionOnly,
146 double startTime, double stopTime,
147 unsigned numOutChannels, size_t outBufferSize, bool outInterleaved,
148 double outRate, sampleFormat outFormat,
149 MixerSpec *mixerSpec);
150
151 // Create or recycle a dialog.
152 static void InitProgress(std::unique_ptr<BasicUI::ProgressDialog> &pDialog,
153 const TranslatableString &title, const TranslatableString &message);
154 static void InitProgress(std::unique_ptr<BasicUI::ProgressDialog> &pDialog,
155 const wxFileNameWrapper &title, const TranslatableString &message);
156
157private:
158 std::vector<FormatInfo> mFormatInfos;
159};
160
161using ExportPluginArray = std::vector < std::unique_ptr< ExportPlugin > > ;
162
163//----------------------------------------------------------------------------
164// Exporter
165//----------------------------------------------------------------------------
166
167// For a file suffix change from the options.
169 AUDACITY_FILE_SUFFIX_EVENT, wxCommandEvent);
170
171class AUDACITY_DLL_API Exporter final : public wxEvtHandler
172{
173 struct ExporterItem;
174public:
175
177 std::function< std::unique_ptr< ExportPlugin >() >;
178
179 // Objects of this type are statically constructed in files implementing
180 // subclasses of ExportPlugin
181 // Register factories, not plugin objects themselves, which allows them
182 // to have some fresh state variables each time export begins again
183 // and to compute translated strings for the current locale
184 struct AUDACITY_DLL_API RegisteredExportPlugin
185 : public Registry::RegisteredItem<ExporterItem>
186 {
188 const Identifier &id, // an internal string naming the plug-in
189 const ExportPluginFactory&,
190 const Registry::Placement &placement = { wxEmptyString, {} } );
191 };
192
193 Exporter( AudacityProject &project );
194 virtual ~Exporter();
195
196 void SetFileDialogTitle( const TranslatableString & DialogTitle );
197 void SetDefaultFormat( const FileExtension & Format ){ mFormatName = Format;};
198
199 bool Process(bool selectedOnly,
200 double t0, double t1);
201 bool Process(unsigned numChannels,
202 const FileExtension &type, const wxString & filename,
203 bool selectedOnly, double t0, double t1);
204
205 bool Process(
206 unsigned numChannels, const FileExtension& type, const wxString& filename,
207 bool selectedOnly, double t0, double t1,
208 std::unique_ptr<BasicUI::ProgressDialog>& progressDialog);
209
210 void DisplayOptions(int index);
211 int FindFormatIndex(int exportindex);
212
213 const ExportPluginArray &GetPlugins();
214
215 // Auto Export from Timer Recording
216 bool ProcessFromTimerRecording(bool selectedOnly,
217 double t0,
218 double t1,
219 wxFileName fnFile,
220 int iFormat,
221 int iSubFormat,
222 int iFilterIndex);
223 bool SetAutoExportOptions();
224 int GetAutoExportFormat();
225 int GetAutoExportSubFormat();
226 int GetAutoExportFilterIndex();
227 wxFileName GetAutoExportFileName();
228 void OnExtensionChanged(wxCommandEvent &evt);
229 void OnHelp(wxCommandEvent &evt);
230
231private:
232 struct AUDACITY_DLL_API ExporterItem final : Registry::SingleItem {
237 };
238
239 bool ExamineTracks();
240 bool GetFilename();
241 bool CheckFilename();
242 bool CheckMix(bool prompt = true);
243 bool ExportTracks(std::unique_ptr<BasicUI::ProgressDialog>& progressDialog);
244
245 static void CreateUserPaneCallback(wxWindow *parent, wxUIntPtr userdata);
246 void CreateUserPane(wxWindow *parent);
247 void OnFilterChanged(wxFileCtrlEvent & evt);
248
249private:
254 std::unique_ptr<MixerSpec> mMixerSpec;
255
257
258 wxFileName mFilename;
259 wxFileName mActualName;
260
261 double mT0;
262 double mT1;
267 unsigned mNumLeft;
268 unsigned mNumRight;
269 unsigned mNumMono;
270 unsigned mChannels;
272
273 wxSimplebook *mBook;
274
275 DECLARE_EVENT_TABLE()
276};
277
278//----------------------------------------------------------------------------
279// ExportMixerPanel
280//----------------------------------------------------------------------------
282{
283public:
284 ExportMixerPanel( wxWindow *parent, wxWindowID id,
285 MixerSpec *mixerSpec, wxArrayString trackNames,
286 const wxPoint& pos = wxDefaultPosition,
287 const wxSize& size = wxDefaultSize);
288 virtual ~ExportMixerPanel();
289
290 void OnMouseEvent(wxMouseEvent & event);
291 void OnPaint(wxPaintEvent & event);
292
293private:
294 std::unique_ptr<wxBitmap> mBitmap;
295 wxRect mEnvRect;
302 wxArrayString mTrackNames;
304
305 void SetFont( wxMemoryDC &memDC, const wxString &text, int width, int height );
306 double Distance( wxPoint &a, wxPoint &b );
307 bool IsOnLine( wxPoint p, wxPoint la, wxPoint lb );
308
309 DECLARE_EVENT_TABLE()
310};
311
312//----------------------------------------------------------------------------
313// ExportMixerDialog
314//----------------------------------------------------------------------------
316{
317public:
318 // constructors and destructors
319 ExportMixerDialog( const TrackList * tracks, bool selectedOnly, unsigned maxNumChannels,
320 wxWindow *parent, wxWindowID id, const TranslatableString &title,
321 const wxPoint& pos = wxDefaultPosition,
322 const wxSize& size = wxDefaultSize,
323 long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );
324 virtual ~ExportMixerDialog();
325
326 MixerSpec* GetMixerSpec() { return mMixerSpec.get(); }
327
328private:
329 wxStaticText *mChannelsText;
330 std::unique_ptr<MixerSpec> mMixerSpec;
331 wxArrayString mTrackNames;
332
333private:
334 void OnOk( wxCommandEvent &event );
335 void OnCancel( wxCommandEvent &event );
336 void OnMixerPanelHelp( wxCommandEvent &event );
337 void OnSlider( wxCommandEvent &event );
338 void OnSize( wxSizeEvent &event );
339
340private:
341 DECLARE_EVENT_TABLE()
342};
343
346
350AUDACITY_DLL_API void ShowExportErrorDialog(wxString ErrorCode,
353 bool allowReporting = true);
354
355AUDACITY_DLL_API
357
358#endif
AUDACITY_DLL_API void ShowExportErrorDialog(wxString ErrorCode, TranslatableString message=AudacityExportMessageStr(), const TranslatableString &caption=AudacityExportCaptionStr(), bool allowReporting=true)
Definition: Export.cpp:1503
AUDACITY_DLL_API TranslatableString AudacityExportCaptionStr()
Definition: Export.cpp:1486
AUDACITY_DLL_API void ShowDiskFullExportErrorDialog(const wxFileNameWrapper &fileName)
Definition: Export.cpp:1516
std::vector< std::shared_ptr< const WaveTrack > > WaveTrackConstArray
Definition: Export.h:39
AUDACITY_DLL_API TranslatableString AudacityExportMessageStr()
Definition: Export.cpp:1490
std::vector< std::unique_ptr< ExportPlugin > > ExportPluginArray
Definition: Export.h:161
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API, AUDACITY_FILE_SUFFIX_EVENT, wxCommandEvent)
int format
Definition: ExportPCM.cpp:53
wxString FileExtension
File extension, not including any leading dot.
Definition: Identifier.h:224
static const auto title
sampleFormat
The ordering of these values with operator < agrees with the order of increasing bit width.
Definition: SampleFormat.h:30
#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:90
Dialog for advanced mixing.
Definition: Export.h:316
std::unique_ptr< MixerSpec > mMixerSpec
Definition: Export.h:330
void OnOk(wxCommandEvent &event)
Definition: Export.cpp:1470
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:1358
void OnCancel(wxCommandEvent &event)
Definition: Export.cpp:1475
void OnSize(wxSizeEvent &event)
Definition: Export.cpp:1451
MixerSpec * GetMixerSpec()
Definition: Export.h:326
virtual ~ExportMixerDialog()
Definition: Export.cpp:1447
wxStaticText * mChannelsText
Definition: Export.h:329
void OnMixerPanelHelp(wxCommandEvent &event)
Definition: Export.cpp:1480
wxArrayString mTrackNames
Definition: Export.h:331
void OnSlider(wxCommandEvent &event)
Definition: Export.cpp:1458
Panel that displays mixing for advanced mixing option.
Definition: Export.h:282
wxRect mEnvRect
Definition: Export.h:295
ExportMixerPanel(wxWindow *parent, wxWindowID id, MixerSpec *mixerSpec, wxArrayString trackNames, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Definition: Export.cpp:1113
void OnMouseEvent(wxMouseEvent &event)
Definition: Export.cpp:1284
int mChannelHeight
Definition: Export.h:303
void SetFont(wxMemoryDC &memDC, const wxString &text, int width, int height)
Definition: Export.cpp:1135
std::unique_ptr< wxBitmap > mBitmap
Definition: Export.h:294
int mSelectedTrack
Definition: Export.h:301
bool IsOnLine(wxPoint p, wxPoint la, wxPoint lb)
Definition: Export.cpp:1279
int mSelectedChannel
Definition: Export.h:301
void OnPaint(wxPaintEvent &event)
Definition: Export.cpp:1156
int mTrackHeight
Definition: Export.h:303
double Distance(wxPoint &a, wxPoint &b)
Definition: Export.cpp:1273
ArrayOf< wxRect > mChannelRects
Definition: Export.h:299
ArrayOf< wxRect > mTrackRects
Definition: Export.h:300
MixerSpec * mMixerSpec
Definition: Export.h:298
virtual ~ExportMixerPanel()
Definition: Export.cpp:1130
wxArrayString mTrackNames
Definition: Export.h:302
virtual ProgressResult Export(AudacityProject *project, std::unique_ptr< BasicUI::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:109
std::vector< FormatInfo > mFormatInfos
Definition: Export.h:158
FileDialogWrapper * mDialog
Definition: Export.h:251
wxFileName mActualName
Definition: Export.h:259
std::function< std::unique_ptr< ExportPlugin >() > ExportPluginFactory
Definition: Export.h:177
int mFormat
Definition: Export.h:264
void SetDefaultFormat(const FileExtension &Format)
Definition: Export.h:197
unsigned mChannels
Definition: Export.h:270
wxSimplebook * mBook
Definition: Export.h:273
bool mSelectedOnly
Definition: Export.h:271
double mT0
Definition: Export.h:261
FileExtension mFormatName
Definition: Export.h:250
unsigned mNumRight
Definition: Export.h:268
unsigned mNumLeft
Definition: Export.h:267
double mT1
Definition: Export.h:262
int mNumSelected
Definition: Export.h:266
std::unique_ptr< MixerSpec > mMixerSpec
Definition: Export.h:254
int mSubFormat
Definition: Export.h:265
wxFileName mFilename
Definition: Export.h:258
ExportPluginArray mPlugins
Definition: Export.h:256
int mFilterIndex
Definition: Export.h:263
AudacityProject * mProject
Definition: Export.h:253
unsigned mNumMono
Definition: Export.h:269
TranslatableString mFileDialogTitle
Definition: Export.h:252
std::vector< FileType > FileTypes
Definition: FileNames.h:75
Abstract base class used in importing a file.
FileExtensions mExtensions
Definition: Export.h:61
TranslatableString mDescription
Definition: Export.h:59
FileNames::FileTypes mMask
Definition: Export.h:62
bool mCanMetaData
Definition: Export.h:64
wxString mFormat
Definition: Export.h:58
~FormatInfo()
Definition: Export.h:56
FormatInfo()
Definition: Export.h:51
unsigned mMaxChannels
Definition: Export.h:63
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:32
ProgressDialog Class.
Generates classes whose instances register items at construction.
Definition: Registry.h:245
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:625
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:1339
Holds a msgid for the translation catalog; may also bind format arguments.
A Track that contains audio waveform data.
Definition: WaveTrack.h:51
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
ProgressResult
Definition: BasicUI.h:147
Definition: Menus.h:35
UndoState::Extensions GetExtensions(AudacityProject &project)
Definition: UndoManager.cpp:49
static RegisteredToolbarFactory factory
Exporter::ExportPluginFactory mFactory
Definition: Export.h:236