Deluge Firmware 1.3.0
Build date: 2025.04.16
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 UI();
95
96 virtual ActionResult padAction(int32_t x, int32_t y, int32_t velocity) { return ActionResult::DEALT_WITH; }
97 virtual ActionResult buttonAction(deluge::hid::Button b, bool on, bool inCardRoutine) {
98 return ActionResult::NOT_DEALT_WITH;
99 }
100 virtual ActionResult horizontalEncoderAction(int32_t offset) { return ActionResult::DEALT_WITH; }
101 virtual ActionResult verticalEncoderAction(int32_t offset, bool inCardRoutine) { return ActionResult::DEALT_WITH; }
102 virtual void selectEncoderAction(int8_t offset) {}
103 virtual void modEncoderAction(int32_t whichModEncoder, int32_t offset);
104 virtual void modButtonAction(uint8_t whichButton, bool on);
105 virtual void modEncoderButtonAction(uint8_t whichModEncoder, bool on);
106
107 virtual void graphicsRoutine();
108 virtual ActionResult timerCallback() { return ActionResult::DEALT_WITH; }
109
110 virtual bool opened() {
111 focusRegained();
112 return true;
113 }
114
115 virtual void focusRegained() {}
116 // the `display` and/or `chosenLanguage` object changed. redraw accordingly.
117 virtual void displayOrLanguageChanged() {}
118 virtual bool canSeeViewUnderneath() { return false; }
121 virtual ClipMinder* toClipMinder() { return nullptr; }
122
126 virtual TimelineView* toTimelineView() { return nullptr; }
127
128 virtual void scrollFinished() {}
129 virtual bool pcReceivedForMidiLearn(MIDICable& fromCable, int32_t channel, int32_t program) { return false; }
130
131 virtual bool noteOnReceivedForMidiLearn(MIDICable& fromCable, int32_t channel, int32_t note, int32_t velocity) {
132 return false;
133 } // Returns whether it was used, I think?
134
135 virtual bool getGreyoutColsAndRows(uint32_t* cols, uint32_t* rows) {
136 return false;
137 } // Returning false means obey UI under me
138
139 // When these return false it means they're transparent, showing what's underneath.
140 // These *must* check whether image has been supplied - if not, just return, saying whether opaque or not.
141 // Cos we need to be able to quiz these without actually getting any rendering done.
142 virtual bool renderMainPads(uint32_t whichRows = 0, RGB image[][kDisplayWidth + kSideBarWidth] = nullptr,
143 uint8_t occupancyMask[][kDisplayWidth + kSideBarWidth] = nullptr,
144 bool drawUndefinedArea = true) {
145 return false;
146 }
147 virtual bool renderSidebar(uint32_t whichRows = 0, RGB image[][kDisplayWidth + kSideBarWidth] = nullptr,
148 uint8_t occupancyMask[][kDisplayWidth + kSideBarWidth] = nullptr) {
149 return false;
150 }
151 // called when back is held, used to exit menus or similar full screen views completely
153 virtual bool exitUI() { return false; };
154 void close();
155
156 virtual void renderOLED(deluge::hid::display::oled_canvas::Canvas& canvas) = 0;
157 bool oledShowsUIUnderneath;
158
159 virtual UIType getUIType() = 0;
160#if ENABLE_MATRIX_DEBUG
161 const char* getUIName();
162#endif
163
164protected:
165 UIType uiType;
166};
167
168// UIs
169UI* getCurrentUI();
170RootUI* getRootUI();
171UI* getUIUpOneLevel(int32_t numLevelsUp);
172static UI* getUIUpOneLevel() {
173 return getUIUpOneLevel(1);
174}
175void closeUI(UI* ui);
176bool openUI(UI* newUI);
177void changeRootUI(UI* newUI);
178bool changeUISideways(UI* newUI);
179bool changeUIAtLevel(UI* newUI, int32_t level);
180bool isUIOpen(UI* ui);
181void setRootUILowLevel(UI* newUI);
182void swapOutRootUILowLevel(UI* newUI);
183void nullifyUIs();
184bool currentUIIsClipMinderScreen();
185bool rootUIIsClipMinderScreen();
186std::pair<uint32_t, uint32_t> getUIGreyoutColsAndRows();
187
188void uiNeedsRendering(UI* ui, uint32_t whichMainRows = 0xFFFFFFFF, uint32_t whichSideRows = 0xFFFFFFFF);
189void renderingNeededRegardlessOfUI(uint32_t whichMainRows = 0xFFFFFFFF, uint32_t whichSideRows = 0xFFFFFFFF);
190void clearPendingUIRendering();
191
192void doAnyPendingUIRendering();
193
194void renderUIsForOled();
195
196// UI modes
197bool isUIModeActive(uint32_t uiMode);
198bool isUIModeActiveExclusively(uint32_t uiMode);
199bool isUIModeWithinRange(const uint32_t* modes);
200bool isNoUIModeActive();
201void exitUIMode(uint32_t uiMode);
202void 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 bool exitUI()
returns whether a UI exited
Definition ui.h:153
virtual TimelineView * toTimelineView()
Convert this view to a TimelineView.
Definition ui.h:126
virtual ClipMinder * toClipMinder()
Definition ui.h:121