diff --git a/software/GToE/GToE.ino b/software/GToE/GToE.ino index 3c4aded..62355a3 100644 --- a/software/GToE/GToE.ino +++ b/software/GToE/GToE.ino @@ -57,6 +57,7 @@ bool isPlaying = false; unsigned int tickCount = 0; unsigned int pulseCount = 0; unsigned int extTriggerCount = 0; +byte extResetCountdown = 0; byte masterClockMode = 0; // 0 - internal, 1 - external 24ppqn, 2 - external beat unsigned long lastExtPulseTime; @@ -185,7 +186,7 @@ void clock() { } //EXT-B - if (masterClockMode == 2 || masterClockMode == 3) { + if (masterClockMode == 2) { if (tickCount >= pulsePeriod && pulseCount < (PPQN-1)) { tickCount = 0; pulseCount++; @@ -193,12 +194,12 @@ void clock() { } //EXT-16 - /*if (masterClockMode == 3) { - if (tickCount >= pulsePeriod && pulseCount < ((PPQN*2)-1)) { // ((6 * (extTriggerCount + 1))-1)) { //hardcoded for 24ppqn + if (masterClockMode == 3) { + if (tickCount >= pulsePeriod && pulseCount < ((6 * (extTriggerCount + 1))-1)) { //hardcoded for 24ppqn tickCount = 0; pulseCount++; } - }*/ + } // pull low all outputs after set pulse length if (tickCount >= PULSE_LENGTH) { @@ -238,27 +239,41 @@ void externalClock() { } if ((newExtPulseTime - lastExtPulseTime) > 3000) { //3000ms is 1/4 at 20bpm resetClocks(); + extResetCountdown = 0; } tickCount = 0; pulseCount = 0; + if (extResetCountdown < 1) { //reset on the second pulse, so that BPM is already calculated correctly + extResetCountdown++; + } else if (extResetCountdown == 1) { + resetClocks(); + extResetCountdown++; //to get out of the loop + } } else if (masterClockMode == 3) { // EXT-1/16 if (!isPlaying) { isPlaying = true; } - if ((newExtPulseTime - lastExtPulseTime) > 750) { //750ms is 1/16 at 20bpm + if ((newExtPulseTime - lastExtPulseTime) > 1000) { //750ms is 1/16 at 20bpm resetClocks(); + extResetCountdown = 0; } tickCount = 0; if (extTriggerCount == 0) { pulseCount = 0; } - if (extTriggerCount < 3) { + if (extTriggerCount < 2) { extTriggerCount++; } else { extTriggerCount = 0; } + if (extResetCountdown < 4) { //reset on the first beat (5th pulse), so that BPM is already calculated correctly + extResetCountdown++; + } else if (extResetCountdown == 4) { + resetClocks(); + extResetCountdown++; //to get out of the loop + } } }