Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
in_key.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 "gui/ui/keyboard/layout/column_controls.h"
21#include "model/scale/note_set.h"
22
23namespace deluge::gui::ui::keyboard::layout {
24
25constexpr int32_t kMinInKeyRowInterval = 1;
26constexpr int32_t kMaxInKeyRowInterval = 16;
27
28class KeyboardLayoutInKey : public ColumnControlsKeyboard {
29public:
30 KeyboardLayoutInKey() {}
31 ~KeyboardLayoutInKey() override {}
32
33 void evaluatePads(PressedPad presses[kMaxNumKeyboardPadPresses]) override;
34 void handleVerticalEncoder(int32_t offset) override;
35 void handleHorizontalEncoder(int32_t offset, bool shiftEnabled, PressedPad presses[kMaxNumKeyboardPadPresses],
36 bool encoderPressed = false) override;
37 void precalculate() override;
38
39 void renderPads(RGB image[][kDisplayWidth + kSideBarWidth]) override;
40
41 l10n::String name() override { return l10n::String::STRING_FOR_KEYBOARD_LAYOUT_IN_KEY; }
42 bool supportsInstrument() override { return true; }
43 bool supportsKit() override { return false; }
44 RequiredScaleMode requiredScaleMode() override { return RequiredScaleMode::Enabled; }
45
46private:
47 void offsetPads(int32_t offset, bool shiftEnabled);
48 inline uint16_t noteFromCoords(int32_t x, int32_t y) { return noteFromPadIndex(padIndexFromCoords(x, y)); }
49
50 inline uint16_t padIndexFromCoords(int32_t x, int32_t y) {
51 return getState().inKey.scrollOffset + x + y * getState().inKey.rowInterval;
52 }
53
54 inline uint16_t noteFromPadIndex(uint16_t padIndex) {
55 NoteSet& scaleNotes = getScaleNotes();
56 uint8_t scaleNoteCount = getScaleNoteCount();
57
58 uint8_t octave = padIndex / scaleNoteCount;
59 uint8_t octaveNoteIndex = padIndex % scaleNoteCount;
60 return octave * kOctaveSize + getRootNote() + scaleNotes[octaveNoteIndex];
61 }
62
63 inline uint16_t padIndexFromNote(uint16_t note) {
64 NoteSet& scaleNotes = getScaleNotes();
65 uint8_t scaleNoteCount = getScaleNoteCount();
66 int16_t rootNote = getRootNote();
67
68 uint8_t padScaleOffset = 0;
69 for (uint8_t idx = 0; idx < scaleNoteCount; ++idx) {
70 if (scaleNotes[idx] == (((note + kOctaveSize) - rootNote) % kOctaveSize)) {
71 padScaleOffset = idx;
72 break;
73 }
74 }
75 int32_t octave = (((note + kOctaveSize) - rootNote) / kOctaveSize) - 1;
76 // Make sure we don't go into negative because our root note is lower than C-2
77 return std::max<int32_t>(octave * scaleNoteCount + padScaleOffset, std::numeric_limits<uint16_t>::min());
78 }
79
80 // inline uint16_t padIndexFromNote(uint16_t note) {
81 // uint8_t scaleNoteCount = getScaleNoteCount();
82
83 // padIndex = octave * scaleNoteCount
84 // C1 = 7
85
86 // return note;
87 // //note % kOctaveSize
88
89 // // uint8_t scaleNoteCount = getScaleNoteCount();
90 // // uint8_t octave = padIndex / scaleNoteCount;
91 // // uint8_t octaveNoteIndex = padIndex % scaleNoteCount;
92 // // return octave * kOctaveSize + getRootNote() + getScaleNotes()[octaveNoteIndex];
93 // }
94
95 RGB noteColours[kDisplayHeight * kMaxInKeyRowInterval + kDisplayWidth];
96};
97
98}; // namespace deluge::gui::ui::keyboard::layout
Definition note_set.h:20
This class represents the colour format most used by the Deluge globally.
Definition rgb.h:14
int16_t getRootNote()
Song root note can be in any octave, layouts get the normalized one.
Definition layout.h:87
bool supportsInstrument() override
This currently includes Synth, MIDI and CV.
Definition in_key.h:42
void precalculate() override
This function is called on visibility change and if colour offset changes.
Definition in_key.cpp:87
void evaluatePads(PressedPad presses[kMaxNumKeyboardPadPresses]) override
Handle input pad presses.
Definition in_key.cpp:26
void handleHorizontalEncoder(int32_t offset, bool shiftEnabled, PressedPad presses[kMaxNumKeyboardPadPresses], bool encoderPressed=false) override
Will be called with offset 0 to recalculate bounds on clip changes.
Definition in_key.cpp:47
void handleVerticalEncoder(int32_t offset) override
Shift state not supplied since that function is already taken.
Definition in_key.cpp:40
void renderPads(RGB image[][kDisplayWidth+kSideBarWidth]) override
Handle output.
Definition in_key.cpp:96
Definition notes_state.h:31