Deluge Firmware 1.3.0
Build date: 2025.10.19
Loading...
Searching...
No Matches
ui.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 "gui/colour/colour.h"
22#include "hid/button.h"
23#include "hid/display/oled_canvas/canvas.h"
24
25class ClipMinder;
26class MIDICable;
27class RootUI;
28class TimelineView;
29
30extern uint32_t currentUIMode;
31extern bool pendingUIRenderingLock;
32
33// Exclusive UI modes - only one of these can be active at a time.
34#define UI_MODE_NONE 0
35#define UI_MODE_HORIZONTAL_ZOOM 2
36#define UI_MODE_VERTICAL_SCROLL 1
37#define UI_MODE_INSTRUMENT_CLIP_COLLAPSING 4
38#define UI_MODE_INSTRUMENT_CLIP_EXPANDING 5
39#define UI_MODE_NOTEROWS_EXPANDING_OR_COLLAPSING 7
40#define UI_MODE_CLIP_PRESSED_IN_SONG_VIEW 9
41#define UI_MODE_MIDI_LEARN 11
42#define UI_MODE_NOTES_PRESSED 12
43#define UI_MODE_SCALE_MODE_BUTTON_PRESSED 14
44#define UI_MODE_SOLO_BUTTON_HELD 15
45// Gaps here
46#define UI_MODE_WAITING_FOR_NEXT_FILE_TO_LOAD 27
47#define UI_MODE_ADDING_DRUM_NOTEROW 28
48#define UI_MODE_CREATING_CLIP 29
49// Gaps here
50#define UI_MODE_LOADING_BUT_ABORT_IF_SELECT_ENCODER_TURNED 33
51#define UI_MODE_LOADING_SONG_ESSENTIAL_SAMPLES 34
52#define UI_MODE_LOADING_SONG_UNESSENTIAL_SAMPLES_UNARMED 35
53#define UI_MODE_LOADING_SONG_UNESSENTIAL_SAMPLES_ARMED 36
54#define UI_MODE_LOADING_SONG_NEW_SONG_PLAYING 37
55#define UI_MODE_SELECTING_MIDI_CC 38
56#define UI_MODE_HOLDING_SECTION_PAD 40
57#define UI_MODE_HOLDING_ARRANGEMENT_ROW_AUDITION 41
58#define UI_MODE_HOLDING_ARRANGEMENT_ROW 42
59#define UI_MODE_EXPLODE_ANIMATION 43
60#define UI_MODE_ANIMATION_FADE 44
61#define UI_MODE_RECORD_COUNT_IN 45
62#define UI_MODE_HOLDING_SAMPLE_MARKER 46
63#define UI_MODE_HOLDING_BUTTON_POTENTIAL_LONG_PRESS 47
64#define UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR 48
65#define UI_MODE_HOLDING_BACKSPACE 49
66#define UI_MODE_VIEWING_RECORD_ARMING 50
67#define UI_MODE_HOLDING_SAVE_BUTTON 51
68#define UI_MODE_HOLDING_LOAD_BUTTON 52
69#define UI_MODE_PREDICTING_QWERTY_TEXT 53
70#define UI_MODE_AUDIO_CLIP_EXPANDING 54
71#define UI_MODE_AUDIO_CLIP_COLLAPSING 55
72#define UI_MODE_MODULATING_PARAM_HOLDING_ENCODER_DOWN 58
73#define UI_MODE_PATCHING_SOURCE_HOLDING_BUTTON_DOWN 59
74#define UI_MODE_MACRO_SETTING_UP 60
75#define UI_MODE_DRAGGING_KIT_NOTEROW 61
76#define UI_MODE_HOLDING_STATUS_PAD 62
77#define UI_MODE_IMPLODE_ANIMATION 63
78#define UI_MODE_STEM_EXPORT 64
79#define UI_MODE_HOLDING_SONG_BUTTON 65
80
81#define EXCLUSIVE_UI_MODES_MASK ((uint32_t)255)
82
83// Non-exclusive UI modes, which can (if the code allows) occur at the same time as other ones, including the
84// "exclusive" ones above.
85#define UI_MODE_QUANTIZE (1 << 27)
86#define UI_MODE_STUTTERING (1 << 28)
87#define UI_MODE_HORIZONTAL_SCROLL (1 << 29)
88#define UI_MODE_AUDITIONING (1 << 30)
89#define UI_MODE_HOLDING_HORIZONTAL_ENCODER_BUTTON ((uint32_t)1 << 31)
90
91#define LONG_PRESS_DURATION 400
92class UI {
93public:
94 virtual ~UI() = default;
95 UI();
96
97 virtual ActionResult padAction(int32_t x, int32_t y, int32_t velocity) { return ActionResult::DEALT_WITH; }
98 virtual ActionResult buttonAction(deluge::hid::Button b, bool on, bool inCardRoutine) {
99 return ActionResult::NOT_DEALT_WITH;
100 }
101 virtual ActionResult horizontalEncoderAction(int32_t offset) { return ActionResult::DEALT_WITH; }
102 virtual ActionResult verticalEncoderAction(int32_t offset, bool inCardRoutine) { return ActionResult::DEALT_WITH; }
103 virtual void selectEncoderAction(int8_t offset) {}
104 virtual void modEncoderAction(int32_t whichModEncoder, int32_t offset);
105 virtual void modButtonAction(uint8_t whichButton, bool on);
106 virtual void modEncoderButtonAction(uint8_t whichModEncoder, bool on);
107
108 virtual void graphicsRoutine();
109 virtual ActionResult timerCallback() { return ActionResult::DEALT_WITH; }
110
111 virtual bool opened() {
112 focusRegained();
113 return true;
114 }
115
116 virtual void focusRegained() {}
117 // the `display` and/or `chosenLanguage` object changed. redraw accordingly.
118 virtual void displayOrLanguageChanged() {}
119 virtual bool canSeeViewUnderneath() { return false; }
122 virtual ClipMinder* toClipMinder() { return nullptr; }
123
127 virtual TimelineView* toTimelineView() { return nullptr; }
128
129 virtual void scrollFinished() {}
130 virtual bool pcReceivedForMidiLearn(MIDICable& fromCable, int32_t channel, int32_t program) { return false; }
131
132 virtual bool noteOnReceivedForMidiLearn(MIDICable& fromCable, int32_t channel, int32_t note, int32_t velocity) {
133 return false;
134 } // Returns whether it was used, I think?
135
136 virtual bool getGreyoutColsAndRows(uint32_t* cols, uint32_t* rows) {
137 return false;
138 } // Returning false means obey UI under me
139
140 // When these return false it means they're transparent, showing what's underneath.
141 // These *must* check whether image has been supplied - if not, just return, saying whether opaque or not.
142 // Cos we need to be able to quiz these without actually getting any rendering done.
143 virtual bool renderMainPads(uint32_t whichRows = 0, RGB image[][kDisplayWidth + kSideBarWidth] = nullptr,
144 uint8_t occupancyMask[][kDisplayWidth + kSideBarWidth] = nullptr,
145 bool drawUndefinedArea = true) {
146 return false;
147 }
148 virtual bool renderSidebar(uint32_t whichRows = 0, RGB image[][kDisplayWidth + kSideBarWidth] = nullptr,
149 uint8_t occupancyMask[][kDisplayWidth + kSideBarWidth] = nullptr) {
150 return false;
151 }
152 // called when back is held, used to exit menus or similar full screen views completely
154 virtual bool exitUI() { return false; };
155 void close();
156
157 virtual void renderOLED(deluge::hid::display::oled_canvas::Canvas& canvas) = 0;
158 bool oledShowsUIUnderneath;
159
162 virtual UI* getUI() { return this; }
164 virtual UIType getUIType() = 0;
167 virtual UIType getUIContextType() { return getUIType(); }
170 virtual UIModControllableContext getUIModControllableContext() { return UIModControllableContext::NONE; }
171#if ENABLE_MATRIX_DEBUG
172 const char* getUIName();
173#endif
174
175protected:
176 UIType uiType;
177};
178
179// UIs
180UI* getCurrentUI();
181RootUI* getRootUI();
182UI* getUIUpOneLevel(int32_t numLevelsUp);
183static UI* getUIUpOneLevel() {
184 return getUIUpOneLevel(1);
185}
186void closeUI(UI* ui);
187bool openUI(UI* newUI);
188void changeRootUI(UI* newUI);
189bool changeUISideways(UI* newUI);
190bool changeUIAtLevel(UI* newUI, int32_t level);
191bool isUIOpen(UI* ui);
192void setRootUILowLevel(UI* newUI);
193void swapOutRootUILowLevel(UI* newUI);
194void nullifyUIs();
195bool currentUIIsClipMinderScreen();
196bool rootUIIsClipMinderScreen();
197std::pair<uint32_t, uint32_t> getUIGreyoutColsAndRows();
198
199void uiNeedsRendering(UI* ui, uint32_t whichMainRows = 0xFFFFFFFF, uint32_t whichSideRows = 0xFFFFFFFF);
200void renderingNeededRegardlessOfUI(uint32_t whichMainRows = 0xFFFFFFFF, uint32_t whichSideRows = 0xFFFFFFFF);
201void clearPendingUIRendering();
202
203void doAnyPendingUIRendering();
204
205void renderUIsForOled();
206
207// UI modes
208bool isUIModeActive(uint32_t uiMode);
209bool isUIModeActiveExclusively(uint32_t uiMode);
210bool isUIModeWithinRange(const uint32_t* modes);
211bool isNoUIModeActive();
212void exitUIMode(uint32_t uiMode);
213void enterUIMode(uint32_t uiMode);
Definition clip_minder.h:23
A MIDI cable connection. Stores all state specific to a given cable and its contained ports and chann...
Definition midi_device.h:94
Definition root_ui.h:27
Definition timeline_view.h:27
Definition ui.h:92
virtual UI * getUI()
When entering a UI (e.g. automationView), you may wish to open a different UI based on the current co...
Definition ui.h:162
virtual bool exitUI()
returns whether a UI exited
Definition ui.h:154
virtual TimelineView * toTimelineView()
Convert this view to a TimelineView.
Definition ui.h:127
virtual UIType getUIContextType()
What context does UI relate to? e.g. UIType could be AUTOMATION but UIContextType could be ARRANGER,...
Definition ui.h:167
virtual ClipMinder * toClipMinder()
Definition ui.h:122
virtual UIModControllableContext getUIModControllableContext()
What mod controllable context is this UI using? E.g. Automation View can use the Song ModControllable...
Definition ui.h:170
virtual UIType getUIType()=0
What type of UI is this? e.g. UIType::ARRANGER.