contexts
type: Specification
type: Feature
name: LV2 Contexts
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 struct { void* host_handle; void (*request_run)(void* host_handle, const char* context_uri); } 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 Context
type: Class
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.

RollingContext
type: Class
subclass of: LV2 Context
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.

BlockingContext
type: Class
subclass of: LV2 Context
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.

Has an optional context
type: Property
domain: Plugin
range: LV2 Context
comment: Signifies a Plugin supports a certain context, defined by a URI, which may be ignored by the host.

Has a required context
type: Property
domain: Plugin
range: LV2 Context
comment: Signifies a Plugin supports a certain context, defined by a URI, which must be supported by the host for the plugin to function.

Is used by context
type: Property
domain: Port
range: LV2 Context
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.

AudioContext
type: Class
subclass of: LV2 Context
comment: The context of the core LV2 run method (LV2_Descriptor::run).

StatelessAudioContext
type: Class
subclass of: LV2 Context
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).

MessageContext
type: Class
subclass of: BlockingContext
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.