void BatchCommands::SetWavToMp3Chain() // a function per default chain?  This is flawed design!  MJS
{
   ResetChain();
 
   AddToChain( wxT("Normalize") );
   AddToChain( wxT("ExportMP3") );
}
void BatchCommands::SetWavToMp3Chain()
{
   ResetChain();
 
   AddToChain( wxT("Import") );
   AddToChain(   _("Normalize") );
   AddToChain( wxT("ExportMp3") );
}
bool BatchCommands::ReadChain(const wxString & chain)
{
   // Clear any previous chain
   ResetChain();

   // Build the filename
   wxFileName name(FileNames::ChainDir(), chain, wxT("txt"));

   // Set the file name
   wxTextFile tf(name.GetFullPath());

   // Open and check
   tf.Open();
   if (!tf.IsOpened()) {
      // wxTextFile will display any errors
      return false;
   }

   // Load commands from the file
   int lines = tf.GetLineCount();
   if (lines > 0) {
      for (int i = 0; i < lines; i++) {

         // Find the command name terminator...ingore line if not found
         int splitAt = tf[i].Find(wxT(':'));
         if (splitAt < 0) {
            continue;
         }

         // Parse and clean
         wxString cmd = tf[i].Left(splitAt).Strip(wxString::both);
         wxString parm = tf[i].Mid(splitAt + 1).Strip(wxString::trailing);
         
         // Backward compatibility for old Chain scripts
         if (cmd == wxT("SaveMP3_56k_before"))
            cmd = wxT("ExportMP3_56k_before");
         else if (cmd == wxT("SaveMP3_56k_after"))
            cmd = wxT("ExportMP3_56k_after");
         else if (cmd == wxT("ExportFlac"))
            cmd = wxT("ExportFLAC");
         else if (cmd == wxT("ExportMp3"))
            cmd = wxT("ExportMP3");
         else if (cmd == wxT("ExportWav"))
            cmd = wxT("ExportWAV");

         // Add to lists
         mCommandChain.Add(cmd);
         mParamsChain.Add(parm);
      }
   }

   // Done with the file
   tf.Close();

   return true;
}
BatchCommands::BatchCommands()
{
   ResetChain();

   wxArrayString names = GetNames();

   if (names.Index(MP3Conversion) == wxNOT_FOUND) {
      AddChain(MP3Conversion);
      RestoreChain(MP3Conversion);
      WriteChain(MP3Conversion);
   }
}
void BatchCommands::SetCleanSpeechChain()
{
   ResetChain();

// TIDY-ME: Effects change their name with localisation.
// Commands (at least currently) don't.  Messy.

/* i18n-hint: Effect name translations must agree with those used elsewhere, or batch won't find them */
   AddToChain( wxT("StereoToMono") );
   AddToChain( wxT("Normalize") );
   AddToChain( wxT("SaveMP3_56k_before") );
   AddToChain( wxT("NoiseRemoval") );
   AddToChain( wxT("TruncateSilence") );
   AddToChain( wxT("Leveller") );
   AddToChain( wxT("Normalize") );
   AddToChain( wxT("ExportMp3") );
}
BatchCommands::BatchCommands()
{
   ResetChain();

   wxArrayString names = GetNames();
#ifdef CLEANSPEECH   // possibly the rest of this fn
   if (names.Index(CleanSpeech) == wxNOT_FOUND) {
      AddChain(CleanSpeech);
      RestoreChain(CleanSpeech);
      WriteChain(CleanSpeech);
   }
#endif   // CLEANSPEECH

   if (names.Index(MP3Conversion) == wxNOT_FOUND) {
      AddChain(MP3Conversion);
      RestoreChain(MP3Conversion);
      WriteChain(MP3Conversion);
   }
}
bool BatchCommands::ReadChain(const wxString & chain)
{
   // Clear any previous chain
   ResetChain();

   // Build the filename
   wxFileName name(FileNames::ChainDir(), chain, wxT("txt"));

   // Set the file name
   wxTextFile tf(name.GetFullPath());

   // Open and check
   tf.Open();
   if (!tf.IsOpened()) {
      // wxTextFile will display any errors
      return false;
   }

   // Load commands from the file
   int lines = tf.GetLineCount();
   if (lines > 0) {
      for (int i = 0; i < lines; i++) {

         // Find the command name terminator...ingore line if not found
         int splitAt = tf[i].Find(wxT(':'));
         if (splitAt < 0) {
            continue;
         }

         // Parse and clean
         wxString cmd = tf[i].Left(splitAt).Strip(wxString::both);
         wxString parm = tf[i].Mid(splitAt + 1).Strip(wxString::trailing);

         // Backward compatibility for old Chain scripts
         // Please comment the version of audacity these are introduced in, so
         // that old ones can easily be removed once users have had a chance to
         // migrate
         if (cmd == wxT("SaveMP3_56k_before"))
            cmd = wxT("ExportMP3_56k_before");
         else if (cmd == wxT("SaveMP3_56k_after"))
            cmd = wxT("ExportMP3_56k_after");
         else if (cmd == wxT("ExportFlac"))
            cmd = wxT("ExportFLAC");
         else if (cmd == wxT("ExportMp3"))
            cmd = wxT("ExportMP3");
         else if (cmd == wxT("ExportWav"))
            cmd = wxT("ExportWAV");
         else if (cmd == wxT("Compressor") && (parm.find(wxT("DecayTime")) != parm.npos))
            parm.Replace(wxT("DecayTime"), wxT("ReleaseTime"), NULL);   // 2.0.6

         // Add to lists
         mCommandChain.Add(cmd);
         mParamsChain.Add(parm);
      }
   }

   // Done with the file
   tf.Close();

   return true;
}