FW: added midi in and out related code

This commit is contained in:
2023-10-12 20:40:49 +03:00
parent 8c2e486fdd
commit 60d8a123a0
3 changed files with 36 additions and 5 deletions

View File

@ -108,11 +108,12 @@ unsigned int pulsePeriod;
bool isPlaying = false;
bool isRecording = false;
bool recordToNextStep = false;
bool MIDIClockRecived = false;
unsigned int tickCount = 0;
unsigned int pulseCount = 0;
byte masterClockMode = 0; // 0 - internal, 1 - external 24ppqn, 2 - external beat
byte masterClockMode = 0; // 0 - internal, 1 - external 24ppqn, 2 - MIDI
unsigned long lastExtPulseTime;
unsigned long newExtPulseTime;
@ -216,6 +217,23 @@ void loop() {
void sendMIDIClock() {
Serial.write(0xF8);
}
void sendMIDIStart() {
Serial.write(0xFA);
}
void sendMIDIStop() {
Serial.write(0xFC);
}
void receiveMIDI() {
if(Serial.available() > 0) {
if (Serial.read() == 0xF8) { //Clock
MIDIClockRecived = true;
} else if (Serial.read() == 0xFA || Serial.read() == 0xFB) { //start and continue
isPlaying = true;
} else if (Serial.read() == 0xFC) { //stop
isPlaying = false;
}
}
}
void clock() {
if (isPlaying) {
@ -244,6 +262,16 @@ void clock() {
}
}
if (masterClockMode == 2 && MIDIClockRecived) { // MIDI should happen here (needs testing)
tickCount = 0; //to make things happen in the main clock function
if (pulseCount < (PPQN - 1)) {
pulseCount++;
} else {
pulseCount = 0;
}
MIDIClockRecived = false;
}
// pull low all outputs after set pulse length
if (tickCount >= PULSE_LENGTH) {
for (byte i = 0; i < 6; i++) {
@ -275,8 +303,7 @@ void externalClock() {
} else {
pulseCount = 0;
}
}
}
}
void sendTriggers() {

View File

@ -171,8 +171,8 @@ void checkInputs() {
masterClockMode = masterClockMode + change;
if (masterClockMode > 100) {
masterClockMode = 0;
} else if (masterClockMode > 1) {
masterClockMode = 1;
} else if (masterClockMode > 2) {
masterClockMode = 2;
}
saveState();
} else if (insideTab && (menuItemSelected || shiftBtnPushed) && displayTab == 0 && menuItem == 2) { //Modulation channel

View File

@ -52,6 +52,8 @@ void updateScreen() {
valueStr = "INT";
} else if (i == 1 && masterClockMode == 1) {
valueStr = "EXT";
} else if (i == 1 && masterClockMode == 2) {
valueStr = "MIDI";
} else if (i == 2 && masterClockMode == 0 && bpmModulationRange != 0 && bpmModulationChannel == 0) {
valueStr = "CV1";
} else if (i == 2 && masterClockMode == 0 && bpmModulationRange != 0 && bpmModulationChannel == 1) {
@ -79,6 +81,8 @@ void updateScreen() {
bpmStr = String(bpm);
} else if (masterClockMode == 1) {
bpmStr = "24";
} else if (masterClockMode == 2) {
bpmStr = "MIDI";
}
char bpmChar[5];
bpmStr.toCharArray(bpmChar, 5);