[SCM] calf/master: + LV2: first, incomplete and full of debug code, attempt at supporting new event extension (the old MIDI extension temporarily disabled)
js at users.alioth.debian.org
js at users.alioth.debian.org
Tue May 7 15:37:02 UTC 2013
The following commit has been merged in the master branch:
commit 04c10e979745d6b5054aa24fd17f948a3405a33e
Author: kfoltman <kfoltman at 78b06b96-2940-0410-b7fc-879d825d01d8>
Date: Fri Feb 1 19:57:31 2008 +0000
+ LV2: first, incomplete and full of debug code, attempt at supporting new event extension (the old MIDI extension temporarily disabled)
git-svn-id: https://calf.svn.sourceforge.net/svnroot/calf/trunk@118 78b06b96-2940-0410-b7fc-879d825d01d8
diff --git a/src/calf/Makefile.am b/src/calf/Makefile.am
index 3634c11..c61586f 100644
--- a/src/calf/Makefile.am
+++ b/src/calf/Makefile.am
@@ -2,6 +2,7 @@ calfdir = $(includedir)/calf
calf_HEADERS = audio_fx.h benchmark.h biquad.h buffer.h custom_ctl.h \
delay.h fft.h fixed_point.h giface.h gui.h inertia.h \
- jackhost.h modules.h modules_dev.h modules_synths.h \
+ jackhost.h lv2_event.h lv2_uri_map.h lv2-midiport.h lv2wrap.h \
+ modules.h modules_dev.h modules_synths.h \
onepole.h organ.h osc.h osctl.h preset.h preset_gui.h primitives.h \
synth.h wave.h
diff --git a/src/calf/lv2_event.h b/src/calf/lv2_event.h
new file mode 100644
index 0000000..6fda1ba
--- /dev/null
+++ b/src/calf/lv2_event.h
@@ -0,0 +1,184 @@
+/* lv2_event.h - C header file for the LV2 events extension.
+ *
+ * Copyright (C) 2006-2007 Lars Luthman <lars.luthman at gmail.com>
+ * Copyright (C) 2008 Dave Robillard <dave at drobilla.net>
+ *
+ * This header 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 header 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 header; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 01222-1307 USA
+ */
+
+#ifndef LV2_EVENT_H
+#define LV2_EVENT_H
+
+#define LV2_EVENT_URI "http://lv2plug.in/ns/ext/event"
+#define LV2_EVENT_AUDIO_STAMP 0
+
+#include <stdint.h>
+
+/** @file
+ * This header defines the code portion of the LV2 events extension with URI
+ * <http://lv2plug.in/ns/ext/event> ('lv2ev').
+ *
+ * This extension is a generic transport mechanism for time stamped events
+ * of any type (e.g. MIDI, OSC, ramps, etc). Each port can transport mixed
+ * events of any type; the type of events and timestamps are defined by a URI
+ * which is mapped to an integer by the host for performance reasons.
+ *
+ * This extension requires the host to support the LV2 URI Map extension.
+ * Any host which supports this extension MUST guarantee that any call to
+ * the LV2 URI Map uri_to_id function with the URI of this extension as the
+ * 'map' argument returns a value within the range of uint16_t.
+ */
+
+
+/** The best Pulses Per Quarter Note for tempo-based uint32_t timestmaps.
+ * Equal to 2^12 * 5 * 7 * 9 * 11 * 13 * 17, which is evenly divisble
+ * by all integers from 1 through 18 inclusive, and powers of 2 up to 2^12.
+ */
+static const uint32_t LV2_EVENT_PPQN = 3136573440;
+
+
+
+/** An LV2 event.
+ *
+ * LV2 events are generic time-stamped containers for any type of event.
+ * The type field defines the format of a given event's contents.
+ *
+ * This struct defines the header of an LV2 event. An LV2 event is a single
+ * chunk of POD (plain old data), usually contained in a flat buffer
+ * (see LV2_EventBuffer below). Unless a required feature says otherwise,
+ * hosts may assume a deep copy of an LV2 event can be created safely
+ * using a simple:
+ *
+ * memcpy(ev_copy, ev, sizeof(LV2_Event) + ev->size); (or equivalent)
+ */
+typedef struct {
+
+ /** The frames portion of timestamp. The units used here can optionally be
+ * set for a port (with the lv2ev:timeUnits property), otherwise this
+ * is audio frames, corresponding to the sample_count parameter of the
+ * LV2 run method (e.g. frame 0 is the first frame for that call to run).
+ */
+ uint32_t frames;
+
+ /** The sub-frames portion of timestamp. The units used here can
+ * optionally be set for a port (with the lv2ev:timeUnits property),
+ * otherwise this is 1/(2^32) of an audio frame.
+ */
+ uint32_t subframes;
+
+ /** The type of this event, as a number which represents some URI
+ * defining an event type. This value MUST be some value previously
+ * returned from a call to the uri_to_id function defined in the LV2
+ * URI map extension.
+ * The type 0 is a special reserved value, meaning the event contains a
+ * single pointer (of native machine size) to a dynamically allocated
+ * LV2_Object. This allows events to carry large non-POD payloads
+ * (e.g. images, waveforms, large SYSEX dumps, etc.) without copying.
+ * See the LV2 Object extension for details.
+ * Plugins which do not support the LV2 Object extension MUST NOT store,
+ * copy, or pass through to an output any event with type 0.
+ * If the type is not 0, plugins may assume the event is POD and should
+ * gracefully ignore or pass through (with a simple copy) any events
+ * of a type the plugin does not recognize.
+ */
+ uint16_t type;
+
+ /** The size of the data portion of this event in bytes, which immediately
+ * follows. The header size (12 bytes) is not included in this value.
+ */
+ uint16_t size;
+
+ /* size bytes of data follow here */
+
+} LV2_Event;
+
+
+
+/** A buffer of LV2 events.
+ *
+ * Like events (which this contains) an event buffer is a single chunk of POD:
+ * the entire buffer (including contents) can be copied with a single memcpy.
+ * The first contained event begins sizeof(LV2_EventBuffer) bytes after
+ * the start of this struct.
+ *
+ * After this header, the buffer contains an event header (defined by struct
+ * LV2_Event), followed by that event's contents (padded to 64 bits), followed by
+ * another header, etc:
+ *
+ * | | | | | | |
+ * | | | | | | | | | | | | | | | | | | | | | | | | |
+ * |FRAMES |SUBFRMS|TYP|LEN|DATA..DATA..PAD|FRAMES | ...
+ */
+typedef struct {
+
+ /** The number of events in this buffer.
+ * INPUTS: The host must set this field to the number of events
+ * contained in the data buffer before calling run().
+ * The plugin must not change this field.
+ * OUTPUTS: The plugin must set this field to the number of events it
+ * has written to the buffer before returning from run().
+ * Any initial value should be ignored by the plugin.
+ */
+ uint32_t event_count;
+
+ /** The size of the data buffer in bytes.
+ * This is set by the host and must not be changed by the plugin.
+ * The host is allowed to change this between run() calls.
+ */
+ uint32_t capacity;
+
+ /** The size of the initial portion of the data buffer containing data.
+ * INPUTS: The host must set this field to the number of bytes used
+ * by all events it has written to the buffer (including headers)
+ * before calling the plugin's run().
+ * The plugin must not change this field.
+ * OUTPUTS: The plugin must set this field to the number of bytes
+ * used by all events it has written to the buffer (including headers)
+ * before returning from run().
+ * Any initial value should be ignored by the plugin.
+ */
+ uint32_t size;
+
+ /** The type of the time stamps for events in this buffer.
+ * As a special exception, '0' always means audio frames and subframes
+ * (1/UINT32_MAX'th of a frame) in the sample rate passed to instantiate.
+ * INPUTS: The host must set this field to the numeric ID of some URI
+ * which defines the meaning of the frames and subframes fields of
+ * contained events (obtained by the LV2 URI Map uri_to_id function
+ * with the URI of this extension as the 'map' argument).
+ * The host must never pass a plugin a buffer which uses a stamp type
+ * the plugin does not 'understand'. The value of this field must
+ * never change, except when connect_port is called on the input
+ * port, at which time the host MUST have set the stamp_type field to
+ * the value that will be used for all run calls (until a reconnect).
+ * OUTPUTS: The plugin may set this to any value that has been returned
+ * from uri_to_id with the URI of this extension for a 'map' argument.
+ * When connected to a buffer with connect_port, output ports MUST set
+ * this field to the type of time stamp they will be writing. On any
+ * call to connect_port on an event input port, the plugin may change
+ * this field on any output port, it is the responsibility of the host
+ * to check if any of these values have changed.
+ */
+ uint16_t stamp_type;
+
+ /** For possible future use. Hosts and plugins that do not know of any
+ * use for this value MUST always set it to 0. */
+ uint16_t pad;
+
+} LV2_Event_Buffer;
+
+
+#endif // LV2_EVENT_H
+
diff --git a/src/calf/lv2_uri_map.h b/src/calf/lv2_uri_map.h
new file mode 100644
index 0000000..edcb49a
--- /dev/null
+++ b/src/calf/lv2_uri_map.h
@@ -0,0 +1,85 @@
+/* lv2_uri_map.h - C header file for the LV2 URI Map extension.
+ *
+ * Copyright (C) 2008 Dave Robillard <dave at drobilla.net>
+ *
+ * This header 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 header 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 header; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 01222-1307 USA
+ */
+
+#ifndef LV2_URI_MAP_H
+#define LV2_URI_MAP_H
+
+#define LV2_URI_MAP_URI "http://lv2plug.in/ns/ext/uri-map"
+
+#include <stdint.h>
+
+/** @file
+ * This header defines the LV2 URI Map extension with the URI
+ * <http://lv2plug.in/ns/ext/uri-map> (preferred prefix 'lv2urimap').
+ *
+ * This extension defines a simple mechanism for plugins to map URIs to
+ * integers, usually for performance reasons (e.g. processing events
+ * typed by URIs in real time). The expected use case is for plugins to
+ * map URIs to integers for things they 'understand' at instantiation time,
+ * and store those values for use in the audio thread without doing any string
+ * comparison. This allows the extensibility of RDF with the performance of
+ * integers (or centrally defined enumerations).
+ */
+
+
+/** Opaque pointer to host data. */
+typedef void* LV2_URI_Map_Callback_Data;
+
+
+/** The data field of the LV2_Feature for this extension.
+ *
+ * To support this feature the host must pass an LV2_Feature struct to the
+ * plugin's instantiate method with URI "http://lv2plug.in/ns/ext/uri-map"
+ * and data pointed to an instance of this struct.
+ */
+typedef struct {
+
+ /** Get the numeric ID of a URI from the host.
+ *
+ * @param callback_data Must be the callback_data member of this struct.
+ * @param map The 'context' of this URI. Certain extensions may define a
+ * URI that must be passed here with certain restrictions on the
+ * return value (e.g. limited range). This value may be NULL if
+ * the plugin needs an ID for a URI in general.
+ * @param uri The URI to be mapped to an integer ID.
+ *
+ * This function is referentially transparent - any number of calls with
+ * the same arguments is guaranteed to return the same value over the life
+ * of a plugin instance (though the same URI may return different values
+ * with a different map parameter). However, this function is not
+ * necessarily very fast: plugins should cache any IDs they might need in
+ * performance critical situations.
+ */
+ uint32_t (*uri_to_id)(LV2_URI_Map_Callback_Data callback_data,
+ const char* map,
+ const char* uri);
+
+
+ /** Opaque pointer to host data.
+ *
+ * The plugin MUST pass this to any call to functions in this struct.
+ * Otherwise, it must not be interpreted in any way.
+ */
+ LV2_URI_Map_Callback_Data callback_data;
+
+} LV2_URI_Map_Feature;
+
+
+#endif // LV2_URI_MAP_H
+
diff --git a/src/calf/lv2wrap.h b/src/calf/lv2wrap.h
index ca25f84..c626c7c 100644
--- a/src/calf/lv2wrap.h
+++ b/src/calf/lv2wrap.h
@@ -4,6 +4,8 @@
#include <lv2.h>
#include <calf/giface.h>
#include <calf/lv2-midiport.h>
+#include <calf/lv2_event.h>
+#include <calf/lv2_uri_map.h>
namespace synth {
@@ -13,6 +15,9 @@ struct lv2_instance: public Module, public plugin_ctl_iface
bool set_srate;
int srate_to_set;
LV2_MIDI *midi_data;
+ LV2_Event_Buffer *event_data;
+ LV2_URI_Map_Feature *uri_map;
+ uint32_t midi_event_type;
lv2_instance()
{
for (int i=0; i < Module::in_count; i++)
@@ -21,7 +26,10 @@ struct lv2_instance: public Module, public plugin_ctl_iface
Module::outs[i] = NULL;
for (int i=0; i < Module::param_count; i++)
Module::params[i] = NULL;
+ uri_map = NULL;
midi_data = NULL;
+ event_data = NULL;
+ midi_event_type = 0xFFFFFFFF;
set_srate = true;
srate_to_set = 44100;
}
@@ -90,9 +98,15 @@ struct lv2_wrapper
int i = port - ins - outs;
mod->params[i] = (float *)DataLocation;
}
+#if USE_OLD_LV2_MIDI
else if (Module::support_midi && port == ins + outs + params) {
mod->midi_data = (LV2_MIDI *)DataLocation;
}
+#else
+ else if (Module::support_midi && port == ins + outs + params) {
+ mod->event_data = (LV2_Event_Buffer *)DataLocation;
+ }
+#endif
}
static void cb_activate(LV2_Handle Instance) {
@@ -110,6 +124,18 @@ struct lv2_wrapper
// XXXKF some people use fractional sample rates; we respect them ;-)
mod->srate_to_set = (uint32_t)sample_rate;
mod->set_srate = true;
+ while(*features)
+ {
+ if (!strcmp((*features)->URI, LV2_URI_MAP_URI))
+ {
+ mod->uri_map = (LV2_URI_Map_Feature *)((*features)->data);
+ mod->midi_event_type = mod->uri_map->uri_to_id(
+ mod->uri_map->callback_data,
+ "http://lv2plug.in/ns/ext/event",
+ "http://lv2plug.in/ns/ext/midi#MidiEvent");
+ }
+ features++;
+ }
return mod;
}
static inline void zero_by_mask(Module *module, uint32_t mask, uint32_t offset, uint32_t nsamples)
@@ -140,6 +166,7 @@ struct lv2_wrapper
}
mod->params_changed();
uint32_t offset = 0;
+#if USE_OLD_LV2_MIDI
if (mod->midi_data)
{
struct MIDI_ITEM {
@@ -168,6 +195,40 @@ struct lv2_wrapper
data += 12 + item->size;
}
}
+#else
+ if (mod->event_data)
+ {
+ printf("Event data: count %d\n", mod->event_data->event_count);
+ struct LV2_Midi_Event: public LV2_Event {
+ unsigned char data[1];
+ };
+ unsigned char *data = (unsigned char *)(mod->event_data + 1);
+ for (uint32_t i = 0; i < mod->event_data->event_count; i++) {
+ LV2_Midi_Event *item = (LV2_Midi_Event *)data;
+ uint32_t ts = item->frames;
+ printf("Event: timestamp %d subframes %d type %d vs %d\n", item->frames, item->subframes, item->type, mod->midi_event_type);
+ if (ts > offset)
+ {
+ process_slice(mod, offset, ts);
+ offset = ts;
+ }
+ if (item->type == mod->midi_event_type)
+ {
+ printf("Midi message %x %x %x %x %d\n", item->data[0], item->data[1], item->data[2], item->data[3], item->size);
+ switch(item->data[0] >> 4)
+ {
+ case 8: mod->note_off(item->data[1], item->data[2]); break;
+ case 9: mod->note_on(item->data[1], item->data[2]); break;
+ case 10: mod->program_change(item->data[1]); break;
+ case 11: mod->control_change(item->data[1], item->data[2]); break;
+ case 14: mod->pitch_bend(item->data[1] + 128 * item->data[2] - 8192); break;
+ }
+ }
+ // printf("timestamp %f item size %d first byte %x\n", item->timestamp, item->size, item->data[0]);
+ data += ((sizeof(LV2_Event) + item->size + 7))&~7;
+ }
+ }
+#endif
process_slice(mod, offset, SampleCount);
}
static void cb_cleanup(LV2_Handle Instance) {
diff --git a/src/makerdf.cpp b/src/makerdf.cpp
index e8ebe2b..c2b2e80 100644
--- a/src/makerdf.cpp
+++ b/src/makerdf.cpp
@@ -23,6 +23,9 @@
#include <config.h>
#include <calf/giface.h>
#include <calf/modules.h>
+#if USE_LV2
+#include <calf/lv2_event.h>
+#endif
using namespace std;
using namespace synth;
@@ -108,11 +111,14 @@ void make_ttl(string path_prefix)
string header;
header =
+ "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n"
"@prefix lv2: <http://lv2plug.in/ns/lv2core#> .\n"
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"
"@prefix doap: <http://usefulinc.com/ns/doap#> .\n"
"@prefix midiext: <http://ll-plugins.nongnu.org/lv2/ext/MidiPort> .\n"
"@prefix uiext: <http://ll-plugins.nongnu.org/lv2/ext/ui#> .\n"
+ "@prefix lv2ev: <http://lv2plug.in/ns/ext/event#> .\n"
+
"\n"
;
@@ -157,13 +163,11 @@ void make_ttl(string path_prefix)
ttl += " uiext:ui <http://calf.sourceforge.net/plugins/gui/gtk2-gui> ;\n";
#endif
-#if USE_PHAT
- ttl += " doap:license <http://usefulinc.com/doap/licenses/gpl> ;\n";
-#else
ttl += " doap:license <http://usefulinc.com/doap/licenses/lgpl> ;\n";
-#endif
if (pi.rt_capable)
ttl += " lv2:optionalFeature lv2:hardRtCapable ;\n";
+ if (pi.midi_in_capable)
+ ttl += " lv2:requiredFeature <" LV2_EVENT_URI "> ;\n";
string ports = "";
int pn = 0;
@@ -175,8 +179,10 @@ void make_ttl(string path_prefix)
add_port(ports, out_names[i], out_names[i], "Output", pn++);
for (int i = 0; i < pi.params; i++)
add_ctl_port(ports, pi.param_props[i], pn++);
- if (pi.midi_in_capable)
- add_port(ports, "midi_in", "MIDI", "Input", pn++, "<http://ll-plugins.nongnu.org/lv2/ext/MidiPort>");
+ if (pi.midi_in_capable) {
+ // add_port(ports, "midi_in", "MIDI", "Input", pn++, "<http://ll-plugins.nongnu.org/lv2/ext/MidiPort>");
+ add_port(ports, "event_in", "Event", "Input", pn++, "lv2ev:EventPort");
+ }
if (!ports.empty())
ttl += " lv2:port " + ports + "\n";
ttl += ".\n\n";
--
calf audio plugins packaging
More information about the pkg-multimedia-commits
mailing list