Jack2
1.9.10
|
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 <cassert> 00021 00022 #include "JackALSARawMidiSendQueue.h" 00023 #include "JackMidiUtil.h" 00024 #include "JackError.h" 00025 00026 using Jack::JackALSARawMidiSendQueue; 00027 00028 JackALSARawMidiSendQueue::JackALSARawMidiSendQueue(snd_rawmidi_t *rawmidi, 00029 size_t bytes_per_poll) 00030 { 00031 assert(bytes_per_poll > 0); 00032 this->bytes_per_poll = bytes_per_poll; 00033 this->rawmidi = rawmidi; 00034 blocked = false; 00035 bytes_available = bytes_per_poll; 00036 } 00037 00038 Jack::JackMidiWriteQueue::EnqueueResult 00039 JackALSARawMidiSendQueue::EnqueueEvent(jack_nframes_t time, size_t size, 00040 jack_midi_data_t *buffer) 00041 { 00042 assert(size == 1); 00043 if (time > GetCurrentFrame()) { 00044 return EVENT_EARLY; 00045 } 00046 if (! bytes_available) { 00047 return BUFFER_FULL; 00048 } 00049 ssize_t result = snd_rawmidi_write(rawmidi, buffer, 1); 00050 switch (result) { 00051 case 1: 00052 blocked = false; 00053 bytes_available--; 00054 return OK; 00055 case -EWOULDBLOCK: 00056 blocked = true; 00057 return BUFFER_FULL; 00058 } 00059 jack_error("JackALSARawMidiSendQueue::EnqueueEvent - snd_rawmidi_write: " 00060 "%s", snd_strerror(result)); 00061 return EN_ERROR; 00062 } 00063 00064 bool 00065 JackALSARawMidiSendQueue::IsBlocked() 00066 { 00067 return blocked; 00068 } 00069 00070 void 00071 JackALSARawMidiSendQueue::ResetPollByteCount() 00072 { 00073 bytes_available = bytes_per_poll; 00074 }