void ControlToolBar::PlayCurrentRegion(bool looped /* = false */, bool cutpreview /* = false */) { if (!CanStopAudioStream()) return; AudacityProject *p = GetActiveProject(); if (p) { double playRegionStart, playRegionEnd; p->GetPlayRegion(&playRegionStart, &playRegionEnd); AudioIOStartStreamOptions options(p->GetDefaultPlayOptions()); options.playLooped = looped; if (cutpreview) options.timeTrack = NULL; ControlToolBar::PlayAppearance appearance = cutpreview ? ControlToolBar::PlayAppearance::CutPreview : looped ? ControlToolBar::PlayAppearance::Looped : ControlToolBar::PlayAppearance::Straight; PlayPlayRegion(SelectedRegion(playRegionStart, playRegionEnd), options, (looped ? PlayMode::loopedPlay : PlayMode::normalPlay), appearance); } }
void Meter::StartMonitoring() { if (gAudioIO->IsMonitoring()) gAudioIO->StopStream(); else { #if WANT_METER_MENU if (mMeterDisabled) { wxCommandEvent dummy; OnDisableMeter(dummy); } #endif AudacityProject *p = GetActiveProject(); if (p) { gAudioIO->StartMonitoring(p->GetRate()); MeterToolBar *bar = p->GetMeterToolBar(); if (bar) { Meter *play, *record; bar->GetMeters(&play, &record); gAudioIO->SetMeters(record, play); } } } }
void ControlToolBar::EnableDisableButtons() { AudacityProject *p = GetActiveProject(); bool tracks = (p && !p->GetTracks()->IsEmpty()); bool busy = gAudioIO->IsBusy(); #if 0 if (tracks) { if (!busy) mPlay->Enable(); } else mPlay->Disable(); #endif //mPlay->SetEnabled(tracks && !busy); mPlay->SetEnabled(tracks && !mRecord->IsDown()); #if (AUDACITY_BRANDING == BRAND_THINKLABS) mPlay->SetEnabled(tracks && !mRecord->IsDown() && !mLoopPlay->IsDown()); mLoopPlay->SetEnabled(tracks && !mRecord->IsDown() && !mPlay->IsDown()); #endif mStop->SetEnabled(busy); mRewind->SetEnabled(tracks && !busy); mFF->SetEnabled(tracks && !busy); }
bool BatchCommands::ApplyEffectCommand(const PluginID & ID, const wxString & command, const wxString & params) { //Possibly end processing here, if in batch-debug if( ReportAndSkip(command, params)) return true; AudacityProject *project = GetActiveProject(); //FIXME: for later versions may want to not select-all in batch mode. //IF nothing selected, THEN select everything // (most effects require that you have something selected). project->SelectAllIfNone(); bool res = false; EffectManager::Get().SetBatchProcessing(ID, true); // transfer the parameters to the effect... if (EffectManager::Get().SetEffectParameters(ID, params)) { // and apply the effect... res = project->OnEffect(ID, AudacityProject::OnEffectFlags::kConfigured | AudacityProject::OnEffectFlags::kSkipState); } EffectManager::Get().SetBatchProcessing(ID, false); return res; }
float ContrastDialog::GetDB() { // not good // why not? // what if more than one track? float rms = float(0.0); AudacityProject *p = GetActiveProject(); TrackListIterator iter(p->GetTracks()); Track *t = iter.First(); if(mT0 > mT1) { wxMessageDialog m(NULL, _("Start time after after end time!\nPlease enter reasonable times."), _("Error"), wxOK); m.ShowModal(); return 1234.0; // 'magic number', but the whole +ve dB range will 'almost' never occur } if(mT0 < t->GetStartTime()) mT0 = t->GetStartTime(); if(mT1 > t->GetEndTime()) mT1 = t->GetEndTime(); if(mT0 > mT1) { wxMessageDialog m(NULL, _("Times are not reasonable!\nPlease enter reasonable times."), _("Error"), wxOK); m.ShowModal(); return 1234.0; } if(mT0 == mT1) return 1234.0; while(t) { // this isn't quite right. What to do if more than one track selected? ((WaveTrack *)t)->GetRMS(&rms, mT0, mT1); t = iter.Next(); } return 20.0*log10(rms); }
bool BatchCommands::IsMono() { AudacityProject *project = GetActiveProject(); if( project == NULL ) { //wxMessageBox( wxT("No project and no Audio to process!") ); return false; } TrackList * tracks = project->GetTracks(); if( tracks == NULL ) { //wxMessageBox( wxT("No tracks to process!") ); return false; } TrackListIterator iter(tracks); Track *t = iter.First(); bool mono = true; while (t) { if (t->GetLinked()) { mono = false; break; } t = iter.Next(); } return mono; }
bool EffectDtmf::Init() { // dialog will be passed values from effect // Effect retrieves values from saved config // Dialog will take care of using them to initialize controls // If there is a selection, use that duration, otherwise use // value from saved config: this is useful is user wants to // replace selection with dtmf sequence if (mT1 > mT0) { // there is a selection: let's fit in there... // MJS: note that this is just for the TTC and is independent of the track rate // but we do need to make sure we have the right number of samples at the project rate AudacityProject *p = GetActiveProject(); double projRate = p->GetRate(); double quantMT0 = QUANTIZED_TIME(mT0, projRate); double quantMT1 = QUANTIZED_TIME(mT1, projRate); mDuration = quantMT1 - quantMT0; mIsSelection = true; } else { // retrieve last used values gPrefs->Read(wxT("/Effects/DtmfGen/SequenceDuration"), &mDuration, 1L); mIsSelection = false; } gPrefs->Read(wxT("/Effects/DtmfGen/String"), &dtmfString, wxT("audacity")); gPrefs->Read(wxT("/Effects/DtmfGen/DutyCycle"), &dtmfDutyCycle, 550L); gPrefs->Read(wxT("/Effects/DtmfGen/Amplitude"), &dtmfAmplitude, 0.8f); dtmfNTones = wxStrlen(dtmfString); return true; }
/// This is the function which actually obeys one command. Rather than applying /// the command directly, an event containing a reference to the command is sent /// to the main (GUI) thread. This is because having more than one thread access /// the GUI at a time causes problems with wxwidgets. int ExecCommand(wxString *pIn, wxString *pOut) { CommandBuilder builder(*pIn); if (builder.WasValid()) { AudacityProject *project = GetActiveProject(); project->SafeDisplayStatusMessage(wxT("Received script command")); Command *cmd = builder.GetCommand(); ScriptCommandRelay::PostCommand(project, cmd); *pOut = wxEmptyString; } else { *pOut = wxT("Syntax error!\n"); *pOut += builder.GetErrorMessage() + wxT("\n"); builder.Cleanup(); } // Wait until all responses from the command have been received. // The last response is signalled by an empty line. wxString msg = ScriptCommandRelay::ReceiveResponse().GetMessage(); while (msg != wxT("\n")) { *pOut += msg + wxT("\n"); msg = ScriptCommandRelay::ReceiveResponse().GetMessage(); } return 0; }
void TranscriptionToolBar::OnEndOff(wxCommandEvent & WXUNUSED(event)) { //If IO is busy, abort immediately if (gAudioIO->IsBusy()){ SetButton(false,mButtons[TTB_EndOff]); return; } mVk->AdjustThreshold(GetSensitivity()); AudacityProject *p = GetActiveProject(); TrackList *tl = p->GetTracks(); TrackListOfKindIterator iter(Track::Wave, tl); Track *t = iter.First(); //Make a track if(t) { auto wt = static_cast<const WaveTrack*>(t); sampleCount start, len; GetSamples(wt, &start, &len); //Adjust length to end if selection is null if(len == 0) { len = start; start = 0; } auto newEnd = mVk->OffBackward(*wt, start + len, len); double newpos = newEnd.as_double() / wt->GetRate(); p->SetSel1(newpos); p->RedrawProject(); SetButton(false, mButtons[TTB_EndOff]); } }
void Theme::ApplyUpdatedImages() { AudacityProject *p = GetActiveProject(); if( p->GetControlToolBar() ) { p->GetControlToolBar()->ReCreateButtons(); } }
// in response of a print-document apple event void AudacityApp::MacPrintFile(const wxString &fileName) { AudacityProject *project = GetActiveProject(); if (project == NULL || !project->GetTracks()->IsEmpty()) { project = CreateNewAudacityProject(gParentWindow); } project->OpenFile(fileName); }
void LOFImportFileHandle::doDuration() { if (callDurationFactor) { double longestDuration = mProject->GetTracks()->GetEndTime(); mProject->ZoomBy(longestDuration / durationFactor); callDurationFactor = false; } }
void ControlToolBar::OnPlay(wxCommandEvent & WXUNUSED(evt)) { StopPlaying(); AudacityProject *p = GetActiveProject(); if (p) p->TP_DisplaySelection(); PlayDefault(); }
void LOFImportFileHandle::doDuration() { if (callDurationFactor) { double longestDuration = mProject->GetTracks()->GetEndTime(); double realZoomValue = ((longestDuration/durationFactor)*(mProject->GetZoom())); mProject->Zoom(realZoomValue); callDurationFactor = false; } }
void ControlToolBar::OnRewind(wxCommandEvent & WXUNUSED(evt)) { mRewind->PushDown(); mRewind->PopUp(); AudacityProject *p = GetActiveProject(); if (p) { p->Rewind(mRewind->WasShiftDown()); } }
void TranscriptionToolBar::EnableDisableButtons() { #ifdef EXPERIMENTAL_VOICE_DETECTION AudacityProject *p = GetActiveProject(); if (!p) return; // Is anything selected? auto selection = p->GetSel0() < p->GetSel1() && p->GetTracks()->Selected(); mButtons[TTB_Calibrate]->SetEnabled(selection); #endif }
void ControlToolBar::OnFF(wxCommandEvent & WXUNUSED(evt)) { mFF->PushDown(); mFF->PopUp(); AudacityProject *p = GetActiveProject(); if (p) { p->SkipEnd(mFF->WasShiftDown()); } }
void ControlToolBar::EnablePauseCommand(bool bEnable) { // Enable/disable the "P" key command. // GetActiveProject() won't work for all callers, e.g., MakeButton(), because it hasn't finished initializing. AudacityProject* pProj = (AudacityProject*)GetParent(); if (pProj) { CommandManager* pCmdMgr = pProj->GetCommandManager(); if (pCmdMgr) pCmdMgr->Enable(wxT("Pause"), bEnable); } }
bool SelectTimeCommand::Apply(const CommandContext & context){ // Many commands need focus on track panel. // No harm in setting it with a scripted select. context.GetProject()->GetTrackPanel()->SetFocus(); if( !bHasT0 && !bHasT1 ) return true; // Defaults if no value... if( !bHasT0 ) mT0 = 0.0; if( !bHasT1 ) mT1 = 0.0; if( !bHasRelativeSpec ) mRelativeTo = 0; AudacityProject * p = context.GetProject(); double end = p->GetTracks()->GetEndTime(); double t0; double t1; const auto &selectedRegion = p->GetViewInfo().selectedRegion; switch( bHasRelativeSpec ? mRelativeTo : 0 ){ default: case 0: //project start t0 = mT0; t1 = mT1; break; case 1: //project t0 = mT0; t1 = end + mT1; break; case 2: //project end; t0 = end - mT0; t1 = end - mT1; break; case 3: //selection start t0 = mT0 + selectedRegion.t0(); t1 = mT1 + selectedRegion.t0(); break; case 4: //selection t0 = mT0 + selectedRegion.t0(); t1 = mT1 + selectedRegion.t1(); break; case 5: //selection end t0 = selectedRegion.t1() - mT0; t1 = selectedRegion.t1() - mT1; break; } p->mViewInfo.selectedRegion.setTimes( t0, t1); return true; }
void ControlToolBar::OnBatch(wxCommandEvent &evt) { AudacityProject *proj = GetActiveProject(); proj->OnApplyChain(); mPlay->Enable(); mStop->Enable(); mRewind->Enable(); mFF->Enable(); mPause->Disable(); mBatch->Enable(); mBatch->PopUp(); }
//FIX-ME: Was this OnMRUProject lost in an edit?? Should we have it back? void AudacityApp::OnMRUProject(wxCommandEvent& event) { AudacityProject *proj = GetActiveProject(); int n = event.GetId() - 6050;//FIX-ME: Use correct ID name. wxString fileName = proj->GetRecentProjects()->GetHistoryFile(n); bool opened = MRUOpen(fileName); if(!opened) { proj->GetRecentProjects()->RemoveFileFromHistory(n); gPrefs->SetPath("/RecentProjects"); proj->GetRecentProjects()->Save(*gPrefs); gPrefs->SetPath(".."); } }
void ControlToolBar::PlayCurrentRegion(bool looped /* = false */) { mPlay->SetAlternate(looped); AudacityProject *p = GetActiveProject(); if (p) { if (looped) p->mLastPlayMode = loopedPlay; else p->mLastPlayMode = normalPlay; PlayPlayRegion(p->GetSel0(), p->GetSel1(), looped); } }
void ControlToolBar::StopPlaying(bool stopStream /* = true*/) { StopScrolling(); AudacityProject *project = GetActiveProject(); if(project) { // Let scrubbing code do some appearance change project->GetScrubber().StopScrubbing(); } if (!CanStopAudioStream()) return; mStop->PushDown(); SetStop(false); if(stopStream) gAudioIO->StopStream(); SetPlay(false); SetRecord(false); #ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT gAudioIO->AILADisable(); #endif mPause->PopUp(); mPaused=false; //Make sure you tell gAudioIO to unpause gAudioIO->SetPaused(mPaused); ClearCutPreviewTracks(); mBusyProject = NULL; // So that we continue monitoring after playing or recording. // also clean the MeterQueues if( project ) { project->MayStartMonitoring(); Meter *meter = project->GetPlaybackMeter(); if( meter ) { meter->Clear(); } meter = project->GetCaptureMeter(); if( meter ) { meter->Clear(); } } }
pascal OSErr AEOpenFiles(const AppleEvent * theAppleEvent, AppleEvent * theReply, long Refcon) { AEDescList docList; AEKeyword keywd; DescType returnedType; Size actualSize; long itemsInList; FSSpec theSpec; CInfoPBRec pb; Handle nameh; short namelen; OSErr err; short i; err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList); if (err != noErr) return err; err = AECountItems(&docList, &itemsInList); if (err != noErr) return err; for (i = 1; i <= itemsInList; i++) { AEGetNthPtr(&docList, i, typeFSS, &keywd, &returnedType, (Ptr) & theSpec, sizeof(theSpec), &actualSize); if (noErr == FSpGetFullPath(&theSpec, &namelen, &nameh)) { HLock(nameh); char *str = new char[namelen + 1]; memcpy(str, (char *) *nameh, namelen); str[namelen] = 0; HUnlock(nameh); DisposeHandle(nameh); AudacityProject *project = GetActiveProject(); if (project == NULL || !project->GetTracks()->IsEmpty()) { project = CreateNewAudacityProject(gParentWindow); } project->OpenFile(str); delete[]str; } } return noErr; }
void AudacityApp::OnMRUFile(wxCommandEvent& event) { AudacityProject *proj = GetActiveProject(); int n = event.GetId() - wxID_FILE1; wxString fileName = proj->GetRecentFiles()->GetHistoryFile(n); bool opened = MRUOpen(fileName); if(!opened) { proj->GetRecentFiles()->RemoveFileFromHistory(n); gPrefs->SetPath(wxT("/RecentFiles")); proj->GetRecentFiles()->Save(*gPrefs); gPrefs->SetPath(wxT("..")); } }
void EffectNoiseRemoval::CleanSpeechMayWriteNoiseGate() { AudacityProject * project = GetActiveProject(); if( !project || !project->GetCleanSpeechMode() ) return; wxFFile noiseGateFile(wxT("noisegate.nrp"), wxT("wb")); bool flag = noiseGateFile.IsOpened(); if (flag == true) { int expectedCount = (windowSize / 2) * sizeof(float); // FIX-ME: Should we check return value on Write? noiseGateFile.Write(mNoiseGate, expectedCount); noiseGateFile.Close(); } }
///Runs the wait for start dialog. Returns false if the user clicks stop while we are recording ///so that the high bool TimerRecordDialog::RunWaitDialog() { int updateResult = eProgressSuccess; if (m_DateTime_Start > wxDateTime::UNow()) updateResult = this->WaitForStart(); if (updateResult != eProgressSuccess) { // Don't proceed, but don't treat it as canceled recording. User just canceled waiting. return true; } else { // Record for specified time. AudacityProject* pProject = GetActiveProject(); pProject->OnRecord(); bool bIsRecording = true; wxString strMsg = _("Recording start") + (wxString)wxT(":\t\t") + GetDisplayDate(m_DateTime_Start) + wxT("\n") + _("Recording end") + wxT(":\t\t") + GetDisplayDate(m_DateTime_End) + wxT("\n") + _("Duration") + wxT(":\t\t") + m_TimeSpan_Duration.Format(); TimerProgressDialog progress(m_TimeSpan_Duration.GetMilliseconds().GetValue(), _("Audacity Timer Record Progress"), strMsg, pdlgHideCancelButton); // Make sure that start and end time are updated, so we always get the full // duration, even if there's some delay getting here. wxTimerEvent dummyTimerEvent; this->OnTimer(dummyTimerEvent); // Loop for progress display during recording. while (bIsRecording && (updateResult == eProgressSuccess)) { wxMilliSleep(kTimerInterval); updateResult = progress.Update(); bIsRecording = (wxDateTime::UNow() <= m_DateTime_End); // Call UNow() again for extra accuracy... } pProject->OnStop(); } // Let the caller handle cancellation or failure from recording progress. if (updateResult == eProgressCancelled || updateResult == eProgressFailed) return false; return true; }
void AudacityApp::OnKey(wxKeyEvent& event) { AudacityProject *audacityPrj = GetActiveProject(); wxString newStr = ""; long key = event.GetKeyCode(); if(event.ControlDown()) newStr += "Ctrl+"; if(event.AltDown()) newStr += "Alt+"; if(event.ShiftDown()) newStr += "Shift+"; if (event.ControlDown() && key >= 1 && key <= 26) newStr += (char)(64 + key); else if (key >= 33 && key <= 126) newStr += (char)key; else if (key == WXK_BACK) newStr = "Backspace"; else if (key == WXK_DELETE) newStr = "Delete"; else if (key == WXK_SPACE) newStr = "Spacebar"; else { event.Skip(); return; // Don't change it if we don't recognize the key } if(audacityPrj->IsActive()) { int commandIndex = audacityPrj->FindCommandByCombos(newStr); if(audacityPrj->GetCommandState(commandIndex) == enabledMenu) { audEventFunction audFunc = audacityPrj->GetCommandFunc(commandIndex); if(audFunc) (audacityPrj->*((wxEventFunction) audFunc))(event); return; } } event.Skip(); }
void EditToolBar::OnButton(wxCommandEvent &event) { int id = event.GetId()-first_ETB_ID; // Be sure the pop-up happens even if there are exceptions, except for buttons which toggle. auto cleanup = finally( [&] { mButtons[id]->InteractionOver();}); AudacityProject *p = GetActiveProject(); if (!p) return; CommandManager* cm = p->GetCommandManager(); if (!cm) return; auto flags = GetMenuManager(*p).GetUpdateFlags(*p); const CommandContext context( *GetActiveProject() ); cm->HandleTextualCommand(EditToolbarButtonList[id].commandName, context, flags, NoFlagsSpecified); }
void ContrastDialog::OnGetBackground(wxCommandEvent & /*event*/) { AudacityProject *p = GetActiveProject(); SelectedTrackListOfKindIterator iter(Track::Wave, p->GetTracks()); for (Track *t = iter.First(); t; t = iter.Next()) { mBackgroundStartT->SetValue(p->mViewInfo.selectedRegion.t0()); mBackgroundEndT->SetValue(p->mViewInfo.selectedRegion.t1()); } SetStartAndEndTime(); mBackgroundIsDefined = GetDB(backgrounddB); m_pButton_UseCurrentB->SetFocus(); results(); }