2 Copyright (C) 2010 Devin Anderson
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.
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.
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.
22 #include "JackFFADOMidiInputPort.h"
23 #include "JackMidiUtil.h"
24 #include "JackError.h"
26 using Jack::JackFFADOMidiInputPort
;
28 JackFFADOMidiInputPort::JackFFADOMidiInputPort(size_t max_bytes
)
31 receive_queue
= new JackFFADOMidiReceiveQueue();
32 std::unique_ptr
<JackFFADOMidiReceiveQueue
> receive_queue_ptr(receive_queue
);
33 write_queue
= new JackMidiBufferWriteQueue();
34 std::unique_ptr
<JackMidiBufferWriteQueue
> write_queue_ptr(write_queue
);
35 raw_queue
= new JackMidiRawInputWriteQueue(write_queue
, max_bytes
,
37 write_queue_ptr
.release();
38 receive_queue_ptr
.release();
41 JackFFADOMidiInputPort::~JackFFADOMidiInputPort()
49 JackFFADOMidiInputPort::Process(JackMidiBuffer
*port_buffer
,
50 uint32_t *input_buffer
, jack_nframes_t frames
)
52 receive_queue
->ResetInputBuffer(input_buffer
, frames
);
53 write_queue
->ResetMidiBuffer(port_buffer
, frames
);
54 jack_nframes_t boundary_frame
= GetLastFrame() + frames
;
56 event
= receive_queue
->DequeueEvent();
58 for (; event
; event
= receive_queue
->DequeueEvent()) {
59 switch (raw_queue
->EnqueueEvent(event
)) {
60 case JackMidiWriteQueue::BUFFER_FULL
:
62 // Processing events early might free up some space in the raw
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
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
:
80 case JackMidiWriteQueue::BUFFER_TOO_SMALL
:
81 jack_error("JackFFADOMidiInputPort::Process - The write queue "
82 "couldn't enqueue a %d-byte event. Dropping event.",
84 // Fallthrough on purpose
85 case JackMidiWriteQueue::OK
:
88 // This is here to stop compilers from warning us about not
89 // handling enumeration values.
94 raw_queue
->Process(boundary_frame
);