Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
track_routing.h
1// SPDX-FileCopyrightText: © 2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "structure/tracks/track.h"
7
8namespace zrythm::structure::tracks
9{
13class TrackRouting : public QObject
14{
15 Q_OBJECT
16 QML_ELEMENT
17 QML_UNCREATABLE ("")
18public:
19 TrackRouting (TrackRegistry &track_registry, QObject * parent = nullptr)
20 : QObject (parent), track_registry_ (track_registry)
21 {
22 }
23
24 // ========================================================================
25 // QML Interface
26 // ========================================================================
27
28 Q_INVOKABLE QVariant getOutputTrack (const Track * source) const;
29
30 Q_INVOKABLE void
31 setOutputTrack (const Track * source, const Track * destination);
32
36 Q_SIGNAL void routingChanged ();
37
38 // ========================================================================
39
40 void
41 add_or_replace_route (const TrackUuid &source, const TrackUuid &destination)
42 {
43 track_routes_.insert_or_assign (source, destination);
44 Q_EMIT routingChanged ();
45 }
46 void remove_route_for_source (const TrackUuid &source)
47 {
48 track_routes_.erase (source);
49 Q_EMIT routingChanged ();
50 }
51 void remove_routes_for_destination (const TrackUuid &destination)
52 {
53 std::erase_if (track_routes_, [&destination] (const auto &kv) {
54 return kv.second == destination;
55 });
56 Q_EMIT routingChanged ();
57 }
58
59 std::optional<TrackUuidReference>
60 get_output_track (const TrackUuid &source) const;
61
62private:
63 static constexpr auto kTrackRoutesKey = "trackRoutes"sv;
64 friend void to_json (nlohmann::json &j, const TrackRouting &t)
65 {
66 j[kTrackRoutesKey] = t.track_routes_;
67 }
68 friend void from_json (const nlohmann::json &j, TrackRouting &t)
69 {
70 j.at (kTrackRoutesKey).get_to (t.track_routes_);
71 }
72
73private:
74 TrackRegistry &track_registry_;
75
79 std::unordered_map<TrackUuid, TrackUuid> track_routes_;
80};
81} // namespace zrythm::structure::tracks
Q_SIGNAL void routingChanged()
Emitted when a change was made in the routing.
Represents a track in the project.
Definition track.h:54