Jack2 1.9.10
|
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 #include "JackError.h" 00025 00026 using Jack::JackFFADOMidiOutputPort; 00027 00028 JackFFADOMidiOutputPort::JackFFADOMidiOutputPort(size_t non_rt_size, 00029 size_t max_non_rt_messages, 00030 size_t max_rt_messages) 00031 { 00032 event = 0; 00033 read_queue = new JackMidiBufferReadQueue(); 00034 std::auto_ptr<JackMidiBufferReadQueue> read_queue_ptr(read_queue); 00035 send_queue = new JackFFADOMidiSendQueue(); 00036 std::auto_ptr<JackFFADOMidiSendQueue> send_queue_ptr(send_queue); 00037 raw_queue = new JackMidiRawOutputWriteQueue(send_queue, non_rt_size, 00038 max_non_rt_messages, 00039 max_rt_messages); 00040 send_queue_ptr.release(); 00041 read_queue_ptr.release(); 00042 } 00043 00044 JackFFADOMidiOutputPort::~JackFFADOMidiOutputPort() 00045 { 00046 delete raw_queue; 00047 delete read_queue; 00048 delete send_queue; 00049 } 00050 00051 void 00052 JackFFADOMidiOutputPort::Process(JackMidiBuffer *port_buffer, 00053 uint32_t *output_buffer, 00054 jack_nframes_t frames) 00055 { 00056 read_queue->ResetMidiBuffer(port_buffer); 00057 send_queue->ResetOutputBuffer(output_buffer, frames); 00058 jack_nframes_t boundary_frame = GetLastFrame() + frames; 00059 if (! event) { 00060 event = read_queue->DequeueEvent(); 00061 } 00062 for (; event; event = read_queue->DequeueEvent()) { 00063 switch (raw_queue->EnqueueEvent(event)) { 00064 case JackMidiWriteQueue::BUFFER_FULL: 00065 00066 // Processing events early might free up some space in the raw 00067 // output queue. 00068 00069 raw_queue->Process(boundary_frame); 00070 switch (raw_queue->EnqueueEvent(event)) { 00071 case JackMidiWriteQueue::BUFFER_TOO_SMALL: 00072 // This shouldn't really happen. It indicates a bug if it 00073 // does. 00074 jack_error("JackFFADOMidiOutputPort::Process - **BUG** " 00075 "JackMidiRawOutputWriteQueue::EnqueueEvent " 00076 "returned `BUFFER_FULL`, and then returned " 00077 "`BUFFER_TOO_SMALL` after a `Process()` call."); 00078 // Fallthrough on purpose 00079 case JackMidiWriteQueue::OK: 00080 continue; 00081 default: 00082 return; 00083 } 00084 case JackMidiWriteQueue::BUFFER_TOO_SMALL: 00085 jack_error("JackFFADOMidiOutputPort::Process - The write queue " 00086 "couldn't enqueue a %d-byte event. Dropping event.", 00087 event->size); 00088 // Fallthrough on purpose 00089 case JackMidiWriteQueue::OK: 00090 continue; 00091 default: 00092 // This is here to stop compliers from warning us about not 00093 // handling enumeration values. 00094 ; 00095 } 00096 break; 00097 } 00098 raw_queue->Process(boundary_frame); 00099 }