Deluge Firmware 1.3.0
Build date: 2026.07.29
Loading...
Searching...
No Matches
layout.h
1/*
2 * Copyright © 2016-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/ui/keyboard/keyboard_screen.h"
22#include "gui/ui/keyboard/notes_state.h"
23#include "gui/ui/keyboard/state_data.h"
24#include "model/clip/instrument_clip.h"
25#include "model/instrument/instrument.h"
26#include "model/note/note_row.h"
27#include "model/scale/note_set.h"
28#include "model/song/song.h"
29
30constexpr uint8_t kMaxNumKeyboardPadPresses = 10;
31
32namespace deluge::gui::ui::keyboard {
33
34enum class RequiredScaleMode : uint8_t {
35 Undefined = 0,
36 Disabled = 1,
37 Enabled = 2,
38};
39
40typedef uint8_t NoteHighlightIntensity[kHighestKeyboardNote];
41
42class KeyboardLayout {
43public:
44 KeyboardLayout() = default;
45 virtual ~KeyboardLayout() {}
46
48 virtual void evaluatePads(PressedPad presses[kMaxNumKeyboardPadPresses]) = 0;
49
51 virtual void handleVerticalEncoder(int32_t offset) = 0;
52
54 virtual void handleHorizontalEncoder(int32_t offset, bool shiftEnabled,
55 PressedPad presses[kMaxNumKeyboardPadPresses],
56 bool encoderPressed = false) = 0;
57
59 virtual void precalculate() = 0;
60
62 virtual void renderPads(RGB image[][kDisplayWidth + kSideBarWidth]) {}
63
64 virtual void renderSidebarPads(RGB image[][kDisplayWidth + kSideBarWidth]) {
65 // Clean sidebar if function is not overwritten
66 for (int32_t y = 0; y < kDisplayHeight; y++) {
67 image[y][kDisplayWidth] = colours::black;
68 image[y][kDisplayWidth + 1] = colours::black;
69 }
70 };
71
72 // Properties
73
74 virtual l10n::String name() = 0;
76 virtual bool supportsInstrument() { return false; }
77 virtual bool supportsKit() { return false; }
78 virtual RequiredScaleMode requiredScaleMode() { return RequiredScaleMode::Undefined; }
82 virtual bool supportsScale(Scale scale) { return true; }
83
84 virtual NotesState& getNotesState() { return currentNotesState; }
85
86 virtual void checkNewInstrument(Instrument* newInstrument) {}
87
88protected:
89 inline bool isKit() { return getCurrentOutputType() == OutputType::KIT; }
91 inline int16_t getRootNote() { return (currentSong->key.rootNote % kOctaveSize); }
92 inline bool getScaleModeEnabled() { return getCurrentInstrumentClip()->inScaleMode; }
93 inline uint8_t getScaleNoteCount() { return currentSong->key.modeNotes.count(); }
94
95 inline NoteSet& getScaleNotes() { return currentSong->key.modeNotes; }
96
97 inline uint8_t getDefaultVelocity() { return getCurrentInstrument()->defaultVelocity; }
98
99 inline int32_t getLowestClipNote() { return kLowestKeyboardNote; }
100 inline int32_t getHighestClipNote() {
101 if (isKit()) {
102 return getCurrentInstrumentClip()->noteRows.getNumElements() - 1;
103 }
104
105 return kHighestKeyboardNote;
106 }
107
108 inline RGB getNoteColour(uint8_t note) {
109 int8_t colourOffset = 0;
110
111 // Get colour offset for kit rows
112 if (getCurrentOutputType() == OutputType::KIT) {
113 if (note >= 0 && note < getCurrentInstrumentClip()->noteRows.getNumElements()) {
114 NoteRow* noteRow = getCurrentInstrumentClip()->noteRows.getElement(note);
115 if (noteRow) {
116 colourOffset = noteRow->getColourOffset(getCurrentInstrumentClip());
117 }
118 }
119 }
120
121 return getCurrentInstrumentClip()->getMainColourFromY(note, colourOffset);
122 }
123
124 inline NoteHighlightIntensity& getHighlightedNotes() { return keyboardScreen.highlightedNotes; }
125 inline NoteHighlightIntensity& getNornsNotes() { return keyboardScreen.nornsNotes; }
126
127 inline KeyboardState& getState() { return getCurrentInstrumentClip()->keyboardState; }
128
129public:
130 uint8_t velocity = 64;
131
132protected:
133 NotesState currentNotesState;
134};
135
136}; // namespace deluge::gui::ui::keyboard
Definition instrument.h:45
Definition note_set.h:20
This class represents the colour format most used by the Deluge globally.
Definition rgb.h:14
virtual bool supportsScale(Scale scale)
Definition layout.h:82
virtual bool supportsInstrument()
This currently includes Synth, MIDI and CV.
Definition layout.h:76
virtual void handleHorizontalEncoder(int32_t offset, bool shiftEnabled, PressedPad presses[kMaxNumKeyboardPadPresses], bool encoderPressed=false)=0
Will be called with offset 0 to recalculate bounds on clip changes.
virtual void evaluatePads(PressedPad presses[kMaxNumKeyboardPadPresses])=0
Handle input pad presses.
virtual void handleVerticalEncoder(int32_t offset)=0
Shift state not supplied since that function is already taken.
virtual void renderPads(RGB image[][kDisplayWidth+kSideBarWidth])
Handle output.
Definition layout.h:62
virtual void precalculate()=0
This function is called on visibility change and if colour offset changes.
int16_t getRootNote()
Song root note can be in any octave, layouts get the normalized one.
Definition layout.h:91
Definition notes_state.h:56
Definition notes_state.h:31