Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
ext_port.h
1// SPDX-FileCopyrightText: © 2019-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "zrythm-config.h"
7
8#include "gui/dsp/port.h"
9#include "utils/serialization.h"
10#include "utils/types.h"
11
12#ifdef HAVE_JACK
13# include "weakjack/weak_libjack.h"
14#endif
15
16namespace zrythm::engine::device_io
17{
19class AudioEngine;
20enum class AudioBackend : basic_enum_base_type_t;
21enum class MidiBackend : basic_enum_base_type_t;
22
26class ExtPort final : public IPortOwner
27{
28public:
32 enum class Type
33 {
34 JACK,
35 ALSA,
36 WindowsMME,
37 RtMidi,
38 RtAudio,
39 };
40
41 using PortType = zrythm::dsp::PortType;
42 using PortFlow = zrythm::dsp::PortFlow;
43
44public:
45 ExtPort () = default;
46#ifdef HAVE_JACK
47 ExtPort (jack_port_t * jport);
48#endif /* defined(HAVE_JACK) */
49
50 bool is_in_active_project () const override;
51
53 const override;
54
56 get_full_designation_for_port (const dsp::PortIdentifier &id) const override;
57
61 [[gnu::cold]] void init_loaded (HardwareProcessor * hw_processor)
62 {
63 hw_processor_ = hw_processor;
64 }
65
69 void print () const;
70
74 bool matches_backend () const;
75
80
81 friend bool operator== (const ExtPort &a, const ExtPort &b);
82
87
91 float * get_buffer (nframes_t nframes) const;
92
96 void clear_buffer (nframes_t nframes);
97
98#if 0
107void
108connect (
109 Port * port,
110 int src);
111#endif
112
119 void disconnect (Port * port, int src);
120
128 bool activate (Port * port, bool activate);
129
137 bool get_enabled () const;
138
139private:
140 static constexpr std::string_view kTypeKey = "type";
141 static constexpr std::string_view kFullNameKey = "fullName";
142 static constexpr std::string_view kShortNameKey = "shortName";
143 static constexpr std::string_view kAlias1Key = "alias1";
144 static constexpr std::string_view kAlias2Key = "alias2";
145 static constexpr std::string_view kNumAliasesKey = "numAliases";
146 static constexpr std::string_view kIsMidiKey = "isMidi";
147 friend void to_json (nlohmann::json &j, const ExtPort &port)
148 {
149 j = nlohmann::json{
150 { kTypeKey, port.type_ },
151 { kFullNameKey, port.full_name_ },
152 { kShortNameKey, port.short_name_ },
153 { kAlias1Key, port.alias1_ },
154 { kAlias2Key, port.alias2_ },
155 { kNumAliasesKey, port.num_aliases_ },
156 { kIsMidiKey, port.is_midi_ },
157 };
158 }
159 friend void from_json (const nlohmann::json &j, ExtPort &port)
160 {
161 j.at (kTypeKey).get_to (port.type_);
162 j.at (kFullNameKey).get_to (port.full_name_);
163 j.at (kShortNameKey).get_to (port.short_name_);
164 j.at (kAlias1Key).get_to (port.alias1_);
165 j.at (kAlias2Key).get_to (port.alias2_);
166 j.at (kNumAliasesKey).get_to (port.num_aliases_);
167 j.at (kIsMidiKey).get_to (port.is_midi_);
168 }
169
170 friend bool operator== (const ExtPort &a, const ExtPort &b)
171 {
172 return a.type_ == b.type_ && a.full_name_ == b.full_name_;
173 }
174
175public:
177#ifdef HAVE_JACK
178 jack_port_t * jport_ = nullptr;
179#else
180 void * jport_ = nullptr;
181#endif
182
185
188
191
194
195 int num_aliases_ = 0;
196
197 Type type_ = (Type) 0;
198
200 bool is_midi_ = false;
201
204
207
210 bool active_ = false;
211
217 bool pending_reconnect_ = false;
218
222 Port * port_ = nullptr;
223};
224}
The Port class represents a port in the audio processing graph.
Definition port.h:180
Struct used to identify Ports in the project.
bool get_enabled() const
Checks in the GSettings whether this port is marked as enabled by the user.
bool active_
Whether the port is active and receiving events (for use by hw processor).
Definition ext_port.h:210
int hw_processor_index_
Index in the HW processor (cache for real-time use)
Definition ext_port.h:203
void disconnect(Port *port, int src)
Disconnects the Port from the ExtPort.
bool activate(Port *port, bool activate)
Activates the port (starts receiving data) or deactivates it.
utils::Utf8String get_id() const
Returns a unique identifier (full name prefixed with backend type).
float * get_buffer(nframes_t nframes) const
Returns the buffer of the external port.
void set_port_metadata_from_owner(dsp::PortIdentifier &id, PortRange &range) const override
Function that will be called by the Port to update the identifier's relevant members based on this po...
bool matches_backend() const
Returns if the ext port matches the current backend.
void init_loaded(HardwareProcessor *hw_processor)
Inits the ExtPort after loading a project.
Definition ext_port.h:61
Port * port_
Temporary port to receive data.
Definition ext_port.h:222
void clear_buffer(nframes_t nframes)
Clears the buffer of the external port.
bool pending_reconnect_
Set to true when a hardware port is disconnected.
Definition ext_port.h:217
bool is_midi_
True if MIDI, false if audio.
Definition ext_port.h:200
utils::Utf8String full_name_
Full port name, used also as ID.
Definition ext_port.h:184
utils::Utf8String get_friendly_name() const
Returns a user-friendly display name (eg, to be used in dropdowns).
utils::Utf8String short_name_
Short port name.
Definition ext_port.h:187
utils::Utf8String alias1_
Alias #1 if any.
Definition ext_port.h:190
HardwareProcessor * hw_processor_
Pointer to owner hardware processor, if any.
Definition ext_port.h:206
utils::Utf8String alias2_
Alias #2 if any.
Definition ext_port.h:193
void print() const
Prints the port info.
Lightweight UTF-8 string wrapper with safe conversions.
Definition string.h:39
uint32_t nframes_t
Frame count.
Definition types.h:55