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 "engine/device_io/ext_port.h"
7#include "gui/dsp/audio_port.h"
8#include "gui/dsp/midi_port.h"
9#include "utils/icloneable.h"
10
11#define HW_IN_PROCESSOR (AUDIO_ENGINE->hw_in_processor_)
12#define HW_OUT_PROCESSOR (AUDIO_ENGINE->hw_out_processor_)
13
14namespace zrythm::engine::device_io
15{
19class HardwareProcessor final
20 : public ICloneable<HardwareProcessor>,
22{
23public:
24 using PortFlow = zrythm::dsp::PortFlow;
25
26public:
27 // Rule of 0
28 HardwareProcessor () = default;
29
30 HardwareProcessor (bool input, AudioEngine * engine);
31
32 void init_loaded (AudioEngine * engine);
33
34 bool is_in_active_project () const;
35
42
49
55 template <typename T = Port> T * find_port (const utils::Utf8String &id);
56
60 void setup ();
61
67 void activate (bool activate);
68
72 void process (nframes_t nframes);
73
75
79 void
80 init_after_cloning (const HardwareProcessor &other, ObjectCloneType clone_type)
81 override;
82
83private:
84 static constexpr auto kIsInputKey = "isInput"sv;
85 static constexpr auto kExtAudioPortsKey = "extAudioPorts"sv;
86 static constexpr auto kExtMidiPortsKey = "extMidiPorts"sv;
87 static constexpr auto kAudioPortsKey = "audioPorts"sv;
88 static constexpr auto kMidiPortsKey = "midiPorts"sv;
89 friend void to_json (nlohmann::json &j, const HardwareProcessor &p)
90 {
91 j = nlohmann::json{
92 { kIsInputKey, p.is_input_ },
93 { kExtAudioPortsKey, p.ext_audio_ports_ },
94 { kExtMidiPortsKey, p.ext_midi_ports_ },
95 { kAudioPortsKey, p.audio_ports_ },
96 { kMidiPortsKey, p.midi_ports_ },
97 };
98 }
99 friend void from_json (const nlohmann::json &j, HardwareProcessor &p);
100
101 template <typename T>
102 std::unique_ptr<T>
103 create_port_for_ext_port (const ExtPort &ext_port, PortFlow flow);
104
105public:
110 bool is_input_ = false;
111
119 std::vector<utils::Utf8String> selected_midi_ports_;
120 std::vector<utils::Utf8String> selected_audio_ports_;
121
125 std::vector<std::unique_ptr<ExtPort>> ext_audio_ports_;
126 std::vector<std::unique_ptr<ExtPort>> ext_midi_ports_;
127
131 std::vector<std::unique_ptr<AudioPort>> audio_ports_;
132 std::vector<std::unique_ptr<MidiPort>> midi_ports_;
133
135 bool setup_ = false;
136
138 bool activated_ = false;
139
140 quint64 rescan_timeout_id_ = 0;
141
143 AudioEngine * engine_ = nullptr;
144};
145
146extern template std::unique_ptr<MidiPort>
147HardwareProcessor::create_port_for_ext_port (const ExtPort &, PortFlow);
148extern template std::unique_ptr<AudioPort>
149HardwareProcessor::create_port_for_ext_port (const ExtPort &, PortFlow);
150extern template Port *
152}
The Port class represents a port in the audio processing graph.
Definition port.h:180
Interface for objects that can be processed in the DSP graph.
Definition graph_node.h:50
void activate(bool activate)
Starts or stops the ports.
AudioEngine * engine_
Pointer to owner engine, if any.
void rescan_ext_ports()
Rescans the hardware ports and appends any missing ones.
T * find_port(const utils::Utf8String &id)
Finds a port from its ID (type + full name).
void process(nframes_t nframes)
Processes the data.
bool is_input_
Whether this is the processor at the start of the graph (input) or at the end (output).
void init_after_cloning(const HardwareProcessor &other, ObjectCloneType clone_type) override
To be used during serialization.
std::vector< utils::Utf8String > selected_midi_ports_
Ports selected by the user in the preferences to enable.
void setup()
Sets up the ports but does not start them.
utils::Utf8String get_node_name() const override
Returns a human friendly name of the node.
std::vector< std::unique_ptr< AudioPort > > audio_ports_
Ports to be used by Zrythm, corresponding to the external ports.
ExtPort * find_ext_port(const utils::Utf8String &id)
Finds an ext port from its ID (type + full name).
std::vector< std::unique_ptr< ExtPort > > ext_audio_ports_
All known external ports.
Lightweight UTF-8 string wrapper with safe conversions.
Definition string.h:39
uint32_t nframes_t
Frame count.
Definition types.h:55
ObjectCloneType
Definition icloneable.h:25