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 140 of file Export.h.

Constructor & Destructor Documentation

Exporter::Exporter ( )

Definition at line 267 of file Export.cpp.

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

268 {
269  mMixerSpec = NULL;
270  mBook = NULL;
271  mFormatName = "";
272 
273  SetFileDialogTitle( _("Export Audio") );
274 
277 
278 #ifdef USE_LIBVORBIS
280 #endif
281 
282 #ifdef USE_LIBFLAC
284 #endif
285 
286 #if USE_LIBTWOLAME
288 #endif
289 
290  // Command line export not available on Windows and Mac platforms
292 
293 #if defined(USE_FFMPEG)
295 #endif
296 }
void RegisterPlugin(movable_ptr< ExportPlugin > &&plugin)
Definition: Export.cpp:322
movable_ptr< ExportPlugin > New_ExportMP3()
Definition: ExportMP3.cpp:2126
movable_ptr< ExportPlugin > New_ExportPCM()
Definition: ExportPCM.cpp:890
void SetFileDialogTitle(const wxString &DialogTitle)
Definition: Export.cpp:302
movable_ptr< ExportPlugin > New_ExportMP2()
movable_ptr< ExportPlugin > New_ExportOGG()
movable_ptr< ExportPlugin > New_ExportFFmpeg()
wxString mFormatName
Definition: Export.h:189
std::unique_ptr< MixerSpec > mMixerSpec
Definition: Export.h:193
movable_ptr< ExportPlugin > New_ExportCL()
Definition: ExportCL.cpp:543
wxSimplebook * mBook
Definition: Export.h:212
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
movable_ptr< ExportPlugin > New_ExportFLAC()
Exporter::~Exporter ( )
virtual

Definition at line 298 of file Export.cpp.

299 {
300 }

Member Function Documentation

bool Exporter::CheckFilename ( )
private

Definition at line 686 of file Export.cpp.

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

Referenced by Process(), and ProcessFromTimerRecording().

687 {
688  //
689  // Ensure that exporting a file by this name doesn't overwrite
690  // one of the existing files in the project. (If it would
691  // overwrite an existing file, DirManager tries to rename the
692  // existing file.)
693  //
694 
695  if (!mProject->GetDirManager()->EnsureSafeFilename(mFilename))
696  return false;
697 
698  if( mFormatName.IsEmpty() )
699  gPrefs->Write(wxT("/Export/Format"), mPlugins[mFormat]->GetFormat(mSubFormat));
700  gPrefs->Write(wxT("/Export/Path"), mFilename.GetPath());
701  gPrefs->Flush();
702 
703  //
704  // To be even safer, return a temporary file name based
705  // on this one...
706  //
707 
709 
710  int suffix = 0;
711  while (mFilename.FileExists()) {
712  mFilename.SetName(mActualName.GetName() +
713  wxString::Format(wxT("%d"), suffix));
714  suffix++;
715  }
716 
717  return true;
718 }
wxFileName mFilename
Definition: Export.h:197
wxString mFormatName
Definition: Export.h:189
AudacityProject * mProject
Definition: Export.h:192
const std::shared_ptr< DirManager > & GetDirManager()
Definition: Project.cpp:1407
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
int mSubFormat
Definition: Export.h:204
ExportPluginArray mPlugins
Definition: Export.h:195
wxFileName mActualName
Definition: Export.h:198
int mFormat
Definition: Export.h:203
bool Exporter::CheckMix ( )
private

Definition at line 750 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().

751 {
752  // Clean up ... should never happen
753  mMixerSpec.reset();
754 
755  // Detemine if exported file will be stereo or mono or multichannel,
756  // and if mixing will occur.
757 
758  int downMix = gPrefs->Read(wxT("/FileFormats/ExportDownMix"), true);
759  int exportedChannels = mPlugins[mFormat]->SetNumExportChannels();
760 
761  if (downMix) {
762  if (mNumRight > 0 || mNumLeft > 0) {
763  mChannels = 2;
764  }
765  else {
766  mChannels = 1;
767  }
769  mPlugins[mFormat]->GetMaxChannels(mSubFormat));
770 
771  auto numLeft = mNumLeft + mNumMono;
772  auto numRight = mNumRight + mNumMono;
773 
774  if (numLeft > 1 || numRight > 1 || mNumLeft + mNumRight + mNumMono > mChannels) {
775  wxString exportFormat = mPlugins[mFormat]->GetFormat(mSubFormat);
776  if (exportFormat != wxT("CL") && exportFormat != wxT("FFMPEG") && exportedChannels == -1)
777  exportedChannels = mChannels;
778 
779  if (exportedChannels == 1) {
781  wxT("MixMono"),
782  _("Your tracks will be mixed down to a single mono channel in the exported file."),
783  true) == wxID_CANCEL)
784  return false;
785  }
786  else if (exportedChannels == 2) {
788  wxT("MixStereo"),
789  _("Your tracks will be mixed down to two stereo channels in the exported file."),
790  true) == wxID_CANCEL)
791  return false;
792  }
793  else {
795  wxT("MixUnknownChannels"),
796  _("Your tracks will be mixed down to one exported file according to the encoder settings."),
797  true) == wxID_CANCEL)
798  return false;
799  }
800  }
801  }
802  else
803  {
804  if (exportedChannels < 0)
805  exportedChannels = mPlugins[mFormat]->GetMaxChannels(mSubFormat);
806 
809  exportedChannels,
810  NULL,
811  1,
812  _("Advanced Mixing Options"));
813 
814  if (md.ShowModal() != wxID_OK) {
815  return false;
816  }
817 
818  mMixerSpec = std::make_unique<MixerSpec>(*(md.GetMixerSpec()));
819  mChannels = mMixerSpec->GetNumChannels();
820  }
821 
822  return true;
823 }
bool mSelectedOnly
Definition: Export.h:210
std::unique_ptr< MixerSpec > mMixerSpec
Definition: Export.h:193
unsigned mChannels
Definition: Export.h:209
unsigned mNumRight
Definition: Export.h:207
AudacityProject * mProject
Definition: Export.h:192
int ShowWarningDialog(wxWindow *parent, const wxString &internalDialogName, const wxString &message, bool showCancelButton, const wxString &footer)
Definition: Warning.cpp:92
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
unsigned mNumLeft
Definition: Export.h:206
int mSubFormat
Definition: Export.h:204
ExportPluginArray mPlugins
Definition: Export.h:195
int min(int a, int b)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
unsigned mNumMono
Definition: Export.h:208
int mFormat
Definition: Export.h:203
Dialog for advanced mixing.
Definition: Export.h:253
TrackList * GetTracks()
Definition: Project.h:177
void Exporter::CreateUserPane ( wxWindow *  parent)
private

Definition at line 877 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().

878 {
879  ShuttleGui S(parent, eIsCreating);
880 
881  S.StartVerticalLay();
882  {
883  S.StartHorizontalLay(wxEXPAND);
884  {
885  S.StartStatic(_("Format Options"), 1);
886  {
887  mBook = safenew wxSimplebook(S.GetParent());
888  S.AddWindow(mBook, wxEXPAND);
889 
890  for (const auto &pPlugin : mPlugins)
891  {
892  for (int j = 0; j < pPlugin->GetFormatCount(); j++)
893  {
894  mBook->AddPage(pPlugin->OptionsCreate(mBook, j), wxEmptyString);
895  }
896  }
897  }
898  S.EndStatic();
899  }
900  S.EndHorizontalLay();
901  }
902  S.EndVerticalLay();
903 
904  return;
905 }
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:366
#define safenew
Definition: Audacity.h:223
ExportPluginArray mPlugins
Definition: Export.h:195
wxSimplebook * mBook
Definition: Export.h:212
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
void Exporter::CreateUserPaneCallback ( wxWindow *  parent,
wxUIntPtr  userdata 
)
staticprivate

Definition at line 868 of file Export.cpp.

References CreateUserPane().

Referenced by GetFilename().

869 {
870  Exporter *self = (Exporter *) userdata;
871  if (self)
872  {
873  self->CreateUserPane(parent);
874  }
875 }
void CreateUserPane(wxWindow *parent)
Definition: Export.cpp:877
void Exporter::DisplayOptions ( int  index)

Definition at line 720 of file Export.cpp.

References mDialog, mPlugins, and mProject.

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

Definition at line 406 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().

407 {
408  // Init
409  mNumSelected = 0;
410  mNumLeft = 0;
411  mNumRight = 0;
412  mNumMono = 0;
413 
414  // First analyze the selected audio, perform sanity checks, and provide
415  // information as appropriate.
416 
417  // Tally how many are right, left, mono, and make sure at
418  // least one track is selected (if selectedOnly==true)
419 
420  double earliestBegin = mT1;
421  double latestEnd = mT0;
422 
423  const TrackList *tracks = mProject->GetTracks();
424  TrackListConstIterator iter1(tracks);
425  const Track *tr = iter1.First();
426 
427  while (tr) {
428  if (tr->GetKind() == Track::Wave) {
429  auto wt = static_cast<const WaveTrack *>(tr);
430  if ( (tr->GetSelected() || !mSelectedOnly) &&
431  !wt->GetMute() ) { // don't count muted tracks
432  mNumSelected++;
433 
434  if (tr->GetChannel() == Track::LeftChannel) {
435  mNumLeft++;
436  }
437  else if (tr->GetChannel() == Track::RightChannel) {
438  mNumRight++;
439  }
440  else if (tr->GetChannel() == Track::MonoChannel) {
441  // It's a mono channel, but it may be panned
442  float pan = ((WaveTrack*)tr)->GetPan();
443 
444  if (pan == -1.0)
445  mNumLeft++;
446  else if (pan == 1.0)
447  mNumRight++;
448  else if (pan == 0)
449  mNumMono++;
450  else {
451  // Panned partially off-center. Mix as stereo.
452  mNumLeft++;
453  mNumRight++;
454  }
455  }
456 
457  if (tr->GetOffset() < earliestBegin) {
458  earliestBegin = tr->GetOffset();
459  }
460 
461  if (tr->GetEndTime() > latestEnd) {
462  latestEnd = tr->GetEndTime();
463  }
464 
465  }
466  }
467 
468  tr = iter1.Next();
469  }
470 
471  if (mNumSelected == 0) {
472  wxString message;
473  if(mSelectedOnly)
474  message = _("All selected audio is muted.");
475  else
476  message = _("All audio is muted.");
477  AudacityMessageBox(message,
478  _("Unable to export"),
479  wxOK | wxICON_INFORMATION);
480  return false;
481  }
482 
483  if (mT0 < earliestBegin)
484  mT0 = earliestBegin;
485 
486  if (mT1 > latestEnd)
487  mT1 = latestEnd;
488 
489  return true;
490 }
A list of TrackListNode items.
Definition: Track.h:553
virtual double GetOffset() const =0
bool GetSelected() const
Definition: Track.h:217
double mT1
Definition: Export.h:201
virtual double GetEndTime() const =0
bool mSelectedOnly
Definition: Export.h:210
virtual int GetChannel() const
Definition: Track.h:223
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:207
AudacityProject * mProject
Definition: Export.h:192
virtual int GetKind() const
Definition: Track.h:267
unsigned mNumLeft
Definition: Export.h:206
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:67
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
unsigned mNumMono
Definition: Export.h:208
double mT0
Definition: Export.h:200
TrackList * GetTracks()
Definition: Project.h:177
int mNumSelected
Definition: Export.h:205
bool Exporter::ExportTracks ( )
private

Definition at line 825 of file Export.cpp.

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

Referenced by Process(), and ProcessFromTimerRecording().

826 {
827  // Keep original in case of failure
828  if (mActualName != mFilename) {
829  ::wxRenameFile(mActualName.GetFullPath(), mFilename.GetFullPath());
830  }
831 
832  bool success = false;
833 
834  auto cleanup = finally( [&] {
835  if (mActualName != mFilename) {
836  // Remove backup
837  if ( success )
838  ::wxRemoveFile(mFilename.GetFullPath());
839  else {
840  // Restore original, if needed
841  ::wxRemoveFile(mActualName.GetFullPath());
842  ::wxRenameFile(mFilename.GetFullPath(), mActualName.GetFullPath());
843  }
844  }
845  else {
846  if ( ! success )
847  // Remove any new, and only partially written, file.
848  ::wxRemoveFile(mFilename.GetFullPath());
849  }
850  } );
851 
852  auto result = mPlugins[mFormat]->Export(mProject,
853  mChannels,
854  mActualName.GetFullPath(),
856  mT0,
857  mT1,
858  mMixerSpec.get(),
859  NULL,
860  mSubFormat);
861 
862  success =
863  result == ProgressResult::Success || result == ProgressResult::Stopped;
864 
865  return success;
866 }
wxFileName mFilename
Definition: Export.h:197
double mT1
Definition: Export.h:201
bool mSelectedOnly
Definition: Export.h:210
std::unique_ptr< MixerSpec > mMixerSpec
Definition: Export.h:193
unsigned mChannels
Definition: Export.h:209
AudacityProject * mProject
Definition: Export.h:192
int mSubFormat
Definition: Export.h:204
ExportPluginArray mPlugins
Definition: Export.h:195
wxFileName mActualName
Definition: Export.h:198
double mT0
Definition: Export.h:200
int mFormat
Definition: Export.h:203
int Exporter::FindFormatIndex ( int  exportindex)

Definition at line 308 of file Export.cpp.

References mPlugins.

309 {
310  int c = 0;
311  for (const auto &pPlugin : mPlugins)
312  {
313  for (int j = 0; j < pPlugin->GetFormatCount(); j++)
314  {
315  if (exportindex == c) return j;
316  c++;
317  }
318  }
319  return 0;
320 }
ExportPluginArray mPlugins
Definition: Export.h:195
wxFileName Exporter::GetAutoExportFileName ( )

Definition at line 977 of file Export.cpp.

References mFilename.

Referenced by TimerRecordDialog::OnAutoExportPathButton_Click().

977  {
978  return mFilename;
979 }
wxFileName mFilename
Definition: Export.h:197
int Exporter::GetAutoExportFilterIndex ( )

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:203
int Exporter::GetAutoExportFormat ( )

Definition at line 965 of file Export.cpp.

References mFormat.

Referenced by TimerRecordDialog::OnAutoExportPathButton_Click().

965  {
966  return mFormat;
967 }
int mFormat
Definition: Export.h:203
int Exporter::GetAutoExportSubFormat ( )

Definition at line 969 of file Export.cpp.

References mSubFormat.

Referenced by TimerRecordDialog::OnAutoExportPathButton_Click().

969  {
970  return mSubFormat;
971 }
int mSubFormat
Definition: Export.h:204
bool Exporter::GetFilename ( )
private

Definition at line 492 of file Export.cpp.

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

Referenced by Process(), and SetAutoExportOptions().

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

Definition at line 327 of file Export.cpp.

References mPlugins.

328 {
329  return mPlugins;
330 }
ExportPluginArray mPlugins
Definition: Export.h:195
void Exporter::OnFilterChanged ( wxFileCtrlEvent &  evt)
private

Definition at line 907 of file Export.cpp.

References mBook.

908 {
909  int index = evt.GetFilterIndex();
910 
911  // On GTK, this event can fire before the userpane is created
912  if (mBook == NULL || index < 0 || index >= (int) mBook->GetPageCount())
913  {
914  return;
915  }
916 
917  mBook->ChangeSelection(index);
918 }
wxSimplebook * mBook
Definition: Export.h:212
bool Exporter::Process ( AudacityProject project,
bool  selectedOnly,
double  t0,
double  t1 
)

Definition at line 332 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(), BatchCommands::ApplySpecialCommand(), AudacityProject::OnExport(), AudacityProject::OnExportSelection(), and BatchCommands::WriteMp3File().

333 {
334  // Save parms
335  mProject = project;
336  mSelectedOnly = selectedOnly;
337  mT0 = t0;
338  mT1 = t1;
339 
340  // Gather track information
341  if (!ExamineTracks()) {
342  return false;
343  }
344 
345  // Ask user for file name
346  if (!GetFilename()) {
347  return false;
348  }
349 
350  // Check for down mixing
351  if (!CheckMix()) {
352  return false;
353  }
354 
355  // Let user edit MetaData
356  if (mPlugins[mFormat]->GetCanMetaData(mSubFormat)) {
357  if (!(project->DoEditMetadata(_("Edit Metadata Tags"), _("Exported Tags"), mProject->GetShowId3Dialog()))) {
358  return false;
359  }
360  }
361 
362  // Ensure filename doesn't interfere with project files.
363  if (!CheckFilename()) {
364  return false;
365  }
366 
367  // Export the tracks
368  bool success = ExportTracks();
369 
370  // Get rid of mixerspec
371  mMixerSpec.reset();
372 
373  return success;
374 }
double mT1
Definition: Export.h:201
bool mSelectedOnly
Definition: Export.h:210
std::unique_ptr< MixerSpec > mMixerSpec
Definition: Export.h:193
bool CheckMix()
Definition: Export.cpp:750
bool GetFilename()
Definition: Export.cpp:492
AudacityProject * mProject
Definition: Export.h:192
bool CheckFilename()
Definition: Export.cpp:686
bool GetShowId3Dialog()
Definition: Project.h:301
int mSubFormat
Definition: Export.h:204
ExportPluginArray mPlugins
Definition: Export.h:195
bool ExportTracks()
Definition: Export.cpp:825
bool DoEditMetadata(const wxString &title, const wxString &shortUndoDescription, bool force)
Definition: Menus.cpp:7005
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
double mT0
Definition: Export.h:200
int mFormat
Definition: Export.h:203
bool ExamineTracks()
Definition: Export.cpp:406
bool Exporter::Process ( AudacityProject project,
unsigned  numChannels,
const wxChar *  type,
const wxString &  filename,
bool  selectedOnly,
double  t0,
double  t1 
)

Definition at line 376 of file Export.cpp.

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

379 {
380  // Save parms
381  mProject = project;
382  mChannels = numChannels;
383  mFilename = filename;
384  mSelectedOnly = selectedOnly;
385  mT0 = t0;
386  mT1 = t1;
388 
389  int i = -1;
390  for (const auto &pPlugin : mPlugins) {
391  ++i;
392  for (int j = 0; j < pPlugin->GetFormatCount(); j++)
393  {
394  if (pPlugin->GetFormat(j).IsSameAs(type, false))
395  {
396  mFormat = i;
397  mSubFormat = j;
398  return CheckFilename() && ExportTracks();
399  }
400  }
401  }
402 
403  return false;
404 }
wxFileName mFilename
Definition: Export.h:197
double mT1
Definition: Export.h:201
bool mSelectedOnly
Definition: Export.h:210
unsigned mChannels
Definition: Export.h:209
AudacityProject * mProject
Definition: Export.h:192
bool CheckFilename()
Definition: Export.cpp:686
int mSubFormat
Definition: Export.h:204
ExportPluginArray mPlugins
Definition: Export.h:195
bool ExportTracks()
Definition: Export.cpp:825
wxFileName mActualName
Definition: Export.h:198
double mT0
Definition: Export.h:200
int mFormat
Definition: Export.h:203
bool Exporter::ProcessFromTimerRecording ( AudacityProject project,
bool  selectedOnly,
double  t0,
double  t1,
wxFileName  fnFile,
int  iFormat,
int  iSubFormat,
int  iFilterIndex 
)

Definition at line 920 of file Export.cpp.

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

Referenced by AudacityProject::ExportFromTimerRecording().

928 {
929  // Save parms
930  mProject = project;
931  mSelectedOnly = selectedOnly;
932  mT0 = t0;
933  mT1 = t1;
934 
935  // Auto Export Parameters
936  mFilename = fnFile;
937  mFormat = iFormat;
938  mSubFormat = iSubFormat;
939  mFilterIndex = iFilterIndex;
940 
941  // Gather track information
942  if (!ExamineTracks()) {
943  return false;
944  }
945 
946  // Check for down mixing
947  if (!CheckMix()) {
948  return false;
949  }
950 
951  // Ensure filename doesn't interfere with project files.
952  if (!CheckFilename()) {
953  return false;
954  }
955 
956  // Export the tracks
957  bool success = ExportTracks();
958 
959  // Get rid of mixerspec
960  mMixerSpec.reset();
961 
962  return success;
963 }
wxFileName mFilename
Definition: Export.h:197
double mT1
Definition: Export.h:201
bool mSelectedOnly
Definition: Export.h:210
std::unique_ptr< MixerSpec > mMixerSpec
Definition: Export.h:193
bool CheckMix()
Definition: Export.cpp:750
AudacityProject * mProject
Definition: Export.h:192
bool CheckFilename()
Definition: Export.cpp:686
int mSubFormat
Definition: Export.h:204
bool ExportTracks()
Definition: Export.cpp:825
double mT0
Definition: Export.h:200
int mFormat
Definition: Export.h:203
bool ExamineTracks()
Definition: Export.cpp:406
int mFilterIndex
Definition: Export.h:202
void Exporter::RegisterPlugin ( movable_ptr< ExportPlugin > &&  plugin)

Definition at line 322 of file Export.cpp.

References mPlugins.

323 {
324  mPlugins.push_back(std::move(ExportPlugin));
325 }
ExportPluginArray mPlugins
Definition: Export.h:195
bool Exporter::SetAutoExportOptions ( AudacityProject project)

Definition at line 981 of file Export.cpp.

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

Referenced by TimerRecordDialog::OnAutoExportPathButton_Click().

981  {
982  mFormat = -1;
983  mProject = project;
984 
985  if( GetFilename()==false )
986  return false;
987 
988  // Let user edit MetaData
989  if (mPlugins[mFormat]->GetCanMetaData(mSubFormat)) {
990  if (!(project->DoEditMetadata(_("Edit Metadata Tags"),
991  _("Exported Tags"), mProject->GetShowId3Dialog()))) {
992  return false;
993  }
994  }
995 
996  return true;
997 }
bool GetFilename()
Definition: Export.cpp:492
AudacityProject * mProject
Definition: Export.h:192
bool GetShowId3Dialog()
Definition: Project.h:301
int mSubFormat
Definition: Export.h:204
ExportPluginArray mPlugins
Definition: Export.h:195
bool DoEditMetadata(const wxString &title, const wxString &shortUndoDescription, bool force)
Definition: Menus.cpp:7005
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
int mFormat
Definition: Export.h:203
void Exporter::SetDefaultFormat ( const wxString &  Format)
inline

Definition at line 148 of file Export.h.

Referenced by AudacityProject::OnExport().

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

Definition at line 302 of file Export.cpp.

References mFileDialogTitle.

Referenced by AudacityProject::OnExportSelection().

303 {
304  // The default title is "Export File"
305  mFileDialogTitle = DialogTitle;
306 }
wxString mFileDialogTitle
Definition: Export.h:191

Member Data Documentation

wxFileName Exporter::mActualName
private

Definition at line 198 of file Export.h.

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

wxSimplebook* Exporter::mBook
private

Definition at line 212 of file Export.h.

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

unsigned Exporter::mChannels
private

Definition at line 209 of file Export.h.

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

FileDialogWrapper* Exporter::mDialog
private

Definition at line 190 of file Export.h.

Referenced by DisplayOptions(), and GetFilename().

wxString Exporter::mFileDialogTitle
private

Definition at line 191 of file Export.h.

Referenced by GetFilename(), and SetFileDialogTitle().

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

Definition at line 202 of file Export.h.

Referenced by GetFilename(), and ProcessFromTimerRecording().

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

Definition at line 189 of file Export.h.

Referenced by CheckFilename(), and GetFilename().

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

Definition at line 193 of file Export.h.

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

unsigned Exporter::mNumLeft
private

Definition at line 206 of file Export.h.

Referenced by CheckMix(), and ExamineTracks().

unsigned Exporter::mNumMono
private

Definition at line 208 of file Export.h.

Referenced by CheckMix(), and ExamineTracks().

unsigned Exporter::mNumRight
private

Definition at line 207 of file Export.h.

Referenced by CheckMix(), and ExamineTracks().

int Exporter::mNumSelected
private

Definition at line 205 of file Export.h.

Referenced by ExamineTracks().

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

Definition at line 210 of file Export.h.

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

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

Definition at line 200 of file Export.h.

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

double Exporter::mT1
private

Definition at line 201 of file Export.h.

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


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