usb_midi.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /**
  2. * @file
  3. * @brief USB MIDI Class public header
  4. *
  5. */
  6. #ifndef _USB_MIDI_H_
  7. #define _USB_MIDI_H_
  8. /* bDescriptorSubType */
  9. #define MIDI_VC_HEADER_DESCRIPTOR_SUBTYPE 0x01U
  10. #define MIDI_MS_HEADER_DESCRIPTOR_SUBTYPE 0x01U
  11. #define MIDI_MS_GENERAL_DESCRIPTOR_SUBTYPE 0x01U
  12. #define MIDI_MIDI_IN_JACK_DESCRIPTOR_SUBTYPE 0x02U
  13. #define MIDI_MIDI_OUT_JACK_DESCRIPTOR_SUBTYPE 0x03U
  14. /* bJackType */
  15. #define MIDI_JACK_TYPE_EMBEDDED 0x01
  16. #define MIDI_JACK_TYPE_EXTERNAL 0x02
  17. #define MIDI_CHANNEL_OMNI 0
  18. #define MIDI_CHANNEL_OFF 17
  19. #define MIDI_PITCHBEND_MIN -8192
  20. #define MIDI_PITCHBEND_MAX 8191
  21. /*! Enumeration of MIDI types */
  22. enum MidiType {
  23. InvalidType = 0x00, ///< For notifying errors
  24. NoteOff = 0x80, ///< Note Off
  25. NoteOn = 0x90, ///< Note On
  26. AfterTouchPoly = 0xA0, ///< Polyphonic AfterTouch
  27. ControlChange = 0xB0, ///< Control Change / Channel Mode
  28. ProgramChange = 0xC0, ///< Program Change
  29. AfterTouchChannel = 0xD0, ///< Channel (monophonic) AfterTouch
  30. PitchBend = 0xE0, ///< Pitch Bend
  31. SystemExclusive = 0xF0, ///< System Exclusive
  32. TimeCodeQuarterFrame = 0xF1, ///< System Common - MIDI Time Code Quarter Frame
  33. SongPosition = 0xF2, ///< System Common - Song Position Pointer
  34. SongSelect = 0xF3, ///< System Common - Song Select
  35. TuneRequest = 0xF6, ///< System Common - Tune Request
  36. Clock = 0xF8, ///< System Real Time - Timing Clock
  37. Start = 0xFA, ///< System Real Time - Start
  38. Continue = 0xFB, ///< System Real Time - Continue
  39. Stop = 0xFC, ///< System Real Time - Stop
  40. ActiveSensing = 0xFE, ///< System Real Time - Active Sensing
  41. SystemReset = 0xFF, ///< System Real Time - System Reset
  42. };
  43. /*! Enumeration of Thru filter modes */
  44. enum MidiFilterMode {
  45. Off = 0, ///< Thru disabled (nothing passes through).
  46. Full = 1, ///< Fully enabled Thru (every incoming message is sent back).
  47. SameChannel = 2, ///< Only the messages on the Input Channel will be sent back.
  48. DifferentChannel = 3, ///< All the messages but the ones on the Input Channel will be sent back.
  49. };
  50. /*! \brief Enumeration of Control Change command numbers.
  51. See the detailed controllers numbers & description here:
  52. http://www.somascape.org/midi/tech/spec.html#ctrlnums
  53. */
  54. enum MidiControlChangeNumber {
  55. // High resolution Continuous Controllers MSB (+32 for LSB) ----------------
  56. BankSelect = 0,
  57. ModulationWheel = 1,
  58. BreathController = 2,
  59. // CC3 undefined
  60. FootController = 4,
  61. PortamentoTime = 5,
  62. DataEntry = 6,
  63. ChannelVolume = 7,
  64. Balance = 8,
  65. // CC9 undefined
  66. Pan = 10,
  67. ExpressionController = 11,
  68. EffectControl1 = 12,
  69. EffectControl2 = 13,
  70. // CC14 undefined
  71. // CC15 undefined
  72. GeneralPurposeController1 = 16,
  73. GeneralPurposeController2 = 17,
  74. GeneralPurposeController3 = 18,
  75. GeneralPurposeController4 = 19,
  76. // Switches ----------------------------------------------------------------
  77. Sustain = 64,
  78. Portamento = 65,
  79. Sostenuto = 66,
  80. SoftPedal = 67,
  81. Legato = 68,
  82. Hold = 69,
  83. // Low resolution continuous controllers -----------------------------------
  84. SoundController1 = 70, ///< Synth: Sound Variation FX: Exciter On/Off
  85. SoundController2 = 71, ///< Synth: Harmonic Content FX: Compressor On/Off
  86. SoundController3 = 72, ///< Synth: Release Time FX: Distortion On/Off
  87. SoundController4 = 73, ///< Synth: Attack Time FX: EQ On/Off
  88. SoundController5 = 74, ///< Synth: Brightness FX: Expander On/Off
  89. SoundController6 = 75, ///< Synth: Decay Time FX: Reverb On/Off
  90. SoundController7 = 76, ///< Synth: Vibrato Rate FX: Delay On/Off
  91. SoundController8 = 77, ///< Synth: Vibrato Depth FX: Pitch Transpose On/Off
  92. SoundController9 = 78, ///< Synth: Vibrato Delay FX: Flange/Chorus On/Off
  93. SoundController10 = 79, ///< Synth: Undefined FX: Special Effects On/Off
  94. GeneralPurposeController5 = 80,
  95. GeneralPurposeController6 = 81,
  96. GeneralPurposeController7 = 82,
  97. GeneralPurposeController8 = 83,
  98. PortamentoControl = 84,
  99. // CC85 to CC90 undefined
  100. Effects1 = 91, ///< Reverb send level
  101. Effects2 = 92, ///< Tremolo depth
  102. Effects3 = 93, ///< Chorus send level
  103. Effects4 = 94, ///< Celeste depth
  104. Effects5 = 95, ///< Phaser depth
  105. // Channel Mode messages ---------------------------------------------------
  106. AllSoundOff = 120,
  107. ResetAllControllers = 121,
  108. LocalControl = 122,
  109. AllNotesOff = 123,
  110. OmniModeOff = 124,
  111. OmniModeOn = 125,
  112. MonoModeOn = 126,
  113. PolyModeOn = 127
  114. };
  115. struct midi_cs_if_ac_header_descriptor {
  116. uint8_t bLength;
  117. uint8_t bDescriptorType;
  118. uint8_t bDescriptorSubType;
  119. uint16_t bcdADC;
  120. uint16_t wTotalLength;
  121. uint8_t bInCollection;
  122. uint8_t baInterfaceNr[];
  123. } __PACKED;
  124. #define MIDI_SIZEOF_AC_HEADER_DESC(n) (8 + n)
  125. struct midi_cs_if_ms_header_descriptor {
  126. uint8_t bLength;
  127. uint8_t bDescriptorType;
  128. uint8_t bDescriptorSubType;
  129. uint16_t bcdMSC;
  130. uint16_t wTotalLength;
  131. } __PACKED;
  132. #define MIDI_SIZEOF_MS_HEADER_DESC (7)
  133. struct midi_cs_if_in_jack_descriptor {
  134. uint8_t bLength;
  135. uint8_t bDescriptorType;
  136. uint8_t bDescriptorSubType;
  137. uint8_t bJackType;
  138. uint8_t bJackId;
  139. uint8_t iJack;
  140. } __PACKED;
  141. #define MIDI_SIZEOF_IN_JACK_DESC (6)
  142. struct midi_cs_if_out_jack_descriptor {
  143. uint8_t bLength;
  144. uint8_t bDescriptorType;
  145. uint8_t bDescriptorSubType;
  146. uint8_t bJackType;
  147. uint8_t bJackId;
  148. uint8_t bNrInputPins;
  149. uint8_t baSourceId;
  150. uint8_t baSourcePin;
  151. uint8_t iJack;
  152. } __PACKED;
  153. #define MIDI_SIZEOF_OUT_JACK_DESC (9)
  154. struct midi_cs_ep_ms_general_descriptor {
  155. uint8_t bLength;
  156. uint8_t bDescriptorType;
  157. uint8_t bDescriptorSubType;
  158. uint8_t bNumEmbMIDIJack;
  159. uint8_t baAssocJackID[];
  160. } __PACKED;
  161. #define MIDI_SIZEOF_MS_GENERAL_DESC(n) (4 + n)
  162. // clang-format off
  163. #define MIDI_IN_JACK_DESCRIPTOR_INIT(bJackType, bJackID) \
  164. 0x06, \
  165. 0x24, \
  166. MIDI_MIDI_IN_JACK_DESCRIPTOR_SUBTYPE, \
  167. bJackType, \
  168. bJackID, \
  169. 0x00
  170. #define MIDI_OUT_JACK_DESCRIPTOR_INIT(bJackType, bJackID, baSourceID) \
  171. 0x09, \
  172. 0x24, \
  173. MIDI_MIDI_OUT_JACK_DESCRIPTOR_SUBTYPE, \
  174. bJackType, \
  175. bJackID, \
  176. 0x01, \
  177. baSourceID, \
  178. 0x01, \
  179. 0x00
  180. #define MIDI_JACK_DESCRIPTOR_INIT(bJackFirstID) \
  181. MIDI_IN_JACK_DESCRIPTOR_INIT(MIDI_JACK_TYPE_EMBEDDED, bJackFirstID), \
  182. MIDI_IN_JACK_DESCRIPTOR_INIT(MIDI_JACK_TYPE_EXTERNAL, (bJackFirstID + 1)), \
  183. MIDI_OUT_JACK_DESCRIPTOR_INIT(MIDI_JACK_TYPE_EMBEDDED, (bJackFirstID + 2), (bJackFirstID + 1)), \
  184. MIDI_OUT_JACK_DESCRIPTOR_INIT(MIDI_JACK_TYPE_EXTERNAL, (bJackFirstID + 3), (bJackFirstID))
  185. #define MIDI_SIZEOF_JACK_DESC (6 + 6 + 9 + 9)
  186. // clang-format on
  187. #endif /* _USB_MIDI_H_ */