Jack2  1.9.8
JackMidiBufferReadQueue.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 "JackMidiBufferReadQueue.h"
00021 #include "JackMidiUtil.h"
00022 
00023 using Jack::JackMidiBufferReadQueue;
00024 
00025 JackMidiBufferReadQueue::JackMidiBufferReadQueue()
00026 {
00027     event_count = 0;
00028     index = 0;
00029 }
00030 
00031 jack_midi_event_t *
00032 JackMidiBufferReadQueue::DequeueEvent()
00033 {
00034     jack_midi_event_t *e = 0;
00035     if (index < event_count) {
00036         JackMidiEvent *event = &(buffer->events[index]);
00037         midi_event.buffer = event->GetData(buffer);
00038         midi_event.size = event->size;
00039         midi_event.time = last_frame_time + event->time;
00040         e = &midi_event;
00041         index++;
00042     }
00043     return e;
00044 }
00045 
00046 void
00047 JackMidiBufferReadQueue::ResetMidiBuffer(JackMidiBuffer *buffer)
00048 {
00049     event_count = 0;
00050     index = 0;
00051     if (! buffer) {
00052         jack_error("JackMidiBufferReadQueue::ResetMidiBuffer - buffer reset "
00053                    "to NULL");
00054     } else if (! buffer->IsValid()) {
00055         jack_error("JackMidiBufferReadQueue::ResetMidiBuffer - buffer reset "
00056                    "to invalid buffer");
00057     } else {
00058         uint32_t lost_events = buffer->lost_events;
00059         if (lost_events) {
00060             jack_error("JackMidiBufferReadQueue::ResetMidiBuffer - %d events "
00061                        "lost during mixdown", lost_events);
00062         }
00063         this->buffer = buffer;
00064         event_count = buffer->event_count;
00065         last_frame_time = GetLastFrame();
00066     }
00067 }