Jack2 1.9.8
|
00001 /* 00002 Copyright (C) 2007 Dmitry Baikov 00003 Original JACK MIDI implementation Copyright (C) 2004 Ian Esten 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU Lesser General Public License as published by 00007 the Free Software Foundation; either version 2.1 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 00019 */ 00020 00021 #include "JackError.h" 00022 #include "JackMidiPort.h" 00023 #include <errno.h> 00024 #include <string.h> 00025 00026 #ifdef __cplusplus 00027 extern "C" 00028 { 00029 #endif 00030 00031 LIB_EXPORT uint32_t jack_midi_get_event_count(void* port_buffer); 00032 00033 LIB_EXPORT int jack_midi_event_get(jack_midi_event_t* event, 00034 void* port_buffer, uint32_t event_index); 00035 00036 LIB_EXPORT void jack_midi_clear_buffer(void* port_buffer); 00037 00038 LIB_EXPORT size_t jack_midi_max_event_size(void* port_buffer); 00039 00040 LIB_EXPORT jack_midi_data_t* jack_midi_event_reserve(void* port_buffer, 00041 jack_nframes_t time, size_t data_size); 00042 00043 LIB_EXPORT int jack_midi_event_write(void* port_buffer, 00044 jack_nframes_t time, const jack_midi_data_t* data, size_t data_size); 00045 00046 LIB_EXPORT jack_nframes_t jack_midi_get_lost_event_count(void* port_buffer); 00047 00048 #ifdef __cplusplus 00049 } 00050 #endif 00051 00052 using namespace Jack; 00053 00054 LIB_EXPORT 00055 uint32_t jack_midi_get_event_count(void* port_buffer) 00056 { 00057 JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer; 00058 if (!buf || !buf->IsValid()) { 00059 return 0; 00060 } 00061 return buf->event_count; 00062 } 00063 00064 LIB_EXPORT 00065 int jack_midi_event_get(jack_midi_event_t *event, void* port_buffer, uint32_t event_index) 00066 { 00067 JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer; 00068 if (!buf || !buf->IsValid()) { 00069 return -EINVAL; 00070 } 00071 if (event_index >= buf->event_count) { 00072 return -ENOBUFS; 00073 } 00074 JackMidiEvent* ev = &buf->events[event_index]; 00075 event->time = ev->time; 00076 event->size = ev->size; 00077 event->buffer = ev->GetData(buf); 00078 return 0; 00079 } 00080 00081 LIB_EXPORT 00082 void jack_midi_clear_buffer(void* port_buffer) 00083 { 00084 JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer; 00085 if (buf && buf->IsValid()) { 00086 buf->Reset(buf->nframes); 00087 } 00088 } 00089 00090 LIB_EXPORT 00091 size_t jack_midi_max_event_size(void* port_buffer) 00092 { 00093 JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer; 00094 if (buf && buf->IsValid()) 00095 return buf->MaxEventSize(); 00096 return 0; 00097 } 00098 00099 LIB_EXPORT 00100 jack_midi_data_t* jack_midi_event_reserve(void* port_buffer, jack_nframes_t time, size_t data_size) 00101 { 00102 JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer; 00103 if (! buf) { 00104 jack_error("jack_midi_event_reserve: port buffer is set to NULL"); 00105 return 0; 00106 } 00107 if (! buf->IsValid()) { 00108 jack_error("jack_midi_event_reserve: port buffer is invalid"); 00109 return 0; 00110 } 00111 if (time >= buf->nframes) { 00112 jack_error("jack_midi_event_reserve: time parameter is out of range " 00113 "(%lu >= %lu)", time, buf->nframes); 00114 return 0; 00115 } 00116 if (buf->event_count && (buf->events[buf->event_count - 1].time > time)) { 00117 jack_error("jack_midi_event_reserve: time parameter is earlier than " 00118 "last reserved event"); 00119 return 0; 00120 } 00121 return buf->ReserveEvent(time, data_size); 00122 } 00123 00124 LIB_EXPORT 00125 int jack_midi_event_write(void* port_buffer, 00126 jack_nframes_t time, const jack_midi_data_t* data, size_t data_size) 00127 { 00128 JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer; 00129 if (!buf && !buf->IsValid()) { 00130 return -EINVAL; 00131 } 00132 if (time >= buf->nframes || (buf->event_count && buf->events[buf->event_count - 1].time > time)) { 00133 return -EINVAL; 00134 } 00135 jack_midi_data_t* dest = buf->ReserveEvent(time, data_size); 00136 if (!dest) { 00137 return -ENOBUFS; 00138 } 00139 memcpy(dest, data, data_size); 00140 return 0; 00141 } 00142 00143 LIB_EXPORT 00144 uint32_t jack_midi_get_lost_event_count(void* port_buffer) 00145 { 00146 JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer; 00147 if (buf && buf->IsValid()) 00148 return buf->lost_events; 00149 return 0; 00150 }