diff options
author | David Robillard <d@drobilla.net> | 2012-02-08 04:56:24 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-02-08 04:56:24 +0000 |
commit | ed78bbe5ba12be1f9bcc736f14c51da6b4f639f3 (patch) | |
tree | 653a2dfe33f3923da45a38fc04ed2106f93528f3 /lv2/lv2plug.in/ns/ext/contexts | |
parent | b617875c6f3ad439d25ae166da79df839ebfdc71 (diff) | |
download | lv2-ed78bbe5ba12be1f9bcc736f14c51da6b4f639f3.tar.xz |
Rearrange tree so top level can be used as an include path for standard style LV2 includes.
Diffstat (limited to 'lv2/lv2plug.in/ns/ext/contexts')
-rw-r--r-- | lv2/lv2plug.in/ns/ext/contexts/contexts.h | 82 | ||||
-rw-r--r-- | lv2/lv2plug.in/ns/ext/contexts/contexts.ttl | 134 | ||||
l--------- | lv2/lv2plug.in/ns/ext/contexts/ext.pc.in | 1 | ||||
-rw-r--r-- | lv2/lv2plug.in/ns/ext/contexts/manifest.ttl | 9 | ||||
-rw-r--r-- | lv2/lv2plug.in/ns/ext/contexts/test.c | 67 | ||||
l--------- | lv2/lv2plug.in/ns/ext/contexts/waf | 1 | ||||
l--------- | lv2/lv2plug.in/ns/ext/contexts/wscript | 1 |
7 files changed, 295 insertions, 0 deletions
diff --git a/lv2/lv2plug.in/ns/ext/contexts/contexts.h b/lv2/lv2plug.in/ns/ext/contexts/contexts.h new file mode 100644 index 0000000..f49b474 --- /dev/null +++ b/lv2/lv2plug.in/ns/ext/contexts/contexts.h @@ -0,0 +1,82 @@ +/* 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> + +#include "lv2/lv2plug.in/ns/lv2core/lv2.h" + +#define LV2_CONTEXTS_URI "http://lv2plug.in/ns/ext/contexts" + +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; +} + +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 (*run)(LV2_Handle instance, + const void* valid_inputs, + void* valid_outputs); + +} LV2_Contexts_MessageContext; + +typedef void* LV2_Contexts_Request_Run_Data; + +typedef struct { + + /** Pointer to opaque host data (to be passed to request_run) */ + LV2_Contexts_Request_Run_Data data; + + /** Request the host execute the context with the given URI */ + void (*request_run)(LV2_Contexts_Request_Run_Data host_handle, + uint32_t context_uri); + +} LV2_Contexts_Request_Run_Feature; + +#endif /* LV2_CONTEXTS_H */ + diff --git a/lv2/lv2plug.in/ns/ext/contexts/contexts.ttl b/lv2/lv2plug.in/ns/ext/contexts/contexts.ttl new file mode 100644 index 0000000..c56c649 --- /dev/null +++ b/lv2/lv2plug.in/ns/ext/contexts/contexts.ttl @@ -0,0 +1,134 @@ +# 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-2010 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 , lv2:Feature ; + doap:name "LV2 Contexts" ; + doap:shortdesc "Support for plugins with several execution contexts." ; + lv2:documentation """ +<p>An extension for LV2 plugins which have several execution contexts.</p> + +<p>Contexts allow plugins to run tasks and/or process input/output in +multiple threads. Contexts can be used to add non-realtime functionality +to a plugin while still keeping the audio run() method realtime safe.</p> + +<p>A context is an LV2 feature, so the usual LV2 feature mechanism is used +to determine whether a plugin has a given context, and whether or not it is +mandatory.</p> + +<p>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.</p> +""" . + + +########################## +## Context Base Classes ## +########################## + +ctx:Context a rdfs:Class ; + rdfs:label "LV2 Context" ; + lv2:documentation """ +<p>A potentially concurrent context (callback) on a plugin.</p> + +<p>Ports are always associated with a context. If a port has no explicit context +property, then its context is ctx:audioContext (the default LV2 run() context).</p> + +<p>A plugin indicates support for a context by supporting an LV2 Feature with +that context's URI. If a plugin optionally supports a context (e.g. +<code><plugin> lv2:optionalFeature ctx:idleContext .</code>), then +all ports associated with that context MUST be lv2:connectionOptional. Thus, +hosts that do not support contexts will connect such ports to NULL and the +plugin can run with only a standard LV2 run() context.</p> + +<p>Any plugin that supports any context (optionally or mandatorily) MUST adhere +to the following additional threading rules for LV2_Descriptor.connect_port:</p> +<ul> +<li>connect_port MUST only be called for a given port from the context +associated with that port</li> +<li>connect_port MAY be called concurrently for ports with different +contexts (but MUST NOT be called concurrently for multiple ports in the +same context)</li> +</ul> +<p>Note this implies that any shared data access in connect_port may be +accessed concurrently. The plugin is responsible for any synchronisation +or locking necessary to make this possible.</p> +""" . + +ctx:audioContext a ctx:Context , lv2:Feature ; + rdfs:comment """The context of LV2_Descriptor.run().""" . + +ctx:messageContext a ctx:Context , lv2:Feature ; + lv2:documentation """ +<p>A non-realtime context for plugin control via message passing. This context +has a run method which takes a bitset of flags for parameters specifying which +input and output ports are valid before and after the run method has executed, +respectively (see <code>LV2_Contexts_MessageContext</code>).</p> +""" . + +ctx:idleContext a ctx:Context , lv2:Feature ; + rdfs:comment """ +A non-realtime idle context, periodically run by the host roughly every second. +This context never has any ports. +""" . + +ctx:requestRunFeature a lv2:Feature ; + lv2:documentation """ +<p>A feature allowing the plugin to request the execution of a particular +context at an arbitrary time. To support this feature, the host MUST pass an +LV2_Feature to <code>instantiate</code> with <code>data</code> pointing to a +LV2_Contexts_Request_Run_Feature.</p> + +<p>The plugin MAY call <code>request_run</code> with the given +<code>data</code> from any non-realtime context to demand soon-as-possible execution +of the specified context.</p> +""" . + +ctx:context a rdf:Property ; + rdfs:domain lv2:Port ; + rdfs:range ctx:Context ; + rdfs:label "is used in 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.""" . + + diff --git a/lv2/lv2plug.in/ns/ext/contexts/ext.pc.in b/lv2/lv2plug.in/ns/ext/contexts/ext.pc.in new file mode 120000 index 0000000..03dd044 --- /dev/null +++ b/lv2/lv2plug.in/ns/ext/contexts/ext.pc.in @@ -0,0 +1 @@ +../../../../../ext.pc.in
\ No newline at end of file diff --git a/lv2/lv2plug.in/ns/ext/contexts/manifest.ttl b/lv2/lv2plug.in/ns/ext/contexts/manifest.ttl new file mode 100644 index 0000000..d2cc036 --- /dev/null +++ b/lv2/lv2plug.in/ns/ext/contexts/manifest.ttl @@ -0,0 +1,9 @@ +@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 ; + lv2:minorVersion 0 ; + lv2:microVersion 1 ; + rdfs:seeAlso <contexts.ttl> . + diff --git a/lv2/lv2plug.in/ns/ext/contexts/test.c b/lv2/lv2plug.in/ns/ext/contexts/test.c new file mode 100644 index 0000000..ca41a10 --- /dev/null +++ b/lv2/lv2plug.in/ns/ext/contexts/test.c @@ -0,0 +1,67 @@ +#include <stdio.h> +#include <stdint.h> +#include <stdbool.h> +#include <limits.h> +#include <assert.h> +#include <unistd.h> +#include "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; +} + diff --git a/lv2/lv2plug.in/ns/ext/contexts/waf b/lv2/lv2plug.in/ns/ext/contexts/waf new file mode 120000 index 0000000..5235032 --- /dev/null +++ b/lv2/lv2plug.in/ns/ext/contexts/waf @@ -0,0 +1 @@ +../../../../../waf
\ No newline at end of file diff --git a/lv2/lv2plug.in/ns/ext/contexts/wscript b/lv2/lv2plug.in/ns/ext/contexts/wscript new file mode 120000 index 0000000..7e2c01b --- /dev/null +++ b/lv2/lv2plug.in/ns/ext/contexts/wscript @@ -0,0 +1 @@ +../../../../../ext.wscript
\ No newline at end of file |