Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
piano.h
1/*
2 * Copyright © 2016-2024 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
25// for vertical scroll
26constexpr int32_t lowestPianoOctave = 0; // C-2 = 0
27constexpr int32_t highestPianoOctave = 9; // this is the last row starting from 0
28// for horizontal scroll
29constexpr int32_t highestNoteOffset = 7; // how much we can shift a keyboard horizontally (7 steps = 1 oct)
30// for colours
31constexpr int32_t totalPianoOctaves = 16; // total number of octaves starting from -2 to 13 (max in Deluge)
32constexpr int32_t colourOffset = 6; // jump in a colour codes fromHUE between rows
33
34// intervals of piano keys layout (0=no key)
35const int32_t pianoIntervals[2][7] = {
36 {0, 2, 4, 0, 7, 9, 11}, // black keys
37 {1, 3, 5, 6, 8, 10, 12}, // white keys
38};
39
40class KeyboardLayoutPiano : public ColumnControlsKeyboard {
41public:
42 KeyboardLayoutPiano() {}
43 ~KeyboardLayoutPiano() override {}
44
45 void evaluatePads(PressedPad presses[kMaxNumKeyboardPadPresses]) override;
46 void handleVerticalEncoder(int32_t offset) override;
47 void handleHorizontalEncoder(int32_t offset, bool shiftEnabled, PressedPad presses[kMaxNumKeyboardPadPresses],
48 bool encoderPressed = false) override;
49 void precalculate() override;
50
51 void renderPads(RGB image[][kDisplayWidth + kSideBarWidth]) override;
52
53 l10n::String name() override { return l10n::String::STRING_FOR_KEYBOARD_LAYOUT_PIANO; }
54 bool supportsInstrument() override { return true; }
55 bool supportsKit() override { return false; }
56
57private:
58 /* intervalFromCoords return a current note interval from 0 to 12 without an octave
59 * depending on x and y. Used for color-coding and detecting noteFromCoords.
60 * even rows (y) = white keys, odd rows = black keys
61 * x % 7 = interval number in the pianoIntervals array (they are repeat every 7 times)
62 */
63 inline uint16_t intervalFromCoords(int32_t x, int32_t y) {
64 return (y == 0 || (y % 2 == 0)) ? (pianoIntervals[1][(x + getState().piano.noteOffset) % 7])
65 : (pianoIntervals[0][(x + getState().piano.noteOffset) % 7]);
66 }
67
68 /* noteFromCoords return a note code (C-2=0) depending on current octave offset, x and y
69 * every 2 rows +1 octave (y/2), every 7 columns +1 octave (x/7). One octave = 12 semi
70 * result= start octave + current interval from Coords + octave by y + ocrave by x - 1 (starting from 0)
71 */
72 inline uint16_t noteFromCoords(int32_t x, int32_t y) {
73 return (getState().piano.scrollOffset) * 12 + intervalFromCoords(x, y) + 12 * (y / 2)
74 + 12 * ((x + getState().piano.noteOffset) / 7) - 1;
75 }
76
77 // each octave has it's own color
78 RGB noteColours[totalPianoOctaves + 1];
79};
80
81}; // namespace deluge::gui::ui::keyboard::layout
This class represents the colour format most used by the Deluge globally.
Definition rgb.h:14
void renderPads(RGB image[][kDisplayWidth+kSideBarWidth]) override
Handle output.
Definition piano.cpp:78
void evaluatePads(PressedPad presses[kMaxNumKeyboardPadPresses]) override
Handle input pad presses.
Definition piano.cpp:27
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 piano.cpp:56
void precalculate() override
This function is called on visibility change and if colour offset changes.
Definition piano.cpp:70
bool supportsInstrument() override
This currently includes Synth, MIDI and CV.
Definition piano.h:54
void handleVerticalEncoder(int32_t offset) override
Shift state not supplied since that function is already taken.
Definition piano.cpp:43
Definition notes_state.h:31