Audacity  2.2.2
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
Exporter Class Referencefinal

#include <Export.h>

Inheritance diagram for Exporter:

Public Member Functions

 Exporter ()
 
virtual ~Exporter ()
 
void SetFileDialogTitle (const wxString &DialogTitle)
 
void SetDefaultFormat (const wxString &Format)
 
void RegisterPlugin (movable_ptr< ExportPlugin > &&plugin)
 
bool Process (AudacityProject *project, bool selectedOnly, double t0, double t1)
 
bool Process (AudacityProject *project, unsigned numChannels, const wxChar *type, const wxString &filename, bool selectedOnly, double t0, double t1)
 
void DisplayOptions (int index)
 
int FindFormatIndex (int exportindex)
 
const ExportPluginArrayGetPlugins ()
 
bool ProcessFromTimerRecording (AudacityProject *project, bool selectedOnly, double t0, double t1, wxFileName fnFile, int iFormat, int iSubFormat, int iFilterIndex)
 
bool SetAutoExportOptions (AudacityProject *project)
 
int GetAutoExportFormat ()
 
int GetAutoExportSubFormat ()
 
int GetAutoExportFilterIndex ()
 
wxFileName GetAutoExportFileName ()
 

Private Member Functions

bool ExamineTracks ()
 
bool GetFilename ()
 
bool CheckFilename ()
 
bool CheckMix ()
 
bool ExportTracks ()
 
void CreateUserPane (wxWindow *parent)
 
void OnFilterChanged (wxFileCtrlEvent &evt)
 

Static Private Member Functions

static void CreateUserPaneCallback (wxWindow *parent, wxUIntPtr userdata)
 

Private Attributes

wxString mFormatName
 
FileDialogWrappermDialog
 
wxString mFileDialogTitle
 
AudacityProjectmProject
 
std::unique_ptr< MixerSpecmMixerSpec
 
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
 

Detailed Description

Definition at line 155 of file Export.h.

Constructor & Destructor Documentation

Exporter::Exporter ( )

Definition at line 273 of file Export.cpp.

References _(), New_ExportCL(), New_ExportFFmpeg(), New_ExportFLAC(), New_ExportMP2(), New_ExportMP3(), New_ExportOGG(), and New_ExportPCM().

274 {
275  mMixerSpec = NULL;
276  mBook = NULL;
277  mFormatName = "";
278 
279  SetFileDialogTitle( _("Export Audio") );
280 
283 
284 #ifdef USE_LIBVORBIS
286 #endif
287 
288 #ifdef USE_LIBFLAC
290 #endif
291 
292 #if USE_LIBTWOLAME
294 #endif
295 
296  // Command line export not available on Windows and Mac platforms
298 
299 #if defined(USE_FFMPEG)
301 #endif
302 }
void RegisterPlugin(movable_ptr< ExportPlugin > &&plugin)
Definition: Export.cpp:328
movable_ptr< ExportPlugin > New_ExportMP3()
Definition: ExportMP3.cpp:2161
movable_ptr< ExportPlugin > New_ExportPCM()
Definition: ExportPCM.cpp:912
void SetFileDialogTitle(const wxString &DialogTitle)
Definition: Export.cpp:308
movable_ptr< ExportPlugin > New_ExportMP2()
movable_ptr< ExportPlugin > New_ExportOGG()
movable_ptr< ExportPlugin > New_ExportFFmpeg()
wxString mFormatName
Definition: Export.h:204
std::unique_ptr< MixerSpec > mMixerSpec
Definition: Export.h:208
movable_ptr< ExportPlugin > New_ExportCL()
Definition: ExportCL.cpp:548
wxSimplebook * mBook
Definition: Export.h:227
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
movable_ptr< ExportPlugin > New_ExportFLAC()
Exporter::~Exporter ( )
virtual

Definition at line 304 of file Export.cpp.

305 {
306 }

Member Function Documentation

bool Exporter::CheckFilename ( )
private

Definition at line 692 of file Export.cpp.

References AudacityProject::GetDirManager(), gPrefs, mActualName, mFilename, mFormat, mFormatName, mPlugins, mProject, and mSubFormat.

Referenced by Process(), and ProcessFromTimerRecording().

693 {
694  //
695  // Ensure that exporting a file by this name doesn't overwrite
696  // one of the existing files in the project. (If it would
697  // overwrite an existing file, DirManager tries to rename the
698  // existing file.)
699  //
700 
701  if (!mProject->GetDirManager()->EnsureSafeFilename(mFilename))
702  return false;
703 
704  if( mFormatName.IsEmpty() )
705  gPrefs->Write(wxT("/Export/Format"), mPlugins[mFormat]->GetFormat(mSubFormat));
706  gPrefs->Write(wxT("/Export/Path"), mFilename.GetPath());
707  gPrefs->Flush();
708 
709  //
710  // To be even safer, return a temporary file name based
711  // on this one...
712  //
713 
715 
716  int suffix = 0;
717  while (mFilename.FileExists()) {
718  mFilename.SetName(mActualName.GetName() +
719  wxString::Format(wxT("%d"), suffix));
720  suffix++;
721  }
722 
723  return true;
724 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
wxFileName mFilename
Definition: Export.h:212
wxString mFormatName
Definition: Export.h:204
AudacityProject * mProject
Definition: Export.h:207
const std::shared_ptr< DirManager > & GetDirManager()
Definition: Project.cpp:1422
int mSubFormat
Definition: Export.h:219
ExportPluginArray mPlugins
Definition: Export.h:210
wxFileName mActualName
Definition: Export.h:213
int mFormat
Definition: Export.h:218
bool Exporter::CheckMix ( )
private

Definition at line 756 of file Export.cpp.

References _(), AudacityProject::GetTracks(), gPrefs, mChannels, mFormat, min(), mMixerSpec, mNumLeft, mNumMono, mNumRight, mPlugins, mProject, mSelectedOnly, mSubFormat, and ShowWarningDialog().

Referenced by Process(), and ProcessFromTimerRecording().

757 {
758  // Clean up ... should never happen
759  mMixerSpec.reset();
760 
761  // Detemine if exported file will be stereo or mono or multichannel,
762  // and if mixing will occur.
763 
764  int downMix = gPrefs->Read(wxT("/FileFormats/ExportDownMix"), true);
765  int exportedChannels = mPlugins[mFormat]->SetNumExportChannels();
766 
767  if (downMix) {
768  if (mNumRight > 0 || mNumLeft > 0) {
769  mChannels = 2;
770  }
771  else {
772  mChannels = 1;
773  }
775  mPlugins[mFormat]->GetMaxChannels(mSubFormat));
776 
777  auto numLeft = mNumLeft + mNumMono;
778  auto numRight = mNumRight + mNumMono;
779 
780  if (numLeft > 1 || numRight > 1 || mNumLeft + mNumRight + mNumMono > mChannels) {
781  wxString exportFormat = mPlugins[mFormat]->GetFormat(mSubFormat);
782  if (exportFormat != wxT("CL") && exportFormat != wxT("FFMPEG") && exportedChannels == -1)
783  exportedChannels = mChannels;
784 
785  if (exportedChannels == 1) {
787  wxT("MixMono"),
788  _("Your tracks will be mixed down to a single mono channel in the exported file."),
789  true) == wxID_CANCEL)
790  return false;
791  }
792  else if (exportedChannels == 2) {
794  wxT("MixStereo"),
795  _("Your tracks will be mixed down to two stereo channels in the exported file."),
796  true) == wxID_CANCEL)
797  return false;
798  }
799  else {
801  wxT("MixUnknownChannels"),
802  _("Your tracks will be mixed down to one exported file according to the encoder settings."),
803  true) == wxID_CANCEL)
804  return false;
805  }
806  }
807  }
808  else
809  {
810  if (exportedChannels < 0)
811  exportedChannels = mPlugins[mFormat]->GetMaxChannels(mSubFormat);
812 
815  exportedChannels,
816  NULL,
817  1,
818  _("Advanced Mixing Options"));
819 
820  if (md.ShowModal() != wxID_OK) {
821  return false;
822  }
823 
824  mMixerSpec = std::make_unique<MixerSpec>(*(md.GetMixerSpec()));
825  mChannels = mMixerSpec->GetNumChannels();
826  }
827 
828  return true;
829 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
bool mSelectedOnly
Definition: Export.h:225
std::unique_ptr< MixerSpec > mMixerSpec
Definition: Export.h:208
unsigned mChannels
Definition: Export.h:224
unsigned mNumRight
Definition: Export.h:222
AudacityProject * mProject
Definition: Export.h:207
int ShowWarningDialog(wxWindow *parent, const wxString &internalDialogName, const wxString &message, bool showCancelButton, const wxString &footer)
Definition: Warning.cpp:93
unsigned mNumLeft
Definition: Export.h:221
int mSubFormat
Definition: Export.h:219
ExportPluginArray mPlugins
Definition: Export.h:210
int min(int a, int b)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
unsigned mNumMono
Definition: Export.h:223
int mFormat
Definition: Export.h:218
Dialog for advanced mixing.
Definition: Export.h:269
TrackList * GetTracks()
Definition: Project.h:192
void Exporter::CreateUserPane ( wxWindow *  parent)
private

Definition at line 885 of file Export.cpp.

References _(), ShuttleGuiBase::AddWindow(), eIsCreating, ShuttleGuiBase::EndHorizontalLay(), ShuttleGuiBase::EndStatic(), ShuttleGuiBase::EndVerticalLay(), ShuttleGuiBase::GetParent(), mBook, mPlugins, safenew, ShuttleGuiBase::StartHorizontalLay(), ShuttleGuiBase::StartStatic(), and ShuttleGuiBase::StartVerticalLay().

Referenced by CreateUserPaneCallback().

886 {
887  ShuttleGui S(parent, eIsCreating);
888 
889  S.StartVerticalLay();
890  {
891  S.StartHorizontalLay(wxEXPAND);
892  {
893  S.StartStatic(_("Format Options"), 1);
894  {
895  mBook = safenew wxSimplebook(S.GetParent());
896  S.AddWindow(mBook, wxEXPAND);
897 
898  for (const auto &pPlugin : mPlugins)
899  {
900  for (int j = 0; j < pPlugin->GetFormatCount(); j++)
901  {
902  mBook->AddPage(pPlugin->OptionsCreate(mBook, j), wxEmptyString);
903  }
904  }
905  }
906  S.EndStatic();
907  }
908  S.EndHorizontalLay();
909  }
910  S.EndVerticalLay();
911 
912  return;
913 }
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
#define safenew
Definition: Audacity.h:230
ExportPluginArray mPlugins
Definition: Export.h:210
wxSimplebook * mBook
Definition: Export.h:227
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void Exporter::CreateUserPaneCallback ( wxWindow *  parent,
wxUIntPtr  userdata 
)
staticprivate

Definition at line 876 of file Export.cpp.

References CreateUserPane().

Referenced by GetFilename().

877 {
878  Exporter *self = (Exporter *) userdata;
879  if (self)
880  {
881  self->CreateUserPane(parent);
882  }
883 }
void CreateUserPane(wxWindow *parent)
Definition: Export.cpp:885
void Exporter::DisplayOptions ( int  index)

Definition at line 726 of file Export.cpp.

References mDialog, mPlugins, and mProject.

727 {
728  int c = 0;
729  int mf = -1, msf = -1;
730  int i = -1;
731  for (const auto &pPlugin : mPlugins)
732  {
733  ++i;
734  for (int j = 0; j < pPlugin->GetFormatCount(); j++)
735  {
736  if (index == c)
737  {
738  mf = i;
739  msf = j;
740  }
741  c++;
742  }
743  }
744  // This shouldn't happen...
745  if (index >= c) {
746  return;
747  }
748 
749 #if defined(__WXMSW__)
750  mPlugins[mf]->DisplayOptions(mProject, msf);
751 #else
752  mPlugins[mf]->DisplayOptions(mDialog, msf);
753 #endif
754 }
AudacityProject * mProject
Definition: Export.h:207
ExportPluginArray mPlugins
Definition: Export.h:210
FileDialogWrapper * mDialog
Definition: Export.h:205
bool Exporter::ExamineTracks ( )
private

Definition at line 412 of file Export.cpp.

References _(), AudacityMessageBox(), TrackListConstIterator::First(), Track::GetChannel(), Track::GetEndTime(), Track::GetKind(), Track::GetOffset(), Track::GetSelected(), AudacityProject::GetTracks(), Track::LeftChannel, mNumLeft, mNumMono, mNumRight, mNumSelected, Track::MonoChannel, mProject, mSelectedOnly, mT0, mT1, TrackListConstIterator::Next(), Track::RightChannel, and Track::Wave.

Referenced by Process(), and ProcessFromTimerRecording().

413 {
414  // Init
415  mNumSelected = 0;
416  mNumLeft = 0;
417  mNumRight = 0;
418  mNumMono = 0;
419 
420  // First analyze the selected audio, perform sanity checks, and provide
421  // information as appropriate.
422 
423  // Tally how many are right, left, mono, and make sure at
424  // least one track is selected (if selectedOnly==true)
425 
426  double earliestBegin = mT1;
427  double latestEnd = mT0;
428 
429  const TrackList *tracks = mProject->GetTracks();
430  TrackListConstIterator iter1(tracks);
431  const Track *tr = iter1.First();
432 
433  while (tr) {
434  if (tr->GetKind() == Track::Wave) {
435  auto wt = static_cast<const WaveTrack *>(tr);
436  if ( (tr->GetSelected() || !mSelectedOnly) &&
437  !wt->GetMute() ) { // don't count muted tracks
438  mNumSelected++;
439 
440  if (tr->GetChannel() == Track::LeftChannel) {
441  mNumLeft++;
442  }
443  else if (tr->GetChannel() == Track::RightChannel) {
444  mNumRight++;
445  }
446  else if (tr->GetChannel() == Track::MonoChannel) {
447  // It's a mono channel, but it may be panned
448  float pan = ((WaveTrack*)tr)->GetPan();
449 
450  if (pan == -1.0)
451  mNumLeft++;
452  else if (pan == 1.0)
453  mNumRight++;
454  else if (pan == 0)
455  mNumMono++;
456  else {
457  // Panned partially off-center. Mix as stereo.
458  mNumLeft++;
459  mNumRight++;
460  }
461  }
462 
463  if (tr->GetOffset() < earliestBegin) {
464  earliestBegin = tr->GetOffset();
465  }
466 
467  if (tr->GetEndTime() > latestEnd) {
468  latestEnd = tr->GetEndTime();
469  }
470 
471  }
472  }
473 
474  tr = iter1.Next();
475  }
476 
477  if (mNumSelected == 0) {
478  wxString message;
479  if(mSelectedOnly)
480  message = _("All selected audio is muted.");
481  else
482  message = _("All audio is muted.");
483  AudacityMessageBox(message,
484  _("Unable to export"),
485  wxOK | wxICON_INFORMATION);
486  return false;
487  }
488 
489  if (mT0 < earliestBegin)
490  mT0 = earliestBegin;
491 
492  if (mT1 > latestEnd)
493  mT1 = latestEnd;
494 
495  return true;
496 }
A list of TrackListNode items.
Definition: Track.h:618
virtual double GetOffset() const =0
bool GetSelected() const
Definition: Track.h:275
double mT1
Definition: Export.h:216
virtual double GetEndTime() const =0
bool mSelectedOnly
Definition: Export.h:225
virtual int GetChannel() const
Definition: Track.h:285
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
unsigned mNumRight
Definition: Export.h:222
AudacityProject * mProject
Definition: Export.h:207
virtual int GetKind() const
Definition: Track.h:329
unsigned mNumLeft
Definition: Export.h:221
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:101
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
unsigned mNumMono
Definition: Export.h:223
double mT0
Definition: Export.h:215
TrackList * GetTracks()
Definition: Project.h:192
int mNumSelected
Definition: Export.h:220
bool Exporter::ExportTracks ( )
private

Definition at line 831 of file Export.cpp.

References mActualName, mChannels, mFilename, mFormat, mMixerSpec, mPlugins, mProject, mSelectedOnly, mSubFormat, mT0, mT1, Stopped, and Success.

Referenced by Process(), and ProcessFromTimerRecording().

832 {
833  // Keep original in case of failure
834  if (mActualName != mFilename) {
835  ::wxRenameFile(mActualName.GetFullPath(), mFilename.GetFullPath());
836  }
837 
838  bool success = false;
839 
840  auto cleanup = finally( [&] {
841  if (mActualName != mFilename) {
842  // Remove backup
843  if ( success )
844  ::wxRemoveFile(mFilename.GetFullPath());
845  else {
846  // Restore original, if needed
847  ::wxRemoveFile(mActualName.GetFullPath());
848  ::wxRenameFile(mFilename.GetFullPath(), mActualName.GetFullPath());
849  }
850  }
851  else {
852  if ( ! success )
853  // Remove any new, and only partially written, file.
854  ::wxRemoveFile(mFilename.GetFullPath());
855  }
856  } );
857 
858  std::unique_ptr<ProgressDialog> pDialog;
859  auto result = mPlugins[mFormat]->Export(mProject,
860  pDialog,
861  mChannels,
862  mActualName.GetFullPath(),
864  mT0,
865  mT1,
866  mMixerSpec.get(),
867  NULL,
868  mSubFormat);
869 
870  success =
871  result == ProgressResult::Success || result == ProgressResult::Stopped;
872 
873  return success;
874 }
wxFileName mFilename
Definition: Export.h:212
double mT1
Definition: Export.h:216
bool mSelectedOnly
Definition: Export.h:225
std::unique_ptr< MixerSpec > mMixerSpec
Definition: Export.h:208
unsigned mChannels
Definition: Export.h:224
AudacityProject * mProject
Definition: Export.h:207
int mSubFormat
Definition: Export.h:219
ExportPluginArray mPlugins
Definition: Export.h:210
wxFileName mActualName
Definition: Export.h:213
double mT0
Definition: Export.h:215
int mFormat
Definition: Export.h:218
int Exporter::FindFormatIndex ( int  exportindex)

Definition at line 314 of file Export.cpp.

References mPlugins.

315 {
316  int c = 0;
317  for (const auto &pPlugin : mPlugins)
318  {
319  for (int j = 0; j < pPlugin->GetFormatCount(); j++)
320  {
321  if (exportindex == c) return j;
322  c++;
323  }
324  }
325  return 0;
326 }
ExportPluginArray mPlugins
Definition: Export.h:210
wxFileName Exporter::GetAutoExportFileName ( )

Definition at line 985 of file Export.cpp.

References mFilename.

Referenced by TimerRecordDialog::OnAutoExportPathButton_Click().

985  {
986  return mFilename;
987 }
wxFileName mFilename
Definition: Export.h:212
int Exporter::GetAutoExportFilterIndex ( )

Definition at line 981 of file Export.cpp.

References mFormat.

Referenced by TimerRecordDialog::OnAutoExportPathButton_Click().

981  {
982  return mFormat;
983 }
int mFormat
Definition: Export.h:218
int Exporter::GetAutoExportFormat ( )

Definition at line 973 of file Export.cpp.

References mFormat.

Referenced by TimerRecordDialog::OnAutoExportPathButton_Click().

973  {
974  return mFormat;
975 }
int mFormat
Definition: Export.h:218
int Exporter::GetAutoExportSubFormat ( )

Definition at line 977 of file Export.cpp.

References mSubFormat.

Referenced by TimerRecordDialog::OnAutoExportPathButton_Click().

977  {
978  return mSubFormat;
979 }
int mSubFormat
Definition: Export.h:219
bool Exporter::GetFilename ( )
private

Definition at line 498 of file Export.cpp.

References _(), AudacityMessageBox(), CreateUserPaneCallback(), FileNames::DefaultToDocumentsFolder(), FindDependencies(), gAudacityProjects, AudacityProject::GetName(), gPrefs, mBook, mDialog, mFileDialogTitle, mFilename, mFilterIndex, mFormat, mFormatName, mPlugins, mProject, mSubFormat, and FileDialogBase::SetUserPaneCreator().

Referenced by Process(), and SetAutoExportOptions().

499 {
500  mFormat = -1;
501 
502  wxString maskString;
503  wxString defaultFormat = mFormatName;
504  if( defaultFormat.IsEmpty() )
505  defaultFormat = gPrefs->Read(wxT("/Export/Format"),
506  wxT("WAV"));
507 
508  mFilterIndex = 0;
509 
510  {
511  int i = -1;
512  for (const auto &pPlugin : mPlugins) {
513  ++i;
514  for (int j = 0; j < pPlugin->GetFormatCount(); j++)
515  {
516  maskString += pPlugin->GetMask(j) + wxT("|");
517  if (mPlugins[i]->GetFormat(j) == defaultFormat) {
518  mFormat = i;
519  mSubFormat = j;
520  }
521  if (mFormat == -1) mFilterIndex++;
522  }
523  }
524  }
525  if (mFormat == -1)
526  {
527  mFormat = 0;
528  mFilterIndex = 0;
529  }
530  maskString.RemoveLast();
531  wxString defext = mPlugins[mFormat]->GetExtension(mSubFormat).Lower();
532 
533 //Bug 1304: Set a default path if none was given. For Export.
534  mFilename = FileNames::DefaultToDocumentsFolder(wxT("/Export/Path"));
535  mFilename.SetName(mProject->GetName());
536  if (mFilename.GetName().empty())
537  mFilename.SetName(_("untitled"));
538  while (true) {
539  // Must reset each iteration
540  mBook = NULL;
541 
542  {
543  auto useFileName = mFilename;
544  if (!useFileName.HasExt())
545  useFileName.SetExt(defext);
548  mFilename.GetPath(),
549  useFileName.GetFullName(),
550  maskString,
551  wxFD_SAVE | wxRESIZE_BORDER);
552  mDialog = &fd;
553  mDialog->PushEventHandler(this);
554 
555  fd.SetUserPaneCreator(CreateUserPaneCallback, (wxUIntPtr) this);
556  fd.SetFilterIndex(mFilterIndex);
557 
558  int result = fd.ShowModal();
559 
560  mDialog->PopEventHandler();
561 
562  if (result == wxID_CANCEL) {
563  return false;
564  }
565 
566  mFilename = fd.GetPath();
567  if (mFilename == wxT("")) {
568  return false;
569  }
570 
571  mFormat = fd.GetFilterIndex();
572  mFilterIndex = fd.GetFilterIndex();
573  }
574 
575  int c = 0;
576  int i = -1;
577  for (const auto &pPlugin : mPlugins)
578  {
579  ++i;
580  for (int j = 0; j < pPlugin->GetFormatCount(); j++)
581  {
582  if (mFilterIndex == c)
583  {
584  mFormat = i;
585  mSubFormat = j;
586  }
587  c++;
588  }
589  }
590 
591  wxString ext = mFilename.GetExt();
592  defext = mPlugins[mFormat]->GetExtension(mSubFormat).Lower();
593 
594  //
595  // Check the extension - add the default if it's not there,
596  // and warn user if it's abnormal.
597  //
598  if (ext.IsEmpty()) {
599  //
600  // Make sure the user doesn't accidentally save the file
601  // as an extension with no name, like just plain ".wav".
602  //
603  if (mFilename.GetName().Left(1) == wxT(".")) {
604  wxString prompt = wxString::Format(
605  _("Are you sure you want to export the file as \"%s\"?\n"),
606  mFilename.GetFullName() );
607 
608  int action = AudacityMessageBox(prompt,
609  _("Warning"),
610  wxYES_NO | wxICON_EXCLAMATION);
611  if (action != wxYES) {
612  continue;
613  }
614  }
615 
616  mFilename.SetExt(defext);
617  }
618  else if (!mPlugins[mFormat]->CheckFileName(mFilename, mSubFormat))
619  {
620  continue;
621  }
622  else if (!ext.IsEmpty() && !mPlugins[mFormat]->IsExtension(ext,mSubFormat) && ext.CmpNoCase(defext)) {
623  wxString prompt;
624  prompt.Printf(_("You are about to export a %s file with the name \"%s\".\n\nNormally these files end in \".%s\", and some programs will not open files with nonstandard extensions.\n\nAre you sure you want to export the file under this name?"),
625  mPlugins[mFormat]->GetFormat(mSubFormat),
626  mFilename.GetFullName(),
627  defext);
628 
629  int action = AudacityMessageBox(prompt,
630  _("Warning"),
631  wxYES_NO | wxICON_EXCLAMATION);
632  if (action != wxYES) {
633  continue;
634  }
635  }
636 
637  if (mFilename.GetFullPath().Length() >= 256) {
638  AudacityMessageBox(_("Sorry, pathnames longer than 256 characters not supported."));
639  continue;
640  }
641 
642  // Check to see if we are writing to a path that a missing aliased file existed at.
643  // This causes problems for the exporter, so we don't allow it.
644  // Overwritting non-missing aliased files is okay.
645  // Also, this can only happen for uncompressed audio.
646  bool overwritingMissingAlias;
647  overwritingMissingAlias = false;
648  for (size_t i = 0; i < gAudacityProjects.size(); i++) {
649  AliasedFileArray aliasedFiles;
650  FindDependencies(gAudacityProjects[i].get(), aliasedFiles);
651  for (const auto &aliasedFile : aliasedFiles) {
652  if (mFilename.GetFullPath() == aliasedFile.mFileName.GetFullPath() &&
653  !mFilename.FileExists()) {
654  // Warn and return to the dialog
655  AudacityMessageBox(_("You are attempting to overwrite an aliased file that is missing.\n\
656  The file cannot be written because the path is needed to restore the original audio to the project.\n\
657  Choose Help > Diagnostics > Check Dependencies to view the locations of all missing files.\n\
658  If you still wish to export, please choose a different filename or folder."));
659  overwritingMissingAlias = true;
660  }
661  }
662  }
663  if (overwritingMissingAlias)
664  continue;
665 
666  if (mFilename.FileExists()) {
667  wxString prompt;
668 
669  prompt.Printf(_("A file named \"%s\" already exists. Replace?"),
670  mFilename.GetFullPath());
671 
672  int action = AudacityMessageBox(prompt,
673  _("Warning"),
674  wxYES_NO | wxICON_EXCLAMATION);
675  if (action != wxYES) {
676  continue;
677  }
678  }
679 
680  break;
681  }
682 
683  return true;
684 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
wxFileName mFilename
Definition: Export.h:212
void FindDependencies(AudacityProject *project, AliasedFileArray &outAliasedFiles)
static wxFileNameWrapper DefaultToDocumentsFolder(const wxString &preference)
Definition: FileNames.cpp:354
AProjectArray gAudacityProjects
Definition: Project.cpp:303
wxString mFormatName
Definition: Export.h:204
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
AudacityProject * mProject
Definition: Export.h:207
wxString mFileDialogTitle
Definition: Export.h:206
static void CreateUserPaneCallback(wxWindow *parent, wxUIntPtr userdata)
Definition: Export.cpp:876
virtual void SetUserPaneCreator(UserPaneCreatorFunction creator, wxUIntPtr userdata)
Definition: FileDialog.cpp:30
int mSubFormat
Definition: Export.h:219
std::list< AliasedFile > AliasedFileArray
Definition: Dependencies.h:53
ExportPluginArray mPlugins
Definition: Export.h:210
FileDialogWrapper * mDialog
Definition: Export.h:205
wxSimplebook * mBook
Definition: Export.h:227
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
wxString GetName()
Definition: Project.cpp:1458
int mFormat
Definition: Export.h:218
int mFilterIndex
Definition: Export.h:217
const ExportPluginArray & Exporter::GetPlugins ( )

Definition at line 333 of file Export.cpp.

References mPlugins.

334 {
335  return mPlugins;
336 }
ExportPluginArray mPlugins
Definition: Export.h:210
void Exporter::OnFilterChanged ( wxFileCtrlEvent &  evt)
private

Definition at line 915 of file Export.cpp.

References mBook.

916 {
917  int index = evt.GetFilterIndex();
918 
919  // On GTK, this event can fire before the userpane is created
920  if (mBook == NULL || index < 0 || index >= (int) mBook->GetPageCount())
921  {
922  return;
923  }
924 
925  mBook->ChangeSelection(index);
926 }
wxSimplebook * mBook
Definition: Export.h:227
bool Exporter::Process ( AudacityProject project,
bool  selectedOnly,
double  t0,
double  t1 
)

Definition at line 338 of file Export.cpp.

References _(), CheckFilename(), CheckMix(), AudacityProject::DoEditMetadata(), ExamineTracks(), ExportTracks(), GetFilename(), AudacityProject::GetShowId3Dialog(), mFormat, mMixerSpec, mPlugins, mProject, mSelectedOnly, mSubFormat, mT0, and mT1.

Referenced by ExportCommand::Apply(), MacroCommands::ApplySpecialCommand(), AudacityProject::OnExport(), AudacityProject::OnExportSelection(), and MacroCommands::WriteMp3File().

339 {
340  // Save parms
341  mProject = project;
342  mSelectedOnly = selectedOnly;
343  mT0 = t0;
344  mT1 = t1;
345 
346  // Gather track information
347  if (!ExamineTracks()) {
348  return false;
349  }
350 
351  // Ask user for file name
352  if (!GetFilename()) {
353  return false;
354  }
355 
356  // Check for down mixing
357  if (!CheckMix()) {
358  return false;
359  }
360 
361  // Let user edit MetaData
362  if (mPlugins[mFormat]->GetCanMetaData(mSubFormat)) {
363  if (!(project->DoEditMetadata(_("Edit Metadata Tags"), _("Exported Tags"), mProject->GetShowId3Dialog()))) {
364  return false;
365  }
366  }
367 
368  // Ensure filename doesn't interfere with project files.
369  if (!CheckFilename()) {
370  return false;
371  }
372 
373  // Export the tracks
374  bool success = ExportTracks();
375 
376  // Get rid of mixerspec
377  mMixerSpec.reset();
378 
379  return success;
380 }
double mT1
Definition: Export.h:216
bool mSelectedOnly
Definition: Export.h:225
std::unique_ptr< MixerSpec > mMixerSpec
Definition: Export.h:208
bool CheckMix()
Definition: Export.cpp:756
bool GetFilename()
Definition: Export.cpp:498
AudacityProject * mProject
Definition: Export.h:207
bool CheckFilename()
Definition: Export.cpp:692
bool GetShowId3Dialog()
Definition: Project.h:316
int mSubFormat
Definition: Export.h:219
ExportPluginArray mPlugins
Definition: Export.h:210
bool ExportTracks()
Definition: Export.cpp:831
bool DoEditMetadata(const wxString &title, const wxString &shortUndoDescription, bool force)
Definition: Menus.cpp:7308
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
double mT0
Definition: Export.h:215
int mFormat
Definition: Export.h:218
bool ExamineTracks()
Definition: Export.cpp:412
bool Exporter::Process ( AudacityProject project,
unsigned  numChannels,
const wxChar *  type,
const wxString &  filename,
bool  selectedOnly,
double  t0,
double  t1 
)

Definition at line 382 of file Export.cpp.

References CheckFilename(), ExportTracks(), mActualName, mChannels, mFilename, mFormat, mPlugins, mProject, mSelectedOnly, mSubFormat, mT0, and mT1.

385 {
386  // Save parms
387  mProject = project;
388  mChannels = numChannels;
389  mFilename = filename;
390  mSelectedOnly = selectedOnly;
391  mT0 = t0;
392  mT1 = t1;
394 
395  int i = -1;
396  for (const auto &pPlugin : mPlugins) {
397  ++i;
398  for (int j = 0; j < pPlugin->GetFormatCount(); j++)
399  {
400  if (pPlugin->GetFormat(j).IsSameAs(type, false))
401  {
402  mFormat = i;
403  mSubFormat = j;
404  return CheckFilename() && ExportTracks();
405  }
406  }
407  }
408 
409  return false;
410 }
wxFileName mFilename
Definition: Export.h:212
double mT1
Definition: Export.h:216
bool mSelectedOnly
Definition: Export.h:225
unsigned mChannels
Definition: Export.h:224
AudacityProject * mProject
Definition: Export.h:207
bool CheckFilename()
Definition: Export.cpp:692
int mSubFormat
Definition: Export.h:219
ExportPluginArray mPlugins
Definition: Export.h:210
bool ExportTracks()
Definition: Export.cpp:831
wxFileName mActualName
Definition: Export.h:213
double mT0
Definition: Export.h:215
int mFormat
Definition: Export.h:218
bool Exporter::ProcessFromTimerRecording ( AudacityProject project,
bool  selectedOnly,
double  t0,
double  t1,
wxFileName  fnFile,
int  iFormat,
int  iSubFormat,
int  iFilterIndex 
)

Definition at line 928 of file Export.cpp.

References CheckFilename(), CheckMix(), ExamineTracks(), ExportTracks(), mFilename, mFilterIndex, mFormat, mMixerSpec, mProject, mSelectedOnly, mSubFormat, mT0, and mT1.

Referenced by AudacityProject::ExportFromTimerRecording().

936 {
937  // Save parms
938  mProject = project;
939  mSelectedOnly = selectedOnly;
940  mT0 = t0;
941  mT1 = t1;
942 
943  // Auto Export Parameters
944  mFilename = fnFile;
945  mFormat = iFormat;
946  mSubFormat = iSubFormat;
947  mFilterIndex = iFilterIndex;
948 
949  // Gather track information
950  if (!ExamineTracks()) {
951  return false;
952  }
953 
954  // Check for down mixing
955  if (!CheckMix()) {
956  return false;
957  }
958 
959  // Ensure filename doesn't interfere with project files.
960  if (!CheckFilename()) {
961  return false;
962  }
963 
964  // Export the tracks
965  bool success = ExportTracks();
966 
967  // Get rid of mixerspec
968  mMixerSpec.reset();
969 
970  return success;
971 }
wxFileName mFilename
Definition: Export.h:212
double mT1
Definition: Export.h:216
bool mSelectedOnly
Definition: Export.h:225
std::unique_ptr< MixerSpec > mMixerSpec
Definition: Export.h:208
bool CheckMix()
Definition: Export.cpp:756
AudacityProject * mProject
Definition: Export.h:207
bool CheckFilename()
Definition: Export.cpp:692
int mSubFormat
Definition: Export.h:219
bool ExportTracks()
Definition: Export.cpp:831
double mT0
Definition: Export.h:215
int mFormat
Definition: Export.h:218
bool ExamineTracks()
Definition: Export.cpp:412
int mFilterIndex
Definition: Export.h:217
void Exporter::RegisterPlugin ( movable_ptr< ExportPlugin > &&  plugin)

Definition at line 328 of file Export.cpp.

References mPlugins.

329 {
330  mPlugins.push_back(std::move(ExportPlugin));
331 }
ExportPluginArray mPlugins
Definition: Export.h:210
bool Exporter::SetAutoExportOptions ( AudacityProject project)

Definition at line 989 of file Export.cpp.

References _(), AudacityProject::DoEditMetadata(), GetFilename(), AudacityProject::GetShowId3Dialog(), mFormat, mPlugins, mProject, and mSubFormat.

Referenced by TimerRecordDialog::OnAutoExportPathButton_Click().

989  {
990  mFormat = -1;
991  mProject = project;
992 
993  if( GetFilename()==false )
994  return false;
995 
996  // Let user edit MetaData
997  if (mPlugins[mFormat]->GetCanMetaData(mSubFormat)) {
998  if (!(project->DoEditMetadata(_("Edit Metadata Tags"),
999  _("Exported Tags"), mProject->GetShowId3Dialog()))) {
1000  return false;
1001  }
1002  }
1003 
1004  return true;
1005 }
bool GetFilename()
Definition: Export.cpp:498
AudacityProject * mProject
Definition: Export.h:207
bool GetShowId3Dialog()
Definition: Project.h:316
int mSubFormat
Definition: Export.h:219
ExportPluginArray mPlugins
Definition: Export.h:210
bool DoEditMetadata(const wxString &title, const wxString &shortUndoDescription, bool force)
Definition: Menus.cpp:7308
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
int mFormat
Definition: Export.h:218
void Exporter::SetDefaultFormat ( const wxString &  Format)
inline

Definition at line 163 of file Export.h.

Referenced by AudacityProject::OnExport().

163 { mFormatName = Format;};
Abstract base class used in importing a file.
Definition: Import.h:32
wxString mFormatName
Definition: Export.h:204
void Exporter::SetFileDialogTitle ( const wxString &  DialogTitle)

Definition at line 308 of file Export.cpp.

References mFileDialogTitle.

Referenced by AudacityProject::OnExportSelection().

309 {
310  // The default title is "Export File"
311  mFileDialogTitle = DialogTitle;
312 }
wxString mFileDialogTitle
Definition: Export.h:206

Member Data Documentation

wxFileName Exporter::mActualName
private

Definition at line 213 of file Export.h.

Referenced by CheckFilename(), ExportTracks(), and Process().

wxSimplebook* Exporter::mBook
private

Definition at line 227 of file Export.h.

Referenced by CreateUserPane(), GetFilename(), and OnFilterChanged().

unsigned Exporter::mChannels
private

Definition at line 224 of file Export.h.

Referenced by CheckMix(), ExportTracks(), and Process().

FileDialogWrapper* Exporter::mDialog
private

Definition at line 205 of file Export.h.

Referenced by DisplayOptions(), and GetFilename().

wxString Exporter::mFileDialogTitle
private

Definition at line 206 of file Export.h.

Referenced by GetFilename(), and SetFileDialogTitle().

wxFileName Exporter::mFilename
private
int Exporter::mFilterIndex
private

Definition at line 217 of file Export.h.

Referenced by GetFilename(), and ProcessFromTimerRecording().

int Exporter::mFormat
private
wxString Exporter::mFormatName
private

Definition at line 204 of file Export.h.

Referenced by CheckFilename(), and GetFilename().

std::unique_ptr<MixerSpec> Exporter::mMixerSpec
private

Definition at line 208 of file Export.h.

Referenced by CheckMix(), ExportTracks(), Process(), and ProcessFromTimerRecording().

unsigned Exporter::mNumLeft
private

Definition at line 221 of file Export.h.

Referenced by CheckMix(), and ExamineTracks().

unsigned Exporter::mNumMono
private

Definition at line 223 of file Export.h.

Referenced by CheckMix(), and ExamineTracks().

unsigned Exporter::mNumRight
private

Definition at line 222 of file Export.h.

Referenced by CheckMix(), and ExamineTracks().

int Exporter::mNumSelected
private

Definition at line 220 of file Export.h.

Referenced by ExamineTracks().

ExportPluginArray Exporter::mPlugins
private
AudacityProject* Exporter::mProject
private
bool Exporter::mSelectedOnly
private

Definition at line 225 of file Export.h.

Referenced by CheckMix(), ExamineTracks(), ExportTracks(), Process(), and ProcessFromTimerRecording().

int Exporter::mSubFormat
private
double Exporter::mT0
private

Definition at line 215 of file Export.h.

Referenced by ExamineTracks(), ExportTracks(), Process(), and ProcessFromTimerRecording().

double Exporter::mT1
private

Definition at line 216 of file Export.h.

Referenced by ExamineTracks(), ExportTracks(), Process(), and ProcessFromTimerRecording().


The documentation for this class was generated from the following files: