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.

208 lines
7.2KB

  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_event_event_t. */
  24. typedef unsigned char jack_event_data_t;
  25. /** A Jack event. */
  26. typedef struct _jack_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_event_data_t *buffer; /**< Raw event data */
  31. } jack_event_t;
  32. /**
  33. * @defgroup EVENTAPI Reading and writing event 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_event_get_count(void* port_buffer) JACK_OPTIONAL_WEAK_EXPORT;
  43. /** Get an event from an event port buffer. It is up to the caller to determine
  44. * which protocol to interpret the data with. The port's type and the metadata
  45. * API should suffice to do so.
  46. *
  47. * If the event represents MIDI data:
  48. *
  49. * Jack MIDI is normalised, the MIDI event returned by this function is
  50. * guaranteed to be a complete MIDI event (the status byte will always be
  51. * present, and no realtime events will interspered with the event).
  52. *
  53. * This rule does not apply to System Exclusive MIDI messages
  54. * since they can be of arbitrary length.
  55. * To maintain smooth realtime operation such events CAN be deliverd
  56. * as multiple, non-normalised events.
  57. * The maximum size of one event "chunk" depends on the MIDI backend in use.
  58. * For example the midiseq driver will create chunks of 256 bytes.
  59. * The first SysEx "chunked" event starts with 0xF0 and the last
  60. * delivered chunk ends with 0xF7.
  61. * To receive the full SysEx message, a caller of jack_midi_event_get()
  62. * must concatenate chunks until a chunk ends with 0xF7.
  63. *
  64. * @param event Event structure to store retrieved event in.
  65. * @param port_buffer Port buffer from which to retrieve event.
  66. * @param event_index Index of event to retrieve.
  67. * @return 0 on success, ENODATA if buffer is empty.
  68. */
  69. int
  70. jack_event_get(jack_event_t *event,
  71. void *port_buffer,
  72. uint32_t event_index) JACK_OPTIONAL_WEAK_EXPORT;
  73. /** Clear an event buffer.
  74. *
  75. * This should be called at the beginning of each process cycle before calling
  76. * @ref jack_event_reserve or @ref jack_event_write. This
  77. * function may not be called on an input port's buffer.
  78. *
  79. * @param port_buffer Port buffer to clear (must be an output port buffer).
  80. */
  81. void
  82. jack_event_clear_buffer(void *port_buffer) JACK_OPTIONAL_WEAK_EXPORT;
  83. /** Reset an event buffer (from data allocated outside of JACK).
  84. *
  85. * This should be called at the beginning of each process cycle before calling
  86. * @ref jack_event_reserve or @ref jack_event_write. This
  87. * function may not be called on an input port's buffer.
  88. *
  89. * @deprecated Please use jack_event_clear_buffer().
  90. *
  91. * @param port_buffer Port buffer to reset.
  92. */
  93. void
  94. jack_event_reset_buffer(void *port_buffer) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  95. /** Get the size of the largest event that can be stored by the port.
  96. *
  97. * This function returns the current space available, taking into account
  98. * events already stored in the port.
  99. *
  100. * @param port_buffer Port buffer to check size of.
  101. */
  102. size_t
  103. jack_event_max_size(void* port_buffer) JACK_OPTIONAL_WEAK_EXPORT;
  104. /** Allocate space for an event to be written to an event port buffer.
  105. *
  106. * Clients are to write the actual event data to be written starting at the
  107. * pointer returned by this function. Clients must not write more than
  108. * @a data_size bytes into this buffer. Clients may write arbitrary binary data,
  109. * but should only write events using the protocol associated with the port.
  110. *
  111. * If this is a MIDI port, clients must write normalised
  112. * MIDI data to the port - no running status and no (1-byte) realtime
  113. * messages interspersed with other messages (realtime messages are fine
  114. * when they occur on their own, like other messages).
  115. *
  116. * Events must be written in order, sorted by their sample offsets.
  117. * JACK will not sort the events for you, and will refuse to store
  118. * out-of-order events.
  119. *
  120. * @param port_buffer Buffer to write event to.
  121. * @param time Sample offset of event.
  122. * @param data_size Length of event's raw data in bytes.
  123. * @return Pointer to the beginning of the reserved event's data buffer, or
  124. * NULL on error (ie not enough space).
  125. */
  126. jack_event_data_t*
  127. jack_event_reserve(void *port_buffer,
  128. jack_nframes_t time,
  129. size_t data_size) JACK_OPTIONAL_WEAK_EXPORT;
  130. /** Write an event into an event port buffer.
  131. *
  132. * This function is simply a wrapper for @ref jack_event_reserve
  133. * which writes the event data into the space reserved in the buffer.
  134. *
  135. * Clients must not write more than
  136. * @a data_size bytes into this buffer. Clients may write arbitrary binary data,
  137. * but should only write events using the protocol associated with the port.
  138. * If this is a MIDI port, clients must write normalised
  139. * MIDI data to the port - no running status and no (1-byte) realtime
  140. * messages interspersed with other messages (realtime messages are fine
  141. * when they occur on their own, like other messages).
  142. *
  143. * Events must be written in order, sorted by their sample offsets.
  144. * JACK will not sort the events for you, and will refuse to store
  145. * out-of-order events.
  146. *
  147. * @param port_buffer Buffer to write event to.
  148. * @param time Sample offset of event.
  149. * @param data Message data to be written.
  150. * @param data_size Length of @a data in bytes.
  151. * @return 0 on success, ENOBUFS if there's not enough space in buffer for event.
  152. */
  153. int
  154. jack_event_write(void *port_buffer,
  155. jack_nframes_t time,
  156. const jack_event_data_t *data,
  157. size_t data_size) JACK_OPTIONAL_WEAK_EXPORT;
  158. /** Get the number of events that could not be written to @a port_buffer.
  159. *
  160. * This function returning a non-zero value implies @a port_buffer is full.
  161. * Currently the only way this can happen is if events are lost on port mixdown
  162. * (when multiple event output ports are connected to one input port).
  163. *
  164. * @param port_buffer Port to receive count for.
  165. * @returns Number of events that could not be written to @a port_buffer.
  166. */
  167. uint32_t
  168. jack_event_get_lost_count(void *port_buffer) JACK_OPTIONAL_WEAK_EXPORT;
  169. /*@}*/
  170. #ifdef __cplusplus
  171. }
  172. #endif
  173. #endif /* __JACK_MIDIPORT_H */