Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
hardware_processor.h
1// SPDX-FileCopyrightText: © 2020-2022, 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "gui/dsp/audio_port.h"
7#include "gui/dsp/ext_port.h"
8#include "gui/dsp/midi_port.h"
9#include "utils/icloneable.h"
10
16
17#define HW_IN_PROCESSOR (AUDIO_ENGINE->hw_in_processor_)
18#define HW_OUT_PROCESSOR (AUDIO_ENGINE->hw_out_processor_)
19
23class HardwareProcessor final
24 : public ICloneable<HardwareProcessor>,
26{
27public:
28 using PortFlow = zrythm::dsp::PortFlow;
29
30public:
31 // Rule of 0
32 HardwareProcessor () = default;
33
34 HardwareProcessor (bool input, AudioEngine * engine);
35
36 void init_loaded (AudioEngine * engine);
37
38 bool is_in_active_project () const;
39
46
53
59 template <typename T = Port> T * find_port (const utils::Utf8String &id);
60
64 void setup ();
65
71 void activate (bool activate);
72
76 void process (nframes_t nframes);
77
79
83 void
84 init_after_cloning (const HardwareProcessor &other, ObjectCloneType clone_type)
85 override;
86
87private:
88 static constexpr auto kIsInputKey = "isInput"sv;
89 static constexpr auto kExtAudioPortsKey = "extAudioPorts"sv;
90 static constexpr auto kExtMidiPortsKey = "extMidiPorts"sv;
91 static constexpr auto kAudioPortsKey = "audioPorts"sv;
92 static constexpr auto kMidiPortsKey = "midiPorts"sv;
93 friend void to_json (nlohmann::json &j, const HardwareProcessor &p)
94 {
95 j = nlohmann::json{
96 { kIsInputKey, p.is_input_ },
97 { kExtAudioPortsKey, p.ext_audio_ports_ },
98 { kExtMidiPortsKey, p.ext_midi_ports_ },
99 { kAudioPortsKey, p.audio_ports_ },
100 { kMidiPortsKey, p.midi_ports_ },
101 };
102 }
103 friend void from_json (const nlohmann::json &j, HardwareProcessor &p);
104
105 template <typename T>
106 std::unique_ptr<T>
107 create_port_for_ext_port (const ExtPort &ext_port, PortFlow flow);
108
109public:
114 bool is_input_ = false;
115
123 std::vector<utils::Utf8String> selected_midi_ports_;
124 std::vector<utils::Utf8String> selected_audio_ports_;
125
129 std::vector<std::unique_ptr<ExtPort>> ext_audio_ports_;
130 std::vector<std::unique_ptr<ExtPort>> ext_midi_ports_;
131
135 std::vector<std::unique_ptr<AudioPort>> audio_ports_;
136 std::vector<std::unique_ptr<MidiPort>> midi_ports_;
137
139 bool setup_ = false;
140
142 bool activated_ = false;
143
144 quint64 rescan_timeout_id_ = 0;
145
147 AudioEngine * engine_ = nullptr;
148};
149
150extern template std::unique_ptr<MidiPort>
151HardwareProcessor::create_port_for_ext_port (const ExtPort &, PortFlow);
152extern template std::unique_ptr<AudioPort>
153HardwareProcessor::create_port_for_ext_port (const ExtPort &, PortFlow);
154extern template Port *
156
The audio engine.
Definition engine.h:168
External port.
Definition ext_port.h:41
utils::Utf8String get_node_name() const override
Returns a human friendly name of the node.
ExtPort * find_ext_port(const utils::Utf8String &id)
Finds an ext port from its ID (type + full name).
bool activated_
Whether currently active.
void setup()
Sets up the ports but does not start them.
std::vector< utils::Utf8String > selected_midi_ports_
Ports selected by the user in the preferences to enable.
AudioEngine * engine_
Pointer to owner engine, if any.
void init_after_cloning(const HardwareProcessor &other, ObjectCloneType clone_type) override
To be used during serialization.
std::vector< std::unique_ptr< AudioPort > > audio_ports_
Ports to be used by Zrythm, corresponding to the external ports.
void process(nframes_t nframes)
Processes the data.
void rescan_ext_ports()
Rescans the hardware ports and appends any missing ones.
bool setup_
Whether set up already.
std::vector< std::unique_ptr< ExtPort > > ext_audio_ports_
All known external ports.
bool is_input_
Whether this is the processor at the start of the graph (input) or at the end (output).
void activate(bool activate)
Starts or stops the ports.
The Port class represents a port in the audio processing graph.
Definition port.h:181
Interface for objects that can be processed in the DSP graph.
Definition graph_node.h:51
Lightweight UTF-8 string wrapper with safe conversions.
Definition string.h:39
External ports.
T * find_port(const utils::Utf8String &id)
Finds a port from its ID (type + full name).
uint32_t nframes_t
Frame count.
Definition types.h:62
ObjectCloneType
Definition icloneable.h:25