Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
port_connection.h
1// SPDX-FileCopyrightText: © 2021-2022, 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#ifndef __AUDIO_PORT_CONNECTION_H__
5#define __AUDIO_PORT_CONNECTION_H__
6
7#include "zrythm-config.h"
8
9#include "dsp/port_identifier.h"
10#include "utils/math.h"
11
12#include <QtQmlIntegration>
13
14using namespace zrythm;
15
19class PortConnection final : public QObject, public ICloneable<PortConnection>
20{
21 Q_OBJECT
22 QML_ELEMENT
23
24public:
25 using PortUuid = dsp::PortIdentifier::PortUuid;
26
27 PortConnection (QObject * parent = nullptr);
28
29 PortConnection (
30 const PortUuid &src,
31 const PortUuid &dest,
32 float multiplier,
33 bool locked,
34 bool enabled,
35 QObject * parent = nullptr);
36
37 void
38 init_after_cloning (const PortConnection &other, ObjectCloneType clone_type)
39 override;
40
41 void update (float multiplier, bool locked, bool enabled)
42 {
43 multiplier_ = multiplier;
44 locked_ = locked;
45 enabled_ = enabled;
46 }
47
48private:
49 static constexpr std::string_view kSourceIdKey = "srcId";
50 static constexpr std::string_view kDestIdKey = "destId";
51 static constexpr std::string_view kMultiplierKey = "multiplier";
52 static constexpr std::string_view kLockedKey = "locked";
53 static constexpr std::string_view kEnabledKey = "enabled";
54 // note: this is only needed for CV ports
55 static constexpr std::string_view kBaseValueKey = "baseValue";
56 friend void to_json (nlohmann::json &j, const PortConnection &port_connection)
57 {
58 j[kSourceIdKey] = port_connection.src_id_;
59 j[kDestIdKey] = port_connection.dest_id_;
60 j[kMultiplierKey] = port_connection.multiplier_;
61 j[kLockedKey] = port_connection.locked_;
62 j[kEnabledKey] = port_connection.enabled_;
63 j[kBaseValueKey] = port_connection.base_value_;
64 }
65 friend void
66 from_json (const nlohmann::json &j, PortConnection &port_connection)
67 {
68 j.at (kSourceIdKey).get_to (port_connection.src_id_);
69 j.at (kDestIdKey).get_to (port_connection.dest_id_);
70 j.at (kMultiplierKey).get_to (port_connection.multiplier_);
71 j.at (kLockedKey).get_to (port_connection.locked_);
72 j.at (kEnabledKey).get_to (port_connection.enabled_);
73 j.at (kBaseValueKey).get_to (port_connection.base_value_);
74 }
75
76public:
77 PortUuid src_id_;
78 PortUuid dest_id_;
79
86 float multiplier_ = 1.0f;
87
94 bool locked_ = false;
95
101 bool enabled_ = true;
102
104 float base_value_ = 0.0f;
105};
106
107bool
108operator== (const PortConnection &lhs, const PortConnection &rhs);
109
112 port_connection,
113 [] (const PortConnection &conn) {
114 return fmt::format (
115 "PortConnection{{src: {}, dest: {}, mult: {:.2f}, locked: {}, enabled: {}}}",
116 conn.src_id_, conn.dest_id_, conn.multiplier_, conn.locked_,
117 conn.enabled_);
118 })
119
120#endif /* __AUDIO_PORT_CONNECTION_H__ */
A connection between two ports.
void init_after_cloning(const PortConnection &other, ObjectCloneType clone_type) override
Initializes the cloned object.
float base_value_
Used for CV -> control port connections.
bool enabled_
Whether the connection is enabled.
float multiplier_
Multiplier to apply, where applicable.
bool locked_
Whether the connection can be removed or the multiplier edited by the user.
#define DEFINE_OBJECT_FORMATTER(obj_type, function_prefix, formatter_func)
Defines a formatter for the given object type.
Definition format.h:80
ObjectCloneType
Definition icloneable.h:25