Exemplo n.º 1
0
// TIDY-ME: Get rid of special commands and make them part of the
// 'menu' system (but not showing on the menu)
//
// ======= IMPORTANT ========
// Special Commands are a KLUDGE whilst we wait for a better system to handle the menu
// commands from batch mode.
//
// Really we should be using a similar (or same) system to that used for effects
// so that parameters can be passed to the commands.  Many of the menu
// commands take a selection as their parameter.
//
// If you find yourself adding lots of existing commands from the menus here, STOP
// and think again.  
// ======= IMPORTANT ========
bool BatchCommands::ApplySpecialCommand(int iCommand, const wxString command,const wxString params)
{
   AudacityProject *project = GetActiveProject();
   wxString filename;
   int numChannels = 1;		//used to switch between mono and stereo export
   if (IsMono()) {
      numChannels = 1;	//export in mono
   } else {
      numChannels = 2;	//export in stereo
   }

   if( ReportAndSkip(command, params))
      return true;

   if (mFileName.IsEmpty()) {   
      filename = project->BuildCleanFileName(project->GetFileName());
   }
   else {
      filename = project->BuildCleanFileName(mFileName);
   }

   // We have a command index, but we don't use it!
   // TODO: Make this special-batch-command code use the menu item code....
   // FIX-ME: No error reporting on write file failure in batch mode.
   if( command == wxT("No Action")){
      return true;
   } else if (!mFileName.IsEmpty() && command == wxT("Import") ){
      project->OnRemoveTracks();
      project->Import(mFileName);
      project->OnSelectAll();
      return true;
   } else if (command == wxT("Save Hq Master1")){
      filename.Replace(wxT("cleaned/"), wxT("cleaned/MasterBefore_"), false);
      return WriteMp3File( filename, 56 );
   } else if (command == wxT("Save Hq Master2")){
      filename.Replace(wxT("cleaned/"), wxT("cleaned/MasterAfter_"), false);
      return WriteMp3File ( filename, 56 );
   } else if (command == wxT("Stereo To Mono")){
      // StereoToMono is an effect masquerading as a menu item.
      Effect * f=GetEffectFromCommandName( _("Stereo To Mono") );
      if( f!=NULL )
         return ApplyEffectCommand( f, command, params );
      wxMessageBox( _("Stereo To Mono Effect not found"));
      return false;
   } else if (command == wxT("ExportMp3") ){
      return WriteMp3File ( filename, 0 ); // 0 bitrate means use default/current
   } else if (command == wxT("ExportWav") ){
      filename.Replace(wxT(".mp3"), wxT(".wav"), false);
      double endTime = GetEndTime();
      if( endTime <= 0.0f )
         return false;
      return ::ExportPCM(project, numChannels, filename, false, 0.0, endTime);
   } else if (command == wxT("ExportOgg")){
#ifdef USE_LIBVORBIS
      filename.Replace(wxT(".mp3"), wxT(".ogg"), false);
      double endTime = GetEndTime();
      if( endTime <= 0.0f )
         return false;
      return ::ExportOGG(project, numChannels, filename, false, 0.0, endTime);
#else
      wxMessageBox(_("Ogg Vorbis support is not included in this build of Audacity"));
      return false;
#endif
   } else if (command == wxT("ExportFlac")){
#ifdef USE_LIBFLAC
      filename.Replace(wxT(".mp3"), wxT(".flac"), false);
      double endTime = GetEndTime();
      if( endTime <= 0.0f )
         return false;
      return ::ExportFLAC(project, numChannels, filename, false, 0.0, endTime);
#else
      wxMessageBox(_("FLAC support is not included in this build of Audacity"));
      return false;
#endif
   } 
   wxMessageBox( wxString::Format(_("Command %s not implemented yet"),command.c_str()) );
   return false;
}
Exemplo n.º 2
0
void BatchProcessDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event))
{
   long item = mChains->GetNextItem(-1,
                                    wxLIST_NEXT_ALL,
                                    wxLIST_STATE_SELECTED);
   if (item == -1) {
      wxMessageBox(_("No chain selected"));
      return;
   }

   wxString name = mChains->GetItemText(item);
   gPrefs->Write(wxT("/Batch/ActiveChain"), name);
   gPrefs->Flush();

   AudacityProject *project = GetActiveProject();
   if (!project->GetIsEmpty()) {
      wxMessageBox(_("Please save and close the current project first."));
      return;
   }

   wxString path = gPrefs->Read(wxT("/DefaultOpenPath"), ::wxGetCwd());
   wxString prompt =  _("Select file(s) for batch processing...");

   FormatList l;
   wxString filter;
   wxString all;

   Importer::Get().GetSupportedImportFormats(&l);
   for (const auto &format : l) {
      const Format *f = &format;

      wxString newfilter = f->formatName + wxT("|");
      for (size_t i = 0; i < f->formatExtensions.size(); i++) {
         if (!newfilter.Contains(wxT("*.") + f->formatExtensions[i] + wxT(";")))
            newfilter += wxT("*.") + f->formatExtensions[i] + wxT(";");
         if (!all.Contains(wxT("*.") + f->formatExtensions[i] + wxT(";")))
            all += wxT("*.") + f->formatExtensions[i] + wxT(";");
      }
      newfilter.RemoveLast(1);
      filter += newfilter;
      filter += wxT("|");
   }
   all.RemoveLast(1);
   filter.RemoveLast(1);

   wxString mask = _("All files|*|All supported files|") +
                   all + wxT("|") +
                   filter;

   wxString type = gPrefs->Read(wxT("/DefaultOpenType"),mask.BeforeFirst(wxT('|')));
   // Convert the type to the filter index
   int index = mask.First(type + wxT("|"));
   if (index == wxNOT_FOUND) {
      index = 0;
   }
   else {
      index = mask.Left(index).Freq(wxT('|')) / 2;
      if (index < 0) {
         index = 0;
      }
   }

   FileDialog dlog(this,
                   prompt,
                   path,
                   wxT(""),
                   mask,
                   wxFD_OPEN | wxFD_MULTIPLE | wxRESIZE_BORDER);

   dlog.SetFilterIndex(index);
   if (dlog.ShowModal() != wxID_OK) {
      return;
   }

   wxArrayString files;
   dlog.GetPaths(files);

   files.Sort();

   wxDialog * pD = safenew wxDialog(this, wxID_ANY, GetTitle());
   pD->SetName(pD->GetTitle());
   ShuttleGui S(pD, eIsCreating);

   S.StartVerticalLay(false);
   {
      S.StartStatic(_("Applying..."), 1);
      {
         wxImageList *imageList = new wxImageList(9, 16);
         imageList->Add(wxIcon(empty9x16_xpm));
         imageList->Add(wxIcon(arrow_xpm));

         S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES |
                    wxLC_SINGLE_SEL);
         mList = S.Id(CommandsListID).AddListControlReportMode();
         mList->AssignImageList(imageList, wxIMAGE_LIST_SMALL);
         mList->InsertColumn(0, _("File"), wxLIST_FORMAT_LEFT);
      }
      S.EndStatic();

      S.StartHorizontalLay(wxCENTER, false);
      {
         S.Id(wxID_CANCEL).AddButton(_("&Cancel"));
      }
      S.EndHorizontalLay();
   }
   S.EndVerticalLay();

   int i;
   for (i = 0; i < (int)files.GetCount(); i++ ) {
      mList->InsertItem(i, files[i], i == 0);
   }

   // Set the column size for the files list.
   mList->SetColumnWidth(0, wxLIST_AUTOSIZE);

   int width = mList->GetColumnWidth(0);
   wxSize sz = mList->GetClientSize();
   if (width > sz.GetWidth() && width < 500) {
      sz.SetWidth(width);
      mList->SetInitialSize(sz);
   }

   pD->Layout();
   pD->Fit();
   pD->SetSizeHints(pD->GetSize());
   pD->CenterOnScreen();
   pD->Move(-1, 0);
   pD->Show();
   Hide();

   mBatchCommands.ReadChain(name);
   for (i = 0; i < (int)files.GetCount(); i++) {
      wxWindowDisabler wd(pD);
      if (i > 0) {
         //Clear the arrow in previous item.
         mList->SetItemImage(i - 1, 0, 0);
      }
      mList->SetItemImage(i, 1, 1);
      mList->EnsureVisible(i);

      project->Import(files[i]);
      project->OnSelectAll();
      if (!mBatchCommands.ApplyChain()) {
         break;
      }

      if (!pD->IsShown() || mAbort) {
         break;
      }
      UndoManager *um = project->GetUndoManager();
      um->ClearStates();
      project->OnSelectAll();
      project->OnRemoveTracks();
   }
   project->OnRemoveTracks();

   // Under Linux an EndModal() here crashes (Bug #1221).
   // But sending a close message instead is OK.
#if !defined(__WXMAC__)
   wxCloseEvent Evt;
   Evt.SetId( wxID_OK );
   Evt.SetEventObject( this);
   ProcessWindowEvent( Evt );
#else
   EndModal(wxID_OK);
#endif 

   // Raise myself again, and the parent window with me
   Show();
}
Exemplo n.º 3
0
void BatchProcessDialog::OnApplyToFiles(wxCommandEvent &event)
{
    long item = mChains->GetNextItem(-1,
                                     wxLIST_NEXT_ALL,
                                     wxLIST_STATE_SELECTED);
    if (item == -1) {
        wxMessageBox(_("No chain selected"));
        return;
    }

    wxString name = mChains->GetItemText(item);
    gPrefs->Write(wxT("/Batch/ActiveChain"), name);

    AudacityProject *project = GetActiveProject();
    if (!project->GetIsEmpty()) {
        wxMessageBox(_("Please save and close the current project first."));
        return;
    }

    wxString path = gPrefs->Read(wxT("/DefaultOpenPath"), ::wxGetCwd());
    wxString prompt =  project->GetCleanSpeechMode() ?
                       _("Select vocal file(s) for batch CleanSpeech Chain...") :
                       _("Select file(s) for batch processing...");
    wxString fileSelector = project->GetCleanSpeechMode() ?
                            _("Vocal files (*.wav;*.mp3)|*.wav;*.mp3|WAV files (*.wav)|*.wav|MP3 files (*.mp3)|*.mp3") :
                            _("All files (*.*)|*.*|WAV files (*.wav)|*.wav|AIFF files (*.aif)|*.aif|AU files (*.au)|*.au|MP3 files (*.mp3)|*.mp3|Ogg Vorbis files (*.ogg)|*.ogg|FLAC files (*.flac)|*.flac"
                             );

    FileDialog dlog(this, prompt,
                    path, wxT(""), fileSelector,
                    wxFD_OPEN | wxFD_MULTIPLE | wxRESIZE_BORDER);

    if (dlog.ShowModal() != wxID_OK) {
        return;
    }

    wxArrayString files;
    dlog.GetPaths(files);

    files.Sort();

    wxDialog d(this, wxID_ANY, GetTitle());
    ShuttleGui S(&d, eIsCreating);

    S.StartVerticalLay(false);
    {
        S.StartStatic(_("Applying..."), 1);
        {
            wxImageList *imageList = new wxImageList(9, 16);
            imageList->Add(wxIcon(empty_9x16_xpm));
            imageList->Add(wxIcon(arrow_xpm));

            S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES |
                       wxLC_SINGLE_SEL);
            mList = S.AddListControlReportMode();
            mList->AssignImageList(imageList, wxIMAGE_LIST_SMALL);
            mList->InsertColumn(0, _("File"), wxLIST_FORMAT_LEFT);
        }
        S.EndStatic();

        S.StartHorizontalLay(wxCENTER, false);
        {
            S.Id(wxID_CANCEL).AddButton(_("&Cancel"));
        }
        S.EndHorizontalLay();
    }
    S.EndVerticalLay();

    int i;
    for (i = 0; i < (int)files.GetCount(); i++ ) {
        mList->InsertItem(i, files[i], i == 0);
    }

    // Set the column size for the files list.
    mList->SetColumnWidth(0, wxLIST_AUTOSIZE);

    int width = mList->GetColumnWidth(0);
    wxSize sz = mList->GetClientSize();
    if (width > sz.GetWidth() && width < 500) {
        sz.SetWidth(width);
        mList->SetInitialSize(sz);
    }

    d.Layout();
    d.Fit();
    d.SetSizeHints(d.GetSize());
    d.CenterOnScreen();
    d.Move(-1, 0);
    d.Show();
    Hide();

    mBatchCommands.ReadChain(name);
    for (i = 0; i < (int)files.GetCount(); i++) {
        wxWindowDisabler wd(&d);
        if (i > 0) {
            //Clear the arrow in previous item.
            mList->SetItemImage(i - 1, 0, 0);
        }
        mList->SetItemImage(i, 1, 1);
        mList->EnsureVisible(i);

        project->OnRemoveTracks();
        project->Import(files[i]);
        project->OnSelectAll();
        if (!mBatchCommands.ApplyChain()) {
            break;
        }

        if (!d.IsShown() || mAbort) {
            break;
        }
        UndoManager *um = project->GetUndoManager();
        um->ClearStates();
    }
    project->OnRemoveTracks();
}