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.

174 lines
5.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. jack_nframes_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. jack_nframes_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. /** Get the size of the largest event that can be stored by the port.
  69. *
  70. * This function returns the current space available, taking into account
  71. * events already stored in the port.
  72. *
  73. * @param port_buffer Port buffer to check size of.
  74. */
  75. size_t
  76. jack_midi_max_event_size(void* port_buffer) JACK_OPTIONAL_WEAK_EXPORT;
  77. /** Allocate space for an event to be written to an event port buffer.
  78. *
  79. * Clients are to write the actual event data to be written starting at the
  80. * pointer returned by this function. Clients must not write more than
  81. * @a data_size bytes into this buffer. Clients must write normalised
  82. * MIDI data to the port - no running status and no (1-byte) realtime
  83. * messages interspersed with other messages (realtime messages are fine
  84. * when they occur on their own, like other messages).
  85. *
  86. * Events must be written in order, sorted by their sample offsets.
  87. * JACK will not sort the events for you, and will refuse to store
  88. * out-of-order events.
  89. *
  90. * @param port_buffer Buffer to write event to.
  91. * @param time Sample offset of event.
  92. * @param data_size Length of event's raw data in bytes.
  93. * @return Pointer to the beginning of the reserved event's data buffer, or
  94. * NULL on error (ie not enough space).
  95. */
  96. jack_midi_data_t*
  97. jack_midi_event_reserve(void *port_buffer,
  98. jack_nframes_t time,
  99. size_t data_size) JACK_OPTIONAL_WEAK_EXPORT;
  100. /** Write an event into an event port buffer.
  101. *
  102. * This function is simply a wrapper for @ref jack_midi_event_reserve
  103. * which writes the event data into the space reserved in the buffer.
  104. *
  105. * Clients must not write more than
  106. * @a data_size bytes into this buffer. Clients must write normalised
  107. * MIDI data to the port - no running status and no (1-byte) realtime
  108. * messages interspersed with other messages (realtime messages are fine
  109. * when they occur on their own, like other messages).
  110. *
  111. * Events must be written in order, sorted by their sample offsets.
  112. * JACK will not sort the events for you, and will refuse to store
  113. * out-of-order events.
  114. *
  115. * @param port_buffer Buffer to write event to.
  116. * @param time Sample offset of event.
  117. * @param data Message data to be written.
  118. * @param data_size Length of @a data in bytes.
  119. * @return 0 on success, ENOBUFS if there's not enough space in buffer for event.
  120. */
  121. int
  122. jack_midi_event_write(void *port_buffer,
  123. jack_nframes_t time,
  124. const jack_midi_data_t *data,
  125. size_t data_size) JACK_OPTIONAL_WEAK_EXPORT;
  126. /** Get the number of events that could not be written to @a port_buffer.
  127. *
  128. * This function returning a non-zero value implies @a port_buffer is full.
  129. * Currently the only way this can happen is if events are lost on port mixdown.
  130. *
  131. * @param port_buffer Port to receive count for.
  132. * @returns Number of events that could not be written to @a port_buffer.
  133. */
  134. jack_nframes_t
  135. jack_midi_get_lost_event_count(void *port_buffer) JACK_OPTIONAL_WEAK_EXPORT;
  136. /*@}*/
  137. #ifdef __cplusplus
  138. }
  139. #endif
  140. #endif /* __JACK_MIDIPORT_H */