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 sample_rate_t sample_rate,
75 nframes_t max_block_length) override;
76
77 void custom_release_resources () override;
78
79 // ============================================================================
80
81 bool is_prefader () const { return is_prefader_; }
82 bool is_audio () const { return signal_type_ == dsp::PortType::Audio; }
83 bool is_midi () const { return signal_type_ == dsp::PortType::Midi; }
84
85 dsp::AudioPort &get_stereo_in_port () const
86 {
87 assert (is_audio ());
88 return *get_input_ports ().at (0).get_object_as<dsp::AudioPort> ();
89 }
90 dsp::MidiPort &get_midi_in_port () const
91 {
92 assert (is_midi ());
93 return *get_input_ports ().front ().get_object_as<dsp::MidiPort> ();
94 }
95 dsp::AudioPort &get_stereo_out_port () const
96 {
97 assert (is_audio ());
98 return *get_output_ports ().front ().get_object_as<dsp::AudioPort> ();
99 }
100 dsp::MidiPort &get_midi_out_port () const
101 {
102 assert (is_midi ());
103 return *get_output_ports ().front ().get_object_as<dsp::MidiPort> ();
104 }
105
106private:
107 static constexpr auto kSignalTypeKey = "signalType"sv;
108 static constexpr auto kIsPrefaderKey = "isPrefader"sv;
109 friend void to_json (nlohmann::json &j, const ChannelSend &p)
110 {
111 to_json (j, static_cast<const dsp::ProcessorBase &> (p));
112 j[kSignalTypeKey] = p.signal_type_;
113 j[kIsPrefaderKey] = p.is_prefader_;
114 }
115 friend void from_json (const nlohmann::json &j, ChannelSend &p);
116
117 friend void init_from (
118 ChannelSend &obj,
119 const ChannelSend &other,
120 utils::ObjectCloneType clone_type);
121
122private:
123 dsp::PortType signal_type_;
124
128 bool is_prefader_{};
129
130 // Processing caches
131 std::unique_ptr<ChannelSendProcessingCaches> processing_caches_;
132};
133
134} // 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
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 sample_rate_t
Sample rate.
Definition types.h:61
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:136