Exemple #1
0
void EditToolBar::EnableDisableButtons()
{
   AudacityProject *p = GetActiveProject();
   if (!p) return;

   // Is anything selected?
   bool selection = false;
   TrackListIterator iter(p->GetTracks());
   for (Track *t = iter.First(); t; t = iter.Next())
      if (t->GetSelected()) {
         selection = true;
         break;
      }
   selection &= (p->GetSel0() < p->GetSel1());

   mButtons[ETBCutID]->SetEnabled(selection);
   mButtons[ETBCopyID]->SetEnabled(selection);
   mButtons[ETBTrimID]->SetEnabled(selection);
   mButtons[ETBSilenceID]->SetEnabled(selection);

   mButtons[ETBUndoID]->SetEnabled(p->GetUndoManager()->UndoAvailable());
   mButtons[ETBRedoID]->SetEnabled(p->GetUndoManager()->RedoAvailable());

   bool tracks = (!p->GetTracks()->IsEmpty());

   mButtons[ETBZoomInID]->SetEnabled(tracks && (p->ZoomInAvailable()));
   mButtons[ETBZoomOutID]->SetEnabled(tracks && (p->ZoomOutAvailable()) );

   #if 0 // Disabled for version 1.2.0 since it doesn't work quite right...
   mButtons[ETBZoomToggleID]->SetEnabled(tracks);
   #endif

   mButtons[ETBZoomSelID]->SetEnabled(selection);
   mButtons[ETBZoomFitID]->SetEnabled(tracks);

   mButtons[ETBPasteID]->SetEnabled(p->Clipboard());

#ifdef EXPERIMENTAL_SYNC_LOCK
   bool bSyncLockTracks;
   gPrefs->Read(wxT("/GUI/SyncLockTracks"), &bSyncLockTracks, false);

   if (bSyncLockTracks)
      mButtons[ETBSyncLockID]->PushDown();
   else
      mButtons[ETBSyncLockID]->PopUp();
#endif
}
// ApplyChain returns true on success, false otherwise.
// Any error reporting to the user has already been done.
bool BatchCommands::ApplyChain(const wxString & filename)
{
   mFileName = filename;
   unsigned int i;
   bool res = true;

   mAbort = false;

   for (i = 0; i < mCommandChain.GetCount(); i++) {
      if (!ApplyCommandInBatchMode(mCommandChain[i], mParamsChain[i]) || mAbort) {
         res = false;
         break;
      }
   }

   mFileName.Empty();
   AudacityProject *proj = GetActiveProject();

   if (!res)
   {
      if(proj) {
         // Chain failed or was cancelled; revert to the previous state
         UndoManager *um = proj->GetUndoManager();
         proj->SetStateTo(um->GetCurrentState());
      }
      return false;
   }

   // Chain was successfully applied; save the new project state
   wxString longDesc, shortDesc;
   wxString name = gPrefs->Read(wxT("/Batch/ActiveChain"), wxEmptyString);
   if (name.IsEmpty())
   {
      longDesc = wxT("Applied batch chain");
      shortDesc = wxT("Apply chain");
   }
   else
   {
      longDesc = wxString::Format(wxT("Applied batch chain '%s'"), name.c_str());
      shortDesc = wxString::Format(wxT("Apply '%s'"), name.c_str());
   }

   if (!proj)
      return false;
   proj->PushState(longDesc, shortDesc);
   return true;
}
Exemple #3
0
void EditToolBar::EnableDisableButtons()
{
   AudacityProject *p = GetActiveProject();
   if (!p) return;

   // Is anything selected?
   bool selection = false;
   TrackListIterator iter(p->GetTracks());
   for (Track *t = iter.First(); t; t = iter.Next())
      if (t->GetSelected()) {
         selection = true;
         break;
      }
   selection &= (p->GetSel0() < p->GetSel1());
   
   mButtons[ETBCutID]->SetEnabled(selection);
   mButtons[ETBCopyID]->SetEnabled(selection);
   mButtons[ETBTrimID]->SetEnabled(selection);
   mButtons[ETBSilenceID]->SetEnabled(selection);

   mButtons[ETBUndoID]->SetEnabled(p->GetUndoManager()->UndoAvailable());
   mButtons[ETBRedoID]->SetEnabled(p->GetUndoManager()->RedoAvailable());

   bool tracks = (!p->GetTracks()->IsEmpty());

   mButtons[ETBZoomInID]->SetEnabled(tracks && (p->GetZoom() < gMaxZoom));
   mButtons[ETBZoomOutID]->SetEnabled(tracks && (p->GetZoom() > gMinZoom) );

   #if 0 // Disabled for version 1.2.0 since it doesn't work quite right...
   mButtons[ETBZoomToggleID]->SetEnabled(tracks);
   #endif

   mButtons[ETBZoomSelID]->SetEnabled(selection);
   mButtons[ETBZoomFitID]->SetEnabled(tracks);

   mButtons[ETBPasteID]->SetEnabled(p->Clipboard());
}
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();
}
Exemple #5
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();
}