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#pragma once
5
6#include "dsp/port_fwd.h"
7
8#include <QtQmlIntegration>
9
10namespace zrythm::dsp
11{
12
16class PortConnection : public QObject
17{
18 Q_OBJECT
19 QML_ELEMENT
20
21public:
22 PortConnection (QObject * parent = nullptr);
23
24 PortConnection (
25 const PortUuid &src,
26 const PortUuid &dest,
27 float multiplier,
28 bool locked,
29 bool enabled,
30 QObject * parent = nullptr);
31
32 void update (float multiplier, bool locked, bool enabled)
33 {
34 multiplier_ = multiplier;
35 locked_ = locked;
36 enabled_ = enabled;
37 }
38
39 void set_bipolar (bool bipolar) { bipolar_ = bipolar; }
40
41 void set_channel_mapping (uint8_t source_channel, uint8_t destination_channel)
42 {
44 std::make_pair (source_channel, destination_channel);
45 }
46 void unset_channel_mapping ()
47 {
49 }
50
51private:
52 static constexpr std::string_view kSourceIdKey = "srcId";
53 static constexpr std::string_view kDestIdKey = "destId";
54 static constexpr std::string_view kMultiplierKey = "multiplier";
55 static constexpr std::string_view kLockedKey = "locked";
56 static constexpr std::string_view kEnabledKey = "enabled";
57 static constexpr std::string_view kBipolarKey = "bipolar";
58 static constexpr std::string_view kSourceDestMappingKey =
59 "sourceChannelToDestinationChannelMapping";
60 friend void to_json (nlohmann::json &j, const PortConnection &port_connection)
61 {
62 j[kSourceIdKey] = port_connection.src_id_;
63 j[kDestIdKey] = port_connection.dest_id_;
64 j[kMultiplierKey] = port_connection.multiplier_;
65 j[kLockedKey] = port_connection.locked_;
66 j[kEnabledKey] = port_connection.enabled_;
67 j[kBipolarKey] = port_connection.bipolar_;
68 j[kSourceDestMappingKey] =
70 }
71 friend void
72 from_json (const nlohmann::json &j, PortConnection &port_connection)
73 {
74 j.at (kSourceIdKey).get_to (port_connection.src_id_);
75 j.at (kDestIdKey).get_to (port_connection.dest_id_);
76 j.at (kMultiplierKey).get_to (port_connection.multiplier_);
77 j.at (kLockedKey).get_to (port_connection.locked_);
78 j.at (kEnabledKey).get_to (port_connection.enabled_);
79 j.at (kBipolarKey).get_to (port_connection.bipolar_);
80 j.at (kSourceDestMappingKey)
81 .get_to (port_connection.source_ch_to_destination_ch_mapping_);
82 }
83
84 friend void init_from (
85 PortConnection &obj,
86 const PortConnection &other,
87 utils::ObjectCloneType clone_type);
88
89 friend bool operator== (const PortConnection &lhs, const PortConnection &rhs)
90 {
91 return lhs.src_id_ == rhs.src_id_ && lhs.dest_id_ == rhs.dest_id_;
92 }
93
94public:
95 PortUuid src_id_;
96 PortUuid dest_id_;
97
104 float multiplier_ = 1.0f;
105
112 bool locked_ = false;
113
119 bool enabled_ = true;
120
131 bool bipolar_{};
132
140 std::optional<std::pair<uint8_t, uint8_t>> source_ch_to_destination_ch_mapping_;
141
142 BOOST_DESCRIBE_CLASS (
143 PortConnection,
144 (),
145 (src_id_,
146 dest_id_,
148 locked_,
149 enabled_,
150 bipolar_,
152 (),
153 ())
154};
155
156} // namespace zrythm::dsp
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.
bool bipolar_
Range type for CV->CV connections, where the destination port is used for modulating parameters.
std::optional< std::pair< uint8_t, uint8_t > > source_ch_to_destination_ch_mapping_
Optional source channel to destination channel mapping.