Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
channel.h
1// SPDX-FileCopyrightText: © 2018-2022, 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "dsp/fader.h"
7#include "dsp/passthrough_processors.h"
8#include "plugins/plugin_group.h"
9#include "structure/tracks/channel_send.h"
10#include "utils/icloneable.h"
11
12namespace zrythm::structure::tracks
13{
14
15class ChannelMidiPassthroughProcessor final
16 : public QObject,
18{
19 Q_OBJECT
20 QML_ELEMENT
21 QML_UNCREATABLE ("")
22
23public:
24 ChannelMidiPassthroughProcessor (
26 QObject * parent = nullptr);
27};
28
29class ChannelAudioPassthroughProcessor final
30 : public QObject,
32{
33 Q_OBJECT
34 QML_ELEMENT
35 QML_UNCREATABLE ("")
36
37public:
38 ChannelAudioPassthroughProcessor (
40 QObject * parent = nullptr);
41};
42
56class Channel : public QObject
57{
58 Q_OBJECT
59 QML_ELEMENT
60 Q_PROPERTY (zrythm::dsp::Fader * fader READ fader CONSTANT)
61 Q_PROPERTY (QVariant preFader READ preFader CONSTANT)
62 Q_PROPERTY (zrythm::dsp::AudioPort * audioOutPort READ audioOutPort CONSTANT)
63 Q_PROPERTY (zrythm::dsp::MidiPort * midiOut READ getMidiOut CONSTANT)
64 Q_PROPERTY (zrythm::plugins::PluginGroup * inserts READ inserts CONSTANT)
65 Q_PROPERTY (zrythm::plugins::PluginGroup * midiFx READ midiFx CONSTANT)
66 Q_PROPERTY (
67 zrythm::plugins::PluginGroup * instruments READ instruments CONSTANT)
68 QML_UNCREATABLE ("")
69
70public:
71 using PortType = zrythm::dsp::PortType;
72 using Plugin = plugins::Plugin;
73 using PluginDescriptor = zrythm::plugins::PluginDescriptor;
74 using PluginPtrVariant = plugins::PluginPtrVariant;
75 using PluginUuid = Plugin::Uuid;
76
77 using NameProvider = std::function<utils::Utf8String ()>;
78
79public:
80 explicit Channel (
81 plugins::PluginRegistry &plugin_registry,
83 dsp::PortType signal_type,
84 NameProvider name_provider,
85 bool hard_limit_fader_output,
86 dsp::Fader::ShouldBeMutedCallback should_be_muted_cb,
87 QObject * parent = nullptr);
88
89 // ============================================================================
90 // QML Interface
91 // ============================================================================
92
93 dsp::Fader * fader () const { return fader_.get (); }
94 QVariant preFader () const
95 {
96 return is_midi () ? QVariant::fromValue (midi_prefader_.get ())
97 : QVariant::fromValue (audio_prefader_.get ());
98 }
99 dsp::AudioPort * audioOutPort () const
100 {
101 return is_audio ()
102 ? std::addressof (audio_postfader_->get_audio_out_port ())
103 : nullptr;
104 }
105 dsp::MidiPort * getMidiOut () const
106 {
107 return is_midi () ? std::addressof (midi_postfader_->get_midi_out_port (0))
108 : nullptr;
109 }
110 plugins::PluginGroup * midiFx () const { return midi_fx_.get (); }
111 plugins::PluginGroup * inserts () const { return inserts_.get (); }
112 plugins::PluginGroup * instruments () const { return instruments_.get (); }
113
114 // ============================================================================
115
116 bool is_midi () const { return signal_type_ == PortType::Midi; }
117 bool is_audio () const { return signal_type_ == PortType::Audio; }
118
124 void get_plugins (std::vector<plugins::PluginPtrVariant> &plugins) const;
125
132 plugins::PluginUuidReference remove_plugin (plugins::Plugin::Uuid id);
133
134 friend void init_from (
135 Channel &obj,
136 const Channel &other,
137 utils::ObjectCloneType clone_type);
138
139 dsp::Fader &get_fader () const { return *fader_; }
140 auto &get_midi_pre_fader () const { return *midi_prefader_; }
141 auto &get_audio_pre_fader () const { return *audio_prefader_; }
142 auto &get_midi_post_fader () const { return *midi_postfader_; }
143 auto &get_audio_post_fader () const { return *audio_postfader_; }
144
145 auto &pre_fader_sends () const { return prefader_sends_; }
146 auto &post_fader_sends () const { return postfader_sends_; }
147
148private:
149 static constexpr auto kMidiFxKey = "midiFx"sv;
150 static constexpr auto kInstrumentsKey = "instruments"sv;
151 static constexpr auto kInsertsKey = "inserts"sv;
152 static constexpr auto kPreFaderSendsKey = "preFaderSends"sv;
153 static constexpr auto kPostFaderSendsKey = "postFaderSends"sv;
154 static constexpr auto kMidiPrefaderKey = "midiPrefader"sv;
155 static constexpr auto kAudioPrefaderKey = "audioPrefader"sv;
156 static constexpr auto kFaderKey = "fader"sv;
157
158 friend void to_json (nlohmann::json &j, const Channel &c)
159 {
160 j[kMidiFxKey] = *c.midi_fx_;
161 j[kInsertsKey] = *c.inserts_;
162 j[kPreFaderSendsKey] = c.prefader_sends_;
163 j[kPostFaderSendsKey] = c.postfader_sends_;
164 j[kInstrumentsKey] = *c.instruments_;
165 j[kMidiPrefaderKey] = c.midi_prefader_;
166 j[kAudioPrefaderKey] = c.audio_prefader_;
167 j[kFaderKey] = c.fader_;
168 }
169 friend void from_json (const nlohmann::json &j, Channel &c);
170
171 dsp::ProcessorBase::ProcessorBaseDependencies dependencies () const
172 {
173 return dependencies_;
174 }
175
176private:
177 dsp::ProcessorBase::ProcessorBaseDependencies dependencies_;
178 plugins::PluginRegistry &plugin_registry_;
179
180 NameProvider name_provider_;
181
182 dsp::PortType signal_type_;
183
184 bool hard_limit_fader_output_;
185
191 utils::QObjectUniquePtr<plugins::PluginGroup> midi_fx_;
192
194 utils::QObjectUniquePtr<plugins::PluginGroup> instruments_;
195
197 utils::QObjectUniquePtr<plugins::PluginGroup> inserts_;
198
199 std::vector<utils::QObjectUniquePtr<ChannelSend>> prefader_sends_;
200 std::vector<utils::QObjectUniquePtr<ChannelSend>> postfader_sends_;
201
203 utils::QObjectUniquePtr<dsp::Fader> fader_;
204
210 utils::QObjectUniquePtr<ChannelMidiPassthroughProcessor> midi_prefader_;
211 utils::QObjectUniquePtr<ChannelAudioPassthroughProcessor> audio_prefader_;
212
219 utils::QObjectUniquePtr<ChannelMidiPassthroughProcessor> midi_postfader_;
220 utils::QObjectUniquePtr<ChannelAudioPassthroughProcessor> audio_postfader_;
221};
222
223}; // namespace zrythm::structure::tracks
Audio port specifics.
Definition audio_port.h:25
A Fader is a processor that is used for volume controls and pan.
Definition fader.h:21
std::function< bool(bool fader_solo_status)> ShouldBeMutedCallback
A callback to check if the fader should be muted based on various external factors (such as solo stat...
Definition fader.h:71
Processor that processes MIDI signals (passthrough by default).
MIDI port specifics.
Definition midi_port.h:22
The PluginDescriptor class provides a set of static utility functions and member functions to work wi...
A flexible container for plugins and nested plugin groups.
DSP processing plugin.
Definition plugin.h:30
void get_plugins(std::vector< plugins::PluginPtrVariant > &plugins) const
Returns all existing plugins in the channel.
plugins::PluginUuidReference remove_plugin(plugins::Plugin::Uuid id)
Removes the given plugin.
Lightweight UTF-8 string wrapper with safe conversions.
Definition utf8_string.h:38