1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
|
/**********************************************************************
Audacity: A Digital Audio Editor
Export.h
Dominic Mazzoni
**********************************************************************/
#ifndef __AUDACITY_EXPORT__
#define __AUDACITY_EXPORT__
#include <functional>
#include <vector>
#include <wx/filename.h> // member variable
#include "Identifier.h"
#include "SampleFormat.h"
#include "../widgets/wxPanelWrapper.h" // to inherit
#include "FileNames.h" // for FileTypes
#include "Registry.h"
class wxArrayString;
class FileDialogWrapper;
class wxFileCtrlEvent;
class wxMemoryDC;
class wxSimplebook;
class wxStaticText;
class AudacityProject;
class WaveTrack;
class Tags;
class TrackList;
namespace MixerOptions{ class Downmix; }
using MixerSpec = MixerOptions::Downmix;
class ProgressDialog;
class ShuttleGui;
class Mixer;
using WaveTrackConstArray = std::vector < std::shared_ptr < const WaveTrack > >;
namespace BasicUI{ enum class ProgressResult : unsigned; }
class wxFileNameWrapper;
namespace BasicUI
{
class ProgressDialog;
}
class AUDACITY_DLL_API FormatInfo
{
public:
FormatInfo() {}
FormatInfo( const FormatInfo & ) = default;
FormatInfo &operator = ( const FormatInfo & ) = default;
//FormatInfo( FormatInfo && ) = default;
//FormatInfo &operator = ( FormatInfo && ) = default;
~FormatInfo() {}
wxString mFormat;
TranslatableString mDescription;
// wxString mExtension;
FileExtensions mExtensions;
FileNames::FileTypes mMask;
unsigned mMaxChannels;
bool mCanMetaData;
};
//----------------------------------------------------------------------------
// ExportPlugin
//----------------------------------------------------------------------------
class AUDACITY_DLL_API ExportPlugin /* not final */
{
public:
using ProgressResult = BasicUI::ProgressResult;
ExportPlugin();
virtual ~ExportPlugin();
int AddFormat();
void SetFormat(const wxString & format, int index);
void SetDescription(const TranslatableString & description, int index);
void AddExtension(const FileExtension &extension, int index);
void SetExtensions(FileExtensions extensions, int index);
void SetMask(FileNames::FileTypes mask, int index);
void SetMaxChannels(unsigned maxchannels, unsigned index);
void SetCanMetaData(bool canmetadata, int index);
virtual int GetFormatCount();
virtual wxString GetFormat(int index);
TranslatableString GetDescription(int index);
/** @brief Return the (first) file name extension for the sub-format.
* @param index The sub-format for which the extension is wanted */
virtual FileExtension GetExtension(int index = 0);
/** @brief Return all the file name extensions used for the sub-format.
* @param index the sub-format for which the extension is required */
virtual FileExtensions GetExtensions(int index = 0);
FileNames::FileTypes GetMask(int index);
virtual unsigned GetMaxChannels(int index);
virtual bool GetCanMetaData(int index);
virtual bool IsExtension(const FileExtension & ext, int index);
virtual bool DisplayOptions(wxWindow *parent, int format = 0);
virtual void OptionsCreate(ShuttleGui &S, int format) = 0;
virtual bool CheckFileName(wxFileName &filename, int format = 0);
/** @brief Exporter plug-ins may override this to specify the number
* of channels in exported file. -1 for unspecified */
virtual int SetNumExportChannels() { return -1; }
/** \brief called to export audio into a file.
*
* @param pDialog To be initialized with pointer to a NEW ProgressDialog if
* it was null, otherwise gives an existing dialog to be reused
* (working around a problem in wxWidgets for Mac; see bug 1600)
* @param selectedOnly Set to true if all tracks should be mixed, to false
* if only the selected tracks should be mixed and exported.
* @param metadata A Tags object that will over-ride the one in *project and
* be used to tag the file that is exported.
* @param subformat Control which of the multiple formats this exporter is
* capable of exporting should be used. Used where a single export plug-in
* handles a number of related formats, but they have separate
* entries in the Format drop-down list box. For example, the options to
* export to "Other PCM", "AIFF 16 Bit" and "WAV 16 Bit" are all the same
* libsndfile export plug-in, but with subformat set to 0, 1, and 2
* respectively.
* @return ProgressResult::Failed or ProgressResult::Cancelled if export
* fails to complete for any reason, in which case this function is
* responsible for alerting the user. Otherwise ProgressResult::Success or
* ProgressResult::Stopped
*/
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;
protected:
std::unique_ptr<Mixer> CreateMixer(const TrackList &tracks,
bool selectionOnly,
double startTime, double stopTime,
unsigned numOutChannels, size_t outBufferSize, bool outInterleaved,
double outRate, sampleFormat outFormat,
MixerSpec *mixerSpec);
// Create or recycle a dialog.
static void InitProgress(std::unique_ptr<BasicUI::ProgressDialog> &pDialog,
const TranslatableString &title, const TranslatableString &message);
static void InitProgress(std::unique_ptr<BasicUI::ProgressDialog> &pDialog,
const wxFileNameWrapper &title, const TranslatableString &message);
private:
std::vector<FormatInfo> mFormatInfos;
};
using ExportPluginArray = std::vector < std::unique_ptr< ExportPlugin > > ;
//----------------------------------------------------------------------------
// Exporter
//----------------------------------------------------------------------------
// For a file suffix change from the options.
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API,
AUDACITY_FILE_SUFFIX_EVENT, wxCommandEvent);
class AUDACITY_DLL_API Exporter final : public wxEvtHandler
{
public:
using ExportPluginFactory =
std::function< std::unique_ptr< ExportPlugin >() >;
// Objects of this type are statically constructed in files implementing
// subclasses of ExportPlugin
// Register factories, not plugin objects themselves, which allows them
// to have some fresh state variables each time export begins again
// and to compute translated strings for the current locale
struct AUDACITY_DLL_API RegisteredExportPlugin{
RegisteredExportPlugin(
const Identifier &id, // an internal string naming the plug-in
const ExportPluginFactory&,
const Registry::Placement &placement = { wxEmptyString, {} } );
};
static bool DoEditMetadata(AudacityProject &project,
const TranslatableString &title,
const TranslatableString &shortUndoDescription, bool force);
Exporter( AudacityProject &project );
virtual ~Exporter();
void SetFileDialogTitle( const TranslatableString & DialogTitle );
void SetDefaultFormat( const FileExtension & Format ){ mFormatName = Format;};
bool Process(bool selectedOnly,
double t0, double t1);
bool Process(unsigned numChannels,
const FileExtension &type, const wxString & filename,
bool selectedOnly, double t0, double t1);
bool Process(
unsigned numChannels, const FileExtension& type, const wxString& filename,
bool selectedOnly, double t0, double t1,
std::unique_ptr<BasicUI::ProgressDialog>& progressDialog);
void DisplayOptions(int index);
int FindFormatIndex(int exportindex);
const ExportPluginArray &GetPlugins();
// Auto Export from Timer Recording
bool ProcessFromTimerRecording(bool selectedOnly,
double t0,
double t1,
wxFileName fnFile,
int iFormat,
int iSubFormat,
int iFilterIndex);
bool SetAutoExportOptions();
int GetAutoExportFormat();
int GetAutoExportSubFormat();
int GetAutoExportFilterIndex();
wxFileName GetAutoExportFileName();
void OnExtensionChanged(wxCommandEvent &evt);
void OnHelp(wxCommandEvent &evt);
private:
bool ExamineTracks();
bool GetFilename();
bool CheckFilename();
bool CheckMix(bool prompt = true);
bool ExportTracks(std::unique_ptr<BasicUI::ProgressDialog>& progressDialog);
static void CreateUserPaneCallback(wxWindow *parent, wxUIntPtr userdata);
void CreateUserPane(wxWindow *parent);
void OnFilterChanged(wxFileCtrlEvent & evt);
private:
FileExtension mFormatName;
FileDialogWrapper *mDialog;
TranslatableString mFileDialogTitle;
AudacityProject *mProject;
std::unique_ptr<MixerSpec> mMixerSpec;
ExportPluginArray mPlugins;
wxFileName mFilename;
wxFileName mActualName;
double mT0;
double mT1;
int mFilterIndex;
int mFormat;
int mSubFormat;
int mNumSelected;
unsigned mNumLeft;
unsigned mNumRight;
unsigned mNumMono;
unsigned mChannels;
bool mSelectedOnly;
wxSimplebook *mBook;
DECLARE_EVENT_TABLE()
};
//----------------------------------------------------------------------------
// ExportMixerPanel
//----------------------------------------------------------------------------
class ExportMixerPanel final : public wxPanelWrapper
{
public:
ExportMixerPanel( wxWindow *parent, wxWindowID id,
MixerSpec *mixerSpec, wxArrayString trackNames,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize);
virtual ~ExportMixerPanel();
void OnMouseEvent(wxMouseEvent & event);
void OnPaint(wxPaintEvent & event);
private:
std::unique_ptr<wxBitmap> mBitmap;
wxRect mEnvRect;
int mWidth;
int mHeight;
MixerSpec *mMixerSpec;
ArrayOf<wxRect> mChannelRects;
ArrayOf<wxRect> mTrackRects;
int mSelectedTrack, mSelectedChannel;
wxArrayString mTrackNames;
int mBoxWidth, mChannelHeight, mTrackHeight;
void SetFont( wxMemoryDC &memDC, const wxString &text, int width, int height );
double Distance( wxPoint &a, wxPoint &b );
bool IsOnLine( wxPoint p, wxPoint la, wxPoint lb );
DECLARE_EVENT_TABLE()
};
//----------------------------------------------------------------------------
// ExportMixerDialog
//----------------------------------------------------------------------------
class ExportMixerDialog final : public wxDialogWrapper
{
public:
// constructors and destructors
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 );
virtual ~ExportMixerDialog();
MixerSpec* GetMixerSpec() { return mMixerSpec.get(); }
private:
wxStaticText *mChannelsText;
std::unique_ptr<MixerSpec> mMixerSpec;
wxArrayString mTrackNames;
private:
void OnOk( wxCommandEvent &event );
void OnCancel( wxCommandEvent &event );
void OnMixerPanelHelp( wxCommandEvent &event );
void OnSlider( wxCommandEvent &event );
void OnSize( wxSizeEvent &event );
private:
DECLARE_EVENT_TABLE()
};
AUDACITY_DLL_API TranslatableString AudacityExportCaptionStr();
AUDACITY_DLL_API TranslatableString AudacityExportMessageStr();
/// We have many Export errors that are essentially anonymous
/// and are distinguished only by an error code number.
/// Rather than repeat the code, we have it just once.
AUDACITY_DLL_API void ShowExportErrorDialog(wxString ErrorCode,
TranslatableString message = AudacityExportMessageStr(),
const TranslatableString& caption = AudacityExportCaptionStr(),
bool allowReporting = true);
AUDACITY_DLL_API
void ShowDiskFullExportErrorDialog(const wxFileNameWrapper &fileName);
#endif
|