Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
port_identifier.h
1// SPDX-FileCopyrightText: © 2018-2021, 2023-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 "utils/icloneable.h"
9#include "utils/types.h"
10#include "utils/uuid_identifiable_object.h"
11
12namespace zrythm::structure::tracks
13{
14class Track;
15}
16namespace zrythm::gui::old_dsp::plugins
17{
18class Plugin;
19}
20
21class Port;
22
23namespace zrythm::dsp
24{
25
29enum class PortFlow
30{
31 Unknown,
32 Input,
33 Output
34};
35
39enum class PortType
40{
41 Unknown,
42 Control,
43 Audio,
44 Event,
45 CV
46};
47
51enum class PortUnit
52{
53 None,
54 Hz,
55 MHz,
56 Db,
57 Degrees,
58 Seconds,
59
61 Ms,
62
64 Us,
65};
66
71{
72public:
73 using TrackUuid =
75 using PluginUuid =
78
82 enum class OwnerType
83 {
84 /* NONE, */
85 AudioEngine,
86
89
92
95
98
106
107 /* TrackProcessor. */
108 TrackProcessor,
109
112
115
118 };
119
123 enum class Flags : std::uint64_t
124 {
125 StereoL = UINT64_C (1) << 0,
126 StereoR = UINT64_C (1) << 1,
127 PianoRoll = UINT64_C (1) << 2,
129 Sidechain = UINT64_C (1) << 3,
132 MainPort = UINT64_C (1) << 4,
133
137 ManualPress = UINT64_C (1) << 5,
138
140 Amplitude = UINT64_C (1) << 6,
141
148 StereoBalance = UINT64_C (1) << 7,
149
156 WantPosition = UINT64_C (1) << 8,
157
165 Trigger = UINT64_C (1) << 9,
166
168 Toggle = UINT64_C (1) << 10,
169
171 Integer = UINT64_C (1) << 11,
172
175 Freewheel = UINT64_C (1) << 12,
176
178 ReportsLatency = UINT64_C (1) << 13,
179
181 NotOnGui = UINT64_C (1) << 14,
182
184 PluginEnabled = UINT64_C (1) << 15,
185
187 PluginControl = UINT64_C (1) << 16,
188
190 FaderMute = UINT64_C (1) << 17,
191
193 ChannelFader = UINT64_C (1) << 18,
194
201 Automatable = UINT64_C (1) << 19,
202
204 MidiAutomatable = UINT64_C (1) << 20,
205
209 SendReceivable = UINT64_C (1) << 21,
210
218 GenericPluginPort = UINT64_C (1) << 22,
219
221 PluginGain = UINT64_C (1) << 23,
222
224 TpMono = UINT64_C (1) << 24,
225
227 TpInputGain = UINT64_C (1) << 25,
228
230 Hw = UINT64_C (1) << 26,
231
238 ModulatorMacro = UINT64_C (1) << 27,
239
241 Logarithmic = UINT64_C (1) << 28,
242
253 IsProperty = UINT64_C (1) << 29,
254
256 TransportRoll = UINT64_C (1) << 30,
257 TransportStop = UINT64_C (1) << 31,
258 TransportBackward = UINT64_C (1) << 32,
259 TransportForward = UINT64_C (1) << 33,
260 TransportLoopToggle = UINT64_C (1) << 34,
261 TransportRecToggle = UINT64_C (1) << 35,
262
264 SupportsPatchMessage = UINT64_C (1) << 36,
265
267 Enumeration = UINT64_C (1) << 37,
268
270 UriParam = UINT64_C (1) << 38,
271
273 Sequence = UINT64_C (1) << 39,
274
276 SupportsMidi = UINT64_C (1) << 40,
277
279 TpOutputGain = UINT64_C (1) << 41,
280
282 MidiPitchBend = UINT64_C (1) << 42,
283
285 MidiPolyKeyPressure = UINT64_C (1) << 43,
286
288 MidiChannelPressure = UINT64_C (1) << 44,
289
291 ChannelSendEnabled = UINT64_C (1) << 45,
292
294 ChannelSendAmount = UINT64_C (1) << 46,
295
297 FaderSolo = UINT64_C (1) << 47,
298
300 FaderListen = UINT64_C (1) << 48,
301
303 FaderMonoCompat = UINT64_C (1) << 49,
304
306 TrackRecording = UINT64_C (1) << 50,
307
309 TpMonitorAudio = UINT64_C (1) << 51,
310
312 Prefader = UINT64_C (1) << 52,
313
315 Postfader = UINT64_C (1) << 53,
316
318 MonitorFader = UINT64_C (1) << 54,
319
321 SampleProcessorFader = UINT64_C (1) << 55,
322
325 SampleProcessorTrack = UINT64_C (1) << 56,
326
328 FaderSwapPhase = UINT64_C (1) << 57,
329
331 MidiClock = UINT64_C (1) << 58,
332 };
333
334 friend bool operator== (const PortIdentifier &lhs, const PortIdentifier &rhs);
335
336public:
337 // void init ();
338
339 utils::Utf8String get_label () const { return label_; }
340
341 bool is_control () const { return type_ == PortType::Control; }
342 bool is_midi () const { return type_ == PortType::Event; }
343 bool is_cv () const { return type_ == PortType::CV; }
344 bool is_audio () const { return type_ == PortType::Audio; }
345
346 bool is_input () const { return flow_ == PortFlow::Input; }
347 bool is_output () const { return flow_ == PortFlow::Output; }
348
349 bool is_monitor_fader_stereo_in_or_out_port () const
350 {
351 return ENUM_BITSET_TEST (flags_, Flags::MonitorFader)
352 && (ENUM_BITSET_TEST (flags_, Flags::StereoL) || ENUM_BITSET_TEST (flags_, Flags::StereoR));
353 }
354
355 auto get_track_id () const { return track_id_; }
356 void set_track_id (TrackUuid track_id) { track_id_ = track_id; }
357 auto get_plugin_id () const { return plugin_id_; }
358 void set_plugin_id (PluginUuid plugin_id) { plugin_id_ = plugin_id; }
359 auto get_symbol () const { return sym_; }
360
361 std::string print_to_str () const;
362 void print () const;
363 size_t get_hash () const;
364
365 static utils::Utf8String port_unit_to_string (PortUnit unit);
366
367 friend void init_from (
368 PortIdentifier &obj,
369 const PortIdentifier &other,
370 utils::ObjectCloneType clone_type)
371 {
372 obj = other;
373 }
374
375public:
378 size_t port_index_{};
379
381 std::optional<TrackUuid> track_id_;
382
386 PortType type_{ PortType::Unknown };
388 PortFlow flow_{ PortFlow::Unknown };
389
391 PortUnit unit_{ PortUnit::None };
392
395
397 std::optional<PluginUuid> plugin_id_;
398
401
404
406 std::optional<utils::Utf8String> uri_;
407
409 std::optional<utils::Utf8String> comment_;
410
412 std::optional<utils::Utf8String> port_group_;
413
415 std::optional<utils::Utf8String> ext_port_id_;
416
418 std::optional<midi_byte_t> midi_channel_;
419
420 friend void to_json (nlohmann::json &j, const PortIdentifier &port)
421 {
422 j = nlohmann::json{
423 { "label", port.label_ },
424 { "symbol", port.sym_ },
425 { "uri", port.uri_ },
426 { "comment", port.comment_ },
427 { "ownerType", port.owner_type_ },
428 { "type", port.type_ },
429 { "flow", port.flow_ },
430 { "unit", port.unit_ },
431 { "flags", port.flags_ },
432 { "trackId", port.track_id_ },
433 { "pluginId", port.plugin_id_ },
434 { "portGroup", port.port_group_ },
435 { "externalPortId", port.ext_port_id_ },
436 { "portIndex", port.port_index_ },
437 { "midiChannel", port.midi_channel_ },
438 };
439 }
440 friend void from_json (const nlohmann::json &j, PortIdentifier &port)
441 {
442 j.at ("label").get_to (port.label_);
443 j.at ("symbol").get_to (port.sym_);
444 j.at ("uri").get_to (port.uri_);
445 j.at ("comment").get_to (port.comment_);
446 j.at ("ownerType").get_to (port.owner_type_);
447 j.at ("type").get_to (port.type_);
448 j.at ("flow").get_to (port.flow_);
449 j.at ("unit").get_to (port.unit_);
450 j.at ("flags").get_to (port.flags_);
451 j.at ("trackId").get_to (port.track_id_);
452 j.at ("pluginId").get_to (port.plugin_id_);
453 j.at ("portGroup").get_to (port.port_group_);
454 j.at ("externalPortId").get_to (port.ext_port_id_);
455 j.at ("portIndex").get_to (port.port_index_);
456 j.at ("midiChannel").get_to (port.midi_channel_);
457 }
458};
459
460}; // namespace zrythm::dsp
461
462ENUM_ENABLE_BITSET (zrythm::dsp::PortIdentifier::Flags);
463
464namespace std
465{
466template <> struct hash<zrythm::utils::UuidIdentifiableObject<Port>::Uuid>
467{
468 std::size_t
469 operator() (const zrythm::utils::UuidIdentifiableObject<Port>::Uuid &uuid) const
470 {
471 return uuid.hash ();
472 }
473};
474}
The Port class represents a port in the audio processing graph.
Definition port.h:169
Struct used to identify Ports in the project.
PortType type_
Data type (e.g.
PortIdentifier::Flags flags_
Flags (e.g.
std::optional< utils::Utf8String > uri_
URI, if LV2 property.
std::optional< utils::Utf8String > comment_
Comment, if any.
std::optional< PluginUuid > plugin_id_
Identifier of plugin.
@ Plugin
zrythm::gui::old_dsp::plugins::Plugin owner.
@ ModulatorMacroProcessor
Modulator macro processor owner.
@ HardwareProcessor
Port is part of a HardwareProcessor.
@ Transport
Port is owned by engine transport.
@ MidiChannelPressure
MIDI channel pressure.
@ ChannelSendEnabled
Channel send enabled.
@ SampleProcessorTrack
Port is owned by sample processor track/channel (including faders owned by those tracks/channels).
@ Prefader
Port is owned by prefader.
@ Automatable
Port has an automation track.
@ MonitorFader
Port is owned by monitor fader.
@ Enumeration
Port's only reasonable values are its scale points.
@ SampleProcessorFader
Port is owned by the sample processor fader.
@ SupportsPatchMessage
LV2 control atom port supports patch messages.
@ ModulatorMacro
Port is part of a modulator macro processor.
@ UriParam
Parameter port's value type is URI.
@ SendReceivable
Channels can send to this port (ie, this port is a track processor midi/stereo in or a plugin sidecha...
@ Sequence
Atom port buffer type is sequence.
@ FaderMute
Port is for fader mute.
@ StereoBalance
Port controls the stereo balance.
@ MidiAutomatable
MIDI automatable control, such as modwheel or pitch bend.
@ IsProperty
zrythm::gui::old_dsp::plugins::Plugin control is a property (changes are set via atom message on the ...
@ WantPosition
Whether the port wants to receive position events.
@ ChannelFader
Port is for channel fader.
@ ChannelSendAmount
Channel send amount.
@ ReportsLatency
Used for plugin ports.
@ TpMonitorAudio
Track processor monitor audio.
@ TpInputGain
Track processor input gain.
@ ManualPress
Piano roll user (piano) key press.
@ Integer
Whether the port is an integer.
@ Toggle
Whether the port is a toggle (on/off).
@ SupportsMidi
Atom or event port supports MIDI.
@ PluginGain
This is the plugin gain.
@ Freewheel
Whether port is for letting the plugin know that we are in freewheeling (export) mode.
@ Sidechain
See http://lv2plug.in/ns/ext/port-groups/port-groups.html#sideChainOf.
@ MainPort
See http://lv2plug.in/ns/ext/port-groups/port-groups.html#mainInput and http://lv2plug....
@ PluginControl
Port is a plugin control.
@ MidiPolyKeyPressure
MIDI poly key pressure.
@ Postfader
Port is owned by postfader.
@ TpOutputGain
Track processor output gain.
@ NotOnGui
Port should not be visible to users.
@ GenericPluginPort
Generic plugin port not belonging to the underlying plugin.
@ PluginEnabled
Port is a switch for plugin enabled.
@ Trigger
Trigger ports will be set to 0 at the end of each cycle.
@ TpMono
Track processor input mono switch.
utils::Utf8String label_
Human readable label.
PortFlow flow_
Flow (IN/OUT).
std::optional< midi_byte_t > midi_channel_
MIDI channel if MIDI CC port, starting from 1 (so [1, 16]).
std::optional< utils::Utf8String > port_group_
Port group this port is part of (only applicable for LV2 plugin ports).
std::optional< utils::Utf8String > ext_port_id_
ExtPort ID (type + full name), if hw port.
utils::Utf8String sym_
Unique symbol.
std::optional< TrackUuid > track_id_
Track identifier.
PortIdentifier::OwnerType owner_type_
Owner type.
This class provides the core functionality for managing a plugin, including creating/initializing the...
Definition plugin.h:45
Represents a track in the project.
Definition track.h:360
Lightweight UTF-8 string wrapper with safe conversions.
Definition string.h:39
Base class for objects that need to be uniquely identified by UUID.