Audacity  2.2.2
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
BatchCommands Class Referencefinal

Maintains the chain of commands used in batch processing. See also BatchCommandDialog and BatchProcessDialog. More...

#include <BatchCommands.h>

Public Types

using CommandName = std::tuple< wxString, wxString, wxString >
 
using CommandNameVector = std::vector< CommandName >
 

Public Member Functions

 BatchCommands ()
 
bool ApplyChain (const wxString &filename=wxT(""))
 
bool ApplyCommand (const wxString &command, const wxString &params, CommandContext const *pContext=NULL)
 
bool ApplyCommandInBatchMode (const wxString &command, const wxString &params)
 
bool ApplySpecialCommand (int iCommand, const wxString &command, const wxString &params)
 
bool ApplyEffectCommand (const PluginID &ID, const wxString &command, const wxString &params, const CommandContext &Context)
 
bool ReportAndSkip (const wxString &command, const wxString &params)
 
void AbortBatch ()
 
wxString BuildCleanFileName (const wxString &fileName, const wxString &extension)
 
bool WriteMp3File (const wxString &Name, int bitrate)
 
double GetEndTime ()
 
bool IsMono ()
 
void ResetChain ()
 
bool ReadChain (const wxString &chain)
 
bool WriteChain (const wxString &chain)
 
bool AddChain (const wxString &chain)
 
bool DeleteChain (const wxString &name)
 
bool RenameChain (const wxString &oldchain, const wxString &newchain)
 
void AddToChain (const wxString &command, int before=-1)
 
void AddToChain (const wxString &command, const wxString &params, int before=-1)
 
void DeleteFromChain (int index)
 
wxString GetCommand (int index)
 
wxString GetParams (int index)
 
int GetCount ()
 
wxString GetMessage ()
 
void AddToMessage (const wxString &msgIn)
 
void SetWavToMp3Chain ()
 
bool IsFixed (const wxString &name)
 
void RestoreChain (const wxString &name)
 
void Split (const wxString &str, wxString &command, wxString &param)
 
wxString Join (const wxString &command, const wxString &param)
 

Static Public Member Functions

static wxArrayString GetNames ()
 
static CommandNameVector GetAllCommands ()
 
static wxString GetCurrentParamsFor (const wxString &command)
 
static wxString PromptForParamsFor (const wxString &command, const wxString &params, wxWindow *parent)
 
static wxString PromptForPresetFor (const wxString &command, const wxString &params, wxWindow *parent)
 

Public Attributes

wxArrayString mCommandChain
 
wxArrayString mParamsChain
 
bool mAbort
 
wxString mMessage
 
Exporter mExporter
 
wxString mFileName
 

Detailed Description

Maintains the chain of commands used in batch processing. See also BatchCommandDialog and BatchProcessDialog.

Definition at line 24 of file BatchCommands.h.

Member Typedef Documentation

using BatchCommands::CommandName = std::tuple<wxString, wxString, wxString>

Definition at line 47 of file BatchCommands.h.

Definition at line 48 of file BatchCommands.h.

Constructor & Destructor Documentation

BatchCommands::BatchCommands ( )

Definition at line 92 of file BatchCommands.cpp.

References AddChain(), GetNames(), mMessage, MP3Conversion, names(), ResetChain(), RestoreChain(), and WriteChain().

93 {
94  mMessage = "";
95  ResetChain();
96 
97  wxArrayString names = GetNames();
98 
99  if (names.Index(MP3Conversion) == wxNOT_FOUND) {
103  }
104 }
static wxArrayString names()
Definition: Tags.cpp:697
static const wxString MP3Conversion
bool WriteChain(const wxString &chain)
wxString mMessage
Definition: BatchCommands.h:86
static wxArrayString GetNames()
void RestoreChain(const wxString &name)
bool AddChain(const wxString &chain)

Member Function Documentation

void BatchCommands::AbortBatch ( )

Definition at line 786 of file BatchCommands.cpp.

References mAbort.

787 {
788  mAbort = true;
789 }
bool BatchCommands::AddChain ( const wxString &  chain)

Definition at line 214 of file BatchCommands.cpp.

References FileNames::ChainDir(), and name.

Referenced by BatchCommands(), and EditChainsDialog::OnAdd().

215 {
216  // Build the filename
217  wxFileName name(FileNames::ChainDir(), chain, wxT("txt"));
218 
219  // Set the file name
220  wxTextFile tf(name.GetFullPath());
221 
222  // Create it..Create will display errors
223  return tf.Create();
224 }
static wxString ChainDir()
Definition: FileNames.cpp:193
const wxChar * name
Definition: Distortion.cpp:94
void BatchCommands::AddToChain ( const wxString &  command,
int  before = -1 
)

Definition at line 791 of file BatchCommands.cpp.

References GetCurrentParamsFor().

Referenced by EditChainsDialog::InsertCommandAt(), EditChainsDialog::OnDown(), EditChainsDialog::OnEditCommandParams(), EditChainsDialog::OnUp(), and SetWavToMp3Chain().

792 {
793  AddToChain(command, GetCurrentParamsFor(command), before);
794 }
void AddToChain(const wxString &command, int before=-1)
static wxString GetCurrentParamsFor(const wxString &command)
void BatchCommands::AddToChain ( const wxString &  command,
const wxString &  params,
int  before = -1 
)

Definition at line 796 of file BatchCommands.cpp.

References mCommandChain, and mParamsChain.

797 {
798  if (before == -1) {
799  before = (int)mCommandChain.GetCount();
800  }
801 
802  mCommandChain.Insert(command, before);
803  mParamsChain.Insert(params, before);
804 }
wxArrayString mParamsChain
Definition: BatchCommands.h:84
wxArrayString mCommandChain
Definition: BatchCommands.h:83
EffectDistortion::Params params
Definition: Distortion.cpp:95
void BatchCommands::AddToMessage ( const wxString &  msgIn)
inline

Definition at line 72 of file BatchCommands.h.

References mMessage.

72 { mMessage += msgIn;};
wxString mMessage
Definition: BatchCommands.h:86
bool BatchCommands::ApplyChain ( const wxString &  filename = wxT(""))

Definition at line 734 of file BatchCommands.cpp.

References _(), ApplyCommandInBatchMode(), GetActiveProject(), gPrefs, mAbort, mCommandChain, mFileName, mParamsChain, name, AudacityProject::PushState(), and AudacityProject::RollbackState().

Referenced by BatchEvalCommand::Apply(), BatchProcessDialog::OnApplyToFiles(), and BatchProcessDialog::OnApplyToProject().

735 {
736  mFileName = filename;
737 
739  bool res = false;
740  auto cleanup = finally( [&] {
741  if (!res) {
742  if(proj) {
743  // Chain failed or was cancelled; revert to the previous state
744  proj->RollbackState();
745  }
746  }
747  } );
748 
749  mAbort = false;
750 
751  size_t i = 0;
752  for (; i < mCommandChain.GetCount(); i++) {
754  break;
755  }
756 
757  res = (i == mCommandChain.GetCount());
758  if (!res)
759  return false;
760 
761  mFileName.Empty();
762 
763  // Chain was successfully applied; save the NEW project state
764  wxString longDesc, shortDesc;
765  wxString name = gPrefs->Read(wxT("/Batch/ActiveChain"), wxEmptyString);
766  if (name.IsEmpty())
767  {
768  /* i18n-hint: active verb in past tense */
769  longDesc = _("Applied batch chain");
770  shortDesc = _("Apply chain");
771  }
772  else
773  {
774  /* i18n-hint: active verb in past tense */
775  longDesc = wxString::Format(_("Applied batch chain '%s'"), name);
776  shortDesc = wxString::Format(_("Apply '%s'"), name);
777  }
778 
779  if (!proj)
780  return false;
781  proj->PushState(longDesc, shortDesc);
782  return true;
783 }
wxArrayString mParamsChain
Definition: BatchCommands.h:84
wxString mFileName
Definition: BatchCommands.h:89
bool ApplyCommandInBatchMode(const wxString &command, const wxString &params)
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
void RollbackState()
Definition: Project.cpp:4543
wxArrayString mCommandChain
Definition: BatchCommands.h:83
void PushState(const wxString &desc, const wxString &shortDesc)
Definition: Project.cpp:4503
const wxChar * name
Definition: Distortion.cpp:94
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
_("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) void TrackMenuTable::OnSetName(wxCommandEvent &)
bool BatchCommands::ApplyCommand ( const wxString &  command,
const wxString &  params,
CommandContext const *  pContext = NULL 
)

Definition at line 672 of file BatchCommands.cpp.

References _(), AlwaysEnabledFlag, ApplyEffectCommand(), ApplySpecialCommand(), AudacityMessageBox(), EffectManager::Get(), GetActiveProject(), AudacityProject::GetCommandManager(), EffectManager::GetEffectByIdentifier(), CommandManager::HandleTextualCommand(), SpecialCommands, and CommandContext::Status().

Referenced by BatchEvalCommand::Apply(), and ApplyCommandInBatchMode().

673 {
674 
675  unsigned int i;
676  // Test for a special command.
677  // CLEANSPEECH remnant
678  for( i = 0; i < sizeof(SpecialCommands)/sizeof(*SpecialCommands); ++i ) {
679  if( command.IsSameAs( SpecialCommands[i].second, false) )
680  return ApplySpecialCommand( i, command, params );
681  }
682  // end CLEANSPEECH remnant
683 
684  // Test for an effect.
685  const PluginID & ID = EffectManager::Get().GetEffectByIdentifier( command );
686  if (!ID.empty())
687  {
688  if( pContext )
689  return ApplyEffectCommand(ID, command, params, *pContext);
690  const CommandContext context( *GetActiveProject() );
691  return ApplyEffectCommand(ID, command, params, context);
692  }
693 
694  AudacityProject *project = GetActiveProject();
695  CommandManager * pManager = project->GetCommandManager();
696  if( pContext ){
697  if( pManager->HandleTextualCommand( command, *pContext, AlwaysEnabledFlag, AlwaysEnabledFlag ) )
698  return true;
699  pContext->Status( wxString::Format(
700  _("Your batch command of %s was not recognized."), command ));
701  return false;
702  }
703  else
704  {
705  const CommandContext context( *GetActiveProject() );
706  if( pManager->HandleTextualCommand( command, context, AlwaysEnabledFlag, AlwaysEnabledFlag ) )
707  return true;
708  }
709 
711  wxString::Format(
712  _("Your batch command of %s was not recognized."), command ));
713 
714  return false;
715 }
static const std::pair< const wxChar *, const wxChar * > SpecialCommands[]
const PluginID & GetEffectByIdentifier(const wxString &strTarget)
bool HandleTextualCommand(const wxString &Str, const CommandContext &context, CommandFlag flags, CommandMask mask)
wxString PluginID
Definition: Types.h:208
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
CommandContext provides addiitonal information to an 'Apply()' command. It provides the project...
CommandManager * GetCommandManager()
Definition: Project.h:344
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
bool ApplySpecialCommand(int iCommand, const wxString &command, const wxString &params)
CommandManager implements a system for organizing all user-callable commands.
bool ApplyEffectCommand(const PluginID &ID, const wxString &command, const wxString &params, const CommandContext &Context)
static EffectManager & Get()
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
_("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) void TrackMenuTable::OnSetName(wxCommandEvent &)
EffectDistortion::Params params
Definition: Distortion.cpp:95
bool BatchCommands::ApplyCommandInBatchMode ( const wxString &  command,
const wxString &  params 
)

Definition at line 717 of file BatchCommands.cpp.

References ApplyCommand(), GetActiveProject(), AudacityProject::GetShowId3Dialog(), and AudacityProject::SetShowId3Dialog().

Referenced by ApplyChain().

718 {
719  AudacityProject *project = GetActiveProject();
720 
721  // enter batch mode...
722  bool prevShowMode = project->GetShowId3Dialog();
723  auto cleanup = finally( [&] {
724  // exit batch mode...
725  project->SetShowId3Dialog(prevShowMode);
726  } );
727 
728  return ApplyCommand( command, params );
729 }
void SetShowId3Dialog(bool flag)
Definition: Project.h:315
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
bool GetShowId3Dialog()
Definition: Project.h:314
bool ApplyCommand(const wxString &command, const wxString &params, CommandContext const *pContext=NULL)
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
EffectDistortion::Params params
Definition: Distortion.cpp:95
bool BatchCommands::ApplyEffectCommand ( const PluginID ID,
const wxString &  command,
const wxString &  params,
const CommandContext Context 
)

Definition at line 628 of file BatchCommands.cpp.

References AudacityProject::DoAudacityCommand(), AudacityProject::DoEffect(), EffectManager::Get(), PluginManager::Get(), GetActiveProject(), PluginManager::GetPlugin(), PluginDescriptor::GetPluginType(), AudacityProject::OnEffectFlags::kConfigured, AudacityProject::OnEffectFlags::kDontRepeatLast, AudacityProject::OnEffectFlags::kSkipState, PluginTypeAudacityCommand, ReportAndSkip(), AudacityProject::SelectAllIfNone(), and EffectManager::SetBatchProcessing().

Referenced by ApplyCommand().

629 {
630  //Possibly end processing here, if in batch-debug
631  if( ReportAndSkip(command, params))
632  return true;
633 
634  const PluginDescriptor *plug = PluginManager::Get().GetPlugin(ID);
635  if (!plug)
636  return false;
637 
638  AudacityProject *project = GetActiveProject();
639 
640  // FIXME: for later versions may want to not select-all in batch mode.
641  // IF nothing selected, THEN select everything
642  // (most effects require that you have something selected).
644  project->SelectAllIfNone();
645 
646  bool res = false;
647 
648  auto cleanup = EffectManager::Get().SetBatchProcessing(ID);
649 
650  // transfer the parameters to the effect...
651  if (EffectManager::Get().SetEffectParameters(ID, params))
652  {
654  // and apply the effect...
655  res = project->DoAudacityCommand(ID,
656  Context,
660  else
661  // and apply the effect...
662  res = project->DoEffect(ID,
663  Context,
667  }
668 
669  return res;
670 }
static const int kConfigured
Definition: Project.h:485
static const int kDontRepeatLast
Definition: Project.h:489
bool DoEffect(const PluginID &ID, const CommandContext &context, int flags)
Definition: Menus.cpp:4419
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
static const int kSkipState
Definition: Project.h:487
static EffectManager & Get()
bool ReportAndSkip(const wxString &command, const wxString &params)
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
PluginType GetPluginType() const
static PluginManager & Get()
EffectDistortion::Params params
Definition: Distortion.cpp:95
bool DoAudacityCommand(const PluginID &ID, const CommandContext &, int flags)
Definition: Menus.cpp:4373
const PluginDescriptor * GetPlugin(const PluginID &ID)
void SetBatchProcessing(const PluginID &ID, bool start)
void SelectAllIfNone()
Definition: Menus.cpp:2261
bool BatchCommands::ApplySpecialCommand ( int  iCommand,
const wxString &  command,
const wxString &  params 
)

Definition at line 544 of file BatchCommands.cpp.

References _(), AudacityMessageBox(), BuildCleanFileName(), GetActiveProject(), GetEndTime(), AudacityProject::GetFileName(), IsMono(), mExporter, mFileName, Exporter::Process(), ReportAndSkip(), and WriteMp3File().

Referenced by ApplyCommand().

545 {
546  if (ReportAndSkip(command, params))
547  return true;
548 
549  AudacityProject *project = GetActiveProject();
550 
551  unsigned numChannels = 1; //used to switch between mono and stereo export
552  if (IsMono()) {
553  numChannels = 1; //export in mono
554  } else {
555  numChannels = 2; //export in stereo
556  }
557 
558  wxString filename;
559  wxString extension; // required for correct message
560  if (command == wxT("ExportWAV"))
561  extension = wxT(".wav");
562  else if (command == wxT("ExportOgg"))
563  extension = wxT(".ogg");
564  else if (command == wxT("ExportFLAC"))
565  extension = wxT(".flac");
566  else extension = wxT(".mp3");
567 
568  if (mFileName.IsEmpty()) {
569  filename = BuildCleanFileName(project->GetFileName(), extension);
570  }
571  else {
572  filename = BuildCleanFileName(mFileName, extension);
573  }
574 
575  // We have a command index, but we don't use it!
576  // TODO: Make this special-batch-command code use the menu item code....
577  // FIXME: TRAP_ERR No error reporting on write file failure in batch mode.
578  if (command == wxT("NoAction")) {
579  return true;
580  } else if (!mFileName.IsEmpty() && command == wxT("Import")) {
581  // historically this was in use, now ignored if there
582  return true;
583  } else if (command == wxT("ExportMP3_56k_before")) {
584  filename.Replace(wxT("cleaned/"), wxT("cleaned/MasterBefore_"), false);
585  return WriteMp3File(filename, 56);
586  } else if (command == wxT("ExportMP3_56k_after")) {
587  filename.Replace(wxT("cleaned/"), wxT("cleaned/MasterAfter_"), false);
588  return WriteMp3File(filename, 56);
589  } else if (command == wxT("ExportMP3")) {
590  return WriteMp3File(filename, 0); // 0 bitrate means use default/current
591  } else if (command == wxT("ExportWAV")) {
592  filename.Replace(wxT(".mp3"), wxT(".wav"), false);
593  double endTime = GetEndTime();
594  if (endTime <= 0.0f) {
595  return false;
596  }
597  return mExporter.Process(project, numChannels, wxT("WAV"), filename, false, 0.0, endTime);
598  } else if (command == wxT("ExportOgg")) {
599 #ifdef USE_LIBVORBIS
600  filename.Replace(wxT(".mp3"), wxT(".ogg"), false);
601  double endTime = GetEndTime();
602  if (endTime <= 0.0f) {
603  return false;
604  }
605  return mExporter.Process(project, numChannels, wxT("OGG"), filename, false, 0.0, endTime);
606 #else
607  AudacityMessageBox(_("Ogg Vorbis support is not included in this build of Audacity"));
608  return false;
609 #endif
610  } else if (command == wxT("ExportFLAC")) {
611 #ifdef USE_LIBFLAC
612  filename.Replace(wxT(".mp3"), wxT(".flac"), false);
613  double endTime = GetEndTime();
614  if (endTime <= 0.0f) {
615  return false;
616  }
617  return mExporter.Process(project, numChannels, wxT("FLAC"), filename, false, 0.0, endTime);
618 #else
619  AudacityMessageBox(_("FLAC support is not included in this build of Audacity"));
620  return false;
621 #endif
622  }
623  AudacityMessageBox(wxString::Format(_("Command %s not implemented yet"),command));
624  return false;
625 }
Exporter mExporter
Definition: BatchCommands.h:88
bool Process(AudacityProject *project, bool selectedOnly, double t0, double t1)
Definition: Export.cpp:338
double GetEndTime()
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
wxString mFileName
Definition: BatchCommands.h:89
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
wxString BuildCleanFileName(const wxString &fileName, const wxString &extension)
bool ReportAndSkip(const wxString &command, const wxString &params)
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
_("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) void TrackMenuTable::OnSetName(wxCommandEvent &)
bool WriteMp3File(const wxString &Name, int bitrate)
EffectDistortion::Params params
Definition: Distortion.cpp:95
const wxString & GetFileName()
Definition: Project.h:300
wxString BatchCommands::BuildCleanFileName ( const wxString &  fileName,
const wxString &  extension 
)

Definition at line 447 of file BatchCommands.cpp.

References _(), AudacityApp::AddFileToHistory(), AudacityMessageBox(), FileNames::Export, FileNames::FindDefaultPath(), and wxGetApp().

Referenced by ApplySpecialCommand().

448 {
449  const wxFileName newFileName{ fileName };
450  wxString justName = newFileName.GetName();
451  wxString pathName = newFileName.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
452  const auto cleanedString = _("cleaned");
453 
454  if (justName.empty()) {
455  wxDateTime now = wxDateTime::Now();
456  int year = now.GetYear();
457  wxDateTime::Month month = now.GetMonth();
458  wxString monthName = now.GetMonthName(month);
459  int dom = now.GetDay();
460  int hour = now.GetHour();
461  int minute = now.GetMinute();
462  int second = now.GetSecond();
463  justName = wxString::Format(wxT("%d-%s-%02d-%02d-%02d-%02d"),
464  year, monthName, dom, hour, minute, second);
465 
466 // SetName(cleanedFileName);
467 // bool isStereo;
468 // double endTime = project->mTracks->GetEndTime();
469 // double startTime = 0.0;
470  //OnSelectAll();
472  ::AudacityMessageBox(wxString::Format(_("Export recording to %s\n/%s/%s%s"),
473  pathName, cleanedString, justName, extension),
474  _("Export recording"),
475  wxOK | wxCENTRE);
476  pathName += wxFileName::GetPathSeparator();
477  }
478  wxString cleanedName = pathName;
479  cleanedName += cleanedString;
480  bool flag = ::wxFileName::FileExists(cleanedName);
481  if (flag == true) {
482  ::AudacityMessageBox(_("Cannot create directory 'cleaned'. \nFile already exists that is not a directory"));
483  return wxString{};
484  }
485  ::wxFileName::Mkdir(cleanedName, 0777, wxPATH_MKDIR_FULL); // make sure it exists
486 
487  cleanedName += wxFileName::GetPathSeparator();
488  cleanedName += justName;
489  cleanedName += extension;
490  wxGetApp().AddFileToHistory(cleanedName);
491 
492  return cleanedName;
493 }
static wxString FindDefaultPath(Operation op)
Definition: FileNames.cpp:384
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
void AddFileToHistory(const wxString &name)
_("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) void TrackMenuTable::OnSetName(wxCommandEvent &)
AudacityApp & wxGetApp()
bool BatchCommands::DeleteChain ( const wxString &  name)

Definition at line 226 of file BatchCommands.cpp.

References FileNames::ChainDir(), and name.

Referenced by EditChainsDialog::OnRemove().

227 {
228  // Build the filename
229  wxFileName name(FileNames::ChainDir(), chain, wxT("txt"));
230 
231  // Delete it...wxRemoveFile will display errors
232  return wxRemoveFile(name.GetFullPath());
233 }
static wxString ChainDir()
Definition: FileNames.cpp:193
const wxChar * name
Definition: Distortion.cpp:94
void BatchCommands::DeleteFromChain ( int  index)

Definition at line 806 of file BatchCommands.cpp.

References mCommandChain, and mParamsChain.

Referenced by EditChainsDialog::OnDelete(), EditChainsDialog::OnDown(), EditChainsDialog::OnEditCommandParams(), and EditChainsDialog::OnUp().

807 {
808  if (index < 0 || index >= (int)mCommandChain.GetCount()) {
809  return;
810  }
811 
812  mCommandChain.RemoveAt(index);
813  mParamsChain.RemoveAt(index);
814 }
wxArrayString mParamsChain
Definition: BatchCommands.h:84
wxArrayString mCommandChain
Definition: BatchCommands.h:83
auto BatchCommands::GetAllCommands ( )
static

Definition at line 254 of file BatchCommands.cpp.

References _(), EffectManager::Get(), PluginManager::Get(), GetActiveProject(), CommandManager::GetAllCommandLabels(), CommandManager::GetAllCommandNames(), EffectManager::GetCommandIdentifier(), AudacityProject::GetCommandManager(), PluginManager::GetFirstPlugin(), PluginDescriptor::GetID(), PluginManager::GetNextPlugin(), PluginDescriptor::GetPluginType(), PluginDescriptor::GetUntranslatedName(), label, PluginTypeAudacityCommand, PluginTypeEffect, and SpecialCommands.

Referenced by EditChainsDialog::Populate(), and BatchCommandDialog::PopulateCommandList().

255 {
256  CommandNameVector commands;
257 
258  AudacityProject *project = GetActiveProject();
259  if (!project)
260  return commands;
261 
262  // CLEANSPEECH remnant
263  for( const auto &command : SpecialCommands )
264  commands.push_back(
265  CommandName( command.first, command.second, _("Special Command") )
266  );
267 
268  // end CLEANSPEECH remnant
269 
272  {
274  while (plug)
275  {
276  auto command = em.GetCommandIdentifier(plug->GetID());
277  if (!command.IsEmpty())
278  commands.push_back(
279  CommandName(
280  plug->GetUntranslatedName(), // plug->GetTranslatedName(),
281  command,
282  plug->GetPluginType() == PluginTypeEffect ?
283  _("Effect") : _("Menu Command (With Parameters)")
284  )
285  );
287  }
288  }
289 
290  CommandManager * mManager = project->GetCommandManager();
291  wxArrayString mLabels;
292  wxArrayString mNames;
293  mLabels.Clear();
294  mNames.Clear();
295  mManager->GetAllCommandLabels(mLabels, false);
296  mManager->GetAllCommandNames(mNames, false);
297  for(size_t i=0; i<mNames.GetCount(); i++) {
298  wxString label = mLabels[i];
299  if( !label.Contains( "..." ) ){
300  label.Replace( "&", "" );
301  wxString squashed = label;
302  squashed.Replace( " ", "" );
303 
304  // We'll disambiguate if the squashed name is short and shorter than the internal name.
305  // Otherwise not.
306  // This means we won't have repetitive items like "Cut (Cut)"
307  // But we will show important disambiguation like "All (SelectAll)" and "By Date (SortByDate)"
308  // Disambiguation is no longer essential as the details box will show it.
309  if( squashed.Length() < wxMin( 18, mNames[i].Length()) )
310  label = label + " (" + mNames[i] + ")";
311 
312  commands.push_back(
313  CommandName(
314  label, // User readable name
315  mNames[i], // Internal name.
316  _("Menu Command (No Parameters)")
317  )
318  );
319  }
320  }
321 
322  // Sort commands by their user-visible names.
323  // PRL: What should happen if first members of pairs are not unique?
324  // Sort stably?
325  std::sort(
326  commands.begin(), commands.end(),
327  [](const CommandName &a, const CommandName &b)
328  { return std::get<0>(a) < std::get<0>(b); }
329  );
330 
331  // JKC: Gave up on trying to use std::unique on this.
332  CommandNameVector uniqueCommands;
333  unsigned size = commands.size();
334  wxString oldName = "";
335  for( unsigned i = 0; i < size; ++i )
336  {
337  if( std::get<0>( commands[i] ) != oldName )
338  uniqueCommands.push_back( commands[i] );
339  oldName = std::get<0>( commands[i] );
340  }
341  return uniqueCommands;
342 }
static const std::pair< const wxChar *, const wxChar * > SpecialCommands[]
const PluginDescriptor * GetFirstPlugin(int type)
std::tuple< wxString, wxString, wxString > CommandName
Definition: BatchCommands.h:47
wxString label
Definition: Tags.cpp:727
std::vector< CommandName > CommandNameVector
Definition: BatchCommands.h:48
const PluginDescriptor * GetNextPlugin(int type)
CommandManager * GetCommandManager()
Definition: Project.h:344
void GetAllCommandLabels(wxArrayString &labels, bool includeMultis)
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
wxString GetUntranslatedName() const
CommandManager implements a system for organizing all user-callable commands.
EffectManager is the class that handles effects and effect categories.
Definition: EffectManager.h:47
static EffectManager & Get()
PluginManager maintains a list of all plug ins. That covers modules, effects, generators, analysis-effects, commands. It also has functions for shared and private configs - which need to move out.
const wxString & GetID() const
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
wxString GetCommandIdentifier(const PluginID &ID)
_("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) void TrackMenuTable::OnSetName(wxCommandEvent &)
PluginType GetPluginType() const
static PluginManager & Get()
void GetAllCommandNames(wxArrayString &names, bool includeMultis)
wxString BatchCommands::GetCommand ( int  index)

Definition at line 106 of file BatchCommands.cpp.

References mCommandChain.

Referenced by EditChainsDialog::OnDown(), EditChainsDialog::OnEditCommandParams(), EditChainsDialog::OnUp(), and EditChainsDialog::PopulateList().

107 {
108  if (index < 0 || index >= (int)mCommandChain.GetCount()) {
109  return wxT("");
110  }
111 
112  return mCommandChain[index];
113 }
wxArrayString mCommandChain
Definition: BatchCommands.h:83
int BatchCommands::GetCount ( )

Definition at line 124 of file BatchCommands.cpp.

References mCommandChain.

Referenced by EditChainsDialog::PopulateList().

125 {
126  return (int)mCommandChain.GetCount();
127 }
wxArrayString mCommandChain
Definition: BatchCommands.h:83
wxString BatchCommands::GetCurrentParamsFor ( const wxString &  command)
static

Definition at line 344 of file BatchCommands.cpp.

References EffectManager::Get(), EffectManager::GetEffectByIdentifier(), and EffectManager::GetEffectParameters().

Referenced by AddToChain(), and BatchCommandDialog::OnItemSelected().

345 {
346  const PluginID & ID = EffectManager::Get().GetEffectByIdentifier(command);
347  if (ID.empty())
348  {
349  return wxEmptyString; // effect not found.
350  }
351 
353 }
const PluginID & GetEffectByIdentifier(const wxString &strTarget)
wxString PluginID
Definition: Types.h:208
static EffectManager & Get()
wxString GetEffectParameters(const PluginID &ID)
double BatchCommands::GetEndTime ( )

Definition at line 398 of file BatchCommands.cpp.

References GetActiveProject(), TrackList::GetEndTime(), and AudacityProject::GetTracks().

Referenced by ApplySpecialCommand(), and WriteMp3File().

399 {
400  AudacityProject *project = GetActiveProject();
401  if( project == NULL )
402  {
403  //AudacityMessageBox( _("No project to process!") );
404  return -1.0;
405  }
406  TrackList * tracks = project->GetTracks();
407  if( tracks == NULL )
408  {
409  //AudacityMessageBox( _("No tracks to process!") );
410  return -1.0;
411  }
412 
413  double endTime = tracks->GetEndTime();
414  return endTime;
415 }
A list of TrackListNode items.
Definition: Track.h:618
double GetEndTime() const
Definition: Track.cpp:1414
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
TrackList * GetTracks()
Definition: Project.h:190
wxString BatchCommands::GetMessage ( )
inline

Definition at line 71 of file BatchCommands.h.

References mMessage.

Referenced by BatchEvalCommand::Apply().

71 { return mMessage;};
wxString mMessage
Definition: BatchCommands.h:86
wxArrayString BatchCommands::GetNames ( )
static

Definition at line 845 of file BatchCommands.cpp.

References FileNames::ChainDir(), and names().

Referenced by BatchCommands(), EditChainsDialog::PopulateChains(), and BatchProcessDialog::PopulateOrExchange().

846 {
847  wxArrayString names;
848  wxArrayString files;
849  wxDir::GetAllFiles(FileNames::ChainDir(), &files, wxT("*.txt"), wxDIR_FILES);
850  size_t i;
851 
852  wxFileName ff;
853  for (i = 0; i < files.GetCount(); i++) {
854  ff = (files[i]);
855  names.Add(ff.GetName());
856  }
857 
858  return names;
859 }
static wxArrayString names()
Definition: Tags.cpp:697
static wxString ChainDir()
Definition: FileNames.cpp:193
wxString BatchCommands::GetParams ( int  index)

Definition at line 115 of file BatchCommands.cpp.

References mParamsChain.

Referenced by EditChainsDialog::OnDown(), EditChainsDialog::OnEditCommandParams(), EditChainsDialog::OnUp(), and EditChainsDialog::PopulateList().

116 {
117  if (index < 0 || index >= (int)mParamsChain.GetCount()) {
118  return wxT("");
119  }
120 
121  return mParamsChain[index];
122 }
wxArrayString mParamsChain
Definition: BatchCommands.h:84
bool BatchCommands::IsFixed ( const wxString &  name)

Definition at line 861 of file BatchCommands.cpp.

References MP3Conversion.

Referenced by EditChainsDialog::OnChainsBeginEdit(), and EditChainsDialog::OnChainSelected().

862 {
863  if (name == MP3Conversion)
864  return true;
865  return false;
866 }
static const wxString MP3Conversion
const wxChar * name
Definition: Distortion.cpp:94
bool BatchCommands::IsMono ( )

Definition at line 417 of file BatchCommands.cpp.

References TrackListIterator::First(), GetActiveProject(), Track::GetLinked(), AudacityProject::GetTracks(), and TrackListIterator::Next().

Referenced by ApplySpecialCommand(), and WriteMp3File().

418 {
419  AudacityProject *project = GetActiveProject();
420  if( project == NULL )
421  {
422  //AudacityMessageBox( _("No project and no Audio to process!") );
423  return false;
424  }
425 
426  TrackList * tracks = project->GetTracks();
427  if( tracks == NULL )
428  {
429  //AudacityMessageBox( _("No tracks to process!") );
430  return false;
431  }
432 
433  TrackListIterator iter(tracks);
434  Track *t = iter.First();
435  bool mono = true;
436  while (t) {
437  if (t->GetLinked()) {
438  mono = false;
439  break;
440  }
441  t = iter.Next();
442  }
443 
444  return mono;
445 }
A list of TrackListNode items.
Definition: Track.h:618
bool GetLinked() const
Definition: Track.h:278
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:101
An iterator for a TrackList.
Definition: Track.h:401
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
TrackList * GetTracks()
Definition: Project.h:190
wxString BatchCommands::Join ( const wxString &  command,
const wxString &  param 
)

Definition at line 899 of file BatchCommands.cpp.

900 {
901  return command + wxT(": ") + param;
902 }
wxString BatchCommands::PromptForParamsFor ( const wxString &  command,
const wxString &  params,
wxWindow *  parent 
)
static

Definition at line 355 of file BatchCommands.cpp.

References EffectManager::Get(), EffectManager::GetEffectByIdentifier(), EffectManager::GetEffectParameters(), params, and EffectManager::SetBatchProcessing().

Referenced by EditChainsDialog::OnEditCommandParams(), and BatchCommandDialog::OnEditParams().

356 {
357  const PluginID & ID = EffectManager::Get().GetEffectByIdentifier(command);
358  if (ID.empty())
359  {
360  return wxEmptyString; // effect not found
361  }
362 
363  wxString res = params;
364 
365  auto cleanup = EffectManager::Get().SetBatchProcessing(ID);
366 
367  if (EffectManager::Get().SetEffectParameters(ID, params))
368  {
369  if (EffectManager::Get().PromptUser(ID, parent))
370  {
372  }
373  }
374 
375  return res;
376 }
const PluginID & GetEffectByIdentifier(const wxString &strTarget)
wxString PluginID
Definition: Types.h:208
static EffectManager & Get()
wxString GetEffectParameters(const PluginID &ID)
EffectDistortion::Params params
Definition: Distortion.cpp:95
void SetBatchProcessing(const PluginID &ID, bool start)
wxString BatchCommands::PromptForPresetFor ( const wxString &  command,
const wxString &  params,
wxWindow *  parent 
)
static

Definition at line 378 of file BatchCommands.cpp.

References EffectManager::Get(), EffectManager::GetEffectByIdentifier(), EffectManager::GetPreset(), and params.

Referenced by BatchCommandDialog::OnUsePreset().

379 {
380  const PluginID & ID = EffectManager::Get().GetEffectByIdentifier(command);
381  if (ID.empty())
382  {
383  return wxEmptyString; // effect not found.
384  }
385 
386  wxString preset = EffectManager::Get().GetPreset(ID, params, parent);
387 
388  // Preset will be empty if the user cancelled the dialog, so return the original
389  // parameter value.
390  if (preset.IsEmpty())
391  {
392  return params;
393  }
394 
395  return preset;
396 }
const PluginID & GetEffectByIdentifier(const wxString &strTarget)
wxString PluginID
Definition: Types.h:208
static EffectManager & Get()
wxString GetPreset(const PluginID &ID, const wxString &params, wxWindow *parent)
EffectDistortion::Params params
Definition: Distortion.cpp:95
bool BatchCommands::ReadChain ( const wxString &  chain)

Definition at line 129 of file BatchCommands.cpp.

References FileNames::ChainDir(), mCommandChain, mParamsChain, name, and ResetChain().

Referenced by BatchEvalCommand::Apply(), BatchProcessDialog::OnApplyToFiles(), BatchProcessDialog::OnApplyToProject(), and EditChainsDialog::OnChainSelected().

130 {
131  // Clear any previous chain
132  ResetChain();
133 
134  // Build the filename
135  wxFileName name(FileNames::ChainDir(), chain, wxT("txt"));
136 
137  // Set the file name
138  wxTextFile tf(name.GetFullPath());
139 
140  // Open and check
141  tf.Open();
142  if (!tf.IsOpened()) {
143  // wxTextFile will display any errors
144  return false;
145  }
146 
147  // Load commands from the file
148  int lines = tf.GetLineCount();
149  if (lines > 0) {
150  for (int i = 0; i < lines; i++) {
151 
152  // Find the command name terminator...ingore line if not found
153  int splitAt = tf[i].Find(wxT(':'));
154  if (splitAt < 0) {
155  continue;
156  }
157 
158  // Parse and clean
159  wxString cmd = tf[i].Left(splitAt).Strip(wxString::both);
160  wxString parm = tf[i].Mid(splitAt + 1).Strip(wxString::trailing);
161 
162  // Add to lists
163  mCommandChain.Add(cmd);
164  mParamsChain.Add(parm);
165  }
166  }
167 
168  // Done with the file
169  tf.Close();
170 
171  return true;
172 }
wxArrayString mParamsChain
Definition: BatchCommands.h:84
static wxString ChainDir()
Definition: FileNames.cpp:193
wxArrayString mCommandChain
Definition: BatchCommands.h:83
const wxChar * name
Definition: Distortion.cpp:94
bool BatchCommands::RenameChain ( const wxString &  oldchain,
const wxString &  newchain 
)

Definition at line 235 of file BatchCommands.cpp.

References FileNames::ChainDir().

Referenced by EditChainsDialog::OnChainsEndEdit().

236 {
237  // Build the filenames
238  wxFileName oname(FileNames::ChainDir(), oldchain, wxT("txt"));
239  wxFileName nname(FileNames::ChainDir(), newchain, wxT("txt"));
240 
241  // Rename it...wxRenameFile will display errors
242  return wxRenameFile(oname.GetFullPath(), nname.GetFullPath());
243 }
static wxString ChainDir()
Definition: FileNames.cpp:193
bool BatchCommands::ReportAndSkip ( const wxString &  command,
const wxString &  params 
)

Definition at line 824 of file BatchCommands.cpp.

References _(), AudacityMessageBox(), and gPrefs.

Referenced by ApplyEffectCommand(), and ApplySpecialCommand().

825 {
826  int bDebug;
827  gPrefs->Read(wxT("/Batch/Debug"), &bDebug, false);
828  if( bDebug == 0 )
829  return false;
830 
831  //TODO: Add a cancel button to these, and add the logic so that we can abort.
832  if( params != wxT("") )
833  {
834  AudacityMessageBox( wxString::Format(_("Apply %s with parameter(s)\n\n%s"),command, params),
835  _("Test Mode"));
836  }
837  else
838  {
839  AudacityMessageBox( wxString::Format(_("Apply %s"),command),
840  _("Test Mode"));
841  }
842  return true;
843 }
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
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
_("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) void TrackMenuTable::OnSetName(wxCommandEvent &)
EffectDistortion::Params params
Definition: Distortion.cpp:95
void BatchCommands::ResetChain ( )

Definition at line 816 of file BatchCommands.cpp.

References mCommandChain, and mParamsChain.

Referenced by BatchCommands(), ReadChain(), and SetWavToMp3Chain().

817 {
818  mCommandChain.Clear();
819  mParamsChain.Clear();
820 }
wxArrayString mParamsChain
Definition: BatchCommands.h:84
wxArrayString mCommandChain
Definition: BatchCommands.h:83
void BatchCommands::RestoreChain ( const wxString &  name)

Definition at line 868 of file BatchCommands.cpp.

References MP3Conversion, and SetWavToMp3Chain().

Referenced by BatchCommands(), and EditChainsDialog::OnDefaults().

869 {
870 // TIDY-ME: Effects change their name with localisation.
871 // Commands (at least currently) don't. Messy.
872 
873  if (name == MP3Conversion)
875 }
static const wxString MP3Conversion
void SetWavToMp3Chain()
const wxChar * name
Definition: Distortion.cpp:94
void BatchCommands::SetWavToMp3Chain ( )

Definition at line 245 of file BatchCommands.cpp.

References AddToChain(), and ResetChain().

Referenced by RestoreChain().

246 {
247  ResetChain();
248 
249  AddToChain( wxT("Normalize") );
250  AddToChain( wxT("ExportMP3") );
251 }
void AddToChain(const wxString &command, int before=-1)
void BatchCommands::Split ( const wxString &  str,
wxString &  command,
wxString &  param 
)

Definition at line 877 of file BatchCommands.cpp.

878 {
879  int splitAt;
880 
881  command.Empty();
882  param.Empty();
883 
884  if (str.IsEmpty()) {
885  return;
886  }
887 
888  splitAt = str.Find(wxT(':'));
889  if (splitAt < 0) {
890  return;
891  }
892 
893  command = str.Mid(0, splitAt);
894  param = str.Mid(splitAt + 1);
895 
896  return;
897 }
bool BatchCommands::WriteChain ( const wxString &  chain)

Definition at line 175 of file BatchCommands.cpp.

References FileNames::ChainDir(), mCommandChain, mParamsChain, and name.

Referenced by BatchCommands(), EditChainsDialog::ChangeOK(), and EditChainsDialog::SaveChanges().

176 {
177  // Build the filename
178  wxFileName name(FileNames::ChainDir(), chain, wxT("txt"));
179 
180  // Set the file name
181  wxTextFile tf(name.GetFullPath());
182 
183  // Create the file (Create() doesn't leave the file open)
184  if (!tf.Exists()) {
185  tf.Create();
186  }
187 
188  // Open it
189  tf.Open();
190 
191  if (!tf.IsOpened()) {
192  // wxTextFile will display any errors
193  return false;
194  }
195 
196  // Start with a clean slate
197  tf.Clear();
198 
199  // Copy over the commands
200  int lines = mCommandChain.GetCount();
201  for (int i = 0; i < lines; i++) {
202  tf.AddLine(mCommandChain[i] + wxT(":") + mParamsChain[ i ]);
203  }
204 
205  // Write the chain
206  tf.Write();
207 
208  // Done with the file
209  tf.Close();
210 
211  return true;
212 }
wxArrayString mParamsChain
Definition: BatchCommands.h:84
static wxString ChainDir()
Definition: FileNames.cpp:193
wxArrayString mCommandChain
Definition: BatchCommands.h:83
const wxChar * name
Definition: Distortion.cpp:94
bool BatchCommands::WriteMp3File ( const wxString &  Name,
int  bitrate 
)

Definition at line 496 of file BatchCommands.cpp.

References GetActiveProject(), GetEndTime(), gPrefs, IsMono(), mExporter, and Exporter::Process().

Referenced by ApplySpecialCommand().

497 { //check if current project is mono or stereo
498  unsigned numChannels = 2;
499  if (IsMono()) {
500  numChannels = 1;
501  }
502 
503  double endTime = GetEndTime();
504  if( endTime <= 0.0f )
505  return false;
506  AudacityProject *project = GetActiveProject();
507  if( bitrate <=0 )
508  {
509  // 'No' bitrate given, use the current default.
510  // Use Mp3Stereo to control if export is to a stereo or mono file
511  return mExporter.Process(project, numChannels, wxT("MP3"), Name, false, 0.0, endTime);
512  }
513 
514 
515  bool rc;
516  long prevBitRate = gPrefs->Read(wxT("/FileFormats/MP3Bitrate"), 128);
517  gPrefs->Write(wxT("/FileFormats/MP3Bitrate"), bitrate);
518 
519  auto cleanup = finally( [&] {
520  gPrefs->Write(wxT("/FileFormats/MP3Bitrate"), prevBitRate);
521  gPrefs->Flush();
522  } );
523 
524  // Use Mp3Stereo to control if export is to a stereo or mono file
525  rc = mExporter.Process(project, numChannels, wxT("MP3"), Name, false, 0.0, endTime);
526  return rc;
527 }
Exporter mExporter
Definition: BatchCommands.h:88
bool Process(AudacityProject *project, bool selectedOnly, double t0, double t1)
Definition: Export.cpp:338
double GetEndTime()
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300

Member Data Documentation

bool BatchCommands::mAbort

Definition at line 85 of file BatchCommands.h.

Referenced by AbortBatch(), and ApplyChain().

wxArrayString BatchCommands::mCommandChain
Exporter BatchCommands::mExporter

Definition at line 88 of file BatchCommands.h.

Referenced by ApplySpecialCommand(), and WriteMp3File().

wxString BatchCommands::mFileName

Definition at line 89 of file BatchCommands.h.

Referenced by ApplyChain(), and ApplySpecialCommand().

wxString BatchCommands::mMessage

Definition at line 86 of file BatchCommands.h.

Referenced by AddToMessage(), BatchCommands(), and GetMessage().

wxArrayString BatchCommands::mParamsChain

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