Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
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
10#ifndef __PLUGINS_BASE_PLUGIN_H__
11#define __PLUGINS_BASE_PLUGIN_H__
12
13#include "zrythm-config.h"
14
15#include "dsp/port.h"
20#include "utils/types.h"
21
22/* pulled in from X11 */
23#undef Bool
24
25typedef struct Project Project;
26typedef struct Channel Channel;
27typedef struct AutomationTrack AutomationTrack;
28typedef struct _ModulatorWidget ModulatorWidget;
29typedef struct Lv2Plugin Lv2Plugin;
31typedef struct MixerSelections MixerSelections;
32typedef struct _WrappedObjectWithChangeSignal WrappedObjectWithChangeSignal;
33
40#define PLUGIN_SCHEMA_VERSION 1
41
42#define PLUGIN_MAGIC 43198683
43#define IS_PLUGIN(x) (((Plugin *) x)->magic == PLUGIN_MAGIC)
44#define IS_PLUGIN_AND_NONNULL(x) (x && IS_PLUGIN (x))
45
49#define PLUGIN_MIN_REFRESH_RATE 30.f
50#define PLUGIN_MAX_REFRESH_RATE 121.f
51
55#define PLUGIN_MIN_SCALE_FACTOR 0.5f
56#define PLUGIN_MAX_SCALE_FACTOR 4.f
57
58#define plugin_is_in_active_project(self) \
59 (self->track && track_is_in_active_project (self->track))
60
63#define plugin_is_auditioner(self) \
64 (self->track && track_is_auditioner (self->track))
65
70typedef struct Plugin
71{
72 int schema_version;
73
75
80
83
86
89 int num_in_ports;
90 size_t in_ports_size;
91
92 /* caches */
93 GPtrArray * ctrl_in_ports;
94 GPtrArray * audio_in_ports;
95 GPtrArray * cv_in_ports;
96 GPtrArray * midi_in_ports;
97
100
103 int num_out_ports;
104 size_t out_ports_size;
105
113 int num_lilv_ports;
114
121
130
137
145 Port * r_out;
146
147 PluginBank ** banks;
148 int num_banks;
149 size_t banks_size;
150
151 PluginPresetIdentifier selected_bank;
152 PluginPresetIdentifier selected_preset;
153
156
160
164
168
172
186
190
194
203 char * state_dir;
204
208
212
223 GtkWindow * window;
224
228
232 GtkBox * ev_box;
233
236 GtkBox * vbox;
237
242
247
248 int magic;
249
251 ModulatorWidget * modulator_widget;
252
259
263
269
272
275
278
281} Plugin;
282
283static const cyaml_schema_field_t plugin_fields_schema[] = {
284 YAML_FIELD_INT (Plugin, schema_version),
285 YAML_FIELD_MAPPING_EMBEDDED (Plugin, id, plugin_identifier_fields_schema),
286 YAML_FIELD_MAPPING_PTR (Plugin, setting, plugin_setting_fields_schema),
287 YAML_FIELD_DYN_PTR_ARRAY_VAR_COUNT_OPT (Plugin, in_ports, port_schema),
288 YAML_FIELD_DYN_PTR_ARRAY_VAR_COUNT_OPT (Plugin, out_ports, port_schema),
289 YAML_FIELD_DYN_PTR_ARRAY_VAR_COUNT_OPT (Plugin, banks, plugin_bank_schema),
291 Plugin,
292 selected_bank,
293 plugin_preset_identifier_fields_schema),
295 Plugin,
296 selected_preset,
297 plugin_preset_identifier_fields_schema),
298 YAML_FIELD_INT (Plugin, visible),
299 YAML_FIELD_STRING_PTR_OPTIONAL (Plugin, state_dir),
300
301 CYAML_FIELD_END
302};
303
304static const cyaml_schema_value_t plugin_schema = {
305 YAML_VALUE_PTR_NULLABLE (Plugin, plugin_fields_schema),
306};
307
308NONNULL_ARGS (1)
309void plugin_init_loaded (Plugin * self, Track * track, MixerSelections * ms);
310
314NONNULL void
316
320NONNULL void
322
326NONNULL void
328
339NONNULL_ARGS (1)
341 PluginSetting * setting,
342 unsigned int track_name_hash,
343 PluginSlotType slot_type,
344 int slot,
345 GError ** error);
346
350Plugin *
351plugin_new_dummy (ZPluginCategory cat, unsigned int track_name_hash, int slot);
352
356NONNULL void
358
362NONNULL Port *
364
368NONNULL bool
370
375void
376plugin_print (Plugin * self, char * buf, size_t buf_sz);
377
387NONNULL void
389 Plugin * pl,
390 bool free_ats,
391 bool fire_events);
392
401NONNULL_ARGS (1) Plugin * plugin_clone (Plugin * src, GError ** error);
402
403void
404plugin_get_full_port_group_designation (
405 Plugin * self,
406 const char * port_group,
407 char * buf);
408
409NONNULL Port *
410plugin_get_port_in_group (Plugin * self, const char * port_group, bool left);
411
417NONNULL Port *
419
426NONNULL int
427plugin_activate (Plugin * pl, bool activate);
428
437NONNULL void
439 Plugin * pl,
440 Track * track,
441 PluginSlotType slot_type,
442 int slot,
443 bool confirm_overwrite,
444 bool fire_events);
445
450NONNULL void
452 Plugin * pl,
453 unsigned int track_name_hash,
454 PluginSlotType slot_type,
455 int slot);
456
461NONNULL void
463 Plugin * pl,
464 Track * prev_track,
465 Track * track,
466 PluginSlotType new_slot_type,
467 int new_slot);
468
469NONNULL void
470plugin_append_ports (Plugin * self, GPtrArray * ports);
471
479NONNULL void
480plugin_expose_ports (Plugin * pl, bool expose, bool inputs, bool outputs);
481
487NONNULL Port *
488plugin_get_port_by_symbol (Plugin * pl, const char * sym);
489
495NONNULL Port *
496plugin_get_port_by_param_uri (Plugin * pl, const char * uri);
497
501NONNULL MALLOC char *
503
517int
519 Plugin * self,
520 Plugin * src,
521 bool is_backup,
522 const char * abs_state_dir);
523
527NONNULL MALLOC char *
529 Plugin * self,
530 bool is_backup,
531 bool create_if_not_exists);
532
536NONNULL WARN_UNUSED_RESULT bool
537plugin_ensure_state_dir (Plugin * self, bool is_backup, GError ** error);
538
542NONNULL void
543plugin_get_all (Project * prj, GPtrArray * arr, bool check_undo_manager);
544
548NONNULL Channel *
549plugin_get_channel (Plugin * self);
550
554NONNULL Track *
555plugin_get_track (const Plugin * self);
556
557NONNULL Plugin *
558plugin_find (const PluginIdentifier * id);
559
565NONNULL void
567
571NONNULL void
573
584NONNULL void
586
590HOT NONNULL OPTIMIZE_O3 void
592
597NONNULL_ARGS (1)
598int plugin_instantiate (Plugin * self, LilvState * state, GError ** error);
599
603NONNULL void
604plugin_set_track_name_hash (Plugin * pl, unsigned int track_name_hash);
605
609NONNULL HOT void
610plugin_process (Plugin * plugin, const EngineProcessTimeInfo * const time_nfo);
611
612NONNULL MALLOC char *
613plugin_generate_window_title (Plugin * plugin);
614
618NONNULL void
620
624NONNULL bool
626
634NONNULL void
635plugin_select (Plugin * self, bool select, bool exclusive);
636
643NONNULL bool
644plugin_is_enabled (Plugin * self, bool check_track);
645
646NONNULL void
647plugin_set_enabled (Plugin * self, bool enabled, bool fire_events);
648
655HOT NONNULL void
657 Plugin * self,
658 const EngineProcessTimeInfo * const time_nfo);
659
668NONNULL int
669plugin_get_event_ports (Plugin * pl, Port ** ports, int input);
670
674NONNULL void
676
680NONNULL void
682
684plugin_add_bank_if_not_exists (Plugin * self, const char * uri, const char * name);
685
686NONNULL void
687plugin_add_preset_to_bank (
688 Plugin * self,
689 PluginBank * bank,
690 PluginPreset * preset);
691
692NONNULL void
693plugin_set_selected_bank_from_index (Plugin * self, int idx);
694
695NONNULL void
696plugin_set_selected_preset_from_index (Plugin * self, int idx);
697
698NONNULL void
699plugin_set_selected_preset_by_name (Plugin * self, const char * name);
700
704NONNULL void
706
715NONNULL void
717
723NONNULL void
725
732NONNULL void
734
740NONNULL void
742
750NONNULL void
752
761NONNULL void
763
768NONNULL int
770
775NONNULL void
777
782#endif
NONNULL void plugin_move(Plugin *pl, Track *track, PluginSlotType slot_type, int slot, bool confirm_overwrite, bool fire_events)
Moves the plugin to the given slot in the given channel.
NONNULL void plugin_set_ui_refresh_rate(Plugin *self)
Sets the UI refresh rate on the Plugin.
NONNULL bool plugin_is_selected(Plugin *pl)
Returns if Plugin exists in MixerSelections.
NONNULL MALLOC char * plugin_get_abs_state_dir(Plugin *self, bool is_backup, bool create_if_not_exists)
Returns the state dir as an absolute path.
NONNULL int plugin_cleanup(Plugin *self)
Cleans up an instantiated but not activated plugin.
int plugin_instantiate(Plugin *self, LilvState *state, GError **error)
Instantiates the plugin (e.g.
NONNULL void plugin_connect_to_plugin(Plugin *src, Plugin *dest)
Connect the output Ports of the given source Plugin to the input Ports of the given destination Plugi...
NONNULL void plugin_set_track_and_slot(Plugin *pl, unsigned int track_name_hash, PluginSlotType slot_type, int slot)
Sets the channel and slot on the plugin and its ports.
NONNULL void plugin_open_ui(Plugin *plugin)
Process show ui.
NONNULL MALLOC char * plugin_get_escaped_name(Plugin *pl)
Returns the escaped name of the plugin.
NONNULL void plugin_set_track_name_hash(Plugin *pl, unsigned int track_name_hash)
Sets the track name hash on the plugin.
NONNULL HOT void plugin_process(Plugin *plugin, const EngineProcessTimeInfo *const time_nfo)
Process plugin.
NONNULL void plugin_connect_to_prefader(Plugin *pl, Channel *ch)
Connects the Plugin's output Port's to the input Port's of the given Channel's prefader.
NONNULL Port * plugin_get_port_by_symbol(Plugin *pl, const char *sym)
Gets a port by its symbol.
NONNULL int plugin_activate(Plugin *pl, bool activate)
Activates or deactivates the plugin.
int plugin_copy_state_dir(Plugin *self, Plugin *src, bool is_backup, const char *abs_state_dir)
Copies the state directory from the given source plugin to the given destination plugin's state direc...
NONNULL void plugin_add_in_port(Plugin *pl, Port *port)
Adds an in port to the plugin's list.
NONNULL void plugin_get_all(Project *prj, GPtrArray *arr, bool check_undo_manager)
Returns all plugins in the current project.
Plugin * plugin_new_dummy(ZPluginCategory cat, unsigned int track_name_hash, int slot)
Create a dummy plugin for tests.
NONNULL void plugin_add_automation_track(Plugin *self, AutomationTrack *at)
Adds an AutomationTrack to the Plugin.
NONNULL_ARGS(1) Plugin *plugin_clone(Plugin *src
Clones the given plugin.
NONNULL Port * plugin_get_port_in_same_group(Plugin *self, Port *port)
Find corresponding port in the same port group (eg, if this is left, find right and vice versa).
NONNULL Port * plugin_get_enabled_port(Plugin *self)
Gets the enable/disable port for this plugin.
NONNULL void plugin_expose_ports(Plugin *pl, bool expose, bool inputs, bool outputs)
Exposes or unexposes plugin ports to the backend.
NONNULL void plugin_update_automatables(Plugin *plugin)
(re)Generates automatables for the plugin.
Plugin * plugin_new_from_setting(PluginSetting *setting, unsigned int track_name_hash, PluginSlotType slot_type, int slot, GError **error)
Creates/initializes a plugin and its internal plugin (LV2, etc.) using the given setting.
NONNULL void plugin_set_caches(Plugin *self)
Sets caches for processing.
NONNULL void plugin_close_ui(Plugin *plugin)
Process hide ui.
HOT NONNULL OPTIMIZE_O3 void plugin_prepare_process(Plugin *self)
Prepare plugin for processing.
NONNULL void plugin_delete_state_files(Plugin *self)
Deletes any state files associated with this plugin.
NONNULL void plugin_disconnect_from_prefader(Plugin *pl, Channel *ch)
Disconnect the automatic connections from the Plugin to the Channel's prefader (if last Plugin).
NONNULL void plugin_free(Plugin *plugin)
Frees given plugin, breaks all its port connections, and frees its ports and other internal pointers.
NONNULL void plugin_update_identifier(Plugin *self)
To be called when changes to the plugin identifier were made, so we can update all children recursive...
NONNULL bool plugin_is_enabled(Plugin *self, bool check_track)
Returns whether the plugin is enabled.
ZPluginCategory
Plugin category.
NONNULL WARN_UNUSED_RESULT bool plugin_ensure_state_dir(Plugin *self, bool is_backup, GError **error)
Ensures the state dir exists or creates it.
HOT NONNULL void plugin_process_passthrough(Plugin *self, const EngineProcessTimeInfo *const time_nfo)
Processes the plugin by passing through the input to its output.
NONNULL int plugin_get_event_ports(Plugin *pl, Port **ports, int input)
Returns the event ports in the plugin.
NONNULL void plugin_disconnect_from_plugin(Plugin *src, Plugin *dest)
Disconnect the automatic connections from the given source Plugin to the given destination Plugin.
NONNULL void plugin_add_out_port(Plugin *pl, Port *port)
Adds an out port to the plugin's list.
void plugin_print(Plugin *self, char *buf, size_t buf_sz)
Prints the plugin to the buffer, if any, or to the log.
NONNULL void plugin_select(Plugin *self, bool select, bool exclusive)
Selects the plugin in the MixerSelections.
NONNULL void plugin_disconnect(Plugin *plugin)
To be called immediately when a channel or plugin is deleted.
NONNULL void plugin_move_automation(Plugin *pl, Track *prev_track, Track *track, PluginSlotType new_slot_type, int new_slot)
Moves the Plugin's automation from one Channel to another.
PluginSlotType
NONNULL void plugin_remove_ats_from_automation_tracklist(Plugin *pl, bool free_ats, bool fire_events)
Removes the automation tracks associated with this plugin from the automation tracklist in the corres...
NONNULL bool plugin_validate(Plugin *self)
Verifies that the plugin identifiers are valid.
NONNULL void plugin_update_latency(Plugin *pl)
Updates the plugin's latency.
NONNULL Port * plugin_get_port_by_param_uri(Plugin *pl, const char *uri)
Gets a port by its param URI.
NONNULL void plugin_generate_automation_tracks(Plugin *plugin, Track *track)
Generates automatables for the plugin.
#define YAML_FIELD_MAPPING_EMBEDDED(owner, member, schema)
Mapping embedded inside the struct.
Definition yaml.h:31
uint32_t nframes_t
Frame count.
Definition types.h:34
#define YAML_FIELD_MAPPING_PTR(owner, member, schema)
Mapping pointer to a struct.
Definition yaml.h:37
#define YAML_FIELD_DYN_PTR_ARRAY_VAR_COUNT_OPT(owner, member, schema)
Dynamic-width (reallocated) array of pointers with variable count, nullable.
Definition yaml.h:127
#define YAML_VALUE_PTR_NULLABLE(cc, fields_schema)
Schema to be used as a pointer that can be NULL.
Definition yaml.h:209
Plugin identifier.
Plugin preset.
Plugin settings.
Ports that transfer audio/midi/other signals to one another.
A Channel is part of a Track (excluding Tracks that don't have Channels) and contains information rel...
Definition channel.h:61
Common struct to pass around during processing to avoid repeating the data in function arguments.
Definition types.h:137
LV2 plugin.
Definition lv2_plugin.h:141
Selections to be used for the timeline's current selections, copying, undoing, etc.
A plugin bank containing presets.
Plugin identifier.
Preset identifier.
Plugin preset.
A setting for a specific plugin descriptor.
The base plugin Inheriting plugins must have this as a child.
Definition plugin.h:71
guint update_ui_source_id
ID of GSource (if > 0).
Definition plugin.h:258
ModulatorWidget * modulator_widget
Modulator widget, if modulator.
Definition plugin.h:251
int state_changed_event_sent
Set to true to avoid sending multiple ET_PLUGIN_STATE_CHANGED for the same plugin.
Definition plugin.h:268
Port * enabled
Control for plugin enabled, for convenience.
Definition plugin.h:120
Track * track
Pointer to owner track, if any.
Definition plugin.h:274
GtkWindow * window
The Plugin's window.
Definition plugin.h:223
bool instantiation_failed
Set to true if instantiation failed and the plugin will be treated as disabled.
Definition plugin.h:167
bool instantiated
Whether the plugin is currently instantiated or not.
Definition plugin.h:163
GtkBox * ev_box
The GdkWindow of this widget should be somewhere inside Plugin::window and will be used for wrapping ...
Definition plugin.h:232
bool external_ui_visible
Whether show () has been called on the LV2 external UI.
Definition plugin.h:227
float ui_update_hz
Update frequency of the UI, in Hz (times per second).
Definition plugin.h:189
nframes_t latency
Latency reported by the Lv2Plugin, if any, in samples.
Definition plugin.h:159
gulong destroy_window_id
ID of the destroy signal for Plugin::window so that we can deactivate before freeing the plugin.
Definition plugin.h:241
Port ** out_ports
Outgoing ports.
Definition plugin.h:102
Port * own_enabled_port
Whether the plugin has a custom "enabled" port (LV2).
Definition plugin.h:129
PluginSetting * setting
Setting this plugin was instantiated with.
Definition plugin.h:85
Port * l_out
Instrument left stereo output, for convenience.
Definition plugin.h:144
Port * gain
Control for plugin gain, for convenience.
Definition plugin.h:136
bool activated
Whether the plugin is currently activated or not.
Definition plugin.h:171
CarlaNativePlugin * carla
Pointer to Carla native plugin.
Definition plugin.h:82
GtkBox * vbox
Vbox containing the above ev_box for wrapping, or used for packing generic UI controls.
Definition plugin.h:236
bool deleting
Whether the plugin is currently being deleted.
Definition plugin.h:207
bool is_function
Whether the plugin is used for functions.
Definition plugin.h:271
MixerSelections * ms
Pointer to owner selections, if any.
Definition plugin.h:277
char * state_dir
State directory (only basename).
Definition plugin.h:203
Port * midi_in_port
Cache.
Definition plugin.h:99
int ui_instantiated
Whether the UI has finished instantiating.
Definition plugin.h:185
WrappedObjectWithChangeSignal * gobj
Used in Gtk.
Definition plugin.h:280
Lv2Plugin * lv2
Pointer back to plugin in its original format.
Definition plugin.h:79
Port ** lilv_ports
Ports at their lilv indices.
Definition plugin.h:112
bool deactivating
Temporary variable to check if plugin is currently undergoing deactivation.
Definition plugin.h:262
gulong close_request_id
ID of the close-request signal for Plugin::window so that we can deactivate before freeing the plugin...
Definition plugin.h:246
GtkWidget * active_preset_item
Active preset item, if wrapped or generic UI.
Definition plugin.h:211
Port ** in_ports
Ports coming in as input.
Definition plugin.h:88
float ui_scale_factor
Scale factor for drawing UIs in scale of the monitor.
Definition plugin.h:193
bool visible
Whether plugin UI is opened or not.
Definition plugin.h:155
Must ONLY be created via port_new()
Definition port.h:140
Contains all of the info that will be serialized into a project file.
Definition project.h:157
Track to be inserted into the Project's Tracklist.
Definition track.h:190
A GObject-ified normal C object with a signal that interested parties can listen to for changes.
Custom types.