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.

140 lines
5.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 __JackMidiRawOutputWriteQueue__
  16. #define __JackMidiRawOutputWriteQueue__
  17. #include "JackMidiAsyncQueue.h"
  18. #include "JackMidiSendQueue.h"
  19. namespace Jack {
  20. /**
  21. * This queue enqueues valid MIDI events and modifies them for raw output
  22. * to a write queue. It has a couple of advantages over straight MIDI
  23. * event copying:
  24. *
  25. * -Running status: Status bytes can be omitted when the status byte of the
  26. * current MIDI message is the same as the status byte of the last sent
  27. * MIDI message.
  28. *
  29. * -Realtime messages: Realtime messages are given priority over
  30. * non-realtime messages. Realtime bytes are interspersed with
  31. * non-realtime bytes so that realtime messages can be sent as close as
  32. * possible to the time they're scheduled for sending.
  33. *
  34. * Use this queue if the MIDI API you're interfacing with allows you to
  35. * send raw MIDI bytes.
  36. */
  37. class SERVER_EXPORT JackMidiRawOutputWriteQueue:
  38. public JackMidiWriteQueue {
  39. private:
  40. jack_midi_event_t *non_rt_event;
  41. jack_nframes_t non_rt_event_time;
  42. JackMidiAsyncQueue *non_rt_queue;
  43. jack_midi_event_t *rt_event;
  44. jack_nframes_t rt_event_time;
  45. JackMidiAsyncQueue *rt_queue;
  46. jack_midi_data_t running_status;
  47. JackMidiSendQueue *send_queue;
  48. void
  49. DequeueNonRealtimeEvent();
  50. void
  51. DequeueRealtimeEvent();
  52. bool
  53. SendByte(jack_nframes_t time, jack_midi_data_t byte);
  54. bool
  55. SendNonRTBytes(jack_nframes_t boundary_frame);
  56. protected:
  57. /**
  58. * Override this method to specify what happens when the write queue
  59. * says that a 1-byte event is too large for its buffer. Basically,
  60. * this should never happen.
  61. */
  62. virtual void
  63. HandleWriteQueueBug(jack_nframes_t time, jack_midi_data_t byte);
  64. public:
  65. using JackMidiWriteQueue::EnqueueEvent;
  66. /**
  67. * Called to create a new raw write queue. The `send_queue` argument
  68. * is the queue to write raw bytes to. The optional `max_rt_messages`
  69. * argument specifies the number of messages that can be enqueued in
  70. * the internal realtime queue. The optional `max_non_rt_messages`
  71. * argument specifies the number of messages that can be enqueued in
  72. * the internal non-realtime queue. The optional `non_rt_size`
  73. * argument specifies the total number of MIDI bytes that can be put in
  74. * the non-realtime queue.
  75. */
  76. JackMidiRawOutputWriteQueue(JackMidiSendQueue *send_queue,
  77. size_t non_rt_size=4096,
  78. size_t max_non_rt_messages=1024,
  79. size_t max_rt_messages=128);
  80. ~JackMidiRawOutputWriteQueue();
  81. EnqueueResult
  82. EnqueueEvent(jack_nframes_t time, size_t size,
  83. jack_midi_data_t *buffer);
  84. /**
  85. * The `Process()` method should be called each time the
  86. * `EnqueueEvent()` method returns 'OK'. The `Process()` method will
  87. * return the next frame at which an event should be sent. The return
  88. * value from `Process()` depends upon the result of writing bytes to
  89. * the write queue:
  90. *
  91. * -If the return value is '0', then all events that have been enqueued
  92. * in this queue have been sent successfully to the write queue. Don't
  93. * call `Process()` again until another event has been enqueued.
  94. *
  95. * -If the return value is an earlier frame or the current frame, it
  96. * means that the write queue returned 'BUFFER_FULL', 'ERROR', or
  97. * 'EVENT_EARLY' when this queue attempted to send the next byte, and
  98. * that the byte should have already been sent, or is scheduled to be
  99. * sent *now*. `Process()` should be called again when the write queue
  100. * can enqueue events again successfully. How to determine when this
  101. * will happen is left up to the caller.
  102. *
  103. * -If the return value is in the future, then `Process()` should be
  104. * called again at that time, or after another event is enqueued.
  105. */
  106. jack_nframes_t
  107. Process(jack_nframes_t boundary_frame=0);
  108. };
  109. }
  110. #endif