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.

115 lines
3.4KB

  1. /*
  2. Copyright (C) 2007 Dmitry Baikov
  3. Original JACK MIDI API 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. #ifndef __JackEventPort__
  17. #define __JackEventPort__
  18. #include "types.h"
  19. #include "JackConstants.h"
  20. #include "JackPlatformPlug.h"
  21. #include <stddef.h>
  22. /** Type for raw event data contained in @ref jack_event_t. */
  23. typedef unsigned char jack_event_data_t;
  24. /** A Jack event. */
  25. struct jack_event_t
  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_event_data_t *buffer; /**< Raw event data */
  30. };
  31. /** A Jack MIDI port type. */
  32. #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi"
  33. /** A Jack OSC port type. */
  34. #define JACK_DEFAULT_OSC_TYPE "32 bit OSC"
  35. /** If you want to toy around with a custom
  36. * event protocol (maybe MIDI 3.0?). Please put details
  37. * about it into the metadata.
  38. */
  39. #define JACK_DEFAULT_EVENT_TYPE "generic binary data"
  40. namespace Jack
  41. {
  42. struct SERVER_EXPORT JackEvent
  43. {
  44. /** Most MIDI events are < 4 bytes in size, so we can save a lot, storing them inplace.
  45. * "inplace" means that instead of storing an offset to the actual data we store 4 bytes in that
  46. * pointer. This is not relevant for OSC data (and other newer protocols) since most packets are a
  47. * lot larger.
  48. */
  49. enum { INLINE_SIZE_MAX = sizeof(jack_shmsize_t) };
  50. uint32_t time;
  51. jack_shmsize_t size;
  52. union {
  53. jack_shmsize_t offset;
  54. jack_event_data_t data[INLINE_SIZE_MAX];
  55. };
  56. jack_event_data_t* GetData(void* buffer)
  57. {
  58. if (size <= INLINE_SIZE_MAX) {
  59. return data;
  60. } else {
  61. return (jack_event_data_t*)buffer + offset;
  62. }
  63. }
  64. };
  65. /*
  66. * To store events with arbitrarily sized payload, but still have O(1) indexed access
  67. * we use a trick here:
  68. * Events are stored in an linear array from the beginning of the buffer,
  69. * but their data (if not inlined) is stored from the end of the same buffer.
  70. */
  71. struct SERVER_EXPORT JackEventBuffer
  72. {
  73. enum { MAGIC = 0x900df00d };
  74. uint32_t magic;
  75. jack_shmsize_t buffer_size;
  76. jack_nframes_t nframes;
  77. jack_shmsize_t write_pos; //!< data write position from the end of the buffer.
  78. uint32_t event_count;
  79. uint32_t lost_events;
  80. JackEvent events[1]; // Using 0 size does not compile with older GCC versions, so use 1 here.
  81. int IsValid() const
  82. {
  83. return magic == MAGIC;
  84. }
  85. void Reset(jack_nframes_t nframes);
  86. jack_shmsize_t MaxEventSize() const;
  87. // checks only size constraints.
  88. jack_event_data_t* ReserveEvent(jack_nframes_t time, jack_shmsize_t size);
  89. };
  90. void EventBufferInit(void* buffer, size_t buffer_size, jack_nframes_t nframes);
  91. } // namespace Jack
  92. #endif