Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
port_connection_action.h
1// SPDX-FileCopyrightText: © 2020-2021, 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "dsp/port_connection.h"
7#include "gui/backend/backend/actions/undoable_action.h"
8#include "utils/icloneable.h"
9
10namespace zrythm::gui::actions
11{
12
13class PortConnectionAction : public QObject, public UndoableAction
14{
15 Q_OBJECT
16 QML_ELEMENT
17 DEFINE_UNDOABLE_ACTION_QML_PROPERTIES (PortConnectionAction)
18
19public:
20 enum class Type
21 {
22 Connect,
23 Disconnect,
24 Enable,
25 Disable,
26 ChangeMultiplier,
27 };
28
29 using PortType = dsp::PortType;
30 using PortUuid = dsp::PortUuid;
31
32public:
33 PortConnectionAction (QObject * parent = nullptr);
34
35 PortConnectionAction (
36 Type type,
37 PortUuid src_id,
38 PortUuid dest_id,
39 float new_val);
40
41 ~PortConnectionAction () override = default;
42
43 QString to_string () const override;
44
45 friend void init_from (
46 PortConnectionAction &obj,
47 const PortConnectionAction &other,
48 utils::ObjectCloneType clone_type);
49
50private:
51 void init_loaded_impl () override { }
52 void undo_impl () override;
53 void perform_impl () override;
54
55 void do_or_undo (bool do_it);
56
57public:
58 Type type_ = Type ();
59
61
67 float val_ = 0.f;
68};
69
70class PortConnectionConnectAction final : public PortConnectionAction
71{
72public:
73 PortConnectionConnectAction (PortUuid src_id, const PortUuid &dest_id)
74 : PortConnectionAction (Type::Connect, src_id, dest_id, 0.f)
75 {
76 }
77};
78
79class PortConnectionDisconnectAction final : public PortConnectionAction
80{
81public:
82 PortConnectionDisconnectAction (PortUuid src_id, const PortUuid &dest_id)
83 : PortConnectionAction (Type::Disconnect, src_id, dest_id, 0.f)
84 {
85 }
86};
87
88class PortConnectionEnableAction final : public PortConnectionAction
89{
90public:
91 PortConnectionEnableAction (PortUuid src_id, const PortUuid &dest_id)
92 : PortConnectionAction (Type::Enable, src_id, dest_id, 0.f)
93 {
94 }
95};
96
97class PortConnectionDisableAction final : public PortConnectionAction
98{
99public:
100 PortConnectionDisableAction (PortUuid src_id, const PortUuid &dest_id)
101 : PortConnectionAction (Type::Disable, src_id, dest_id, 0.f)
102 {
103 }
104};
105
106class PortConnectionChangeMultiplierAction final : public PortConnectionAction
107{
108public:
109 PortConnectionChangeMultiplierAction (
110 PortUuid src_id,
111 PortUuid dest_id,
112 float new_multiplier)
113 : PortConnectionAction (Type::ChangeMultiplier, src_id, dest_id, new_multiplier)
114 {
115 }
116};
117
118}; // namespace zrythm::gui::actions
QString to_string() const override
Stringizes the action to be used in Undo/Redo buttons.
float val_
Value before/after the change.
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:38