From 725d4a404b838da6b67d9da66228a1125bddef57 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 20 Nov 2011 23:08:57 +0000 Subject: Lay out repository structure to match include and URI structure. Treat lv2core like all the other specifications in gendoc.py. --- ns/ext/contexts/contexts.h | 82 ++++++++++++++++++++++++++ ns/ext/contexts/contexts.ttl | 134 +++++++++++++++++++++++++++++++++++++++++++ ns/ext/contexts/ext.pc.in | 1 + ns/ext/contexts/manifest.ttl | 9 +++ ns/ext/contexts/test.c | 67 ++++++++++++++++++++++ ns/ext/contexts/waf | 1 + ns/ext/contexts/wscript | 1 + 7 files changed, 295 insertions(+) create mode 100644 ns/ext/contexts/contexts.h create mode 100644 ns/ext/contexts/contexts.ttl create mode 120000 ns/ext/contexts/ext.pc.in create mode 100644 ns/ext/contexts/manifest.ttl create mode 100644 ns/ext/contexts/test.c create mode 120000 ns/ext/contexts/waf create mode 120000 ns/ext/contexts/wscript (limited to 'ns/ext/contexts') diff --git a/ns/ext/contexts/contexts.h b/ns/ext/contexts/contexts.h new file mode 100644 index 0000000..f49b474 --- /dev/null +++ b/ns/ext/contexts/contexts.h @@ -0,0 +1,82 @@ +/* LV2 Contexts Extension + * Copyright (C) 2007-2009 David Robillard + * + * 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 + * . + */ + +#ifndef LV2_CONTEXTS_H +#define LV2_CONTEXTS_H + +#include + +#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/ns/ext/contexts/contexts.ttl b/ns/ext/contexts/contexts.ttl new file mode 100644 index 0000000..c56c649 --- /dev/null +++ b/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: . +@prefix lv2: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix doap: . +@prefix foaf: . + + + a lv2:Specification , lv2:Feature ; + doap:name "LV2 Contexts" ; + doap:shortdesc "Support for plugins with several execution contexts." ; + lv2:documentation """ +

An extension for LV2 plugins which have several execution contexts.

+ +

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.

+ +

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.

+ +

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.

+""" . + + +########################## +## Context Base Classes ## +########################## + +ctx:Context a rdfs:Class ; + rdfs:label "LV2 Context" ; + lv2:documentation """ +

A potentially concurrent context (callback) on a plugin.

+ +

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).

+ +

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. +<plugin> lv2:optionalFeature ctx:idleContext .), 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.

+ +

Any plugin that supports any context (optionally or mandatorily) MUST adhere +to the following additional threading rules for LV2_Descriptor.connect_port:

+
    +
  • connect_port MUST only be called for a given port from the context +associated with that port
  • +
  • connect_port MAY be called concurrently for ports with different +contexts (but MUST NOT be called concurrently for multiple ports in the +same context)
  • +
+

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.

+""" . + +ctx:audioContext a ctx:Context , lv2:Feature ; + rdfs:comment """The context of LV2_Descriptor.run().""" . + +ctx:messageContext a ctx:Context , lv2:Feature ; + lv2:documentation """ +

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 LV2_Contexts_MessageContext).

+""" . + +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 """ +

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 instantiate with data pointing to a +LV2_Contexts_Request_Run_Feature.

+ +

The plugin MAY call request_run with the given +data from any non-realtime context to demand soon-as-possible execution +of the specified context.

+""" . + +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/ns/ext/contexts/ext.pc.in b/ns/ext/contexts/ext.pc.in new file mode 120000 index 0000000..1cdad2a --- /dev/null +++ b/ns/ext/contexts/ext.pc.in @@ -0,0 +1 @@ +../../../ext.pc.in \ No newline at end of file diff --git a/ns/ext/contexts/manifest.ttl b/ns/ext/contexts/manifest.ttl new file mode 100644 index 0000000..d2cc036 --- /dev/null +++ b/ns/ext/contexts/manifest.ttl @@ -0,0 +1,9 @@ +@prefix lv2: . +@prefix rdfs: . + + + a lv2:Specification ; + lv2:minorVersion 0 ; + lv2:microVersion 1 ; + rdfs:seeAlso . + diff --git a/ns/ext/contexts/test.c b/ns/ext/contexts/test.c new file mode 100644 index 0000000..ca41a10 --- /dev/null +++ b/ns/ext/contexts/test.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include +#include +#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/ns/ext/contexts/waf b/ns/ext/contexts/waf new file mode 120000 index 0000000..917d5c5 --- /dev/null +++ b/ns/ext/contexts/waf @@ -0,0 +1 @@ +../../../waf \ No newline at end of file diff --git a/ns/ext/contexts/wscript b/ns/ext/contexts/wscript new file mode 120000 index 0000000..cf8cbae --- /dev/null +++ b/ns/ext/contexts/wscript @@ -0,0 +1 @@ +../../../ext.wscript \ No newline at end of file -- cgit v1.2.1