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
34
41#define PLUGIN_SCHEMA_VERSION 1
42
43#define PLUGIN_MAGIC 43198683
44#define IS_PLUGIN(x) (((Plugin *) x)->magic == PLUGIN_MAGIC)
45#define IS_PLUGIN_AND_NONNULL(x) (x && IS_PLUGIN (x))
46
50#define PLUGIN_MIN_REFRESH_RATE 30.f
51#define PLUGIN_MAX_REFRESH_RATE 121.f
52
56#define PLUGIN_MIN_SCALE_FACTOR 0.5f
57#define PLUGIN_MAX_SCALE_FACTOR 4.f
58
59#define plugin_is_in_active_project(self) \
60 (self->track && track_is_in_active_project (self->track))
61
64#define plugin_is_auditioner(self) \
65 (self->track && track_is_auditioner (self->track))
66
71typedef struct Plugin
72{
73 int schema_version;
74
76
81
84
87
90 int num_in_ports;
91 size_t in_ports_size;
92
93 /* caches */
94 GPtrArray * ctrl_in_ports;
95 GPtrArray * audio_in_ports;
96 GPtrArray * cv_in_ports;
97 GPtrArray * midi_in_ports;
98
101
104 int num_out_ports;
105 size_t out_ports_size;
106
114 int num_lilv_ports;
115
122
131
138
146 Port * r_out;
147
148 PluginBank ** banks;
149 int num_banks;
150 size_t banks_size;
151
152 PluginPresetIdentifier selected_bank;
153 PluginPresetIdentifier selected_preset;
154
157
161
165
169
173
187
191
195
204 char * state_dir;
205
209
213
224 GtkWindow * window;
225
229
233 GtkBox * ev_box;
234
237 GtkBox * vbox;
238
243
248
249 int magic;
250
252 ModulatorWidget * modulator_widget;
253
260
264
270
273
276
279
282} Plugin;
283
284static const cyaml_schema_field_t plugin_fields_schema[] = {
285 YAML_FIELD_INT (Plugin, schema_version),
287 Plugin,
288 id,
289 plugin_identifier_fields_schema),
291 Plugin,
292 setting,
293 plugin_setting_fields_schema),
295 Plugin,
296 in_ports,
297 port_schema),
299 Plugin,
300 out_ports,
301 port_schema),
303 Plugin,
304 banks,
305 plugin_bank_schema),
307 Plugin,
308 selected_bank,
309 plugin_preset_identifier_fields_schema),
311 Plugin,
312 selected_preset,
313 plugin_preset_identifier_fields_schema),
314 YAML_FIELD_INT (Plugin, visible),
315 YAML_FIELD_STRING_PTR_OPTIONAL (Plugin, state_dir),
316
317 CYAML_FIELD_END
318};
319
320static const cyaml_schema_value_t plugin_schema = {
321 YAML_VALUE_PTR_NULLABLE (Plugin, plugin_fields_schema),
322};
323
324NONNULL_ARGS (1)
325void plugin_init_loaded (
326 Plugin * self,
327 Track * track,
328 MixerSelections * ms);
329
333NONNULL void
335 Plugin * self,
336 AutomationTrack * at);
337
341NONNULL void
343
347NONNULL void
349
360NONNULL_ARGS (1)
362 PluginSetting * setting,
363 unsigned int track_name_hash,
364 PluginSlotType slot_type,
365 int slot,
366 GError ** error);
367
371Plugin *
373 ZPluginCategory cat,
374 unsigned int track_name_hash,
375 int slot);
376
380NONNULL void
382
386NONNULL Port *
388
392NONNULL bool
394
399void
400plugin_print (Plugin * self, char * buf, size_t buf_sz);
401
411NONNULL void
413 Plugin * pl,
414 bool free_ats,
415 bool fire_events);
416
425NONNULL_ARGS (1)
426Plugin * plugin_clone (Plugin * src, GError ** error);
427
428void
429plugin_get_full_port_group_designation (
430 Plugin * self,
431 const char * port_group,
432 char * buf);
433
434NONNULL Port *
435plugin_get_port_in_group (
436 Plugin * self,
437 const char * port_group,
438 bool left);
439
445NONNULL Port *
447
454NONNULL int
455plugin_activate (Plugin * pl, bool activate);
456
464NONNULL void
466 Plugin * pl,
467 Track * track,
468 PluginSlotType slot_type,
469 int slot,
470 bool fire_events);
471
476NONNULL void
478 Plugin * pl,
479 unsigned int track_name_hash,
480 PluginSlotType slot_type,
481 int slot);
482
487NONNULL void
489 Plugin * pl,
490 Track * prev_track,
491 Track * track,
492 PluginSlotType new_slot_type,
493 int new_slot);
494
495NONNULL void
496plugin_append_ports (Plugin * self, GPtrArray * ports);
497
505NONNULL void
507 Plugin * pl,
508 bool expose,
509 bool inputs,
510 bool outputs);
511
517NONNULL Port *
518plugin_get_port_by_symbol (Plugin * pl, const char * sym);
519
525NONNULL Port *
526plugin_get_port_by_param_uri (Plugin * pl, const char * uri);
527
531NONNULL MALLOC char *
533
547int
549 Plugin * self,
550 Plugin * src,
551 bool is_backup,
552 const char * abs_state_dir);
553
557NONNULL MALLOC char *
559 Plugin * self,
560 bool is_backup,
561 bool create_if_not_exists);
562
566NONNULL WARN_UNUSED_RESULT bool
568 Plugin * self,
569 bool is_backup,
570 GError ** error);
571
575NONNULL void
577 Project * prj,
578 GPtrArray * arr,
579 bool check_undo_manager);
580
581NONNULL Channel *
582plugin_get_channel (Plugin * self);
583
584NONNULL Track *
585plugin_get_track (Plugin * self);
586
587NONNULL Plugin *
588plugin_find (const PluginIdentifier * id);
589
595NONNULL void
597
601NONNULL void
603
614NONNULL void
616 Plugin * plugin,
617 Track * track);
618
622HOT NONNULL OPTIMIZE_O3 void
624
629NONNULL_ARGS (1)
631 Plugin * self,
632 LilvState * state,
633 GError ** error);
634
638NONNULL void
640 Plugin * pl,
641 unsigned int track_name_hash);
642
646NONNULL HOT void
648 Plugin * plugin,
649 const EngineProcessTimeInfo * const time_nfo);
650
651NONNULL MALLOC char *
652plugin_generate_window_title (Plugin * plugin);
653
657NONNULL void
659
663NONNULL bool
665
673NONNULL void
674plugin_select (Plugin * self, bool select, bool exclusive);
675
682NONNULL bool
683plugin_is_enabled (Plugin * self, bool check_track);
684
685NONNULL void
686plugin_set_enabled (
687 Plugin * self,
688 bool enabled,
689 bool fire_events);
690
697HOT NONNULL void
699 Plugin * self,
700 const EngineProcessTimeInfo * const time_nfo);
701
710NONNULL int
711plugin_get_event_ports (Plugin * pl, Port ** ports, int input);
712
716NONNULL void
718
722NONNULL void
724
726plugin_add_bank_if_not_exists (
727 Plugin * self,
728 const char * uri,
729 const char * name);
730
731NONNULL void
732plugin_add_preset_to_bank (
733 Plugin * self,
734 PluginBank * bank,
735 PluginPreset * preset);
736
737NONNULL void
738plugin_set_selected_bank_from_index (Plugin * self, int idx);
739
740NONNULL void
741plugin_set_selected_preset_from_index (Plugin * self, int idx);
742
743NONNULL void
744plugin_set_selected_preset_by_name (
745 Plugin * self,
746 const char * name);
747
751NONNULL void
753
762NONNULL void
764
770NONNULL void
772
779NONNULL void
781
787NONNULL void
789
797NONNULL void
799
808NONNULL void
810
815NONNULL int
817
822NONNULL void
824
829#endif
COLD NONNULL_ARGS(1) void automation_track_init_loaded(AutomationTrack *self
Inits a loaded AutomationTracklist.
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_move(Plugin *pl, Track *track, PluginSlotType slot_type, int slot, bool fire_events)
Moves the plugin to the given slot in the given channel.
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.
Plugin * plugin_clone(Plugin *src, GError **error)
Clones the given plugin.
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 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:32
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:39
#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:138
#define YAML_VALUE_PTR_NULLABLE(cc, fields_schema)
Schema to be used as a pointer that can be NULL.
Definition yaml.h:228
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:63
Common struct to pass around during processing to avoid repeating the data in function arguments.
Definition types.h:140
LV2 plugin.
Definition lv2_plugin.h:144
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:72
guint update_ui_source_id
ID of GSource (if > 0).
Definition plugin.h:259
ModulatorWidget * modulator_widget
Modulator widget, if modulator.
Definition plugin.h:252
int state_changed_event_sent
Set to true to avoid sending multiple ET_PLUGIN_STATE_CHANGED for the same plugin.
Definition plugin.h:269
Port * enabled
Control for plugin enabled, for convenience.
Definition plugin.h:121
Track * track
Pointer to owner track, if any.
Definition plugin.h:275
GtkWindow * window
The Plugin's window.
Definition plugin.h:224
bool instantiation_failed
Set to true if instantiation failed and the plugin will be treated as disabled.
Definition plugin.h:168
bool instantiated
Whether the plugin is currently instantiated or not.
Definition plugin.h:164
GtkBox * ev_box
The GdkWindow of this widget should be somewhere inside Plugin::window and will be used for wrapping ...
Definition plugin.h:233
bool external_ui_visible
Whether show () has been called on the LV2 external UI.
Definition plugin.h:228
float ui_update_hz
Update frequency of the UI, in Hz (times per second).
Definition plugin.h:190
nframes_t latency
Latency reported by the Lv2Plugin, if any, in samples.
Definition plugin.h:160
gulong destroy_window_id
ID of the destroy signal for Plugin::window so that we can deactivate before freeing the plugin.
Definition plugin.h:242
Port ** out_ports
Outgoing ports.
Definition plugin.h:103
Port * own_enabled_port
Whether the plugin has a custom "enabled" port (LV2).
Definition plugin.h:130
PluginSetting * setting
Setting this plugin was instantiated with.
Definition plugin.h:86
Port * l_out
Instrument left stereo output, for convenience.
Definition plugin.h:145
Port * gain
Control for plugin gain, for convenience.
Definition plugin.h:137
bool activated
Whether the plugin is currently activated or not.
Definition plugin.h:172
CarlaNativePlugin * carla
Pointer to Carla native plugin.
Definition plugin.h:83
GtkBox * vbox
Vbox containing the above ev_box for wrapping, or used for packing generic UI controls.
Definition plugin.h:237
bool deleting
Whether the plugin is currently being deleted.
Definition plugin.h:208
bool is_function
Whether the plugin is used for functions.
Definition plugin.h:272
MixerSelections * ms
Pointer to owner selections, if any.
Definition plugin.h:278
char * state_dir
State directory (only basename).
Definition plugin.h:204
Port * midi_in_port
Cache.
Definition plugin.h:100
int ui_instantiated
Whether the UI has finished instantiating.
Definition plugin.h:186
WrappedObjectWithChangeSignal * gobj
Used in Gtk.
Definition plugin.h:281
Lv2Plugin * lv2
Pointer back to plugin in its original format.
Definition plugin.h:80
Port ** lilv_ports
Ports at their lilv indices.
Definition plugin.h:113
bool deactivating
Temporary variable to check if plugin is currently undergoing deactivation.
Definition plugin.h:263
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:247
GtkWidget * active_preset_item
Active preset item, if wrapped or generic UI.
Definition plugin.h:212
Port ** in_ports
Ports coming in as input.
Definition plugin.h:89
float ui_scale_factor
Scale factor for drawing UIs in scale of the monitor.
Definition plugin.h:194
bool visible
Whether plugin UI is opened or not.
Definition plugin.h:156
Must ONLY be created via port_new()
Definition port.h:150
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:193
A GObject-ified normal C object with a signal that interested parties can listen to for changes.
Custom types.