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.

101 lines
2.7KB

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