aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2021-06-04 22:23:19 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2021-06-04 22:23:19 +0800
commit9981f1d60352c01ae4373b84acd05460e2aa49d5 (patch)
tree3c75ad61509a3a58663c706015edbe9d82fe103f
parent28402bb0af8d1ca1e1c6c9408ebe18738c19c0da (diff)
downloadQMidiPlayer-9981f1d60352c01ae4373b84acd05460e2aa49d5.tar.xz
Rendered visualization should no longer drift away from correct timing...
... after tempo changes.
-rw-r--r--visualization/qmpvisualization.cpp14
-rw-r--r--visualization/qmpvisualization.hpp1
2 files changed, 14 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;
diff --git a/visualization/qmpvisualization.hpp b/visualization/qmpvisualization.hpp
index c0bc067..c53f548 100644
--- a/visualization/qmpvisualization.hpp
+++ b/visualization/qmpvisualization.hpp
@@ -42,6 +42,7 @@ private:
uint32_t rpnid[16], rpnval[16];
std::chrono::steady_clock::time_point lst;
double etps;
+ double roffset;
bool shouldclose, playing, debug;
bool rendermode, hidewindow;
int herh, heh, hfrf;