1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-21 23:00:06 +02:00

Reorder some things that happen in the track panel timer update.

This commit is contained in:
Paul Licameli 2015-08-26 17:57:02 -04:00
parent 67c794891d
commit c45ea059e6
2 changed files with 90 additions and 90 deletions

View File

@ -1056,17 +1056,7 @@ void TrackPanel::OnTimer(wxTimerEvent& event)
ScrollDuringDrag();
}
wxCommandEvent dummyEvent;
AudacityProject *p = GetProject();
{
wxCommandEvent e(EVT_TRACK_PANEL_TIMER);
p->GetEventHandler()->ProcessEvent(e);
}
#ifdef EXPERIMENTAL_SCRUBBING_BASIC
TimerUpdateScrubbing();
#endif
AudacityProject *const p = GetProject();
// Check whether we were playing or recording, but the stream has stopped.
if (p->GetAudioIOToken()>0 && !IsAudioActive())
@ -1091,7 +1081,19 @@ void TrackPanel::OnTimer(wxTimerEvent& event)
DisplaySelection();
}
TimerUpdateIndicator();
// Notify listeners for timer ticks
{
wxCommandEvent e(EVT_TRACK_PANEL_TIMER);
p->GetEventHandler()->ProcessEvent(e);
}
const double playPos = gAudioIO->GetStreamTime();
// The sequence of the next two is important.
#ifdef EXPERIMENTAL_SCRUBBING_BASIC
TimerUpdateScrubbing(playPos);
#endif
TimerUpdateIndicator(playPos);
DrawOverlays(false);
@ -1204,36 +1206,18 @@ double TrackPanel::GetScreenEndTime() const
return mViewInfo->PositionToTime(width, true);
}
void TrackPanel::TimerUpdateIndicator()
void TrackPanel::TimerUpdateIndicator(double playPos)
{
double pos = 0.0;
if (!IsAudioActive())
mNewIndicatorX = -1;
else {
// Calculate the horizontal position of the indicator
pos = gAudioIO->GetStreamTime();
#ifdef EXPERIMENTAL_SCRUBBING_SMOOTH_SCROLL
if (mSmoothScrollingScrub) {
// Pan the view, so that we center the play indicator.
const int posX = mViewInfo->TimeToPosition(pos);
int width;
GetTracksUsableArea(&width, NULL);
const int deltaX = posX - width / 2;
mViewInfo->h =
mViewInfo->OffsetTimeByPixels(mViewInfo->h, deltaX, true);
if (!mScrollBeyondZero)
// Can't scroll too far left
mViewInfo->h = std::max(0.0, mViewInfo->h);
Refresh(false);
}
#endif
AudacityProject *p = GetProject();
const bool
onScreen = between_incexc(mViewInfo->h,
pos,
onScreen = playPos >= 0.0 &&
between_incexc(mViewInfo->h,
playPos,
GetScreenEndTime());
// This displays the audio time, too...
@ -1244,11 +1228,11 @@ void TrackPanel::TimerUpdateIndicator()
if( mViewInfo->bUpdateTrackIndicator &&
p->mLastPlayMode != loopedPlay &&
p->mLastPlayMode != oneSecondPlay &&
pos >= 0 &&
playPos >= 0 &&
!onScreen &&
!gAudioIO->IsPaused() )
{
mListener->TP_ScrollWindow( pos );
mListener->TP_ScrollWindow( playPos );
}
// Always update scrollbars even if not scrolling the window. This is
@ -1256,7 +1240,7 @@ void TrackPanel::TimerUpdateIndicator()
// length of the project and therefore the appearance of the scrollbar.
MakeParentRedrawScrollbars();
mNewIndicatorX = mViewInfo->TimeToPosition(pos, GetLeftOffset());
mNewIndicatorX = mViewInfo->TimeToPosition(playPos, GetLeftOffset());
}
}
@ -7441,7 +7425,7 @@ bool TrackPanel::ShouldDrawScrubSpeed()
);
}
void TrackPanel::TimerUpdateScrubbing()
void TrackPanel::TimerUpdateScrubbing(double playPos)
{
if (!IsScrubbing()) {
mNextScrubRect = wxRect();
@ -7479,9 +7463,8 @@ void TrackPanel::TimerUpdateScrubbing()
if (!ShouldDrawScrubSpeed()) {
mNextScrubRect = wxRect();
return;
}
else {
int panelWidth, panelHeight;
GetSize(&panelWidth, &panelHeight);
@ -7533,6 +7516,23 @@ void TrackPanel::TimerUpdateScrubbing()
yy = std::max(0, std::min(panelHeight - height, yy));
mNextScrubRect = wxRect(xx, yy, width, height);
}
#ifdef EXPERIMENTAL_SCRUBBING_SMOOTH_SCROLL
if (mSmoothScrollingScrub) {
// Pan the view, so that we center the play indicator.
const int posX = mViewInfo->TimeToPosition(playPos);
int width;
GetTracksUsableArea(&width, NULL);
const int deltaX = posX - width / 2;
mViewInfo->h =
mViewInfo->OffsetTimeByPixels(mViewInfo->h, deltaX, true);
if (!mScrollBeyondZero)
// Can't scroll too far left
mViewInfo->h = std::max(0.0, mViewInfo->h);
Refresh(false);
}
#endif
}
std::pair<wxRect, bool> TrackPanel::GetScrubSpeedRectangle()

View File

@ -258,7 +258,7 @@ class AUDACITY_DLL_API TrackPanel:public wxPanel {
virtual bool IsOverCutline(WaveTrack * track, wxRect &rect, wxMouseEvent &event);
virtual void HandleTrackSpecificMouseEvent(wxMouseEvent & event);
virtual void TimerUpdateIndicator();
virtual void TimerUpdateIndicator(double playPos);
// Second member of pair indicates whether the indicator is out of date:
virtual std::pair<wxRect, bool> GetIndicatorRectangle();
virtual void UndrawIndicator(wxDC & dc);
@ -272,7 +272,7 @@ class AUDACITY_DLL_API TrackPanel:public wxPanel {
#ifdef EXPERIMENTAL_SCRUBBING_BASIC
bool ShouldDrawScrubSpeed();
virtual void TimerUpdateScrubbing();
virtual void TimerUpdateScrubbing(double playPos);
// Second member of pair indicates whether the cursor is out of date:
virtual std::pair<wxRect, bool> GetScrubSpeedRectangle();
virtual void UndrawScrubSpeed(wxDC & dc);