Deluge Firmware 1.3.0
Build date: 2026.11.28
Loading...
Searching...
No Matches
menu_item.h
1/*
2 * Copyright © 2014-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 "definitions_cxx.hpp"
21#include "deluge/model/settings/runtime_feature_settings.h"
22#include "gui/l10n/l10n.h"
23#include "gui/l10n/strings.h"
24#include "model/mod_controllable/mod_controllable_audio.h"
25#include <span>
26
27enum class PatchingSourceShortcutTarget { PARAMETER, RANGE, PARENT };
28
29enum class MenuPermission {
30 NO,
31 YES,
32 MUST_SELECT_RANGE,
33};
34
36 uint8_t start_x{0};
37 uint8_t start_y{0};
38 uint8_t width{0};
39 uint8_t height{0};
40};
41
42class Sound;
43class MultiRange;
44class MIDICable;
45
46namespace deluge::gui::menu_item {
47class Submenu;
48class HorizontalMenu;
49} // namespace deluge::gui::menu_item
50
52class MenuItem {
53public:
54 MenuItem() : name(deluge::l10n::String::EMPTY_STRING), title(deluge::l10n::String::EMPTY_STRING) {}
55 MenuItem(deluge::l10n::String newName, deluge::l10n::String newTitle = deluge::l10n::String::EMPTY_STRING)
56 : name(newName), title(newTitle) {
57 if (newTitle == deluge::l10n::String::EMPTY_STRING) {
58 title = newName;
59 }
60 }
61
62 MenuItem(const MenuItem& other) = delete;
63 MenuItem(const MenuItem&& other) = delete;
64 MenuItem& operator=(const MenuItem& other) = delete;
65 MenuItem& operator=(const MenuItem&& other) = delete;
66
67 virtual ~MenuItem() = default;
68
71
79 virtual ActionResult buttonAction(deluge::hid::Button b, bool on, bool inCardRoutine) {
80 return ActionResult::NOT_DEALT_WITH;
81 }
82
85 virtual void horizontalEncoderAction(int32_t offset) {}
89 virtual void verticalEncoderAction(int32_t offset) {}
94 virtual void selectEncoderAction(int32_t offset) {}
98 virtual bool selectEncoderActionEditsInstrument() { return false; }
105 virtual MenuItem* selectButtonPress() { return nullptr; }
106
108 virtual ActionResult timerCallback() { return ActionResult::DEALT_WITH; }
109
113 virtual bool usesAffectEntire() { return false; }
114
118
120 virtual MenuPermission checkPermissionToBeginSession(ModControllableAudio* modControllable, int32_t whichThing,
121 MultiRange** currentRange);
125 virtual void beginSession(MenuItem* navigatedBackwardFrom = nullptr) {};
126
128 virtual void endSession();
129
131 virtual void readValueAgain() {}
133 virtual void readCurrentValue() {}
134
138
141 virtual uint8_t getIndexOfPatchedParamToBlink() { return 255; }
147 virtual deluge::modulation::params::Kind getParamKind() { return deluge::modulation::params::Kind::NONE; }
150 virtual uint32_t getParamIndex() { return 255; }
151
157 virtual uint8_t shouldBlinkPatchingSourceShortcut(PatchSource s, uint8_t* colour) { return 255; }
159 [[nodiscard]] virtual PatchingSourceShortcutTarget
160 getPatchingSourceShortcutTarget(bool previous_press_still_active) const {
161 return PatchingSourceShortcutTarget::PARAMETER;
162 }
163
176 virtual MenuItem* patchingSourceShortcutPress(PatchSource s, bool previousPressStillActive = false) {
177 return nullptr;
178 }
179
183
187 virtual void learnKnob(MIDICable* cable, int32_t whichKnob, int32_t modKnobMode, int32_t midiChannel) {}
188
190 virtual bool allowsLearnMode() { return false; }
195 virtual bool learnNoteOn(MIDICable& cable, int32_t channel, int32_t noteCode) { return false; }
196
197 virtual void learnProgramChange(MIDICable& cable, int32_t channel, int32_t programNumber) {}
198 virtual void learnCC(MIDICable& cable, int32_t channel, int32_t ccNumber, int32_t value);
199
202 virtual bool shouldBlinkLearnLed() { return false; }
203
205 virtual void unlearnAction() {}
206
208 virtual bool isRangeDependent() { return false; }
209
213
218 virtual void renderOLED();
220 virtual void drawPixelsForOled() {}
221
227
229 deluge::l10n::String title;
230
238 [[nodiscard]] virtual std::string_view getTitle() const { return deluge::l10n::getView(title); }
239
250 virtual uint8_t shouldDrawDotOnName() { return 255; }
251
255 virtual void drawName();
256
260 const deluge::l10n::String name;
264 [[nodiscard]] virtual std::string_view getName() const { return deluge::l10n::getView(name); }
265
271 virtual bool isRelevant(ModControllableAudio* modControllable, int32_t whichThing) const { return true; }
272
274 static void drawItemsForOled(std::span<std::string_view> options, int32_t selectedOption, int32_t offset = 0);
275
277 virtual bool shouldEnterSubmenu() { return true; }
278
280 // length = spacing before (4 pixels)
281 // + width of icon (7 pixels)
282 // + spacing after (3 pixels)
283 // spacing before is to ensure that menu item text doesn't overlap and can scroll
284 virtual int32_t getSubmenuItemTypeRenderLength() { return (4 + kSubmenuIconSpacingX + 3); }
285 // icon is rendered 10 pixels from right edge of the display (7px icon width + 3px from edge)
286 virtual int32_t getSubmenuItemTypeRenderIconStart() { return (OLED_MAIN_WIDTH_PIXELS - kSubmenuIconSpacingX - 3); }
287 // render the submenu item type (icon or value)
288 virtual void renderSubmenuItemTypeForOled(int32_t yPixel);
289 virtual bool isSubmenu() { return false; }
290 virtual void setupNumberEditor() {}
291 virtual void updatePadLights();
292
300 virtual void getColumnLabel(StringBuf& label) { label.append(getName().data()); }
301
305 [[nodiscard]] virtual bool showColumnLabel() const { return true; }
306
310 [[nodiscard]] virtual int32_t getOccupiedSlots() const { return 1; };
311
315 [[nodiscard]] virtual bool showNotification() const { return true; }
316
320 [[nodiscard]] virtual bool allowToBeginSessionFromHorizontalMenu() { return false; }
321
325 virtual void getNotificationValue(StringBuf& valueBuf) {}
326
327 virtual void renderInHorizontalMenu(const SlotPosition& slot) {};
328
329 deluge::gui::menu_item::HorizontalMenu* parent{nullptr};
330
331 virtual bool selectEncoderActionIsPermitted() { return true; }
332
334};
335
336#define NO_NAVIGATION ((MenuItem*)0xFFFFFFFF)
337
340bool isItemRelevant(MenuItem* item);
A MIDI cable connection. Stores all state specific to a given cable and its contained ports and chann...
Definition midi_device.h:96
Base class for all menu items.
Definition menu_item.h:52
virtual std::string_view getTitle() const
Get the title to be used when rendering on OLED, both as a deluge::gui::menu_item::Submenu and when d...
Definition menu_item.h:238
virtual void endSession()
End an editing session with this menu item.
Definition menu_item.cpp:82
virtual void readValueAgain()
Re-read the value from the system and redraw the display to match.
Definition menu_item.h:131
virtual MenuPermission checkPermissionToBeginSession(ModControllableAudio *modControllable, int32_t whichThing, MultiRange **currentRange)
Double-check that this MenuItem will work with the currently selected sound range.
Definition menu_item.cpp:27
virtual ActionResult timerCallback()
Handle a TimerName::UI_SPECIFIC event.
Definition menu_item.h:108
virtual void getNotificationValue(StringBuf &valueBuf)
Get the parameter value string to show in the popup.
Definition menu_item.h:325
virtual void horizontalEncoderAction(int32_t offset)
Handle horizontal encoder movement.
Definition menu_item.h:85
virtual void verticalEncoderAction(int32_t offset)
Handle vertical encoder movement.
Definition menu_item.h:89
virtual bool allowsLearnMode()
Used by SoundEditor to determine if the current menu item can accept MIDI learning.
Definition menu_item.h:190
virtual MenuItem * patchingSourceShortcutPress(PatchSource s, bool previousPressStillActive=false)
Action to take when a source shortcut is pressed.
Definition menu_item.h:176
virtual bool shouldBlinkLearnLed()
Definition menu_item.h:202
virtual MenuItem * selectButtonPress()
Handle a select button press.
Definition menu_item.h:105
virtual int32_t getOccupiedSlots() const
Get the number of occupied slots in Horizontal menu.
Definition menu_item.h:310
virtual bool allowToBeginSessionFromHorizontalMenu()
Allow entering menu session by selecting the menu item twice in Horizontal menu.
Definition menu_item.h:320
deluge::l10n::String title
Can get overridden by getTitle(). Actual max num chars for OLED display is 14.
Definition menu_item.h:229
virtual bool usesAffectEntire()
Claim support for Kit AFFECT_ENTIRE editing.
Definition menu_item.h:113
virtual bool selectEncoderActionEditsInstrument()
Used by the sound editor to mark the current instrument as edited when the select encoder is scrolled...
Definition menu_item.h:98
virtual bool shouldEnterSubmenu()
Check if selecting this menu item (with select encoder) should enter a submenu.
Definition menu_item.h:277
virtual void learnKnob(MIDICable *cable, int32_t whichKnob, int32_t modKnobMode, int32_t midiChannel)
Definition menu_item.h:187
virtual void drawPixelsForOled()
Paints the pixels below the standard title block.
Definition menu_item.h:220
virtual bool learnNoteOn(MIDICable &cable, int32_t channel, int32_t noteCode)
Attempt to bind this menu item to a note code.
Definition menu_item.h:195
virtual PatchingSourceShortcutTarget getPatchingSourceShortcutTarget(bool previous_press_still_active) const
Describe shortcut routing without changing the selected source or destination.
Definition menu_item.h:160
virtual bool isRangeDependent()
Returns true if this parameter is only relevant to some note ranges.
Definition menu_item.h:208
virtual uint32_t getParamIndex()
Definition menu_item.h:150
virtual bool isRelevant(ModControllableAudio *modControllable, int32_t whichThing) const
Check if this MenuItem should show up in a containing deluge::gui::menu_item::Submenu.
Definition menu_item.h:271
virtual deluge::modulation::params::Kind getParamKind()
Definition menu_item.h:147
const deluge::l10n::String name
Default name for use on OLED for deluge::gui::menu_item::Submenu s.
Definition menu_item.h:260
virtual ActionResult buttonAction(deluge::hid::Button b, bool on, bool inCardRoutine)
Handle an arbitrary button.
Definition menu_item.h:79
virtual int32_t getSubmenuItemTypeRenderLength()
Handle rendering of submenu item types.
Definition menu_item.h:284
virtual uint8_t getIndexOfPatchedParamToBlink()
Definition menu_item.h:141
virtual bool showNotification() const
Show a popup with the full name and value of the editing parameter at the top of Horizontal menu.
Definition menu_item.h:315
virtual std::string_view getName() const
Get the actual name for use on OLED for deluge::gui::menu_item::Submenu s.
Definition menu_item.h:264
virtual void unlearnAction()
Unlearn the parameter controlled by this menu.
Definition menu_item.h:205
virtual void readCurrentValue()
Like readValueAgain, but does not redraw.
Definition menu_item.h:133
virtual uint8_t shouldDrawDotOnName()
Get the "draw dot state".
Definition menu_item.h:250
virtual uint8_t shouldBlinkPatchingSourceShortcut(PatchSource s, uint8_t *colour)
Definition menu_item.h:157
virtual void renderOLED()
Root rendering routine for OLED.
Definition menu_item.cpp:37
static void drawItemsForOled(std::span< std::string_view > options, int32_t selectedOption, int32_t offset=0)
Internal helper which can draw the standard deluge::gui::menu_item::Submenu layout.
Definition menu_item.cpp:48
virtual void beginSession(MenuItem *navigatedBackwardFrom=nullptr)
Begin an editing session with this menu item.
Definition menu_item.h:125
virtual void selectEncoderAction(int32_t offset)
Handle select encoder movement.
Definition menu_item.h:94
virtual void drawName()
Draw the name we want to use when selecting this in a deluge::gui::menu_item::Submenu to the 7SEG.
Definition menu_item.cpp:43
virtual bool showColumnLabel() const
Show a label for the parameter in Horizontal menu.
Definition menu_item.h:305
Definition mod_controllable_audio.h:47
Definition multi_range.h:23
Definition sound.h:78
Definition d_stringbuf.h:16
Kind
Definition param.h:42
Definition menu_item.h:35