Skip to content

Commit

Permalink
stop tearing playhead
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxshao committed Jan 23, 2022
1 parent 3b34066 commit 67723d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
15 changes: 11 additions & 4 deletions src/editor/views/MooClock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ MooClock::MooClock(PxtoneClient *client)
m_prev_clock(0),
m_prev_moo_clock(0),
m_this_seek(0),
m_clock(0),
m_animation(new Animation(this)),
m_this_seek_caught_up(false) {
// Ticking is controlled by 1 animation, vs. recomputing [now] every time it's
// called, because different views call [now] possibly at different times.
connect(m_animation, &Animation::valueChanged, this, &MooClock::tick);
connect(m_client->controller(), &PxtoneController::seeked, [this](int clock) {
m_this_seek = clock;
m_this_seek_caught_up = false;
m_prev_clock = 0;
});
}

int MooClock::nowNoWrap() {
void MooClock::tick() {
int clock = m_client->pxtn()->moo_get_now_clock(*m_client->moo());

// Some really hacky magic to get the playhead smoother given that
Expand Down Expand Up @@ -64,11 +69,11 @@ int MooClock::nowNoWrap() {
if (clock >= m_this_seek) m_this_seek_caught_up = true;
if (!m_this_seek_caught_up) clock = m_this_seek;

return clock;
m_clock = clock;
}

int MooClock::now() {
return MasterExtended::wrapClock(m_client->pxtn()->master, nowNoWrap());
int MooClock::now() const {
return MasterExtended::wrapClock(m_client->pxtn()->master, m_clock);

// 2021-01-18: I'm not actually sure when this case will happen. So I've
// commented it out.
Expand All @@ -79,6 +84,8 @@ int MooClock::now() {
// clock += last_clock() - repeat_clock();
}

int MooClock::nowNoWrap() const { return m_clock; }

int MooClock::last_clock() const {
return MasterExtended::last_clock(m_client->pxtn()->master);
}
Expand Down
9 changes: 6 additions & 3 deletions src/editor/views/MooClock.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QElapsedTimer>
#include <QObject>

#include "Animation.h"
#include "editor/PxtoneClient.h"

// A bunch of things to give the illusion of a smooth playhead when there's a
Expand All @@ -12,15 +13,17 @@ class MooClock : public QObject {
Q_OBJECT

PxtoneClient *m_client;
int m_prev_clock, m_prev_moo_clock, m_this_seek;
int m_prev_clock, m_prev_moo_clock, m_this_seek, m_clock;
Animation *m_animation;
bool m_this_seek_caught_up;
QElapsedTimer timeSinceLastClock;

public:
explicit MooClock(PxtoneClient *client);

int now();
int nowNoWrap();
void tick();
int now() const;
int nowNoWrap() const;
bool this_seek_caught_up() const { return m_this_seek_caught_up; }
bool has_last() const;
int wrapClock(int clock) const;
Expand Down

0 comments on commit 67723d1

Please sign in to comment.