LCOV - code coverage report
Current view: top level - src/gui/commands - command_clear.h (source / functions) Coverage Total Hit
Test: merged.info Lines: 92.9 % 14 13
Test Date: 2026-06-03 09:13:19 Functions: 80.0 % 5 4

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

Generated by: LCOV version 2.0-1