Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
velocity_drums.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.h"
21
22namespace deluge::gui::ui::keyboard::layout {
23
24constexpr int32_t k_min_zoom_level = 0;
25constexpr int32_t k_max_zoom_level = 12;
26
27// The zoom_arr is used to set the edge sizes of the pads {x size, y size} on each zoom level.
28const int32_t zoom_arr[13][2] = {{1, 1}, {2, 1}, {3, 1}, {2, 2}, {3, 2}, {4, 2}, {5, 2},
29 {3, 4}, {4, 4}, {5, 4}, {8, 4}, {8, 8}, {16, 8}};
30
31class KeyboardLayoutVelocityDrums : public KeyboardLayout {
32public:
33 KeyboardLayoutVelocityDrums() = default;
34 ~KeyboardLayoutVelocityDrums() override = default;
35 void precalculate() override {}
36
37 void evaluatePads(PressedPad presses[kMaxNumKeyboardPadPresses]) override;
38 void handleVerticalEncoder(int32_t offset) override;
39 void handleHorizontalEncoder(int32_t offset, bool shiftEnabled, PressedPad presses[kMaxNumKeyboardPadPresses],
40 bool encoderPressed = false) override;
41
42 void renderPads(RGB image[][kDisplayWidth + kSideBarWidth]) override;
43
44 l10n::String name() override { return l10n::String::STRING_FOR_KEYBOARD_LAYOUT_VELOCITY_DRUMS; }
45 bool supportsInstrument() override { return false; }
46 bool supportsKit() override { return true; }
47
48private:
49 inline uint8_t velocityFromCoords(int32_t x, int32_t y, uint32_t edge_size_x, uint32_t edge_size_y) {
50 uint32_t velocity = 0;
51 if (edge_size_x == 1) {
52 // No need to do a lot of calculations or use max velocity for only one option.
53 velocity = FlashStorage::defaultVelocity * 2;
54 }
55 else {
56 bool odd_pad = (edge_size_x % 2 == 1); // check if the view has odd width pads
57 uint32_t x_limit = kDisplayWidth - 2 - edge_size_x; // end of second to last pad in a row (the regular pads)
58 bool x_adjust = (odd_pad && x > x_limit);
59 uint32_t localX = x_adjust ? x - x_limit : x % (edge_size_x);
60
61 if (edge_size_y == 1) {
62 velocity = (localX + 1) * 200 / (edge_size_x + x_adjust); // simpler, more useful, easier on the ears.
63 }
64 else {
65 if (edge_size_x % 2 == 1 && x > kDisplayWidth - 2 - edge_size_x)
66 edge_size_x += 1;
67 uint32_t position = localX + 1;
68 position += ((y % edge_size_y) * (edge_size_x + x_adjust));
69 // We use two bytes to keep the precision of the calculations high,
70 // then shift it down to one byte at the end.
71 uint32_t stepSize = 0xFFFF / ((edge_size_x + x_adjust) * edge_size_y);
72 velocity = (position * stepSize) >> 8;
73 }
74 }
75 return velocity; // returns an integer value 0-255, which will then be divided by 2 to get 0-127
76 }
77};
78
79}; // namespace deluge::gui::ui::keyboard::layout
This class represents the colour format most used by the Deluge globally.
Definition rgb.h:14
bool supportsInstrument() override
This currently includes Synth, MIDI and CV.
Definition velocity_drums.h:45
void evaluatePads(PressedPad presses[kMaxNumKeyboardPadPresses]) override
Handle input pad presses.
Definition velocity_drums.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 velocity_drums.cpp:91
void renderPads(RGB image[][kDisplayWidth+kSideBarWidth]) override
Handle output.
Definition velocity_drums.cpp:132
void precalculate() override
This function is called on visibility change and if colour offset changes.
Definition velocity_drums.h:35
void handleVerticalEncoder(int32_t offset) override
Shift state not supplied since that function is already taken.
Definition velocity_drums.cpp:85
Definition notes_state.h:31