forked from sudip-mondal-2002/Amplitron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_clear.h
More file actions
44 lines (36 loc) · 1.03 KB
/
Copy pathcommand_clear.h
File metadata and controls
44 lines (36 loc) · 1.03 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
43
44
#pragma once
#include "gui/commands/command_base.h"
#include "audio/engine/audio_engine.h"
#include "audio/effects/effect.h"
#include <vector>
namespace Amplitron {
/**
* @brief Command that removes every effect from the signal chain at once.
*
* Captures the full chain state before clearing so that undo() can restore it.
*/
class ClearAllCommand : public Command {
public:
explicit ClearAllCommand(AudioEngine& engine)
: engine_(engine) {
for (auto& fx : engine_.effects()) {
saved_.push_back(fx);
}
}
bool execute() override {
while (!engine_.effects().empty()) {
engine_.remove_effect(static_cast<int>(engine_.effects().size()) - 1);
}
return true;
}
void undo() override {
for (auto& fx : saved_) {
engine_.add_effect(fx);
}
}
const char* description() const override { return "Clear All"; }
private:
AudioEngine& engine_;
std::vector<std::shared_ptr<Effect>> saved_;
};
} // namespace Amplitron