From 504d78d2000274e426f6e3db3126edf801df5042 Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Sat, 20 May 2023 00:32:33 +0300 Subject: [PATCH] Bad try at adding 1/16 ext clock. seems like ext beat clock is also brocken --- software/GToE/GToE.ino | 63 ++++++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/software/GToE/GToE.ino b/software/GToE/GToE.ino index 2dc89ac..3c4aded 100644 --- a/software/GToE/GToE.ino +++ b/software/GToE/GToE.ino @@ -18,7 +18,7 @@ #define ENC_D2_PIN 4 #define START_STOP_BTN_PIN 5 -#define INPUT_PIN 2 //needs to be an interrupt pin +#define EXT_INPUT_PIN 2 //needs to be an interrupt pin #define ANALOGUE_INPUT_1_PIN A2 #define ANALOGUE_INPUT_2_PIN A1 @@ -56,6 +56,7 @@ bool isPlaying = false; unsigned int tickCount = 0; unsigned int pulseCount = 0; +unsigned int extTriggerCount = 0; byte masterClockMode = 0; // 0 - internal, 1 - external 24ppqn, 2 - external beat unsigned long lastExtPulseTime; @@ -120,8 +121,8 @@ void setup() { pinMode(ENC_BTN_PIN, INPUT_PULLUP); pinMode(START_STOP_BTN_PIN, INPUT_PULLUP); pinMode(START_STOP_BTN_PIN, ANALOGUE_INPUT_1_PIN); - pinMode(INPUT_PIN, INPUT_PULLUP); - attachInterrupt(digitalPinToInterrupt(INPUT_PIN), externalClock, FALLING); + pinMode(EXT_INPUT_PIN, INPUT_PULLUP); + attachInterrupt(digitalPinToInterrupt(EXT_INPUT_PIN), externalClock, FALLING); for (int i=0; i<6; i++) { pinMode(outsPins[i], OUTPUT); @@ -153,7 +154,7 @@ void loop() { display.clearDisplay(); display.display(); } - if (masterClockMode == 2) { //&& tickCount > PULSE_LENGTH) { //execute only after PULSE_LENGTH to avoid delays + if (masterClockMode == 2 || masterClockMode == 3) { calculateBPMTiming(); } } @@ -170,7 +171,7 @@ void clock() { //it's placed after the triggers to avoid problems on the start (when pulseCount==0) tickCount++; if (masterClockMode == 0) { - if (tickCount == pulsePeriod) { + if (tickCount >= pulsePeriod) { tickCount = 0; if (pulseCount < (PPQN-1)) { //-1 is here to avoid extra IF to reset to 0 pulseCount++; @@ -184,13 +185,21 @@ void clock() { } //EXT-B - if (masterClockMode == 2) { + if (masterClockMode == 2 || masterClockMode == 3) { if (tickCount >= pulsePeriod && pulseCount < (PPQN-1)) { tickCount = 0; pulseCount++; } } + //EXT-16 + /*if (masterClockMode == 3) { + if (tickCount >= pulsePeriod && pulseCount < ((PPQN*2)-1)) { // ((6 * (extTriggerCount + 1))-1)) { //hardcoded for 24ppqn + tickCount = 0; + pulseCount++; + } + }*/ + // pull low all outputs after set pulse length if (tickCount >= PULSE_LENGTH) { for (int i = 0; i<6; i++) { @@ -206,7 +215,6 @@ void externalClock() { newExtPulseTime = millis(); if (masterClockMode == 1) { // EXT-24 - //reset cycles if there was no pulses for a while if ((newExtPulseTime - lastExtPulseTime) > 125) { //125ms is 20bpm for (int i = 0; i<6; i++) { @@ -233,6 +241,24 @@ void externalClock() { } tickCount = 0; pulseCount = 0; + + } else if (masterClockMode == 3) { // EXT-1/16 + if (!isPlaying) { + isPlaying = true; + } + if ((newExtPulseTime - lastExtPulseTime) > 750) { //750ms is 1/16 at 20bpm + resetClocks(); + } + tickCount = 0; + if (extTriggerCount == 0) { + pulseCount = 0; + } + + if (extTriggerCount < 3) { + extTriggerCount++; + } else { + extTriggerCount = 0; + } } } @@ -307,6 +333,9 @@ void calculateBPMTiming() { } else if (masterClockMode == 2) { //for external beat clock pulsePeriod = (newExtPulseTime - lastExtPulseTime) / PPQN; + + } else if (masterClockMode == 3) { //for external 1/16 clock + pulsePeriod = (newExtPulseTime - lastExtPulseTime) / 6; //6 is hardcoded 1/16 at 24ppqn } } @@ -380,13 +409,15 @@ void checkInputs() { bpm = MINBPM; } calculateBPMTiming(); + } else if (displayTab == 0 && insideTab == 1) { //Clock mode masterClockMode = masterClockMode + change; - if (masterClockMode == 3) { - masterClockMode = 2; - } else if (masterClockMode == 255) { + if (masterClockMode > 250) { masterClockMode = 0; + } else if (masterClockMode > 3) { + masterClockMode = 3; } + } else if (displayTab == 0 && insideTab == 2 && masterClockMode == 0) { //bpm modulation bpmModulationRange = bpmModulationRange + change; if (bpmModulationRange == 255 && bpmModulationChannel == 0) { @@ -411,6 +442,7 @@ void checkInputs() { if (!isPlaying) { calculateCycles(); } + } else if (displayTab != 0 && insideTab == 1) { //random channels[displayTab-1].random = channels[displayTab-1].random + change; if (channels[displayTab-1].random == 65535) { @@ -418,6 +450,7 @@ void checkInputs() { } else if (channels[displayTab-1].random > 9) { channels[displayTab-1].random = 9; } + } else if (displayTab != 0 && insideTab == 2) { //modulation channels[displayTab-1].modulationRange = channels[displayTab-1].modulationRange + change; if (channels[displayTab-1].modulationRange < 0 && channels[displayTab-1].modulationChannel == 0) { @@ -432,10 +465,6 @@ void checkInputs() { channels[displayTab-1].modulationRange = 6; } - /*if (channels[displayTab-1].modulationRange > 6 || channels[displayTab-1].modulationRange < -6) { - channels[displayTab-1].modulationChannel = !channels[displayTab-1].modulationChannel; - channels[displayTab-1].modulationRange = 0; - }*/ } else if (displayTab != 0 && insideTab == 3) { //offset channels[displayTab-1].offset = channels[displayTab-1].offset + change; if (channels[displayTab-1].offset == 65535) { @@ -527,6 +556,10 @@ void updateScreen() { display.setCursor(8,16); display.setTextSize(2); display.println(F("BEAT")); + } else if (displayTab == 0 && masterClockMode == 3) { + display.setCursor(8,16); + display.setTextSize(2); + display.println(F("1/16")); } else { if (clockModes[channels[displayTab-1].mode] == 0) { display.print(F("OFF")); @@ -556,6 +589,8 @@ void updateScreen() { display.println(F("EXT24 ")); } else if (masterClockMode == 2) { display.println(F("EXT-B ")); + } else if (masterClockMode == 3) { + display.println(F("EXT16 ")); } else { display.println(F("INT ")); }