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