Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
channel_send.h
1// SPDX-FileCopyrightText: © 2020-2021, 2024-2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "dsp/audio_port.h"
7#include "dsp/midi_port.h"
8#include "dsp/parameter.h"
9#include "dsp/port.h"
10#include "dsp/processor_base.h"
11#include "utils/icloneable.h"
12
13namespace zrythm::structure::tracks
14{
15
22class ChannelSend : public QObject, public dsp::ProcessorBase
23{
24 Q_OBJECT
25 Q_PROPERTY (
26 zrythm::dsp::ProcessorParameter * amountParam READ amountParam CONSTANT)
27 Q_PROPERTY (
28 zrythm::dsp::ProcessorParameter * enabledParam READ enabledParam CONSTANT)
29 Q_PROPERTY (
30 QVariant destinationPort READ destinationPort WRITE setDestinationPort
31 NOTIFY destinationPortChanged)
32 QML_ELEMENT
33 QML_UNCREATABLE ("")
34
35 struct ChannelSendProcessingCaches
36 {
37 dsp::ProcessorParameter * amount_param_{};
38 dsp::ProcessorParameter * enabled_param_{};
39 std::vector<dsp::AudioPort *> audio_ins_rt_;
40 std::vector<dsp::AudioPort *> audio_outs_rt_;
41 dsp::MidiPort * midi_in_rt_{};
42 dsp::MidiPort * midi_out_rt_{};
43 };
44
45public:
51 dsp::PortType signal_type,
52 int slot,
53 bool is_prefader,
54 QObject * parent = nullptr);
55 Z_DISABLE_COPY_MOVE (ChannelSend)
56 ~ChannelSend () override;
57
58 // ============================================================================
59 // QML Interface
60 // ============================================================================
61
62 /**
63 * @brief Send amount (amplitude), 0 to 2 for audio, velocity multiplier for
64 * MIDI.
65 */
67 {
68 return get_parameters ().front ().get_object_as<dsp::ProcessorParameter> ();
69 }
70
81 QVariant destinationPort () const;
82 void setDestinationPort (const QVariant &port);
83
84 Q_SIGNAL void destinationPortChanged ();
85
86 // ============================================================================
87
88 // ============================================================================
89 // ProcessorBase Interface
90 // ============================================================================
91
93 EngineProcessTimeInfo time_nfo,
94 const dsp::ITransport &transport,
95 const dsp::TempoMap &tempo_map) noexcept override;
96
97 void custom_prepare_for_processing (
98 const dsp::graph::GraphNode * node,
99 units::sample_rate_t sample_rate,
100 nframes_t max_block_length) override;
101
102 void custom_release_resources () override;
103
104 // ============================================================================
105
106 bool is_prefader () const { return is_prefader_; }
107 bool is_audio () const { return signal_type_ == dsp::PortType::Audio; }
108 bool is_midi () const { return signal_type_ == dsp::PortType::Midi; }
109
110 dsp::AudioPort &get_stereo_in_port () const
111 {
112 assert (is_audio ());
113 return *get_input_ports ().at (0).get_object_as<dsp::AudioPort> ();
114 }
115 dsp::MidiPort &get_midi_in_port () const
116 {
117 assert (is_midi ());
118 return *get_input_ports ().front ().get_object_as<dsp::MidiPort> ();
119 }
120 dsp::AudioPort &get_stereo_out_port () const
121 {
122 assert (is_audio ());
123 return *get_output_ports ().front ().get_object_as<dsp::AudioPort> ();
124 }
125 dsp::MidiPort &get_midi_out_port () const
126 {
127 assert (is_midi ());
128 return *get_output_ports ().front ().get_object_as<dsp::MidiPort> ();
129 }
134 [[nodiscard]] auto destination_port () const { return destination_port_; }
135
143 void set_destination_port (dsp::PortUuidReference port);
153 bool has_destination () const { return destination_port_.has_value (); }
154
155private:
156 static constexpr auto kSignalTypeKey = "signalType"sv;
157 static constexpr auto kIsPrefaderKey = "isPrefader"sv;
158 static constexpr auto kDestinationPortKey = "destinationPort"sv;
159 friend void to_json (nlohmann::json &j, const ChannelSend &p);
160 friend void from_json (const nlohmann::json &j, ChannelSend &p);
161
162 friend void init_from (
163 ChannelSend &obj,
164 const ChannelSend &other,
165 utils::ObjectCloneType clone_type);
166
167private:
168 dsp::PortType signal_type_;
169
173 bool is_prefader_{};
174
180 std::optional<dsp::PortUuidReference> destination_port_;
181
182 // Processing caches
183 std::unique_ptr<ChannelSendProcessingCaches> processing_caches_;
184};
185
186} // namespace zrythm::structure::tracks
Audio port specifics.
Definition audio_port.h:25
Interface for transport.
Definition itransport.h:17
MIDI port specifics.
Definition midi_port.h:22
A base class for processors in the DSP graph.
Processor parameter that accepts automation and modulation sources and integrates with QML and the DS...
Definition parameter.h:220
Represents a node in a DSP graph.
Definition graph_node.h:131
auto destination_port() const
Returns the destination port reference, if set.
dsp::ProcessorParameter * amountParam() const
Send amount (amplitude), 0 to 2 for audio, velocity multiplier for MIDI.
void set_destination_port(dsp::PortUuidReference port)
Sets the destination port.
dsp::ProcessorParameter * enabledParam() const
Whether this send is enabled.
void custom_process_block(EngineProcessTimeInfo time_nfo, const dsp::ITransport &transport, const dsp::TempoMap &tempo_map) noexcept override
Custom processor logic after processing all owned parameters.
QVariant destinationPort() const
QML accessor for destination port.
bool has_destination() const
Checks if this send has a destination configured.
void clear_destination_port()
Clears the destination port.
ChannelSend(dsp::ProcessorBase::ProcessorBaseDependencies dependencies, dsp::PortType signal_type, int slot, bool is_prefader, QObject *parent=nullptr)
uint32_t nframes_t
Frame count.
Definition types.h:58
Common struct to pass around during processing to avoid repeating the data in function arguments.
Definition types.h:133