From 4018b191b4d9c4a6d9a411cfaeb2b47280826e3a Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 27 Mar 2019 04:15:28 -0400 Subject: [PATCH] Remove Get/Set functions for selection bounds from AudacityProject --- src/AdornedRulerPanel.cpp | 13 ++++++++----- src/LabelTrack.cpp | 7 ++++--- src/Lyrics.cpp | 9 ++++++--- src/LyricsWindow.cpp | 3 ++- src/Project.cpp | 14 -------------- src/Project.h | 4 ---- src/commands/SelectCommand.cpp | 13 +++++++------ src/effects/Effect.cpp | 6 ++++-- src/effects/Generator.cpp | 4 +++- src/effects/nyquist/Nyquist.cpp | 5 +++-- src/toolbars/ControlToolBar.cpp | 16 +++++++++------- src/toolbars/TranscriptionToolBar.cpp | 16 ++++++++++------ .../playabletrack/wavetrack/ui/CutlineHandle.cpp | 4 ++-- 13 files changed, 58 insertions(+), 56 deletions(-) diff --git a/src/AdornedRulerPanel.cpp b/src/AdornedRulerPanel.cpp index d2c48b991..7400a8ebd 100644 --- a/src/AdornedRulerPanel.cpp +++ b/src/AdornedRulerPanel.cpp @@ -198,8 +198,9 @@ void AdornedRulerPanel::QuickPlayRulerOverlay::Update() && (!project->GetScrubber().IsScrubbing() || project->GetScrubber().IsSpeedPlaying())) mNewQPIndicatorPos = -1; else { + const auto &selectedRegion = project->GetViewInfo().selectedRegion; double latestEnd = - std::max(ruler->mTracks->GetEndTime(), project->GetSel1()); + std::max(ruler->mTracks->GetEndTime(), selectedRegion.t1()); if (ruler->mQuickPlayPos >= latestEnd) mNewQPIndicatorPos = -1; else { @@ -1461,8 +1462,9 @@ void AdornedRulerPanel::HandleQPRelease(wxMouseEvent &evt) const double t0 = mTracks->GetStartTime(); const double t1 = mTracks->GetEndTime(); - const double sel0 = mProject->GetSel0(); - const double sel1 = mProject->GetSel1(); + const auto &selectedRegion = mProject->GetViewInfo().selectedRegion; + const double sel0 = selectedRegion.t0(); + const double sel1 = selectedRegion.t1(); // We want some audio in the selection, but we allow a dragged // region to include selected white-space and space before audio start. @@ -1529,8 +1531,9 @@ void AdornedRulerPanel::StartQPPlay(bool looped, bool cutPreview) { const double t0 = mTracks->GetStartTime(); const double t1 = mTracks->GetEndTime(); - const double sel0 = mProject->GetSel0(); - const double sel1 = mProject->GetSel1(); + const auto &selectedRegion = mProject->GetViewInfo().selectedRegion; + const double sel0 = selectedRegion.t0(); + const double sel1 = selectedRegion.t1(); // Start / Restart playback on left click. bool startPlaying = (mPlayRegionStart >= 0); diff --git a/src/LabelTrack.cpp b/src/LabelTrack.cpp index 78cb2ba7a..fcfd67ba7 100644 --- a/src/LabelTrack.cpp +++ b/src/LabelTrack.cpp @@ -2191,6 +2191,7 @@ void LabelTrack::ShowContextMenu() void LabelTrack::OnContextMenu(wxCommandEvent & evt) { AudacityProject *p = GetActiveProject(); + auto &selectedRegion = p->GetViewInfo().selectedRegion; switch (evt.GetId()) { @@ -2211,7 +2212,7 @@ void LabelTrack::OnContextMenu(wxCommandEvent & evt) /// paste selected text if paste menu item is selected case OnPasteSelectedTextID: - if (PasteSelectedText(p->GetSel0(), p->GetSel1())) + if (PasteSelectedText(selectedRegion.t0(), selectedRegion.t1())) { p->PushState(_("Modified Label"), _("Label Edit"), @@ -2221,7 +2222,7 @@ void LabelTrack::OnContextMenu(wxCommandEvent & evt) /// DELETE selected label case OnDeleteSelectedLabelID: { - int ndx = GetLabelIndex(p->GetSel0(), p->GetSel1()); + int ndx = GetLabelIndex(selectedRegion.t0(), selectedRegion.t1()); if (ndx != -1) { DeleteLabel(ndx); @@ -2233,7 +2234,7 @@ void LabelTrack::OnContextMenu(wxCommandEvent & evt) break; case OnEditSelectedLabelID: { - int ndx = GetLabelIndex(p->GetSel0(), p->GetSel1()); + int ndx = GetLabelIndex(selectedRegion.t0(), selectedRegion.t1()); if (ndx != -1) DoEditLabels(*p, this, ndx); } diff --git a/src/Lyrics.cpp b/src/Lyrics.cpp index b56b94a0a..902a6ba2b 100644 --- a/src/Lyrics.cpp +++ b/src/Lyrics.cpp @@ -56,7 +56,8 @@ void HighlightTextCtrl::OnMouseEvent(wxMouseEvent& event) { Syllable* pCurSyl = mLyricsPanel->GetSyllable(nNewSyl); AudacityProject* pProj = GetActiveProject(); - pProj->SetSel0(pCurSyl->t); + auto &selectedRegion = pProj->GetViewInfo().selectedRegion; + selectedRegion.setT0( pCurSyl->t ); //v Should probably select to end as in // SelectActions::Handler::OnSelectCursorEnd, @@ -438,7 +439,8 @@ void LyricsPanel::Update(double t) // TrackPanel::OnTimer passes gAudioIO->GetStreamTime(), which is -DBL_MAX if !IsStreamActive(). // In that case, use the selection start time. AudacityProject* pProj = GetActiveProject(); - mT = pProj->GetSel0(); + const auto &selectedRegion = pProj->GetViewInfo().selectedRegion; + mT = selectedRegion.t0(); } else mT = t; @@ -501,7 +503,8 @@ void LyricsPanel::UpdateLyrics(wxEvent &e) AddLabels(pLabelTrack); Finish(pLabelTrack->GetEndTime()); - Update(mProject->GetSel0()); + const auto &selectedRegion = mProject->GetViewInfo().selectedRegion; + Update(selectedRegion.t0()); } void LyricsPanel::OnStartStop(wxCommandEvent &e) diff --git a/src/LyricsWindow.cpp b/src/LyricsWindow.cpp index 211c26662..feda83e79 100644 --- a/src/LyricsWindow.cpp +++ b/src/LyricsWindow.cpp @@ -158,7 +158,8 @@ void LyricsWindow::OnTimer(wxCommandEvent &event) else { // Reset lyrics display. - GetLyricsPanel()->Update(mProject->GetSel0()); + const auto &selectedRegion = mProject->GetViewInfo().selectedRegion; + GetLyricsPanel()->Update(selectedRegion.t0()); } // Let other listeners get the notification diff --git a/src/Project.cpp b/src/Project.cpp index a8e5df5a9..3d7a40467 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -1470,20 +1470,6 @@ void AudacityProject::RefreshCursor() mTrackPanel->HandleCursorForPresentMouseState(); } -void AudacityProject::SetSel0(double newSel0) -{ - //Bound checking should go on here - - mViewInfo.selectedRegion.setT0(newSel0); -} - -void AudacityProject::SetSel1(double newSel1) -{ - //Bound checking should go on here - - mViewInfo.selectedRegion.setT1(newSel1); -} - void AudacityProject::OnCapture(wxCommandEvent& evt) { evt.Skip(); diff --git a/src/Project.h b/src/Project.h index b8d1a8b9f..701045630 100644 --- a/src/Project.h +++ b/src/Project.h @@ -220,8 +220,6 @@ class AUDACITY_DLL_API AudacityProject final : public wxFrame, bool ZoomOutAvailable() const { return mViewInfo.ZoomOutAvailable(); } const SelectedRegion &GetSelection() const { return mViewInfo.selectedRegion; } SelectedRegion &GetSelection() { return mViewInfo.selectedRegion; } - double GetSel0() const { return mViewInfo.selectedRegion.t0(); } - double GetSel1() const { return mViewInfo.selectedRegion.t1(); } const ZoomInfo &GetZoomInfo() const { return mViewInfo; } const ViewInfo &GetViewInfo() const { return mViewInfo; } ViewInfo &GetViewInfo() { return mViewInfo; } @@ -230,8 +228,6 @@ class AUDACITY_DLL_API AudacityProject final : public wxFrame, bool IsPlayRegionLocked() { return mLockPlayRegion; } void SetPlayRegionLocked(bool value) { mLockPlayRegion = value; } - void SetSel0(double); //Added by STM - void SetSel1(double); //Added by STM bool Clipboard() { return (msClipT1 - msClipT0) > 0.0; } diff --git a/src/commands/SelectCommand.cpp b/src/commands/SelectCommand.cpp index 1034dbc3c..4ede23295 100644 --- a/src/commands/SelectCommand.cpp +++ b/src/commands/SelectCommand.cpp @@ -102,6 +102,7 @@ bool SelectTimeCommand::Apply(const CommandContext & context){ double t0; double t1; + const auto &selectedRegion = p->GetViewInfo().selectedRegion; switch( bHasRelativeSpec ? mRelativeTo : 0 ){ default: case 0: //project start @@ -117,16 +118,16 @@ bool SelectTimeCommand::Apply(const CommandContext & context){ t1 = end - mT1; break; case 3: //selection start - t0 = mT0 + p->GetSel0(); - t1 = mT1 + p->GetSel0(); + t0 = mT0 + selectedRegion.t0(); + t1 = mT1 + selectedRegion.t0(); break; case 4: //selection - t0 = mT0 + p->GetSel0(); - t1 = mT1 + p->GetSel1(); + t0 = mT0 + selectedRegion.t0(); + t1 = mT1 + selectedRegion.t1(); break; case 5: //selection end - t0 = p->GetSel1() - mT0; - t1 = p->GetSel1() - mT1; + t0 = selectedRegion.t1() - mT0; + t1 = selectedRegion.t1() - mT1; break; } diff --git a/src/effects/Effect.cpp b/src/effects/Effect.cpp index 3517900b1..cae185cd9 100644 --- a/src/effects/Effect.cpp +++ b/src/effects/Effect.cpp @@ -1869,8 +1869,10 @@ bool Effect::ProcessTrack(int count, // Transfer the data from the temporary tracks to the actual ones genLeft->Flush(); // mT1 gives us the NEW selection. We want to replace up to GetSel1(). - left->ClearAndPaste(mT0, p->GetSel1(), genLeft.get(), true, true, - nullptr /* &warper */); + auto &selectedRegion = p->GetViewInfo().selectedRegion; + left->ClearAndPaste(mT0, + selectedRegion.t1(), genLeft.get(), true, true, + nullptr /* &warper */); if (genRight) { diff --git a/src/effects/Generator.cpp b/src/effects/Generator.cpp index 2cce54401..a348b8e2f 100644 --- a/src/effects/Generator.cpp +++ b/src/effects/Generator.cpp @@ -79,8 +79,10 @@ bool Generator::Process() tmp->Flush(); StepTimeWarper warper{ mT0+GetDuration(), GetDuration()-(mT1-mT0) }; + const auto &selectedRegion = p->GetViewInfo().selectedRegion; track->ClearAndPaste( - p->GetSel0(), p->GetSel1(), &*tmp, true, false, &warper); + selectedRegion.t0(), selectedRegion.t1(), + &*tmp, true, false, &warper); } if (!bGoodResult) { diff --git a/src/effects/nyquist/Nyquist.cpp b/src/effects/nyquist/Nyquist.cpp index d023d6326..199560418 100644 --- a/src/effects/nyquist/Nyquist.cpp +++ b/src/effects/nyquist/Nyquist.cpp @@ -925,8 +925,9 @@ finish: // Selection is to be set to whatever it is in the project. AudacityProject *project = GetActiveProject(); if (project) { - mT0 = project->GetSel0(); - mT1 = project->GetSel1(); + auto &selectedRegion = project->GetViewInfo().selectedRegion; + mT0 = selectedRegion.t0(); + mT1 = selectedRegion.t1(); } else { mT0 = 0; diff --git a/src/toolbars/ControlToolBar.cpp b/src/toolbars/ControlToolBar.cpp index 9733a5ec6..368ef1adb 100644 --- a/src/toolbars/ControlToolBar.cpp +++ b/src/toolbars/ControlToolBar.cpp @@ -612,13 +612,14 @@ int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion, if (t1 == t0) { if (looped) { + const auto &selectedRegion = p->GetViewInfo().selectedRegion; // play selection if there is one, otherwise // set start of play region to project start, // and loop the project from current play position. - if ((t0 > p->GetSel0()) && (t0 < p->GetSel1())) { - t0 = p->GetSel0(); - t1 = p->GetSel1(); + if ((t0 > selectedRegion.t0()) && (t0 < selectedRegion.t1())) { + t0 = selectedRegion.t0(); + t1 = selectedRegion.t1(); } else { // loop the entire project @@ -983,8 +984,9 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt) const bool appendRecord = (altAppearance == bPreferNewTrack); if (p) { - double t0 = p->GetSel0(); - double t1 = p->GetSel1(); + const auto &selectedRegion = p->GetViewInfo().selectedRegion; + double t0 = selectedRegion.t0(); + double t1 = selectedRegion.t1(); // When no time selection, recording duration is 'unlimited'. if (t1 == t0) t1 = DBL_MAX; @@ -1008,8 +1010,8 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt) } // Whether we decided on NEW tracks or not: - if (t1 <= p->GetSel0() && p->GetSel1() > p->GetSel0()) { - t1 = p->GetSel1(); // record within the selection + if (t1 <= selectedRegion.t0() && selectedRegion.t1() > selectedRegion.t0()) { + t1 = selectedRegion.t1(); // record within the selection } else { t1 = DBL_MAX; // record for a long, long time diff --git a/src/toolbars/TranscriptionToolBar.cpp b/src/toolbars/TranscriptionToolBar.cpp index d91c23c71..b277b397c 100644 --- a/src/toolbars/TranscriptionToolBar.cpp +++ b/src/toolbars/TranscriptionToolBar.cpp @@ -414,8 +414,9 @@ void TranscriptionToolBar::GetSamples( //First, get the current selection. It is part of the mViewInfo, which is //part of the project - double start = p->GetSel0(); - double end = p->GetSel1(); + const auto &selectedRegion = p->GetViewInfo().selectedRegion; + double start = selectedRegion.t0(); + double end = selectedRegion.t1(); auto ss0 = sampleCount( (start - t->GetOffset()) * t->GetRate() ); auto ss1 = sampleCount( (end - t->GetOffset()) * t->GetRate() ); @@ -563,7 +564,8 @@ void TranscriptionToolBar::OnStartOn(wxCommandEvent & WXUNUSED(event)) auto newstart = mVk->OnForward(*wt, start, len); double newpos = newstart.as_double() / wt->GetRate(); - p->SetSel0(newpos); + auto &selectedRegion = p->GetViewInfo().selectedRegion; + selectedRegion.setT0( newpos ); p->RedrawProject(); SetButton(false, mButtons[TTB_StartOn]); @@ -594,7 +596,8 @@ void TranscriptionToolBar::OnStartOff(wxCommandEvent & WXUNUSED(event)) auto newstart = mVk->OffForward(*wt, start, len); double newpos = newstart.as_double() / wt->GetRate(); - p->SetSel0(newpos); + auto &selectedRegion = p->GetViewInfo().selectedRegion; + selectedRegion.setT0( newpos ); p->RedrawProject(); SetButton(false, mButtons[TTB_StartOn]); @@ -699,8 +702,9 @@ void TranscriptionToolBar::OnSelectSound(wxCommandEvent & WXUNUSED(event)) mVk->OffForward(*wt, start + len, (int)(tl->GetEndTime() * rate)); //reset the selection bounds. - p->SetSel0(newstart.as_double() / rate); - p->SetSel1(newend.as_double() / rate); + auto &selectedRegion = p->GetViewInfo().selectedRegion; + selectedRegion.setTimes( + newstart.as_double() / rate, newend.as_double() / rate ); p->RedrawProject(); } diff --git a/src/tracks/playabletrack/wavetrack/ui/CutlineHandle.cpp b/src/tracks/playabletrack/wavetrack/ui/CutlineHandle.cpp index 3d50fd247..066456e9d 100644 --- a/src/tracks/playabletrack/wavetrack/ui/CutlineHandle.cpp +++ b/src/tracks/playabletrack/wavetrack/ui/CutlineHandle.cpp @@ -248,8 +248,8 @@ UIHandle::Result CutlineHandle::Cancel(AudacityProject *pProject) pProject->RollbackState(); if (mOperation == Expand) { AudacityProject *const project = pProject; - project->SetSel0(mStartTime); - project->SetSel1(mEndTime); + auto &selectedRegion = project->GetViewInfo().selectedRegion; + selectedRegion.setTimes( mStartTime, mEndTime ); result |= UpdateSelection; } return result;