LCOV - code coverage report
Current view: top level - src/gui/views - gui_analyzer.h (source / functions) Coverage Total Hit
Test: merged.info Lines: 100.0 % 21 21
Test Date: 2026-06-03 09:13:19 Functions: 100.0 % 4 4

            Line data    Source code
       1              : #pragma once
       2              : 
       3              : #include "audio/dsp/spectrum_analyzer.h"
       4              : #include "audio/dsp/level_analyzer.h"
       5              : #include "gui/ui_component.h"
       6              : #include <imgui.h>
       7              : #include <functional>
       8              : 
       9              : namespace Amplitron {
      10              : 
      11              : enum class SpectrumDisplayMode {
      12              :     Input   = 0,
      13              :     Output  = 1,
      14              :     Overlay = 2,
      15              : };
      16              : 
      17            8 : struct SpectrumSnapshot {
      18            8 :     std::array<float, SpectrumAnalyzer::DISPLAY_BARS> smoothed_input_db{};
      19            8 :     std::array<float, SpectrumAnalyzer::DISPLAY_BARS> smoothed_output_db{};
      20            8 :     std::array<float, SpectrumAnalyzer::DISPLAY_BARS> input_peak_db{};
      21            8 :     std::array<float, SpectrumAnalyzer::DISPLAY_BARS> output_peak_db{};
      22              : };
      23              : 
      24            8 : struct AnalyzerProps {
      25              :     // VU levels (pre-calculated by LevelAnalyzer in the audio engine)
      26            8 :     float smoothed_input_rms  = 0.0f;
      27            8 :     float smoothed_output_rms = 0.0f;
      28            8 :     float input_peak_hold     = 0.0f;
      29            8 :     float output_peak_hold    = 0.0f;
      30            8 :     bool  input_clip_active   = false;
      31            8 :     bool  output_clip_active  = false;
      32            8 :     float input_clip_flash    = 0.0f;
      33            8 :     float output_clip_flash   = 0.0f;
      34              : 
      35              :     // Spectrum analyzer (pre-calculated by SpectrumAnalyzer in the audio engine)
      36              :     SpectrumSnapshot spectrum;
      37              : 
      38              :     std::function<void(bool)>                on_expanded_changed;
      39              :     std::function<void(SpectrumDisplayMode)> on_mode_changed;
      40              :     std::function<void(bool)>                on_set_analyzer_enabled;
      41              : };
      42              : 
      43              : /**
      44              :  * @brief Reactive real-time analyzer panel component.
      45              :  *
      46              :  * Receives all pre-computed level and spectrum data via AnalyzerProps.
      47              :  * Zero math or signal processing occurs here — only ImGui drawing calls.
      48              :  */
      49            6 : class GuiAnalyzer : public UIComponent<AnalyzerProps> {
      50              : public:
      51           30 :     GuiAnalyzer() = default;
      52              : 
      53              :     /** @brief Render the collapsible analyzer panel. */
      54              :     void render() override;
      55              : 
      56              :     /** @brief Height to reserve for this panel in the parent layout. */
      57            2 :     float analyzer_reserved_height() const { return expanded_ ? 245.0f : 38.0f; }
      58              : 
      59              :     SpectrumDisplayMode current_mode() const { return mode_; }
      60            2 :     bool is_expanded() const { return expanded_; }
      61           15 :     void set_expanded(bool expanded) { expanded_ = expanded; }
      62              : 
      63              : private:
      64              :     void render_vu_bar(const char* id,
      65              :                        const char* label,
      66              :                        float rms_level,
      67              :                        float peak_hold,
      68              :                        bool  clip_active,
      69              :                        float clip_flash,
      70              :                        ImU32 base_color,
      71              :                        ImU32 peak_color);
      72              : 
      73              :     void draw_spectrum(ImDrawList* dl,
      74              :                        const ImVec2& pos,
      75              :                        const ImVec2& size) const;
      76              : 
      77            6 :     bool expanded_ = true;
      78            6 :     SpectrumDisplayMode mode_ = SpectrumDisplayMode::Output;
      79              : };
      80              : 
      81              : } // namespace Amplitron
        

Generated by: LCOV version 2.0-1