Jack2 1.9.8

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