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.

185 lines
6.1KB

  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. * @param event Event structure to store retrieved event in.
  50. * @param port_buffer Port buffer from which to retrieve event.
  51. * @param event_index Index of event to retrieve.
  52. * @return 0 on success, ENODATA if buffer is empty.
  53. */
  54. int
  55. jack_midi_event_get(jack_midi_event_t *event,
  56. void *port_buffer,
  57. uint32_t event_index) JACK_OPTIONAL_WEAK_EXPORT;
  58. /** Clear an event buffer.
  59. *
  60. * This should be called at the beginning of each process cycle before calling
  61. * @ref jack_midi_event_reserve or @ref jack_midi_event_write. This
  62. * function may not be called on an input port's buffer.
  63. *
  64. * @param port_buffer Port buffer to clear (must be an output port buffer).
  65. */
  66. void
  67. jack_midi_clear_buffer(void *port_buffer) JACK_OPTIONAL_WEAK_EXPORT;
  68. /** Reset an event buffer (from data allocated outside of JACK).
  69. *
  70. * This should be called at the beginning of each process cycle before calling
  71. * @ref jack_midi_event_reserve or @ref jack_midi_event_write. This
  72. * function may not be called on an input port's buffer.
  73. *
  74. * @param port_buffer Port buffer to resetted.
  75. */
  76. void
  77. jack_midi_reset_buffer(void *port_buffer) JACK_OPTIONAL_WEAK_EXPORT;
  78. /** Get the size of the largest event that can be stored by the port.
  79. *
  80. * This function returns the current space available, taking into account
  81. * events already stored in the port.
  82. *
  83. * @param port_buffer Port buffer to check size of.
  84. */
  85. size_t
  86. jack_midi_max_event_size(void* port_buffer) JACK_OPTIONAL_WEAK_EXPORT;
  87. /** Allocate space for an event to be written to an event port buffer.
  88. *
  89. * Clients are to write the actual event data to be written starting at the
  90. * pointer returned by this function. Clients must not write more than
  91. * @a data_size bytes into this buffer. Clients must write normalised
  92. * MIDI data to the port - no running status and no (1-byte) realtime
  93. * messages interspersed with other messages (realtime messages are fine
  94. * when they occur on their own, like other messages).
  95. *
  96. * Events must be written in order, sorted by their sample offsets.
  97. * JACK will not sort the events for you, and will refuse to store
  98. * out-of-order events.
  99. *
  100. * @param port_buffer Buffer to write event to.
  101. * @param time Sample offset of event.
  102. * @param data_size Length of event's raw data in bytes.
  103. * @return Pointer to the beginning of the reserved event's data buffer, or
  104. * NULL on error (ie not enough space).
  105. */
  106. jack_midi_data_t*
  107. jack_midi_event_reserve(void *port_buffer,
  108. jack_nframes_t time,
  109. size_t data_size) JACK_OPTIONAL_WEAK_EXPORT;
  110. /** Write an event into an event port buffer.
  111. *
  112. * This function is simply a wrapper for @ref jack_midi_event_reserve
  113. * which writes the event data into the space reserved in the buffer.
  114. *
  115. * Clients must not write more than
  116. * @a data_size bytes into this buffer. Clients must write normalised
  117. * MIDI data to the port - no running status and no (1-byte) realtime
  118. * messages interspersed with other messages (realtime messages are fine
  119. * when they occur on their own, like other messages).
  120. *
  121. * Events must be written in order, sorted by their sample offsets.
  122. * JACK will not sort the events for you, and will refuse to store
  123. * out-of-order events.
  124. *
  125. * @param port_buffer Buffer to write event to.
  126. * @param time Sample offset of event.
  127. * @param data Message data to be written.
  128. * @param data_size Length of @a data in bytes.
  129. * @return 0 on success, ENOBUFS if there's not enough space in buffer for event.
  130. */
  131. int
  132. jack_midi_event_write(void *port_buffer,
  133. jack_nframes_t time,
  134. const jack_midi_data_t *data,
  135. size_t data_size) JACK_OPTIONAL_WEAK_EXPORT;
  136. /** Get the number of events that could not be written to @a port_buffer.
  137. *
  138. * This function returning a non-zero value implies @a port_buffer is full.
  139. * Currently the only way this can happen is if events are lost on port mixdown.
  140. *
  141. * @param port_buffer Port to receive count for.
  142. * @returns Number of events that could not be written to @a port_buffer.
  143. */
  144. uint32_t
  145. jack_midi_get_lost_event_count(void *port_buffer) JACK_OPTIONAL_WEAK_EXPORT;
  146. /*@}*/
  147. #ifdef __cplusplus
  148. }
  149. #endif
  150. #endif /* __JACK_MIDIPORT_H */