LCOV - code coverage report
Current view: top level - src/gui/views - gui_presets.h (source / functions) Coverage Total Hit
Test: merged.info Lines: 100.0 % 6 6
Test Date: 2026-06-07 15:51:50 Functions: 100.0 % 6 6

            Line data    Source code
       1              : #pragma once
       2              : 
       3              : #include <string>
       4              : #include <vector>
       5              : 
       6              : #include "audio/engine/i_audio_engine.h"
       7              : #include "gui/commands/command_history.h"
       8              : #include "preset_manager.h"
       9              : 
      10              : namespace Amplitron {
      11              : 
      12              : class PedalBoard;
      13              : class IMidiManager;
      14              : 
      15              : /**
      16              :  * @brief Handles preset save/load/delete UI and logic.
      17              :  * Extracted from GuiManager for single-responsibility.
      18              :  */
      19              : class GuiPresets {
      20              :    public:
      21              :     /**
      22              :      * @brief Construct a GuiPresets helper for the given audio engine and undo history.
      23              :      * @param engine Reference to the engine used for preset state capture.
      24              :      * @param history Shared command history for undo/redo integration.
      25              :      */
      26              :     GuiPresets(IAudioEngine& engine, CommandHistory& history, IPresetManager& presets);
      27              : 
      28              :     /** @brief Render save preset popup. Only call when show is true. */
      29              :     void render_save_popup(bool& show);
      30              : 
      31              :     /** @brief Render load preset popup. Only call when show is true. */
      32              :     void render_load_popup(bool& show);
      33              : 
      34              :     /** @brief Initialize dialog for "New Preset" (clears fields). */
      35              :     void begin_new_preset();
      36              : 
      37              :     /** @brief Initialize dialog for "Save Preset" (preserves current name). */
      38              :     void begin_save_preset();
      39              : 
      40              :     /** @brief Set the pedal board pointer (for rebuild_widgets calls). */
      41           15 :     void set_pedal_board(PedalBoard* pb) { pedal_board_ = pb; }
      42              : 
      43              :     /** @brief Set the MidiManager pointer (for saving/loading midi mappings). */
      44           15 :     void set_midi_manager(IMidiManager* m) { midi_manager_ = m; }
      45              : 
      46              :     // Preset management methods
      47              :     void refresh_presets(bool preserve_selection = true);
      48              :     bool save_named_preset(const std::string& preset_name, const std::string& description);
      49              :     bool load_preset_by_index(int index);
      50              :     bool load_preset_by_path(const std::string& path);
      51              :     bool delete_preset_by_index(int index);
      52              :     void ensure_factory_presets();
      53              : 
      54              :     // Accessors for menu bar integration
      55           12 :     int selected_preset_index() const { return selected_preset_index_; }
      56           39 :     int preset_count() const { return static_cast<int>(preset_files_.size()); }
      57           10 :     const std::string& status_message() const { return preset_status_msg_; }
      58            3 :     void set_status_message(const std::string& msg) { preset_status_msg_ = msg; }
      59              : 
      60              :     /** @brief Return true if the current engine state differs from the last saved preset. */
      61              :     bool is_dirty() const;
      62              : 
      63              :     /** @brief Return the current preset name or "Untitled" if unset. */
      64              :     std::string current_preset_name() const;
      65              : 
      66              :     /** @brief Serialise the current engine state to a JSON string for clipboard export. */
      67              :     std::string serialise_current_preset_to_json() const;
      68              : 
      69              :     /** @brief Record the current engine state as the clean saved preset state. */
      70              :     void mark_clean();
      71              : 
      72              :    private:
      73              :     std::string preset_name_from_path(const std::string& filepath) const;
      74              :     std::string preset_path_from_name(const std::string& preset_name) const;
      75              : 
      76              :     IAudioEngine& engine_;
      77              :     CommandHistory& history_;
      78              :     IPresetManager& presets_;
      79              :     PresetData saved_state_;
      80              :     bool saved_state_valid_ = false;
      81              :     PedalBoard* pedal_board_ = nullptr;
      82              :     IMidiManager* midi_manager_ = nullptr;
      83              : 
      84              :     // Preset UI state
      85              :     char preset_name_buf_[128] = "My Preset";
      86              :     char preset_desc_buf_[256] = "";
      87              :     std::vector<std::string> preset_files_;
      88              :     int selected_preset_index_ = -1;
      89              :     bool factory_presets_initialized_ = false;
      90              :     bool preset_dialog_is_new_ = false;
      91              :     std::string preset_status_msg_;
      92              : };
      93              : 
      94              : }  // namespace Amplitron
        

Generated by: LCOV version 2.0-1