Browse Source

Added full support for Midi Time Codes and Real Time messages

can now receive and send Midi Time Codes
and send Real Time messages
teensy4-core
Karg 9 years ago
parent
commit
09f8b04899
2 changed files with 35 additions and 0 deletions
  1. +9
    -0
      teensy3/usb_midi.c
  2. +26
    -0
      teensy3/usb_midi.h

+ 9
- 0
teensy3/usb_midi.c View File

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_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;
void (*usb_midi_handleTimeCodeQuarterFrame)(uint16_t data) = 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
#define TX_PACKET_LIMIT 6 #define TX_PACKET_LIMIT 6
goto return_message; goto return_message;
} }
} }
if (type1 == 0x02) {
// From Timm Schlegelmilch, karg.music at gmail.com
// http://karg-music.blogspot.de/2015/06/receiving-midi-time-codes-over-usb-with.html
usb_midi_msg_type = 9;
if (usb_midi_handleTimeCodeQuarterFrame)
(*usb_midi_handleTimeCodeQuarterFrame)(n >> 16);
return 1;
}
return 0; return 0;
} }



+ 26
- 0
teensy3/usb_midi.h View File

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_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);
extern void (*usb_midi_handleTimeCodeQuarterFrame)(uint16_t data);


#ifdef __cplusplus #ifdef __cplusplus
} }
void sendSysEx(uint32_t length, const uint8_t *data) { void sendSysEx(uint32_t length, const uint8_t *data) {
usb_midi_send_sysex(data, length); usb_midi_send_sysex(data, length);
} }
void sendRealTime(uint32_t type) __attribute__((always_inline)) {
uint32_t data = ( (type & 0xFF) | ((type << 8) & 0xFF00) );
switch (type) {
case 0xF8: // Clock
case 0xFA: // Start
case 0xFC: // Stop
case 0xFB: // Continue
case 0xFE: // ActiveSensing
case 0xFF: // SystemReset
usb_midi_write_packed(data);
break;
default: // Invalid Real Time marker
break;
}
}
void sendTimeCodeQuarterFrame(uint32_t type, uint32_t value) __attribute__((always_inline)) {
uint32_t data = ( ((type & 0x07) << 4) | (value & 0x0F) );
sendTimeCodeQuarterFrame(data);
}
void sendTimeCodeQuarterFrame(uint32_t data) __attribute__((always_inline)) {
usb_midi_write_packed(0xF108 | ((data & 0x7F) << 16));
}
void send_now(void) { void send_now(void) {
usb_midi_flush_output(); usb_midi_flush_output();
} }
inline void setHandleRealTimeSystem(void (*fptr)(uint8_t realtimebyte)) { inline void setHandleRealTimeSystem(void (*fptr)(uint8_t realtimebyte)) {
usb_midi_handleRealTimeSystem = fptr; usb_midi_handleRealTimeSystem = fptr;
}; };
inline void setHandleTimeCodeQuarterFrame(void (*fptr)(uint16_t data)) {
usb_midi_handleTimeCodeQuarterFrame = fptr;
};
private: private:
}; };



Loading…
Cancel
Save