# LV2 Patch

http://lv2plug.in/ns/ext/patch
Messages for accessing and manipulating properties.

Version | 2.4
Date | 2018-03-16
Discuss | devel@lists.lv2plug.in (subscribe)
Developer | David Robillard

- Index
- Reference
- History
- API

This vocabulary defines messages which can be used to access and manipulate properties. It is designed to provide a dynamic control interface for LV2 plugins, but is useful in many contexts.

The main feature of this design is that the messages themselves are described in the same format as the data they work with. In particular, messages can be serialised as a binary Object or in Turtle (or any other RDF serialisation).

The idea behind using a property-based interface for control is to prevent an an explosion of message types. Instead of a custom message for each action, control is achieved via manipulating properties (which are likely already defined for other reasons). Note, however, that this is purely conceptual; there is no requirement that the receiver actually implement a store of resources with properties.

For example, consider an object that can blink. Rather than define a specific interface to control this (e.g. `obj.start_blinking(); obj.stop_blinking()`), set a blinking property to true or false (e.g. `obj.set(blinking, true)`) to achieve the desired behaviour. One benefit of this approach is that a persistent state model is available for free: simply serialise the blinking property.

This specification is strictly metadata and does not define any binary mechanism, though it can be completely expressed by standard types in the LV2 Atom extension. Thus, hosts can be expected to be capable of transmitting it between plugins, or between a plugin and its UI, making it a good choice for advanced plugin control.

## Index

Classes | Properties | Instances | Files
--- | --- | --- | ---
Message Request Copy Delete Get Insert Move Patch Put Set Response Ack Error | add body destination property readable remove request sequenceNumber subject value writable | wildcard | lv2-patch.doap.ttl patch.h patch.ttl

## Reference

### Class patch:Ack

Ack

An acknowledgement that a request has been successfully processed. This is returned as a reply when a specific reply type is not necessary or appropriate.

Sub-class of | patch:Response

### Class patch:Copy

Copy

Copy the patch:subject to patch:destination. After this, patch:destination has the description patch:subject had prior to this request's execution, and patch:subject is unchanged. It is an error if the subject does not exist or the destination already exists. Multiple patch:subject properties may be given if the patch:destination is a container, the semantics of this use case are application defined.

Sub-class of | patch:Request
Restriction on patch:destination |
owl:cardinality | 1
Restriction on patch:subject |
owl:minCardinality | 1

### Class patch:Delete

Delete

Request the subject(s) be deleted.

Sub-class of | patch:Request

### Class patch:Error

Error

A response indicating an error processing a request.

Sub-class of | patch:Response

### Class patch:Get

Get

Request a description of the subject.

The detail of the response is not specified, it may be a flat description of all the properties of the subject, or a more expressive description with several subjects. A good choice is a concise bounded description, i.e. a description which recursively includes all properties with blank node values.

The response should have the same patch:subject property as the request, and a patch:body that is a description of that subject. For example:

    <get-request>
        a patch:Get ;
        patch:subject <something> .

Could result in:

    []
        a patch:Response ;
        patch:request <get-request> ;
        patch:subject <something> ;
        patch:body [
            eg:name "Something" ;
            eg:ratio 1.6180339887 ;
        ] .

Note the use of blank nodes is not required; the value of patch:body may be the actual resource node. Depending on the transport and syntax used this may be preferable. For example, the same response could be written:

    <something>
        eg:name "Something" ;
        eg:ratio 1.6180339887 .

    []
        a patch:Response ;
        patch:request <get-request> ;
        patch:subject <something> ;
        patch:body <something> .

If the patch:subject property is absent, then the Get implicitly applies to the receiver.

Sub-class of | patch:Request

### Class patch:Insert

Insert

Insert the patch:body at patch:subject. If the subject does not exist, it is created. If the subject does already exist, it is added to. This request only adds properties, it never removes them. The user must take care that multiple values are not set for properties which should only have one value.

Sub-class of | patch:Request
Restriction on patch:subject |
owl:cardinality | 1

### Class patch:Message

Patch Message

In domain of | patch:subject
| patch:remove
| patch:body
| patch:add
| patch:destination
| patch:sequenceNumber

### Class patch:Move

Move

Move the patch:subject to patch:destination. After this, patch:destination has the description patch:subject had prior to this request's execution, and patch:subject no longer exists. It is an error if the subject does not exist or the destination already exists.

Sub-class of | patch:Request
Restriction on patch:subject |
owl:cardinality | 1
Restriction on patch:destination |
owl:cardinality | 1

### Class patch:Patch

Patch

Add and/or remove properties of the subject.

This method always has at least one patch:subject, and exactly one patch:add and patch:remove property. The value of patch:add and patch:remove are nodes which have the properties to add or remove from the subject(s), respectively. The special value patch:wildcard may be used as the value of a remove property to remove all properties with the given predicate. For example:

    []
        a patch:Patch ;
        patch:subject <something> ;
        patch:add [
            eg:name "New name" ;
            eg:age 42 ;
        ] ;
        patch:remove [
            eg:name "Old name" ;
            eg:age patch:wildcard ;  # Remove all old eg:age properties
        ] .

Sub-class of | patch:Request
Restriction on patch:subject |
owl:minCardinality | 1

### Class patch:Put

Put

Put the patch:body as the patch:subject. If the subject does not already exist, it is created. If the subject does already exist, the patch:body is considered an updated version of it, and the previous version is replaced.

    []
        a patch:Put ;
        patch:subject <something> ;
        patch:body [
            eg:name "New name" ;
            eg:age 42 ;
        ] .

Sub-class of | patch:Request
Restriction on patch:subject |
owl:cardinality | 1

### Class patch:Request

Request

A request. A request may have a patch:subject property, which indicates which resource the request applies to. The subject may be omitted in contexts where it is implicit (e.g. the recipient is the subject).

Sub-class of | patch:Message
In range of | patch:request

### Class patch:Response

Response

A response to a message.

Sub-class of | patch:Message
In domain of | patch:request

### Class patch:Set

Set

A compact message for setting one property to a specific value.

This is equivalent to a patch:Patch which removes all pre-existing values for the property before setting the new value. For example:

    []
        a patch:Set ;
        patch:subject <something> ;
        patch:property eg:name ;
        patch:value "New name" .

Which is equivalent to:

    []
        a patch:Patch ;
        patch:subject <something> ;
        patch:add [
            eg:name "New name" ;
        ] ;
        patch:remove [
            eg:name patch:wildcard ;
        ] .

Sub-class of | patch:Request
Restriction on patch:property |
owl:cardinality | 1
Restriction on patch:value |
owl:cardinality | 1
In domain of | patch:property
| patch:value

### Property patch:add

OWL Type | Object Property
Domain | patch:Message

### Property patch:body

The body of a message. The details of this property's value depend on the type of message it is a part of.

OWL Type | Object Property
Domain | patch:Message

### Property patch:destination

OWL Type | Object Property
Domain | patch:Message

### Property patch:property

property

The property for a Set message.

Domain | patch:Set
Range | rdf:Property

### Property patch:readable

readable

Indicates that the subject may have a property that can be read via a patch:Get message. See the similar property patch:writable for details.

Range | rdf:Property

### Property patch:remove

remove

OWL Type | Object Property
Domain | patch:Message

### Property patch:request

request

The request this is a response to. This can be used if referring directly to the URI or blank node ID of the request is possible. Otherwise, use patch:sequenceNumber.

OWL Type | Object Property
Domain | patch:Response
Range | patch:Request

### Property patch:sequenceNumber

sequence number

The sequence number of a request or response. This property is used to associate replies with requests when it is not feasible to refer to request URIs with patch:request. A patch:Response with a given sequence number is the reply to the previously send patch:Request with the same sequence number. The special sequence number 0 means no reply is desired.

OWL Type | Object Property
Domain | patch:Message
Range | xsd:int

### Property patch:subject

The subject this message applies to.

OWL Type | Object Property
Domain | patch:Message

### Property patch:value

value

The value of a property in a patch:Set message.

Domain | patch:Set
Range | rdf:Property

### Property patch:writable

writable

Indicates that subject may have a property that can be written via a patch message. This is used to list supported properties, e.g. so user interfaces can present appropriate controls. For example:

    @prefix eg:   <http://example.org/> .
    @prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

    eg:title
        a rdf:Property ;
        rdfs:label "title" ;
        rdfs:range xsd:string .

    eg:plugin
        patch:writable eg:title .

Range | rdf:Property

### Instance patch:wildcard

A wildcard which matches any resource. This makes it possible to describe the removal of all values for a given property.

Type | rdfs:Resource

## History

Version 2.4 (2015-04-07)
  - Define patch:Get with no subject to implicitly apply to reciever. This can be used by UIs to get an initial description of a plugin.
  - Add patch:Copy method.
Version 2.2 (2014-08-08)
  - Add patch:sequenceNumber for associating replies with requests.
Version 2.0 (2013-01-10)
  - Add patch:readable and patch:writable for describing available properties.
  - Make patch:Set a compact message for setting one property.
Version 1.0 (2012-04-17)
  - Initial release.