Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
route_track_command.h
1// SPDX-FileCopyrightText: © 2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <utility>
7
8#include "structure/tracks/track_all.h"
9#include "structure/tracks/track_routing.h"
10
11#include <QUndoCommand>
12
13namespace zrythm::commands
14{
18class RouteTrackCommand : public QUndoCommand
19{
20public:
21 static constexpr auto CommandId = 6451638;
22
23 RouteTrackCommand (
26 std::optional<structure::tracks::Track::Uuid> target_id)
27 : QUndoCommand (QObject::tr ("Route Track")), router_ (router),
28 source_id_ (source_id), target_id_ (target_id)
29 {
30 }
31
32 int id () const override { return CommandId; }
33
34 void undo () override
35 {
36 // restore previous routing
37
38 const auto prev_target = target_id_;
39
40 // re-store current target
41 const auto cur_target = router_.get_output_track (source_id_);
42 if (cur_target.has_value ())
43 {
44 target_id_ = cur_target->id ();
45 }
46 else
47 {
48 target_id_ = std::nullopt;
49 }
50
51 // replace
52 if (prev_target.has_value ())
53 {
54 router_.add_or_replace_route (source_id_, prev_target.value ());
55 }
56 else
57 {
58 router_.remove_route_for_source (source_id_);
59 }
60 }
61 void redo () override
62 {
63 // get new target
64 const auto new_target = target_id_;
65
66 // store previous target
67 const auto prev_target = router_.get_output_track (source_id_);
68 if (prev_target.has_value ())
69 {
70 target_id_ = prev_target->id ();
71 }
72 else
73 {
74 target_id_ = std::nullopt;
75 }
76
77 // replace
78 if (new_target.has_value ())
79 {
80 router_.add_or_replace_route (source_id_, new_target.value ());
81 }
82 else
83 {
84 router_.remove_route_for_source (source_id_);
85 }
86 }
87
88private:
91 std::optional<structure::tracks::Track::Uuid> target_id_;
92};
93
94} // namespace zrythm::commands
Management of track-to-track connections.