mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-20 06:10:06 +02:00
Move the code that scrolls during scrub out of Scrubbing.cpp
This commit is contained in:
parent
039aaa13a0
commit
f48694ef47
@ -933,14 +933,18 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
|
||||
mCursorOverlay = std::make_unique<EditCursorOverlay>(this);
|
||||
|
||||
#ifdef EXPERIMENTAL_SCRUBBING_BASIC
|
||||
// This must follow construction of *mIndicatorOverlay, because it must
|
||||
// attach its timer event handler later (so that its handler is invoked
|
||||
// earlier)
|
||||
mScrubOverlay = std::make_unique<ScrubbingOverlay>(this);
|
||||
mScrubber = std::make_unique<Scrubber>(this);
|
||||
#endif
|
||||
|
||||
// This must follow construction of *mScrubOverlay, because it must
|
||||
// More order dependencies here...
|
||||
// This must follow construction of *mIndicatorOverlay, because it must
|
||||
// attach its timer event handler later (so that its handler is invoked
|
||||
// earlier)
|
||||
mPlaybackScroller = std::make_unique<PlaybackScroller>(this);
|
||||
|
||||
// This must follow construction of *mPlaybackScroller,
|
||||
// because it must
|
||||
// attach its timer event handler later (so that its handler is invoked
|
||||
// earlier)
|
||||
this->Connect(EVT_TRACK_PANEL_TIMER,
|
||||
@ -5315,3 +5319,46 @@ int AudacityProject::GetEstimatedRecordingMinsLeftOnDisk() {
|
||||
int iRecMins = (int)(dRecTime / 60.0);
|
||||
return iRecMins;
|
||||
}
|
||||
|
||||
AudacityProject::PlaybackScroller::PlaybackScroller(AudacityProject *project)
|
||||
: mProject(project)
|
||||
{
|
||||
mProject->Connect(EVT_TRACK_PANEL_TIMER,
|
||||
wxCommandEventHandler(PlaybackScroller::OnTimer),
|
||||
NULL,
|
||||
this);
|
||||
}
|
||||
|
||||
AudacityProject::PlaybackScroller::~PlaybackScroller()
|
||||
{
|
||||
mProject->Disconnect(EVT_TRACK_PANEL_TIMER,
|
||||
wxCommandEventHandler(PlaybackScroller::OnTimer),
|
||||
NULL,
|
||||
this);
|
||||
}
|
||||
|
||||
void AudacityProject::PlaybackScroller::OnTimer(wxCommandEvent &event)
|
||||
{
|
||||
// Let other listeners get the notification
|
||||
event.Skip();
|
||||
|
||||
#ifdef EXPERIMENTAL_SCRUBBING_SMOOTH_SCROLL
|
||||
if (mActive && mProject->IsAudioActive())
|
||||
{
|
||||
// Pan the view, so that we center the play indicator.
|
||||
|
||||
ViewInfo &viewInfo = mProject->GetViewInfo();
|
||||
TrackPanel *const trackPanel = mProject->GetTrackPanel();
|
||||
const int posX = viewInfo.TimeToPosition(viewInfo.mRecentStreamTime);
|
||||
int width;
|
||||
trackPanel->GetTracksUsableArea(&width, NULL);
|
||||
const int deltaX = posX - width / 2;
|
||||
viewInfo.h =
|
||||
viewInfo.OffsetTimeByPixels(viewInfo.h, deltaX, true);
|
||||
if (!viewInfo.bScrollBeyondZero)
|
||||
// Can't scroll too far left
|
||||
viewInfo.h = std::max(0.0, viewInfo.h);
|
||||
trackPanel->Refresh(false);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -720,6 +720,28 @@ public:
|
||||
const Scrubber &GetScrubber() const { return *mScrubber; }
|
||||
#endif
|
||||
|
||||
class PlaybackScroller final : public wxEvtHandler
|
||||
{
|
||||
public:
|
||||
explicit PlaybackScroller(AudacityProject *project);
|
||||
~PlaybackScroller();
|
||||
|
||||
void Activate(bool active)
|
||||
{
|
||||
mActive = active;
|
||||
}
|
||||
|
||||
private:
|
||||
void OnTimer(wxCommandEvent &event);
|
||||
|
||||
AudacityProject *mProject;
|
||||
bool mActive { false };
|
||||
};
|
||||
std::unique_ptr<PlaybackScroller> mPlaybackScroller;
|
||||
|
||||
public:
|
||||
PlaybackScroller &GetPlaybackScroller() { return *mPlaybackScroller; }
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
|
@ -200,7 +200,7 @@ void Scrubber::MarkScrubStart(
|
||||
// needed for the decision to start scrubbing later when handling
|
||||
// drag events.
|
||||
#ifdef EXPERIMENTAL_SCRUBBING_SMOOTH_SCROLL
|
||||
mSmoothScrollingScrub = smoothScrolling;
|
||||
SetScrollScrubbing (smoothScrolling);
|
||||
#endif
|
||||
mAlwaysSeeking = alwaysSeeking;
|
||||
mScrubStartPosition = xx;
|
||||
@ -356,25 +356,6 @@ void Scrubber::ContinueScrubbing()
|
||||
if (mScrubSpeedDisplayCountdown > 0)
|
||||
--mScrubSpeedDisplayCountdown;
|
||||
}
|
||||
|
||||
#ifdef EXPERIMENTAL_SCRUBBING_SMOOTH_SCROLL
|
||||
if (mSmoothScrollingScrub) {
|
||||
// Pan the view, so that we center the play indicator.
|
||||
|
||||
ViewInfo &viewInfo = mProject->GetViewInfo();
|
||||
TrackPanel *const trackPanel = mProject->GetTrackPanel();
|
||||
const int posX = viewInfo.TimeToPosition(viewInfo.mRecentStreamTime);
|
||||
int width;
|
||||
trackPanel->GetTracksUsableArea(&width, NULL);
|
||||
const int deltaX = posX - width / 2;
|
||||
viewInfo.h =
|
||||
viewInfo.OffsetTimeByPixels(viewInfo.h, deltaX, true);
|
||||
if (!viewInfo.bScrollBeyondZero)
|
||||
// Can't scroll too far left
|
||||
viewInfo.h = std::max(0.0, viewInfo.h);
|
||||
trackPanel->Refresh(false);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Scrubber::StopScrubbing()
|
||||
@ -382,7 +363,7 @@ void Scrubber::StopScrubbing()
|
||||
UncheckAllMenuItems();
|
||||
|
||||
mScrubStartPosition = -1;
|
||||
mSmoothScrollingScrub = false;
|
||||
SetScrollScrubbing (false);
|
||||
|
||||
if (!IsScrubbing())
|
||||
{
|
||||
@ -393,6 +374,12 @@ void Scrubber::StopScrubbing()
|
||||
}
|
||||
}
|
||||
|
||||
void Scrubber::SetScrollScrubbing(bool scrollScrubbing)
|
||||
{
|
||||
mSmoothScrollingScrub = scrollScrubbing;
|
||||
mProject->GetPlaybackScroller().Activate(scrollScrubbing);
|
||||
}
|
||||
|
||||
bool Scrubber::IsScrubbing() const
|
||||
{
|
||||
if (mScrubToken <= 0)
|
||||
@ -403,6 +390,7 @@ bool Scrubber::IsScrubbing() const
|
||||
const_cast<Scrubber&>(*this).mScrubToken = -1;
|
||||
const_cast<Scrubber&>(*this).mScrubStartPosition = -1;
|
||||
#ifdef EXPERIMENTAL_SCRUBBING_SMOOTH_SCROLL
|
||||
// Don't call SetScrollScrubbing
|
||||
const_cast<Scrubber&>(*this).mSmoothScrollingScrub = false;
|
||||
#endif
|
||||
return false;
|
||||
@ -557,7 +545,6 @@ void ScrubbingOverlay::Draw
|
||||
dc.DrawText(mLastScrubSpeedText, mLastScrubRect.GetX(), mLastScrubRect.GetY());
|
||||
}
|
||||
|
||||
|
||||
void ScrubbingOverlay::OnTimer(wxCommandEvent &event)
|
||||
{
|
||||
// Let other listeners get the notification
|
||||
@ -666,7 +653,7 @@ void Scrubber::DoScrub(bool scroll, bool seek)
|
||||
MarkScrubStart(xx, scroll, seek);
|
||||
}
|
||||
else if(!match) {
|
||||
mSmoothScrollingScrub = scroll;
|
||||
SetScrollScrubbing(scroll);
|
||||
mAlwaysSeeking = seek;
|
||||
UncheckAllMenuItems();
|
||||
CheckMenuItem();
|
||||
|
@ -54,8 +54,11 @@ public:
|
||||
bool HasStartedScrubbing() const
|
||||
{ return GetScrubStartPosition() >= 0; }
|
||||
bool IsScrubbing() const;
|
||||
|
||||
bool IsScrollScrubbing() const // If true, implies HasStartedScrubbing()
|
||||
{ return mSmoothScrollingScrub; }
|
||||
void SetScrollScrubbing(bool scrollScrubbing);
|
||||
|
||||
bool IsAlwaysSeeking() const
|
||||
{ return mAlwaysSeeking; }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user