Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add community feature setting to allow for notes to be displayed with either sharps or flats #3203

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/deluge/gui/l10n/english.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@
"STRING_FOR_DEFAULT_UI_DEFAULT_STARTUP_SONG_MODE_TEMPLATE": "Template song (Default.xml)",
"STRING_FOR_DEFAULT_UI_DEFAULT_STARTUP_SONG_MODE_LAST_OPENED": "Last opened song",
"STRING_FOR_DEFAULT_UI_DEFAULT_STARTUP_SONG_MODE_LAST_SAVED": "Last saved song",
"STRING_FOR_DEFAULT_UI_FLATS": "Use Flats (b)",
"STRING_FOR_TEMPO_MAGNITUDE_MATCHING": "Tempo magnitude matching",
"STRING_FOR_TRIGGER_CLOCK": "Trigger clock",
"STRING_FOR_FM_MODULATOR_1": "FM modulator 1",
Expand Down Expand Up @@ -491,6 +492,7 @@
"STRING_FOR_COMMUNITY_FEATURE_FINE_TEMPO_KNOB": "Fine Tempo Knob",
"STRING_FOR_COMMUNITY_FEATURE_MOD_DEPTH_DECIMALS": "Mod. Depth Decimals",
"STRING_FOR_COMMUNITY_FEATURE_CATCH_NOTES": "Catch Notes",
"STRING_FOR_COMMUNITY_FEATURE_USE_FLATS": "Use Flats (b)",
"STRING_FOR_COMMUNITY_FEATURE_DELETE_UNUSED_KIT_ROWS": "Delete Unused Kit Rows",
"STRING_FOR_COMMUNITY_FEATURE_ALT_DELAY_PARAMS": "Alternative Golden Knob Delay Params",
"STRING_FOR_COMMUNITY_FEATURE_QUANTIZED_STUTTER": "Stutter Rate Quantize",
Expand Down
1 change: 1 addition & 0 deletions src/deluge/gui/l10n/g_english.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ PLACE_SDRAM_DATA Language english{
{STRING_FOR_COMMUNITY_FEATURE_FINE_TEMPO_KNOB, "Fine Tempo Knob"},
{STRING_FOR_COMMUNITY_FEATURE_MOD_DEPTH_DECIMALS, "Mod. Depth Decimals"},
{STRING_FOR_COMMUNITY_FEATURE_CATCH_NOTES, "Catch Notes"},
{STRING_FOR_COMMUNITY_FEATURE_USE_FLATS, "Use Flats (b)"},
{STRING_FOR_COMMUNITY_FEATURE_DELETE_UNUSED_KIT_ROWS, "Delete Unused Kit Rows"},
{STRING_FOR_COMMUNITY_FEATURE_ALT_DELAY_PARAMS, "Alternative Golden Knob Delay Params"},
{STRING_FOR_COMMUNITY_FEATURE_QUANTIZED_STUTTER, "Stutter Rate Quantize"},
Expand Down
1 change: 1 addition & 0 deletions src/deluge/gui/l10n/g_seven_segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ PLACE_SDRAM_DATA Language seven_segment{
{STRING_FOR_COMMUNITY_FEATURE_FINE_TEMPO_KNOB, "TEMP"},
{STRING_FOR_COMMUNITY_FEATURE_MOD_DEPTH_DECIMALS, "MOD."},
{STRING_FOR_COMMUNITY_FEATURE_CATCH_NOTES, "CATC"},
{STRING_FOR_COMMUNITY_FEATURE_USE_FLATS, "FLAT"},
{STRING_FOR_COMMUNITY_FEATURE_DELETE_UNUSED_KIT_ROWS, "UNUS"},
{STRING_FOR_COMMUNITY_FEATURE_ALT_DELAY_PARAMS, "DELA"},
{STRING_FOR_COMMUNITY_FEATURE_QUANTIZED_STUTTER, "STUT"},
Expand Down
2 changes: 2 additions & 0 deletions src/deluge/gui/l10n/seven_segment.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@
"STRING_FOR_DEFAULT_UI_DEFAULT_STARTUP_SONG_MODE_TEMPLATE": "TMPL",
"STRING_FOR_DEFAULT_UI_DEFAULT_STARTUP_SONG_MODE_LAST_OPENED": "OPEN",
"STRING_FOR_DEFAULT_UI_DEFAULT_STARTUP_SONG_MODE_LAST_SAVED": "SAVE",
"STRING_FOR_DEFAULT_UI_FLATS": "FLAT",
"STRING_FOR_TEMPO_MAGNITUDE_MATCHING": "MAGN",
"STRING_FOR_TRIGGER_CLOCK": "TCLOCK",
"STRING_FOR_FM_MODULATOR_1": "MOD1",
Expand Down Expand Up @@ -373,6 +374,7 @@
"STRING_FOR_COMMUNITY_FEATURE_FINE_TEMPO_KNOB": "TEMP",
"STRING_FOR_COMMUNITY_FEATURE_MOD_DEPTH_DECIMALS": "MOD.",
"STRING_FOR_COMMUNITY_FEATURE_CATCH_NOTES": "CATC",
"STRING_FOR_COMMUNITY_FEATURE_USE_FLATS": "FLAT",
"STRING_FOR_COMMUNITY_FEATURE_DELETE_UNUSED_KIT_ROWS": "UNUS",
"STRING_FOR_COMMUNITY_FEATURE_ALT_DELAY_PARAMS": "DELA",
"STRING_FOR_COMMUNITY_FEATURE_QUANTIZED_STUTTER": "STUT",
Expand Down
1 change: 1 addition & 0 deletions src/deluge/gui/l10n/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ enum class String : size_t {
STRING_FOR_COMMUNITY_FEATURE_FINE_TEMPO_KNOB,
STRING_FOR_COMMUNITY_FEATURE_MOD_DEPTH_DECIMALS,
STRING_FOR_COMMUNITY_FEATURE_CATCH_NOTES,
STRING_FOR_COMMUNITY_FEATURE_USE_FLATS,
STRING_FOR_COMMUNITY_FEATURE_DELETE_UNUSED_KIT_ROWS,
STRING_FOR_COMMUNITY_FEATURE_ALT_DELAY_PARAMS,
STRING_FOR_COMMUNITY_FEATURE_QUANTIZED_STUTTER,
Expand Down
16 changes: 12 additions & 4 deletions src/deluge/gui/menu_item/key_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "gui/ui/sound_editor.h"
#include "hid/display/display.h"
#include "util/functions.h"
#include "model/settings/runtime_feature_settings.h"


namespace deluge::gui::menu_item {

Expand Down Expand Up @@ -57,11 +59,17 @@ void KeyRange::selectEncoderAction(int32_t offset) {

void KeyRange::getText(char* buffer, int32_t* getLeftLength, int32_t* getRightLength, bool mayShowJustOne) {

*(buffer++) = noteCodeToNoteLetter[lower];
bool useFlats = runtimeFeatureSettings.get(RuntimeFeatureSettingType::UseFlats)
== RuntimeFeatureStateToggle::On;
char accidential = !useFlats ? '#' : 'b';


*(buffer++) = !useFlats ? noteCodeToNoteLetter[lower] : noteCodeToNoteLetterFlats[lower];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears in a lot of places now. Might be nicer to have getNoteLetterAndAccidental(int32_t node, char& letter, char& accidental) which checks the runtimeFeature and provides them, instead of duplicating the code.

Copy link
Collaborator

@nikodemus nikodemus Jan 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(There is no meaningful performance impact from an additional function call in display code, and a possible benefit from reduced code size by reducing duplication.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be made inline if there's a desire for avoiding the stack, but I agree, a function would be more DRY.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that makes sense. Where should I put the function since it would be used from multiple files?

int32_t leftLength = 1;


if (noteCodeIsSharp[lower]) {
*(buffer++) = (display->haveOLED()) ? '#' : '.';
*(buffer++) = (display->haveOLED()) ? accidential : '.';
if (display->haveOLED()) {
leftLength++;
}
Expand All @@ -81,10 +89,10 @@ void KeyRange::getText(char* buffer, int32_t* getLeftLength, int32_t* getRightLe

*(buffer++) = '-';

*(buffer++) = noteCodeToNoteLetter[upper];
*(buffer++) = !useFlats ? noteCodeToNoteLetter[upper] : noteCodeToNoteLetterFlats[upper];
int32_t rightLength = 1;
if (noteCodeIsSharp[upper]) {
*(buffer++) = (display->haveOLED()) ? '#' : '.';
*(buffer++) = (display->haveOLED()) ? accidential : '.';
if (display->haveOLED()) {
rightLength++;
}
Expand Down
2 changes: 2 additions & 0 deletions src/deluge/gui/menu_item/runtime_feature/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ SettingToggle menuFineTempo(RuntimeFeatureSettingType::FineTempoKnob);
SettingToggle menuQuantize(RuntimeFeatureSettingType::Quantize);
SettingToggle menuPatchCableResolution(RuntimeFeatureSettingType::PatchCableResolution);
SettingToggle menuCatchNotes(RuntimeFeatureSettingType::CatchNotes);
SettingToggle menuUseFlats(RuntimeFeatureSettingType::UseFlats);
SettingToggle menuDeleteUnusedKitRows(RuntimeFeatureSettingType::DeleteUnusedKitRows);
SettingToggle menuAltGoldenKnobDelayParams(RuntimeFeatureSettingType::AltGoldenKnobDelayParams);
SettingToggle menuQuantizedStutterRate(RuntimeFeatureSettingType::QuantizedStutterRate);
Expand All @@ -58,6 +59,7 @@ std::array<MenuItem*, RuntimeFeatureSettingType::MaxElement - kNonTopLevelSettin
&menuQuantize,
&menuPatchCableResolution,
&menuCatchNotes,
&menuUseFlats,
&menuDeleteUnusedKitRows,
&menuAltGoldenKnobDelayParams,
&menuQuantizedStutterRate,
Expand Down
9 changes: 7 additions & 2 deletions src/deluge/gui/ui/keyboard/keyboard_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,15 +766,20 @@ void KeyboardScreen::selectEncoderAction(int8_t offset) {
}
else if (getCurrentOutputType() != OutputType::KIT && currentUIMode == UI_MODE_SCALE_MODE_BUTTON_PRESSED
&& getCurrentInstrumentClip()->inScaleMode) {

bool useFlats = runtimeFeatureSettings.get(RuntimeFeatureSettingType::UseFlats)
== RuntimeFeatureStateToggle::On;
toggleScaleModeOnButtonRelease = false;
int32_t newRootNote = ((currentSong->key.rootNote + kOctaveSize) + offset) % kOctaveSize;
instrumentClipView.setupChangingOfRootNote(newRootNote);

char noteName[3] = {0};
noteName[0] = noteCodeToNoteLetter[newRootNote];
noteName[0] = !useFlats ? noteCodeToNoteLetter[newRootNote] : noteCodeToNoteLetterFlats[newRootNote];

if (display->haveOLED()) {
if (noteCodeIsSharp[newRootNote]) {
noteName[1] = '#';
char accidential = !useFlats ? '#' : 'b';
noteName[1] = accidential;
}
}
display->displayPopup(noteName, 3, false, (noteCodeIsSharp[newRootNote] ? 0 : 255));
Expand Down
5 changes: 5 additions & 0 deletions src/deluge/model/settings/runtime_feature_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ void RuntimeFeatureSettings::init() {
// CatchNotes
SetupOnOffSetting(settings[RuntimeFeatureSettingType::CatchNotes], STRING_FOR_COMMUNITY_FEATURE_CATCH_NOTES,
"catchNotes", RuntimeFeatureStateToggle::On);

// UseFlats
SetupOnOffSetting(settings[RuntimeFeatureSettingType::UseFlats], STRING_FOR_COMMUNITY_FEATURE_USE_FLATS,
"useFlats", RuntimeFeatureStateToggle::Off);

// DeleteUnusedKitRows
SetupOnOffSetting(settings[RuntimeFeatureSettingType::DeleteUnusedKitRows],
STRING_FOR_COMMUNITY_FEATURE_DELETE_UNUSED_KIT_ROWS, "deleteUnusedKitRows",
Expand Down
1 change: 1 addition & 0 deletions src/deluge/model/settings/runtime_feature_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ enum RuntimeFeatureSettingType : uint32_t {
FineTempoKnob,
PatchCableResolution,
CatchNotes,
UseFlats,
DeleteUnusedKitRows,
AltGoldenKnobDelayParams,
QuantizedStutterRate,
Expand Down
11 changes: 9 additions & 2 deletions src/deluge/util/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "gui/ui/qwerty_ui.h"
#include "hid/display/display.h"
#include "hid/encoders.h"
#include "model/settings/runtime_feature_settings.h"
#include "modulation/arpeggiator.h"
#include "processing/audio_output.h"
#include "processing/sound/sound.h"
Expand Down Expand Up @@ -1879,10 +1880,16 @@ void noteCodeToString(int32_t noteCode, char* buffer, int32_t* getLengthWithoutD
int32_t octave = (noteCode) / 12 - 2;
int32_t noteCodeWithinOctave = (uint16_t)(noteCode + 120) % (uint8_t)12;

*thisChar = noteCodeToNoteLetter[noteCodeWithinOctave];
bool useFlats = runtimeFeatureSettings.get(RuntimeFeatureSettingType::UseFlats)
== RuntimeFeatureStateToggle::On;


*thisChar = !useFlats ? noteCodeToNoteLetter[noteCodeWithinOctave] : noteCodeToNoteLetterFlats[noteCodeWithinOctave];

thisChar++;
if (noteCodeIsSharp[noteCodeWithinOctave]) {
*thisChar = display->haveOLED() ? '#' : '.';
char accidential = !useFlats ? '#' : 'b';
*thisChar = display->haveOLED() ? accidential : '.';
thisChar++;
}
if (appendOctaveNo) {
Expand Down
7 changes: 6 additions & 1 deletion src/deluge/util/lookuptables/lookuptables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,15 @@ const int16_t lanczosKernelA16[1025] = {
0, };



//C C# D D# E F F# G G# A A# B
const uint8_t noteCodeToNoteLetter[12] = {67, 67, 68, 68, 69, 70, 70, 71, 71, 65, 65, 66};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{'C', 'C', 'D', ...} etc instead of raw ascii codes, preferably.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am weary to change the existing constant. What would the implications of that change be? Would I need to update the places that use the constant?

const bool noteCodeIsSharp[12] = {0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0};

//C Db D Eb E F Gb G Ab A Bb B
const uint8_t noteCodeToNoteLetterFlats[12] = {67, 68, 68, 69, 69, 70, 71, 71, 65, 65, 66, 66};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{'C', 'C', 'D', ...} etc instead of raw ascii codes, preferably.

const bool noteCodeIsFlat[12] = {0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same table as notecodeIsSharp, can have just one table noteHasAccidental.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't end up using noteCodeIsFlat anyways, I should delete. I think I'd rather not change the existing constants and will just use noteCodeIsSharp



/**
* @brief How iterance is encoded:
*
Expand Down
3 changes: 3 additions & 0 deletions src/deluge/util/lookuptables/lookuptables.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ extern deluge::l10n::String presetReverbNames[NUM_PRESET_REVERBS];
extern const uint8_t noteCodeToNoteLetter[];
extern const bool noteCodeIsSharp[];

extern const uint8_t noteCodeToNoteLetterFlats[];
extern const bool noteCodeIsFlat[];

extern const std::array<Iterance, 35> iterancePresets;

#define MAX_CHORD_TYPES 9
Expand Down