Skip to content

Commit

Permalink
Merge pull request #28 from DatanoiseTV/RP235x-PD-MidiClock
Browse files Browse the repository at this point in the history
Add rudimentary MIDI clock support.
  • Loading branch information
DatanoiseTV authored Oct 13, 2024
2 parents 327df27 + 206ea66 commit 14d6aaf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/midi_input_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -25,6 +26,7 @@ class MIDIInputUSB {
std::function<void(uint16_t, uint8_t)> MIDIPitchBendCallback = nullptr;
std::function<void(uint8_t, uint8_t)> MIDIAftertouchCallback = nullptr;
std::function<void(uint8_t, uint8_t)> MIDIChannelPressureCallback = nullptr;
std::function<void(uint8_t, uint8_t)> MIDIClockCallback = nullptr;

// Helper function for parsing pitch bend data
uint16_t parsePitchBend(const uint8_t* packet);
Expand Down
11 changes: 11 additions & 0 deletions src/midi_input_usb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit 14d6aaf

Please sign in to comment.