JackMidiAPI.cpp

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 General Public License as published by
00007   the Free Software Foundation; either version 2 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 General Public License for more details.
00014 
00015   You should have received a copy of the GNU General Public License
00016   along with this program; if not, write to the Free Software
00017   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 */
00020 #include "JackError.h"
00021 #include "JackMidiPort.h"
00022 #include "JackExports.h"
00023 #include <errno.h>
00024 #include <string.h>
00025 
00026 #ifdef WIN32
00027 #define ENOBUFS 55
00028 #endif
00029 
00030 #ifdef __cplusplus
00031 extern "C" {
00032 #endif
00033 
00034     EXPORT jack_nframes_t jack_midi_get_event_count(void* port_buffer);
00035 
00036     EXPORT int jack_midi_event_get(jack_midi_event_t* event,
00037         void* port_buffer, jack_nframes_t event_index);
00038 
00039     EXPORT void jack_midi_clear_buffer(void* port_buffer);
00040 
00041     EXPORT size_t jack_midi_max_event_size(void* port_buffer);
00042 
00043     EXPORT jack_midi_data_t* jack_midi_event_reserve(void* port_buffer,
00044         jack_nframes_t time, size_t data_size);
00045 
00046     EXPORT int jack_midi_event_write(void* port_buffer,
00047         jack_nframes_t time, const jack_midi_data_t* data, size_t data_size);
00048 
00049     EXPORT jack_nframes_t jack_midi_get_lost_event_count(void* port_buffer);
00050 
00051 #ifdef __cplusplus
00052 }
00053 #endif
00054 
00055 using namespace Jack;
00056 
00057 EXPORT
00058 jack_nframes_t jack_midi_get_event_count(void* port_buffer)
00059 {
00060     JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer;
00061     if (!buf || !buf->IsValid())
00062         return 0;
00063     return buf->event_count;
00064 }
00065 
00066 EXPORT
00067 int jack_midi_event_get(jack_midi_event_t *event, void* port_buffer, jack_nframes_t event_index)
00068 {
00069     JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer;
00070     if (!buf || !buf->IsValid())
00071         return -EINVAL;
00072     if (event_index < 0 || event_index >= buf->event_count)
00073         return -ENOBUFS;
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 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 EXPORT
00090 size_t jack_midi_max_event_size(void* port_buffer)
00091 {
00092     JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer;
00093     if (buf && buf->IsValid())
00094         return buf->MaxEventSize();
00095     return 0;
00096 }
00097 
00098 EXPORT
00099 jack_midi_data_t* jack_midi_event_reserve(void* port_buffer, jack_nframes_t time, size_t data_size)
00100 {
00101     JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer;
00102     if (!buf && !buf->IsValid())
00103         return 0;
00104     if (time < 0 || time >= buf->nframes || (buf->event_count && buf->events[buf->event_count - 1].time > time))
00105         return 0;
00106     return buf->ReserveEvent(time, data_size);
00107 }
00108 
00109 EXPORT
00110 int jack_midi_event_write(void* port_buffer,
00111         jack_nframes_t time, const jack_midi_data_t* data, size_t data_size)
00112 {
00113     JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer;
00114     if (!buf && !buf->IsValid())
00115         return -EINVAL;
00116     if (time < 0 || time >= buf->nframes || (buf->event_count && buf->events[buf->event_count - 1].time > time))
00117         return -EINVAL;
00118     jack_midi_data_t* dest = buf->ReserveEvent(time, data_size);
00119     if (!dest)
00120         return -ENOBUFS;
00121     memcpy(dest, data, data_size);
00122     return 0;
00123 }
00124 
00125 EXPORT
00126 jack_nframes_t jack_midi_get_lost_event_count(void* port_buffer)
00127 {
00128     JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer;
00129     if (buf && buf->IsValid())
00130         return buf->lost_events; 
00131     return 0;
00132 }

Generated on Thu Feb 14 11:16:02 2008 for Jackdmp by  doxygen 1.5.1