Browse Source

Add usb_midi_class::setHandleSysEx()

Switched order of parameters as suggested by PaulStoffregen.
teensy4-core
Patrick Beard 10 years ago
parent
commit
80b8f4ac81
2 changed files with 14 additions and 0 deletions
  1. +10
    -0
      teensy3/usb_midi.c
  2. +4
    -0
      teensy3/usb_midi.h

+ 10
- 0
teensy3/usb_midi.c View File

void (*usb_midi_handleProgramChange)(uint8_t ch, uint8_t program) = NULL; void (*usb_midi_handleProgramChange)(uint8_t ch, uint8_t program) = NULL;
void (*usb_midi_handleAfterTouch)(uint8_t ch, uint8_t pressure) = NULL; void (*usb_midi_handleAfterTouch)(uint8_t ch, uint8_t pressure) = NULL;
void (*usb_midi_handlePitchChange)(uint8_t ch, int pitch) = NULL; void (*usb_midi_handlePitchChange)(uint8_t ch, int pitch) = NULL;
void (*usb_midi_handleSysEx)(const uint8_t *data, uint16_t length, uint8_t complete) = NULL;
void (*usb_midi_handleRealTimeSystem)(uint8_t rtb) = NULL; void (*usb_midi_handleRealTimeSystem)(uint8_t rtb) = NULL;


// Maximum number of transmit packets to queue so we don't starve other endpoints for memory // Maximum number of transmit packets to queue so we don't starve other endpoints for memory


void static sysex_byte(uint8_t b) void static sysex_byte(uint8_t b)
{ {
// when buffer is full, send another chunk to handler.
if (usb_midi_msg_sysex_len == USB_MIDI_SYSEX_MAX) {
if (usb_midi_handleSysEx) {
(*usb_midi_handleSysEx)(usb_midi_msg_sysex, usb_midi_msg_sysex_len, 0);
usb_midi_msg_sysex_len = 0;
}
}
if (usb_midi_msg_sysex_len < USB_MIDI_SYSEX_MAX) { if (usb_midi_msg_sysex_len < USB_MIDI_SYSEX_MAX) {
usb_midi_msg_sysex[usb_midi_msg_sysex_len++] = b; usb_midi_msg_sysex[usb_midi_msg_sysex_len++] = b;
} }
usb_midi_msg_data1 = usb_midi_msg_sysex_len; usb_midi_msg_data1 = usb_midi_msg_sysex_len;
usb_midi_msg_sysex_len = 0; usb_midi_msg_sysex_len = 0;
usb_midi_msg_type = 7; // 7 = Sys Ex usb_midi_msg_type = 7; // 7 = Sys Ex
if (usb_midi_handleSysEx)
(*usb_midi_handleSysEx)(usb_midi_msg_sysex, usb_midi_msg_data1, 1);
return 1; return 1;
} }
if (type1 == 0x0F) { if (type1 == 0x0F) {

+ 4
- 0
teensy3/usb_midi.h View File

extern void (*usb_midi_handleProgramChange)(uint8_t ch, uint8_t program); extern void (*usb_midi_handleProgramChange)(uint8_t ch, uint8_t program);
extern void (*usb_midi_handleAfterTouch)(uint8_t ch, uint8_t pressure); extern void (*usb_midi_handleAfterTouch)(uint8_t ch, uint8_t pressure);
extern void (*usb_midi_handlePitchChange)(uint8_t ch, int pitch); extern void (*usb_midi_handlePitchChange)(uint8_t ch, int pitch);
extern void (*usb_midi_handleSysEx)(const uint8_t *data, uint16_t length, uint8_t complete);
extern void (*usb_midi_handleRealTimeSystem)(uint8_t rtb); extern void (*usb_midi_handleRealTimeSystem)(uint8_t rtb);


#ifdef __cplusplus #ifdef __cplusplus
inline void setHandlePitchChange(void (*fptr)(uint8_t channel, int pitch)) { inline void setHandlePitchChange(void (*fptr)(uint8_t channel, int pitch)) {
usb_midi_handlePitchChange = fptr; usb_midi_handlePitchChange = fptr;
}; };
inline void setHandleSysEx(void (*fptr)(const uint8_t *data, uint16_t length, bool complete)) {
usb_midi_handleSysEx = (void (*)(const uint8_t *, uint16_t, uint8_t))fptr;
}
inline void setHandleRealTimeSystem(void (*fptr)(uint8_t realtimebyte)) { inline void setHandleRealTimeSystem(void (*fptr)(uint8_t realtimebyte)) {
usb_midi_handleRealTimeSystem = fptr; usb_midi_handleRealTimeSystem = fptr;
}; };

Loading…
Cancel
Save