6#include "dsp/port_connection.h"
7#include "utils/icloneable.h"
15class PortConnectionsManager :
public QObject
22 using ConnectionsVector = std::vector<PortConnection *>;
24 explicit PortConnectionsManager (QObject * parent =
nullptr);
33 using ConnectionHashTable = std::unordered_map<PortUuid, ConnectionsVector>;
35 static const auto &connection_ref_predicate (
const PortConnection * conn)
64 int get_sources (ConnectionsVector * arr,
const PortUuid &
id)
const
69 int get_dests (ConnectionsVector * arr,
const PortUuid &
id)
const
74 int get_num_sources (
const PortUuid &
id)
const
76 return get_sources (
nullptr,
id);
78 int get_num_dests (
const PortUuid &
id)
const
80 return get_dests (
nullptr,
id);
83 auto get_connection_count () const noexcept {
return connections_.size (); }
98 ConnectionsVector * arr,
122 bool connection_exists (
const PortUuid &src,
const PortUuid &dest)
const
137 const PortUuid &dest,
152 const PortUuid &dest,
160 const PortConnection *
196 bool contains_connection (
const PortConnection &conn)
const;
198 void print_ht (
const ConnectionHashTable &ht);
202 friend void init_from (
203 PortConnectionsManager &obj,
204 const PortConnectionsManager &other,
209 connections_.clear ();
213 auto &get_connections ()
const {
return connections_; }
216 static constexpr auto kConnectionsKey =
"connections"sv;
217 friend void to_json (nlohmann::json &j,
const PortConnectionsManager &pcm)
219 j[kConnectionsKey] = pcm.connections_;
221 friend void from_json (
const nlohmann::json &j, PortConnectionsManager &pcm)
223 for (
const auto &conn_json : j.at (kConnectionsKey))
225 auto * conn =
new PortConnection (&pcm);
226 from_json (conn_json, *conn);
227 pcm.connections_.push_back (conn);
229 pcm.regenerate_hashtables ();
232 void add_or_replace_connection (
233 ConnectionHashTable &ht,
235 const PortConnection &conn);
241 std::vector<PortConnection *> connections_;
249 ConnectionHashTable src_ht_;
257 ConnectionHashTable dest_ht_;
A connection between two ports.
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.
PortConnection * get_connection(const PortUuid &src, const PortUuid &dest) const
void regenerate_hashtables()
Regenerates the hash tables.
void reset_connections_from_other(const PortConnectionsManager *other)
Removes all connections from this.
bool update_connection(const PortConnection &before, const PortConnection &after)
Replaces the given before connection with after.
int get_sources_or_dests(ConnectionsVector *arr, const PortUuid &id, bool sources) const
Adds the sources/destinations of id in the given array.
PortConnection * get_source_or_dest(const PortUuid &id, bool sources) const
Wrapper over get_sources_or_dests() that returns the first connection.
bool remove_connection(const PortUuid &src, const PortUuid &dest)
Removes the connection for the given ports if it exists.
const PortConnection * add_default_connection(const PortUuid &src, const PortUuid &dest, bool locked)
Overload for default settings (multiplier = 1.0, enabled = true).
int get_unlocked_sources_or_dests(ConnectionsVector *arr, const PortUuid &id, bool sources) const
Adds the sources/destinations of id in the given array.
void remove_all_connections(const PortUuid &pi)
Disconnect all sources and dests of the given port identifier.
const PortConnection * add_connection(const PortUuid &src, const PortUuid &dest, float multiplier, bool locked, bool enabled)
Stores the connection for the given ports if it doesn't exist, otherwise updates the existing connect...