2 Copyright (C) 2007 Dmitry Baikov
3 Original JACK MIDI implementation Copyright (C) 2004 Ian Esten
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "JackError.h"
22 #include "JackMidiPort.h"
23 #include "JackCompilerDeps.h"
26 #include "JackSystemDeps.h"
33 EXPORT jack_nframes_t
jack_midi_get_event_count(void* port_buffer
);
35 EXPORT
int jack_midi_event_get(jack_midi_event_t
* event
,
36 void* port_buffer
, jack_nframes_t event_index
);
38 EXPORT
void jack_midi_clear_buffer(void* port_buffer
);
40 EXPORT
size_t jack_midi_max_event_size(void* port_buffer
);
42 EXPORT jack_midi_data_t
* jack_midi_event_reserve(void* port_buffer
,
43 jack_nframes_t time
, size_t data_size
);
45 EXPORT
int jack_midi_event_write(void* port_buffer
,
46 jack_nframes_t time
, const jack_midi_data_t
* data
, size_t data_size
);
48 EXPORT jack_nframes_t
jack_midi_get_lost_event_count(void* port_buffer
);
57 jack_nframes_t
jack_midi_get_event_count(void* port_buffer
)
59 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
60 if (!buf
|| !buf
->IsValid())
62 return buf
->event_count
;
66 int jack_midi_event_get(jack_midi_event_t
*event
, void* port_buffer
, jack_nframes_t event_index
)
68 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
69 if (!buf
|| !buf
->IsValid())
71 if (event_index
>= buf
->event_count
)
73 JackMidiEvent
* ev
= &buf
->events
[event_index
];
74 event
->time
= ev
->time
;
75 event
->size
= ev
->size
;
76 event
->buffer
= ev
->GetData(buf
);
81 void jack_midi_clear_buffer(void* port_buffer
)
83 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
84 if (buf
&& buf
->IsValid())
85 buf
->Reset(buf
->nframes
);
89 size_t jack_midi_max_event_size(void* port_buffer
)
91 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
92 if (buf
&& buf
->IsValid())
93 return buf
->MaxEventSize();
98 jack_midi_data_t
* jack_midi_event_reserve(void* port_buffer
, jack_nframes_t time
, size_t data_size
)
100 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
101 if (!buf
&& !buf
->IsValid())
103 if (time
>= buf
->nframes
|| (buf
->event_count
&& buf
->events
[buf
->event_count
- 1].time
> time
))
105 return buf
->ReserveEvent(time
, data_size
);
109 int jack_midi_event_write(void* port_buffer
,
110 jack_nframes_t time
, const jack_midi_data_t
* data
, size_t data_size
)
112 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
113 if (!buf
&& !buf
->IsValid())
115 if (time
>= buf
->nframes
|| (buf
->event_count
&& buf
->events
[buf
->event_count
- 1].time
> time
))
117 jack_midi_data_t
* dest
= buf
->ReserveEvent(time
, data_size
);
120 memcpy(dest
, data
, data_size
);
125 jack_nframes_t
jack_midi_get_lost_event_count(void* port_buffer
)
127 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
128 if (buf
&& buf
->IsValid())
129 return buf
->lost_events
;