jack2 codebase
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.

198 lines
6.7KB

  1. /*
  2. Copyright (C) 2004 Ian Esten
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2.1 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #ifndef __JACK_MIDIPORT_H
  16. #define __JACK_MIDIPORT_H
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #include <jack/weakmacros.h>
  21. #include <jack/types.h>
  22. #include <stdlib.h>
  23. /** Type for raw event data contained in @ref jack_midi_event_t. */
  24. typedef unsigned char jack_midi_data_t;
  25. /** A Jack MIDI event. */
  26. typedef struct _jack_midi_event
  27. {
  28. jack_nframes_t time; /**< Sample index at which event is valid */
  29. size_t size; /**< Number of bytes of data in \a buffer */
  30. jack_midi_data_t *buffer; /**< Raw MIDI data */
  31. } jack_midi_event_t;
  32. /**
  33. * @defgroup MIDIAPI Reading and writing MIDI data
  34. * @{
  35. */
  36. /** Get number of events in a port buffer.
  37. *
  38. * @param port_buffer Port buffer from which to retrieve event.
  39. * @return number of events inside @a port_buffer
  40. */
  41. uint32_t
  42. jack_midi_get_event_count(void* port_buffer) JACK_OPTIONAL_WEAK_EXPORT;
  43. /** Get a MIDI event from an event port buffer.
  44. *
  45. * Jack MIDI is normalised, the MIDI event returned by this function is
  46. * guaranteed to be a complete MIDI event (the status byte will always be
  47. * present, and no realtime events will interspered with the event).
  48. *
  49. * This rule does not apply to System Exclusive MIDI messages
  50. * since they can be of arbitrary length.
  51. * To maintain smooth realtime operation such events CAN be deliverd
  52. * as multiple, non-normalised events.
  53. * The maximum size of one event "chunk" depends on the MIDI backend in use.
  54. * For example the midiseq driver will create chunks of 256 bytes.
  55. * The first SysEx "chunked" event starts with 0xF0 and the last
  56. * delivered chunk ends with 0xF7.
  57. * To receive the full SysEx message, a caller of jack_midi_event_get()
  58. * must concatenate chunks until a chunk ends with 0xF7.
  59. *
  60. * @param event Event structure to store retrieved event in.
  61. * @param port_buffer Port buffer from which to retrieve event.
  62. * @param event_index Index of event to retrieve.
  63. * @return 0 on success, ENODATA if buffer is empty.
  64. */
  65. int
  66. jack_midi_event_get(jack_midi_event_t *event,
  67. void *port_buffer,
  68. uint32_t event_index) JACK_OPTIONAL_WEAK_EXPORT;
  69. /** Clear an event buffer.
  70. *
  71. * This should be called at the beginning of each process cycle before calling
  72. * @ref jack_midi_event_reserve or @ref jack_midi_event_write. This
  73. * function may not be called on an input port's buffer.
  74. *
  75. * @param port_buffer Port buffer to clear (must be an output port buffer).
  76. */
  77. void
  78. jack_midi_clear_buffer(void *port_buffer) JACK_OPTIONAL_WEAK_EXPORT;
  79. /** Reset an event buffer (from data allocated outside of JACK).
  80. *
  81. * This should be called at the beginning of each process cycle before calling
  82. * @ref jack_midi_event_reserve or @ref jack_midi_event_write. This
  83. * function may not be called on an input port's buffer.
  84. *
  85. * @deprecated Please use jack_midi_clear_buffer().
  86. *
  87. * @param port_buffer Port buffer to resetted.
  88. */
  89. void
  90. jack_midi_reset_buffer(void *port_buffer) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  91. /** Get the size of the largest event that can be stored by the port.
  92. *
  93. * This function returns the current space available, taking into account
  94. * events already stored in the port.
  95. *
  96. * @param port_buffer Port buffer to check size of.
  97. */
  98. size_t
  99. jack_midi_max_event_size(void* port_buffer) JACK_OPTIONAL_WEAK_EXPORT;
  100. /** Allocate space for an event to be written to an event port buffer.
  101. *
  102. * Clients are to write the actual event data to be written starting at the
  103. * pointer returned by this function. Clients must not write more than
  104. * @a data_size bytes into this buffer. Clients must write normalised
  105. * MIDI data to the port - no running status and no (1-byte) realtime
  106. * messages interspersed with other messages (realtime messages are fine
  107. * when they occur on their own, like other messages).
  108. *
  109. * Events must be written in order, sorted by their sample offsets.
  110. * JACK will not sort the events for you, and will refuse to store
  111. * out-of-order events.
  112. *
  113. * @param port_buffer Buffer to write event to.
  114. * @param time Sample offset of event.
  115. * @param data_size Length of event's raw data in bytes.
  116. * @return Pointer to the beginning of the reserved event's data buffer, or
  117. * NULL on error (ie not enough space).
  118. */
  119. jack_midi_data_t*
  120. jack_midi_event_reserve(void *port_buffer,
  121. jack_nframes_t time,
  122. size_t data_size) JACK_OPTIONAL_WEAK_EXPORT;
  123. /** Write an event into an event port buffer.
  124. *
  125. * This function is simply a wrapper for @ref jack_midi_event_reserve
  126. * which writes the event data into the space reserved in the buffer.
  127. *
  128. * Clients must not write more than
  129. * @a data_size bytes into this buffer. Clients must write normalised
  130. * MIDI data to the port - no running status and no (1-byte) realtime
  131. * messages interspersed with other messages (realtime messages are fine
  132. * when they occur on their own, like other messages).
  133. *
  134. * Events must be written in order, sorted by their sample offsets.
  135. * JACK will not sort the events for you, and will refuse to store
  136. * out-of-order events.
  137. *
  138. * @param port_buffer Buffer to write event to.
  139. * @param time Sample offset of event.
  140. * @param data Message data to be written.
  141. * @param data_size Length of @a data in bytes.
  142. * @return 0 on success, ENOBUFS if there's not enough space in buffer for event.
  143. */
  144. int
  145. jack_midi_event_write(void *port_buffer,
  146. jack_nframes_t time,
  147. const jack_midi_data_t *data,
  148. size_t data_size) JACK_OPTIONAL_WEAK_EXPORT;
  149. /** Get the number of events that could not be written to @a port_buffer.
  150. *
  151. * This function returning a non-zero value implies @a port_buffer is full.
  152. * Currently the only way this can happen is if events are lost on port mixdown.
  153. *
  154. * @param port_buffer Port to receive count for.
  155. * @returns Number of events that could not be written to @a port_buffer.
  156. */
  157. uint32_t
  158. jack_midi_get_lost_event_count(void *port_buffer) JACK_OPTIONAL_WEAK_EXPORT;
  159. /*@}*/
  160. #ifdef __cplusplus
  161. }
  162. #endif
  163. #endif /* __JACK_MIDIPORT_H */