From baa3989502d3655130f9d5149a4afcd05bd50c1c Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 9 Nov 2022 23:52:10 -0500 Subject: [PATCH] fix metronome in virtual tempo --- src/engine/engine.cpp | 1 + src/engine/engine.h | 3 ++- src/engine/playback.cpp | 23 +++++++++++++---------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index aab6b1188..55d3ad1a4 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -2358,6 +2358,7 @@ void DivEngine::reset() { firstTick=false; shallStop=false; shallStopSched=false; + pendingMetroTick=0; nextSpeed=speed1; divider=60; if (curSubSong->customTempo) { diff --git a/src/engine/engine.h b/src/engine/engine.h index 8f57c5794..7bd0ae2e1 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -358,7 +358,7 @@ class DivEngine { double clockDrift; int stepPlay; int changeOrd, changePos, totalSeconds, totalTicks, totalTicksR, totalCmds, lastCmds, cmdsPerSecond, globalPitch; - unsigned char extValue; + unsigned char extValue, pendingMetroTick; unsigned char speed1, speed2; short tempoAccum; DivStatusView view; @@ -1073,6 +1073,7 @@ class DivEngine { cmdsPerSecond(0), globalPitch(0), extValue(0), + pendingMetroTick(0), speed1(3), speed2(3), tempoAccum(0), diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index 24fc92389..708c55105 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -963,6 +963,13 @@ void DivEngine::nextRow() { printf("| %.2x:%s | \x1b[1;33m%3d%s\x1b[m\n",curOrder,pb1,curRow,pb3); } + if (curSubSong->hilightA>0) { + if ((curRow%curSubSong->hilightA)==0) pendingMetroTick=1; + } + if (curSubSong->hilightB>0) { + if ((curRow%curSubSong->hilightB)==0) pendingMetroTick=2; + } + prevOrder=curOrder; prevRow=curRow; @@ -1597,16 +1604,6 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi // 2. check whether we gonna tick if (cycles<=0) { // we have to tick - if (!freelance && stepPlay!=-1 && subticks==1) { - unsigned int realPos=size-(runLeftG>>MASTER_CLOCK_PREC); - if (realPos>=size) realPos=size-1; - if (curSubSong->hilightA>0) { - if ((curRow%curSubSong->hilightA)==0 && ticks==1) metroTick[realPos]=1; - } - if (curSubSong->hilightB>0) { - if ((curRow%curSubSong->hilightB)==0 && ticks==1) metroTick[realPos]=2; - } - } if (nextTick()) { lastLoopPos=size-(runLeftG>>MASTER_CLOCK_PREC); logD("last loop pos: %d for a size of %d and runLeftG of %d",lastLoopPos,size,runLeftG); @@ -1623,6 +1620,12 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi } } } + if (pendingMetroTick) { + unsigned int realPos=size-(runLeftG>>MASTER_CLOCK_PREC); + if (realPos>=size) realPos=size-1; + metroTick[realPos]=pendingMetroTick; + pendingMetroTick=0; + } } else { // 3. tick the clock and fill buffers as needed if (cycles