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