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.

161 lines
4.5KB

  1. /*
  2. Copyright (C) 2007 Dmitry Baikov
  3. Original JACK MIDI implementation Copyright (C) 2004 Ian Esten
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #include "JackError.h"
  17. #include "JackEventPort.h"
  18. #include <errno.h>
  19. #include <string.h>
  20. #ifdef __cplusplus
  21. extern "C"
  22. {
  23. #endif
  24. LIB_EXPORT uint32_t jack_event_get_count(void* port_buffer);
  25. LIB_EXPORT int jack_event_get(jack_event_t* event,
  26. void* port_buffer, uint32_t event_index);
  27. LIB_EXPORT void jack_event_clear_buffer(void* port_buffer);
  28. LIB_EXPORT void jack_event_reset_buffer(void* port_buffer);
  29. LIB_EXPORT size_t jack_event_max_size(void* port_buffer);
  30. LIB_EXPORT jack_event_data_t* jack_event_reserve(void* port_buffer,
  31. jack_nframes_t time, size_t data_size);
  32. LIB_EXPORT int jack_event_write(void* port_buffer,
  33. jack_nframes_t time, const jack_event_data_t* data, size_t data_size);
  34. LIB_EXPORT jack_nframes_t jack_event_get_lost_count(void* port_buffer);
  35. #ifdef __cplusplus
  36. }
  37. #endif
  38. using namespace Jack;
  39. LIB_EXPORT
  40. uint32_t jack_event_get_count(void* port_buffer)
  41. {
  42. JackEventBuffer *buf = (JackEventBuffer*)port_buffer;
  43. if (!buf || !buf->IsValid()) {
  44. return 0;
  45. }
  46. return buf->event_count;
  47. }
  48. LIB_EXPORT
  49. int jack_event_get(jack_event_t *event, void* port_buffer, uint32_t event_index)
  50. {
  51. JackEventBuffer *buf = (JackEventBuffer*)port_buffer;
  52. if (!buf || !buf->IsValid()) {
  53. return -EINVAL;
  54. }
  55. if (event_index >= buf->event_count) {
  56. return -ENOBUFS;
  57. }
  58. JackEvent* ev = &buf->events[event_index];
  59. event->time = ev->time;
  60. event->size = ev->size;
  61. event->buffer = ev->GetData(buf);
  62. return 0;
  63. }
  64. LIB_EXPORT
  65. void jack_event_clear_buffer(void* port_buffer)
  66. {
  67. JackEventBuffer *buf = (JackEventBuffer*)port_buffer;
  68. if (buf && buf->IsValid()) {
  69. buf->Reset(buf->nframes);
  70. }
  71. }
  72. LIB_EXPORT
  73. void jack_event_reset_buffer(void* port_buffer)
  74. {
  75. EventBufferInit(port_buffer, BUFFER_SIZE_MAX, BUFFER_SIZE_MAX);
  76. }
  77. LIB_EXPORT
  78. size_t jack_event_max_size(void* port_buffer)
  79. {
  80. JackEventBuffer *buf = (JackEventBuffer*)port_buffer;
  81. if (buf && buf->IsValid()) {
  82. return buf->MaxEventSize();
  83. }
  84. return 0;
  85. }
  86. LIB_EXPORT
  87. jack_event_data_t* jack_event_reserve(void* port_buffer, jack_nframes_t time, size_t data_size)
  88. {
  89. JackEventBuffer *buf = (JackEventBuffer*)port_buffer;
  90. if (! buf) {
  91. jack_error("jack_event_reserve: port buffer is set to NULL");
  92. return 0;
  93. }
  94. if (! buf->IsValid()) {
  95. jack_error("jack_event_reserve: port buffer is invalid");
  96. return 0;
  97. }
  98. if (time >= buf->nframes) {
  99. jack_error("jack_event_reserve: time parameter is out of range "
  100. "(%lu >= %lu)", time, buf->nframes);
  101. return 0;
  102. }
  103. if (buf->event_count && (buf->events[buf->event_count - 1].time > time)) {
  104. jack_error("jack_event_reserve: time parameter is earlier than "
  105. "last reserved event");
  106. return 0;
  107. }
  108. return buf->ReserveEvent(time, data_size);
  109. }
  110. LIB_EXPORT
  111. int jack_event_write(void* port_buffer,
  112. jack_nframes_t time, const jack_event_data_t* data, size_t data_size)
  113. {
  114. JackEventBuffer *buf = (JackEventBuffer*)port_buffer;
  115. if (!buf || !buf->IsValid()) {
  116. return -EINVAL;
  117. }
  118. if (time >= buf->nframes || (buf->event_count && buf->events[buf->event_count - 1].time > time)) {
  119. return -EINVAL;
  120. }
  121. jack_event_data_t* dest = buf->ReserveEvent(time, data_size);
  122. if (!dest) {
  123. return -ENOBUFS;
  124. }
  125. memcpy(dest, data, data_size);
  126. return 0;
  127. }
  128. LIB_EXPORT
  129. uint32_t jack_event_get_lost_count(void* port_buffer)
  130. {
  131. JackEventBuffer *buf = (JackEventBuffer*)port_buffer;
  132. if (buf && buf->IsValid()) {
  133. return buf->lost_events;
  134. }
  135. return 0;
  136. }