6#include "zrythm-config.h"
8#include "dsp/channel.h"
9#include "gui/dsp/channel_send.h"
11#include "gui/dsp/fader.h"
12#include "gui/dsp/plugin.h"
13#include "gui/dsp/plugin_span.h"
14#include "gui/dsp/track.h"
15#include "utils/icloneable.h"
27static constexpr float MAX_FADER_AMP = 1.42f;
29struct PluginImportData;
47 Q_PROPERTY (
Fader * fader READ getFader CONSTANT)
48 Q_PROPERTY (
Fader * preFader READ getPreFader CONSTANT)
49 Q_PROPERTY (
AudioPort * leftAudioOut READ getLeftAudioOut CONSTANT)
50 Q_PROPERTY (
AudioPort * rightAudioOut READ getRightAudioOut CONSTANT)
51 Q_PROPERTY (
MidiPort * midiOut READ getMidiOut CONSTANT)
54 static constexpr auto STRIP_SIZE = zrythm::dsp::STRIP_SIZE;
55 using PortType = zrythm::dsp::PortType;
61 using PluginSlotType = zrythm::plugins::PluginSlotType;
62 using PluginPtrVariant = gui::old_dsp::plugins::PluginPtrVariant;
63 using PluginUuid = Plugin::Uuid;
66 friend struct PluginImportData;
79 TrackRegistry &track_registry,
80 PluginRegistry &plugin_registry,
81 PortRegistry &port_registry,
88 TrackRegistry &track_registry,
89 PluginRegistry &plugin_registry,
90 PortRegistry &port_registry)
91 :
Channel (track_registry, plugin_registry, port_registry, {})
96 auto &get_track_registry () {
return track_registry_; }
97 auto &get_track_registry ()
const {
return track_registry_; }
98 auto &get_plugin_registry () {
return plugin_registry_; }
99 auto &get_plugin_registry ()
const {
return plugin_registry_; }
100 auto &get_port_registry () {
return port_registry_; }
101 auto &get_port_registry ()
const {
return port_registry_; }
110 AudioPort * getLeftAudioOut ()
const
112 return stereo_out_left_id_.has_value ()
113 ? std::addressof (get_stereo_out_ports ().first)
116 AudioPort * getRightAudioOut ()
const
118 return stereo_out_left_id_.has_value ()
119 ? std::addressof (get_stereo_out_ports ().second)
122 MidiPort * getMidiOut ()
const
124 return midi_out_id_.has_value () ? std::addressof (get_midi_out_port ()) : nullptr;
135 bool is_in_active_project ()
const override;
145 MidiPort &get_midi_out_port ()
const
147 return *std::get<MidiPort *> (
midi_out_id_->get_object ());
149 std::pair<AudioPort &, AudioPort &> get_stereo_out_ports ()
const
151 auto * l = std::get<AudioPort *> (stereo_out_left_id_->get_object ());
152 auto * r = std::get<AudioPort *> (stereo_out_right_id_->get_object ());
173 std::optional<PluginSpan> plugins,
174 const PluginDescriptor * descr,
177 bool ask_if_overwrite);
212 PluginUuidReference plugin_id,
216 bool gen_automatables,
250 bool deleting_plugin);
287 std::optional<PluginPtrVariant> get_plugin_at_slot (PluginSlot slot)
const;
289 auto get_plugin_slot (
const PluginUuid &plugin_id)
const -> PluginSlot;
291 std::optional<PluginPtrVariant> get_plugin_from_id (PluginUuid
id)
const;
293 std::optional<PluginPtrVariant> get_instrument ()
const
346 void set_phase (
float phase);
348 float get_phase ()
const;
350 void set_balance_control (
float val);
357 float get_balance_control ()
const;
375 auto &get_sends ()
const {
return sends_; }
378 static constexpr auto kMidiFxKey =
"midiFx"sv;
379 static constexpr auto kInsertsKey =
"inserts"sv;
380 static constexpr auto kSendsKey =
"sends"sv;
381 static constexpr auto kInstrumentKey =
"instrument"sv;
382 static constexpr auto kPrefaderKey =
"prefader"sv;
383 static constexpr auto kFaderKey =
"fader"sv;
384 static constexpr auto kMidiOutKey =
"midiOut"sv;
385 static constexpr auto kStereoOutLKey =
"stereoOutL"sv;
386 static constexpr auto kStereoOutRKey =
"stereoOutR"sv;
387 static constexpr auto kOutputIdKey =
"outputId"sv;
388 static constexpr auto kTrackIdKey =
"trackId"sv;
389 static constexpr auto kExtMidiInputsKey =
"extMidiIns"sv;
390 static constexpr auto kAllMidiInputsKey =
"allMidiIns"sv;
391 static constexpr auto kMidiChannelsKey =
"midiChannels"sv;
392 static constexpr auto kAllMidiChannelsKey =
"allMidiChannels"sv;
393 static constexpr auto kExtStereoLInputsKey =
"extStereoLIns"sv;
394 static constexpr auto kAllStereoLInputsKey =
"allStereoLIns"sv;
395 static constexpr auto kExtStereoRInputsKey =
"extStereoRIns"sv;
396 static constexpr auto kAllStereoRInputsKey =
"allStereoRIns"sv;
397 static constexpr auto kWidthKey =
"width"sv;
399 friend void to_json (nlohmann::json &j,
const Channel &c)
401 j[kMidiFxKey] = c.midi_fx_;
402 j[kInsertsKey] = c.inserts_;
403 j[kSendsKey] = c.sends_;
404 j[kInstrumentKey] = c.instrument_;
405 j[kPrefaderKey] = c.prefader_;
406 j[kFaderKey] = c.fader_;
407 j[kMidiOutKey] = c.midi_out_id_;
408 j[kStereoOutLKey] = c.stereo_out_left_id_;
409 j[kStereoOutRKey] = c.stereo_out_right_id_;
410 j[kOutputIdKey] = c.output_track_uuid_;
411 j[kTrackIdKey] = c.track_uuid_;
412 if (!c.all_midi_ins_)
414 j[kExtMidiInputsKey] = c.ext_midi_ins_;
416 j[kAllMidiInputsKey] = c.all_midi_ins_;
417 if (!c.all_midi_channels_)
419 j[kMidiChannelsKey] = c.midi_channels_;
421 j[kAllMidiChannelsKey] = c.all_midi_channels_;
422 if (!c.all_stereo_l_ins_)
424 j[kExtStereoLInputsKey] = c.ext_stereo_l_ins_;
426 j[kAllStereoLInputsKey] = c.all_stereo_l_ins_;
427 if (!c.all_stereo_r_ins_)
429 j[kExtStereoRInputsKey] = c.ext_stereo_r_ins_;
431 j[kAllStereoRInputsKey] = c.all_stereo_r_ins_;
432 j[kWidthKey] = c.width_;
434 friend void from_json (
const nlohmann::json &j,
Channel &c);
439 void connect_no_prev_no_next (Plugin &pl);
444 void connect_no_prev_next (Plugin &pl, Plugin &next_pl);
449 void connect_prev_no_next (Plugin &prev_pl, Plugin &pl);
454 void connect_prev_next (Plugin &prev_pl, Plugin &pl, Plugin &next_pl);
459 void disconnect_no_prev_no_next (Plugin &pl);
464 void disconnect_no_prev_next (Plugin &pl, Plugin &next_pl);
469 void disconnect_prev_no_next (Plugin &prev_pl, Plugin &pl);
474 void disconnect_prev_next (Plugin &prev_pl, Plugin &pl, Plugin &next_pl);
482 void connect_plugin_to_prefader (Plugin &pl);
488 void disconnect_plugin_from_prefader (Plugin &pl);
490 void connect_plugins ();
502 void disconnect_plugin_from_strip (PluginSlot slot, Plugin &pl);
507 void disconnect_port_hardware_inputs (Port &port);
512 TrackRegistry &track_registry_;
513 PortRegistry &port_registry_;
514 PluginRegistry &plugin_registry_;
521 std::array<std::optional<PluginUuidReference>, STRIP_SIZE>
midi_fx_;
524 std::array<std::optional<PluginUuidReference>, STRIP_SIZE>
inserts_;
536 std::array<std::unique_ptr<ChannelSend>, STRIP_SIZE>
sends_;
611 std::optional<PortUuidReference> stereo_out_left_id_;
612 std::optional<PortUuidReference> stereo_out_right_id_;
Abstract class for a track that has a channel in the mixer.
A Fader is a processor that is used for volume controls and pan.
Abstract base class for a track that can be routed to.
Span of plugins that offers helper methods.
Represents a track in the project.
Port connections manager.
Struct used to identify Ports in the project.
std::array< std::optional< PluginUuidReference >, STRIP_SIZE > inserts_
The channel insert strip.
bool get_mono_compat_enabled()
Gets whether mono compatibility is enabled.
void init()
Initializes the Channel (performs logic that needs the object to be constructed).
bool all_midi_channels_
If true, the channel will accept MIDI messages from all MIDI channels.
void handle_plugin_import(const Plugin *pl, std::optional< PluginSpan > plugins, const PluginDescriptor *descr, PluginSlot slot, bool copy, bool ask_if_overwrite)
Handles import (paste/drop) of plugins or plugin descriptors or mixer selections.
bool all_stereo_r_ins_
If true, the channel will connect to all stereo R ins found.
ChannelTrack * track_
Owner track.
std::array< bool, 16 > midi_channels_
1 or 0 flags for each channel to enable it or disable it.
std::optional< PortUuidReference > midi_out_id_
MIDI output for sending MIDI signals to other destinations, such as other channels when directly rout...
std::array< std::optional< PluginUuidReference >, STRIP_SIZE > midi_fx_
The MIDI effect strip on instrument/MIDI tracks.
void paste_plugins_to_slot(PluginSpan plugins, PluginSlot slot)
Paste the selections starting at the slot in the given channel.
std::vector< std::unique_ptr< ExtPort > > ext_stereo_l_ins_
External audio L inputs that are currently connected to this channel as official inputs,...
std::optional< TrackUuid > output_track_uuid_
Whether or not output_pos corresponds to a Track or not.
void disconnect_channel()
Disconnects the channel from the processing chain and removes any plugins it contains.
std::optional< TrackUuid > track_uuid_
Track associated with this channel.
void add_balance_control(float pan)
Adds to (or subtracts from) the pan.
void handle_recording(long g_frames_start, nframes_t nframes)
Handles the recording logic inside the process cycle.
void process()
Perform processing of the audio signal.
void connect_channel(dsp::PortConnectionsManager &mgr, AudioEngine &engine)
Connects the channel's ports.
void select_all(PluginSlotType type, bool select)
Selects/deselects all plugins in the given slot type.
void reset_fader(bool fire_events)
Sets fader to 0.0.
int width_
Channel widget width - reserved for future use.
std::optional< PluginUuidReference > instrument_
The instrument plugin, if instrument track.
bool should_bounce_to_master(utils::audio::BounceStep step) const override
Whether the port should add its data to the master output when bouncing.
void set_track_ptr(ChannelTrack &track)
Set the track ptr to the channel and all its internals that reference a track (Plugin,...
void expose_ports_to_backend(AudioEngine &engine)
Exposes the channel's ports to the backend.
std::vector< std::unique_ptr< ExtPort > > ext_midi_ins_
External MIDI inputs that are currently connected to this channel as official inputs,...
Fader * fader_
The channel fader.
void append_ports(std::vector< Port * > &ports, bool include_plugins)
Appends all channel ports and optionally plugin ports to the array.
bool get_swap_phase()
Gets whether mono compatibility is enabled.
void reconnect_ext_input_ports(AudioEngine &engine)
Called when the input has changed for Midi, Instrument or Audio tracks.
std::array< std::unique_ptr< ChannelSend >, STRIP_SIZE > sends_
The sends strip.
PluginUuid remove_plugin_from_channel(PluginSlot slot, bool moving_plugin, bool deleting_plugin)
Removes a plugin at the given slot from the channel.
Channel(TrackRegistry &track_registry, PluginRegistry &plugin_registry, PortRegistry &port_registry, OptionalRef< ChannelTrack > track)
Main constructor used by the others.
std::vector< std::unique_ptr< ExtPort > > ext_stereo_r_ins_
External audio R inputs that are currently connected to this channel as official inputs,...
PluginPtrVariant add_plugin(PluginUuidReference plugin_id, PluginSlot slot, bool confirm, bool moving_plugin, bool gen_automatables, bool recalc_graph, bool pub_events)
Adds given plugin to given position in the strip.
void set_mono_compat_enabled(bool enabled, bool fire_events)
Sets whether mono compatibility is enabled.
AutomationTrack * get_automation_track(PortIdentifier::Flags port_flags) const
Convenience function to get the automation track of the given type for the channel.
bool all_stereo_l_ins_
If true, the channel will connect to all stereo L ins found.
void set_caches()
Sets caches for processing.
void get_plugins(std::vector< Plugin * > &pls)
Returns all existing plugins in the channel.
Fader * prefader_
Prefader.
void prepare_process(nframes_t nframes)
Prepares the channel for processing.
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 all_midi_ins_
If true, the channel will connect to all MIDI ins found.
void set_swap_phase(bool enabled, bool fire_events)
Sets whether mono compatibility is enabled.
Channel(TrackRegistry &track_registry, PluginRegistry &plugin_registry, PortRegistry &port_registry)
To be used when deserializing or cloning an existing identity.
This class provides the core functionality for managing a plugin, including creating/initializing the...
The PluginDescriptor class provides a set of static utility functions and member functions to work wi...
Lightweight UTF-8 string wrapper with safe conversions.
uint32_t nframes_t
Frame count.
@ Fader
0 to 1, suitable for drawing.
Wrapper around std::optional<std::reference_wrapper<T>> that provides a more convenient API.