Audio plugin host https://kx.studio/carla
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.

98 lines
2.9KB

  1. /*
  2. * Copyright (c) 2012 Mark McCurry
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  19. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. */
  24. #ifndef RTOSC_THREAD_LINK
  25. #define RTOSC_THREAD_LINK
  26. #include <cstring>
  27. #include <cassert>
  28. #include <cstdio>
  29. #include <rtosc/rtosc.h>
  30. namespace rtosc {
  31. typedef const char *msg_t;
  32. /**
  33. * ThreadLink - A simple wrapper around jack's ringbuffers desinged to make
  34. * sending messages via rt-osc trivial.
  35. * This class provides the basics of reading and writing events via fixed sized
  36. * buffers, which can be specified at compile time.
  37. */
  38. class ThreadLink
  39. {
  40. public:
  41. ThreadLink(size_t max_message_length, size_t max_messages);
  42. ~ThreadLink(void);
  43. /**
  44. * Write message to ringbuffer
  45. * @see rtosc_message()
  46. */
  47. void write(const char *dest, const char *args, ...);
  48. /**
  49. * Write an arary of arguments to ringbuffer
  50. * @see rtosc_amessage()
  51. */
  52. void writeArray(const char *dest, const char *args, const rtosc_arg_t *aargs);
  53. /**
  54. * Directly write message to ringbuffer
  55. */
  56. void raw_write(const char *msg);
  57. /**
  58. * @returns true iff there is another message to be read in the buffer
  59. */
  60. bool hasNext(void) const;
  61. /**
  62. * Read a new message from the ringbuffer
  63. */
  64. msg_t read(void);
  65. /**
  66. * Peak at last message read without reading another
  67. */
  68. msg_t peak(void) const;
  69. /**
  70. * Raw write buffer access for more complicated task
  71. */
  72. char *buffer(void);
  73. /**
  74. * Access to write buffer length
  75. */
  76. size_t buffer_size(void) const;
  77. private:
  78. const size_t MaxMsg;
  79. const size_t BufferSize;
  80. char *write_buffer;
  81. char *read_buffer;
  82. struct internal_ringbuffer_t *ring;
  83. };
  84. };
  85. #endif