Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
notes_state.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 <array>
22#include <bitset>
23#include <climits>
24#include <cstdint>
25#include <cstring>
26
27constexpr uint8_t kMaxNumActiveNotes = 10;
28
29namespace deluge::gui::ui::keyboard {
30
31struct PressedPad : Cartesian {
32 uint32_t timeLastPadPress;
33 bool padPressHeld;
34 bool active;
35 // all evaluatePads will be called at least once with pad.active == false on release. Following
36 // that, dead will be set to true to avoid repeatedly processing releases.
37 // exception - if the pad is "used up" by switching keyboard columns it will be set dead immediately to prevent
38 // processing its release, while still being set as active
39 bool dead;
40};
41
42struct NoteState {
43 uint8_t note = 0;
46 uint8_t activationCount = 0;
47 uint8_t velocity = 0;
48 int16_t mpeValues[3] = {0};
50 bool generatedNote = false;
51};
52
53// Always needs to be 0 currently for the math to math
54constexpr uint8_t kLowestKeyboardNote = 0;
55constexpr uint8_t kHighestKeyboardNote = kOctaveSize * 12;
56struct NotesState {
57 using NoteArray = std::array<NoteState, kMaxNumActiveNotes>;
58
59 std::bitset<kHighestKeyboardNote> states;
60 NoteArray notes;
61 uint8_t count = 0;
62
63 [[nodiscard]] NoteArray::iterator begin() { return notes.begin(); }
64
65 [[nodiscard]] NoteArray::iterator end() { return notes.begin() + count; }
66
67 [[nodiscard]] NoteArray::const_iterator begin() const { return notes.begin(); }
68
69 [[nodiscard]] NoteArray::const_iterator end() const { return notes.end() + count; }
70
71 NoteArray::size_type enableNote(uint8_t note, uint8_t velocity, bool generatedNote = false,
72 int16_t* mpeValues = nullptr) {
73 if (noteEnabled(note)) {
74 for (auto i = 0; i < notes.size(); ++i) {
75 auto& noteState = notes[i];
76 if (noteState.note == note) {
77 noteState.activationCount++;
78 return i;
79 }
80 }
81 }
82 if (count == kMaxNumActiveNotes) {
83 return count;
84 }
85
86 NoteArray::size_type idx = count++;
87 NoteState& state = notes[idx];
88 state.note = note;
89 state.velocity = velocity;
90 state.generatedNote = generatedNote;
91 if (mpeValues != nullptr) {
92 memcpy(&state.mpeValues, mpeValues, sizeof(state.mpeValues));
93 }
94
95 states[note] = true;
96
97 return idx;
98 }
99
100 [[nodiscard]] constexpr bool noteEnabled(uint8_t note) const { return states[note]; }
101};
102
103}; // namespace deluge::gui::ui::keyboard
Definition notes_state.h:42
uint8_t activationCount
Definition notes_state.h:46
bool generatedNote
Generated notes will only create sound and not be used for interaction (e.g. setting root note)
Definition notes_state.h:50
Definition notes_state.h:56
Definition notes_state.h:31