Line data Source code
1 : #pragma once
2 :
3 : #include <vector>
4 :
5 : #include "audio/effects/core/effect.h"
6 : #include "audio/engine/i_audio_engine.h"
7 : #include "gui/commands/command_base.h"
8 :
9 : namespace Amplitron {
10 :
11 : /**
12 : * @brief Command that removes every effect from the signal chain at once.
13 : *
14 : * Captures the full chain state before clearing so that undo() can restore it.
15 : */
16 : class ClearAllCommand : public Command {
17 : public:
18 24 : explicit ClearAllCommand(IAudioEngine& engine) : engine_(engine) {
19 42 : for (auto& fx : engine_.effects()) {
20 24 : saved_.push_back(fx);
21 : }
22 24 : }
23 :
24 21 : bool execute() override {
25 48 : while (!engine_.effects().empty()) {
26 27 : engine_.remove_effect(static_cast<int>(engine_.effects().size()) - 1);
27 : }
28 21 : return true;
29 : }
30 :
31 15 : void undo() override {
32 33 : for (auto& fx : saved_) {
33 24 : engine_.add_effect(fx);
34 : }
35 15 : }
36 :
37 0 : const char* description() const override { return "Clear All"; }
38 :
39 : private:
40 : IAudioEngine& engine_;
41 : std::vector<std::shared_ptr<Effect>> saved_;
42 : };
43 :
44 : } // namespace Amplitron
|