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::pair< 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)
 
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)
 
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 22 of file BatchCommands.h.

Member Typedef Documentation

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

Definition at line 45 of file BatchCommands.h.

Definition at line 46 of file BatchCommands.h.

Constructor & Destructor Documentation

BatchCommands::BatchCommands ( )

Definition at line 86 of file BatchCommands.cpp.

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

87 {
88  mMessage = "";
89  ResetChain();
90 
91  wxArrayString names = GetNames();
92 
93  if (names.Index(MP3Conversion) == wxNOT_FOUND) {
97  }
98 }
static wxArrayString names()
Definition: Tags.cpp:697
static const wxString MP3Conversion
bool WriteChain(const wxString &chain)
wxString mMessage
Definition: BatchCommands.h:84
static wxArrayString GetNames()
void RestoreChain(const wxString &name)
bool AddChain(const wxString &chain)

Member Function Documentation

void BatchCommands::AbortBatch ( )

Definition at line 737 of file BatchCommands.cpp.

References mAbort.

738 {
739  mAbort = true;
740 }
bool BatchCommands::AddChain ( const wxString &  chain)

Definition at line 237 of file BatchCommands.cpp.

References FileNames::ChainDir(), and name.

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

238 {
239  // Build the filename
240  wxFileName name(FileNames::ChainDir(), chain, wxT("txt"));
241 
242  // Set the file name
243  wxTextFile tf(name.GetFullPath());
244 
245  // Create it..Create will display errors
246  return tf.Create();
247 }
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 742 of file BatchCommands.cpp.

References GetCurrentParamsFor().

Referenced by EditChainsDialog::OnCommandActivated(), EditChainsDialog::OnDown(), EditChainsDialog::OnInsert(), EditChainsDialog::OnUp(), and SetWavToMp3Chain().

743 {
744  AddToChain(command, GetCurrentParamsFor(command), before);
745 }
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 747 of file BatchCommands.cpp.

References mCommandChain, and mParamsChain.

748 {
749  if (before == -1) {
750  before = (int)mCommandChain.GetCount();
751  }
752 
753  mCommandChain.Insert(command, before);
754  mParamsChain.Insert(params, before);
755 }
wxArrayString mParamsChain
Definition: BatchCommands.h:82
wxArrayString mCommandChain
Definition: BatchCommands.h:81
EffectDistortion::Params params
Definition: Distortion.cpp:95
void BatchCommands::AddToMessage ( const wxString &  msgIn)
inline

Definition at line 70 of file BatchCommands.h.

References mMessage.

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

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

686 {
687  mFileName = filename;
688 
690  bool res = false;
691  auto cleanup = finally( [&] {
692  if (!res) {
693  if(proj) {
694  // Chain failed or was cancelled; revert to the previous state
695  proj->RollbackState();
696  }
697  }
698  } );
699 
700  mAbort = false;
701 
702  size_t i = 0;
703  for (; i < mCommandChain.GetCount(); i++) {
705  break;
706  }
707 
708  res = (i == mCommandChain.GetCount());
709  if (!res)
710  return false;
711 
712  mFileName.Empty();
713 
714  // Chain was successfully applied; save the NEW project state
715  wxString longDesc, shortDesc;
716  wxString name = gPrefs->Read(wxT("/Batch/ActiveChain"), wxEmptyString);
717  if (name.IsEmpty())
718  {
719  /* i18n-hint: active verb in past tense */
720  longDesc = _("Applied batch chain");
721  shortDesc = _("Apply chain");
722  }
723  else
724  {
725  /* i18n-hint: active verb in past tense */
726  longDesc = wxString::Format(_("Applied batch chain '%s'"), name);
727  shortDesc = wxString::Format(_("Apply '%s'"), name);
728  }
729 
730  if (!proj)
731  return false;
732  proj->PushState(longDesc, shortDesc);
733  return true;
734 }
wxArrayString mParamsChain
Definition: BatchCommands.h:82
wxString mFileName
Definition: BatchCommands.h:87
bool ApplyCommandInBatchMode(const wxString &command, const wxString &params)
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:158
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
void RollbackState()
Definition: Project.cpp:4542
wxArrayString mCommandChain
Definition: BatchCommands.h:81
_("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 PushState(const wxString &desc, const wxString &shortDesc)
Definition: Project.cpp:4502
const wxChar * name
Definition: Distortion.cpp:94
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
bool BatchCommands::ApplyCommand ( const wxString &  command,
const wxString &  params 
)

Definition at line 643 of file BatchCommands.cpp.

References _(), ApplyEffectCommand(), ApplySpecialCommand(), AudacityMessageBox(), EffectManager::Get(), EffectManager::GetEffectByIdentifier(), and SpecialCommands.

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

644 {
645 
646  unsigned int i;
647  // Test for a special command.
648  // CLEANSPEECH remnant
649  for( i = 0; i < sizeof(SpecialCommands)/sizeof(*SpecialCommands); ++i ) {
650  if( command == SpecialCommands[i].second )
651  return ApplySpecialCommand( i, command, params );
652  }
653  // end CLEANSPEECH remnant
654 
655  // Test for an effect.
656  const PluginID & ID = EffectManager::Get().GetEffectByIdentifier( command );
657  if (!ID.empty())
658  {
659  return ApplyEffectCommand(ID, command, params);
660  }
661 
663  wxString::Format(
664  _("Your batch command of %s was not recognized."), command ));
665 
666  return false;
667 }
static const std::pair< const wxChar *, const wxChar * > SpecialCommands[]
const PluginID & GetEffectByIdentifier(const wxString &strTarget)
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
bool ApplyEffectCommand(const PluginID &ID, const wxString &command, const wxString &params)
bool ApplySpecialCommand(int iCommand, const wxString &command, const wxString &params)
static EffectManager & Get()
_("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 &)
EffectDistortion::Params params
Definition: Distortion.cpp:95
bool BatchCommands::ApplyCommandInBatchMode ( const wxString &  command,
const wxString &  params 
)

Definition at line 669 of file BatchCommands.cpp.

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

Referenced by ApplyChain().

670 {
671  AudacityProject *project = GetActiveProject();
672 
673  // enter batch mode...
674  bool prevShowMode = project->GetShowId3Dialog();
675  auto cleanup = finally( [&] {
676  // exit batch mode...
677  project->SetShowId3Dialog(prevShowMode);
678  } );
679 
680  return ApplyCommand( command, params );
681 }
bool ApplyCommand(const wxString &command, const wxString &params)
void SetShowId3Dialog(bool flag)
Definition: Project.h:299
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:158
bool GetShowId3Dialog()
Definition: Project.h:298
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 
)

Definition at line 614 of file BatchCommands.cpp.

References AudacityProject::DoEffect(), EffectManager::Get(), GetActiveProject(), AudacityProject::OnEffectFlags::kConfigured, AudacityProject::OnEffectFlags::kDontRepeatLast, AudacityProject::OnEffectFlags::kSkipState, ReportAndSkip(), AudacityProject::SelectAllIfNone(), and EffectManager::SetBatchProcessing().

Referenced by ApplyCommand().

615 {
616  //Possibly end processing here, if in batch-debug
617  if( ReportAndSkip(command, params))
618  return true;
619 
620  AudacityProject *project = GetActiveProject();
621 
622  // FIXME: for later versions may want to not select-all in batch mode.
623  // IF nothing selected, THEN select everything
624  // (most effects require that you have something selected).
625  project->SelectAllIfNone();
626 
627  bool res = false;
628 
629  auto cleanup = EffectManager::Get().SetBatchProcessing(ID);
630 
631  // transfer the parameters to the effect...
632  if (EffectManager::Get().SetEffectParameters(ID, params))
633  {
634  // and apply the effect...
638  }
639 
640  return res;
641 }
static const int kConfigured
Definition: Project.h:483
static const int kDontRepeatLast
Definition: Project.h:487
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:158
static const int kSkipState
Definition: Project.h:485
static EffectManager & Get()
bool DoEffect(const PluginID &ID, int flags)
Definition: Menus.cpp:4316
bool ReportAndSkip(const wxString &command, const wxString &params)
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
EffectDistortion::Params params
Definition: Distortion.cpp:95
void SetBatchProcessing(const PluginID &ID, bool start)
void SelectAllIfNone()
Definition: Menus.cpp:2200
bool BatchCommands::ApplySpecialCommand ( int  iCommand,
const wxString &  command,
const wxString &  params 
)

Definition at line 530 of file BatchCommands.cpp.

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

Referenced by ApplyCommand().

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

Definition at line 434 of file BatchCommands.cpp.

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

Referenced by ApplySpecialCommand().

435 {
436  const wxFileName newFileName{ fileName };
437  wxString justName = newFileName.GetName();
438  wxString pathName = newFileName.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
439  const auto cleanedString = _("cleaned");
440 
441  if (justName.empty()) {
442  wxDateTime now = wxDateTime::Now();
443  int year = now.GetYear();
444  wxDateTime::Month month = now.GetMonth();
445  wxString monthName = now.GetMonthName(month);
446  int dom = now.GetDay();
447  int hour = now.GetHour();
448  int minute = now.GetMinute();
449  int second = now.GetSecond();
450  justName = wxString::Format(wxT("%d-%s-%02d-%02d-%02d-%02d"),
451  year, monthName, dom, hour, minute, second);
452 
453 // SetName(cleanedFileName);
454 // bool isStereo;
455 // double endTime = project->mTracks->GetEndTime();
456 // double startTime = 0.0;
457  //OnSelectAll();
459  ::AudacityMessageBox(wxString::Format(_("Export recording to %s\n/%s/%s%s"),
460  pathName, cleanedString, justName, extension),
461  _("Export recording"),
462  wxOK | wxCENTRE);
463  pathName += wxFileName::GetPathSeparator();
464  }
465  wxString cleanedName = pathName;
466  cleanedName += cleanedString;
467  bool flag = ::wxFileName::FileExists(cleanedName);
468  if (flag == true) {
469  ::AudacityMessageBox(_("Cannot create directory 'cleaned'. \nFile already exists that is not a directory"));
470  return wxString{};
471  }
472  ::wxFileName::Mkdir(cleanedName, 0777, wxPATH_MKDIR_FULL); // make sure it exists
473 
474  cleanedName += wxFileName::GetPathSeparator();
475  cleanedName += justName;
476  cleanedName += extension;
477  wxGetApp().AddFileToHistory(cleanedName);
478 
479  return cleanedName;
480 }
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"))), 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 &)
AudacityApp & wxGetApp()
bool BatchCommands::DeleteChain ( const wxString &  name)

Definition at line 249 of file BatchCommands.cpp.

References FileNames::ChainDir(), and name.

Referenced by EditChainsDialog::OnRemove().

250 {
251  // Build the filename
252  wxFileName name(FileNames::ChainDir(), chain, wxT("txt"));
253 
254  // Delete it...wxRemoveFile will display errors
255  return wxRemoveFile(name.GetFullPath());
256 }
static wxString ChainDir()
Definition: FileNames.cpp:193
const wxChar * name
Definition: Distortion.cpp:94
void BatchCommands::DeleteFromChain ( int  index)

Definition at line 757 of file BatchCommands.cpp.

References mCommandChain, and mParamsChain.

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

758 {
759  if (index < 0 || index >= (int)mCommandChain.GetCount()) {
760  return;
761  }
762 
763  mCommandChain.RemoveAt(index);
764  mParamsChain.RemoveAt(index);
765 }
wxArrayString mParamsChain
Definition: BatchCommands.h:82
wxArrayString mCommandChain
Definition: BatchCommands.h:81
auto BatchCommands::GetAllCommands ( )
static

Definition at line 277 of file BatchCommands.cpp.

References EffectManager::Get(), PluginManager::Get(), GetActiveProject(), EffectManager::GetEffectIdentifier(), PluginManager::GetFirstPlugin(), PluginDescriptor::GetID(), PluginManager::GetNextPlugin(), PluginDescriptor::GetUntranslatedName(), PluginTypeEffect, and SpecialCommands.

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

278 {
279  CommandNameVector commands;
280 
281  AudacityProject *project = GetActiveProject();
282  if (!project)
283  return commands;
284 
285  // CLEANSPEECH remnant
286  for( const auto &command : SpecialCommands )
287  commands.push_back( {
288  //wxGetTranslation
289  (command.first),
290  command.second
291  } );
292 
293  // end CLEANSPEECH remnant
294 
298  while (plug)
299  {
300  auto command = em.GetEffectIdentifier(plug->GetID());
301  if (!command.IsEmpty())
302  commands.push_back( {
303  plug->GetUntranslatedName(), // plug->GetTranslatedName(),
304  command
305  } );
306  plug = pm.GetNextPlugin(PluginTypeEffect);
307  }
308 
309  // Sort commands by their user-visible names.
310  // PRL: What should happen if first members of pairs are not unique?
311  // Sort stably?
312  std::sort(
313  commands.begin(), commands.end(),
314  [](const CommandName &a, const CommandName &b)
315  { return a.first < b.first; }
316  );
317 
318  /* This is for later in development: include the menu commands.
319  CommandManager * mManager = project->GetCommandManager();
320  wxArrayString mNames;
321  mNames.Clear();
322  mManager->GetAllCommandNames(mNames, false);
323  for(i=0; i<mNames.GetCount(); i++) {
324  commands.Add( mNames[i] );
325  }
326  */
327  return commands;
328 }
static const std::pair< const wxChar *, const wxChar * > SpecialCommands[]
std::vector< CommandName > CommandNameVector
Definition: BatchCommands.h:46
wxString GetEffectIdentifier(const PluginID &ID)
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:158
const PluginDescriptor * GetNextPlugin(PluginType type)
const PluginDescriptor * GetFirstPlugin(PluginType type)
wxString GetUntranslatedName() const
EffectManager is the class that handles effects and effect categories.
Definition: EffectManager.h:49
static EffectManager & Get()
const wxString & GetID() const
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
static PluginManager & Get()
std::pair< wxString, wxString > CommandName
Definition: BatchCommands.h:45
wxString BatchCommands::GetCommand ( int  index)

Definition at line 100 of file BatchCommands.cpp.

References mCommandChain.

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

101 {
102  if (index < 0 || index >= (int)mCommandChain.GetCount()) {
103  return wxT("");
104  }
105 
106  return mCommandChain[index];
107 }
wxArrayString mCommandChain
Definition: BatchCommands.h:81
int BatchCommands::GetCount ( )

Definition at line 118 of file BatchCommands.cpp.

References mCommandChain.

Referenced by EditChainsDialog::PopulateList().

119 {
120  return (int)mCommandChain.GetCount();
121 }
wxArrayString mCommandChain
Definition: BatchCommands.h:81
wxString BatchCommands::GetCurrentParamsFor ( const wxString &  command)
static

Definition at line 331 of file BatchCommands.cpp.

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

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

332 {
333  const PluginID & ID = EffectManager::Get().GetEffectByIdentifier(command);
334  if (ID.empty())
335  {
336  return wxEmptyString; // effect not found.
337  }
338 
340 }
const PluginID & GetEffectByIdentifier(const wxString &strTarget)
static EffectManager & Get()
wxString GetEffectParameters(const PluginID &ID)
double BatchCommands::GetEndTime ( )

Definition at line 385 of file BatchCommands.cpp.

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

Referenced by ApplySpecialCommand(), and WriteMp3File().

386 {
387  AudacityProject *project = GetActiveProject();
388  if( project == NULL )
389  {
390  //AudacityMessageBox( _("No project to process!") );
391  return -1.0;
392  }
393  TrackList * tracks = project->GetTracks();
394  if( tracks == NULL )
395  {
396  //AudacityMessageBox( _("No tracks to process!") );
397  return -1.0;
398  }
399 
400  double endTime = tracks->GetEndTime();
401  return endTime;
402 }
A list of TrackListNode items.
Definition: Track.h:611
double GetEndTime() const
Definition: Track.cpp:1409
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:158
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
TrackList * GetTracks()
Definition: Project.h:174
wxString BatchCommands::GetMessage ( )
inline

Definition at line 69 of file BatchCommands.h.

References mMessage.

Referenced by BatchEvalCommand::Apply().

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

Definition at line 796 of file BatchCommands.cpp.

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

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

797 {
798  wxArrayString names;
799  wxArrayString files;
800  wxDir::GetAllFiles(FileNames::ChainDir(), &files, wxT("*.txt"), wxDIR_FILES);
801  size_t i;
802 
803  wxFileName ff;
804  for (i = 0; i < files.GetCount(); i++) {
805  ff = (files[i]);
806  names.Add(ff.GetName());
807  }
808 
809  return names;
810 }
static wxArrayString names()
Definition: Tags.cpp:697
static wxString ChainDir()
Definition: FileNames.cpp:193
wxString BatchCommands::GetParams ( int  index)

Definition at line 109 of file BatchCommands.cpp.

References mParamsChain.

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

110 {
111  if (index < 0 || index >= (int)mParamsChain.GetCount()) {
112  return wxT("");
113  }
114 
115  return mParamsChain[index];
116 }
wxArrayString mParamsChain
Definition: BatchCommands.h:82
bool BatchCommands::IsFixed ( const wxString &  name)

Definition at line 812 of file BatchCommands.cpp.

References MP3Conversion.

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

813 {
814  if (name == MP3Conversion)
815  return true;
816  return false;
817 }
static const wxString MP3Conversion
const wxChar * name
Definition: Distortion.cpp:94
bool BatchCommands::IsMono ( )

Definition at line 404 of file BatchCommands.cpp.

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

Referenced by ApplySpecialCommand(), and WriteMp3File().

405 {
406  AudacityProject *project = GetActiveProject();
407  if( project == NULL )
408  {
409  //AudacityMessageBox( _("No project and no Audio to process!") );
410  return false;
411  }
412 
413  TrackList * tracks = project->GetTracks();
414  if( tracks == NULL )
415  {
416  //AudacityMessageBox( _("No tracks to process!") );
417  return false;
418  }
419 
420  TrackListIterator iter(tracks);
421  Track *t = iter.First();
422  bool mono = true;
423  while (t) {
424  if (t->GetLinked()) {
425  mono = false;
426  break;
427  }
428  t = iter.Next();
429  }
430 
431  return mono;
432 }
A list of TrackListNode items.
Definition: Track.h:611
bool GetLinked() const
Definition: Track.h:271
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:158
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:94
An iterator for a TrackList.
Definition: Track.h:394
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
TrackList * GetTracks()
Definition: Project.h:174
wxString BatchCommands::Join ( const wxString &  command,
const wxString &  param 
)

Definition at line 850 of file BatchCommands.cpp.

851 {
852  return command + wxT(": ") + param;
853 }
wxString BatchCommands::PromptForParamsFor ( const wxString &  command,
const wxString &  params,
wxWindow *  parent 
)
static

Definition at line 342 of file BatchCommands.cpp.

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

Referenced by BatchCommandDialog::OnEditParams().

343 {
344  const PluginID & ID = EffectManager::Get().GetEffectByIdentifier(command);
345  if (ID.empty())
346  {
347  return wxEmptyString; // effect not found
348  }
349 
350  wxString res = params;
351 
352  auto cleanup = EffectManager::Get().SetBatchProcessing(ID);
353 
354  if (EffectManager::Get().SetEffectParameters(ID, params))
355  {
356  if (EffectManager::Get().PromptUser(ID, parent))
357  {
359  }
360  }
361 
362  return res;
363 }
const PluginID & GetEffectByIdentifier(const wxString &strTarget)
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 365 of file BatchCommands.cpp.

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

Referenced by BatchCommandDialog::OnUsePreset().

366 {
367  const PluginID & ID = EffectManager::Get().GetEffectByIdentifier(command);
368  if (ID.empty())
369  {
370  return wxEmptyString; // effect not found.
371  }
372 
373  wxString preset = EffectManager::Get().GetPreset(ID, params, parent);
374 
375  // Preset will be empty if the user cancelled the dialog, so return the original
376  // parameter value.
377  if (preset.IsEmpty())
378  {
379  return params;
380  }
381 
382  return preset;
383 }
const PluginID & GetEffectByIdentifier(const wxString &strTarget)
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 123 of file BatchCommands.cpp.

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

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

124 {
125  // Clear any previous chain
126  ResetChain();
127 
128  // Build the filename
129  wxFileName name(FileNames::ChainDir(), chain, wxT("txt"));
130 
131  // Set the file name
132  wxTextFile tf(name.GetFullPath());
133 
134  // Open and check
135  tf.Open();
136  if (!tf.IsOpened()) {
137  // wxTextFile will display any errors
138  return false;
139  }
140 
141  // Load commands from the file
142  int lines = tf.GetLineCount();
143  if (lines > 0) {
144  for (int i = 0; i < lines; i++) {
145 
146  // Find the command name terminator...ingore line if not found
147  int splitAt = tf[i].Find(wxT(':'));
148  if (splitAt < 0) {
149  continue;
150  }
151 
152  // Parse and clean
153  wxString cmd = tf[i].Left(splitAt).Strip(wxString::both);
154  wxString parm = tf[i].Mid(splitAt + 1).Strip(wxString::trailing);
155 
156  // Backward compatibility for old Chain scripts
157  // Please comment the version of audacity these are introduced in, so
158  // that old ones can easily be removed once users have had a chance to
159  // migrate
160  if (cmd == wxT("SaveMP3_56k_before"))
161  cmd = wxT("ExportMP3_56k_before");
162  else if (cmd == wxT("SaveMP3_56k_after"))
163  cmd = wxT("ExportMP3_56k_after");
164  else if (cmd == wxT("ExportFlac"))
165  cmd = wxT("ExportFLAC");
166  else if (cmd == wxT("ExportMp3"))
167  cmd = wxT("ExportMP3");
168  else if (cmd == wxT("ExportWav"))
169  cmd = wxT("ExportWAV");
170  else if (cmd == wxT("Compressor") && (parm.find(wxT("DecayTime")) != parm.npos))
171  parm.Replace(wxT("DecayTime"), wxT("ReleaseTime"), NULL); // 2.0.6
172 
173  // Add to lists
174  mCommandChain.Add(cmd);
175  mParamsChain.Add(parm);
176  }
177  }
178 
179  // Done with the file
180  tf.Close();
181 
182  return true;
183 }
wxArrayString mParamsChain
Definition: BatchCommands.h:82
static wxString ChainDir()
Definition: FileNames.cpp:193
wxArrayString mCommandChain
Definition: BatchCommands.h:81
const wxChar * name
Definition: Distortion.cpp:94
bool BatchCommands::RenameChain ( const wxString &  oldchain,
const wxString &  newchain 
)

Definition at line 258 of file BatchCommands.cpp.

References FileNames::ChainDir().

Referenced by EditChainsDialog::OnChainsEndEdit().

259 {
260  // Build the filenames
261  wxFileName oname(FileNames::ChainDir(), oldchain, wxT("txt"));
262  wxFileName nname(FileNames::ChainDir(), newchain, wxT("txt"));
263 
264  // Rename it...wxRenameFile will display errors
265  return wxRenameFile(oname.GetFullPath(), nname.GetFullPath());
266 }
static wxString ChainDir()
Definition: FileNames.cpp:193
bool BatchCommands::ReportAndSkip ( const wxString &  command,
const wxString &  params 
)

Definition at line 775 of file BatchCommands.cpp.

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

Referenced by ApplyEffectCommand(), and ApplySpecialCommand().

776 {
777  int bDebug;
778  gPrefs->Read(wxT("/Batch/Debug"), &bDebug, false);
779  if( bDebug == 0 )
780  return false;
781 
782  //TODO: Add a cancel button to these, and add the logic so that we can abort.
783  if( params != wxT("") )
784  {
785  AudacityMessageBox( wxString::Format(_("Apply %s with parameter(s)\n\n%s"),command, params),
786  _("Test Mode"));
787  }
788  else
789  {
790  AudacityMessageBox( wxString::Format(_("Apply %s"),command),
791  _("Test Mode"));
792  }
793  return true;
794 }
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"))), 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 &)
EffectDistortion::Params params
Definition: Distortion.cpp:95
void BatchCommands::ResetChain ( )

Definition at line 767 of file BatchCommands.cpp.

References mCommandChain, and mParamsChain.

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

768 {
769  mCommandChain.Clear();
770  mParamsChain.Clear();
771 }
wxArrayString mParamsChain
Definition: BatchCommands.h:82
wxArrayString mCommandChain
Definition: BatchCommands.h:81
void BatchCommands::RestoreChain ( const wxString &  name)

Definition at line 819 of file BatchCommands.cpp.

References MP3Conversion, and SetWavToMp3Chain().

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

820 {
821 // TIDY-ME: Effects change their name with localisation.
822 // Commands (at least currently) don't. Messy.
823 
824  if (name == MP3Conversion)
826 }
static const wxString MP3Conversion
void SetWavToMp3Chain()
const wxChar * name
Definition: Distortion.cpp:94
void BatchCommands::SetWavToMp3Chain ( )

Definition at line 268 of file BatchCommands.cpp.

References AddToChain(), and ResetChain().

Referenced by RestoreChain().

269 {
270  ResetChain();
271 
272  AddToChain( wxT("Normalize") );
273  AddToChain( wxT("ExportMP3") );
274 }
void AddToChain(const wxString &command, int before=-1)
void BatchCommands::Split ( const wxString &  str,
wxString &  command,
wxString &  param 
)

Definition at line 828 of file BatchCommands.cpp.

829 {
830  int splitAt;
831 
832  command.Empty();
833  param.Empty();
834 
835  if (str.IsEmpty()) {
836  return;
837  }
838 
839  splitAt = str.Find(wxT(':'));
840  if (splitAt < 0) {
841  return;
842  }
843 
844  command = str.Mid(0, splitAt);
845  param = str.Mid(splitAt + 1);
846 
847  return;
848 }
bool BatchCommands::WriteChain ( const wxString &  chain)

Definition at line 186 of file BatchCommands.cpp.

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

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

187 {
188  // Build the filename
189  wxFileName name(FileNames::ChainDir(), chain, wxT("txt"));
190 
191  // Set the file name
192  wxTextFile tf(name.GetFullPath());
193 
194  // Create the file (Create() doesn't leave the file open)
195  if (!tf.Exists()) {
196  tf.Create();
197  }
198 
199  // Open it
200  tf.Open();
201 
202  if (!tf.IsOpened()) {
203  // wxTextFile will display any errors
204  return false;
205  }
206 
207  // Start with a clean slate
208  tf.Clear();
209 
210  // Copy over the commands
211  int lines = mCommandChain.GetCount();
212  for (int i = 0; i < lines; i++) {
213  // restore deprecated commands in chain script
214  if (mCommandChain[i] == wxT("ExportMP3_56k_before"))
215  mCommandChain[i] = wxT("SaveMP3_56k_before");
216  else if (mCommandChain[i] == wxT("ExportMP3_56k_after"))
217  mCommandChain[i] = wxT("SaveMP3_56k_after");
218  else if (mCommandChain[i] == wxT("ExportFLAC"))
219  mCommandChain[i] = wxT("ExportFlac");
220  else if (mCommandChain[i] == wxT("ExportMP3"))
221  mCommandChain[i] = wxT("ExportMp3");
222  else if (mCommandChain[i] == wxT("ExportWAV"))
223  mCommandChain[i] = wxT("ExportWav");
224 
225  tf.AddLine(mCommandChain[i] + wxT(":") + mParamsChain[ i ]);
226  }
227 
228  // Write the chain
229  tf.Write();
230 
231  // Done with the file
232  tf.Close();
233 
234  return true;
235 }
wxArrayString mParamsChain
Definition: BatchCommands.h:82
static wxString ChainDir()
Definition: FileNames.cpp:193
wxArrayString mCommandChain
Definition: BatchCommands.h:81
const wxChar * name
Definition: Distortion.cpp:94
bool BatchCommands::WriteMp3File ( const wxString &  Name,
int  bitrate 
)

Definition at line 482 of file BatchCommands.cpp.

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

Referenced by ApplySpecialCommand().

483 { //check if current project is mono or stereo
484  unsigned numChannels = 2;
485  if (IsMono()) {
486  numChannels = 1;
487  }
488 
489  double endTime = GetEndTime();
490  if( endTime <= 0.0f )
491  return false;
492  AudacityProject *project = GetActiveProject();
493  if( bitrate <=0 )
494  {
495  // 'No' bitrate given, use the current default.
496  // Use Mp3Stereo to control if export is to a stereo or mono file
497  return mExporter.Process(project, numChannels, wxT("MP3"), Name, false, 0.0, endTime);
498  }
499 
500 
501  bool rc;
502  long prevBitRate = gPrefs->Read(wxT("/FileFormats/MP3Bitrate"), 128);
503  gPrefs->Write(wxT("/FileFormats/MP3Bitrate"), bitrate);
504 
505  auto cleanup = finally( [&] {
506  gPrefs->Write(wxT("/FileFormats/MP3Bitrate"), prevBitRate);
507  gPrefs->Flush();
508  } );
509 
510  // Use Mp3Stereo to control if export is to a stereo or mono file
511  rc = mExporter.Process(project, numChannels, wxT("MP3"), Name, false, 0.0, endTime);
512  return rc;
513 }
Exporter mExporter
Definition: BatchCommands.h:86
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:158
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300

Member Data Documentation

bool BatchCommands::mAbort

Definition at line 83 of file BatchCommands.h.

Referenced by AbortBatch(), and ApplyChain().

wxArrayString BatchCommands::mCommandChain
Exporter BatchCommands::mExporter

Definition at line 86 of file BatchCommands.h.

Referenced by ApplySpecialCommand(), and WriteMp3File().

wxString BatchCommands::mFileName

Definition at line 87 of file BatchCommands.h.

Referenced by ApplyChain(), and ApplySpecialCommand().

wxString BatchCommands::mMessage

Definition at line 84 of file BatchCommands.h.

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

wxArrayString BatchCommands::mParamsChain

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