Fix last commit
[carla.git] / source / includes / lv2 / lv2-midifunctions.h
blobd068f498ab7c4b6cba794c4e35806f2f8a9ab318
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"
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
32 typedef struct {
33 LV2_MIDI* midi;
34 uint32_t frame_count;
35 uint32_t position;
36 } LV2_MIDIState;
39 inline double lv2midi_get_event(LV2_MIDIState* state,
40 double* timestamp,
41 uint32_t* size,
42 unsigned char** data) {
44 if (state->position >= state->midi->size) {
45 state->position = state->midi->size;
46 *timestamp = state->frame_count;
47 *size = 0;
48 *data = NULL;
49 return *timestamp;
52 *timestamp = *(double*)(state->midi->data + state->position);
53 *size = (uint32_t)*(size_t*)(state->midi->data + state->position + sizeof(double));
54 *data = state->midi->data + state->position +
55 sizeof(double) + sizeof(size_t);
56 return *timestamp;
60 inline double lv2midi_step(LV2_MIDIState* state) {
62 if (state->position >= state->midi->size) {
63 state->position = state->midi->size;
64 return state->frame_count;
67 state->position += (uint32_t)sizeof(double);
68 size_t size = *(size_t*)(state->midi->data + state->position);
69 state->position += (uint32_t)sizeof(size_t);
70 state->position += (uint32_t)size;
71 return *(double*)(state->midi->data + state->position);
75 inline void lv2midi_put_event(LV2_MIDIState* state,
76 double timestamp,
77 uint32_t size,
78 const unsigned char* data) {
80 if (state->midi->size + sizeof(double) + sizeof(size_t) + size < state->midi->capacity)
82 *((double*)(state->midi->data + state->midi->size)) = timestamp;
83 state->midi->size += (uint32_t)sizeof(double);
84 *((size_t*)(state->midi->data + state->midi->size)) = size;
85 state->midi->size += (uint32_t)sizeof(size_t);
86 memcpy(state->midi->data + state->midi->size, data, size);
88 state->midi->size += size;
89 state->midi->event_count++;
93 #ifdef __cplusplus
94 } /* extern "C" */
95 #endif
97 #endif