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.

100 lines
3.6KB

  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. #include <memory>
  16. #include "JackFFADOMidiOutputPort.h"
  17. #include "JackMidiUtil.h"
  18. #include "JackError.h"
  19. using Jack::JackFFADOMidiOutputPort;
  20. JackFFADOMidiOutputPort::JackFFADOMidiOutputPort(size_t non_rt_size,
  21. size_t max_non_rt_messages,
  22. size_t max_rt_messages)
  23. {
  24. event = 0;
  25. read_queue = new JackMidiBufferReadQueue();
  26. std::unique_ptr<JackMidiBufferReadQueue> read_queue_ptr(read_queue);
  27. send_queue = new JackFFADOMidiSendQueue();
  28. std::unique_ptr<JackFFADOMidiSendQueue> send_queue_ptr(send_queue);
  29. raw_queue = new JackMidiRawOutputWriteQueue(send_queue, non_rt_size,
  30. max_non_rt_messages,
  31. max_rt_messages);
  32. send_queue_ptr.release();
  33. read_queue_ptr.release();
  34. }
  35. JackFFADOMidiOutputPort::~JackFFADOMidiOutputPort()
  36. {
  37. delete raw_queue;
  38. delete read_queue;
  39. delete send_queue;
  40. }
  41. void
  42. JackFFADOMidiOutputPort::Process(JackMidiBuffer *port_buffer,
  43. uint32_t *output_buffer,
  44. jack_nframes_t frames)
  45. {
  46. read_queue->ResetMidiBuffer(port_buffer);
  47. send_queue->ResetOutputBuffer(output_buffer, frames);
  48. jack_nframes_t boundary_frame = GetLastFrame() + frames;
  49. if (! event) {
  50. event = read_queue->DequeueEvent();
  51. }
  52. for (; event; event = read_queue->DequeueEvent()) {
  53. switch (raw_queue->EnqueueEvent(event)) {
  54. case JackMidiWriteQueue::BUFFER_FULL:
  55. // Processing events early might free up some space in the raw
  56. // output queue.
  57. raw_queue->Process(boundary_frame);
  58. switch (raw_queue->EnqueueEvent(event)) {
  59. case JackMidiWriteQueue::BUFFER_TOO_SMALL:
  60. // This shouldn't really happen. It indicates a bug if it
  61. // does.
  62. jack_error("JackFFADOMidiOutputPort::Process - **BUG** "
  63. "JackMidiRawOutputWriteQueue::EnqueueEvent "
  64. "returned `BUFFER_FULL`, and then returned "
  65. "`BUFFER_TOO_SMALL` after a `Process()` call.");
  66. // Fallthrough on purpose
  67. case JackMidiWriteQueue::OK:
  68. continue;
  69. default:
  70. return;
  71. }
  72. case JackMidiWriteQueue::BUFFER_TOO_SMALL:
  73. jack_error("JackFFADOMidiOutputPort::Process - The write queue "
  74. "couldn't enqueue a %d-byte event. Dropping event.",
  75. event->size);
  76. // Fallthrough on purpose
  77. case JackMidiWriteQueue::OK:
  78. continue;
  79. default:
  80. // This is here to stop compilers from warning us about not
  81. // handling enumeration values.
  82. ;
  83. }
  84. break;
  85. }
  86. raw_queue->Process(boundary_frame);
  87. }