6#include "dsp/port_connection.h"
7#include "utils/icloneable.h"
10#include <nlohmann/json_fwd.hpp>
18class PortConnectionsManager :
public QObject
25 using ConnectionsVector = std::vector<PortConnection *>;
27 explicit PortConnectionsManager (QObject * parent =
nullptr);
36 using ConnectionHashTable = std::unordered_map<PortUuid, ConnectionsVector>;
68 int get_sources (ConnectionsVector * arr,
const PortUuid &
id)
const
73 int get_dests (ConnectionsVector * arr,
const PortUuid &
id)
const
78 int get_num_sources (
const PortUuid &
id)
const
80 return get_sources (
nullptr,
id);
82 int get_num_dests (
const PortUuid &
id)
const
84 return get_dests (
nullptr,
id);
87 auto get_connection_count () const noexcept {
return connections_.size (); }
102 ConnectionsVector * arr,
126 bool connection_exists (
const PortUuid &src,
const PortUuid &dest)
const
141 const PortUuid &dest,
156 const PortUuid &dest,
164 const PortConnection *
200 bool contains_connection (
const PortConnection &conn)
const;
202 void print_ht (
const ConnectionHashTable &ht);
206 friend void init_from (
207 PortConnectionsManager &obj,
208 const PortConnectionsManager &other,
213 connections_.clear ();
217 auto &connections ()
const {
return connections_; }
220 friend void to_json (nlohmann::json &j,
const PortConnectionsManager &pcm);
221 friend void from_json (
const nlohmann::json &j, PortConnectionsManager &pcm);
223 void add_or_replace_connection (
224 ConnectionHashTable &ht,
226 const PortConnection &conn);
232 std::vector<utils::QObjectUniquePtr<PortConnection>> connections_;
240 ConnectionHashTable src_ht_;
248 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...
A unique pointer for QObject objects that also works with QObject-based ownership.