Deluge Firmware 1.3.0
Build date: 2025.04.16
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; }
79
80 virtual NotesState& getNotesState() { return currentNotesState; }
81
82 virtual void checkNewInstrument(Instrument* newInstrument) {}
83
84protected:
85 inline bool isKit() { return getCurrentOutputType() == OutputType::KIT; }
87 inline int16_t getRootNote() { return (currentSong->key.rootNote % kOctaveSize); }
88 inline bool getScaleModeEnabled() { return getCurrentInstrumentClip()->inScaleMode; }
89 inline uint8_t getScaleNoteCount() { return currentSong->key.modeNotes.count(); }
90
91 inline NoteSet& getScaleNotes() { return currentSong->key.modeNotes; }
92
93 inline uint8_t getDefaultVelocity() { return getCurrentInstrument()->defaultVelocity; }
94
95 inline int32_t getLowestClipNote() { return kLowestKeyboardNote; }
96 inline int32_t getHighestClipNote() {
97 if (isKit()) {
98 return getCurrentInstrumentClip()->noteRows.getNumElements() - 1;
99 }
100
101 return kHighestKeyboardNote;
102 }
103
104 inline RGB getNoteColour(uint8_t note) {
105 int8_t colourOffset = 0;
106
107 // Get colour offset for kit rows
108 if (getCurrentOutputType() == OutputType::KIT) {
109 if (note >= 0 && note < getCurrentInstrumentClip()->noteRows.getNumElements()) {
110 NoteRow* noteRow = getCurrentInstrumentClip()->noteRows.getElement(note);
111 if (noteRow) {
112 colourOffset = noteRow->getColourOffset(getCurrentInstrumentClip());
113 }
114 }
115 }
116
117 return getCurrentInstrumentClip()->getMainColourFromY(note, colourOffset);
118 }
119
120 inline NoteHighlightIntensity& getHighlightedNotes() { return keyboardScreen.highlightedNotes; }
121 inline NoteHighlightIntensity& getNornsNotes() { return keyboardScreen.nornsNotes; }
122
123 inline KeyboardState& getState() { return getCurrentInstrumentClip()->keyboardState; }
124
125public:
126 uint8_t velocity = 64;
127
128protected:
129 NotesState currentNotesState;
130};
131
132}; // 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 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:87
Definition notes_state.h:31