diff options
author | Chris Xiong <chirs241097@gmail.com> | 2021-06-04 22:23:19 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2021-06-04 22:23:19 +0800 |
commit | 9981f1d60352c01ae4373b84acd05460e2aa49d5 (patch) | |
tree | 3c75ad61509a3a58663c706015edbe9d82fe103f /visualization/qmpvisualization.cpp | |
parent | 28402bb0af8d1ca1e1c6c9408ebe18738c19c0da (diff) | |
download | QMidiPlayer-9981f1d60352c01ae4373b84acd05460e2aa49d5.tar.xz |
Rendered visualization should no longer drift away from correct timing...
... after tempo changes.
Diffstat (limited to 'visualization/qmpvisualization.cpp')
-rw-r--r-- | visualization/qmpvisualization.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/visualization/qmpvisualization.cpp b/visualization/qmpvisualization.cpp index 3dc0324..207b8cd 100644 --- a/visualization/qmpvisualization.cpp +++ b/visualization/qmpvisualization.cpp @@ -245,6 +245,7 @@ void qmpVisualization::reset() delete pool[i]; pool.clear(); elb = ctk = lstk = cfr = 0; + roffset = 0; tspool.clear(); cts = 0x0402; cks = 0; @@ -909,7 +910,7 @@ bool qmpVisualization::update() { if (rendermode) { - ctk = 1e6 * (cfr) / tfps / ctp * api->getDivision() + lstk; + ctk = 1e6 * cfr / tfps / ctp * api->getDivision() + lstk; ++cfr; } else @@ -981,11 +982,22 @@ bool qmpVisualization::update() } if (~ltpc && ctp != pool[ltpc]->key) { + uint32_t oldtp = ctp; ctp = pool[ltpc]->key; if (rendermode) { + if (ctk > pool[ltpc]->tcs) + { + double oldtpft = (double)(ctk - pool[ltpc]->tcs) * (oldtp / 1e6 / api->getDivision()); + roffset += oldtpft; + } lstk = pool[ltpc]->tcs; cfr = 1; + while (roffset > 1. / tfps) //usually only run once + { + ++ cfr; + roffset -= 1. / tfps; + } } } int t, r; |