From 6227de116b3aeefc5242595df62b325449680ba2 Mon Sep 17 00:00:00 2001 From: Brian Whitman Date: Sat, 7 Sep 2024 10:12:56 -0700 Subject: [PATCH] fixing usb midi --- amy | 2 +- tulip/esp32s3/usb_keyboard.c | 2 +- tulip/macos/virtualmidi.m | 2 +- tulip/shared/midi.c | 12 ++++++++---- tulip/shared/midi.h | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/amy b/amy index 39ed22c71..de39652dc 160000 --- a/amy +++ b/amy @@ -1 +1 @@ -Subproject commit 39ed22c711a4322db2e49e341d3d621a342e0ea5 +Subproject commit de39652dc267237958d24946b5fac785e640d754 diff --git a/tulip/esp32s3/usb_keyboard.c b/tulip/esp32s3/usb_keyboard.c index 031cf2044..738e52555 100644 --- a/tulip/esp32s3/usb_keyboard.c +++ b/tulip/esp32s3/usb_keyboard.c @@ -165,7 +165,7 @@ static void midi_transfer_cb(usb_transfer_t *transfer) { p[i], p[i + 1], p[i + 2], p[i + 3]); // Strip the first byte which is the USB-MIDI virtual wire ID, // rest is MIDI message (at least for 3-byte messages). - convert_midi_bytes_to_messages(p + i + 1, 3); + convert_midi_bytes_to_messages(p + i + 1, 3, 1); } esp_err_t err = usb_host_transfer_submit(transfer); if (err != ESP_OK) { diff --git a/tulip/macos/virtualmidi.m b/tulip/macos/virtualmidi.m index 33559713e..e8da9073b 100644 --- a/tulip/macos/virtualmidi.m +++ b/tulip/macos/virtualmidi.m @@ -75,7 +75,7 @@ void midi_out(uint8_t * bytes, uint16_t len) { data[0] = bytes[2]; data[1] = bytes[1]; data[2] = bytes[0]; - convert_midi_bytes_to_messages(data, 3); + convert_midi_bytes_to_messages(data, 3, 1); } else { //printf("bytes[3] was not 0x20\n"); } diff --git a/tulip/shared/midi.c b/tulip/shared/midi.c index a4e02f156..69bfed541 100644 --- a/tulip/shared/midi.c +++ b/tulip/shared/midi.c @@ -66,10 +66,12 @@ void callback_midi_message_received(uint8_t *data, size_t len) { 1 0xFF reset | XXXX */ -void convert_midi_bytes_to_messages(uint8_t * data, size_t len) { +void convert_midi_bytes_to_messages(uint8_t * data, size_t len, uint8_t usb) { // i take any amount of bytes and add messages // remember this can start in the middle of a midi message, so act accordingly // running status is handled by keeping the status byte around after getting a message. + // remember that USB midi always comes in groups of 3 here, even if it's just a one byte message + // so we have USB (and mac IAC) set a usb flag so we know to end the loop once a message is parsed for(size_t i=0;i