You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 line
1.2KB

  1. #ifndef MIDIUSB_h
  2. #define MIDIUSB_h
  3. // For compatibility with Arduino's MIDIUSB library
  4. #include "usb_midi.h"
  5. #ifdef __cplusplus
  6. #if !defined(USB_MIDI) && !defined(USB_MIDI4) && !defined(USB_MIDI16) && !defined(USB_MIDI_SERIAL) && !defined(USB_MIDI4_SERIAL) && !defined(USB_MIDI16_SERIAL) && !defined(USB_MIDI_AUDIO_SERIAL) && !defined(USB_MIDI16_AUDIO_SERIAL) && !defined(USB_EVERYTHING)
  7. #error "Please select MIDI in Tools > USB Type to use MIDIUSB.h"
  8. #endif
  9. typedef struct {
  10. union {
  11. struct {
  12. uint8_t header;
  13. uint8_t byte1;
  14. uint8_t byte2;
  15. uint8_t byte3;
  16. };
  17. uint32_t word;
  18. };
  19. } midiEventPacket_t;
  20. class MIDI_
  21. {
  22. public:
  23. constexpr MIDI_(void) { }
  24. uint32_t available(void) {
  25. return usb_midi_available();
  26. }
  27. midiEventPacket_t read(void) {
  28. midiEventPacket_t event;
  29. event.word = usb_midi_read_message();
  30. return event;
  31. }
  32. void flush(void) {
  33. usb_midi_flush_output();
  34. }
  35. void sendMIDI(midiEventPacket_t event) {
  36. usb_midi_write_packed(event.word);
  37. }
  38. size_t write(const uint8_t *buffer, size_t size) {
  39. // TODO - is this really needed?
  40. return 0;
  41. }
  42. operator bool() {
  43. // TODO - is this really needed?
  44. return true;
  45. }
  46. };
  47. extern MIDI_ MidiUSB;
  48. #endif // __cplusplus
  49. #endif // MIDIUSB_h