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
46#define PLUGIN_DEFAULT_BANK_URI "https://lv2.zrythm.org#default-bank"
47#define PLUGIN_INIT_PRESET_URI "https://lv2.zrythm.org#init-preset"
48
52#define PLUGIN_MIN_REFRESH_RATE 30.f
53#define PLUGIN_MAX_REFRESH_RATE 121.f
54
58#define PLUGIN_MIN_SCALE_FACTOR 0.5f
59#define PLUGIN_MAX_SCALE_FACTOR 4.f
60
61#define plugin_is_in_active_project(self) \
62 (self->track && track_is_in_active_project (self->track))
63
66#define plugin_is_auditioner(self) \
67 (self->track && track_is_auditioner (self->track))
68
73typedef struct Plugin
74{
75 int schema_version;
76
78
81
84
87 int num_in_ports;
88 size_t in_ports_size;
89
90 /* caches */
91 GPtrArray * ctrl_in_ports;
92 GPtrArray * audio_in_ports;
93 GPtrArray * cv_in_ports;
94 GPtrArray * midi_in_ports;
95
98
101 int num_out_ports;
102 size_t out_ports_size;
103
110
119
126
134 Port * r_out;
135
136 PluginBank ** banks;
137 int num_banks;
138 size_t banks_size;
139
140 PluginPresetIdentifier selected_bank;
141 PluginPresetIdentifier selected_preset;
142
145
148
151
155
158
172
175
178
187 char * state_dir;
188
192
196
207 GtkWindow * window;
208
212 GtkBox * ev_box;
213
216 GtkBox * vbox;
217
222
227
228 int magic;
229
231 ModulatorWidget * modulator_widget;
232
239
243
249
252
255
258
261} Plugin;
262
263NONNULL_ARGS (1)
264void plugin_init_loaded (Plugin * self, Track * track, MixerSelections * ms);
265
269NONNULL void
271
275NONNULL void
277
281NONNULL void
283
294NONNULL_ARGS (1)
296 PluginSetting * setting,
297 unsigned int track_name_hash,
298 ZPluginSlotType slot_type,
299 int slot,
300 GError ** error);
301
305Plugin *
306plugin_new_dummy (ZPluginCategory cat, unsigned int track_name_hash, int slot);
307
311NONNULL void
313
317NONNULL Port *
319
323NONNULL bool
325
330void
331plugin_print (Plugin * self, char * buf, size_t buf_sz);
332
342NONNULL void
344 Plugin * pl,
345 bool free_ats,
346 bool fire_events);
347
356NONNULL_ARGS (1) Plugin * plugin_clone (Plugin * src, GError ** error);
357
358void
359plugin_get_full_port_group_designation (
360 Plugin * self,
361 const char * port_group,
362 char * buf);
363
364NONNULL Port *
365plugin_get_port_in_group (Plugin * self, const char * port_group, bool left);
366
372NONNULL Port *
374
381NONNULL int
382plugin_activate (Plugin * pl, bool activate);
383
392NONNULL void
394 Plugin * pl,
395 Track * track,
396 ZPluginSlotType slot_type,
397 int slot,
398 bool confirm_overwrite,
399 bool fire_events);
400
405NONNULL void
407 Plugin * pl,
408 unsigned int track_name_hash,
409 ZPluginSlotType slot_type,
410 int slot);
411
416NONNULL void
418 Plugin * pl,
419 Track * prev_track,
420 Track * track,
421 ZPluginSlotType new_slot_type,
422 int new_slot);
423
424NONNULL void
425plugin_append_ports (Plugin * self, GPtrArray * ports);
426
434NONNULL void
435plugin_expose_ports (Plugin * pl, bool expose, bool inputs, bool outputs);
436
442NONNULL Port *
443plugin_get_port_by_symbol (Plugin * pl, const char * sym);
444
448NONNULL MALLOC char *
450
464int
466 Plugin * self,
467 Plugin * src,
468 bool is_backup,
469 const char * abs_state_dir);
470
474NONNULL MALLOC char *
476 Plugin * self,
477 bool is_backup,
478 bool create_if_not_exists);
479
483NONNULL WARN_UNUSED_RESULT bool
484plugin_ensure_state_dir (Plugin * self, bool is_backup, GError ** error);
485
489NONNULL void
490plugin_get_all (Project * prj, GPtrArray * arr, bool check_undo_manager);
491
495NONNULL Channel *
496plugin_get_channel (Plugin * self);
497
501NONNULL Track *
502plugin_get_track (const Plugin * self);
503
504NONNULL Plugin *
505plugin_find (const PluginIdentifier * id);
506
512NONNULL void
514
518NONNULL void
520
531NONNULL void
533
537HOT NONNULL OPTIMIZE_O3 void
539
543NONNULL_ARGS (1) int plugin_instantiate (Plugin * self, GError ** error);
544
548NONNULL void
549plugin_set_track_name_hash (Plugin * pl, unsigned int track_name_hash);
550
554NONNULL HOT void
555plugin_process (Plugin * plugin, const EngineProcessTimeInfo * const time_nfo);
556
557NONNULL MALLOC char *
558plugin_generate_window_title (Plugin * plugin);
559
563NONNULL void
565
569NONNULL bool
571
579NONNULL void
580plugin_select (Plugin * self, bool select, bool exclusive);
581
588NONNULL bool
589plugin_is_enabled (Plugin * self, bool check_track);
590
591NONNULL void
592plugin_set_enabled (Plugin * self, bool enabled, bool fire_events);
593
600HOT NONNULL void
602 Plugin * self,
603 const EngineProcessTimeInfo * const time_nfo);
604
613NONNULL int
614plugin_get_event_ports (Plugin * pl, Port ** ports, int input);
615
619NONNULL void
621
625NONNULL void
627
629plugin_add_bank_if_not_exists (Plugin * self, const char * uri, const char * name);
630
631NONNULL void
632plugin_add_preset_to_bank (
633 Plugin * self,
634 PluginBank * bank,
635 PluginPreset * preset);
636
637NONNULL void
638plugin_set_selected_bank_from_index (Plugin * self, int idx);
639
640NONNULL void
641plugin_set_selected_preset_from_index (Plugin * self, int idx);
642
643NONNULL void
644plugin_set_selected_preset_by_name (Plugin * self, const char * name);
645
649NONNULL void
651
660NONNULL void
662
667NONNULL void
669
676NONNULL void
678
683NONNULL void
685
693NONNULL void
695
702NONNULL void
704
709NONNULL int
711
716NONNULL void
718
723#endif
Ports that transfer audio/midi/other signals to one another.
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.
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_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.
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...
Plugin * plugin_new_from_setting(PluginSetting *setting, unsigned int track_name_hash, ZPluginSlotType slot_type, int slot, GError **error)
Creates/initializes a plugin and its internal plugin (LV2, etc.) using the given setting.
NONNULL bool plugin_is_enabled(Plugin *self, bool check_track)
Returns whether the plugin is enabled.
NONNULL void plugin_set_track_and_slot(Plugin *pl, unsigned int track_name_hash, ZPluginSlotType slot_type, int slot)
Sets the channel and slot on the plugin and its ports.
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.
ZPluginSlotType
NONNULL void plugin_move_automation(Plugin *pl, Track *prev_track, Track *track, ZPluginSlotType new_slot_type, int new_slot)
Moves the Plugin's automation from one Channel to another.
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_move(Plugin *pl, Track *track, ZPluginSlotType slot_type, int slot, bool confirm_overwrite, bool fire_events)
Moves the plugin to the given slot in the given channel.
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_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 void plugin_generate_automation_tracks(Plugin *plugin, Track *track)
Generates automatables for the plugin.
uint32_t nframes_t
Frame count.
Definition types.h:35
Plugin identifier.
Plugin preset.
Plugin settings.
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:138
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:74
guint update_ui_source_id
ID of GSource (if > 0).
Definition plugin.h:238
ModulatorWidget * modulator_widget
Modulator widget, if modulator.
Definition plugin.h:231
int state_changed_event_sent
Set to true to avoid sending multiple ET_PLUGIN_STATE_CHANGED for the same plugin.
Definition plugin.h:248
Port * enabled
Control for plugin enabled, for convenience.
Definition plugin.h:109
Track * track
Pointer to owner track, if any.
Definition plugin.h:254
GtkWindow * window
The Plugin's window.
Definition plugin.h:207
bool instantiation_failed
Set to true if instantiation failed and the plugin will be treated as disabled.
Definition plugin.h:154
bool instantiated
Whether the plugin is currently instantiated or not.
Definition plugin.h:150
GtkBox * ev_box
The GdkWindow of this widget should be somewhere inside Plugin::window and will be used for wrapping ...
Definition plugin.h:212
float ui_update_hz
Update frequency of the UI, in Hz (times per second).
Definition plugin.h:174
nframes_t latency
Latency reported by the Lv2Plugin, if any, in samples.
Definition plugin.h:147
gulong destroy_window_id
ID of the destroy signal for Plugin::window so that we can deactivate before freeing the plugin.
Definition plugin.h:221
Port ** out_ports
Outgoing ports.
Definition plugin.h:100
Port * own_enabled_port
Whether the plugin has a custom "enabled" port (LV2).
Definition plugin.h:118
PluginSetting * setting
Setting this plugin was instantiated with.
Definition plugin.h:83
Port * l_out
Instrument left stereo output, for convenience.
Definition plugin.h:133
Port * gain
Control for plugin gain, for convenience.
Definition plugin.h:125
bool activated
Whether the plugin is currently activated or not.
Definition plugin.h:157
CarlaNativePlugin * carla
Pointer to Carla native plugin.
Definition plugin.h:80
GtkBox * vbox
Vbox containing the above ev_box for wrapping, or used for packing generic UI controls.
Definition plugin.h:216
bool deleting
Whether the plugin is currently being deleted.
Definition plugin.h:191
bool is_function
Whether the plugin is used for functions.
Definition plugin.h:251
MixerSelections * ms
Pointer to owner selections, if any.
Definition plugin.h:257
char * state_dir
State directory (only basename).
Definition plugin.h:187
Port * midi_in_port
Cache.
Definition plugin.h:97
int ui_instantiated
Whether the UI has finished instantiating.
Definition plugin.h:171
WrappedObjectWithChangeSignal * gobj
Used in Gtk.
Definition plugin.h:260
bool deactivating
Temporary variable to check if plugin is currently undergoing deactivation.
Definition plugin.h:242
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:226
GtkWidget * active_preset_item
Active preset item, if wrapped or generic UI.
Definition plugin.h:195
Port ** in_ports
Ports coming in as input.
Definition plugin.h:86
float ui_scale_factor
Scale factor for drawing UIs in scale of the monitor.
Definition plugin.h:177
bool visible
Whether plugin UI is opened or not.
Definition plugin.h:144
Must ONLY be created via port_new()
Definition port.h:139
Contains all of the info that will be serialized into a project file.
Definition project.h:146
Track to be inserted into the Project's Tracklist.
Definition track.h:177
A GObject-ified normal C object with a signal that interested parties can listen to for changes.
Custom types.