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-2024 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#ifndef ZRYTHM_DSP_PORT_IDENTIFIER_H
5#define ZRYTHM_DSP_PORT_IDENTIFIER_H
6
7#include "zrythm-config.h"
8
9#include "utils/icloneable.h"
10#include "utils/types.h"
11#include "utils/uuid_identifiable_object.h"
12
13class Track;
14namespace zrythm::gui::old_dsp::plugins
15{
16class Plugin;
17}
18
19class Port;
20
21namespace zrythm::dsp
22{
23
27enum class PortFlow
28{
29 Unknown,
30 Input,
31 Output
32};
33
37enum class PortType
38{
39 Unknown,
40 Control,
41 Audio,
42 Event,
43 CV
44};
45
49enum class PortUnit
50{
51 None,
52 Hz,
53 MHz,
54 Db,
55 Degrees,
56 Seconds,
57
59 Ms,
60
62 Us,
63};
64
68class PortIdentifier : public ICloneable<PortIdentifier>
69{
70public:
72 using PluginUuid =
75
79 enum class OwnerType
80 {
81 /* NONE, */
82 AudioEngine,
83
86
89
92
95
103
104 /* TrackProcessor. */
105 TrackProcessor,
106
109
112
115 };
116
120 enum class Flags
121 {
122 StereoL = 1 << 0,
123 StereoR = 1 << 1,
124 PianoRoll = 1 << 2,
126 Sidechain = 1 << 3,
129 MainPort = 1 << 4,
130
134 ManualPress = 1 << 5,
135
137 Amplitude = 1 << 6,
138
146
153 WantPosition = 1 << 8,
154
162 Trigger = 1 << 9,
163
165 Toggle = 1 << 10,
166
168 Integer = 1 << 11,
169
172 Freewheel = 1 << 12,
173
175 ReportsLatency = 1 << 13,
176
178 NotOnGui = 1 << 14,
179
181 PluginEnabled = 1 << 15,
182
184 PluginControl = 1 << 16,
185
187 FaderMute = 1 << 17,
188
190 ChannelFader = 1 << 18,
191
198 Automatable = 1 << 19,
199
202
206 SendReceivable = 1 << 21,
207
209 Bpm = 1 << 22,
210
219
221 PluginGain = 1 << 24,
222
224 TpMono = 1 << 25,
225
227 TpInputGain = 1 << 26,
228
230 Hw = 1 << 27,
231
238 ModulatorMacro = 1 << 28,
239
241 Logarithmic = 1 << 29,
242
253 IsProperty = 1 << 30,
254 };
255
256 enum class Flags2
257 {
260 TransportStop = 1 << 1,
261 TransportBackward = 1 << 2,
262 TransportForward = 1 << 3,
263 TransportLoopToggle = 1 << 4,
264 TransportRecToggle = 1 << 5,
265
268
270 Enumeration = 1 << 7,
271
273 UriParam = 1 << 8,
274
276 Sequence = 1 << 9,
277
279 SupportsMidi = 1 << 10,
280
282 TpOutputGain = 1 << 11,
283
285 MidiPitchBend = 1 << 12,
286
289
292
295
298
300 BeatsPerBar = 1 << 17,
301
303 BeatUnit = 1 << 18,
304
306 FaderSolo = 1 << 19,
307
309 FaderListen = 1 << 20,
310
313
315 TrackRecording = 1 << 22,
316
318 TpMonitorAudio = 1 << 23,
319
321 Prefader = 1 << 24,
322
324 Postfader = 1 << 25,
325
327 MonitorFader = 1 << 26,
328
331
336
338 FaderSwapPhase = 1 << 29,
339
341 MidiClock = 1 << 30,
342 };
343
344 friend bool operator== (const PortIdentifier &lhs, const PortIdentifier &rhs);
345
346public:
347 // void init ();
348
349 utils::Utf8String get_label () const { return label_; }
350
351 bool is_control () const { return type_ == PortType::Control; }
352 bool is_midi () const { return type_ == PortType::Event; }
353 bool is_cv () const { return type_ == PortType::CV; }
354 bool is_audio () const { return type_ == PortType::Audio; }
355
356 bool is_input () const { return flow_ == PortFlow::Input; }
357 bool is_output () const { return flow_ == PortFlow::Output; }
358
359 bool is_monitor_fader_stereo_in_or_out_port () const
360 {
361 return ENUM_BITSET_TEST (flags2_, Flags2::MonitorFader)
362 && (ENUM_BITSET_TEST (flags_, Flags::StereoL) || ENUM_BITSET_TEST (flags_, Flags::StereoR));
363 }
364
365 auto get_track_id () const { return track_id_; }
366 void set_track_id (TrackUuid track_id) { track_id_ = track_id; }
367 auto get_plugin_id () const { return plugin_id_; }
368 void set_plugin_id (PluginUuid plugin_id) { plugin_id_ = plugin_id; }
369 auto get_symbol () const { return sym_; }
370
371 std::string print_to_str () const;
372 void print () const;
373 bool validate () const;
374 size_t get_hash () const;
375
376 static utils::Utf8String port_unit_to_string (PortUnit unit);
377
378 void
379 init_after_cloning (const PortIdentifier &other, ObjectCloneType clone_type)
380 override
381 {
382 *this = other;
383 }
384
385public:
388 size_t port_index_{};
389
391 std::optional<TrackUuid> track_id_;
392
396 PortType type_{ PortType::Unknown };
398 PortFlow flow_{ PortFlow::Unknown };
399
401 PortUnit unit_{ PortUnit::None };
402
405 PortIdentifier::Flags2 flags2_{};
406
408 std::optional<PluginUuid> plugin_id_;
409
412
415
417 std::optional<utils::Utf8String> uri_;
418
420 std::optional<utils::Utf8String> comment_;
421
423 std::optional<utils::Utf8String> port_group_;
424
426 std::optional<utils::Utf8String> ext_port_id_;
427
429 std::optional<midi_byte_t> midi_channel_;
430
431 friend void to_json (nlohmann::json &j, const PortIdentifier &port)
432 {
433 j = nlohmann::json{
434 { "label", port.label_ },
435 { "symbol", port.sym_ },
436 { "uri", port.uri_ },
437 { "comment", port.comment_ },
438 { "ownerType", port.owner_type_ },
439 { "type", port.type_ },
440 { "flow", port.flow_ },
441 { "unit", port.unit_ },
442 { "flags", port.flags_ },
443 { "flags2", port.flags2_ },
444 { "trackId", port.track_id_ },
445 { "pluginId", port.plugin_id_ },
446 { "portGroup", port.port_group_ },
447 { "externalPortId", port.ext_port_id_ },
448 { "portIndex", port.port_index_ },
449 { "midiChannel", port.midi_channel_ },
450 };
451 }
452 friend void from_json (const nlohmann::json &j, PortIdentifier &port)
453 {
454 j.at ("label").get_to (port.label_);
455 j.at ("symbol").get_to (port.sym_);
456 j.at ("uri").get_to (port.uri_);
457 j.at ("comment").get_to (port.comment_);
458 j.at ("ownerType").get_to (port.owner_type_);
459 j.at ("type").get_to (port.type_);
460 j.at ("flow").get_to (port.flow_);
461 j.at ("unit").get_to (port.unit_);
462 j.at ("flags").get_to (port.flags_);
463 j.at ("flags2").get_to (port.flags2_);
464 j.at ("trackId").get_to (port.track_id_);
465 j.at ("pluginId").get_to (port.plugin_id_);
466 j.at ("portGroup").get_to (port.port_group_);
467 j.at ("externalPortId").get_to (port.ext_port_id_);
468 j.at ("portIndex").get_to (port.port_index_);
469 j.at ("midiChannel").get_to (port.midi_channel_);
470 }
471};
472
473}; // namespace zrythm::dsp
474
475ENUM_ENABLE_BITSET (zrythm::dsp::PortIdentifier::Flags);
476ENUM_ENABLE_BITSET (zrythm::dsp::PortIdentifier::Flags2);
477
478namespace std
479{
480template <> struct hash<zrythm::utils::UuidIdentifiableObject<Port>::Uuid>
481{
482 std::size_t
483 operator() (const zrythm::utils::UuidIdentifiableObject<Port>::Uuid &uuid) const
484 {
485 return uuid.hash ();
486 }
487};
488}
489
490#endif
The Port class represents a port in the audio processing graph.
Definition port.h:181
Represents a track in the project.
Definition track.h:281
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.
utils::Utf8String label_
Human readable label.
PortFlow flow_
Flow (IN/OUT).
@ Automatable
Port has an automation track.
@ ModulatorMacro
Port is part of a modulator macro processor.
@ SendReceivable
Channels can send to this port (ie, this port is a track processor midi/stereo in or a plugin sidecha...
@ 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.
@ ReportsLatency
Used for plugin ports.
@ 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).
@ 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.
@ 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.
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.
@ 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.
@ 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.
@ UriParam
Parameter port's value type is URI.
@ Sequence
Atom port buffer type is sequence.
@ ChannelSendAmount
Channel send amount.
@ TpMonitorAudio
Track processor monitor audio.
@ SupportsMidi
Atom or event port supports MIDI.
@ MidiPolyKeyPressure
MIDI poly key pressure.
@ Postfader
Port is owned by postfader.
@ TpOutputGain
Track processor output gain.
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:41
Lightweight UTF-8 string wrapper with safe conversions.
Definition string.h:39
Base class for objects that need to be uniquely identified by UUID.
ObjectCloneType
Definition icloneable.h:25
Custom types.