aboutsummaryrefslogtreecommitdiffstats
path: root/ext/contexts.lv2
diff options
context:
space:
mode:
Diffstat (limited to 'ext/contexts.lv2')
-rw-r--r--ext/contexts.lv2/contexts.h72
-rw-r--r--ext/contexts.lv2/contexts.ttl202
-rw-r--r--ext/contexts.lv2/manifest.ttl7
-rw-r--r--ext/contexts.lv2/test.c65
4 files changed, 346 insertions, 0 deletions
diff --git a/ext/contexts.lv2/contexts.h b/ext/contexts.lv2/contexts.h
new file mode 100644
index 0000000..c6e8ef2
--- /dev/null
+++ b/ext/contexts.lv2/contexts.h
@@ -0,0 +1,72 @@
+/* LV2 Contexts Extension
+ * Copyright (C) 2007-2009 David Robillard <http://drobilla.net>
+ *
+ * This header is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU 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 General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/** @file
+ * C header for the LV2 Contexts extension
+ * <http://lv2plug.in/ns/ext/contexts>.
+ */
+
+#ifndef LV2_CONTEXTS_H
+#define LV2_CONTEXTS_H
+
+#include <stdint.h>
+
+#define LV2_CONTEXTS_URI "http://lv2plug.in/ns/ext/contexts"
+
+#define LV2_CONTEXT_MESSAGE "http://lv2plug.in/ns/ext/contexts#MessageContext"
+
+static inline void
+lv2_contexts_set_port_valid(void* flags, uint32_t index) {
+ ((uint8_t*)flags)[index / 8] |= 1 << (index % 8);
+}
+
+static inline void
+lv2_contexts_unset_port_valid(void* flags, uint32_t index) {
+ ((uint8_t*)flags)[index / 8] &= ~(1 << (index % 8));
+}
+
+static inline int
+lv2_contexts_port_is_valid(const void* flags, uint32_t index) {
+ return (((uint8_t*)flags)[index / 8] & (1 << (index % 8))) != 0;
+}
+
+#include "lv2.h"
+
+
+typedef struct {
+
+ /** The message run function. This is called once to process a set of
+ * inputs and produce a set of outputs.
+ *
+ * Before calling the host MUST set valid_inputs such that the bit
+ * corresponding to each input port is 1 iff data is present. The plugin
+ * MUST only inspect bits corresponding to ports in the message thread.
+ *
+ * Similarly, before returning the plugin MUST set valid_outputs such that
+ * the bit corresponding to each output port of the message context is 1
+ * iff the value at that port has changed.
+ * The plugin must return 1 if outputs have been written, 0 otherwise.
+ */
+ uint32_t (*message_run)(LV2_Handle instance,
+ const void* valid_inputs,
+ void* valid_outputs);
+
+} LV2_Contexts_MessageContext;
+
+#endif /* LV2_CONTEXTS_H */
+
diff --git a/ext/contexts.lv2/contexts.ttl b/ext/contexts.lv2/contexts.ttl
new file mode 100644
index 0000000..59c4cb1
--- /dev/null
+++ b/ext/contexts.lv2/contexts.ttl
@@ -0,0 +1,202 @@
+# LV2 Contexts Extension
+#
+# Allows for an LV2 plugin to have several independent contexts, each with its
+# own run callback and associated ports.
+#
+# Copyright (C) 2007 David Robillard
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+# OTHER DEALINGS IN THE SOFTWARE.
+
+@prefix ctx: <http://lv2plug.in/ns/ext/contexts#> .
+@prefix lv2: <http://lv2plug.in/ns/lv2core#> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema> .
+@prefix doap: <http://usefulinc.com/ns/doap#> .
+@prefix foaf: <http://xmlns.com/foaf/0.1/> .
+
+<http://lv2plug.in/ns/ext/contexts>
+ a lv2:Specification ;
+ a lv2:Feature ;
+ doap:name "LV2 Contexts" ;
+ rdfs:comment """
+An extension for LV2 plugins which have several execution contexts.
+
+Any host which supports this extension must pass an LV2_Feature to
+the plugin's instantiate method with URI http://lv2plug.in/ns/ext/contexts
+and a pointer to a
+<pre>
+struct {
+ void* host_handle;
+ void (*request_run)(void* host_handle, const char* context_uri);
+}
+</pre>
+where the plugin may call request_run with the given host_handle (from any
+context) to demand immediate execution of the context specified.
+
+If the host does not support blocking contexts, request_run may be set to NULL,
+but plugins which have a :BlockingContext which is :mandatory MUST NOT be
+instantiated. If the plugin has ANY context which is :hardRTCapable,
+request_run must be realtime safe (as defined by lv2:hardRTCapable).
+
+Unless otherwise stated, each context (defined by some URI) adds a new
+threading class similar to the Audio class defined by LV2. Each context has a
+run callback and a connect_port callback both in the same class (i.e. can't be
+called concurrently), but may be called concurrently with functions for other
+contexts (excluding the Instantiation class). Context properties such as
+ctx:hardRTCapable apply to both functions.
+The host MUST only call the correct connect_port function associated with the
+context for that port, i.e. it is an error to use the main LV2 connect_port
+function on a port with a context other than the main LV2 run function.
+"""^^lv2:basicXHTML .
+
+
+##########################
+## Context Base Classes ##
+##########################
+
+ctx:Context a rdfs:Class ;
+ rdfs:label "LV2 Context" ;
+ rdfs:comment """
+A potentially concurrent context (callback) on a plugin.
+
+If a plugin supports a context (specified with the :optionalContext or
+ctx:requiredContext plugin properties) its extension_data function, called with
+the URI for that context, should return a context descriptor as defined by the
+specification of the context URI. If a plugin has any contexts, it MUST specify
+the associated context of ALL ports, with the :context port property.""" .
+
+
+ctx:RollingContext a rdfs:Class ;
+ rdfs:subClassOf ctx:Context ;
+ rdfs:comment """
+A context which is is continually executed in blocks (like the standard LV2
+run callback). Extension data is a pointer to a
+
+struct {
+ void (*run)(LV2Handle instance, uint32_t sample_count);
+ void (*connect_port)(LV2_Handle instance, uint32_t port, void* data);
+}
+
+When run is called, sample_count frames worth of input/output should be
+read from/written to all ports associated with this context.
+""" .
+
+
+ctx:BlockingContext a rdfs:Class ;
+ rdfs:subClassOf ctx:Context ;
+ rdfs:comment """
+A context which is executed only when there is work to be done
+(e.g. a message is received). Extension data is a pointer to a
+
+struct LV2BlockingContext {
+ bool (*run)(LV2Handle instance, uint8_t* valid_inputs, uint8_t* valid_outputs)
+ void (*connect_port)(LV2_Handle instance, uint32_t port, void* data);
+}
+
+When run is called, any pending input in ports associated with this context
+should be read, and true returned iff output was written (meaning plugins
+connected to ports where output has been written should be executed).
+
+Before calling run, the host MUST set the nth bit of valid_inputs to 1 if the
+input port with index n has valid input that should be processed, otherwise 0.
+Before returning from run, the plugin MUST set the nth bit of valid_outputs
+to 1 if the port with index n was written to, otherwise 0.
+The header lv2_contexts.h provides utility functions for these purposes.
+The plugin MUST NOT touch any bits corresponding to ports on another context.
+""" .
+
+
+#######################
+## Plugin Properties ##
+#######################
+
+ctx:optionalContext a rdf:Property ;
+ rdfs:domain lv2:Plugin ;
+ rdfs:range ctx:Context ;
+ rdfs:label "Has an optional context" ;
+ rdfs:comment """
+Signifies a Plugin supports a certain context, defined by a URI, which may
+be ignored by the host.""" .
+
+ctx:requiredContext a rdf:Property ;
+ rdfs:domain lv2:Plugin ;
+ rdfs:range ctx:Context ;
+ rdfs:label "Has a required context" ;
+ rdfs:comment """
+Signifies a Plugin supports a certain context, defined by a URI, which must be
+supported by the host for the plugin to function.""" .
+
+
+#####################
+## Port Properties ##
+#####################
+
+ctx:context a rdf:Property ;
+ rdfs:domain lv2:Port ;
+ rdfs:range ctx:Context ;
+ rdfs:label "Is used by context" ;
+ rdfs:comment """
+The context a particular port is associated with; the port will only be
+connected/read/written by that context.
+
+If no context is specified, the port is considered part of the default LV2
+audio context.""" .
+
+
+##################################
+## Specific context definitions ##
+##################################
+
+
+ctx:AudioContext a rdfs:Class ;
+ rdfs:subClassOf ctx:Context ;
+ rdfs:comment """
+The context of the core LV2 run method (LV2_Descriptor::run).
+""" .
+
+
+ctx:StatelessAudioContext a rdfs:Class ;
+ rdfs:subClassOf ctx:Context ;
+ rdfs:comment """
+The usual LV2 run context (ctx:AudioContext), with the additional property
+that the plugin has no internal state whatsoever (other than the sample rate
+and the locations ports are currently connected to). On a plugin with a
+ctx:StatelessAudioContext, the nframes parameter to run is meaningless and
+ignored by the plugin, and the host may assume that any call to run with
+a given set of inputs will produce the exact same set of outputs (i.e.
+the plugin's run method is purely functional). This context inherently
+conflicts with lv2:isLive, a plugin MUST NOT have both a
+ctx:StatelessAudioContext and the lv2:isLive feature.
+
+For easy compatibility with hosts that don't care whether the audio context
+is stateless or not, this context should be listed as a ctx:optionalContext
+(since the default LV2 context is implicitly present).
+""" .
+
+
+ctx:MessageContext a rdfs:Class ;
+ rdfs:subClassOf ctx:BlockingContext ;
+ rdfs:comment """
+A blocking context for on-demand message-like processing. The plugin's
+lv2:hardRTCapable property does not apply to the message context, there are
+no realtime restrictions on the plugin's message context, and no
+syncronisation guarantees between the message context and any other context.
+""" .
+
diff --git a/ext/contexts.lv2/manifest.ttl b/ext/contexts.lv2/manifest.ttl
new file mode 100644
index 0000000..373b8f6
--- /dev/null
+++ b/ext/contexts.lv2/manifest.ttl
@@ -0,0 +1,7 @@
+@prefix lv2: <http://lv2plug.in/ns/lv2core#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+
+<http://lv2plug.in/ns/ext/contexts>
+ a lv2:Specification ;
+ rdfs:seeAlso <contexts.ttl> .
+
diff --git a/ext/contexts.lv2/test.c b/ext/contexts.lv2/test.c
new file mode 100644
index 0000000..f55cdd6
--- /dev/null
+++ b/ext/contexts.lv2/test.c
@@ -0,0 +1,65 @@
+#include <stdio.h>
+#include <limits.h>
+#include <assert.h>
+#include <unistd.h>
+#include "lv2_contexts.h"
+
+#define TEST_ASSERT(check) do {\
+ if (!(check)) {\
+ fprintf(stderr, "Failure at line %d: %s\n", __LINE__, #check);\
+ assert(false);\
+ _exit(1);\
+ }\
+} while (0)
+
+#define NUM_PORTS 64
+
+void
+print_flags(void* flags)
+{
+ for (int i = NUM_PORTS; i >= 0; --i)
+ printf((lv2_contexts_port_is_valid(flags, i)) ? "1" : "0");
+ printf("\n");
+}
+
+
+int
+main()
+{
+ uint64_t flags = 0;
+ print_flags(&flags);
+
+ lv2_contexts_set_port_valid(&flags, 16);
+ print_flags(&flags);
+ for (int i = 0; i < NUM_PORTS; ++i) {
+ if (i == 16) {
+ TEST_ASSERT(lv2_contexts_port_is_valid(&flags, i));
+ } else {
+ TEST_ASSERT(!lv2_contexts_port_is_valid(&flags, i));
+ }
+ }
+
+ lv2_contexts_set_port_valid(&flags, 46);
+ lv2_contexts_set_port_valid(&flags, 0);
+ print_flags(&flags);
+ for (int i = 0; i < NUM_PORTS; ++i) {
+ if (i == 0 || i == 16 || i == 46) {
+ TEST_ASSERT(lv2_contexts_port_is_valid(&flags, i));
+ } else {
+ TEST_ASSERT(!lv2_contexts_port_is_valid(&flags, i));
+ }
+ }
+
+ lv2_contexts_unset_port_valid(&flags, 16);
+ print_flags(&flags);
+ for (int i = 0; i < NUM_PORTS; ++i) {
+ if (i == 0 || i == 46) {
+ TEST_ASSERT(lv2_contexts_port_is_valid(&flags, i));
+ } else {
+ TEST_ASSERT(!lv2_contexts_port_is_valid(&flags, i));
+ }
+ }
+
+ return 0;
+}
+