rearranged bpm screen UI. bpm modulation doesn't work yet, it's only UI

This commit is contained in:
--global
2023-05-12 22:53:49 +03:00
parent 343422c1b5
commit c3f2f5480c

View File

@ -11,7 +11,7 @@
#define PULSE_LENGTH 12 //ms (with 12 ms you can't get higher than 208bpm)
#define MAXBPM 200 //250 at 24ppqn with 5ms pulse will be 50/50 square wave
#define MINBPM 20
#define SCREEN_TIMEOUT 30000 //30 sec
#define SCREEN_TIMEOUT 30000 //Turn display off after 30 sec
#define INPUT_PIN 2 //needs to be an interrupt pin
#define ENC_BTN_PIN 14
@ -26,11 +26,13 @@ const int outsPins[6] = {6, 11, 7, 10, 8, 9};
const int clockModes[17] = {-24, -12, -8, -6, -4, -3, -2, 1, 2, 3, 4, 5, 6, 7, 8, 16, 32}; //positive - divide, negative - multiply, 0 - off
unsigned int bpm = 130;
bool bpmModulationChannel; //0 - CV1, 1 - CV2
byte bpmModulationRange = 0;
struct channel {
unsigned int mode;
unsigned int random;
bool modulationChannel; //0 - A1, 1 - A2
bool modulationChannel; //0 - CV1, 1 - CV2
int modulationRange;
unsigned int offset;
};
@ -222,7 +224,6 @@ void externalClock() {
void sendTriggers() {
for (int i = 0; i<6; i++) {
if (playingModes[i] != clockModes[channels[i].mode]) {
needPulseReset[i] = true;
@ -326,7 +327,7 @@ void checkInputs() {
insideTab = 1;
}
updateScreen();
} else if (encReleasedTime - encPressedTime < 2000 && displayTab != 0) { // longer press (<2s) and switches random mode, longer than 2s presses are ignored
} else if (encReleasedTime - encPressedTime < 2000) { // longer press (<2s) and switches random mode, longer than 2s presses are ignored
if (insideTab == 0) {
insideTab = 1;
} else {
@ -334,18 +335,6 @@ void checkInputs() {
}
updateScreen();
}
else if (encReleasedTime - encPressedTime < 2000 && displayTab == 0) { // switch to external clock mode
if (masterClockMode < 2) {
masterClockMode++;
} else {
masterClockMode = 0;
isPlaying = false; // These don't seem to help with play btn not working after switching modes
resetClocks(); // so maybe remove them
calculateBPMTiming(); //
calculateCycles(); //
}
updateScreen();
}
}
//encoder
@ -353,7 +342,7 @@ void checkInputs() {
int encPosition = encoder.getPosition();
if (encPositionOld != encPosition) {
int change = encPositionOld - encPosition;
if (displayTab == 0 && masterClockMode == 0) {
if (displayTab == 0 && insideTab == 0 && masterClockMode == 0) {
bpm = bpm + change;
if (bpm > MAXBPM) {
bpm = MAXBPM;
@ -361,6 +350,15 @@ void checkInputs() {
bpm = MINBPM;
}
calculateBPMTiming();
} else if (displayTab == 0 && insideTab == 1) {
masterClockMode = masterClockMode + change;
if (masterClockMode == 3) {
masterClockMode = 2;
} else if (masterClockMode == 255) {
masterClockMode = 0;
}
} else if (displayTab == 0 && insideTab == 2) {
bpmModulationRange = bpmModulationRange + change;
} 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
@ -397,7 +395,7 @@ void checkInputs() {
}
//play button
if (!digitalRead(START_STOP_BTN_PIN) && !playBtnPushed && masterClockMode == 0) {
if (!digitalRead(START_STOP_BTN_PIN) && !playBtnPushed && masterClockMode == 0) {
resetClocks();
isPlaying = !isPlaying;
playBtnPushed = true;
@ -456,12 +454,22 @@ void updateScreen() {
display.setTextSize(3);
display.setTextColor(SSD1306_WHITE);
if (displayTab == 0 && masterClockMode == 0) {
display.print(bpm);
if (bpm<100) {
display.print(" ");
}
display.println(bpm);
display.setCursor(21,40);
display.setTextSize(2);
display.println(F("bpm"));
} else if (displayTab == 0 && masterClockMode == 1) {
display.println(F("EXT-24"));
display.println(F(" 24"));
display.setCursor(8,40);
display.setTextSize(2);
display.println(F("PPQN"));
} else if (displayTab == 0 && masterClockMode == 2) {
display.println(F("EXT-B"));
display.setCursor(8,16);
display.setTextSize(2);
display.println(F("BEAT"));
} else {
if (clockModes[channels[displayTab-1].mode] == 0) {
display.print(F("OFF"));
@ -480,7 +488,36 @@ void updateScreen() {
//Extra params
display.setCursor(58,16);
display.setTextSize(1);
if (displayTab != 0) {
if (displayTab == 0) {
if (insideTab == 1) {
display.setTextColor(SSD1306_BLACK, SSD1306_WHITE);
} else {
display.setTextColor(SSD1306_WHITE);
}
display.print(F(" CLK:"));
if (masterClockMode == 1) {
display.println(F("EXT24 "));
} else if (masterClockMode == 2) {
display.println(F("EXT-B "));
} else {
display.println(F("INT "));
}
if (insideTab == 2) {
display.setTextColor(SSD1306_BLACK, SSD1306_WHITE);
} else {
display.setTextColor(SSD1306_WHITE);
}
display.setCursor(58,30);
display.print(F(" MOD:"));
if (bpmModulationRange != 0) {
display.print(F("CV"));
display.print(bpmModulationChannel+1);
display.print("+");
display.print(bpmModulationRange * 10);
} else {
display.print(F("Off "));
}
} else {
if (insideTab == 1) {
display.setTextColor(SSD1306_BLACK, SSD1306_WHITE);
} else {
@ -501,14 +538,14 @@ void updateScreen() {
display.setCursor(58,30);
display.print(F(" MOD:"));
if (channels[displayTab-1].modulationChannel && channels[displayTab-1].modulationRange != 0) {
display.print(F("A2 "));
display.print(F("CV2 "));
if (channels[displayTab-1].modulationRange > 0) {
display.print(F("+"));
}
display.print(channels[displayTab-1].modulationRange);
display.print(F(" "));
} else if (!channels[displayTab-1].modulationChannel && channels[displayTab-1].modulationRange != 0) {
display.print(F("A1 "));
display.print(F("CV1 "));
if (channels[displayTab-1].modulationRange > 0) {
display.print(F("+"));
}