Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
lv2_plugin.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2018-2022 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3/*
4 * This file incorporates work covered by the following copyright and
5 * permission notice:
6 *
7 * ---
8 *
9 Copyright 2007-2016 David Robillard <http://drobilla.net>
10
11 Permission to use, copy, modify, and/or distribute this software for any
12 purpose with or without fee is hereby granted, provided that the above
13 copyright notice and this permission notice appear in all copies.
14
15 THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
16 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
18 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23 ---
24 */
25
32#ifndef __PLUGINS_LV2_PLUGIN_H__
33#define __PLUGINS_LV2_PLUGIN_H__
34
35#include "zrythm-config.h"
36
37#include <stdio.h>
38#include <stdlib.h>
39#include <string.h>
40
41#ifdef HAVE_ISATTY
42# include <unistd.h>
43#endif
44
45#include "dsp/port.h"
46#include "dsp/position.h"
48#include "plugins/lv2/lv2_evbuf.h"
50#include "plugins/lv2/lv2_worker.h"
51
52#include "zix/ring.h"
53#include "zix/sem.h"
54#include "zix/thread.h"
55#include <lilv/lilv.h>
56#include <lv2/data-access/data-access.h>
57#include <lv2/log/log.h>
58#include <lv2/options/options.h>
59#include <lv2/state/state.h>
60#include <lv2/urid/urid.h>
61#include <sratom/sratom.h>
62#include <suil/suil.h>
63
64typedef struct Lv2Plugin Lv2Plugin;
65typedef struct _GtkWidget GtkWidget;
66typedef struct _GtkCheckMenuItem GtkCheckMenuItem;
67typedef struct Port Port;
68typedef struct Plugin Plugin;
70
77#define LV2_PLUGIN_MAGIC 58173672
78#define IS_LV2_PLUGIN(tr) (tr && tr->magic == LV2_PLUGIN_MAGIC)
79
80#define LV2_ZRYTHM__defaultBank "https://lv2.zrythm.org#default-bank"
81#define LV2_ZRYTHM__initPreset "https://lv2.zrythm.org#init-preset"
82#define LV2_KX__externalUi \
83 "http://kxstudio.sf.net/ns/lv2ext/" \
84 "external-ui#Widget"
85
86/* currently missing from the spec */
87#ifndef LV2_CORE__enabled
88# define LV2_CORE__enabled LV2_CORE_PREFIX "enabled"
89#endif
90#ifndef LV2_CORE__isSideChain
91# define LV2_CORE__isSideChain LV2_CORE_PREFIX "isSideChain"
92#endif
93
94#define LV2_PARAM_MAX_STR_LEN 1200
95
96#define lv2_plugin_is_in_active_project(self) \
97 (plugin_is_in_active_project ((self)->plugin))
98
102typedef struct Lv2Parameter
103{
105 LV2_URID urid;
106
110 bool readable;
111 bool writable;
112 char symbol[LV2_PARAM_MAX_STR_LEN];
113 char label[LV2_PARAM_MAX_STR_LEN];
114 char comment[LV2_PARAM_MAX_STR_LEN];
115
118
120 float minf;
121 float maxf;
122 float deff;
124
129typedef struct
130{
131 uint32_t index;
132 uint32_t protocol;
133 uint32_t size;
134 uint8_t body[];
136
140typedef struct Lv2Plugin
141{
142 LV2_Feature map_feature;
143 LV2_Feature unmap_feature;
144 LV2_Feature make_path_temp_feature;
145 LV2_Feature sched_feature;
146 LV2_Feature state_sched_feature;
147 LV2_Feature safe_restore_feature;
148 LV2_Feature log_feature;
149 LV2_Feature options_feature;
150 LV2_Feature def_state_feature;
151 LV2_Feature hard_rt_capable_feature;
152 LV2_Feature data_access_feature;
153 LV2_Feature instance_access_feature;
154 LV2_Feature bounded_block_length_feature;
155
160 const LV2_Feature * features[13];
161
166 const LV2_Feature * state_features[7];
167
171 LV2_Options_Option options[10];
172
182 LV2_Extension_Data_Feature ext_data_feature;
183
186
193 const LV2_Options_Interface * options_iface;
194
196 LV2_Atom_Forge main_forge;
198 LV2_Atom_Forge dsp_forge;
200 Sratom * sratom;
202 Sratom * ui_sratom;
214 ZixSem work_lock;
216 const LilvPlugin * lilv_plugin;
218 LilvState * preset;
219
221 LilvInstance * instance;
222
224 SuilHost * suil_host;
226 SuilInstance * suil_instance;
227
234 char * temp_dir;
235
238 uint32_t midi_event_id;
239 bool exit;
240
243
246
256
264
272
274 ZixSem exit_sem;
275
279
282
285
286 bool updating;
287
289 LV2_URID_Map map;
290
292 LV2_URID_Unmap unmap;
293
295 SerdEnv * env;
296
299
303
305 float bpm;
306
309
312
313 /* ---- plugin feature data ---- */
314
316 LV2_State_Make_Path make_path_temp;
317
319 LV2_Worker_Schedule sched;
320
322 LV2_Worker_Schedule ssched;
323
325 LV2_Log_Log llog;
326
327 /* ---- end plugin feature data ---- */
328
329 int magic;
330
331} Lv2Plugin;
332
333#if 0
334static const cyaml_schema_field_t
335 lv2_plugin_fields_schema[] =
336{
338 Lv2Plugin, ports, lv2_port_schema),
339
340 CYAML_FIELD_END
341};
342
343static const cyaml_schema_value_t
344 lv2_plugin_schema =
345{
347 Lv2Plugin, lv2_plugin_fields_schema),
348};
349#endif
350
351NONNULL void
352lv2_plugin_init_loaded (Lv2Plugin * self);
353
359NONNULL PluginDescriptor *
361
371NONNULL_ARGS (1, 2)
373 Plugin * plugin,
374 const char * uri,
375 GError ** error);
376
396NONNULL_ARGS (1)
398 Lv2Plugin * self,
399 bool use_state_file,
400 char * preset_uri,
401 LilvState * state,
402 GError ** error);
403
413NONNULL Lv2Plugin *
415
419NONNULL void
421 Lv2Plugin * self,
422 const EngineProcessTimeInfo * const time_nfo);
423
430NONNULL nframes_t
432
447
455NONNULL char *
457
461NONNULL bool
462lv2_plugin_is_ui_supported (const char * pl_uri, const char * ui_uri);
463
467void
468lv2_plugin_get_uis (const char * pl_uri, char ** uris, int * num_uris);
469
479bool
481 const LilvUIs * uis,
483 const LilvUI ** out_ui,
484 const LilvNode ** out_ui_type);
485
486NONNULL char *
487lv2_plugin_get_ui_class (const char * pl_uri, const char * ui_uri);
488
492NONNULL char *
493lv2_plugin_get_ui_bundle_uri (const char * pl_uri, const char * ui_uri);
494
498NONNULL char *
499lv2_plugin_get_ui_binary_uri (const char * pl_uri, const char * ui_uri);
500
512bool
514 const char * plugin_uri,
515 char ** out_ui,
516 char ** out_ui_type,
517 bool allow_bridged,
518 bool print_result);
519
520/* FIXME remove */
521NONNULL bool
522lv2_plugin_ui_type_is_external (const LilvNode * ui_type);
523
524NONNULL bool
525lv2_plugin_is_ui_external (const char * uri, const char * ui_uri, GError ** error);
526
530void
532 Port * port,
533 uint32_t size,
534 LV2_URID type,
535 const void * body);
536
541NONNULL Port *
542lv2_plugin_get_property_port (Lv2Plugin * self, LV2_URID property);
543
551const void *
553 const char * port_sym,
554 void * user_data,
555 uint32_t * size,
556 uint32_t * type);
557
558NONNULL char *
559lv2_plugin_get_library_path (Lv2Plugin * self);
560
561NONNULL char *
562lv2_plugin_get_abs_state_file_path (Lv2Plugin * self, bool is_backup);
563
567NONNULL void
569
570NONNULL int
571lv2_plugin_activate (Lv2Plugin * self, bool activate);
572
577NONNULL bool
578lv2_plugin_can_cleanup (const char * uri);
579
584NONNULL void
586
587NONNULL int
588lv2_plugin_cleanup (Lv2Plugin * self);
589
593NONNULL void
595
600#endif
Ports that transfer audio/midi/other signals to one another.
NONNULL_ARGS(1) int undo_manager_undo(UndoManager *self
Undo last action.
Lv2PluginPickUiFlag
In order of preference.
Definition lv2_plugin.h:437
NONNULL nframes_t lv2_plugin_get_latency(Lv2Plugin *pl)
Returns the plugin's latency in samples.
NONNULL bool lv2_plugin_can_cleanup(const char *uri)
Returns whether the plugin can be cleaned up (some plugins crash on cleanup).
NONNULL void lv2_plugin_populate_banks(Lv2Plugin *self)
Populates the banks in the plugin instance.
int lv2_plugin_instantiate(Lv2Plugin *self, bool use_state_file, char *preset_uri, LilvState *state, GError **error)
Instantiate the plugin.
NONNULL void lv2_plugin_process(Lv2Plugin *self, const EngineProcessTimeInfo *const time_nfo)
Processes the plugin for this cycle.
NONNULL void lv2_plugin_free(Lv2Plugin *self)
Frees the Lv2Plugin and all its components.
Lv2Plugin * lv2_plugin_new_from_uri(Plugin *plugin, const char *uri, GError **error)
Creates an LV2 plugin from given uri.
const void * lv2_plugin_get_port_value(const char *port_sym, void *user_data, uint32_t *size, uint32_t *type)
Function to get a port value.
NONNULL bool lv2_plugin_is_ui_supported(const char *pl_uri, const char *ui_uri)
Returns whether the given UI uri is supported.
NONNULL char * lv2_plugin_has_deprecated_ui(const char *uri)
Returns whether the plugin has a custom UI that is deprecated (GtkUI, QtUI, etc.).
NONNULL Lv2Plugin * lv2_plugin_new(Plugin *plugin)
Creates a new LV2 plugin using the given Plugin instance.
NONNULL PluginDescriptor * lv2_plugin_create_descriptor_from_lilv(const LilvPlugin *lp)
Returns a newly allocated plugin descriptor for the given LilvPlugin if it can be hosted,...
NONNULL void lv2_plugin_allocate_port_buffers(Lv2Plugin *plugin)
Allocate port buffers (only necessary for MIDI).
void lv2_plugin_set_control(Port *port, uint32_t size, LV2_URID type, const void *body)
Ported from Lv2Control.
NONNULL char * lv2_plugin_get_ui_binary_uri(const char *pl_uri, const char *ui_uri)
Returns the binary path of the UI as a URI.
void lv2_plugin_get_uis(const char *pl_uri, char **uris, int *num_uris)
Returns the UI URIs that this plugin has.
bool lv2_plugin_pick_ui(const LilvUIs *uis, Lv2PluginPickUiFlag flag, const LilvUI **out_ui, const LilvNode **out_ui_type)
Pick the most preferable UI for the given flag.
NONNULL char * lv2_plugin_get_ui_bundle_uri(const char *pl_uri, const char *ui_uri)
Returns the bundle path of the UI as a URI.
bool lv2_plugin_pick_most_preferable_ui(const char *plugin_uri, char **out_ui, char **out_ui_type, bool allow_bridged, bool print_result)
Pick the most preferable UI.
NONNULL Port * lv2_plugin_get_property_port(Lv2Plugin *self, LV2_URID property)
Returns the property port matching the given property URID.
@ LV2_PLUGIN_UI_WRAPPABLE
Plugin UI wrappable using Suil.
Definition lv2_plugin.h:439
@ LV2_PLUGIN_UI_FOR_BRIDGING
Gtk2.
Definition lv2_plugin.h:445
@ LV2_PLUGIN_UI_EXTERNAL
External/KxExternal UI.
Definition lv2_plugin.h:442
uint_fast64_t unsigned_frame_t
Unsigned type for frame index.
Definition types.h:60
uint32_t nframes_t
Frame count.
Definition types.h:35
#define YAML_VALUE_PTR(cc, fields_schema)
Schema to be used as a pointer.
Definition yaml.h:202
#define YAML_FIELD_DYN_PTR_ARRAY_VAR_COUNT(owner, member, schema)
Dynamic-width (reallocated) array of pointers with variable count.
Definition yaml.h:81
LV2 extension to allow plugins to receive information about the host.
C header for the LV2 External UI extension http://kxstudio.sf.net/ns/lv2ext/external-ui.
Position struct and API.
String utilities.
Common struct to pass around during processing to avoid repeating the data in function arguments.
Definition types.h:138
On UI instantiation, host must supply LV2_EXTERNAL_UI__Host feature.
When LV2_EXTERNAL_UI__Widget UI is instantiated, the returned LV2UI_Widget handle must be cast to poi...
Control change event, sent through ring buffers for UI updates.
Definition lv2_plugin.h:130
Used temporarily to transfer data.
Definition lv2_plugin.h:103
bool has_range
Whether the ranges below are valid.
Definition lv2_plugin.h:117
float minf
Value range.
Definition lv2_plugin.h:120
LV2_URID value_type_urid
Value type URID (forge.Bool, forge.Int, etc.).
Definition lv2_plugin.h:109
LV2_URID urid
URI URID.
Definition lv2_plugin.h:105
LV2 plugin.
Definition lv2_plugin.h:141
bool want_position
Whether the plugin has at least 1 atom port that supports position.
Definition lv2_plugin.h:278
LV2_URID_Unmap unmap
Int => URI map.
Definition lv2_plugin.h:292
uint32_t comm_buffer_size
Plugin <=> UI communication buffer size.
Definition lv2_plugin.h:185
char * temp_dir
Temporary plugin state directory (absolute path).
Definition lv2_plugin.h:234
bool has_external_ui
Whether the plugin has an external UI.
Definition lv2_plugin.h:281
void * ui_event_buf
Buffer for readding UI port events.
Definition lv2_plugin.h:208
LV2_Log_Log llog
Log.
Definition lv2_plugin.h:325
LilvState * preset
Current preset.
Definition lv2_plugin.h:218
LV2_Extension_Data_Feature ext_data_feature
Data access feature.
Definition lv2_plugin.h:182
Sratom * ui_sratom
Atom serializer for UI thread.
Definition lv2_plugin.h:202
SerdEnv * env
Environment for RDF printing.
Definition lv2_plugin.h:295
Plugin * plugin
Base Plugin instance (parent).
Definition lv2_plugin.h:308
LV2_URID_Map map
URI => Int map.
Definition lv2_plugin.h:289
unsigned_frame_t gframes
Global (start) frames the plugin was last processed at.
Definition lv2_plugin.h:302
LilvInstance * instance
Plugin instance (shared library).
Definition lv2_plugin.h:221
ZixSem exit_sem
Exit semaphore.
Definition lv2_plugin.h:274
ZixRing * ui_to_plugin_events
Port events from UI to plugin.
Definition lv2_plugin.h:204
LV2_Atom_Forge dsp_forge
Atom forge (DSP thread).
Definition lv2_plugin.h:198
int rolling
Transport was rolling or not last cycle.
Definition lv2_plugin.h:298
bool safe_restore
Whether plugin restore() is thread-safe.
Definition lv2_plugin.h:245
const LilvPlugin * lilv_plugin
Plugin class (RDF data).
Definition lv2_plugin.h:216
LV2_State_Make_Path make_path_temp
Make path feature data.
Definition lv2_plugin.h:316
float bpm
Last BPM known by the plugin.
Definition lv2_plugin.h:305
const LV2_Feature * features[13]
Supported features passed when instantiating plugins.
Definition lv2_plugin.h:160
Lv2Worker state_worker
Synchronous worker for state restore.
Definition lv2_plugin.h:212
LV2_External_UI_Widget * external_ui_widget
Data structure used for external UIs.
Definition lv2_plugin.h:284
int enabled_in
Index of enabled port, or -1 if no port with "enabled" designation found.
Definition lv2_plugin.h:271
LV2_Worker_Schedule sched
Plugin worker schedule.
Definition lv2_plugin.h:319
ZixRing * plugin_to_ui_events
Port events from plugin to UI.
Definition lv2_plugin.h:206
LV2_Options_Option options[10]
Options to pass to plugin on instantiation.
Definition lv2_plugin.h:171
const LV2_Feature * state_features[7]
Features that are passed to state extension calls, such as when saving the state.
Definition lv2_plugin.h:166
uint32_t midi_event_id
MIDI event class ID in event context.
Definition lv2_plugin.h:238
Sratom * sratom
Atom serializer.
Definition lv2_plugin.h:200
LV2_Atom_Forge main_forge
Atom forge (main/GTK thread).
Definition lv2_plugin.h:196
uint32_t event_delta_t
Frames since last update sent to UI.
Definition lv2_plugin.h:237
SuilHost * suil_host
Plugin UI host support.
Definition lv2_plugin.h:224
Lv2Worker worker
Worker thread implementation.
Definition lv2_plugin.h:210
SuilInstance * suil_instance
Plugin UI instance (shared library).
Definition lv2_plugin.h:226
bool request_update
Whether a plugin update is needed.
Definition lv2_plugin.h:242
LV2_Worker_Schedule ssched
State worker schedule.
Definition lv2_plugin.h:322
ZixSem work_lock
Lock for plugin work() method.
Definition lv2_plugin.h:214
int control_in
Index of control input port, or -1 if no port with "control" designation found.
Definition lv2_plugin.h:263
bool has_default_state
Whether the plugin has a default state that must be loaded before running run() for the first time.
Definition lv2_plugin.h:255
bool exit
True iff execution is finished.
Definition lv2_plugin.h:239
LV2_External_UI_Host extui
Used for external UIs.
Definition lv2_plugin.h:311
const LV2_Options_Interface * options_iface
Options interface for setting plugin options dynamically.
Definition lv2_plugin.h:193
The base plugin Inheriting plugins must have this as a child.
Definition plugin.h:71
Must ONLY be created via port_new()
Definition port.h:140
API for Suil, an LV2 UI wrapper library.