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.

96 lines
3.4KB

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