From 2d3c3dd683dd389a7f17f1589ee43e119d690fb7 Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Fri, 12 May 2023 01:08:36 +0300 Subject: [PATCH] fixed unwanted offset when changing subdiv with external clock, also seems like there's almost no delay between external trigger and outputs --- software/GToE/GToE.ino | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/software/GToE/GToE.ino b/software/GToE/GToE.ino index a0b6dce..a7b7d37 100644 --- a/software/GToE/GToE.ino +++ b/software/GToE/GToE.ino @@ -54,8 +54,7 @@ bool isPlaying = false; unsigned int tickCount = 0; unsigned int pulseCount = 0; -unsigned int masterClockMode = 0; // 0 - internal, 1 - external 24ppqn, 2 - external beat -bool externalPulseCounted = true; +byte masterClockMode = 0; // 0 - internal, 1 - external 24ppqn, 2 - external beat unsigned long lastExtPulseTime; unsigned long newExtPulseTime; @@ -97,12 +96,13 @@ void setup() { //Serial.begin(9600); //check last bit in eeprom to know if settings were stored - if (EEPROM.read(1023) == 'K') { + if (EEPROM.read(1023) == 'R') { EEPROM.get(0, bpm); - EEPROM.get(sizeof(int), channels); + EEPROM.get(sizeof(int), masterClockMode); + EEPROM.get(sizeof(int)+sizeof(byte), channels); } else { saveState(); - EEPROM.write(1023, 'K'); + EEPROM.write(1023, 'R'); } calculateCycles(); @@ -147,7 +147,7 @@ void clock() { if (isPlaying) { // Action on each pulse - if (tickCount == 0 && masterClockMode == 0) { + if (tickCount == 0) { //&& masterClockMode == 0) { sendTriggers(); } @@ -176,19 +176,8 @@ void clock() { } void externalClock() { - externalPulseCounted = false; lastExtPulseTime = newExtPulseTime; newExtPulseTime = millis(); - if (masterClockMode == 1) { - isPlaying = true; - sendTriggers(); - tickCount = 0; - if (pulseCount < (PPQN-1)) { - pulseCount++; - } else { - pulseCount = 0; - } - } //reset cycles if there was no pulses for a while if ((newExtPulseTime - lastExtPulseTime) > 125) { //125ms is 20bpm @@ -196,14 +185,25 @@ void externalClock() { channelPulseCount[i] = 0; } } + + if (masterClockMode == 1) { // EXT-24 + if (!isPlaying) { + isPlaying = true; + } + tickCount = 0; //to make things happen in the main clock function + if (pulseCount < (PPQN-1)) { + pulseCount++; + } else { + pulseCount = 0; + } + } } void sendTriggers() { - calculateCycles(); - //switching modes on the beat and resetting channel clock if (pulseCount == 0) { + calculateCycles(); for (int i = 0; i<6; i++) { if (playingModes[i] != clockModes[channels[i].mode]) { channelPulseCount[i] = 0; @@ -268,7 +268,8 @@ void resetClocks() { void saveState() { EEPROM.put(0, bpm); - EEPROM.put(sizeof(int), channels); + EEPROM.put(sizeof(int), masterClockMode); + EEPROM.put(sizeof(int)+sizeof(byte), channels); } void checkInputs() {