Deluge Firmware 1.3.0
Build date: 2025.06.05
Loading...
Searching...
No Matches
submenu.h
1/*
2 * Copyright © 2017-2023 Synthstrom Audible Limited
3 *
4 * This file is part of The Synthstrom Audible Deluge Firmware.
5 *
6 * The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software Foundation,
8 * either version 3 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with this program.
15 * If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include "gui/menu_item/menu_item.h"
21#include "gui/ui/sound_editor.h"
22#include "menu_item.h"
23#include "util/containers.h"
24#include <initializer_list>
25#include <span>
26
27namespace deluge::gui::menu_item {
28
29class Submenu : public MenuItem {
30public:
31 enum RenderingStyle { VERTICAL, HORIZONTAL };
32
33 Submenu(l10n::String newName, std::initializer_list<MenuItem*> newItems)
34 : MenuItem(newName), items{newItems}, current_item_{items.end()} {}
35 Submenu(l10n::String newName, std::span<MenuItem*> newItems)
36 : MenuItem(newName), items{newItems.begin(), newItems.end()}, current_item_{items.end()} {}
37 Submenu(l10n::String newName, l10n::String title, std::initializer_list<MenuItem*> newItems)
38 : MenuItem(newName, title), items{newItems}, current_item_{items.end()} {}
39 Submenu(l10n::String newName, l10n::String title, std::span<MenuItem*> newItems)
40 : MenuItem(newName, title), items{newItems.begin(), newItems.end()}, current_item_{items.end()} {}
41 Submenu(l10n::String newName, std::span<MenuItem*> newItems, int32_t newThingIndex)
42 : MenuItem(newName), items{newItems.begin(), newItems.end()}, current_item_{items.end()},
43 thingIndex(newThingIndex) {}
44 Submenu(l10n::String newName, std::initializer_list<MenuItem*> newItems, int32_t newThingIndex)
45 : MenuItem(newName), items{newItems}, current_item_{items.end()}, thingIndex(newThingIndex) {}
46
47 void beginSession(MenuItem* navigatedBackwardFrom = nullptr) override;
48 void updateDisplay();
49 void selectEncoderAction(int32_t offset) final;
50 MenuItem* selectButtonPress() final;
51 ActionResult buttonAction(deluge::hid::Button b, bool on, bool inCardRoutine) override;
52 void readValueAgain() final { updateDisplay(); }
53 void unlearnAction() final;
54 bool usesAffectEntire() override;
55 bool allowsLearnMode() final;
56 void learnKnob(MIDICable* cable, int32_t whichKnob, int32_t modKnobMode, int32_t midiChannel) final;
57 void learnProgramChange(MIDICable& cable, int32_t channel, int32_t programNumber) override;
58 bool learnNoteOn(MIDICable& cable, int32_t channel, int32_t noteCode) final;
59 virtual RenderingStyle renderingStyle() const { return RenderingStyle::VERTICAL; };
60 void renderInHorizontalMenu(int32_t startX, int32_t width, int32_t startY, int32_t height) override;
61 void drawPixelsForOled() override;
62 void drawSubmenuItemsForOled(std::span<MenuItem*> options, const int32_t selectedOption);
65 bool wrapAround();
66 bool isSubmenu() override { return true; }
67 virtual bool focusChild(const MenuItem* child);
68 void updatePadLights() override;
69 MenuItem* patchingSourceShortcutPress(PatchSource s, bool previousPressStillActive = false) override;
71 uint32_t getParamIndex() override;
72 std::optional<uint8_t> getThingIndex() { return thingIndex; }
73
74protected:
75 std::optional<uint8_t> thingIndex = std::nullopt;
76 uint32_t initial_index_ = 0;
77 deluge::vector<MenuItem*> items;
78 typename decltype(items)::iterator current_item_;
79
80private:
81 bool shouldForwardButtons();
82};
83
84class HorizontalMenu : public Submenu {
85public:
86 enum Layout { FIXED, DYNAMIC };
87 struct PageInfo {
88 public:
89 int32_t number;
90 int32_t itemsWidthScaling;
91 std::vector<MenuItem*> items;
92 };
93 struct Paging {
94 public:
95 int32_t visiblePageNumber;
96 int32_t selectedItemPositionOnPage;
97 std::vector<PageInfo> pages;
98 PageInfo& getVisiblePage() { return pages[visiblePageNumber]; }
99 };
100
101 using Submenu::Submenu;
102
103 HorizontalMenu(l10n::String newName, std::span<MenuItem*> newItems, Layout layout)
104 : Submenu(newName, newItems), horizontalMenuLayout(layout), paging{} {}
105 HorizontalMenu(l10n::String newName, std::initializer_list<MenuItem*> newItems, Layout layout)
106 : Submenu(newName, newItems), horizontalMenuLayout(layout), paging{} {}
107 HorizontalMenu(l10n::String newName, l10n::String newTitle, std::initializer_list<MenuItem*> newItems,
108 Layout layout)
109 : Submenu(newName, newTitle, newItems), horizontalMenuLayout(layout), paging{} {}
110
111 RenderingStyle renderingStyle() const override;
112 ActionResult buttonAction(deluge::hid::Button b, bool on, bool inCardRoutine) override;
113 void renderOLED() override;
114 void drawPixelsForOled() override;
115 void endSession() override;
116
117protected:
118 HorizontalMenu::Paging paging;
119 int32_t lastSelectedHorizontalMenuItemPosition = kNoSelection;
120 Layout horizontalMenuLayout = Layout::DYNAMIC;
121
122private:
123 ActionResult selectHorizontalMenuItemOnVisiblePage(int32_t selectedColumn);
124 ActionResult switchVisiblePage(int32_t direction);
125 void updateSelectedHorizontalMenuItemLED(int32_t itemNumber);
126 HorizontalMenu::Paging splitMenuItemsByPages();
127 int32_t calcPageItemsWidthScaling(int32_t totalItemsSpan, std::vector<MenuItem*>& pageItems,
128 bool isLastPage = false) const;
129};
130
131} // namespace deluge::gui::menu_item
A MIDI cable connection. Stores all state specific to a given cable and its contained ports and chann...
Definition midi_device.h:94
Base class for all menu items.
Definition menu_item.h:39
deluge::l10n::String title
Can get overridden by getTitle(). Actual max num chars for OLED display is 14.
Definition menu_item.h:211
ActionResult selectHorizontalMenuItemOnVisiblePage(int32_t selectedColumn)
Selects the menu item covering the given virtual column on the visible page.
Definition submenu.cpp:410
void drawPixelsForOled() override
Paints the pixels below the standard title block.
Definition submenu.cpp:125
void updateSelectedHorizontalMenuItemLED(int32_t itemNumber)
When updating the selected horizontal menu item, you need to refresh the lit instrument LED's.
Definition submenu.cpp:522
void renderOLED() override
Root rendering routine for OLED.
Definition submenu.cpp:117
ActionResult buttonAction(deluge::hid::Button b, bool on, bool inCardRoutine) override
Handle an arbitrary button.
Definition submenu.cpp:347
void endSession() override
Definition submenu.cpp:554
Definition submenu.h:29
bool learnNoteOn(MIDICable &cable, int32_t channel, int32_t noteCode) final
Attempt to bind this menu item to a note code.
Definition submenu.cpp:608
bool allowsLearnMode() final
Used by SoundEditor to determine if the current menu item can accept MIDI learning.
Definition submenu.cpp:590
void readValueAgain() final
Re-read the value from the system and redraw the display to match.
Definition submenu.h:52
bool wrapAround()
Indicates if the menu-like object should wrap-around. Destined to be virtualized. At the moment imple...
Definition submenu.cpp:254
void unlearnAction() final
Unlearn the parameter controlled by this menu.
Definition submenu.cpp:584
void drawPixelsForOled() override
Paints the pixels below the standard title block.
Definition submenu.cpp:76
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition submenu.cpp:631
ActionResult buttonAction(deluge::hid::Button b, bool on, bool inCardRoutine) override
Handle an arbitrary button.
Definition submenu.cpp:338
void learnKnob(MIDICable *cable, int32_t whichKnob, int32_t modKnobMode, int32_t midiChannel) final
Definition submenu.cpp:597
deluge::modulation::params::Kind getParamKind() override
Definition submenu.cpp:566
void selectEncoderAction(int32_t offset) final
Handle select encoder movement.
Definition submenu.cpp:258
void beginSession(MenuItem *navigatedBackwardFrom=nullptr) override
Begin an editing session with this menu item.
Definition submenu.cpp:14
uint32_t getParamIndex() override
Definition submenu.cpp:575
MenuItem * selectButtonPress() final
Handle a select button press.
Definition submenu.cpp:329
MenuItem * patchingSourceShortcutPress(PatchSource s, bool previousPressStillActive=false) override
Action to take when a source shortcut is pressed.
Definition submenu.cpp:641
Kind
Definition param.h:42