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
size_t jack_midi_max_event_size(void* port_buffer
);
40 LIB_EXPORT jack_midi_data_t
* jack_midi_event_reserve(void* port_buffer
,
41 jack_nframes_t time
, size_t data_size
);
43 LIB_EXPORT
int jack_midi_event_write(void* port_buffer
,
44 jack_nframes_t time
, const jack_midi_data_t
* data
, size_t data_size
);
46 LIB_EXPORT jack_nframes_t
jack_midi_get_lost_event_count(void* port_buffer
);
55 uint32_t jack_midi_get_event_count(void* port_buffer
)
57 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
58 if (!buf
|| !buf
->IsValid()) {
61 return buf
->event_count
;
65 int jack_midi_event_get(jack_midi_event_t
*event
, void* port_buffer
, uint32_t event_index
)
67 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
68 if (!buf
|| !buf
->IsValid()) {
71 if (event_index
>= buf
->event_count
) {
74 JackMidiEvent
* ev
= &buf
->events
[event_index
];
75 event
->time
= ev
->time
;
76 event
->size
= ev
->size
;
77 event
->buffer
= ev
->GetData(buf
);
82 void jack_midi_clear_buffer(void* port_buffer
)
84 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
85 if (buf
&& buf
->IsValid()) {
86 buf
->Reset(buf
->nframes
);
91 size_t jack_midi_max_event_size(void* port_buffer
)
93 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
94 if (buf
&& buf
->IsValid())
95 return buf
->MaxEventSize();
100 jack_midi_data_t
* jack_midi_event_reserve(void* port_buffer
, jack_nframes_t time
, size_t data_size
)
102 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
104 jack_error("jack_midi_event_reserve: port buffer is set to NULL");
107 if (! buf
->IsValid()) {
108 jack_error("jack_midi_event_reserve: port buffer is invalid");
111 if (time
>= buf
->nframes
) {
112 jack_error("jack_midi_event_reserve: time parameter is out of range "
113 "(%lu >= %lu)", time
, buf
->nframes
);
116 if (buf
->event_count
&& (buf
->events
[buf
->event_count
- 1].time
> time
)) {
117 jack_error("jack_midi_event_reserve: time parameter is earlier than "
118 "last reserved event");
121 return buf
->ReserveEvent(time
, data_size
);
125 int jack_midi_event_write(void* port_buffer
,
126 jack_nframes_t time
, const jack_midi_data_t
* data
, size_t data_size
)
128 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
129 if (!buf
&& !buf
->IsValid()) {
132 if (time
>= buf
->nframes
|| (buf
->event_count
&& buf
->events
[buf
->event_count
- 1].time
> time
)) {
135 jack_midi_data_t
* dest
= buf
->ReserveEvent(time
, data_size
);
139 memcpy(dest
, data
, data_size
);
144 uint32_t jack_midi_get_lost_event_count(void* port_buffer
)
146 JackMidiBuffer
*buf
= (JackMidiBuffer
*)port_buffer
;
147 if (buf
&& buf
->IsValid())
148 return buf
->lost_events
;