Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
chord_keyboard.h
1/*
2 * Copyright © 2016-2024 Synthstrom Audible Limited
3 * Copyright © 2024 Madeline Scyphers
4 *
5 * This file is part of The Synthstrom Audible Deluge Firmware.
6 *
7 * The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU General Public License as published by the Free Software Foundation,
9 * either version 3 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along with this program.
16 * If not, see <https://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include "definitions.h"
22#include "gui/ui/keyboard/chords.h"
23#include "gui/ui/keyboard/layout/column_controls.h"
24#include "util/const_functions.h"
25#include <array>
26#include <set>
27
28namespace deluge::gui::ui::keyboard::layout {
29
30const int32_t SCALEFIRST = 0;
31const int32_t SCALESECOND = 1;
32const int32_t SCALETHIRD = 2;
33const int32_t SCALEFOURTH = 3;
34const int32_t SCALEFIFTH = 4;
35const int32_t SCALESIXTH = 5;
36const int32_t SCALESEVENTH = 6;
37const int32_t SCALEOCTAVE = 7;
38
39enum class ChordKeyboardMode { ROW, COLUMN };
40const int32_t kChordKeyboardColumns = 14;
41
43class KeyboardLayoutChord : public ColumnControlsKeyboard {
44public:
45 KeyboardLayoutChord() = default;
46 ~KeyboardLayoutChord() override = default;
47
48 void evaluatePads(PressedPad presses[kMaxNumKeyboardPadPresses]) override;
49 void handleVerticalEncoder(int32_t offset) override;
50 void handleHorizontalEncoder(int32_t offset, bool shiftEnabled, PressedPad presses[kMaxNumKeyboardPadPresses],
51 bool encoderPressed = false) override;
52 void precalculate() override;
53
54 void renderPads(RGB image[][kDisplayWidth + kSideBarWidth]) override;
55
56 l10n::String name() override { return l10n::String::STRING_FOR_KEYBOARD_LAYOUT_CHORD_KEYBOARD; }
57 bool supportsInstrument() override { return true; }
58 bool supportsKit() override { return false; }
59 RequiredScaleMode requiredScaleMode() override { return RequiredScaleMode::Disabled; }
60
61 ChordKeyboardMode mode = ChordKeyboardMode::COLUMN;
62
63protected:
64 bool allowSidebarType(ColumnControlFunction sidebarType) override;
65
66private:
67 void offsetPads(int32_t offset, bool shiftEnabled);
68 void handleControlButton(int32_t x, int32_t y);
69 uint8_t noteFromCoordsRow(int32_t x, int32_t y, int32_t root, NoteSet& scaleNotes, uint8_t scaleNoteCount);
70 void evaluatePadsRow(PressedPad pressed);
71 void evaluatePadsColumn(PressedPad pressed);
72 void drawChordName(int16_t noteCode, const char* chordName = "", const char* voicingName = "");
73
74 Scale lastScale = NO_SCALE;
75
76 // ChordKeyboardMode mode = ChordKeyboardMode::ROW;
77
78 std::array<RGB, static_cast<int>(ChordQuality::CHORD_QUALITY_MAX)> qualityColours = {
79 colours::blue, colours::purple, colours::green, colours::kelly::very_light_blue,
80 colours::cyan, colours::yellow};
81
82 std::array<int32_t, kOctaveSize + kDisplayHeight + kDisplayWidth> qualities;
83
84 std::array<int32_t, kDisplayWidth - 1> scaleSteps = {
85 SCALEFIRST,
86 SCALEFIFTH,
87 SCALETHIRD + SCALEOCTAVE,
88 SCALESEVENTH + SCALEOCTAVE,
89 SCALEFIFTH + SCALEOCTAVE,
90 SCALETHIRD + 2 * SCALEOCTAVE,
91 SCALESECOND + 2 * SCALEOCTAVE,
92 SCALESIXTH + SCALEOCTAVE,
93 SCALEOCTAVE,
94 SCALEFIFTH,
95 SCALESEVENTH,
96 SCALETHIRD - SCALEOCTAVE,
97 SCALESECOND,
98 SCALEFIFTH,
99 SCALEFIRST,
100 // SCALEFIRST - SCALEOCTAVE,
101 };
102
103 std::array<const std::array<const Chord, majorChords.size()>*, 6> chordColumns = {
104 &majorChords, &minorChords, &diminishedChords, &augmentedChords, &dominantChords, &otherChords};
105
106 std::set<Scale> acceptedScales = {Scale::MAJOR_SCALE, Scale::MINOR_SCALE, Scale::DORIAN_SCALE,
107 Scale::PHRYGIAN_SCALE, Scale::LYDIAN_SCALE, Scale::MIXOLYDIAN_SCALE,
108 Scale::LOCRIAN_SCALE};
109};
110
111}; // 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
void evaluatePads(PressedPad presses[kMaxNumKeyboardPadPresses]) override
Handle input pad presses.
Definition chord_keyboard.cpp:33
bool supportsInstrument() override
This currently includes Synth, MIDI and CV.
Definition chord_keyboard.h:57
void handleVerticalEncoder(int32_t offset) override
Shift state not supplied since that function is already taken.
Definition chord_keyboard.cpp:122
void precalculate() override
This function is called on visibility change and if colour offset changes.
Definition chord_keyboard.cpp:152
void renderPads(RGB image[][kDisplayWidth+kSideBarWidth]) override
Handle output.
Definition chord_keyboard.cpp:187
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 chord_keyboard.cpp:129
Definition notes_state.h:31