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

@@ -51,6 +51,7 @@ void (*usb_midi_handleAfterTouch)(uint8_t ch, uint8_t pressure) = 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_handleTimeCodeQuarterFrame)(uint16_t data) = NULL;

// Maximum number of transmit packets to queue so we don't starve other endpoints for memory
#define TX_PACKET_LIMIT 6
@@ -277,6 +278,14 @@ int usb_midi_read(uint32_t channel)
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;
}


+ 26
- 0
teensy3/usb_midi.h View File

@@ -81,6 +81,7 @@ 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_handleSysEx)(const uint8_t *data, uint16_t length, uint8_t complete);
extern void (*usb_midi_handleRealTimeSystem)(uint8_t rtb);
extern void (*usb_midi_handleTimeCodeQuarterFrame)(uint16_t data);

#ifdef __cplusplus
}
@@ -124,6 +125,28 @@ class usb_midi_class
void sendSysEx(uint32_t length, const uint8_t *data) {
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) {
usb_midi_flush_output();
}
@@ -173,6 +196,9 @@ class usb_midi_class
inline void setHandleRealTimeSystem(void (*fptr)(uint8_t realtimebyte)) {
usb_midi_handleRealTimeSystem = fptr;
};
inline void setHandleTimeCodeQuarterFrame(void (*fptr)(uint16_t data)) {
usb_midi_handleTimeCodeQuarterFrame = fptr;
};
private:
};


Loading…
Cancel
Save