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.

132 lines
3.8KB

  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 "JackMidiPort.h"
  18. #include "JackCompilerDeps.h"
  19. #include <errno.h>
  20. #include <string.h>
  21. #include "JackSystemDeps.h"
  22. #ifdef __cplusplus
  23. extern "C"
  24. {
  25. #endif
  26. EXPORT jack_nframes_t jack_midi_get_event_count(void* port_buffer);
  27. EXPORT int jack_midi_event_get(jack_midi_event_t* event,
  28. void* port_buffer, jack_nframes_t event_index);
  29. EXPORT void jack_midi_clear_buffer(void* port_buffer);
  30. EXPORT size_t jack_midi_max_event_size(void* port_buffer);
  31. EXPORT jack_midi_data_t* jack_midi_event_reserve(void* port_buffer,
  32. jack_nframes_t time, size_t data_size);
  33. EXPORT int jack_midi_event_write(void* port_buffer,
  34. jack_nframes_t time, const jack_midi_data_t* data, size_t data_size);
  35. EXPORT jack_nframes_t jack_midi_get_lost_event_count(void* port_buffer);
  36. #ifdef __cplusplus
  37. }
  38. #endif
  39. using namespace Jack;
  40. EXPORT
  41. jack_nframes_t jack_midi_get_event_count(void* port_buffer)
  42. {
  43. JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer;
  44. if (!buf || !buf->IsValid())
  45. return 0;
  46. return buf->event_count;
  47. }
  48. EXPORT
  49. int jack_midi_event_get(jack_midi_event_t *event, void* port_buffer, jack_nframes_t event_index)
  50. {
  51. JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer;
  52. if (!buf || !buf->IsValid())
  53. return -EINVAL;
  54. if (event_index >= buf->event_count)
  55. return -ENOBUFS;
  56. JackMidiEvent* ev = &buf->events[event_index];
  57. event->time = ev->time;
  58. event->size = ev->size;
  59. event->buffer = ev->GetData(buf);
  60. return 0;
  61. }
  62. EXPORT
  63. void jack_midi_clear_buffer(void* port_buffer)
  64. {
  65. JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer;
  66. if (buf && buf->IsValid())
  67. buf->Reset(buf->nframes);
  68. }
  69. EXPORT
  70. size_t jack_midi_max_event_size(void* port_buffer)
  71. {
  72. JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer;
  73. if (buf && buf->IsValid())
  74. return buf->MaxEventSize();
  75. return 0;
  76. }
  77. EXPORT
  78. jack_midi_data_t* jack_midi_event_reserve(void* port_buffer, jack_nframes_t time, size_t data_size)
  79. {
  80. JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer;
  81. if (!buf && !buf->IsValid())
  82. return 0;
  83. if (time >= buf->nframes || (buf->event_count && buf->events[buf->event_count - 1].time > time))
  84. return 0;
  85. return buf->ReserveEvent(time, data_size);
  86. }
  87. EXPORT
  88. int jack_midi_event_write(void* port_buffer,
  89. jack_nframes_t time, const jack_midi_data_t* data, size_t data_size)
  90. {
  91. JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer;
  92. if (!buf && !buf->IsValid())
  93. return -EINVAL;
  94. if (time >= buf->nframes || (buf->event_count && buf->events[buf->event_count - 1].time > time))
  95. return -EINVAL;
  96. jack_midi_data_t* dest = buf->ReserveEvent(time, data_size);
  97. if (!dest)
  98. return -ENOBUFS;
  99. memcpy(dest, data, data_size);
  100. return 0;
  101. }
  102. EXPORT
  103. jack_nframes_t jack_midi_get_lost_event_count(void* port_buffer)
  104. {
  105. JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer;
  106. if (buf && buf->IsValid())
  107. return buf->lost_events;
  108. return 0;
  109. }