Blindly add a few stuff from VST
[juce-lv2.git] / juce / source / src / audio / plugin_client / LV2 / lv2_ui.h
blobe999317d05b276f0d6c6f89d5377b102719f23dc
1 /*
2 LV2 UI Extension
3 Copyright 2009-2011 David Robillard <d@drobilla.net>
4 Copyright 2006-2008 Lars Luthman <lars.luthman@gmail.com>
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
10 THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 /**
20 * @file
21 * C header for the LV2 UI extension <http://lv2plug.in/ns/extensions/ui>.
24 #ifndef LV2_UI_H
25 #define LV2_UI_H
27 #include "lv2.h"
29 #define LV2_UI_URI "http://lv2plug.in/ns/extensions/ui"
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
35 /**
36 A pointer to some widget or other type of UI handle.
38 The actual type is defined by the type URI of the UI. All the functionality
39 provided by this extension is toolkit independent, the host only needs to
40 pass the necessary callbacks and display the widget, if possible. Plugins
41 may have several UIs, in various toolkits.
43 typedef void* LV2UI_Widget;
45 /**
46 A pointer to a particular instance of a UI.
48 It is valid to compare this to NULL (0 for C++) but otherwise the host MUST
49 not attempt to interpret it. The UI plugin may use it to reference internal
50 instance data.
52 typedef void* LV2UI_Handle;
54 /**
55 A pointer to a particular plugin controller, provided by the host.
57 It is valid to compare this to NULL (0 for C++) but otherwise the UI plugin
58 MUST NOT attempt to interpret it. The host may use it to reference internal
59 instance data.
61 typedef void* LV2UI_Controller;
63 /**
64 The type of the host-provided function that the UI can use to
65 send data to a plugin's input ports.
67 The @c buffer parameter must point to a block of data, @c buffer_size bytes
68 large. The contents of this buffer and what the host should do with it
69 depends on the value of the @c format parameter.
71 The @c format parameter should either be 0 or a numeric ID for a "Transfer
72 mechanism". Transfer mechanisms are Features and may be defined in
73 meta-extensions. They specify how to translate the data buffers passed to
74 this function to input data for the plugin ports. If a UI wishes to write
75 data to an input port, it must list a transfer mechanism Feature for that
76 port's class as an optional or required feature (depending on whether the UI
77 will work without being able to write to that port or not). The only
78 exception is when the UI wants to write single float values to input ports
79 of the class lv2:ControlPort, in which case @c buffer_size should always be
80 4, the buffer should always contain a single IEEE-754 float, and @c format
81 should be 0.
83 The numeric IDs for the transfer mechanisms are provided by a URI-to-integer
84 mapping function provided by the host, using the URI Map feature
85 <http://lv2plug.in/ns/ext/uri-map> with the map URI
86 "http://lv2plug.in/ns/extensions/ui". Thus a UI that requires transfer
87 mechanism features also requires the URI Map feature, but this is implicit -
88 the UI does not have to list the URI map feature as a required or optional
89 feature in it's RDF data.
91 An UI MUST NOT pass a @c format parameter value (except 0) that has not been
92 returned by the host-provided URI mapping function for a host-supported
93 transfer mechanism feature URI.
95 The UI MUST NOT try to write to a port for which there is no specified
96 transfer mechanism, or to an output port. The UI is responsible for
97 allocating the buffer and deallocating it after the call.
99 typedef void (*LV2UI_Write_Function)(LV2UI_Controller controller,
100 uint32_t port_index,
101 uint32_t buffer_size,
102 uint32_t format,
103 const void* buffer);
106 The implementation of a UI.
108 A pointer to an object of this type is returned by the lv2ui_descriptor()
109 function.
111 typedef struct _LV2UI_Descriptor {
113 The URI for this UI (not for the plugin it controls).
115 const char* URI;
118 Create a new UI object and return a handle to it. This function works
119 similarly to the instantiate() member in LV2_Descriptor.
121 @param descriptor The descriptor for the UI that you want to instantiate.
123 @param plugin_uri The URI of the plugin that this UI will control.
125 @param bundle_path The path to the bundle containing the RDF data file
126 that references this shared object file, including the trailing '/'.
128 @param write_function A function provided by the host that the UI can use
129 to send data to the plugin's input ports.
131 @param controller A handle for the plugin instance that should be passed
132 as the first parameter of @c write_function.
134 @param widget A pointer to an LV2UI_Widget. The UI will write a widget
135 pointer to this location (what type of widget depends on the RDF class of
136 the UI) that will be the main UI widget.
138 @param features An array of LV2_Feature pointers. The host must pass all
139 feature URIs that it and the UI supports and any additional data, just
140 like in the LV2 plugin instantiate() function. Note that UI features and
141 plugin features are NOT necessarily the same, they just share the same
142 data structure - this will probably not be the same array as the one the
143 plugin host passes to a plugin.
146 LV2UI_Handle (*instantiate)(const struct _LV2UI_Descriptor* descriptor,
147 const char* plugin_uri,
148 const char* bundle_path,
149 LV2UI_Write_Function write_function,
150 LV2UI_Controller controller,
151 LV2UI_Widget* widget,
152 const LV2_Feature* const* features);
156 Destroy the UI object and the associated widget. The host must not try
157 to access the widget after calling this function.
159 void (*cleanup)(LV2UI_Handle ui);
162 Tell the UI that something interesting has happened at a plugin port.
164 What is interesting and how it is written to the buffer passed to this
165 function is defined by the @c format parameter, which has the same meaning
166 as in LV2UI_Write_Function. The only exception is ports of the class
167 lv2:ControlPort, for which this function should be called when the port
168 value changes (it does not have to be called for every single change if
169 the host's UI thread has problems keeping up with the thread the plugin is
170 running in), @c buffer_size should be 4, the buffer should contain a
171 single IEEE-754 float, and @c format should be 0.
173 By default, the host should only call this function for input ports of the
174 lv2:ControlPort class. However, the default setting can be modified by
175 using the following URIs in the UI's RDF data:
176 <pre>
177 uiext:portNotification
178 uiext:noPortNotification
179 uiext:plugin
180 uiext:portIndex
181 </pre>
182 For example, if you want the UI with uri
183 <code><http://my.pluginui></code> for the plugin with URI
184 <code><http://my.plugin></code> to get notified when the value of the
185 output control port with index 4 changes, you would use the following
186 in the RDF for your UI:
187 <pre>
188 <http://my.pluginui> uiext:portNotification [ uiext:plugin <http://my.plugin> ;
189 uiext:portIndex 4 ] .
190 </pre>
191 and similarly with <code>uiext:noPortNotification</code> if you wanted
192 to prevent notifications for a port for which it would be on by default
193 otherwise. The UI is not allowed to request notifications for ports of
194 types for which no transfer mechanism is specified, if it does it should
195 be considered broken and the host should not load it.
197 The @c buffer is only valid during the time of this function call, so if
198 the UI wants to keep it for later use it has to copy the contents to an
199 internal buffer.
201 This member may be set to NULL if the UI is not interested in any
202 port events.
204 void (*port_event)(LV2UI_Handle ui,
205 uint32_t port_index,
206 uint32_t buffer_size,
207 uint32_t format,
208 const void* buffer);
211 Return a data structure associated with an extension URI, for example
212 a struct containing additional function pointers.
214 Avoid returning function pointers directly since standard C/C++ has no
215 valid way of casting a void* to a function pointer. This member may be set
216 to NULL if the UI is not interested in supporting any extensions. This is
217 similar to the extension_data() member in LV2_Descriptor.
219 const void* (*extension_data)(const char* uri);
221 } LV2UI_Descriptor;
224 A plugin UI programmer must include a function called "lv2ui_descriptor"
225 with the following function prototype within the shared object file. This
226 function will have C-style linkage (if you are using C++ this is taken care
227 of by the 'extern "C"' clause at the top of the file). This function will
228 be accessed by the UI host using the @c dlsym() function and called to get a
229 LV2UI_UIDescriptor for the wanted plugin.
231 Just like lv2_descriptor(), this function takes an index parameter. The
232 index should only be used for enumeration and not as any sort of ID number -
233 the host should just iterate from 0 and upwards until the function returns
234 NULL or a descriptor with an URI matching the one the host is looking for.
236 const LV2UI_Descriptor* lv2ui_descriptor(uint32_t index);
239 The type of the lv2ui_descriptor() function.
241 typedef const LV2UI_Descriptor* (*LV2UI_DescriptorFunction)(uint32_t index);
243 #ifdef __cplusplus
245 #endif
247 #endif /* LV2_UI_H */