summaryrefslogtreecommitdiffstats
path: root/src/common/lv2ext
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-08-02 18:33:34 +0000
committerDavid Robillard <d@drobilla.net>2007-08-02 18:33:34 +0000
commite671a1e03df0d327691b9d13fb3bd753fb58a85c (patch)
treed2458bd7a0c2463d391a6f672c9876e877ab2e71 /src/common/lv2ext
parent191b78d09365112a868ddaf3f813ef2b5bc2c252 (diff)
downloadingen-e671a1e03df0d327691b9d13fb3bd753fb58a85c.tar.gz
ingen-e671a1e03df0d327691b9d13fb3bd753fb58a85c.tar.bz2
ingen-e671a1e03df0d327691b9d13fb3bd753fb58a85c.zip
Fix MIDI patching.
Remove ugly C LV2 MIDI functions and moved functionality into MidiBuffer. git-svn-id: http://svn.drobilla.net/lad/ingen@671 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/common/lv2ext')
-rw-r--r--src/common/lv2ext/Makefile.am2
-rw-r--r--src/common/lv2ext/lv2-midifunctions.h168
2 files changed, 1 insertions, 169 deletions
diff --git a/src/common/lv2ext/Makefile.am b/src/common/lv2ext/Makefile.am
index ed382ecc..a4dceb45 100644
--- a/src/common/lv2ext/Makefile.am
+++ b/src/common/lv2ext/Makefile.am
@@ -1 +1 @@
-noinst_HEADERS = lv2-midiport.h lv2-midifunctions.h
+noinst_HEADERS = lv2-midiport.h
diff --git a/src/common/lv2ext/lv2-midifunctions.h b/src/common/lv2ext/lv2-midifunctions.h
deleted file mode 100644
index 0f47ca5d..00000000
--- a/src/common/lv2ext/lv2-midifunctions.h
+++ /dev/null
@@ -1,168 +0,0 @@
-/****************************************************************************
-
- lv2-midifunctions.h - support file for using MIDI in LV2 plugins
-
- Copyright (C) 2006-2007 Lars Luthman <lars.luthman@gmail.com>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 01222-1307 USA
-
-****************************************************************************/
-
-/** @file
- This file contains static helper functions for the LV2 MIDI datatype
- extension.
-*/
-
-#ifndef LV2_MIDIFUNCTIONS
-#define LV2_MIDIFUNCTIONS
-
-#include <string.h>
-#include <stdlib.h>
-
-#include "lv2-midiport.h"
-
-
-/** This structure contains information about a MIDI port buffer, the
- current period size, and the position in the MIDI data buffer that
- we are currently reading from or writing to. It needs to be recreated
- or at least reinitialised every process() call. */
-typedef struct {
-
- /** The MIDI port structure that we want to read or write. */
- LV2_MIDI* midi;
-
- /** The number of frames in this process cycle. */
- uint32_t frame_count;
-
- /** The current position in the data buffer. Should be initialised to 0. */
- uint32_t position;
-
-} LV2_MIDIState;
-
-
-inline static LV2_MIDI* lv2midi_new(uint32_t capacity)
-{
- LV2_MIDI* midi = (LV2_MIDI*)malloc(sizeof(LV2_MIDI));
-
- midi->event_count = 0;
- midi->capacity = capacity;
- midi->size = 0;
- midi->data = (unsigned char*)malloc(sizeof(unsigned char) * capacity);
-
- return midi;
-}
-
-
-static void lv2midi_free(LV2_MIDI* midi)
-{
- free(midi->data);
- free(midi);
-}
-
-
-static void lv2midi_reset_buffer(LV2_MIDI* midi)
-{
- midi->event_count = 0;
- midi->size = 0;
-}
-
-
-static void lv2midi_reset_state(LV2_MIDIState* state, LV2_MIDI* midi, uint32_t frame_count)
-{
- state->midi = midi;
- state->frame_count = frame_count;
- state->position = 0;
-}
-
-
-/** This function reads one event from the port associated with the @c state
- parameter and writes its timestamp, size and a pointer to its data bytes
- into the parameters @c timestamp, @c size and @c data, respectively.
- It does not advance the read position in the MIDI data buffer, two
- subsequent calls to lv2midi_get_event() will read the same event.
-
- The function returns the timestamp for the read event, or the @c frame_count
- member of @c state if there are no more events in the buffer. */
-static double lv2midi_get_event(LV2_MIDIState* state,
- double* timestamp,
- uint32_t* size,
- unsigned char** data) {
-
- if (state->position >= state->midi->size) {
- state->position = state->midi->size;
- *timestamp = state->frame_count;
- *size = 0;
- *data = NULL;
- return *timestamp;
- }
-
- *timestamp = *(double*)(state->midi->data + state->position);
- *size = *(uint32_t*)(state->midi->data + state->position + sizeof(double));
- *data = state->midi->data + state->position +
- sizeof(double) + sizeof(uint32_t);
- return *timestamp;
-}
-
-
-/** This function advances the read/write position in @c state to the next
- event and returns its timestamp, or the @c frame_count member of @c state
- is there are no more events. */
-static double lv2midi_step(LV2_MIDIState* state) {
-
- if (state->position + sizeof(double) + sizeof(uint32_t) >= state->midi->size) {
- state->position = state->midi->size;
- return state->frame_count;
- }
-
- state->position += sizeof(double);
- uint32_t size = *(uint32_t*)(state->midi->data + state->position);
- state->position += sizeof(uint32_t);
- state->position += size;
-
- if (state->position >= state->midi->size)
- return state->frame_count;
-
- return *(double*)(state->midi->data + state->position);
-}
-
-
-/** This function writes one MIDI event to the port buffer associated with
- @c state. It returns 0 when the event was written successfully to the
- buffer, and -1 when there was not enough room. The read/write position
- is advanced automatically. */
-static int lv2midi_put_event(LV2_MIDIState* state,
- double timestamp,
- uint32_t size,
- const unsigned char* data) {
-
- if (state->midi->capacity - state->midi->size <
- sizeof(double) + sizeof(uint32_t) + size)
- return -1;
-
- *(double*)(state->midi->data + state->midi->size) = timestamp;
- state->midi->size += sizeof(double);
- *(uint32_t*)(state->midi->data + state->midi->size) = size;
- state->midi->size += sizeof(uint32_t);
- memcpy(state->midi->data + state->midi->size, data, size);
- state->midi->size += size;
-
- ++state->midi->event_count;
-
- return 0;
-}
-
-
-#endif
-