Skip to content

Commit

Permalink
* Removed &isNatural parameter from noteCodeToString()
Browse files Browse the repository at this point in the history
* rootNote set to given noteCode when not provided as parameter
* Tested MultiRange menu option
* Adjusted KeyRange highlight of right side to line up with note display
*
  • Loading branch information
todd-gochenour committed Jan 14, 2025
1 parent 3a80f89 commit e30bb45
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 36 deletions.
10 changes: 8 additions & 2 deletions src/deluge/gui/menu_item/multi_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,10 @@ void MultiRange::getText(char* buffer, int32_t* getLeftLength, int32_t* getRight
}
else {
int32_t note = soundEditor.currentSource->ranges.getElement(this->getValue() - 1)->topNote + 1;
noteCodeToString(note, buffer, getLeftLength);
noteCodeToString(note, buffer);
if (getLeftLength) {
*getLeftLength = strlen(buffer);
}
}

char* bufferPos = buffer + strlen(buffer);
Expand Down Expand Up @@ -385,7 +388,10 @@ void MultiRange::getText(char* buffer, int32_t* getLeftLength, int32_t* getRight

*(bufferPos++) = '-';
*(bufferPos++) = ' ';
noteCodeToString(note, bufferPos, getRightLength);
noteCodeToString(note, bufferPos);
if (getRightLength) {
*getRightLength = strlen(bufferPos);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/deluge/gui/menu_item/range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void Range::drawPixelsForOled() {
else if (soundEditor.editingRangeEdge == RangeEdit::RIGHT) {
int32_t stringEndX = (OLED_MAIN_WIDTH_PIXELS + stringWidth) >> 1;
highlightWidth = digitWidth * rightLength;
highlightStartX = stringEndX - highlightWidth;
highlightStartX = stringEndX - highlightWidth - (kTextHugeSpacingX >> 1); // dash is half the width of digit
goto doHighlightJustOneEdge;
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/deluge/gui/ui/keyboard/keyboard_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,10 +768,9 @@ void KeyboardScreen::selectEncoderAction(int8_t offset) {
instrumentClipView.setupChangingOfRootNote(newRootNote);

char noteName[3] = {0};
int32_t isNatural = 1; // gets modified inside noteCodeToString to be 0 if sharp or flat.
noteCodeToString(currentSong->key.rootNote, noteName, &isNatural, true, currentSong->key.rootNote,
noteCodeToString(currentSong->key.rootNote, noteName, true, currentSong->key.rootNote,
currentSong->getCurrentScale());
display->displayPopup(noteName, 3, false, (noteIsAltered[newRootNote] ? 0 : 255));
display->displayPopup(noteName, 3);
layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->handleHorizontalEncoder(
0, false, pressedPads, xEncoderActive);
layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->precalculate();
Expand Down
6 changes: 2 additions & 4 deletions src/deluge/gui/ui/keyboard/layout/chord_keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,7 @@ void KeyboardLayoutChord::handleControlButton(int32_t x, int32_t y) {

void KeyboardLayoutChord::drawChordName(int16_t noteCode, const char* chordName, const char* voicingName) {
char noteName[3] = {0};
int32_t isNatural = 1; // gets modified inside noteCodeToString to be 0 if sharp or flat.
noteCodeToString(noteCode, noteName, &isNatural, false, currentSong->key.rootNote, currentSong->getCurrentScale());
noteCodeToString(noteCode, noteName, false, currentSong->key.rootNote, currentSong->getCurrentScale());

char fullChordName[300];
if (voicingName && *voicingName) {
Expand All @@ -271,10 +270,9 @@ void KeyboardLayoutChord::drawChordName(int16_t noteCode, const char* chordName,
}
if (display->haveOLED()) {
display->popupTextTemporary(fullChordName);
D_PRINTLN("Popup text: %s", fullChordName);
// D_PRINTLN("Popup text: %s", fullChordName);
}
else {
int8_t drawDot = !isNatural ? 0 : 255;
display->setScrollingText(fullChordName, 0);
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/deluge/gui/ui/keyboard/layout/chord_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ void KeyboardLayoutChordLibrary::renderPads(RGB image[][kDisplayWidth + kSideBar

void KeyboardLayoutChordLibrary::drawChordName(int16_t noteCode, const char* chordName, const char* voicingName) {
char noteName[3] = {0};
int32_t isNatural = 1; // gets modified inside noteCodeToString to be 0 if sharp.
noteCodeToString(noteCode, noteName, &isNatural, false, currentSong->key.rootNote, currentSong->getCurrentScale());
noteCodeToString(noteCode, noteName, false, currentSong->key.rootNote, currentSong->getCurrentScale());

char fullChordName[300];

Expand All @@ -181,7 +180,6 @@ void KeyboardLayoutChordLibrary::drawChordName(int16_t noteCode, const char* cho
display->popupTextTemporary(fullChordName);
}
else {
int8_t drawDot = !isNatural ? 0 : 255;
display->setScrollingText(fullChordName, 0);
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/deluge/gui/views/automation_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1394,8 +1394,7 @@ void AutomationView::renderNoteEditorDisplayOLED(deluge::hid::display::oled_canv
strncpy(noteRowName, drumName.c_str(), 49);
}
else {
int32_t isNatural = 1; // gets modified inside noteCodeToString to be 0 if sharp.
noteCodeToString(modelStackWithNoteRow->getNoteRow()->getNoteCode(), noteRowName, &isNatural, true,
noteCodeToString(modelStackWithNoteRow->getNoteRow()->getNoteCode(), noteRowName, true,
currentSong->key.rootNote, currentSong->getCurrentScale());
}
}
Expand Down Expand Up @@ -1575,8 +1574,7 @@ void AutomationView::renderNoteEditorDisplay7SEG(InstrumentClip* clip, OutputTyp
strncpy(noteRowName, drumName.c_str(), 49);
}
else {
int32_t isNatural = 1; // gets modified inside noteCodeToString to be 0 if sharp or flat.
noteCodeToString(modelStackWithNoteRow->getNoteRow()->getNoteCode(), noteRowName, &isNatural, true,
noteCodeToString(modelStackWithNoteRow->getNoteRow()->getNoteCode(), noteRowName, true,
currentSong->key.rootNote, currentSong->getCurrentScale());
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/deluge/model/clip/instrument_clip_minder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,14 +559,12 @@ void InstrumentClipMinder::drawActualNoteCode(int16_t noteCode) {
}

char noteName[5];
int32_t isNatural = 1; // gets modified inside noteCodeToString to be 0 if sharp or flat.
noteCodeToString(noteCode, noteName, &isNatural, true, currentSong->key.rootNote, currentSong->getCurrentScale());
noteCodeToString(noteCode, noteName, true, currentSong->key.rootNote, currentSong->getCurrentScale());
if (display->haveOLED()) {
display->popupTextTemporary(noteName);
}
else {
uint8_t drawDot = !isNatural ? 0 : 255;
display->setText(noteName, false, drawDot, true);
display->setText(noteName, false, 255, true);
}
}

Expand Down
17 changes: 6 additions & 11 deletions src/deluge/model/scale/preset_scales.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ const uint8_t getAccidental(int32_t rootNoteCode, Scale scale) {
}
}

void noteCodeToString(int32_t noteCode, char* buffer, int32_t* getLengthWithoutDot,
void noteCodeToString(int32_t noteCode, char* buffer,
bool appendOctaveNo, // defaults to true
int32_t rootNoteCode, // defaults to -1
Scale scale) { // defaults to NO_SCALE
int32_t rootNoteCode, // defaults to -1, becomes noteCode
Scale scale) { // defaults to MAJOR
char* thisChar = buffer;
int32_t octave = (noteCode) / 12 - 2;
int32_t n = (uint16_t)(noteCode + 120) % (uint8_t)12;

if (rootNoteCode == -1) {
rootNoteCode = noteCode;
}
uint8_t accidental = getAccidental(rootNoteCode, scale);
if (noteIsAltered[n]) { // actually: if code is a black key on the piano?
if ((accidental == '#')) {
Expand All @@ -88,13 +90,6 @@ void noteCodeToString(int32_t noteCode, char* buffer, int32_t* getLengthWithoutD
if (appendOctaveNo) {
intToString(octave, thisChar, 1);
}

if (getLengthWithoutDot) {
*getLengthWithoutDot = strlen(buffer);
if (noteIsAltered[n]) {
(*getLengthWithoutDot)--;
}
}
// D_PRINTLN(",noteCodeToString,%s", buffer);
}

Expand Down
4 changes: 2 additions & 2 deletions src/deluge/model/scale/preset_scales.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ const uint8_t majorAccidental[12] = {129, 129, '#', 129, '#', 129, '#', '#', 129
const uint8_t noteLetter[12] = {'C', 'C', 'D', 'D', 'E', 'F', 'F', 'G', 'G', 'A', 'A', 'B'};
const uint8_t noteIsAltered[12] = {0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0};
const uint8_t getAccidental(int32_t rootNoteCode, Scale scale);
void noteCodeToString(int32_t noteCode, char* buffer, int32_t* getLengthWithoutDot = nullptr,
bool appendOctaveNo = true, int32_t rootNoteCode = -1, Scale scale = Scale::NO_SCALE);
void noteCodeToString(int32_t noteCode, char* buffer, bool appendOctaveNo = true, int32_t rootNoteCode = -1,
Scale scale = Scale::MAJOR_SCALE);

Scale getScale(NoteSet notes);

Expand Down
3 changes: 1 addition & 2 deletions src/deluge/model/song/song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5782,8 +5782,7 @@ Error Song::addInstrumentsToFileItems(OutputType outputType) {

void Song::getCurrentRootNoteAndScaleName(StringBuf& buffer) {
char noteName[5];
int32_t isNatural = 1; // gets modified inside noteCodeToString to be 0 if sharp or flat.
noteCodeToString(currentSong->key.rootNote, noteName, &isNatural, true, currentSong->key.rootNote,
noteCodeToString(currentSong->key.rootNote, noteName, true, currentSong->key.rootNote,
currentSong->getCurrentScale());

buffer.append(noteName);
Expand Down

0 comments on commit e30bb45

Please sign in to comment.