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