Bad try at adding 1/16 ext clock. seems like ext beat clock is also brocken

This commit is contained in:
--global
2023-05-20 00:32:33 +03:00
parent ca2e5bf551
commit 504d78d200

View File

@ -18,7 +18,7 @@
#define ENC_D2_PIN 4 #define ENC_D2_PIN 4
#define START_STOP_BTN_PIN 5 #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_1_PIN A2
#define ANALOGUE_INPUT_2_PIN A1 #define ANALOGUE_INPUT_2_PIN A1
@ -56,6 +56,7 @@ bool isPlaying = false;
unsigned int tickCount = 0; unsigned int tickCount = 0;
unsigned int pulseCount = 0; unsigned int pulseCount = 0;
unsigned int extTriggerCount = 0;
byte masterClockMode = 0; // 0 - internal, 1 - external 24ppqn, 2 - external beat byte masterClockMode = 0; // 0 - internal, 1 - external 24ppqn, 2 - external beat
unsigned long lastExtPulseTime; unsigned long lastExtPulseTime;
@ -120,8 +121,8 @@ void setup() {
pinMode(ENC_BTN_PIN, INPUT_PULLUP); pinMode(ENC_BTN_PIN, INPUT_PULLUP);
pinMode(START_STOP_BTN_PIN, INPUT_PULLUP); pinMode(START_STOP_BTN_PIN, INPUT_PULLUP);
pinMode(START_STOP_BTN_PIN, ANALOGUE_INPUT_1_PIN); pinMode(START_STOP_BTN_PIN, ANALOGUE_INPUT_1_PIN);
pinMode(INPUT_PIN, INPUT_PULLUP); pinMode(EXT_INPUT_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(INPUT_PIN), externalClock, FALLING); attachInterrupt(digitalPinToInterrupt(EXT_INPUT_PIN), externalClock, FALLING);
for (int i=0; i<6; i++) { for (int i=0; i<6; i++) {
pinMode(outsPins[i], OUTPUT); pinMode(outsPins[i], OUTPUT);
@ -153,7 +154,7 @@ void loop() {
display.clearDisplay(); display.clearDisplay();
display.display(); display.display();
} }
if (masterClockMode == 2) { //&& tickCount > PULSE_LENGTH) { //execute only after PULSE_LENGTH to avoid delays if (masterClockMode == 2 || masterClockMode == 3) {
calculateBPMTiming(); calculateBPMTiming();
} }
} }
@ -170,7 +171,7 @@ void clock() {
//it's placed after the triggers to avoid problems on the start (when pulseCount==0) //it's placed after the triggers to avoid problems on the start (when pulseCount==0)
tickCount++; tickCount++;
if (masterClockMode == 0) { if (masterClockMode == 0) {
if (tickCount == pulsePeriod) { if (tickCount >= pulsePeriod) {
tickCount = 0; tickCount = 0;
if (pulseCount < (PPQN-1)) { //-1 is here to avoid extra IF to reset to 0 if (pulseCount < (PPQN-1)) { //-1 is here to avoid extra IF to reset to 0
pulseCount++; pulseCount++;
@ -184,13 +185,21 @@ void clock() {
} }
//EXT-B //EXT-B
if (masterClockMode == 2) { if (masterClockMode == 2 || masterClockMode == 3) {
if (tickCount >= pulsePeriod && pulseCount < (PPQN-1)) { if (tickCount >= pulsePeriod && pulseCount < (PPQN-1)) {
tickCount = 0; tickCount = 0;
pulseCount++; 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 // pull low all outputs after set pulse length
if (tickCount >= PULSE_LENGTH) { if (tickCount >= PULSE_LENGTH) {
for (int i = 0; i<6; i++) { for (int i = 0; i<6; i++) {
@ -206,7 +215,6 @@ void externalClock() {
newExtPulseTime = millis(); newExtPulseTime = millis();
if (masterClockMode == 1) { // EXT-24 if (masterClockMode == 1) { // EXT-24
//reset cycles if there was no pulses for a while //reset cycles if there was no pulses for a while
if ((newExtPulseTime - lastExtPulseTime) > 125) { //125ms is 20bpm if ((newExtPulseTime - lastExtPulseTime) > 125) { //125ms is 20bpm
for (int i = 0; i<6; i++) { for (int i = 0; i<6; i++) {
@ -233,6 +241,24 @@ void externalClock() {
} }
tickCount = 0; tickCount = 0;
pulseCount = 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 } else if (masterClockMode == 2) { //for external beat clock
pulsePeriod = (newExtPulseTime - lastExtPulseTime) / PPQN; 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; bpm = MINBPM;
} }
calculateBPMTiming(); calculateBPMTiming();
} else if (displayTab == 0 && insideTab == 1) { //Clock mode } else if (displayTab == 0 && insideTab == 1) { //Clock mode
masterClockMode = masterClockMode + change; masterClockMode = masterClockMode + change;
if (masterClockMode == 3) { if (masterClockMode > 250) {
masterClockMode = 2;
} else if (masterClockMode == 255) {
masterClockMode = 0; masterClockMode = 0;
} else if (masterClockMode > 3) {
masterClockMode = 3;
} }
} else if (displayTab == 0 && insideTab == 2 && masterClockMode == 0) { //bpm modulation } else if (displayTab == 0 && insideTab == 2 && masterClockMode == 0) { //bpm modulation
bpmModulationRange = bpmModulationRange + change; bpmModulationRange = bpmModulationRange + change;
if (bpmModulationRange == 255 && bpmModulationChannel == 0) { if (bpmModulationRange == 255 && bpmModulationChannel == 0) {
@ -411,6 +442,7 @@ void checkInputs() {
if (!isPlaying) { if (!isPlaying) {
calculateCycles(); calculateCycles();
} }
} else if (displayTab != 0 && insideTab == 1) { //random } else if (displayTab != 0 && insideTab == 1) { //random
channels[displayTab-1].random = channels[displayTab-1].random + change; channels[displayTab-1].random = channels[displayTab-1].random + change;
if (channels[displayTab-1].random == 65535) { if (channels[displayTab-1].random == 65535) {
@ -418,6 +450,7 @@ void checkInputs() {
} else if (channels[displayTab-1].random > 9) { } else if (channels[displayTab-1].random > 9) {
channels[displayTab-1].random = 9; channels[displayTab-1].random = 9;
} }
} else if (displayTab != 0 && insideTab == 2) { //modulation } else if (displayTab != 0 && insideTab == 2) { //modulation
channels[displayTab-1].modulationRange = channels[displayTab-1].modulationRange + change; channels[displayTab-1].modulationRange = channels[displayTab-1].modulationRange + change;
if (channels[displayTab-1].modulationRange < 0 && channels[displayTab-1].modulationChannel == 0) { if (channels[displayTab-1].modulationRange < 0 && channels[displayTab-1].modulationChannel == 0) {
@ -432,10 +465,6 @@ void checkInputs() {
channels[displayTab-1].modulationRange = 6; 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 } else if (displayTab != 0 && insideTab == 3) { //offset
channels[displayTab-1].offset = channels[displayTab-1].offset + change; channels[displayTab-1].offset = channels[displayTab-1].offset + change;
if (channels[displayTab-1].offset == 65535) { if (channels[displayTab-1].offset == 65535) {
@ -527,6 +556,10 @@ void updateScreen() {
display.setCursor(8,16); display.setCursor(8,16);
display.setTextSize(2); display.setTextSize(2);
display.println(F("BEAT")); display.println(F("BEAT"));
} else if (displayTab == 0 && masterClockMode == 3) {
display.setCursor(8,16);
display.setTextSize(2);
display.println(F("1/16"));
} else { } else {
if (clockModes[channels[displayTab-1].mode] == 0) { if (clockModes[channels[displayTab-1].mode] == 0) {
display.print(F("OFF")); display.print(F("OFF"));
@ -556,6 +589,8 @@ void updateScreen() {
display.println(F("EXT24 ")); display.println(F("EXT24 "));
} else if (masterClockMode == 2) { } else if (masterClockMode == 2) {
display.println(F("EXT-B ")); display.println(F("EXT-B "));
} else if (masterClockMode == 3) {
display.println(F("EXT16 "));
} else { } else {
display.println(F("INT ")); display.println(F("INT "));
} }