Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
port_identifier.h
Go to the documentation of this file.
1// clang-format off
2// SPDX-FileCopyrightText: © 2018-2021, 2023 Alexandros Theodotou <alex@zrythm.org>
3// SPDX-License-Identifier: LicenseRef-ZrythmLicense
4// clang-format on
5
12#ifndef __AUDIO_PORT_IDENTIFIER_H__
13#define __AUDIO_PORT_IDENTIFIER_H__
14
15#include "zrythm-config.h"
16
17#include <cstddef>
18#include <cstdint>
19
21#include "utils/types.h"
22
29#define PORT_IDENTIFIER_SCHEMA_VERSION 1
30
31#define PORT_IDENTIFIER_MAGIC 3411841
32#define IS_PORT_IDENTIFIER(tr) \
33 (tr && ((PortIdentifier *) tr)->magic == PORT_IDENTIFIER_MAGIC)
34
38enum class ZPortFlow
39{
40 Z_PORT_FLOW_UNKNOWN,
41 Z_PORT_FLOW_INPUT,
42 Z_PORT_FLOW_OUTPUT
43};
44
48enum class ZPortType
49{
50 Z_PORT_TYPE_UNKNOWN,
51 Z_PORT_TYPE_CONTROL,
52 Z_PORT_TYPE_AUDIO,
53 Z_PORT_TYPE_EVENT,
54 Z_PORT_TYPE_CV
55};
56
60enum class PortUnit
61{
62 Z_PORT_UNIT_NONE,
63 Z_PORT_UNIT_HZ,
64 Z_PORT_UNIT_MHZ,
65 Z_PORT_UNIT_DB,
66 Z_PORT_UNIT_DEGREES,
67 Z_PORT_UNIT_SECONDS,
68
71
74};
75
76const char *
77port_unit_to_str (const PortUnit unit);
78
89typedef struct PortIdentifier
90{
94 enum class OwnerType
95 {
96 /* NONE, */
97 PORT_OWNER_TYPE_AUDIO_ENGINE,
98
100 PLUGIN,
101
103 TRACK,
104
106 CHANNEL,
107
109 FADER,
110
118
119 /* TrackProcessor. */
120 TRACK_PROCESSOR,
121
123 HW,
124
127
130 };
131
135 enum class Flags
136 {
137 STEREO_L = 1 << 0,
138 STEREO_R = 1 << 1,
139 PianoRoll = 1 << 2,
141 SIDECHAIN = 1 << 3,
144 MAIN_PORT = 1 << 4,
145 MANUAL_PRESS = 1 << 5,
146
148 AMPLITUDE = 1 << 6,
149
156 STEREO_BALANCE = 1 << 7,
157
164 WANT_POSITION = 1 << 8,
165
173 TRIGGER = 1 << 9,
174
176 TOGGLE = 1 << 10,
177
179 INTEGER = 1 << 11,
180
183 FREEWHEEL = 1 << 12,
184
186 REPORTS_LATENCY = 1 << 13,
187
189 NOT_ON_GUI = 1 << 14,
190
192 PLUGIN_ENABLED = 1 << 15,
193
195 PLUGIN_CONTROL = 1 << 16,
196
198 FADER_MUTE = 1 << 17,
199
201 CHANNEL_FADER = 1 << 18,
202
209 AUTOMATABLE = 1 << 19,
210
213 MIDI_AUTOMATABLE = 1 << 20,
214
218 SEND_RECEIVABLE = 1 << 21,
219
221 BPM = 1 << 22,
222
230 GENERIC_PLUGIN_PORT = 1 << 23,
231
233 PLUGIN_GAIN = 1 << 24,
234
236 TP_MONO = 1 << 25,
237
239 TP_INPUT_GAIN = 1 << 26,
240
242 HW = 1 << 27,
243
250 MODULATOR_MACRO = 1 << 28,
251
253 LOGARITHMIC = 1 << 29,
254
265 IS_PROPERTY = 1 << 30,
266 };
267
268 enum class Flags2
269 {
271 TRANSPORT_ROLL = 1 << 0,
272 TRANSPORT_STOP = 1 << 1,
273 TRANSPORT_BACKWARD = 1 << 2,
274 TRANSPORT_FORWARD = 1 << 3,
275 TRANSPORT_LOOP_TOGGLE = 1 << 4,
276 TRANSPORT_REC_TOGGLE = 1 << 5,
277
280 SUPPORTS_PATCH_MESSAGE = 1 << 6,
281
284 ENUMERATION = 1 << 7,
285
287 URI_PARAM = 1 << 8,
288
290 SEQUENCE = 1 << 9,
291
293 SUPPORTS_MIDI = 1 << 10,
294
296 TP_OUTPUT_GAIN = 1 << 11,
297
299 MIDI_PITCH_BEND = 1 << 12,
300
302 MIDI_POLY_KEY_PRESSURE = 1 << 13,
303
305 MIDI_CHANNEL_PRESSURE = 1 << 14,
306
308 CHANNEL_SEND_ENABLED = 1 << 15,
309
311 CHANNEL_SEND_AMOUNT = 1 << 16,
312
314 BEATS_PER_BAR = 1 << 17,
315
317 BEAT_UNIT = 1 << 18,
318
320 FADER_SOLO = 1 << 19,
321
323 FADER_LISTEN = 1 << 20,
324
326 FADER_MONO_COMPAT = 1 << 21,
327
329 TRACK_RECORDING = 1 << 22,
330
332 TP_MONITOR_AUDIO = 1 << 23,
333
335 PREFADER = 1 << 24,
336
338 POSTFADER = 1 << 25,
339
341 MonitorFader = 1 << 26,
342
344 SAMPLE_PROCESSOR_FADER = 1 << 27,
345
349 SAMPLE_PROCESSOR_TRACK = 1 << 28,
350
352 FADER_SWAP_PHASE = 1 << 29,
353
355 MIDI_CLOCK = 1 << 30,
356 };
357
358 int schema_version = PORT_IDENTIFIER_SCHEMA_VERSION;
359
361 char * label = nullptr;
362
364 char * sym = nullptr;
365
367 char * uri = nullptr;
368
370 char * comment = nullptr;
371
380 PortIdentifier::Flags2 flags2 = (Flags2) 0;
381
384
387
389 char * port_group = nullptr;
390
392 char * ext_port_id = nullptr;
393
395 unsigned int track_name_hash = 0;
396
398 int port_index = 0;
399
400public:
401 PortIdentifier () = default;
402 PortIdentifier (const PortIdentifier &other);
404
405 PortIdentifier &operator= (const PortIdentifier &other);
406
407 void init ();
408
409 inline const char * get_label () const { return label; }
410
416 inline int get_midi_channel () const
417 {
418 if (
419 static_cast<int> (flags2 & PortIdentifier::Flags2::MIDI_PITCH_BEND) != 0
420 || static_cast<int> (flags2 & PortIdentifier::Flags2::MIDI_POLY_KEY_PRESSURE)
421 != 0
422 || static_cast<int> (flags2 & PortIdentifier::Flags2::MIDI_CHANNEL_PRESSURE)
423 != 0)
424 {
425 return port_index + 1;
426 }
427 else if (
428 static_cast<int> (flags & PortIdentifier::Flags::MIDI_AUTOMATABLE) != 0)
429 {
430 return port_index / 128 + 1;
431 }
432 return -1;
433 }
434
441 WARN_UNUSED_RESULT bool is_equal (const PortIdentifier &other) const;
442
443 NONNULL void print_to_str (char * buf, size_t buf_sz) const;
444 void print () const;
445 bool validate () const;
446 uint32_t get_hash () const;
448
449ENUM_ENABLE_BITSET (PortIdentifier::Flags);
450ENUM_ENABLE_BITSET (PortIdentifier::Flags2);
451
456int
457port_identifier_port_group_cmp (const void * p1, const void * p2);
458
459const char *
460port_identifier_get_label (void * data);
461
462uint32_t
463port_identifier_get_hash (const void * data);
464
465void
466port_identifier_destroy_notify (void * data);
467
471int
472port_identifier_is_equal_func (const void * a, const void * b);
473
478#endif
ZPortType
Type of signals the Port handles.
int port_identifier_port_group_cmp(const void *p1, const void *p2)
Port group comparator function where p1 and p2 are pointers to Port.
PortUnit
Port unit to be displayed in the UI.
ZPortFlow
Direction of the signal.
int port_identifier_is_equal_func(const void *a, const void *b)
To be used as GEqualFunc.
@ Z_PORT_UNIT_MS
Milliseconds.
@ Z_PORT_UNIT_US
Microseconds.
Plugin identifier.
Piano roll serializable backend.
Definition piano_roll.h:164
Plugin identifier.
Struct used to identify Ports in the project.
WARN_UNUSED_RESULT bool is_equal(const PortIdentifier &other) const
Returns if the 2 PortIdentifier's are equal.
@ ENUMERATION
Port's only reasonable values are its scale points.
@ MIDI_POLY_KEY_PRESSURE
MIDI poly key pressure.
@ CHANNEL_SEND_ENABLED
Channel send enabled.
@ POSTFADER
Port is owned by postfader.
@ MonitorFader
Port is owned by monitor fader.
@ MIDI_PITCH_BEND
MIDI pitch bend.
@ SEQUENCE
Atom port buffer type is sequence.
@ URI_PARAM
Parameter port's value type is URI.
@ TRACK_RECORDING
Track recording.
@ CHANNEL_SEND_AMOUNT
Channel send amount.
@ FADER_LISTEN
Fader listen.
@ TP_OUTPUT_GAIN
Track processor output gain.
@ SAMPLE_PROCESSOR_FADER
Port is owned by the sample processor fader.
@ FADER_SOLO
Fader solo.
@ SUPPORTS_MIDI
Atom or event port supports MIDI.
@ MIDI_CHANNEL_PRESSURE
MIDI channel pressure.
@ PREFADER
Port is owned by prefader.
@ MIDI_CLOCK
MIDI clock.
@ TRANSPORT_ROLL
Transport ports.
@ SAMPLE_PROCESSOR_TRACK
Port is owned by sample processor track/channel (including faders owned by those tracks/channels).
@ FADER_MONO_COMPAT
Fader mono compat.
@ TP_MONITOR_AUDIO
Track processor monitor audio.
@ BEATS_PER_BAR
Beats per bar.
@ SUPPORTS_PATCH_MESSAGE
LV2 control atom port supports patch messages.
@ FADER_SWAP_PHASE
Fader swap phase.
char * label
Human readable label.
char * port_group
Port group this port is part of (only applicable for LV2 plugin ports).
char * sym
Unique symbol.
PortUnit unit
Port unit.
int get_midi_channel() const
Returns the MIDI channel for a MIDI CC port, or -1 if not a MIDI CC port.
ZPortType type
Data type (e.g.
ZPortFlow flow
Flow (IN/OUT).
PortIdentifier::Flags flags
Flags (e.g.
unsigned int track_name_hash
Track name hash (0 for non-track ports).
char * uri
URI, if LV2 property.
char * comment
Comment, if any.
OwnerType
Type of owner.
@ HW
Port is part of a HardwareProcessor.
@ CHANNEL_SEND
Channel send.
@ MODULATOR_MACRO_PROCESSOR
Modulator macro processor owner.
@ PORT_OWNER_TYPE_TRANSPORT
Port is owned by engine transport.
@ CHANNEL
Channel owner.
PortIdentifier::OwnerType owner_type
Owner type.
int port_index
Index (e.g.
PluginIdentifier plugin_id
Identifier of plugin.
char * ext_port_id
ExtPort ID (type + full name), if hw port.
@ MAIN_PORT
See http://lv2plug.in/ns/ext/port-groups/port-groups.html#mainInput and http://lv2plug....
@ REPORTS_LATENCY
Used for plugin ports.
@ TP_MONO
Track processor input mono switch.
@ TOGGLE
Whether the port is a toggle (on/off).
@ CHANNEL_FADER
Port is for channel fader.
@ MODULATOR_MACRO
Port is part of a modulator macro processor.
@ WANT_POSITION
Whether the port wants to receive position events.
@ NOT_ON_GUI
Port should not be visible to users.
@ AMPLITUDE
Amplitude port.
@ PLUGIN_CONTROL
Port is a plugin control.
@ PLUGIN_ENABLED
Port is a switch for plugin enabled.
@ INTEGER
Whether the port is an integer.
@ STEREO_BALANCE
Port controls the stereo balance.
@ MIDI_AUTOMATABLE
MIDI automatable control, such as modwheel or pitch bend.
@ 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.
@ AUTOMATABLE
Port has an automation track.
@ IS_PROPERTY
Plugin control is a property (changes are set via atom message on the plugin's control port),...
@ GENERIC_PLUGIN_PORT
Generic plugin port not belonging to the underlying plugin.
@ PLUGIN_GAIN
This is the plugin gain.
@ FADER_MUTE
Port is for fader mute.
@ LOGARITHMIC
Logarithmic.
@ TRIGGER
Trigger ports will be set to 0 at the end of each cycle.
@ SEND_RECEIVABLE
Channels can send to this port (ie, this port is a track processor midi/stereo in or a plugin sidecha...
@ TP_INPUT_GAIN
Track processor input gain.
@ BPM
This is a BPM port.
Custom types.