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.

99 lines
3.0KB

  1. /*
  2. Copyright (C) 2010 Devin Anderson
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2.1 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #ifndef __JackMidiAsyncQueue__
  16. #define __JackMidiAsyncQueue__
  17. #include "JackMidiPort.h"
  18. #include "JackMidiReadQueue.h"
  19. #include "JackMidiWriteQueue.h"
  20. #include "ringbuffer.h"
  21. namespace Jack {
  22. /**
  23. * This is a MIDI message queue designed to allow two threads to pass MIDI
  24. * messages between two threads (though it can also be used to buffer
  25. * events internally). This is especially useful if the MIDI API
  26. * you're attempting to interface with doesn't provide the ability to
  27. * schedule MIDI events ahead of time and/or has blocking send/receive
  28. * calls, as it allows a separate thread to handle input/output while the
  29. * JACK process thread copies events from a `JackMidiBufferReadQueue` to
  30. * this queue, or from this queue to a `JackMidiBufferWriteQueue`.
  31. */
  32. class SERVER_EXPORT JackMidiAsyncQueue:
  33. public JackMidiReadQueue, public JackMidiWriteQueue {
  34. private:
  35. static const size_t INFO_SIZE =
  36. sizeof(jack_nframes_t) + sizeof(size_t);
  37. jack_ringbuffer_t *byte_ring;
  38. jack_midi_data_t *data_buffer;
  39. jack_midi_event_t dequeue_event;
  40. jack_ringbuffer_t *info_ring;
  41. size_t max_bytes;
  42. public:
  43. using JackMidiWriteQueue::EnqueueEvent;
  44. /**
  45. * Creates a new asynchronous MIDI message queue. The queue can store
  46. * up to `max_messages` MIDI messages and up to `max_bytes` of MIDI
  47. * data before it starts rejecting messages.
  48. */
  49. JackMidiAsyncQueue(size_t max_bytes=4096, size_t max_messages=1024);
  50. virtual ~JackMidiAsyncQueue();
  51. /**
  52. * Dequeues and returns a MIDI event. Returns '0' if there are no MIDI
  53. * events available. This method may be overridden.
  54. */
  55. virtual jack_midi_event_t *
  56. DequeueEvent();
  57. /**
  58. * Enqueues the MIDI event specified by the arguments. The return
  59. * value indiciates whether or not the event was successfully enqueued.
  60. * This method may be overridden.
  61. */
  62. virtual EnqueueResult
  63. EnqueueEvent(jack_nframes_t time, size_t size,
  64. jack_midi_data_t *buffer);
  65. /**
  66. * Returns the maximum size event that can be enqueued right *now*.
  67. */
  68. size_t
  69. GetAvailableSpace();
  70. };
  71. }
  72. #endif