Skip to content

Commit e29dd76

Browse files
committed
Chromatic keymap
1 parent 5b4faff commit e29dd76

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

Applications/Note/Note.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,7 @@ void Note::LayoutSelector() {
392392
UIButton octaveModeBtn;
393393
octaveModeBtn.SetName("Octave Mode");
394394
octaveModeBtn.SetColorFunc([&]() -> Color { return Color(0xFFFF00).DimIfNot(notePadConfigs[activeConfig].mode == OCTAVE_LAYOUT); });
395-
octaveModeBtn.OnPress([&]() -> void {
396-
if(notePadConfigs[activeConfig].mode != OCTAVE_LAYOUT)
397-
{
398-
notePadConfigs[activeConfig].mode = OCTAVE_LAYOUT;
399-
}
400-
});
395+
octaveModeBtn.OnPress([&]() -> void { notePadConfigs[activeConfig].mode = OCTAVE_LAYOUT; });
401396
layoutSelector.AddUIComponent(octaveModeBtn, Point(2, 0));
402397

403398
UIButton offsetModeBtn;
@@ -413,16 +408,17 @@ void Note::LayoutSelector() {
413408
});
414409
layoutSelector.AddUIComponent(offsetModeBtn, Point(3, 0));
415410

411+
UIButton chromaticModeBtn;
412+
chromaticModeBtn.SetName("Chromatic Mode");
413+
chromaticModeBtn.SetColorFunc([&]() -> Color { return Color(0xFFFF00).DimIfNot(notePadConfigs[activeConfig].mode == CHROMATIC_LAYOUT); });
414+
chromaticModeBtn.OnPress([&]() -> void { notePadConfigs[activeConfig].mode = CHROMATIC_LAYOUT; });
415+
layoutSelector.AddUIComponent(chromaticModeBtn, Point(4, 0));
416+
416417
UIButton pianoModeBtn;
417418
pianoModeBtn.SetName("Piano Mode");
418419
pianoModeBtn.SetColorFunc([&]() -> Color { return Color(0xFFFF00).DimIfNot(notePadConfigs[activeConfig].mode == PIANO_LAYOUT); });
419-
pianoModeBtn.OnPress([&]() -> void {
420-
if(notePadConfigs[activeConfig].mode != PIANO_LAYOUT)
421-
{
422-
notePadConfigs[activeConfig].mode = PIANO_LAYOUT;
423-
}
424-
});
425-
layoutSelector.AddUIComponent(pianoModeBtn, Point(4, 0));
420+
pianoModeBtn.OnPress([&]() -> void { notePadConfigs[activeConfig].mode = PIANO_LAYOUT; });
421+
layoutSelector.AddUIComponent(pianoModeBtn, Point(5, 0));
426422

427423
// Offset Mode
428424
UISelector yOffsetInput;
@@ -465,7 +461,7 @@ void Note::LayoutSelector() {
465461
inKeyNoteOnlyToggle.SetName("In Key Notes Only");
466462
inKeyNoteOnlyToggle.SetColorFunc([&]() -> Color { return Color(0xFFFFFF).DimIfNot(notePadConfigs[activeConfig].inKeyNoteOnly); });
467463
inKeyNoteOnlyToggle.OnPress([&]() -> void { notePadConfigs[activeConfig].inKeyNoteOnly = !notePadConfigs[activeConfig].inKeyNoteOnly; });
468-
inKeyNoteOnlyToggle.SetEnableFunc([&]() -> bool { return notePadConfigs[activeConfig].mode == OCTAVE_LAYOUT || notePadConfigs[activeConfig].mode == OFFSET_LAYOUT; });
464+
inKeyNoteOnlyToggle.SetEnableFunc([&]() -> bool { return notePadConfigs[activeConfig].mode == OCTAVE_LAYOUT || notePadConfigs[activeConfig].mode == OFFSET_LAYOUT || notePadConfigs[activeConfig].mode == CHROMATIC_LAYOUT;; });
469465
layoutSelector.AddUIComponent(inKeyNoteOnlyToggle, Point(0, 7));
470466

471467
layoutSelector.Start();

Applications/Note/NotePad.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
enum NoteLayoutMode : uint8_t {
99
OCTAVE_LAYOUT,
1010
OFFSET_LAYOUT,
11+
CHROMATIC_LAYOUT,
1112
PIANO_LAYOUT,
1213
};
1314

@@ -253,6 +254,27 @@ class NotePad : public UIComponent {
253254
}
254255
}
255256

257+
void GenerateChromaticKeymap() {
258+
noteMap.reserve(dimension.Area());
259+
uint8_t note = 12 * config->octave + config->rootKey;
260+
for(uint8_t i = 0; i < dimension.Area(); i++)
261+
{
262+
uint8_t x = i % dimension.x;
263+
uint8_t y = i / dimension.x;
264+
int8_t ui_y = dimension.y - y - 1;
265+
noteMap[ui_y * dimension.x + x] = note;
266+
if(!config->inKeyNoteOnly)
267+
{
268+
note++;
269+
}
270+
else
271+
{
272+
note = GetNextInScaleNote(note);
273+
}
274+
}
275+
}
276+
277+
256278
void GeneratePianoKeymap() {
257279
noteMap.reserve(dimension.Area());
258280
const int8_t blackKeys[7] = {-1, 1, 3, -1, 6, 8, 10};
@@ -298,6 +320,9 @@ class NotePad : public UIComponent {
298320
case OFFSET_LAYOUT:
299321
GenerateOffsetKeymap();
300322
break;
323+
case CHROMATIC_LAYOUT:
324+
GenerateChromaticKeymap();
325+
break;
301326
case PIANO_LAYOUT:
302327
GeneratePianoKeymap();
303328
break;

0 commit comments

Comments
 (0)