mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-21 14:50:06 +02:00
Reorder some things that happen in the track panel timer update.
This commit is contained in:
parent
67c794891d
commit
c45ea059e6
@ -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,60 +7463,76 @@ void TrackPanel::TimerUpdateScrubbing()
|
||||
|
||||
if (!ShouldDrawScrubSpeed()) {
|
||||
mNextScrubRect = wxRect();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
int panelWidth, panelHeight;
|
||||
GetSize(&panelWidth, &panelHeight);
|
||||
|
||||
// Where's the mouse?
|
||||
int xx, yy;
|
||||
::wxGetMousePosition(&xx, &yy);
|
||||
ScreenToClient(&xx, &yy);
|
||||
|
||||
const bool seeking = PollIsSeeking();
|
||||
|
||||
// Find the text
|
||||
const double speed =
|
||||
#ifdef EXPERIMENTAL_SCRUBBING_SMOOTH_SCROLL
|
||||
mSmoothScrollingScrub
|
||||
? seeking
|
||||
? FindSeekSpeed(mViewInfo->PositionToTime(xx, GetLeftOffset()))
|
||||
: FindScrubSpeed(mViewInfo->PositionToTime(xx, GetLeftOffset()))
|
||||
:
|
||||
#endif
|
||||
mMaxScrubSpeed;
|
||||
|
||||
const wxChar *format =
|
||||
#ifdef EXPERIMENTAL_SCRUBBING_SMOOTH_SCROLL
|
||||
mSmoothScrollingScrub
|
||||
? seeking
|
||||
? wxT("%+.2fX")
|
||||
: wxT("%+.2f")
|
||||
:
|
||||
#endif
|
||||
wxT("%.2f");
|
||||
|
||||
mScrubSpeedText = wxString::Format(format, speed);
|
||||
|
||||
// Find the origin for drawing text
|
||||
wxCoord width, height;
|
||||
{
|
||||
wxClientDC dc(this);
|
||||
static const wxFont labelFont(24, wxSWISS, wxNORMAL, wxNORMAL);
|
||||
dc.SetFont(labelFont);
|
||||
dc.GetTextExtent(mScrubSpeedText, &width, &height);
|
||||
}
|
||||
xx = std::max(0, std::min(panelWidth - width, xx - width / 2));
|
||||
|
||||
// Put the text above the cursor, if it fits.
|
||||
enum { offset = 20 };
|
||||
yy -= height + offset;
|
||||
if (yy < 0)
|
||||
yy += height + 2 * offset;
|
||||
yy = std::max(0, std::min(panelHeight - height, yy));
|
||||
|
||||
mNextScrubRect = wxRect(xx, yy, width, height);
|
||||
}
|
||||
|
||||
int panelWidth, panelHeight;
|
||||
GetSize(&panelWidth, &panelHeight);
|
||||
|
||||
// Where's the mouse?
|
||||
int xx, yy;
|
||||
::wxGetMousePosition(&xx, &yy);
|
||||
ScreenToClient(&xx, &yy);
|
||||
|
||||
const bool seeking = PollIsSeeking();
|
||||
|
||||
// Find the text
|
||||
const double speed =
|
||||
#ifdef EXPERIMENTAL_SCRUBBING_SMOOTH_SCROLL
|
||||
mSmoothScrollingScrub
|
||||
? seeking
|
||||
? FindSeekSpeed(mViewInfo->PositionToTime(xx, GetLeftOffset()))
|
||||
: FindScrubSpeed(mViewInfo->PositionToTime(xx, GetLeftOffset()))
|
||||
:
|
||||
#endif
|
||||
mMaxScrubSpeed;
|
||||
|
||||
const wxChar *format =
|
||||
#ifdef EXPERIMENTAL_SCRUBBING_SMOOTH_SCROLL
|
||||
mSmoothScrollingScrub
|
||||
? seeking
|
||||
? wxT("%+.2fX")
|
||||
: wxT("%+.2f")
|
||||
:
|
||||
#endif
|
||||
wxT("%.2f");
|
||||
|
||||
mScrubSpeedText = wxString::Format(format, speed);
|
||||
|
||||
// Find the origin for drawing text
|
||||
wxCoord width, height;
|
||||
{
|
||||
wxClientDC dc(this);
|
||||
static const wxFont labelFont(24, wxSWISS, wxNORMAL, wxNORMAL);
|
||||
dc.SetFont(labelFont);
|
||||
dc.GetTextExtent(mScrubSpeedText, &width, &height);
|
||||
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);
|
||||
}
|
||||
xx = std::max(0, std::min(panelWidth - width, xx - width / 2));
|
||||
|
||||
// Put the text above the cursor, if it fits.
|
||||
enum { offset = 20 };
|
||||
yy -= height + offset;
|
||||
if (yy < 0)
|
||||
yy += height + 2 * offset;
|
||||
yy = std::max(0, std::min(panelHeight - height, yy));
|
||||
|
||||
mNextScrubRect = wxRect(xx, yy, width, height);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::pair<wxRect, bool> TrackPanel::GetScrubSpeedRectangle()
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user