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() {