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-2025 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/processor_base.h"
10#include "utils/icloneable.h"
11
12namespace zrythm::structure::tracks
13{
14
20class ChannelSend : public QObject, public dsp::ProcessorBase
21{
22 Q_OBJECT
23 Q_PROPERTY (
24 zrythm::dsp::ProcessorParameter * amountParam READ amountParam CONSTANT)
25 QML_ELEMENT
26 QML_UNCREATABLE ("")
27
28 struct ChannelSendProcessingCaches
29 {
30 dsp::ProcessorParameter * amount_param_{};
31 std::vector<dsp::AudioPort *> audio_ins_rt_;
32 std::vector<dsp::AudioPort *> audio_outs_rt_;
33 dsp::MidiPort * midi_in_rt_{};
34 dsp::MidiPort * midi_out_rt_{};
35 };
36
37public:
43 dsp::PortType signal_type,
44 int slot,
45 bool is_prefader,
46 QObject * parent = nullptr);
47 Z_DISABLE_COPY_MOVE (ChannelSend)
48 ~ChannelSend () override;
49
50 // ============================================================================
51 // QML Interface
52 // ============================================================================
53
57 */
59 {
60 return get_parameters ().front ().get_object_as<dsp::ProcessorParameter> ();
61 }
62
63 // ============================================================================
64
65 // ============================================================================
66 // ProcessorBase Interface
67 // ============================================================================
70 EngineProcessTimeInfo time_nfo,
71 const dsp::ITransport &transport) noexcept override;
72
73 void custom_prepare_for_processing (
74 const dsp::graph::GraphNode * node,
75 units::sample_rate_t sample_rate,
76 nframes_t max_block_length) override;
77
78 void custom_release_resources () override;
79
80 // ============================================================================
81
82 bool is_prefader () const { return is_prefader_; }
83 bool is_audio () const { return signal_type_ == dsp::PortType::Audio; }
84 bool is_midi () const { return signal_type_ == dsp::PortType::Midi; }
85
86 dsp::AudioPort &get_stereo_in_port () const
87 {
88 assert (is_audio ());
89 return *get_input_ports ().at (0).get_object_as<dsp::AudioPort> ();
90 }
91 dsp::MidiPort &get_midi_in_port () const
92 {
93 assert (is_midi ());
94 return *get_input_ports ().front ().get_object_as<dsp::MidiPort> ();
95 }
96 dsp::AudioPort &get_stereo_out_port () const
97 {
98 assert (is_audio ());
99 return *get_output_ports ().front ().get_object_as<dsp::AudioPort> ();
100 }
101 dsp::MidiPort &get_midi_out_port () const
102 {
103 assert (is_midi ());
104 return *get_output_ports ().front ().get_object_as<dsp::MidiPort> ();
105 }
106
107private:
108 static constexpr auto kSignalTypeKey = "signalType"sv;
109 static constexpr auto kIsPrefaderKey = "isPrefader"sv;
110 friend void to_json (nlohmann::json &j, const ChannelSend &p)
111 {
112 to_json (j, static_cast<const dsp::ProcessorBase &> (p));
113 j[kSignalTypeKey] = p.signal_type_;
114 j[kIsPrefaderKey] = p.is_prefader_;
115 }
116 friend void from_json (const nlohmann::json &j, ChannelSend &p);
117
118 friend void init_from (
119 ChannelSend &obj,
120 const ChannelSend &other,
121 utils::ObjectCloneType clone_type);
122
123private:
124 dsp::PortType signal_type_;
125
129 bool is_prefader_{};
130
131 // Processing caches
132 std::unique_ptr<ChannelSendProcessingCaches> processing_caches_;
133};
134
135} // 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:225
Represents a node in a DSP graph.
Definition graph_node.h:129
dsp::ProcessorParameter * amountParam() const
Send amount (amplitude), 0 to 2 for audio, velocity multiplier for MIDI.
void custom_process_block(EngineProcessTimeInfo time_nfo, const dsp::ITransport &transport) noexcept override
Custom processor logic after processing all owned parameters.
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