Jack2  1.9.9
JackFFADOMidiInputPort.cpp
1 /*
2 Copyright (C) 2010 Devin Anderson
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13 
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 
18 */
19 
20 #include <memory>
21 
22 #include "JackFFADOMidiInputPort.h"
23 #include "JackMidiUtil.h"
24 #include "JackError.h"
25 
27 
28 JackFFADOMidiInputPort::JackFFADOMidiInputPort(size_t max_bytes)
29 {
30  event = 0;
31  receive_queue = new JackFFADOMidiReceiveQueue();
32  std::auto_ptr<JackFFADOMidiReceiveQueue> receive_queue_ptr(receive_queue);
33  write_queue = new JackMidiBufferWriteQueue();
34  std::auto_ptr<JackMidiBufferWriteQueue> write_queue_ptr(write_queue);
35  raw_queue = new JackMidiRawInputWriteQueue(write_queue, max_bytes,
36  max_bytes);
37  write_queue_ptr.release();
38  receive_queue_ptr.release();
39 }
40 
41 JackFFADOMidiInputPort::~JackFFADOMidiInputPort()
42 {
43  delete raw_queue;
44  delete receive_queue;
45  delete write_queue;
46 }
47 
48 void
49 JackFFADOMidiInputPort::Process(JackMidiBuffer *port_buffer,
50  uint32_t *input_buffer, jack_nframes_t frames)
51 {
52  receive_queue->ResetInputBuffer(input_buffer, frames);
53  write_queue->ResetMidiBuffer(port_buffer, frames);
54  jack_nframes_t boundary_frame = GetLastFrame() + frames;
55  if (! event) {
56  event = receive_queue->DequeueEvent();
57  }
58  for (; event; event = receive_queue->DequeueEvent()) {
59  switch (raw_queue->EnqueueEvent(event)) {
60  case JackMidiWriteQueue::BUFFER_FULL:
61 
62  // Processing events early might free up some space in the raw
63  // input queue.
64 
65  raw_queue->Process(boundary_frame);
66  switch (raw_queue->EnqueueEvent(event)) {
67  case JackMidiWriteQueue::BUFFER_TOO_SMALL:
68  // This shouldn't really happen. It indicates a bug if it
69  // does.
70  jack_error("JackFFADOMidiInputPort::Process - **BUG** "
71  "JackMidiRawInputWriteQueue::EnqueueEvent returned "
72  "`BUFFER_FULL`, and then returned "
73  "`BUFFER_TOO_SMALL` after a `Process()` call.");
74  // Fallthrough on purpose
75  case JackMidiWriteQueue::OK:
76  continue;
77  default:
78  return;
79  }
80  case JackMidiWriteQueue::BUFFER_TOO_SMALL:
81  jack_error("JackFFADOMidiInputPort::Process - The write queue "
82  "couldn't enqueue a %d-byte event. Dropping event.",
83  event->size);
84  // Fallthrough on purpose
85  case JackMidiWriteQueue::OK:
86  continue;
87  default:
88  // This is here to stop compliers from warning us about not
89  // handling enumeration values.
90  ;
91  }
92  break;
93  }
94  raw_queue->Process(boundary_frame);
95 }
SERVER_EXPORT void jack_error(const char *fmt,...)
Definition: JackError.cpp:91
jack_nframes_t Process(jack_nframes_t boundary_frame=0)
EnqueueResult EnqueueEvent(jack_nframes_t time, size_t size, jack_midi_data_t *buffer)
void ResetMidiBuffer(JackMidiBuffer *buffer, jack_nframes_t frames)