Jack2  1.9.8
JackALSARawMidiReceiveQueue.cpp
00001 /*
00002 Copyright (C) 2011 Devin Anderson
00003 
00004 This program is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2 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 General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 
00018 */
00019 
00020 #include "JackALSARawMidiReceiveQueue.h"
00021 #include "JackError.h"
00022 #include "JackMidiUtil.h"
00023 
00024 using Jack::JackALSARawMidiReceiveQueue;
00025 
00026 JackALSARawMidiReceiveQueue::
00027 JackALSARawMidiReceiveQueue(snd_rawmidi_t *rawmidi, size_t buffer_size)
00028 {
00029     buffer = new jack_midi_data_t[buffer_size];
00030     this->buffer_size = buffer_size;
00031     this->rawmidi = rawmidi;
00032 }
00033 
00034 JackALSARawMidiReceiveQueue::~JackALSARawMidiReceiveQueue()
00035 {
00036     delete[] buffer;
00037 }
00038 
00039 jack_midi_event_t *
00040 JackALSARawMidiReceiveQueue::DequeueEvent()
00041 {
00042     ssize_t result = snd_rawmidi_read(rawmidi, buffer, buffer_size);
00043     if (result > 0) {
00044         event.buffer = buffer;
00045         event.size = (size_t) result;
00046         event.time = GetCurrentFrame();
00047         return &event;
00048     }
00049     if (result && (result != -EWOULDBLOCK)) {
00050         jack_error("JackALSARawMidiReceiveQueue::DequeueEvent - "
00051                    "snd_rawmidi_read: %s", snd_strerror(result));
00052     }
00053     return 0;
00054 }