From cf0bf0f188e3afb2e4be75ac02dfec88bc7cb32e Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Fri, 12 May 2023 18:09:04 +0300 Subject: [PATCH] Fixed bug when EXT-B continued playing after incoming triggers stopped --- software/GToE/GToE.ino | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/software/GToE/GToE.ino b/software/GToE/GToE.ino index 6bbb6ed..63d70ab 100644 --- a/software/GToE/GToE.ino +++ b/software/GToE/GToE.ino @@ -106,7 +106,6 @@ void setup() { saveState(); EEPROM.write(1023, 'R'); } - calculateCycles(); pinMode(ENC_BTN_PIN, INPUT_PULLUP); pinMode(START_STOP_BTN_PIN, INPUT_PULLUP); @@ -131,9 +130,10 @@ void setup() { delay(800); updateScreen(); - updateTiming(); + calculateCycles(); + calculateBPMTiming(); - FlexiTimer2::set(1, 1.0/1000, clock); // 1.0/1000 = 1ms period. If other than 1ms updateTiming() might need tweaking + FlexiTimer2::set(1, 1.0/1000, clock); // 1.0/1000 = 1ms period. If other than 1ms calculateBPMTiming() might need tweaking FlexiTimer2::start(); } @@ -143,30 +143,41 @@ void loop() { display.clearDisplay(); display.display(); } + if (masterClockMode == 2) { + calculateBPMTiming(); + } } void clock() { if (isPlaying) { // Action on each pulse - if (tickCount == 0) { //&& masterClockMode == 0) { + if (tickCount == 0) { sendTriggers(); } //this part gets the Pulse and Ticks ticking //it's placed after the triggers to avoid problems on the start (when pulseCount==0) tickCount++; - if (masterClockMode == 0 || 2) { + if (masterClockMode == 0) { if (tickCount == pulsePeriod) { tickCount = 0; if (pulseCount < (PPQN-1)) { //-1 is here to avoid extra IF to reset to 0 pulseCount++; - } else if (masterClockMode == 0) { + } else { pulseCount = 0; } } } + //EXT-B + if (masterClockMode == 2) { + if (tickCount == pulsePeriod && pulseCount < (PPQN-1)) { + tickCount = 0; + pulseCount++; + } + } + // pull low all outputs after set pulse length if (tickCount >= PULSE_LENGTH) { for (int i = 0; i<6; i++) { @@ -220,9 +231,6 @@ void sendTriggers() { //switching modes on the beat and resetting channel clock if (pulseCount == 0) { - if (masterClockMode == 2) { - updateTiming(); - } calculateCycles(); for (int i = 0; i<6; i++) { if (needPulseReset[i] == true) { @@ -272,7 +280,7 @@ void calculateCycles() { } } -void updateTiming() { +void calculateBPMTiming() { if (masterClockMode == 0) { pulsePeriod = 60000 / (bpm * PPQN); } else if (masterClockMode == 2) { //for external beat clock @@ -346,7 +354,7 @@ void checkInputs() { } else if (bpm < MINBPM) { bpm = MINBPM; } - updateTiming(); + calculateBPMTiming(); } else if (displayTab != 0 && insideTab == 0) { //subdivision channels[displayTab-1].mode = channels[displayTab-1].mode - change; if (channels[displayTab-1].mode == 65535) { //65535 is 0-1 for unsigned vars