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.

160 lines
5.0KB

  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/types.h>
  21. #include <stdlib.h>
  22. /** Type for raw event data contained in @ref jack_midi_event_t. */
  23. typedef unsigned char jack_midi_data_t;
  24. /** A Jack MIDI event. */
  25. typedef struct _jack_midi_event
  26. {
  27. jack_nframes_t time; /**< Sample index at which event is valid */
  28. size_t size; /**< Number of bytes of data in \a buffer */
  29. jack_midi_data_t *buffer; /**< Raw MIDI data */
  30. } jack_midi_event_t;
  31. /**
  32. * @defgroup MIDIAPI Reading and writing MIDI data
  33. * @{
  34. */
  35. /** Get number of events in a port buffer.
  36. *
  37. * @param port_buffer Port buffer from which to retrieve event.
  38. * @return number of events inside @a port_buffer
  39. */
  40. jack_nframes_t
  41. jack_midi_get_event_count(void* port_buffer);
  42. /** Get a MIDI event from an event port buffer.
  43. *
  44. * Jack MIDI is normalised, the MIDI event returned by this function is
  45. * guaranteed to be a complete MIDI event (the status byte will always be
  46. * present, and no realtime events will interspered with the event).
  47. *
  48. * @param event Event structure to store retrieved event in.
  49. * @param port_buffer Port buffer from which to retrieve event.
  50. * @param event_index Index of event to retrieve.
  51. * @return 0 on success, ENODATA if buffer is empty.
  52. */
  53. int
  54. jack_midi_event_get(jack_midi_event_t *event,
  55. void *port_buffer,
  56. jack_nframes_t event_index);
  57. /** Clear an event buffer.
  58. *
  59. * This should be called at the beginning of each process cycle before calling
  60. * @ref jack_midi_event_reserve or @ref jack_midi_event_write. This
  61. * function may not be called on an input port's buffer.
  62. *
  63. * @param port_buffer Port buffer to clear (must be an output port buffer).
  64. */
  65. void
  66. jack_midi_clear_buffer(void *port_buffer);
  67. /** Get the size of the largest event that can be stored by the port.
  68. *
  69. * This function returns the current space available, taking into account
  70. * events already stored in the port.
  71. *
  72. * @param port_buffer Port buffer to check size of.
  73. */
  74. size_t
  75. jack_midi_max_event_size(void* port_buffer);
  76. /** Allocate space for an event to be written to an event port buffer.
  77. *
  78. * Clients are to write the actual event data to be written starting at the
  79. * pointer returned by this function. Clients must not write more than
  80. * @a data_size bytes into this buffer. Clients must write normalised
  81. * MIDI data to the port - no running status and no (1-byte) realtime
  82. * messages interspersed with other messages (realtime messages are fine
  83. * when they occur on their own, like other messages).
  84. *
  85. * @param port_buffer Buffer to write event to.
  86. * @param time Sample offset of event.
  87. * @param data_size Length of event's raw data in bytes.
  88. * @return Pointer to the beginning of the reserved event's data buffer, or
  89. * NULL on error (ie not enough space).
  90. */
  91. jack_midi_data_t*
  92. jack_midi_event_reserve(void *port_buffer,
  93. jack_nframes_t time,
  94. size_t data_size);
  95. /** Write an event into an event port buffer.
  96. *
  97. * This function is simply a wrapper for @ref jack_midi_event_reserve
  98. * which writes the event data into the space reserved in the buffer.
  99. * The same restrictions on the MIDI data apply.
  100. *
  101. * @param port_buffer Buffer to write event to.
  102. * @param time Sample offset of event.
  103. * @param data Message data to be written.
  104. * @param data_size Length of @a data in bytes.
  105. * @return 0 on success, ENOBUFS if there's not enough space in buffer for event.
  106. */
  107. int
  108. jack_midi_event_write(void *port_buffer,
  109. jack_nframes_t time,
  110. const jack_midi_data_t *data,
  111. size_t data_size);
  112. /** Get the number of events that could not be written to @a port_buffer.
  113. *
  114. * This function returning a non-zero value implies @a port_buffer is full.
  115. * Currently the only way this can happen is if events are lost on port mixdown.
  116. *
  117. * @param port_buffer Port to receive count for.
  118. * @returns Number of events that could not be written to @a port_buffer.
  119. */
  120. jack_nframes_t
  121. jack_midi_get_lost_event_count(void *port_buffer);
  122. /*@}*/
  123. #ifdef __cplusplus
  124. }
  125. #endif
  126. #endif /* __JACK_MIDIPORT_H */