Line data Source code
1 : #pragma once
2 :
3 : #include <set>
4 :
5 : #include "audio/engine/i_audio_engine.h"
6 : #include "common.h"
7 : #include "gui/commands/command_history.h"
8 :
9 : namespace Amplitron {
10 :
11 : class PedalWidget;
12 : class GuiMidi;
13 :
14 : /**
15 : * @brief Visual representation of the audio effect signal chain.
16 : *
17 : * Renders a horizontal strip of PedalWidget instances, an "Add Pedal" menu,
18 : * and drag-and-drop reordering. All structural changes (add, remove, reorder)
19 : * are routed through CommandHistory for undo/redo support.
20 : */
21 : class PedalBoard {
22 : friend class TestAccessor;
23 :
24 : public:
25 : /**
26 : * @brief Construct the pedal board.
27 : * @param engine Reference to the audio engine that owns the effect chain.
28 : * @param history Reference to the shared command history for undo/redo.
29 : * @param gui_midi Optional GuiMidi pointer for MIDI learn on initial widgets.
30 : */
31 : PedalBoard(IAudioEngine& engine, CommandHistory& history, GuiMidi* gui_midi = nullptr);
32 :
33 : /** @brief Destructor. */
34 : ~PedalBoard();
35 :
36 : /** @brief Render the toolbar and signal chain each frame. */
37 : void render();
38 :
39 : /** @brief Recreate PedalWidget instances from the current engine effect list.
40 : * Preserves visibility of effects already on the board by tracking effect pointer
41 : * identity; new effects (e.g. after preset load or add) are shown only if enabled. */
42 : void rebuild_widgets();
43 :
44 : /** @brief Whether only enabled pedals are shown (default true). */
45 3 : bool show_active_only() const { return show_active_only_; }
46 :
47 : /** @brief Inject a GuiMidi pointer to propagate to PedalWidgets. */
48 : void set_gui_midi(GuiMidi* gm) { gui_midi_ = gm; }
49 :
50 : private:
51 : /** @brief Render the "+ Add Pedal" button and its popup menu. */
52 : void render_add_pedal_menu();
53 :
54 : /** @brief Render the amp model selector dropdown. */
55 : void render_amp_selector();
56 :
57 : /** @brief Render the MIDI status and quick actions menu. */
58 : void render_midi_menu();
59 :
60 : /** @brief Render the signal flow line, pedal widgets, and drag-and-drop targets. */
61 : void render_signal_chain();
62 :
63 : /** @brief Find the index of the current AmpSimulator in the effect chain (-1 if none). */
64 : int find_amp_index() const;
65 :
66 : /** @brief Add an effect, rebuild widgets, and mark it visible. */
67 : void add_effect_and_show(std::shared_ptr<Effect> effect);
68 :
69 : IAudioEngine& engine_;
70 : CommandHistory& history_;
71 : std::vector<std::unique_ptr<PedalWidget>> widgets_;
72 : bool show_active_only_ = true;
73 : std::set<int> visible_indices_; // Indices of pedals that should be visible
74 : GuiMidi* gui_midi_ = nullptr;
75 : bool show_confirm_reset_ = false;
76 : bool show_confirm_clear_ = false;
77 : bool show_confirm_midi_clear_ = false;
78 : };
79 :
80 : } // namespace Amplitron
|