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"
31 LIB_EXPORT
uint32_t jack_midi_get_event_count(void* port_buffer
);
33 LIB_EXPORT
int jack_midi_event_get(jack_midi_event_t
* event
,
34 void* port_buffer
, uint32_t event_index
);
36 LIB_EXPORT
void jack_midi_clear_buffer(void* port_buffer
);
38 LIB_EXPORT
void jack_midi_reset_buffer(void* port_buffer
);
40 LIB_EXPORT
size_t jack_midi_max_event_size(void* port_buffer
);
42 LIB_EXPORT jack_midi_data_t
* jack_midi_event_reserve(void* port_buffer
,
43 jack_nframes_t time
, size_t data_size
);
45 LIB_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 LIB_EXPORT jack_nframes_t
jack_midi_get_lost_event_count(void* port_buffer
);
57 uint32_t jack_midi_get_event_count(void* port_buffer
)
59 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
60 if (!buf
|| !buf
->IsValid()) {
63 return buf
->event_count
;
67 int jack_midi_event_get(jack_midi_event_t
*event
, void* port_buffer
, uint32_t event_index
)
69 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
70 if (!buf
|| !buf
->IsValid()) {
73 if (event_index
>= buf
->event_count
) {
76 JackMidiEvent
* ev
= &buf
->events
[event_index
];
77 event
->time
= ev
->time
;
78 event
->size
= ev
->size
;
79 event
->buffer
= ev
->GetData(buf
);
84 void jack_midi_clear_buffer(void* port_buffer
)
86 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
87 if (buf
&& buf
->IsValid()) {
88 buf
->Reset(buf
->nframes
);
93 void jack_midi_reset_buffer(void* port_buffer
)
95 MidiBufferInit(port_buffer
, BUFFER_SIZE_MAX
, BUFFER_SIZE_MAX
);
99 size_t jack_midi_max_event_size(void* port_buffer
)
101 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
102 if (buf
&& buf
->IsValid()) {
103 return buf
->MaxEventSize();
109 jack_midi_data_t
* jack_midi_event_reserve(void* port_buffer
, jack_nframes_t time
, size_t data_size
)
111 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
113 jack_error("jack_midi_event_reserve: port buffer is set to NULL");
116 if (! buf
->IsValid()) {
117 jack_error("jack_midi_event_reserve: port buffer is invalid");
120 if (time
>= buf
->nframes
) {
121 jack_error("jack_midi_event_reserve: time parameter is out of range "
122 "(%lu >= %lu)", time
, buf
->nframes
);
125 if (buf
->event_count
&& (buf
->events
[buf
->event_count
- 1].time
> time
)) {
126 jack_error("jack_midi_event_reserve: time parameter is earlier than "
127 "last reserved event");
130 return buf
->ReserveEvent(time
, data_size
);
134 int jack_midi_event_write(void* port_buffer
,
135 jack_nframes_t time
, const jack_midi_data_t
* data
, size_t data_size
)
137 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
138 if (!buf
|| !buf
->IsValid()) {
141 if (time
>= buf
->nframes
|| (buf
->event_count
&& buf
->events
[buf
->event_count
- 1].time
> time
)) {
144 jack_midi_data_t
* dest
= buf
->ReserveEvent(time
, data_size
);
148 memcpy(dest
, data
, data_size
);
153 uint32_t jack_midi_get_lost_event_count(void* port_buffer
)
155 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
156 if (buf
&& buf
->IsValid()) {
157 return buf
->lost_events
;