|
1 | 1 | #include "NotePad.h" |
2 | 2 | #include <algorithm> |
| 3 | +#include <cstring> |
3 | 4 |
|
4 | 5 | const Color polyNoteColor[12] = { |
5 | 6 | Color(0x00FFD9), |
@@ -138,6 +139,29 @@ void NotePad::UpdateActiveKeyVelocity(Point position, Fract16 velocity) { |
138 | 139 | } |
139 | 140 | } |
140 | 141 |
|
| 142 | +// Note highlighting for visualizing notes from external MIDI input. |
| 143 | +void NotePad::SetNoteHighlight(uint8_t note, bool highlight) { |
| 144 | + if (note >= 128) return; |
| 145 | + uint8_t byteIndex = note / 8; |
| 146 | + uint8_t mask = static_cast<uint8_t>(1u << (note % 8)); |
| 147 | + if (highlight) { |
| 148 | + highlightedNotes[byteIndex] |= mask; |
| 149 | + } else { |
| 150 | + highlightedNotes[byteIndex] &= static_cast<uint8_t>(~mask); |
| 151 | + } |
| 152 | +} |
| 153 | + |
| 154 | +void NotePad::ClearNoteHighlight() { |
| 155 | + memset(highlightedNotes, 0, sizeof(highlightedNotes)); |
| 156 | +} |
| 157 | + |
| 158 | +bool NotePad::IsNoteHighlighted(uint8_t note) const { |
| 159 | + if (note >= 128) return false; |
| 160 | + uint8_t byteIndex = note / 8; |
| 161 | + uint8_t mask = static_cast<uint8_t>(1u << (note % 8)); |
| 162 | + return (highlightedNotes[byteIndex] & mask) != 0; |
| 163 | +} |
| 164 | + |
141 | 165 | void NotePad::GenerateOctaveKeymap() { |
142 | 166 | noteMap.reserve(dimension.Area()); |
143 | 167 | int16_t root = 12 * rt->config->octave + rt->config->rootKey + rt->config->rootOffset; |
@@ -350,7 +374,7 @@ bool NotePad::RenderRootNScale(Point origin) { |
350 | 374 | if (note == 255) { |
351 | 375 | MatrixOS::LED::SetColor(globalPos, Color(0)); |
352 | 376 | } |
353 | | - else if (IsNoteActive(note) || rt->midiPipeline.IsNoteActive(note)) { // If find the note is currently active. Show it as white |
| 377 | + else if (IsNoteActive(note) || rt->midiPipeline.IsNoteActive(note) || IsNoteHighlighted(note)) { // If find the note is currently active. Show it as white |
354 | 378 | MatrixOS::LED::SetColor(globalPos, Color::White); |
355 | 379 | } |
356 | 380 | else { |
@@ -391,7 +415,7 @@ bool NotePad::RenderColorPerKey(Point origin) { |
391 | 415 | if (note == 255) { |
392 | 416 | MatrixOS::LED::SetColor(globalPos, Color(0)); |
393 | 417 | } |
394 | | - else if (IsNoteActive(note) || rt->midiPipeline.IsNoteActive(note)) { // If find the note is currently active. Show it as white |
| 418 | + else if (IsNoteActive(note) || rt->midiPipeline.IsNoteActive(note) || IsNoteHighlighted(note)) { // If find the note is currently active. Show it as white |
395 | 419 | MatrixOS::LED::SetColor(globalPos, Color::White); |
396 | 420 | } |
397 | 421 | else { |
|
0 commit comments