Line data Source code
1 : #pragma once
2 :
3 : #include <chrono>
4 :
5 : namespace Amplitron {
6 :
7 : /**
8 : * @brief Abstract base class for all undoable commands (Gang of Four Command Pattern).
9 : *
10 : * Each concrete command encapsulates a single reversible action on the audio
11 : * engine (e.g. adding an effect, changing a parameter). Commands are stored
12 : * in a CommandHistory and invoked via execute() / undo().
13 : */
14 172 : class Command {
15 : public:
16 177 : virtual ~Command() = default;
17 :
18 : /** @brief Apply this command's action. Returns true if a mutation occurred. */
19 0 : virtual bool execute() { return true; }
20 :
21 : /** @brief Reverse this command's action. */
22 : virtual void undo() = 0;
23 :
24 : /** @brief Return a short human-readable label (shown in the Edit menu). */
25 : virtual const char* description() const = 0;
26 :
27 : /**
28 : * @brief Attempt to merge @p other into this command (coalescing).
29 : *
30 : * Two commands can merge if they affect the same target within a short
31 : * time window. Returns true if this command absorbed @p other.
32 : */
33 54 : virtual bool merge_with(const Command& /*other*/) { return false; }
34 :
35 : /** @brief Return the steady-clock time point when this command was created. */
36 : auto timestamp() const { return timestamp_; }
37 :
38 : protected:
39 86 : std::chrono::steady_clock::time_point timestamp_ = std::chrono::steady_clock::now();
40 : };
41 :
42 : } // namespace Amplitron
|