Jack2 1.9.10

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