From 6b029bada79ac3c93a9b684b70cb65e8250a47e8 Mon Sep 17 00:00:00 2001 From: Sylwester <6614616+DatanoiseTV@users.noreply.github.com> Date: Sun, 13 Oct 2024 14:45:20 +0200 Subject: [PATCH 1/2] Update midi_input_usb.h --- include/midi_input_usb.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/midi_input_usb.h b/include/midi_input_usb.h index b9812f8..92be128 100644 --- a/include/midi_input_usb.h +++ b/include/midi_input_usb.h @@ -13,6 +13,7 @@ class MIDIInputUSB { void setPitchBendCallback(void (*callback)(uint16_t, uint8_t)); void setAftertouchCallback(void (*callback)(uint8_t, uint8_t)); void setChannelPressureCallback(void (*callback)(uint8_t, uint8_t)); + void setClockCallback(void (*callback)()); // MIDI processing function void process(); @@ -25,6 +26,7 @@ class MIDIInputUSB { std::function MIDIPitchBendCallback = nullptr; std::function MIDIAftertouchCallback = nullptr; std::function MIDIChannelPressureCallback = nullptr; + std::function MIDIClockCallback = nullptr; // Helper function for parsing pitch bend data uint16_t parsePitchBend(const uint8_t* packet); From 206ea66397ee82d2cad3d5d161b6212a7ff2f791 Mon Sep 17 00:00:00 2001 From: Sylwester <6614616+DatanoiseTV@users.noreply.github.com> Date: Sun, 13 Oct 2024 14:48:41 +0200 Subject: [PATCH 2/2] Add rudimentary MIDI Clock support --- src/midi_input_usb.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/midi_input_usb.cpp b/src/midi_input_usb.cpp index bae94e7..8bf1f02 100644 --- a/src/midi_input_usb.cpp +++ b/src/midi_input_usb.cpp @@ -26,6 +26,10 @@ void MIDIInputUSB::setChannelPressureCallback(void (*callback)(uint8_t, uint8_t) MIDIChannelPressureCallback = callback; } +void MIDIInputUSB::setClockCallback(void (*callback)()) { + MIDIClockCallback = callback; +} + // Helper function to parse pitch bend data uint16_t MIDIInputUSB::parsePitchBend(const uint8_t* packet) { // Combine the two data bytes into a 14-bit pitch bend value @@ -50,6 +54,13 @@ void MIDIInputUSB::process() { uint8_t status = packet[0] >> 4; uint8_t channel = packet[0] & 0xF; + if(packet[0] == 0xF8]{ + if (MIDIClockCallback != NULL) + { + MIDIClockCallback(); + } + } + switch (status) { case 0x8: // Note Off if (MIDINoteOffCallback != nullptr) {