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 (std::unique_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 }
std::unique_ptr< ExportPlugin > New_ExportMP2()
void SetFileDialogTitle(const wxString &DialogTitle)
Definition: Export.cpp:308
std::unique_ptr< ExportPlugin > New_ExportMP3()
Definition: ExportMP3.cpp:2161
wxString mFormatName
Definition: Export.h:204
std::unique_ptr< MixerSpec > mMixerSpec
Definition: Export.h:208
std::unique_ptr< ExportPlugin > New_ExportFLAC()
wxSimplebook * mBook
Definition: Export.h:227
std::unique_ptr< ExportPlugin > New_ExportCL()
Definition: ExportCL.cpp:549
_("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 RegisterPlugin(std::unique_ptr< ExportPlugin > &&plugin)
Definition: Export.cpp:328
std::unique_ptr< ExportPlugin > New_ExportFFmpeg()
std::unique_ptr< ExportPlugin > New_ExportPCM()
Definition: ExportPCM.cpp:915
std::unique_ptr< ExportPlugin > New_ExportOGG()
Exporter::~Exporter ( )
virtual

Definition at line 304 of file Export.cpp.

305 {
306 }

Member Function Documentation

bool Exporter::CheckFilename ( )
private

Definition at line 693 of file Export.cpp.

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

Referenced by Process(), and ProcessFromTimerRecording().

694 {
695  //
696  // Ensure that exporting a file by this name doesn't overwrite
697  // one of the existing files in the project. (If it would
698  // overwrite an existing file, DirManager tries to rename the
699  // existing file.)
700  //
701 
702  if (!mProject->GetDirManager()->EnsureSafeFilename(mFilename))
703  return false;
704 
705  if( mFormatName.IsEmpty() )
706  gPrefs->Write(wxT("/Export/Format"), mPlugins[mFormat]->GetFormat(mSubFormat));
707  gPrefs->Write(wxT("/Export/Path"), mFilename.GetPath());
708  gPrefs->Flush();
709 
710  //
711  // To be even safer, return a temporary file name based
712  // on this one...
713  //
714 
716 
717  int suffix = 0;
718  while (mFilename.FileExists()) {
719  mFilename.SetName(mActualName.GetName() +
720  wxString::Format(wxT("%d"), suffix));
721  suffix++;
722  }
723 
724  return true;
725 }
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:1429
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 757 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().

758 {
759  // Clean up ... should never happen
760  mMixerSpec.reset();
761 
762  // Detemine if exported file will be stereo or mono or multichannel,
763  // and if mixing will occur.
764 
765  int downMix = gPrefs->Read(wxT("/FileFormats/ExportDownMix"), true);
766  int exportedChannels = mPlugins[mFormat]->SetNumExportChannels();
767 
768  if (downMix) {
769  if (mNumRight > 0 || mNumLeft > 0) {
770  mChannels = 2;
771  }
772  else {
773  mChannels = 1;
774  }
776  mPlugins[mFormat]->GetMaxChannels(mSubFormat));
777 
778  auto numLeft = mNumLeft + mNumMono;
779  auto numRight = mNumRight + mNumMono;
780 
781  if (numLeft > 1 || numRight > 1 || mNumLeft + mNumRight + mNumMono > mChannels) {
782  wxString exportFormat = mPlugins[mFormat]->GetFormat(mSubFormat);
783  if (exportFormat != wxT("CL") && exportFormat != wxT("FFMPEG") && exportedChannels == -1)
784  exportedChannels = mChannels;
785 
786  if (exportedChannels == 1) {
788  wxT("MixMono"),
789  _("Your tracks will be mixed down and exported as one mono file."),
790  true) == wxID_CANCEL)
791  return false;
792  }
793  else if (exportedChannels == 2) {
795  wxT("MixStereo"),
796  _("Your tracks will be mixed down and exported as one stereo file."),
797  true) == wxID_CANCEL)
798  return false;
799  }
800  else {
802  wxT("MixUnknownChannels"),
803  _("Your tracks will be mixed down to one exported file according to the encoder settings."),
804  true) == wxID_CANCEL)
805  return false;
806  }
807  }
808  }
809  else
810  {
811  if (exportedChannels < 0)
812  exportedChannels = mPlugins[mFormat]->GetMaxChannels(mSubFormat);
813 
816  exportedChannels,
817  NULL,
818  1,
819  _("Advanced Mixing Options"));
820 
821  if (md.ShowModal() != wxID_OK) {
822  return false;
823  }
824 
825  mMixerSpec = std::make_unique<MixerSpec>(*(md.GetMixerSpec()));
826  mChannels = mMixerSpec->GetNumChannels();
827  }
828 
829  return true;
830 }
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 886 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().

887 {
888  ShuttleGui S(parent, eIsCreating);
889 
890  S.StartVerticalLay();
891  {
892  S.StartHorizontalLay(wxEXPAND);
893  {
894  S.StartStatic(_("Format Options"), 1);
895  {
896  mBook = safenew wxSimplebook(S.GetParent());
897  S.AddWindow(mBook, wxEXPAND);
898 
899  for (const auto &pPlugin : mPlugins)
900  {
901  for (int j = 0; j < pPlugin->GetFormatCount(); j++)
902  {
903  mBook->AddPage(pPlugin->OptionsCreate(mBook, j), wxEmptyString);
904  }
905  }
906  }
907  S.EndStatic();
908  }
909  S.EndHorizontalLay();
910  }
911  S.EndVerticalLay();
912 
913  return;
914 }
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 877 of file Export.cpp.

References CreateUserPane().

Referenced by GetFilename().

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

Definition at line 727 of file Export.cpp.

References mDialog, mPlugins, and mProject.

728 {
729  int c = 0;
730  int mf = -1, msf = -1;
731  int i = -1;
732  for (const auto &pPlugin : mPlugins)
733  {
734  ++i;
735  for (int j = 0; j < pPlugin->GetFormatCount(); j++)
736  {
737  if (index == c)
738  {
739  mf = i;
740  msf = j;
741  }
742  c++;
743  }
744  }
745  // This shouldn't happen...
746  if (index >= c) {
747  return;
748  }
749 
750 #if defined(__WXMSW__)
751  mPlugins[mf]->DisplayOptions(mProject, msf);
752 #else
753  mPlugins[mf]->DisplayOptions(mDialog, msf);
754 #endif
755 }
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:619
virtual double GetOffset() const =0
bool GetSelected() const
Definition: Track.h:276
double mT1
Definition: Export.h:216
virtual double GetEndTime() const =0
bool mSelectedOnly
Definition: Export.h:225
virtual int GetChannel() const
Definition: Track.h:286
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:330
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:102
_("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 832 of file Export.cpp.

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

Referenced by Process(), and ProcessFromTimerRecording().

833 {
834  // Keep original in case of failure
835  if (mActualName != mFilename) {
836  ::wxRenameFile(mActualName.GetFullPath(), mFilename.GetFullPath());
837  }
838 
839  bool success = false;
840 
841  auto cleanup = finally( [&] {
842  if (mActualName != mFilename) {
843  // Remove backup
844  if ( success )
845  ::wxRemoveFile(mFilename.GetFullPath());
846  else {
847  // Restore original, if needed
848  ::wxRemoveFile(mActualName.GetFullPath());
849  ::wxRenameFile(mFilename.GetFullPath(), mActualName.GetFullPath());
850  }
851  }
852  else {
853  if ( ! success )
854  // Remove any new, and only partially written, file.
855  ::wxRemoveFile(mFilename.GetFullPath());
856  }
857  } );
858 
859  std::unique_ptr<ProgressDialog> pDialog;
860  auto result = mPlugins[mFormat]->Export(mProject,
861  pDialog,
862  mChannels,
863  mActualName.GetFullPath(),
865  mT0,
866  mT1,
867  mMixerSpec.get(),
868  NULL,
869  mSubFormat);
870 
871  success =
872  result == ProgressResult::Success || result == ProgressResult::Stopped;
873 
874  return success;
875 }
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 986 of file Export.cpp.

References mFilename.

Referenced by TimerRecordDialog::OnAutoExportPathButton_Click().

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

Definition at line 982 of file Export.cpp.

References mFormat.

Referenced by TimerRecordDialog::OnAutoExportPathButton_Click().

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

Definition at line 974 of file Export.cpp.

References mFormat.

Referenced by TimerRecordDialog::OnAutoExportPathButton_Click().

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

Definition at line 978 of file Export.cpp.

References mSubFormat.

Referenced by TimerRecordDialog::OnAutoExportPathButton_Click().

978  {
979  return mSubFormat;
980 }
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  mSubFormat = 0;
530  }
531  maskString.RemoveLast();
532  wxString defext = mPlugins[mFormat]->GetExtension(mSubFormat).Lower();
533 
534 //Bug 1304: Set a default path if none was given. For Export.
535  mFilename = FileNames::DefaultToDocumentsFolder(wxT("/Export/Path"));
536  mFilename.SetName(mProject->GetName());
537  if (mFilename.GetName().empty())
538  mFilename.SetName(_("untitled"));
539  while (true) {
540  // Must reset each iteration
541  mBook = NULL;
542 
543  {
544  auto useFileName = mFilename;
545  if (!useFileName.HasExt())
546  useFileName.SetExt(defext);
549  mFilename.GetPath(),
550  useFileName.GetFullName(),
551  maskString,
552  wxFD_SAVE | wxRESIZE_BORDER);
553  mDialog = &fd;
554  mDialog->PushEventHandler(this);
555 
556  fd.SetUserPaneCreator(CreateUserPaneCallback, (wxUIntPtr) this);
557  fd.SetFilterIndex(mFilterIndex);
558 
559  int result = fd.ShowModal();
560 
561  mDialog->PopEventHandler();
562 
563  if (result == wxID_CANCEL) {
564  return false;
565  }
566 
567  mFilename = fd.GetPath();
568  if (mFilename == wxT("")) {
569  return false;
570  }
571 
572  mFormat = fd.GetFilterIndex();
573  mFilterIndex = fd.GetFilterIndex();
574  }
575 
576  int c = 0;
577  int i = -1;
578  for (const auto &pPlugin : mPlugins)
579  {
580  ++i;
581  for (int j = 0; j < pPlugin->GetFormatCount(); j++)
582  {
583  if (mFilterIndex == c)
584  {
585  mFormat = i;
586  mSubFormat = j;
587  }
588  c++;
589  }
590  }
591 
592  wxString ext = mFilename.GetExt();
593  defext = mPlugins[mFormat]->GetExtension(mSubFormat).Lower();
594 
595  //
596  // Check the extension - add the default if it's not there,
597  // and warn user if it's abnormal.
598  //
599  if (ext.IsEmpty()) {
600  //
601  // Make sure the user doesn't accidentally save the file
602  // as an extension with no name, like just plain ".wav".
603  //
604  if (mFilename.GetName().Left(1) == wxT(".")) {
605  wxString prompt = wxString::Format(
606  _("Are you sure you want to export the file as \"%s\"?\n"),
607  mFilename.GetFullName() );
608 
609  int action = AudacityMessageBox(prompt,
610  _("Warning"),
611  wxYES_NO | wxICON_EXCLAMATION);
612  if (action != wxYES) {
613  continue;
614  }
615  }
616 
617  mFilename.SetExt(defext);
618  }
619  else if (!mPlugins[mFormat]->CheckFileName(mFilename, mSubFormat))
620  {
621  continue;
622  }
623  else if (!ext.IsEmpty() && !mPlugins[mFormat]->IsExtension(ext,mSubFormat) && ext.CmpNoCase(defext)) {
624  wxString prompt;
625  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?"),
626  mPlugins[mFormat]->GetFormat(mSubFormat),
627  mFilename.GetFullName(),
628  defext);
629 
630  int action = AudacityMessageBox(prompt,
631  _("Warning"),
632  wxYES_NO | wxICON_EXCLAMATION);
633  if (action != wxYES) {
634  continue;
635  }
636  }
637 
638  if (mFilename.GetFullPath().Length() >= 256) {
639  AudacityMessageBox(_("Sorry, pathnames longer than 256 characters not supported."));
640  continue;
641  }
642 
643  // Check to see if we are writing to a path that a missing aliased file existed at.
644  // This causes problems for the exporter, so we don't allow it.
645  // Overwritting non-missing aliased files is okay.
646  // Also, this can only happen for uncompressed audio.
647  bool overwritingMissingAlias;
648  overwritingMissingAlias = false;
649  for (size_t i = 0; i < gAudacityProjects.size(); i++) {
650  AliasedFileArray aliasedFiles;
651  FindDependencies(gAudacityProjects[i].get(), aliasedFiles);
652  for (const auto &aliasedFile : aliasedFiles) {
653  if (mFilename.GetFullPath() == aliasedFile.mFileName.GetFullPath() &&
654  !mFilename.FileExists()) {
655  // Warn and return to the dialog
656  AudacityMessageBox(_("You are attempting to overwrite an aliased file that is missing.\n\
657  The file cannot be written because the path is needed to restore the original audio to the project.\n\
658  Choose Help > Diagnostics > Check Dependencies to view the locations of all missing files.\n\
659  If you still wish to export, please choose a different filename or folder."));
660  overwritingMissingAlias = true;
661  }
662  }
663  }
664  if (overwritingMissingAlias)
665  continue;
666 
667  if (mFilename.FileExists()) {
668  wxString prompt;
669 
670  prompt.Printf(_("A file named \"%s\" already exists. Replace?"),
671  mFilename.GetFullPath());
672 
673  int action = AudacityMessageBox(prompt,
674  _("Warning"),
675  wxYES_NO | wxICON_EXCLAMATION);
676  if (action != wxYES) {
677  continue;
678  }
679  }
680 
681  break;
682  }
683 
684  return true;
685 }
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:877
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:1465
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 916 of file Export.cpp.

References mBook.

917 {
918  int index = evt.GetFilterIndex();
919 
920  // On GTK, this event can fire before the userpane is created
921  if (mBook == NULL || index < 0 || index >= (int) mBook->GetPageCount())
922  {
923  return;
924  }
925 
926  mBook->ChangeSelection(index);
927 }
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(), AudacityProject::SaveCopyWaveTracks(), 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:757
bool GetFilename()
Definition: Export.cpp:498
AudacityProject * mProject
Definition: Export.h:207
bool CheckFilename()
Definition: Export.cpp:693
bool GetShowId3Dialog()
Definition: Project.h:316
int mSubFormat
Definition: Export.h:219
ExportPluginArray mPlugins
Definition: Export.h:210
bool ExportTracks()
Definition: Export.cpp:832
bool DoEditMetadata(const wxString &title, const wxString &shortUndoDescription, bool force)
Definition: Menus.cpp:7334
_("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:693
int mSubFormat
Definition: Export.h:219
ExportPluginArray mPlugins
Definition: Export.h:210
bool ExportTracks()
Definition: Export.cpp:832
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 929 of file Export.cpp.

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

Referenced by AudacityProject::ExportFromTimerRecording().

937 {
938  // Save parms
939  mProject = project;
940  mSelectedOnly = selectedOnly;
941  mT0 = t0;
942  mT1 = t1;
943 
944  // Auto Export Parameters
945  mFilename = fnFile;
946  mFormat = iFormat;
947  mSubFormat = iSubFormat;
948  mFilterIndex = iFilterIndex;
949 
950  // Gather track information
951  if (!ExamineTracks()) {
952  return false;
953  }
954 
955  // Check for down mixing
956  if (!CheckMix()) {
957  return false;
958  }
959 
960  // Ensure filename doesn't interfere with project files.
961  if (!CheckFilename()) {
962  return false;
963  }
964 
965  // Export the tracks
966  bool success = ExportTracks();
967 
968  // Get rid of mixerspec
969  mMixerSpec.reset();
970 
971  return success;
972 }
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:757
AudacityProject * mProject
Definition: Export.h:207
bool CheckFilename()
Definition: Export.cpp:693
int mSubFormat
Definition: Export.h:219
bool ExportTracks()
Definition: Export.cpp:832
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 ( std::unique_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 990 of file Export.cpp.

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

Referenced by TimerRecordDialog::OnAutoExportPathButton_Click().

990  {
991  mFormat = -1;
992  mProject = project;
993 
994  if( GetFilename()==false )
995  return false;
996 
997  // Let user edit MetaData
998  if (mPlugins[mFormat]->GetCanMetaData(mSubFormat)) {
999  if (!(project->DoEditMetadata(_("Edit Metadata Tags"),
1000  _("Exported Tags"), mProject->GetShowId3Dialog()))) {
1001  return false;
1002  }
1003  }
1004 
1005  return true;
1006 }
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:7334
_("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: