1 /****************************************************************************
3 lv2-midifunctions.h - support file for using MIDI in LV2 plugins
5 Copyright (C) 2006 Lars Luthman <lars.luthman@gmail.com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 01222-1307 USA
21 ****************************************************************************/
23 #ifndef LV2_MIDIFUNCTIONS
24 #define LV2_MIDIFUNCTIONS
26 #include "lv2-miditype.h"
36 static double lv2midi_get_event(LV2_MIDIState
* state
,
39 unsigned char** data
) {
41 if (state
->position
>= state
->midi
->size
) {
42 state
->position
= state
->midi
->size
;
43 *timestamp
= state
->frame_count
;
49 *timestamp
= *(double*)(state
->midi
->data
+ state
->position
);
50 *size
= *(size_t*)(state
->midi
->data
+ state
->position
+ sizeof(double));
51 *data
= state
->midi
->data
+ state
->position
+
52 sizeof(double) + sizeof(size_t);
57 static double lv2midi_step(LV2_MIDIState
* state
) {
59 if (state
->position
>= state
->midi
->size
) {
60 state
->position
= state
->midi
->size
;
61 return state
->frame_count
;
64 state
->position
+= sizeof(double);
65 size_t size
= *(size_t*)(state
->midi
->data
+ state
->position
);
66 state
->position
+= sizeof(size_t);
67 state
->position
+= size
;
68 return *(double*)(state
->midi
->data
+ state
->position
);