Drone strategy and fixed MIDI panic

This commit is contained in:
Dejvino
2026-02-22 23:03:03 +01:00
parent 33c6329f0b
commit 4e4ba0d0e4
7 changed files with 172 additions and 10 deletions
+51
View File
@@ -1,4 +1,5 @@
#include "MidiDriver.h"
#include "config.h"
// MIDI UART Pins (GP0/GP1)
#define PIN_MIDI_TX 0
@@ -7,6 +8,7 @@
MidiDriver midi;
MidiDriver::MidiDriver() : lastInputNote(-1), lastInputVelocity(0), _runningStatus(0), _byteIndex(0), _data1(0), _data2(0) {
memset(activeNotes, 0, sizeof(activeNotes));
}
void MidiDriver::begin() {
@@ -88,6 +90,20 @@ void MidiDriver::unlock() {
}
void MidiDriver::sendNoteOn(uint8_t note, uint8_t velocity, uint8_t channel) {
#ifdef MIDI_DEBUG
Serial.print(F("["));
Serial.print(millis());
Serial.print(F("] "));
Serial.print(F("MIDI OUT: Note On CH:"));
Serial.print(channel);
Serial.print(F(" Note:"));
Serial.print(note);
Serial.print(F(" Vel:"));
Serial.println(velocity);
#endif
if (channel >= 1 && channel <= 16 && note < 128) {
activeNotes[channel - 1][note] = (velocity > 0);
}
uint8_t status = 0x90 | (channel - 1);
Serial1.write(status);
Serial1.write(note);
@@ -95,6 +111,18 @@ void MidiDriver::sendNoteOn(uint8_t note, uint8_t velocity, uint8_t channel) {
}
void MidiDriver::sendNoteOff(uint8_t note, uint8_t channel) {
#ifdef MIDI_DEBUG
Serial.print(F("["));
Serial.print(millis());
Serial.print(F("] "));
Serial.print(F("MIDI OUT: Note Off CH:"));
Serial.print(channel);
Serial.print(F(" Note:"));
Serial.println(note);
#endif
if (channel >= 1 && channel <= 16 && note < 128) {
activeNotes[channel - 1][note] = false;
}
uint8_t status = 0x80 | (channel - 1);
Serial1.write(status);
Serial1.write(note);
@@ -102,10 +130,33 @@ void MidiDriver::sendNoteOff(uint8_t note, uint8_t channel) {
}
void MidiDriver::sendRealtime(uint8_t status) {
#ifdef MIDI_DEBUG
if (status != 0xF8) {
Serial.print(F("["));
Serial.print(millis());
Serial.print(F("] "));
Serial.print(F("MIDI OUT: Realtime 0x"));
Serial.println(status, HEX);
}
#endif
Serial1.write(status);
}
void MidiDriver::panic(uint8_t channel) {
#ifdef MIDI_DEBUG
Serial.print(F("["));
Serial.print(millis());
Serial.print(F("] "));
Serial.print(F("MIDI OUT: Panic CH:"));
Serial.println(channel);
#endif
if (channel >= 1 && channel <= 16) {
for (int i = 0; i < 128; i++) {
if (activeNotes[channel - 1][i]) {
sendNoteOff(i, channel);
}
}
}
uint8_t status = 0xB0 | (channel - 1);
Serial1.write(status);
Serial1.write((uint8_t)123); // All Notes Off