Jack2
1.9.8
|
00001 /* 00002 Copyright (C) 2010 Devin Anderson 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU Lesser General Public License as published by 00006 the Free Software Foundation; either version 2.1 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU Lesser General Public License for more details. 00013 00014 You should have received a copy of the GNU Lesser General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 */ 00019 00020 #include <memory> 00021 00022 #include "JackFFADOMidiOutputPort.h" 00023 #include "JackMidiUtil.h" 00024 00025 using Jack::JackFFADOMidiOutputPort; 00026 00027 JackFFADOMidiOutputPort::JackFFADOMidiOutputPort(size_t non_rt_size, 00028 size_t max_non_rt_messages, 00029 size_t max_rt_messages) 00030 { 00031 event = 0; 00032 read_queue = new JackMidiBufferReadQueue(); 00033 std::auto_ptr<JackMidiBufferReadQueue> read_queue_ptr(read_queue); 00034 send_queue = new JackFFADOMidiSendQueue(); 00035 std::auto_ptr<JackFFADOMidiSendQueue> send_queue_ptr(send_queue); 00036 raw_queue = new JackMidiRawOutputWriteQueue(send_queue, non_rt_size, 00037 max_non_rt_messages, 00038 max_rt_messages); 00039 send_queue_ptr.release(); 00040 read_queue_ptr.release(); 00041 } 00042 00043 JackFFADOMidiOutputPort::~JackFFADOMidiOutputPort() 00044 { 00045 delete raw_queue; 00046 delete read_queue; 00047 delete send_queue; 00048 } 00049 00050 void 00051 JackFFADOMidiOutputPort::Process(JackMidiBuffer *port_buffer, 00052 uint32_t *output_buffer, 00053 jack_nframes_t frames) 00054 { 00055 read_queue->ResetMidiBuffer(port_buffer); 00056 send_queue->ResetOutputBuffer(output_buffer, frames); 00057 jack_nframes_t boundary_frame = GetLastFrame() + frames; 00058 if (! event) { 00059 event = read_queue->DequeueEvent(); 00060 } 00061 for (; event; event = read_queue->DequeueEvent()) { 00062 switch (raw_queue->EnqueueEvent(event)) { 00063 case JackMidiWriteQueue::BUFFER_FULL: 00064 00065 // Processing events early might free up some space in the raw 00066 // output queue. 00067 00068 raw_queue->Process(boundary_frame); 00069 switch (raw_queue->EnqueueEvent(event)) { 00070 case JackMidiWriteQueue::BUFFER_TOO_SMALL: 00071 // This shouldn't really happen. It indicates a bug if it 00072 // does. 00073 jack_error("JackFFADOMidiOutputPort::Process - **BUG** " 00074 "JackMidiRawOutputWriteQueue::EnqueueEvent " 00075 "returned `BUFFER_FULL`, and then returned " 00076 "`BUFFER_TOO_SMALL` after a `Process()` call."); 00077 // Fallthrough on purpose 00078 case JackMidiWriteQueue::OK: 00079 continue; 00080 default: 00081 return; 00082 } 00083 case JackMidiWriteQueue::BUFFER_TOO_SMALL: 00084 jack_error("JackFFADOMidiOutputPort::Process - The write queue " 00085 "couldn't enqueue a %d-byte event. Dropping event.", 00086 event->size); 00087 // Fallthrough on purpose 00088 case JackMidiWriteQueue::OK: 00089 continue; 00090 default: 00091 // This is here to stop compliers from warning us about not 00092 // handling enumeration values. 00093 ; 00094 } 00095 break; 00096 } 00097 raw_queue->Process(boundary_frame); 00098 }