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-01 11:15:25 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           30 :     explicit ClearAllCommand(AudioEngine& engine)
      18           24 :         : 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              :     AudioEngine& engine_;
      41              :     std::vector<std::shared_ptr<Effect>> saved_;
      42              : };
      43              : 
      44              : } // namespace Amplitron
        

Generated by: LCOV version 2.0-1