6#include "dsp/port_connection.h"
7#include "gui/dsp/audio_port.h"
8#include "gui/dsp/control_port.h"
9#include "gui/dsp/midi_port.h"
10#include "gui/dsp/track.h"
11#include "plugins/plugin_slot.h"
12#include "utils/icloneable.h"
51 gui::old_dsp::plugins::Plugin::Uuid pl_id;
71 :
public ICloneable<ChannelSend>,
76 using PortType = dsp::PortType;
92 TrackRegistry &track_registry,
93 PortRegistry &port_registry,
95 :
ChannelSend (track_registry, port_registry, track, slot, true)
104 TrackRegistry &track_registry,
105 PortRegistry &port_registry)
106 :
ChannelSend (track_registry, port_registry, track, std::nullopt, false)
113 ChannelSend (TrackRegistry &track_registry, PortRegistry &port_registry)
114 :
ChannelSend (track_registry, port_registry, std::nullopt, std::nullopt, false)
123 TrackRegistry &track_registry,
124 PortRegistry &port_registry,
126 std::optional<int> slot,
130 auto &get_port_registry () {
return port_registry_; }
131 auto &get_port_registry ()
const {
return port_registry_; }
134 void init_loaded (ChannelTrack * track);
136 bool is_in_active_project ()
const override;
144 bool is_prefader ()
const
156 bool is_enabled ()
const;
158 bool is_empty ()
const {
return !is_enabled (); }
181 float get_amount_value ()
const {
return get_amount_port ().control_; }
207 void set_amount (
float amount);
209 std::pair<AudioPort &, AudioPort &> get_stereo_in_ports ()
const
216 auto * r = std::get<AudioPort *> (stereo_in_right_id_->get_object ());
219 MidiPort &get_midi_in_port ()
const
221 return *std::get<MidiPort *> (
midi_in_id_->get_object ());
223 std::pair<AudioPort &, AudioPort &> get_stereo_out_ports ()
const
227 throw ZrythmException (
"stereo_out_left_id_ not set");
230 auto * r = std::get<AudioPort *> (stereo_out_right_id_->get_object ());
233 MidiPort &get_midi_out_port ()
const
235 return *std::get<MidiPort *> (
midi_out_id_->get_object ());
237 ControlPort &get_amount_port ()
const
239 return *std::get<ControlPort *> (
amount_id_->get_object ());
241 ControlPort &get_enabled_port ()
const
243 return *std::get<ControlPort *> (
enabled_id_->get_object ());
263 void append_ports (std::vector<Port *> &ports);
271 std::vector<PortConnection *> &arr)
const;
273 void prepare_process (std::size_t block_length);
277 bool is_connected_to (std::pair<PortUuid, PortUuid> stereo)
const
279 return is_connected_to (stereo, std::nullopt);
281 bool is_connected_to (
const PortUuid &midi)
const
283 return is_connected_to (std::nullopt, midi);
291 bool is_audio ()
const {
return get_signal_type () == PortType::Audio; }
292 bool is_midi ()
const {
return get_signal_type () == PortType::Event; }
297 static constexpr auto kSlotKey =
"slot"sv;
298 static constexpr auto kAmountKey =
"amount"sv;
299 static constexpr auto kEnabledKey =
"enabled"sv;
300 static constexpr auto kIsSidechainKey =
"isSidechain"sv;
301 static constexpr auto kMidiInKey =
"midiIn"sv;
302 static constexpr auto kStereoInLKey =
"stereoInL"sv;
303 static constexpr auto kStereoInRKey =
"stereoInR"sv;
304 static constexpr auto kMidiOutKey =
"midiOut"sv;
305 static constexpr auto kStereoOutLKey =
"stereoOutL"sv;
306 static constexpr auto kStereoOutRKey =
"stereoOutR"sv;
307 static constexpr auto kTrackIdKey =
"trackId"sv;
308 friend void to_json (nlohmann::json &j,
const ChannelSend &p)
311 { kSlotKey, p.
slot_ },
317 { kStereoInRKey, p.stereo_in_right_id_ },
320 { kStereoOutRKey, p.stereo_out_right_id_ },
324 friend void from_json (
const nlohmann::json &j,
ChannelSend &p)
326 j.at (kSlotKey).get_to (p.
slot_);
332 j.at (kStereoInRKey).get_to (p.stereo_in_right_id_);
335 j.at (kStereoOutRKey).get_to (p.stereo_out_right_id_);
339 PortType get_signal_type ()
const;
341 void disconnect_midi ();
342 void disconnect_audio ();
344 void construct_for_slot (ChannelTrack &track,
int slot);
346 dsp::PortConnectionsManager * get_port_connections_manager ()
const;
351 bool is_connected_to (
352 std::optional<std::pair<PortUuid, PortUuid>> stereo,
353 std::optional<PortUuid> midi)
const;
356 PortRegistry &port_registry_;
357 TrackRegistry &track_registry_;
368 std::optional<PortUuidReference> stereo_in_right_id_;
383 std::optional<PortUuidReference> stereo_out_right_id_;
std::optional< PortUuidReference > midi_in_id_
MIDI input if MIDI send.
bool connect_midi(MidiPort &port, bool recalc_graph, bool validate)
Connects a send to a midi port.
std::optional< PortUuidReference > enabled_id_
Whether the send is currently enabled.
ChannelSend(ChannelTrack &track, TrackRegistry &track_registry, PortRegistry &port_registry)
To be used when deserializing.
bool connect_stereo(AudioPort &l, AudioPort &r, bool sidechain, bool recalc_graph, bool validate)
Connects a send to stereo ports.
TrackUuid track_id_
Pointer back to owner track.
void disconnect(bool recalc_graph)
Removes the connection at the given send.
int append_connection(const zrythm::dsp::PortConnectionsManager *mgr, std::vector< PortConnection * > &arr) const
Appends the connection(s), if non-empty, to the given array (if not nullptr) and returns the number o...
OptionalRef< ChannelTrack > track_
Use this if set (via the new identity constructo).
std::optional< PortUuidReference > midi_out_id_
MIDI output if MIDI send.
bool is_sidechain_
If the send is a sidechain.
ChannelSend * find_in_project() const
Finds the project send from a given send instance.
utils::Utf8String get_node_name() const override
Returns a human friendly name of the node.
Track * get_target_track()
Gets the target track.
int slot_
Slot index in the channel sends.
void set_amount_from_widget(float val)
Sets the amount from a widget amount (0.0-1.0).
utils::Utf8String get_dest_name() const
Get the name of the destination, or a placeholder text if empty.
ChannelTrack * get_track() const
Gets the owner track.
std::optional< PortUuidReference > stereo_in_left_id_
Stereo input if audio send.
void init_after_cloning(const ChannelSend &other, ObjectCloneType clone_type) override
Initializes the cloned object.
ChannelSend(ChannelTrack &track, TrackRegistry &track_registry, PortRegistry &port_registry, int slot)
To be used when creating a new (identity) ChannelSend.
std::optional< PortUuidReference > amount_id_
Send amount (amplitude), 0 to 2 for audio, velocity multiplier for MIDI.
void connect_to_owner()
Connects the ports to the owner track if not connected.
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...
bool is_target_sidechain()
Returns whether the channel send target is a sidechain port (rather than a target track).
ChannelSend(TrackRegistry &track_registry, PortRegistry &port_registry)
To be used when instantiating or cloning an existing identity.
float get_amount_for_widgets() const
Gets the amount to be used in widgets (0.0-1.0).
std::optional< PortUuidReference > stereo_out_left_id_
Stereo output if audio send.
Abstract class for a track that has a channel in the mixer.
Represents a track in the project.
A connection between two ports.
Port connections manager.
Struct used to identify Ports in the project.
Interface for objects that can be processed in the DSP graph.
Lightweight UTF-8 string wrapper with safe conversions.
Base class for exceptions in Zrythm.
constexpr int CHANNEL_SEND_POST_FADER_START_SLOT
The slot where post-fader sends begin (starting from 0).
ChannelSendTargetType
Target type.
@ Track
Send to track inputs.
@ PluginSidechain
Send to plugin sidechain inputs.
Send target (used in list views).
utils::Utf8String describe() const
Returns a string describing this target (track/plugin name/etc.).
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.