Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
undoable_action.h
1// SPDX-FileCopyrightText: © 2018-2022, 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "dsp/port_connections_manager.h"
7#include "plugins/plugin.h"
8#include "utils/types.h"
9
10namespace zrythm::gui::actions
11{
12
13#define DEFINE_UNDOABLE_ACTION_QML_PROPERTIES(ClassType) \
14public: \
15 /* ================================================================ */ \
16 /* helpers */ \
17 /* ================================================================ */ \
18 Q_INVOKABLE QString getDescription () const \
19 { \
20 return to_string (); \
21 }
22
26class UndoableAction
27{
28public:
29 using PortConnectionsManager = dsp::PortConnectionsManager;
30
34 enum class Type
35 {
36 /* ---- Track/Channel ---- */
37 TracklistSelections,
38
39 ChannelSend,
40
41 /* ---- end ---- */
42
43 MixerSelections,
44 ArrangerSelections,
45
46 /* ---- connections ---- */
47
48 MidiMapping,
49 PortConnection,
50 Port,
51
52 /* ---- end ---- */
53
54 /* ---- range ---- */
55
56 Range,
57
58 /* ---- end ---- */
59
60 Transport,
61
62 Chord,
63 };
64
65 UndoableAction () = default;
66 UndoableAction (Type type);
68 Type type,
69 dsp::FramesPerTick frames_per_tick,
70 units::sample_rate_t sample_rate);
71 virtual ~UndoableAction () = default;
72
78 void init_loaded (sample_rate_t engine_sample_rate);
79
83 virtual bool needs_pause () const { return true; };
84
91 virtual bool needs_transport_total_bar_update (bool perform) const
92 {
93 return true;
94 };
95
103 virtual bool affects_audio_region_internal_positions () const { return true; }
104
110 virtual void get_plugins (std::vector<plugins::Plugin *> &plugins) { };
111
112 auto get_frames_per_tick () const { return frames_per_tick_; }
113 auto get_ticks_per_frame () const
114 {
115 return to_ticks_per_frame (get_frames_per_tick ());
116 }
117
123 void set_num_actions (int num_actions);
124
130 void save_or_load_port_connections (bool performing);
131
139 void perform ();
140
146 void undo ();
147
151 virtual QString to_string () const = 0;
152
153protected:
154 friend void init_from (
155 UndoableAction &obj,
156 const UndoableAction &other,
157 utils::ObjectCloneType clone_type);
158
159private:
161 virtual void init_loaded_impl () = 0;
162 virtual void perform_impl () = 0;
163 virtual void undo_impl () = 0;
164
166 void do_or_undo (bool perform);
167
168public:
171
173 dsp::FramesPerTick frames_per_tick_;
174
181 units::sample_rate_t sample_rate_ = 0;
182
192
197 std::unique_ptr<dsp::PortConnectionsManager> port_connections_before_;
198
200 std::unique_ptr<dsp::PortConnectionsManager> port_connections_after_;
201};
202
205class ChordAction;
208class PortAction;
210class RangeAction;
212class TransportAction;
213using UndoableActionVariant = std::variant<
224using UndoableActionPtrVariant = to_pointer_variant<UndoableActionVariant>;
225
226template <typename T>
228 std::derived_from<T, UndoableAction> && !std::is_same_v<T, UndoableAction>;
229
230}; // namespace zrythm::gui::actions
An action that performs changes to the arranger selections.
Action for channel send changes.
Action for chord pad changes.
Action for manipulating plugins (plugin slot selections in the mixer).
Base class to be inherited by implementing undoable actions.
virtual bool needs_transport_total_bar_update(bool perform) const
Returns whether the total transport bars need to be recalculated.
std::unique_ptr< dsp::PortConnectionsManager > port_connections_after_
void undo()
Undoes the action.
void set_num_actions(int num_actions)
Sets the number of actions for this action.
virtual bool needs_pause() const
Returns whether the action requires pausing the engine.
int num_actions_
Number of actions to perform.
virtual QString to_string() const =0
Stringizes the action to be used in Undo/Redo buttons.
std::unique_ptr< dsp::PortConnectionsManager > port_connections_before_
An (optional) clone of the port connections at the start of the action, used for reverting port conne...
virtual void get_plugins(std::vector< plugins::Plugin * > &plugins)
Get the plugins referenced in this action.
void perform()
Performs the action.
dsp::FramesPerTick frames_per_tick_
A snapshot of AudioEngine.frames_per_tick when the action is executed.
virtual bool affects_audio_region_internal_positions() const
Whether audio region loop/fade/etc.
Type undoable_action_type_
Undoable action type.
units::sample_rate_t sample_rate_
Sample rate of this action.
void save_or_load_port_connections(bool performing)
To be used by actions that save/load port connections.
void init_loaded(sample_rate_t engine_sample_rate)
Non virtual function following the NVI pattern.