ViewInfo does not depend on AudioIOBase...

... ViewInfo should only be concerned with screen geometry.

(And so it won't depend on AudioIO (even higher level) after stream time moves
there.)

PlaybackScroller receives the timer event directly (not from ViewInfo) and
caches playback position instead.  Then, as before, it propagates the event
to PlayIndicatorOverlay.
This commit is contained in:
Paul Licameli 2020-12-17 11:58:31 -05:00
parent aa8e4eef06
commit d92a68f076
5 changed files with 18 additions and 32 deletions

View File

@ -1660,7 +1660,7 @@ void ProjectWindow::TP_HandleResize()
ProjectWindow::PlaybackScroller::PlaybackScroller(AudacityProject *project)
: mProject(project)
{
ViewInfo::Get( *mProject ).Bind(EVT_TRACK_PANEL_TIMER,
mProject->Bind(EVT_TRACK_PANEL_TIMER,
&PlaybackScroller::OnTimer,
this);
}
@ -1670,9 +1670,12 @@ void ProjectWindow::PlaybackScroller::OnTimer(wxCommandEvent &event)
// Let other listeners get the notification
event.Skip();
auto gAudioIO = AudioIOBase::Get();
mRecentStreamTime = gAudioIO->GetStreamTime();
auto cleanup = finally([&]{
// Propagate the message to other listeners bound to this
this->ProcessEvent( event );
this->SafelyProcessEvent( event );
});
if(!ProjectAudioIO::Get( *mProject ).IsAudioActive())
@ -1692,7 +1695,7 @@ void ProjectWindow::PlaybackScroller::OnTimer(wxCommandEvent &event)
auto &viewInfo = ViewInfo::Get( *mProject );
auto &trackPanel = GetProjectPanel( *mProject );
const int posX = viewInfo.TimeToPosition(viewInfo.mRecentStreamTime);
const int posX = viewInfo.TimeToPosition(mRecentStreamTime);
auto width = viewInfo.GetTracksUsableWidth();
int deltaX;
switch (mMode)

View File

@ -75,11 +75,17 @@ public:
mMode = mode;
}
double GetRecentStreamTime() const { return mRecentStreamTime; }
private:
void OnTimer(wxCommandEvent &event);
AudacityProject *mProject;
Mode mMode { Mode::Off };
// During timer update, grab the volatile stream time just once, so that
// various other drawing code can use the exact same value.
double mRecentStreamTime{ -1.0 };
};
PlaybackScroller &GetPlaybackScroller() { return *mPlaybackScroller; }

View File

@ -14,7 +14,6 @@ Paul Licameli
#include <algorithm>
#include "AudioIOBase.h"
#include "Prefs.h"
#include "Project.h"
#include "xml/XMLWriter.h"
@ -150,12 +149,7 @@ void NotifyingSelectedRegion::Notify( bool delayed )
static const AudacityProject::AttachedObjects::RegisteredFactory key{
[]( AudacityProject &project ) {
auto result =
std::make_unique<ViewInfo>(0.0, 1.0, ZoomInfo::GetDefaultZoom());
project.Bind(EVT_TRACK_PANEL_TIMER,
&ViewInfo::OnTimer,
result.get());
return std::move( result );
return std::make_unique<ViewInfo>(0.0, 1.0, ZoomInfo::GetDefaultZoom());
}
};
@ -180,7 +174,6 @@ ViewInfo::ViewInfo(double start, double screenDuration, double pixelsPerSecond)
, scrollStep(16)
, bUpdateTrackIndicator(true)
, bScrollBeyondZero(false)
, mRecentStreamTime(-1.0)
{
UpdatePrefs();
}
@ -248,15 +241,6 @@ bool ViewInfo::ReadXMLAttribute(const wxChar *attr, const wxChar *value)
return false;
}
void ViewInfo::OnTimer(wxCommandEvent &event)
{
auto gAudioIO = AudioIOBase::Get();
mRecentStreamTime = gAudioIO->GetStreamTime();
event.Skip();
// Propagate the message to other listeners bound to this
this->ProcessEvent( event );
}
int ViewInfo::UpdateScrollPrefsID()
{
static int value = wxNewId();

View File

@ -224,16 +224,9 @@ public:
bool bScrollBeyondZero;
bool bAdjustSelectionEdges;
// During timer update, grab the volatile stream time just once, so that
// various other drawing code can use the exact same value.
double mRecentStreamTime;
void WriteXMLAttributes(XMLWriter &xmlFile) const;
bool ReadXMLAttribute(const wxChar *attr, const wxChar *value);
// Receive track panel timer notifications
void OnTimer(wxCommandEvent &event);
private:
int mHeight{ 0 };
};

View File

@ -174,13 +174,13 @@ void PlayIndicatorOverlay::OnTimer(wxCommandEvent &event)
}
}
else {
// Calculate the horizontal position of the indicator
const double playPos = viewInfo.mRecentStreamTime;
auto &window = ProjectWindow::Get( *mProject );
auto &scroller = window.GetPlaybackScroller();
// Calculate the horizontal position of the indicator
const double playPos = scroller.GetRecentStreamTime();
using Mode = ProjectWindow::PlaybackScroller::Mode;
const Mode mode =
window.GetPlaybackScroller().GetMode();
const Mode mode = scroller.GetMode();
const bool pinned = ( mode == Mode::Pinned || mode == Mode::Right );
// Use a small tolerance to avoid flicker of play head pinned all the way