Lv2Evbuf.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * lv2_evbuf.h - Lv2 event buffer definitions
  3. *
  4. * Copyright (c) 2019-2020 Johannes Lorenz <jlsf2013$users.sourceforge.net, $=@>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. /*
  25. * The original code was written by David Robillard <http://drobilla.net>
  26. * Original version: 6f22ee0 from https://github.com/drobilla/jalv.git
  27. * Minor changes have been done, but no functional changes.
  28. * Considering this as an "external library", the identifiers do not need to
  29. * match the LMMS coding conventions.
  30. */
  31. #ifndef LV2_EVBUF_H
  32. #define LV2_EVBUF_H
  33. #include "lmmsconfig.h"
  34. #ifdef LMMS_HAVE_LV2
  35. #include <cstdint>
  36. /**
  37. An abstract/opaque LV2 event buffer.
  38. */
  39. typedef struct LV2_Evbuf_Impl LV2_Evbuf;
  40. /**
  41. An iterator over an LV2_Evbuf.
  42. */
  43. typedef struct {
  44. LV2_Evbuf* evbuf;
  45. uint32_t offset;
  46. } LV2_Evbuf_Iterator;
  47. /**
  48. Allocate a new, empty event buffer.
  49. URIDs for atom:Chunk and atom:Sequence must be passed for LV2_EVBUF_ATOM.
  50. */
  51. LV2_Evbuf*
  52. lv2_evbuf_new(uint32_t capacity, uint32_t atom_Chunk, uint32_t atom_Sequence);
  53. /**
  54. Free an event buffer allocated with lv2_evbuf_new.
  55. */
  56. void
  57. lv2_evbuf_free(LV2_Evbuf* evbuf);
  58. /**
  59. Clear and initialize an existing event buffer.
  60. The contents of buf are ignored entirely and overwritten, except capacity
  61. which is unmodified.
  62. If input is false and this is an atom buffer, the buffer will be prepared
  63. for writing by the plugin. This MUST be called before every run cycle.
  64. */
  65. void
  66. lv2_evbuf_reset(LV2_Evbuf* evbuf, bool input);
  67. /**
  68. Return the total padded size of the events stored in the buffer.
  69. */
  70. uint32_t
  71. lv2_evbuf_get_size(LV2_Evbuf* evbuf);
  72. /**
  73. Return the actual buffer implementation.
  74. The format of the buffer returned depends on the buffer type.
  75. */
  76. void*
  77. lv2_evbuf_get_buffer(LV2_Evbuf* evbuf);
  78. /**
  79. Return an iterator to the start of `evbuf`.
  80. */
  81. LV2_Evbuf_Iterator
  82. lv2_evbuf_begin(LV2_Evbuf* evbuf);
  83. /**
  84. Return an iterator to the end of `evbuf`.
  85. */
  86. LV2_Evbuf_Iterator
  87. lv2_evbuf_end(LV2_Evbuf* evbuf);
  88. /**
  89. Check if `iter` is valid.
  90. @return True if `iter` is valid, otherwise false (past end of buffer)
  91. */
  92. bool
  93. lv2_evbuf_is_valid(LV2_Evbuf_Iterator iter);
  94. /**
  95. Advance `iter` forward one event.
  96. `iter` must be valid.
  97. @return True if `iter` is valid, otherwise false (reached end of buffer)
  98. */
  99. LV2_Evbuf_Iterator
  100. lv2_evbuf_next(LV2_Evbuf_Iterator iter);
  101. /**
  102. Dereference an event iterator (i.e. get the event currently pointed to).
  103. `iter` must be valid.
  104. `type` Set to the type of the event.
  105. `size` Set to the size of the event.
  106. `data` Set to the contents of the event.
  107. @return True on success.
  108. */
  109. bool
  110. lv2_evbuf_get( LV2_Evbuf_Iterator iter,
  111. uint32_t* frames,
  112. uint32_t* type,
  113. uint32_t* size,
  114. uint8_t** data);
  115. /**
  116. Write an event at `iter`.
  117. The event (if any) pointed to by `iter` will be overwritten, and `iter`
  118. incremented to point to the following event (i.e. several calls to this
  119. function can be done in sequence without twiddling iter in-between).
  120. @return True if event was written, otherwise false (buffer is full).
  121. */
  122. bool
  123. lv2_evbuf_write( LV2_Evbuf_Iterator* iter,
  124. uint32_t frames,
  125. uint32_t type,
  126. uint32_t size,
  127. const uint8_t* data);
  128. #endif // LMMS_HAVE_LV2
  129. #endif // LV2_EVBUF_H