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 one thread to pass MIDI
  24. * messages to another thread (though it can also be used to buffer events
  25. * internally). This is especially useful if the MIDI API you're
  26. * attempting to interface with doesn't provide the ability to schedule
  27. * MIDI events ahead of time and/or has blocking send/receive calls, as it
  28. * allows a separate thread to handle input/output while the JACK process
  29. * thread copies events from a MIDI buffer to this queue, or vice versa.
  30. */
  31. class SERVER_EXPORT JackMidiAsyncQueue:
  32. public JackMidiReadQueue, public JackMidiWriteQueue {
  33. private:
  34. static const size_t INFO_SIZE =
  35. sizeof(jack_nframes_t) + sizeof(size_t);
  36. jack_ringbuffer_t *byte_ring;
  37. jack_midi_data_t *data_buffer;
  38. jack_midi_event_t dequeue_event;
  39. jack_ringbuffer_t *info_ring;
  40. size_t max_bytes;
  41. public:
  42. using JackMidiWriteQueue::EnqueueEvent;
  43. /**
  44. * Creates a new asynchronous MIDI message queue. The queue can store
  45. * up to `max_messages` MIDI messages and up to `max_bytes` of MIDI
  46. * data before it starts rejecting messages.
  47. */
  48. JackMidiAsyncQueue(size_t max_bytes=4096, size_t max_messages=1024);
  49. virtual
  50. ~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 indicates 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