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