Zrythm v2.0.0-alpha.1
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/qqmlintegration.h>
9
10#include <nlohmann/json_fwd.hpp>
11
12namespace zrythm::dsp
13{
14
18class PortConnection : public QObject
19{
20 Q_OBJECT
21 QML_ELEMENT
22
23public:
24 PortConnection (QObject * parent = nullptr);
25
26 PortConnection (
27 const PortUuid &src,
28 const PortUuid &dest,
29 float multiplier,
30 bool locked,
31 bool enabled,
32 QObject * parent = nullptr);
33
34 void update (float multiplier, bool locked, bool enabled)
35 {
36 multiplier_ = multiplier;
37 locked_ = locked;
38 enabled_ = enabled;
39 }
40
41 void set_bipolar (bool bipolar) { bipolar_ = bipolar; }
42
43 void set_channel_mapping (uint8_t source_channel, uint8_t destination_channel)
44 {
46 std::make_pair (source_channel, destination_channel);
47 }
48 void unset_channel_mapping ()
49 {
51 }
52
53private:
54 static constexpr std::string_view kSourceIdKey = "srcId";
55 static constexpr std::string_view kDestIdKey = "destId";
56 static constexpr std::string_view kMultiplierKey = "multiplier";
57 static constexpr std::string_view kLockedKey = "locked";
58 static constexpr std::string_view kEnabledKey = "enabled";
59 static constexpr std::string_view kBipolarKey = "bipolar";
60 static constexpr std::string_view kSourceDestMappingKey =
61 "sourceChannelToDestinationChannelMapping";
62 friend void
63 to_json (nlohmann::json &j, const PortConnection &port_connection);
64 friend void
65 from_json (const nlohmann::json &j, PortConnection &port_connection);
66
67 friend void init_from (
68 PortConnection &obj,
69 const PortConnection &other,
70 utils::ObjectCloneType clone_type);
71
72 friend bool operator== (const PortConnection &lhs, const PortConnection &rhs)
73 {
74 return lhs.src_id_ == rhs.src_id_ && lhs.dest_id_ == rhs.dest_id_;
75 }
76
77public:
78 PortUuid src_id_;
79 PortUuid dest_id_;
80
87 float multiplier_ = 1.0f;
88
95 bool locked_ = false;
96
102 bool enabled_ = true;
103
114 bool bipolar_{};
115
123 std::optional<std::pair<uint8_t, uint8_t>> source_ch_to_destination_ch_mapping_;
124
125 BOOST_DESCRIBE_CLASS (
126 PortConnection,
127 (),
128 (src_id_,
129 dest_id_,
131 locked_,
132 enabled_,
133 bipolar_,
135 (),
136 ())
137};
138
139} // 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.