Jack2 1.9.10

JackMidiBufferWriteQueue.cpp

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 "JackMidiBufferWriteQueue.h"
00021 #include "JackMidiUtil.h"
00022 #include "JackError.h"
00023 
00024 using Jack::JackMidiBufferWriteQueue;
00025 
00026 JackMidiBufferWriteQueue::JackMidiBufferWriteQueue()
00027 {
00028     // Empty
00029 }
00030 
00031 Jack::JackMidiWriteQueue::EnqueueResult
00032 JackMidiBufferWriteQueue::EnqueueEvent(jack_nframes_t time, size_t size,
00033                                        jack_midi_data_t *data)
00034 {
00035     if (time >= next_frame_time) {
00036         return EVENT_EARLY;
00037     }
00038     if (time < last_frame_time) {
00039         time = last_frame_time;
00040     }
00041     jack_midi_data_t *dst = buffer->ReserveEvent(time - last_frame_time, size);
00042     if (! dst) {
00043         return size > max_bytes ? BUFFER_TOO_SMALL : BUFFER_FULL;
00044     }
00045     memcpy(dst, data, size);
00046     return OK;
00047 }
00048 
00049 void
00050 JackMidiBufferWriteQueue::ResetMidiBuffer(JackMidiBuffer *buffer,
00051                                           jack_nframes_t frames)
00052 {
00053     if (! buffer) {
00054         jack_error("JackMidiBufferWriteQueue::ResetMidiBuffer - buffer reset "
00055                    "to NULL");
00056     } else if (! buffer->IsValid()) {
00057         jack_error("JackMidiBufferWriteQueue::ResetMidiBuffer - buffer reset "
00058                    "to invalid buffer");
00059     } else {
00060         this->buffer = buffer;
00061         buffer->Reset(frames);
00062         last_frame_time = GetLastFrame();
00063         max_bytes = buffer->MaxEventSize();
00064         next_frame_time = last_frame_time + frames;
00065     }
00066 }