MIDIClassCommon.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2012.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  9. Permission to use, copy, modify, distribute, and sell this
  10. software and its documentation for any purpose is hereby granted
  11. without fee, provided that the above copyright notice appear in
  12. all copies and that both that the copyright notice and this
  13. permission notice and warranty disclaimer appear in supporting
  14. documentation, and that the name of the author not be used in
  15. advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.
  17. The author disclaim all warranties with regard to this
  18. software, including all implied warranties of merchantability
  19. and fitness. In no event shall the author be liable for any
  20. special, indirect or consequential damages or any damages
  21. whatsoever resulting from loss of use, data or profits, whether
  22. in an action of contract, negligence or other tortious action,
  23. arising out of or in connection with the use or performance of
  24. this software.
  25. */
  26. /** \file
  27. * \brief Common definitions and declarations for the library USB MIDI Class driver.
  28. *
  29. * Common definitions and declarations for the library USB MIDI Class driver.
  30. *
  31. * \note This file should not be included directly. It is automatically included as needed by the USB module driver
  32. * dispatch header located in LUFA/Drivers/USB.h.
  33. */
  34. /** \ingroup Group_USBClassMIDI
  35. * \defgroup Group_USBClassMIDICommon Common Class Definitions
  36. *
  37. * \section Sec_ModDescription Module Description
  38. * Constants, Types and Enum definitions that are common to both Device and Host modes for the USB
  39. * MIDI Class.
  40. *
  41. * @{
  42. */
  43. #ifndef _MIDI_CLASS_COMMON_H_
  44. #define _MIDI_CLASS_COMMON_H_
  45. /* Macros: */
  46. #define __INCLUDE_FROM_AUDIO_DRIVER
  47. /* Includes: */
  48. #include "../../Core/StdDescriptors.h"
  49. #include "AudioClassCommon.h"
  50. /* Enable C linkage for C++ Compilers: */
  51. #if defined(__cplusplus)
  52. extern "C" {
  53. #endif
  54. /* Preprocessor Checks: */
  55. #if !defined(__INCLUDE_FROM_MIDI_DRIVER)
  56. #error Do not include this file directly. Include LUFA/Drivers/USB.h instead.
  57. #endif
  58. /* Macros: */
  59. /** \name MIDI Command Values */
  60. //@{
  61. /** MIDI command for a note on (activation) event. */
  62. #define MIDI_COMMAND_NOTE_ON 0x90
  63. /** MIDI command for a note off (deactivation) event. */
  64. #define MIDI_COMMAND_NOTE_OFF 0x80
  65. //@}
  66. /** Standard key press velocity value used for all note events. */
  67. #define MIDI_STANDARD_VELOCITY 64
  68. /** Convenience macro. MIDI channels are numbered from 1-10 (natural numbers) however the logical channel
  69. * addresses are zero-indexed. This converts a natural MIDI channel number into the logical channel address.
  70. *
  71. * \param[in] channel MIDI channel number to address.
  72. *
  73. * \return Constructed MIDI channel ID.
  74. */
  75. #define MIDI_CHANNEL(channel) ((channel) - 1)
  76. /** Constructs a MIDI event ID from a given MIDI command and a virtual MIDI cable index. This can then be
  77. * used to create and decode \ref MIDI_EventPacket_t MIDI event packets.
  78. *
  79. * \param[in] virtualcable Index of the virtual MIDI cable the event relates to
  80. * \param[in] command MIDI command to send through the virtual MIDI cable
  81. *
  82. * \return Constructed MIDI event ID.
  83. */
  84. #define MIDI_EVENT(virtualcable, command) ((virtualcable << 4) | (command >> 4))
  85. /* Enums: */
  86. /** Enum for the possible MIDI jack types in a MIDI device jack descriptor. */
  87. enum MIDI_JackTypes_t
  88. {
  89. MIDI_JACKTYPE_Embedded = 0x01, /**< MIDI class descriptor jack type value for an embedded (logical) MIDI input or output jack. */
  90. MIDI_JACKTYPE_External = 0x02, /**< MIDI class descriptor jack type value for an external (physical) MIDI input or output jack. */
  91. };
  92. /* Type Defines: */
  93. /** \brief MIDI class-specific Streaming Interface Descriptor (LUFA naming conventions).
  94. *
  95. * Type define for an Audio class-specific MIDI streaming interface descriptor. This indicates to the host
  96. * how MIDI the specification compliance of the device and the total length of the Audio class-specific descriptors.
  97. * See the USB Audio specification for more details.
  98. *
  99. * \see \ref USB_MIDI_StdDescriptor_AudioInterface_AS_t for the version of this type with standard element names.
  100. *
  101. * \note Regardless of CPU architecture, these values should be stored as little endian.
  102. */
  103. typedef struct
  104. {
  105. USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
  106. uint8_t Subtype; /**< Sub type value used to distinguish between audio class-specific descriptors. */
  107. uint16_t AudioSpecification; /**< Binary coded decimal value, indicating the supported Audio Class
  108. * specification version.
  109. */
  110. uint16_t TotalLength; /**< Total length of the Audio class-specific descriptors, including this descriptor. */
  111. } ATTR_PACKED USB_MIDI_Descriptor_AudioInterface_AS_t;
  112. /** \brief MIDI class-specific Streaming Interface Descriptor (USB-IF naming conventions).
  113. *
  114. * Type define for an Audio class-specific MIDI streaming interface descriptor. This indicates to the host
  115. * how MIDI the specification compliance of the device and the total length of the Audio class-specific descriptors.
  116. * See the USB Audio specification for more details.
  117. *
  118. * \see \ref USB_MIDI_Descriptor_AudioInterface_AS_t for the version of this type with non-standard LUFA specific
  119. * element names.
  120. *
  121. * \note Regardless of CPU architecture, these values should be stored as little endian.
  122. */
  123. typedef struct
  124. {
  125. uint8_t bLength; /**< Size of the descriptor, in bytes. */
  126. uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
  127. * given by the specific class.
  128. */
  129. uint8_t bDescriptorSubtype; /**< Sub type value used to distinguish between audio class-specific descriptors. */
  130. uint16_t bcdMSC; /**< Binary coded decimal value, indicating the supported MIDI Class specification version. */
  131. uint16_t wTotalLength; /**< Total length of the Audio class-specific descriptors, including this descriptor. */
  132. } ATTR_PACKED USB_MIDI_StdDescriptor_AudioInterface_AS_t;
  133. /** \brief MIDI class-specific Input Jack Descriptor (LUFA naming conventions).
  134. *
  135. * Type define for an Audio class-specific MIDI IN jack. This gives information to the host on a MIDI input, either
  136. * a physical input jack, or a logical jack (receiving input data internally, or from the host via an endpoint).
  137. *
  138. * \see \ref USB_MIDI_StdDescriptor_InputJack_t for the version of this type with standard element names.
  139. *
  140. * \note Regardless of CPU architecture, these values should be stored as little endian.
  141. */
  142. typedef struct
  143. {
  144. USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
  145. uint8_t Subtype; /**< Sub type value used to distinguish between audio class-specific descriptors. */
  146. uint8_t JackType; /**< Type of jack, one of the \c JACKTYPE_* mask values. */
  147. uint8_t JackID; /**< ID value of this jack - must be a unique value within the device. */
  148. uint8_t JackStrIndex; /**< Index of a string descriptor describing this descriptor within the device. */
  149. } ATTR_PACKED USB_MIDI_Descriptor_InputJack_t;
  150. /** \brief MIDI class-specific Input Jack Descriptor (USB-IF naming conventions).
  151. *
  152. * Type define for an Audio class-specific MIDI IN jack. This gives information to the host on a MIDI input, either
  153. * a physical input jack, or a logical jack (receiving input data internally, or from the host via an endpoint).
  154. *
  155. * \see \ref USB_MIDI_Descriptor_InputJack_t for the version of this type with non-standard LUFA specific
  156. * element names.
  157. *
  158. * \note Regardless of CPU architecture, these values should be stored as little endian.
  159. */
  160. typedef struct
  161. {
  162. uint8_t bLength; /**< Size of the descriptor, in bytes. */
  163. uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
  164. * given by the specific class.
  165. */
  166. uint8_t bDescriptorSubtype; /**< Sub type value used to distinguish between audio class-specific descriptors. */
  167. uint8_t bJackType; /**< Type of jack, one of the \c JACKTYPE_* mask values. */
  168. uint8_t bJackID; /**< ID value of this jack - must be a unique value within the device. */
  169. uint8_t iJack; /**< Index of a string descriptor describing this descriptor within the device. */
  170. } ATTR_PACKED USB_MIDI_StdDescriptor_InputJack_t;
  171. /** \brief MIDI class-specific Output Jack Descriptor (LUFA naming conventions).
  172. *
  173. * Type define for an Audio class-specific MIDI OUT jack. This gives information to the host on a MIDI output, either
  174. * a physical output jack, or a logical jack (sending output data internally, or to the host via an endpoint).
  175. *
  176. * \see \ref USB_MIDI_StdDescriptor_OutputJack_t for the version of this type with standard element names.
  177. *
  178. * \note Regardless of CPU architecture, these values should be stored as little endian.
  179. */
  180. typedef struct
  181. {
  182. USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
  183. uint8_t Subtype; /**< Sub type value used to distinguish between audio class-specific descriptors. */
  184. uint8_t JackType; /**< Type of jack, one of the \c JACKTYPE_* mask values. */
  185. uint8_t JackID; /**< ID value of this jack - must be a unique value within the device. */
  186. uint8_t NumberOfPins; /**< Number of output channels within the jack, either physical or logical. */
  187. uint8_t SourceJackID[1]; /**< ID of each output pin's source data jack. */
  188. uint8_t SourcePinID[1]; /**< Pin number in the input jack of each output pin's source data. */
  189. uint8_t JackStrIndex; /**< Index of a string descriptor describing this descriptor within the device. */
  190. } ATTR_PACKED USB_MIDI_Descriptor_OutputJack_t;
  191. /** \brief MIDI class-specific Output Jack Descriptor (USB-IF naming conventions).
  192. *
  193. * Type define for an Audio class-specific MIDI OUT jack. This gives information to the host on a MIDI output, either
  194. * a physical output jack, or a logical jack (sending output data internally, or to the host via an endpoint).
  195. *
  196. * \see \ref USB_MIDI_Descriptor_OutputJack_t for the version of this type with non-standard LUFA specific
  197. * element names.
  198. *
  199. * \note Regardless of CPU architecture, these values should be stored as little endian.
  200. */
  201. typedef struct
  202. {
  203. uint8_t bLength; /**< Size of the descriptor, in bytes. */
  204. uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
  205. * given by the specific class.
  206. */
  207. uint8_t bDescriptorSubtype; /**< Sub type value used to distinguish between audio class-specific descriptors. */
  208. uint8_t bJackType; /**< Type of jack, one of the \c JACKTYPE_* mask values. */
  209. uint8_t bJackID; /**< ID value of this jack - must be a unique value within the device. */
  210. uint8_t bNrInputPins; /**< Number of output channels within the jack, either physical or logical. */
  211. uint8_t baSourceID[1]; /**< ID of each output pin's source data jack. */
  212. uint8_t baSourcePin[1]; /**< Pin number in the input jack of each output pin's source data. */
  213. uint8_t iJack; /**< Index of a string descriptor describing this descriptor within the device. */
  214. } ATTR_PACKED USB_MIDI_StdDescriptor_OutputJack_t;
  215. /** \brief Audio class-specific Jack Endpoint Descriptor (LUFA naming conventions).
  216. *
  217. * Type define for an Audio class-specific extended MIDI jack endpoint descriptor. This contains extra information
  218. * on the usage of MIDI endpoints used to stream MIDI events in and out of the USB Audio device, and follows an Audio
  219. * class-specific extended MIDI endpoint descriptor. See the USB Audio specification for more details.
  220. *
  221. * \see \ref USB_MIDI_StdDescriptor_Jack_Endpoint_t for the version of this type with standard element names.
  222. *
  223. * \note Regardless of CPU architecture, these values should be stored as little endian.
  224. */
  225. typedef struct
  226. {
  227. USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
  228. uint8_t Subtype; /**< Sub type value used to distinguish between audio class-specific descriptors. */
  229. uint8_t TotalEmbeddedJacks; /**< Total number of jacks inside this endpoint. */
  230. uint8_t AssociatedJackID[1]; /**< IDs of each jack inside the endpoint. */
  231. } ATTR_PACKED USB_MIDI_Descriptor_Jack_Endpoint_t;
  232. /** \brief Audio class-specific Jack Endpoint Descriptor (USB-IF naming conventions).
  233. *
  234. * Type define for an Audio class-specific extended MIDI jack endpoint descriptor. This contains extra information
  235. * on the usage of MIDI endpoints used to stream MIDI events in and out of the USB Audio device, and follows an Audio
  236. * class-specific extended MIDI endpoint descriptor. See the USB Audio specification for more details.
  237. *
  238. * \see \ref USB_MIDI_Descriptor_Jack_Endpoint_t for the version of this type with non-standard LUFA specific
  239. * element names.
  240. *
  241. * \note Regardless of CPU architecture, these values should be stored as little endian.
  242. */
  243. typedef struct
  244. {
  245. uint8_t bLength; /**< Size of the descriptor, in bytes. */
  246. uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
  247. * given by the specific class.
  248. */
  249. uint8_t bDescriptorSubtype; /**< Sub type value used to distinguish between audio class-specific descriptors. */
  250. uint8_t bNumEmbMIDIJack; /**< Total number of jacks inside this endpoint. */
  251. uint8_t bAssocJackID[1]; /**< IDs of each jack inside the endpoint. */
  252. } ATTR_PACKED USB_MIDI_StdDescriptor_Jack_Endpoint_t;
  253. /** \brief MIDI Class Driver Event Packet.
  254. *
  255. * Type define for a USB MIDI event packet, used to encapsulate sent and received MIDI messages from a USB MIDI interface.
  256. *
  257. * \note Regardless of CPU architecture, these values should be stored as little endian.
  258. */
  259. typedef struct
  260. {
  261. uint8_t Event; /**< MIDI event type, constructed with the \ref MIDI_EVENT() macro. */
  262. uint8_t Data1; /**< First byte of data in the MIDI event. */
  263. uint8_t Data2; /**< Second byte of data in the MIDI event. */
  264. uint8_t Data3; /**< Third byte of data in the MIDI event. */
  265. } ATTR_PACKED MIDI_EventPacket_t;
  266. /* Disable C linkage for C++ Compilers: */
  267. #if defined(__cplusplus)
  268. }
  269. #endif
  270. #endif
  271. /** @} */