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.

104 lines
2.9KB

  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 __JackMidiPort__
  17. #define __JackMidiPort__
  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_midi_event_t. */
  23. typedef unsigned char jack_midi_data_t;
  24. /** A Jack MIDI event. */
  25. struct jack_midi_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_midi_data_t *buffer; /**< Raw MIDI data */
  30. };
  31. /** A Jack MIDI port type. */
  32. #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi"
  33. namespace Jack
  34. {
  35. struct SERVER_EXPORT JackMidiEvent
  36. {
  37. // Most MIDI events are < 4 bytes in size, so we can save a lot, storing them inplace.
  38. enum { INLINE_SIZE_MAX = sizeof(jack_shmsize_t) };
  39. uint32_t time;
  40. jack_shmsize_t size;
  41. union {
  42. jack_shmsize_t offset;
  43. jack_midi_data_t data[INLINE_SIZE_MAX];
  44. };
  45. jack_midi_data_t* GetData(void* buffer)
  46. {
  47. if (size <= INLINE_SIZE_MAX) {
  48. return data;
  49. } else {
  50. return (jack_midi_data_t*)buffer + offset;
  51. }
  52. }
  53. };
  54. /*
  55. * To store events with arbitrarily sized payload, but still have O(1) indexed access
  56. * we use a trick here:
  57. * Events are stored in an linear array from the beginning of the buffer,
  58. * but their data (if not inlined) is stored from the end of the same buffer.
  59. */
  60. struct SERVER_EXPORT JackMidiBuffer
  61. {
  62. enum { MAGIC = 0x900df00d };
  63. uint32_t magic;
  64. jack_shmsize_t buffer_size;
  65. jack_nframes_t nframes;
  66. jack_shmsize_t write_pos; //!< data write position from the end of the buffer.
  67. uint32_t event_count;
  68. uint32_t lost_events;
  69. JackMidiEvent events[1]; // Using 0 size does not compile with older GCC versions, so use 1 here.
  70. int IsValid() const
  71. {
  72. return magic == MAGIC;
  73. }
  74. void Reset(jack_nframes_t nframes);
  75. jack_shmsize_t MaxEventSize() const;
  76. // checks only size constraints.
  77. jack_midi_data_t* ReserveEvent(jack_nframes_t time, jack_shmsize_t size);
  78. };
  79. void MidiBufferInit(void* buffer, size_t buffer_size, jack_nframes_t nframes);
  80. } // namespace Jack
  81. #endif