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
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{
173public:
174
176 std::function< std::unique_ptr< ExportPlugin >() >;
177
178 // Objects of this type are statically constructed in files implementing
179 // subclasses of ExportPlugin
180 // Register factories, not plugin objects themselves, which allows them
181 // to have some fresh state variables each time export begins again
182 // and to compute translated strings for the current locale
183 struct AUDACITY_DLL_API RegisteredExportPlugin{
185 const Identifier &id, // an internal string naming the plug-in
186 const ExportPluginFactory&,
187 const Registry::Placement &placement = { wxEmptyString, {} } );
188 };
189
190 static bool DoEditMetadata(AudacityProject &project,
192 const TranslatableString &shortUndoDescription, bool force);
193
194 Exporter( AudacityProject &project );
195 virtual ~Exporter();
196
197 void SetFileDialogTitle( const TranslatableString & DialogTitle );
198 void SetDefaultFormat( const FileExtension & Format ){ mFormatName = Format;};
199
200 bool Process(bool selectedOnly,
201 double t0, double t1);
202 bool Process(unsigned numChannels,
203 const FileExtension &type, const wxString & filename,
204 bool selectedOnly, double t0, double t1);
205
206 bool Process(
207 unsigned numChannels, const FileExtension& type, const wxString& filename,
208 bool selectedOnly, double t0, double t1,
209 std::unique_ptr<BasicUI::ProgressDialog>& progressDialog);
210
211 void DisplayOptions(int index);
212 int FindFormatIndex(int exportindex);
213
214 const ExportPluginArray &GetPlugins();
215
216 // Auto Export from Timer Recording
217 bool ProcessFromTimerRecording(bool selectedOnly,
218 double t0,
219 double t1,
220 wxFileName fnFile,
221 int iFormat,
222 int iSubFormat,
223 int iFilterIndex);
224 bool SetAutoExportOptions();
225 int GetAutoExportFormat();
226 int GetAutoExportSubFormat();
227 int GetAutoExportFilterIndex();
228 wxFileName GetAutoExportFileName();
229 void OnExtensionChanged(wxCommandEvent &evt);
230 void OnHelp(wxCommandEvent &evt);
231
232private:
233 bool ExamineTracks();
234 bool GetFilename();
235 bool CheckFilename();
236 bool CheckMix(bool prompt = true);
237 bool ExportTracks(std::unique_ptr<BasicUI::ProgressDialog>& progressDialog);
238
239 static void CreateUserPaneCallback(wxWindow *parent, wxUIntPtr userdata);
240 void CreateUserPane(wxWindow *parent);
241 void OnFilterChanged(wxFileCtrlEvent & evt);
242
243private:
248 std::unique_ptr<MixerSpec> mMixerSpec;
249
251
252 wxFileName mFilename;
253 wxFileName mActualName;
254
255 double mT0;
256 double mT1;
261 unsigned mNumLeft;
262 unsigned mNumRight;
263 unsigned mNumMono;
264 unsigned mChannels;
266
267 wxSimplebook *mBook;
268
269 DECLARE_EVENT_TABLE()
270};
271
272//----------------------------------------------------------------------------
273// ExportMixerPanel
274//----------------------------------------------------------------------------
276{
277public:
278 ExportMixerPanel( wxWindow *parent, wxWindowID id,
279 MixerSpec *mixerSpec, wxArrayString trackNames,
280 const wxPoint& pos = wxDefaultPosition,
281 const wxSize& size = wxDefaultSize);
282 virtual ~ExportMixerPanel();
283
284 void OnMouseEvent(wxMouseEvent & event);
285 void OnPaint(wxPaintEvent & event);
286
287private:
288 std::unique_ptr<wxBitmap> mBitmap;
289 wxRect mEnvRect;
296 wxArrayString mTrackNames;
298
299 void SetFont( wxMemoryDC &memDC, const wxString &text, int width, int height );
300 double Distance( wxPoint &a, wxPoint &b );
301 bool IsOnLine( wxPoint p, wxPoint la, wxPoint lb );
302
303 DECLARE_EVENT_TABLE()
304};
305
306//----------------------------------------------------------------------------
307// ExportMixerDialog
308//----------------------------------------------------------------------------
310{
311public:
312 // constructors and destructors
313 ExportMixerDialog( const TrackList * tracks, bool selectedOnly, unsigned maxNumChannels,
314 wxWindow *parent, wxWindowID id, const TranslatableString &title,
315 const wxPoint& pos = wxDefaultPosition,
316 const wxSize& size = wxDefaultSize,
317 long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );
318 virtual ~ExportMixerDialog();
319
320 MixerSpec* GetMixerSpec() { return mMixerSpec.get(); }
321
322private:
323 wxStaticText *mChannelsText;
324 std::unique_ptr<MixerSpec> mMixerSpec;
325 wxArrayString mTrackNames;
326
327private:
328 void OnOk( wxCommandEvent &event );
329 void OnCancel( wxCommandEvent &event );
330 void OnMixerPanelHelp( wxCommandEvent &event );
331 void OnSlider( wxCommandEvent &event );
332 void OnSize( wxSizeEvent &event );
333
334private:
335 DECLARE_EVENT_TABLE()
336};
337
340
344AUDACITY_DLL_API void ShowExportErrorDialog(wxString ErrorCode,
347 bool allowReporting = true);
348
349AUDACITY_DLL_API
351
352#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:1538
AUDACITY_DLL_API TranslatableString AudacityExportCaptionStr()
Definition: Export.cpp:1521
AUDACITY_DLL_API void ShowDiskFullExportErrorDialog(const wxFileNameWrapper &fileName)
Definition: Export.cpp:1551
AUDACITY_DLL_API TranslatableString AudacityExportMessageStr()
Definition: Export.cpp:1525
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: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:310
std::unique_ptr< MixerSpec > mMixerSpec
Definition: Export.h:324
void OnOk(wxCommandEvent &event)
Definition: Export.cpp:1505
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:1393
void OnCancel(wxCommandEvent &event)
Definition: Export.cpp:1510
void OnSize(wxSizeEvent &event)
Definition: Export.cpp:1486
MixerSpec * GetMixerSpec()
Definition: Export.h:320
virtual ~ExportMixerDialog()
Definition: Export.cpp:1482
wxStaticText * mChannelsText
Definition: Export.h:323
void OnMixerPanelHelp(wxCommandEvent &event)
Definition: Export.cpp:1515
wxArrayString mTrackNames
Definition: Export.h:325
void OnSlider(wxCommandEvent &event)
Definition: Export.cpp:1493
Panel that displays mixing for advanced mixing option.
Definition: Export.h:276
wxRect mEnvRect
Definition: Export.h:289
ExportMixerPanel(wxWindow *parent, wxWindowID id, MixerSpec *mixerSpec, wxArrayString trackNames, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Definition: Export.cpp:1148
void OnMouseEvent(wxMouseEvent &event)
Definition: Export.cpp:1319
int mChannelHeight
Definition: Export.h:297
void SetFont(wxMemoryDC &memDC, const wxString &text, int width, int height)
Definition: Export.cpp:1170
std::unique_ptr< wxBitmap > mBitmap
Definition: Export.h:288
int mSelectedTrack
Definition: Export.h:295
bool IsOnLine(wxPoint p, wxPoint la, wxPoint lb)
Definition: Export.cpp:1314
int mSelectedChannel
Definition: Export.h:295
void OnPaint(wxPaintEvent &event)
Definition: Export.cpp:1191
int mTrackHeight
Definition: Export.h:297
double Distance(wxPoint &a, wxPoint &b)
Definition: Export.cpp:1308
ArrayOf< wxRect > mChannelRects
Definition: Export.h:293
ArrayOf< wxRect > mTrackRects
Definition: Export.h:294
MixerSpec * mMixerSpec
Definition: Export.h:292
virtual ~ExportMixerPanel()
Definition: Export.cpp:1165
wxArrayString mTrackNames
Definition: Export.h:296
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:245
wxFileName mActualName
Definition: Export.h:253
std::function< std::unique_ptr< ExportPlugin >() > ExportPluginFactory
Definition: Export.h:176
int mFormat
Definition: Export.h:258
void SetDefaultFormat(const FileExtension &Format)
Definition: Export.h:198
unsigned mChannels
Definition: Export.h:264
wxSimplebook * mBook
Definition: Export.h:267
bool mSelectedOnly
Definition: Export.h:265
double mT0
Definition: Export.h:255
FileExtension mFormatName
Definition: Export.h:244
unsigned mNumRight
Definition: Export.h:262
unsigned mNumLeft
Definition: Export.h:261
double mT1
Definition: Export.h:256
int mNumSelected
Definition: Export.h:260
std::unique_ptr< MixerSpec > mMixerSpec
Definition: Export.h:248
int mSubFormat
Definition: Export.h:259
wxFileName mFilename
Definition: Export.h:252
ExportPluginArray mPlugins
Definition: Export.h:250
int mFilterIndex
Definition: Export.h:257
AudacityProject * mProject
Definition: Export.h:247
unsigned mNumMono
Definition: Export.h:263
TranslatableString mFileDialogTitle
Definition: Export.h:246
std::vector< FileType > FileTypes
Definition: FileNames.h:76
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.
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:1338
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