6#include "zrythm-config.h"
12#include "gui/dsp/port.h"
13#include "gui/dsp/port_span.h"
14#include "gui/dsp/track_fwd.h"
15#include "plugins/plugin_configuration.h"
16#include "plugins/plugin_descriptor.h"
17#include "plugins/plugin_slot.h"
20namespace zrythm::gui::old_dsp::plugins
45 using PluginSlotType = zrythm::plugins::PluginSlotType;
46 using PluginSlotNo = PluginSlot::SlotNo;
49 using PluginCategory = zrythm::plugins::PluginCategory;
53 utils::UuidIdentifiablObjectResolver<TrackPtrVariant, TrackUuid>;
103 void add_preset (
Preset &&preset);
119 constexpr static auto DEFAULT_BANK_URI =
"https://lv2.zrythm.org#default-bank";
120 constexpr static auto INIT_PRESET_URI =
"https://lv2.zrythm.org#init-preset";
126 constexpr static float MAX_REFRESH_RATE = 121.f;
132 constexpr static float MAX_SCALE_FACTOR = 4.f;
137 PluginDescriptor &get_descriptor () {
return *
setting_->descr_; }
144 static Plugin * from_variant (
const auto &variant)
146 return std::visit ([&] (
auto &&pl) -> Plugin * {
return pl; }, variant);
149 static auto name_projection (
const auto &var)
151 return std::visit ([&] (
auto &&val) {
return val->get_name (); }, var);
154 auto get_input_port_span ()
const {
return PortSpan{
in_ports_ }; }
155 auto get_output_port_span ()
const {
return PortSpan{
out_ports_ }; }
166 bool is_in_active_project ()
const override;
175 const dsp::PortIdentifier::PortUuid &port_uuid,
234 auto get_slot_type ()
const
237 assert (slot.has_value ());
238 if (slot->has_slot_index ())
240 return slot->get_slot_with_index ().first;
243 return slot->get_slot_type_only ();
266 std::optional<PortPtrVariant>
284 std::optional<fs::path> abs_state_dir);
319 std::optional<TrackPtrVariant> get_track ()
const;
321 void set_track (
const TrackUuid &track_id)
323 track_id_ = track_id;
327 TrackUuid get_track_id ()
const
329 assert (has_track ());
333 bool has_track ()
const {
return track_id_.has_value (); }
366 auto get_slot () const -> std::optional<PluginSlot>;
375 utils::Utf8String generate_window_title () const;
382 bool is_selected ()
const {
return selected_; }
384 void set_selected (
bool selected) {
selected_ = selected; }
394 void select (
bool select,
bool exclusive);
405 void set_enabled (
bool enabled,
bool fire_events);
424 void set_selected_bank_from_index (
int idx);
426 void set_selected_preset_from_index (
int idx);
488 std::optional<utils::Utf8String> uri,
504 void set_stereo_outs_and_midi_in ();
505 void set_enabled_and_gain ();
507 void set_port_index (PortUuidReference port_id);
509 virtual void populate_banks () = 0;
514 virtual void set_selected_preset_from_index_impl (
int idx) = 0;
516 virtual void cleanup_impl () = 0;
525 virtual void instantiate_impl (
bool loading,
bool use_state_file) = 0;
539 save_state (
bool is_backup, std::optional<fs::path> abs_state_dir) = 0;
545 virtual void open_custom_ui (
bool show) = 0;
547 virtual void activate_impl (
bool activate =
true) = 0;
556 virtual void close () = 0;
565 Plugin (PortRegistry &port_registry,
const PluginConfiguration &setting);
568 static constexpr auto kTrackIdKey =
"trackId"sv;
569 static constexpr auto kSettingKey =
"setting"sv;
570 static constexpr auto kInPortsKey =
"inPorts"sv;
571 static constexpr auto kOutPortsKey =
"outPorts"sv;
572 static constexpr auto kBanksKey =
"banks"sv;
573 static constexpr auto kSelectedBankKey =
"selectedBank"sv;
574 static constexpr auto kSelectedPresetKey =
"selectedPreset"sv;
575 static constexpr auto kVisibleKey =
"visible"sv;
576 static constexpr auto kStateDirectoryKey =
"stateDir"sv;
577 friend void to_json (nlohmann::json &j,
const Plugin &p)
579 to_json (j,
static_cast<const UuidIdentifiableObject &
> (p));
580 j[kTrackIdKey] = p.track_id_;
584 j[kBanksKey] = p.banks_;
585 j[kSelectedBankKey] = p.selected_bank_;
586 j[kSelectedPresetKey] = p.selected_preset_;
590 friend void from_json (
const nlohmann::json &j,
Plugin &p)
592 from_json (j,
static_cast<UuidIdentifiableObject &
> (p));
593 j.at (kTrackIdKey).get_to (p.track_id_);
594 j.at (kSettingKey).get_to (p.
setting_);
597 j.at (kBanksKey).get_to (p.banks_);
598 j.at (kSelectedBankKey).get_to (p.selected_bank_);
599 j.at (kSelectedPresetKey).get_to (p.selected_preset_);
600 j.at (kVisibleKey).get_to (p.
visible_);
601 j.at (kStateDirectoryKey).get_to (p.
state_dir_);
606 std::optional<TrackResolver> track_resolver_;
608 std::optional<TrackUuid> track_id_;
617 std::vector<ControlPort *> ctrl_in_ports_;
618 std::vector<AudioPort *> audio_in_ports_;
619 std::vector<CVPort *> cv_in_ports_;
620 std::vector<MidiPort *> midi_in_ports_;
657 std::vector<Bank> banks_;
741class CarlaNativePlugin;
743using PluginVariant = std::variant<CarlaNativePlugin>;
744using PluginPtrVariant = to_pointer_variant<PluginVariant>;
745using PluginUniquePtrVariant = to_unique_ptr_variant<PluginVariant>;
747using PluginRegistryRef = std::reference_wrapper<PluginRegistry>;
754 const nlohmann::json &j,
755 gui::old_dsp::plugins::PluginRegistry ®istry);
The Port class represents a port in the audio processing graph.
Interface for objects that can be processed in the DSP graph.
Struct used to identify Ports in the project.
This class provides the core functionality for managing a plugin, including creating/initializing the...
Configuration for instantiating a plugin descriptor.
The PluginDescriptor class provides a set of static utility functions and member functions to work wi...
ProtocolType
Plugin protocol.
A registry that owns and manages objects identified by a UUID.
Lightweight UTF-8 string wrapper with safe conversions.
Base class for objects that need to be uniquely identified by UUID.
A reference-counted RAII wrapper for a UUID in a registry.
void close_ui()
Process hide ui.
ControlPort * own_enabled_port_
Whether the plugin has a custom "enabled" port (LV2).
void process_passthrough(EngineProcessTimeInfo time_nfo)
Processes the plugin by passing through the input to its output.
std::vector< PortUuidReference > in_ports_
Ports coming in as input.
utils::Utf8String uri_
URI if LV2.
std::atomic< bool > state_changed_event_sent_
Set to true to avoid sending multiple ET_PLUGIN_STATE_CHANGED for the same plugin.
int idx_
Index in bank, or -1 if this is used for a bank.
void cleanup()
Cleans up resources of an instantiated but not activated plugin.
Bank * add_bank_if_not_exists(std::optional< utils::Utf8String > uri, const utils::Utf8String &name)
Adds a bank to the plugin's list and returns a reference to it.
void update_automatables()
(re)Generates automatables for the plugin.
bool instantiated_
Latency reported by the Lv2Plugin, if any, in samples.
void add_in_port(const PortUuidReference &port_id)
Adds an in port to the plugin's list and returns a reference to it.
void remove_ats_from_automation_tracklist(bool free_ats, bool fire_events)
Removes the automation tracks associated with this plugin from the automation tracklist in the corres...
bool is_function_
Whether the plugin is used for functions.
void update_identifier()
To be called when changes to the plugin identifier were made, so we can update all children recursive...
utils::Utf8String uri_
URI if LV2.
static constexpr float MIN_REFRESH_RATE
UI refresh rate limits.
utils::Utf8String name_
Human readable name.
std::vector< Preset > presets_
Presets in this bank.
bool deactivating_
Temporary variable to check if plugin is currently undergoing deactivation.
ControlPort * get_enabled_port()
Gets the enable/disable port for this plugin.
int carla_program_
Carla program index.
void set_port_metadata_from_owner(dsp::PortIdentifier &id, PortRange &range) const override
Function that will be called by the Port to update the identifier's relevant members based on this po...
Plugin(PortRegistry &port_registry, const PluginConfiguration &setting)
Creates/initializes a plugin and its internal plugin (LV2, etc.) using the given setting.
void copy_members_from(Plugin &other)
void connect_to_plugin(Plugin &dest)
Connect the output Ports of the given source Plugin to the input Ports of the given destination Plugi...
void init_loaded()
Initializes a plugin after deserialization.
ControlPort * enabled_
Control for plugin enabled, for convenience.
bool selected_
Whether selected in the slot owner (mixer for example).
utils::Utf8String get_node_name() const override
Returns a human friendly name of the node.
std::unique_ptr< PluginConfiguration > setting_
Setting this plugin was instantiated with.
std::vector< PortUuidReference > out_ports_
Outgoing ports.
void open_ui()
Process show ui.
void delete_state_files()
Deletes any state files associated with this plugin.
bool is_enabled(bool check_track) const
Returns whether the plugin is enabled.
void instantiate()
Instantiates the plugin (e.g.
ulong close_request_id_
ID of the close-request signal for Plugin.window so that we can deactivate before freeing the plugin.
void prepare_process()
Updates the plugin's latency.
static fs::path get_abs_state_dir(const fs::path &plugin_state_dir, bool is_backup)
Constructs the absolute path to the plugin state dir based on the given relative path given.
void append_ports(std::vector< Port * > &ports)
Appends this plugin's ports to the given vector.
PluginUuid plugin_id_
Plugin identifier.
int bank_idx_
Bank index in plugin.
void disconnect()
To be called immediately when a channel or plugin is deleted.
float ui_update_hz_
Update frequency of the UI, in Hz (times per second).
bool should_bounce_to_master(utils::audio::BounceStep step) const override
Whether the port should add its data to the master output when bouncing.
AudioPort * l_out_
Instrument left stereo output, for convenience.
ulong destroy_window_id_
ID of the destroy signal for Plugin.window so that we can deactivate before freeing the plugin.
float ui_scale_factor_
Scale factor for drawing UIs in scale of the monitor.
bool instantiation_failed_
Set to true if instantiation failed and the plugin will be treated as disabled.
void ensure_state_dir(bool is_backup)
Ensures the state dir exists or creates it.
Port * get_port_in_same_group(const Port &port)
Finds the corresponding port in the same port group (eg, if this is left, find right and vice versa).
MidiPort * midi_in_port_
Cache.
bool visible_
Whether plugin UI is opened or not.
bool validate() const
Verifies that the plugin identifiers are valid.
void copy_state_dir(const Plugin &src, bool is_backup, std::optional< fs::path > abs_state_dir)
Copies the state directory from the given source plugin to this plugin's state directory.
auto get_slot() const -> std::optional< PluginSlot >
Returns the slot this number is inserted at in the owner.
void set_ui_refresh_rate()
Sets the UI refresh rate on the Plugin.
fs::path state_dir_
State directory (only basename).
void activate(bool activate=true)
Activates or deactivates the plugin.
bool activated_
Whether the plugin is currently activated or not.
ControlPort * gain_
Control for plugin gain, for convenience.
void set_caches()
Sets caches for processing.
utils::Utf8String name_
Human readable name.
uint update_ui_source_id_
ID of GSource (if > 0).
fs::path get_abs_state_dir(bool is_backup, bool create_if_not_exists)
Returns the state dir as an absolute path.
void on_control_change_event(const dsp::PortIdentifier::PortUuid &port_uuid, const dsp::PortIdentifier &id, float val) override
Will be called when a control port's value changes.
void add_out_port(const PortUuidReference &port_id)
Adds an out port to the plugin's list and returns a reference to it.
bool deleting_
Whether the plugin is currently being deleted.
void expose_ports(AudioEngine &engine, bool expose, bool inputs, bool outputs)
Exposes or unexposes plugin ports to the backend.
std::optional< PortPtrVariant > get_port_by_symbol(const utils::Utf8String &sym)
Gets a port by its symbol.
void process_block(EngineProcessTimeInfo time_nfo) override
Process plugin.
static constexpr float MIN_SCALE_FACTOR
UI scale factor limits.
fs::path get_abs_state_dir(bool is_backup) const
Simply gets the absolute state directory path, without attempting to create it.
bool is_auditioner() const
Whether the plugin is used for MIDI auditioning in SampleProcessor.
std::string print() const
Prints the plugin to string.
void disconnect_from_plugin(Plugin &dest)
Disconnect the automatic connections from the given source Plugin to the given destination Plugin.
Common struct to pass around during processing to avoid repeating the data in function arguments.
Wrapper around std::optional<std::reference_wrapper<T>> that provides a more convenient API.
A plugin bank containing presets.