From d1fa20c319aeb02ee32104dc531c2a090ce67997 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Thu, 2 Jan 2025 18:50:39 -0500 Subject: [PATCH 1/7] refactor more const char* to std::string and std::string_view depending on ownership --- src/CMakeLists.txt | 9 +- src/deluge/gui/l10n/english.json | 13 +- src/deluge/gui/l10n/g_english.cpp | 9 ++ src/deluge/gui/l10n/g_seven_segment.cpp | 10 ++ src/deluge/gui/l10n/seven_segment.json | 14 +- src/deluge/gui/l10n/strings.h | 11 ++ src/deluge/gui/menu_item/decimal.cpp | 87 +++++----- src/deluge/gui/menu_item/defaults/magnitude.h | 8 +- .../gui/menu_item/defaults/swing_interval.h | 4 +- src/deluge/gui/menu_item/dx/param.cpp | 29 ++-- src/deluge/gui/menu_item/integer.cpp | 8 +- src/deluge/gui/menu_item/integer_range.cpp | 29 ++-- src/deluge/gui/menu_item/integer_range.h | 2 +- src/deluge/gui/menu_item/key_range.cpp | 42 +++-- src/deluge/gui/menu_item/key_range.h | 2 +- src/deluge/gui/menu_item/midi/command.cpp | 12 +- src/deluge/gui/menu_item/multi_range.cpp | 50 +++--- src/deluge/gui/menu_item/multi_range.h | 6 +- .../gui/menu_item/patch_cable_strength.cpp | 12 +- src/deluge/gui/menu_item/patch_cables.cpp | 8 +- src/deluge/gui/menu_item/range.cpp | 40 ++--- src/deluge/gui/menu_item/range.h | 4 +- src/deluge/gui/menu_item/sync_level.cpp | 17 +- src/deluge/gui/menu_item/sync_level.h | 2 +- .../menu_item/sync_level/relative_to_song.h | 4 +- .../gui/ui/keyboard/layout/chord_keyboard.cpp | 7 +- .../ui/keyboard/layout/column_controls.cpp | 24 +-- src/deluge/gui/views/session_view.cpp | 19 ++- src/deluge/gui/views/session_view.h | 4 +- src/deluge/gui/views/timeline_view.cpp | 5 +- src/deluge/gui/views/view.cpp | 24 ++- src/deluge/hid/display/display.h | 18 +-- src/deluge/hid/display/oled.cpp | 82 +++++----- src/deluge/hid/display/oled.h | 18 +-- src/deluge/hid/display/oled_canvas/canvas.cpp | 14 +- src/deluge/hid/display/oled_canvas/canvas.h | 17 +- src/deluge/hid/display/seven_segment.cpp | 20 +-- src/deluge/hid/display/seven_segment.h | 22 +-- .../global_effectable/global_effectable.cpp | 5 +- .../mod_controllable_audio.cpp | 14 +- .../mod_controllable/mod_controllable_audio.h | 2 +- src/deluge/model/song/song.cpp | 8 +- src/deluge/model/song/song.h | 4 +- src/deluge/model/sync.cpp | 22 +-- src/deluge/model/sync.h | 2 +- src/deluge/playback/playback_handler.cpp | 65 +++----- src/deluge/playback/playback_handler.h | 2 +- src/deluge/processing/sound/sound.cpp | 4 +- src/deluge/util/cfunctions.c | 148 ------------------ src/deluge/util/cfunctions.h | 2 - src/deluge/util/d_string.cpp | 28 ++++ src/deluge/util/d_string.h | 101 +++++++++--- src/deluge/util/functions.cpp | 115 ++++++++------ src/deluge/util/functions.h | 5 +- src/deluge/util/lookuptables/lookuptables.cpp | 4 +- src/deluge/util/lookuptables/lookuptables.h | 2 +- src/deluge/util/string.cpp | 83 ++++++++++ src/deluge/util/string.h | 19 +++ src/sys_stubs.c | 116 +++++++------- 59 files changed, 768 insertions(+), 689 deletions(-) create mode 100644 src/deluge/util/string.cpp create mode 100644 src/deluge/util/string.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0d165e29ed..15f84ded59 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,13 @@ cmake_path(SET SHARED_INCLUDE ${CMAKE_CURRENT_LIST_DIR}) -target_sources(deluge PUBLIC main.c resetprg.c c_lib_alternatives.S malloc.c terminate.cpp) +target_sources(deluge PUBLIC + main.c + resetprg.c + c_lib_alternatives.S + malloc.c + terminate.cpp + sys_stubs.c +) add_subdirectory(OSLikeStuff) add_subdirectory(deluge) diff --git a/src/deluge/gui/l10n/english.json b/src/deluge/gui/l10n/english.json index 142aa5741b..c9592cb734 100644 --- a/src/deluge/gui/l10n/english.json +++ b/src/deluge/gui/l10n/english.json @@ -946,6 +946,17 @@ "STRING_FOR_DEFAULT_CLIP_TYPE": "Clip Type", "STRING_FOR_DEFAULT_NEW_CLIP_TYPE": "New Clip Type", - "STRING_FOR_DEFAULT_USE_LAST_CLIP_TYPE": "Use Last Clip Type" + "STRING_FOR_DEFAULT_USE_LAST_CLIP_TYPE": "Use Last Clip Type", + + "STRING_FOR_CHORD_ROW_MODE" : "Chord Row Mode", + "STRING_FOR_CHORD_COLUMN_MODE" : "Chord Column Mode", + + "STRING_FOR_MODWHEEL": "Modwheel", + "STRING_FOR_CHORD": "Chord", + "STRING_FOR_SONG_CHORD_MEMORY": "Song Chord Memory", + "STRING_FOR_CLIP_CHORD_MEMORY": "Clip Chord Memory", + "STRING_FOR_DX_OPERATORS": "DX operators", + "STRING_FOR_SONG_MACROS": "Song macros", + "STRING_FOR_BEAT_REPEAT": "Beat repeat" } } diff --git a/src/deluge/gui/l10n/g_english.cpp b/src/deluge/gui/l10n/g_english.cpp index 8a0cb1cce1..da2b59595e 100644 --- a/src/deluge/gui/l10n/g_english.cpp +++ b/src/deluge/gui/l10n/g_english.cpp @@ -869,6 +869,15 @@ PLACE_SDRAM_DATA Language english{ {STRING_FOR_DEFAULT_CLIP_TYPE, "Clip Type"}, {STRING_FOR_DEFAULT_NEW_CLIP_TYPE, "New Clip Type"}, {STRING_FOR_DEFAULT_USE_LAST_CLIP_TYPE, "Use Last Clip Type"}, + {STRING_FOR_CHORD_ROW_MODE, "Chord Row Mode"}, + {STRING_FOR_CHORD_COLUMN_MODE, "Chord Column Mode"}, + {STRING_FOR_MODWHEEL, "Modwheel"}, + {STRING_FOR_CHORD, "Chord"}, + {STRING_FOR_SONG_CHORD_MEMORY, "Song Chord Memory"}, + {STRING_FOR_CLIP_CHORD_MEMORY, "Clip Chord Memory"}, + {STRING_FOR_DX_OPERATORS, "DX operators"}, + {STRING_FOR_SONG_MACROS, "Song macros"}, + {STRING_FOR_BEAT_REPEAT, "Beat repeat"}, }, }; } // namespace deluge::l10n::built_in diff --git a/src/deluge/gui/l10n/g_seven_segment.cpp b/src/deluge/gui/l10n/g_seven_segment.cpp index 6d0d0c38fa..aaf1fb47ee 100644 --- a/src/deluge/gui/l10n/g_seven_segment.cpp +++ b/src/deluge/gui/l10n/g_seven_segment.cpp @@ -499,6 +499,16 @@ PLACE_SDRAM_DATA Language seven_segment{ {STRING_FOR_NOTE_ROW_EDITOR_FILL, "FILL"}, {STRING_FOR_DEFAULT_NEW_CLIP_TYPE, "TYPE"}, {STRING_FOR_DEFAULT_USE_LAST_CLIP_TYPE, "LAST"}, + {STRING_FOR_CHORD_ROW_MODE, "ROW"}, + {STRING_FOR_CHORD_COLUMN_MODE, "COL"}, + {STRING_FOR_VELOCITY, "VEL"}, + {STRING_FOR_MODWHEEL, "MOD"}, + {STRING_FOR_CHORD, "CHRD"}, + {STRING_FOR_SONG_CHORD_MEMORY, "CMEM"}, + {STRING_FOR_CLIP_CHORD_MEMORY, "CCME"}, + {STRING_FOR_DX_OPERATORS, "DX"}, + {STRING_FOR_SONG_MACROS, "SONG"}, + {STRING_FOR_BEAT_REPEAT, "BEAT"}, }, &built_in::english, }; diff --git a/src/deluge/gui/l10n/seven_segment.json b/src/deluge/gui/l10n/seven_segment.json index 84931b2169..74504386d3 100644 --- a/src/deluge/gui/l10n/seven_segment.json +++ b/src/deluge/gui/l10n/seven_segment.json @@ -537,6 +537,18 @@ "STRING_FOR_NOTE_ROW_EDITOR_FILL": "FILL", "STRING_FOR_DEFAULT_NEW_CLIP_TYPE": "TYPE", - "STRING_FOR_DEFAULT_USE_LAST_CLIP_TYPE": "LAST" + "STRING_FOR_DEFAULT_USE_LAST_CLIP_TYPE": "LAST", + + "STRING_FOR_CHORD_ROW_MODE" : "ROW", + "STRING_FOR_CHORD_COLUMN_MODE" : "COL", + + "STRING_FOR_VELOCITY": "VEL", + "STRING_FOR_MODWHEEL": "MOD", + "STRING_FOR_CHORD": "CHRD", + "STRING_FOR_SONG_CHORD_MEMORY": "CMEM", + "STRING_FOR_CLIP_CHORD_MEMORY": "CCME", + "STRING_FOR_DX_OPERATORS": "DX", + "STRING_FOR_SONG_MACROS": "SONG", + "STRING_FOR_BEAT_REPEAT": "BEAT" } } diff --git a/src/deluge/gui/l10n/strings.h b/src/deluge/gui/l10n/strings.h index bfec18cdd2..7103cef4fb 100644 --- a/src/deluge/gui/l10n/strings.h +++ b/src/deluge/gui/l10n/strings.h @@ -992,6 +992,17 @@ enum class String : size_t { STRING_FOR_DEFAULT_NEW_CLIP_TYPE, STRING_FOR_DEFAULT_USE_LAST_CLIP_TYPE, + STRING_FOR_CHORD_ROW_MODE, + STRING_FOR_CHORD_COLUMN_MODE, + + STRING_FOR_MODWHEEL, + STRING_FOR_CHORD, + STRING_FOR_SONG_CHORD_MEMORY, + STRING_FOR_CLIP_CHORD_MEMORY, + STRING_FOR_DX_OPERATORS, + STRING_FOR_SONG_MACROS, + STRING_FOR_BEAT_REPEAT, + STRING_LAST }; diff --git a/src/deluge/gui/menu_item/decimal.cpp b/src/deluge/gui/menu_item/decimal.cpp index 7f9cb73ebb..60c155c889 100644 --- a/src/deluge/gui/menu_item/decimal.cpp +++ b/src/deluge/gui/menu_item/decimal.cpp @@ -15,17 +15,18 @@ * If not, see . */ -#include -#include -#include - #include "decimal.h" #include "gui/ui/sound_editor.h" #include "hid/display/display.h" #include "hid/display/oled.h" #include "hid/led/indicator_leds.h" -#include "util/cfunctions.h" +#include "util/d_string.h" #include "util/functions.h" +#include "util/string.h" +#include +#include +#include +#include namespace deluge::gui::menu_item { @@ -131,61 +132,70 @@ void Decimal::scrollToGoodPos() { } void Decimal::drawPixelsForOled() { - int32_t numDecimalPlaces = getNumDecimalPlaces(); - char buffer[13]; - intToString(this->getValue(), buffer, numDecimalPlaces + 1); - int32_t length = strlen(buffer); + int32_t fractional_length = getNumDecimalPlaces(); + + std::string int_string = string::fromInt(this->getValue(), fractional_length + 1); + + std::string_view int_string_view = int_string; - int32_t editingChar = length - soundEditor.numberEditPos; - if (soundEditor.numberEditPos >= numDecimalPlaces) { + int32_t editingChar = int_string.length() - soundEditor.numberEditPos; + if (soundEditor.numberEditPos >= fractional_length) { editingChar--; } int32_t digitWidth = kTextHugeSpacingX; int32_t periodWidth = digitWidth / 2; - int32_t stringWidth = digitWidth * length + (numDecimalPlaces ? periodWidth : 0); + int32_t stringWidth = (digitWidth * int_string.length()) + (fractional_length ? periodWidth : 0); int32_t stringStartX = (OLED_MAIN_WIDTH_PIXELS - stringWidth) >> 1; int32_t ourDigitStartX = stringStartX + editingChar * digitWidth; // for values with decimal digits showing - if (numDecimalPlaces) { - int32_t numCharsBeforeDecimalPoint = length - numDecimalPlaces; + if (fractional_length) { + int32_t integral_length = int_string.length() - fractional_length; + // draw digits before period - hid::display::OLED::main.drawString(std::string_view(buffer, numCharsBeforeDecimalPoint), stringStartX, 20, - digitWidth, kTextHugeSizeY, 0, 128, true); + hid::display::OLED::main.drawString(int_string_view.substr(0, integral_length), stringStartX, 20, digitWidth, + kTextHugeSizeY, 0, 128, true); // draw period - hid::display::OLED::main.drawString(".", stringStartX + numCharsBeforeDecimalPoint * digitWidth, 20, - periodWidth, kTextHugeSizeY, 0, 128, true); + hid::display::OLED::main.drawString(".", stringStartX + integral_length * digitWidth, 20, periodWidth, + kTextHugeSizeY, 0, 128, true); + // modify properties so that the remaining digits and the cursor get drawn correctly - std::memmove(buffer, buffer + numCharsBeforeDecimalPoint, sizeof(buffer) - numCharsBeforeDecimalPoint); - stringStartX += numCharsBeforeDecimalPoint * digitWidth + periodWidth; - if (editingChar > numCharsBeforeDecimalPoint) + int_string_view = int_string_view.substr(integral_length); + stringStartX += integral_length * digitWidth + periodWidth; + if (editingChar > integral_length) ourDigitStartX -= periodWidth; } + // draw remaining digits - hid::display::OLED::main.drawString(buffer, stringStartX, 20, digitWidth, kTextHugeSizeY, 0, 128, true); + hid::display::OLED::main.drawString(int_string_view, stringStartX, 20, digitWidth, kTextHugeSizeY, 0, 128, true); + // draw cursor hid::display::OLED::setupBlink(ourDigitStartX + 1, digitWidth - 2, 41, 42, movingCursor); } void Decimal::drawActualValue(bool justDidHorizontalScroll) { - char buffer[12]; + int32_t minNumDigits = getNumDecimalPlaces() + 1; minNumDigits = std::max(minNumDigits, soundEditor.numberEditPos + 1); - intToString(this->getValue(), buffer, minNumDigits); - int32_t stringLength = strlen(buffer); - char* outputText = buffer + std::max(stringLength - 4 - soundEditor.numberScrollAmount, 0_i32); + std::string int_string = string::fromInt(this->getValue(), minNumDigits); + + std::string_view output_text = + static_cast(int_string) + .substr(std::max(static_cast(int_string.length()) - 4 - soundEditor.numberScrollAmount, 0_i32)); - if (strlen(outputText) > 4) { - outputText[4] = 0; + if (output_text.length() > 4) { + output_text = output_text.substr(0, 4); } int32_t dotPos; - if (getNumDecimalPlaces()) + if (getNumDecimalPlaces() != 0) { dotPos = soundEditor.numberScrollAmount + 3 - getNumDecimalPlaces(); - else + } + else { dotPos = 255; + } indicator_leds::blinkLed(IndicatorLED::BACK, 255, 0, !justDidHorizontalScroll); @@ -193,7 +203,7 @@ void Decimal::drawActualValue(bool justDidHorizontalScroll) { memset(&blinkMask, 255, kNumericDisplayLength); blinkMask[3 + soundEditor.numberScrollAmount - soundEditor.numberEditPos] = 0b10000000; - display->setText(outputText, + display->setText(output_text, true, // alignRight dotPos, // drawDot true, // doBlink @@ -219,10 +229,12 @@ void DecimalWithoutScrolling::selectEncoderAction(int32_t offset) { void DecimalWithoutScrolling::drawDecimal(int32_t textWidth, int32_t textHeight, int32_t yPixel) { int32_t numDecimalPlaces = getNumDecimalPlaces(); - char buffer[12]; - floatToString(getDisplayValue(), buffer, numDecimalPlaces, numDecimalPlaces); - strncat(buffer, getUnit(), 4); - deluge::hid::display::OLED::main.drawStringCentred(buffer, yPixel + OLED_MAIN_TOPMOST_PIXEL, textWidth, textHeight); + + std::string float_string = string::fromFloat(getDisplayValue(), numDecimalPlaces); + float_string.append(getUnit(), 4); + + deluge::hid::display::OLED::main.drawStringCentred(float_string, yPixel + OLED_MAIN_TOPMOST_PIXEL, textWidth, + textHeight); } void DecimalWithoutScrolling::drawPixelsForOled() { @@ -233,14 +245,13 @@ void DecimalWithoutScrolling::drawActualValue(bool justDidHorizontalScroll) { int32_t dotPos; float displayValue = getDisplayValue(); int32_t numDecimalPlaces = displayValue > 100 ? 1 : 2; - char buffer[12]; - floatToString(displayValue, buffer, numDecimalPlaces, numDecimalPlaces); + std::string text = string::fromFloat(displayValue, numDecimalPlaces); if (numDecimalPlaces) { dotPos = 3 - numDecimalPlaces; } else { dotPos = 255; } - display->setText(buffer, dotPos); + display->setText(text, dotPos); } } // namespace deluge::gui::menu_item diff --git a/src/deluge/gui/menu_item/defaults/magnitude.h b/src/deluge/gui/menu_item/defaults/magnitude.h index 2472b0bae5..f1231ae067 100644 --- a/src/deluge/gui/menu_item/defaults/magnitude.h +++ b/src/deluge/gui/menu_item/defaults/magnitude.h @@ -20,7 +20,7 @@ #include "hid/display/oled.h" #include "model/sync.h" #include "storage/flash_storage.h" -#include "util/d_string.h" +#include "util/string.h" namespace deluge::gui::menu_item::defaults { class Magnitude final : public Enumeration { @@ -36,11 +36,9 @@ class Magnitude final : public Enumeration { FlashStorage::defaultSwingInterval = clampSwingIntervalSyncLevel(FlashStorage::defaultSwingInterval - delta); } void drawPixelsForOled() override { - char buffer[12]; - deluge::hid::display::oled_canvas::Canvas& canvas = hid::display::OLED::main; + hid::display::oled_canvas::Canvas& canvas = hid::display::OLED::main; - intToString(96 << this->getValue(), buffer); - canvas.drawStringCentred(buffer, 18 + OLED_MAIN_TOPMOST_PIXEL, 18, 20); + canvas.drawStringCentred(string::fromInt(96 << this->getValue()), 18 + OLED_MAIN_TOPMOST_PIXEL, 18, 20); } void drawValue() override { display->setTextAsNumber(96 << this->getValue()); } diff --git a/src/deluge/gui/menu_item/defaults/swing_interval.h b/src/deluge/gui/menu_item/defaults/swing_interval.h index 6e152e2a1a..c335939f67 100644 --- a/src/deluge/gui/menu_item/defaults/swing_interval.h +++ b/src/deluge/gui/menu_item/defaults/swing_interval.h @@ -34,8 +34,8 @@ class SwingInterval final : public Interval { } protected: - void getNoteLengthName(StringBuf& buffer) override { - syncValueToString(this->getValue(), buffer, FlashStorage::defaultMagnitude); + std::string getNoteLengthName() override { + return syncValueToString(this->getValue(), FlashStorage::defaultMagnitude); } }; diff --git a/src/deluge/gui/menu_item/dx/param.cpp b/src/deluge/gui/menu_item/dx/param.cpp index 9c46d42232..82f2328afc 100644 --- a/src/deluge/gui/menu_item/dx/param.cpp +++ b/src/deluge/gui/menu_item/dx/param.cpp @@ -26,8 +26,10 @@ #include "model/song/song.h" #include "processing/sound/sound.h" #include "processing/source.h" +#include "util/string.h" #include #include +#include namespace deluge::gui::menu_item { @@ -353,20 +355,18 @@ void DxParam::flashParamName() { } using deluge::hid::display::OLED; -static void show(const char* text, int r, int c, bool inv = false) { +static void show(std::string_view text, int r, int c, bool inv = false) { int ybel = 7 + (2 + r) * (kTextSizeYUpdated + 2); int xpos = 5 + c * kTextSpacingX; OLED::main.drawString(text, xpos, ybel, kTextSpacingX, kTextSizeYUpdated); if (inv) { - int width = strlen(text); + int width = text.length(); OLED::main.invertArea(xpos - 1, kTextSpacingX * width + 1, ybel - 1, ybel + kTextSizeYUpdated); } } static void show(int val, int r, int c, bool inv = false) { - char buffer[12]; - intToString(val, buffer, 2); - show(buffer, r, c, inv); + show(string::fromInt(val, 2), r, c, inv); } static void renderEnvelope(uint8_t* params, int op, int idx) { @@ -381,8 +381,6 @@ static void renderEnvelope(uint8_t* params, int op, int idx) { } static void renderScaling(uint8_t* params, int op, int idx) { - char buffer[12]; - for (int i = 0; i < 2; i++) { int val = params[op * 21 + 9 + i]; show(val, 0, 1 + i * 11, (9 + i == idx)); @@ -393,9 +391,8 @@ static void renderScaling(uint8_t* params, int op, int idx) { int ybelmid = 7 + 2 * (kTextSizeYUpdated + 2) + ((kTextSizeYUpdated + 1) >> 1); int val = params[op * 21 + 8]; - intToString(val, buffer, 2); int xpos = 14 + 6 * kTextSpacingX; - OLED::main.drawString(buffer, xpos, ybelmid, kTextSpacingX, kTextSizeYUpdated); + OLED::main.drawString(string::fromInt(val, 2), xpos, ybelmid, kTextSpacingX, kTextSizeYUpdated); if (8 == idx) { OLED::main.invertArea(xpos - 1, kTextSpacingX * 2 + 1, ybelmid - 1, ybelmid + kTextSizeYUpdated); } @@ -456,7 +453,6 @@ static void renderTuning(uint8_t* params, int op, int param) { } static void renderLFO(uint8_t* params, int param) { - char buffer[12]; int ybel = 5 + 2 * (kTextSizeYUpdated + 2) + 2; int ybel2 = ybel + (kTextSizeYUpdated + 2); @@ -467,7 +463,6 @@ static void renderLFO(uint8_t* params, int param) { for (int i = 0; i < 2; i++) { int val = params[139 + i]; - intToString(val, buffer, 2); int xpre = 10 + (i * 9) * kTextSpacingX; int xpos = xpre + 6 * kTextSpacingX; const char* text = (i == 0) ? "pitch" : " amp"; @@ -481,15 +476,11 @@ static void renderLFO(uint8_t* params, int param) { show(shapes_long[shap], 0, 12, (142 == param)); int val = params[143]; - intToString(val, buffer, 1); - show(buffer, 1, 10, (143 == param)); + show(string::fromInt(val), 1, 10, (143 == param)); } static void renderAlgorithm(uint8_t* params) { - - char buffer[12]; - intToString(params[134] + 1, buffer, 2); - OLED::main.drawString(buffer, 116, 7, kTextSpacingX, kTextSizeYUpdated); + OLED::main.drawString(string::fromInt(params[134] + 1, 2), 116, 7, kTextSpacingX, kTextSizeYUpdated); FmAlgorithm a = FmCore::algorithms[params[134]]; for (int i = 0; i < 6; i++) { @@ -515,12 +506,10 @@ static void renderAlgorithm(uint8_t* params) { void DxParam::drawPixelsForOled() { const int y0 = 20; - char buffer[12]; if (param < 0 || param == 135 || param == 136) { int val = getValue(); - intToString(val, buffer, param < 0 ? 2 : 1); - OLED::main.drawString(buffer, 50, y0, kTextHugeSpacingX, kTextHugeSizeY); + OLED::main.drawString(string::fromInt(val, param < 0 ? 2 : 1), 50, y0, kTextHugeSpacingX, kTextHugeSizeY); return; } diff --git a/src/deluge/gui/menu_item/integer.cpp b/src/deluge/gui/menu_item/integer.cpp index 36a494d159..1a7f31fec6 100644 --- a/src/deluge/gui/menu_item/integer.cpp +++ b/src/deluge/gui/menu_item/integer.cpp @@ -19,6 +19,8 @@ #include "hid/display/display.h" #include "hid/display/oled.h" #include "util/cfunctions.h" +#include "util/d_string.h" +#include "util/string.h" namespace deluge::gui::menu_item { @@ -62,9 +64,9 @@ void IntegerWithOff::drawPixelsForOled() { } void Integer::drawInteger(int32_t textWidth, int32_t textHeight, int32_t yPixel) { - char buffer[12]; - intToString(getDisplayValue(), buffer, 1); - strncat(buffer, getUnit(), 4); + std::string buffer; + buffer += string::fromInt(getDisplayValue()); + buffer.append(getUnit(), 4); deluge::hid::display::OLED::main.drawStringCentred(buffer, yPixel + OLED_MAIN_TOPMOST_PIXEL, textWidth, textHeight); } diff --git a/src/deluge/gui/menu_item/integer_range.cpp b/src/deluge/gui/menu_item/integer_range.cpp index 5b89070980..187fd16364 100644 --- a/src/deluge/gui/menu_item/integer_range.cpp +++ b/src/deluge/gui/menu_item/integer_range.cpp @@ -20,6 +20,8 @@ #include "gui/ui/sound_editor.h" #include "hid/display/display.h" #include "util/functions.h" +#include "util/string.h" +#include namespace deluge::gui::menu_item { @@ -69,31 +71,30 @@ void IntegerRange::selectEncoderAction(int32_t offset) { } } -void IntegerRange::getText(char* buffer, int32_t* getLeftLength, int32_t* getRightLength, bool mayShowJustOne) { +std::string IntegerRange::getText(size_t* getLeftLength, size_t* getRightLength, bool mayShowJustOne) { - intToString(lower, buffer); + std::string left = deluge::string::fromInt(lower); - int32_t leftLength = strlen(buffer); - if (getLeftLength) { - *getLeftLength = leftLength; + if (getLeftLength != nullptr) { + *getLeftLength = left.length(); } if (mayShowJustOne && lower == upper) { - if (getRightLength) { + if (getRightLength != nullptr) { *getRightLength = 0; } - return; + return left; } - char* bufferPos = buffer + leftLength; + std::string right = deluge::string::fromInt(upper); - *(bufferPos++) = '-'; - - intToString(upper, bufferPos); - - if (getRightLength) { - *getRightLength = strlen(bufferPos); + if (getRightLength != nullptr) { + *getRightLength = right.length(); } + + left += '-'; + left += right; + return left; } // Call seedRandom() before you call this diff --git a/src/deluge/gui/menu_item/integer_range.h b/src/deluge/gui/menu_item/integer_range.h index 82feeb0721..77eb060a33 100644 --- a/src/deluge/gui/menu_item/integer_range.h +++ b/src/deluge/gui/menu_item/integer_range.h @@ -26,7 +26,7 @@ class IntegerRange final : public Range { IntegerRange(l10n::String newName, l10n::String title, int32_t newMin, int32_t newMax) : Range(newName, title), minValue(newMin), maxValue(newMax) {} void beginSession(MenuItem* navigatedBackwardFrom) override; - void getText(char* buffer, int32_t* getLeftLength, int32_t* getRightLength, bool mayShowJustOne) override; + std::string getText(size_t* getLeftLength, size_t* getRightLength, bool mayShowJustOne) override; void selectEncoderAction(int32_t offset) override; int32_t getRandomValueInRange(); diff --git a/src/deluge/gui/menu_item/key_range.cpp b/src/deluge/gui/menu_item/key_range.cpp index 0a89bc8c29..d339e11ae2 100644 --- a/src/deluge/gui/menu_item/key_range.cpp +++ b/src/deluge/gui/menu_item/key_range.cpp @@ -55,46 +55,40 @@ void KeyRange::selectEncoderAction(int32_t offset) { } } -void KeyRange::getText(char* buffer, int32_t* getLeftLength, int32_t* getRightLength, bool mayShowJustOne) { - - *(buffer++) = noteCodeToNoteLetter[lower]; - int32_t leftLength = 1; +std::string KeyRange::getText(size_t* getLeftLength, size_t* getRightLength, bool mayShowJustOne) { + std::string left; + left += noteCodeToNoteLetter[lower]; if (noteCodeIsSharp[lower]) { - *(buffer++) = (display->haveOLED()) ? '#' : '.'; - if (display->haveOLED()) { - leftLength++; - } + left += display->haveOLED() ? '#' : '.'; } - if (getLeftLength) { - *getLeftLength = leftLength; + if (getLeftLength != nullptr) { + *getLeftLength = (left.back() == '.') ? 2 : 1; } if (mayShowJustOne && lower == upper) { - *buffer = 0; - if (getRightLength) { + if (getRightLength != nullptr) { *getRightLength = 0; } - return; + return left; } - *(buffer++) = '-'; + std::string right; + right += noteCodeToNoteLetter[upper]; - *(buffer++) = noteCodeToNoteLetter[upper]; - int32_t rightLength = 1; if (noteCodeIsSharp[upper]) { - *(buffer++) = (display->haveOLED()) ? '#' : '.'; - if (display->haveOLED()) { - rightLength++; - } + left += display->haveOLED() ? '#' : '.'; } - *buffer = 0; - - if (getRightLength) { - *getRightLength = rightLength; + if (getRightLength != nullptr) { + *getLeftLength = (left.back() == '.') ? 2 : 1; } + + // concatenate and return + left += '-'; + left += right; + return left; } // Call seedRandom() before you call this diff --git a/src/deluge/gui/menu_item/key_range.h b/src/deluge/gui/menu_item/key_range.h index 698d43794c..d131c0eee4 100644 --- a/src/deluge/gui/menu_item/key_range.h +++ b/src/deluge/gui/menu_item/key_range.h @@ -23,7 +23,7 @@ namespace deluge::gui::menu_item { class KeyRange final : public Range { public: using Range::Range; - void getText(char* buffer, int32_t* getLeftLength, int32_t* getRightLength, bool mayShowJustOne) override; + std::string getText(size_t* getLeftLength, size_t* getRightLength, bool mayShowJustOne) override; void selectEncoderAction(int32_t offset) override; int32_t getRandomValueInRange(); diff --git a/src/deluge/gui/menu_item/midi/command.cpp b/src/deluge/gui/menu_item/midi/command.cpp index e9df51809d..0b168c5ec1 100644 --- a/src/deluge/gui/menu_item/midi/command.cpp +++ b/src/deluge/gui/menu_item/midi/command.cpp @@ -24,6 +24,7 @@ #include "io/midi/midi_engine.h" #include "util/cfunctions.h" #include "util/misc.h" +#include "util/string.h" namespace deluge::gui::menu_item::midi { @@ -61,7 +62,6 @@ void Command::drawPixelsForOled() { } else { channelText = l10n::get(l10n::String::STRING_FOR_CHANNEL); - char buffer[12]; int32_t channelmod = 0; if (command->channelOrZone >= IS_A_PC) { channelmod = IS_A_PC; // the great CC channel hack extended @@ -69,8 +69,9 @@ void Command::drawPixelsForOled() { else if (command->channelOrZone >= IS_A_CC) { channelmod = IS_A_CC; } - intToString(command->channelOrZone + 1 - channelmod, buffer, 1); - image.drawString(buffer, kTextSpacingX * 8, yPixel, kTextSpacingX, kTextSizeYUpdated); + + image.drawString(string::fromInt(command->channelOrZone + 1 - channelmod), kTextSpacingX * 8, yPixel, + kTextSpacingX, kTextSizeYUpdated); } image.drawString(channelText, 0, yPixel, kTextSpacingX, kTextSizeYUpdated); @@ -85,9 +86,8 @@ void Command::drawPixelsForOled() { image.drawString("PC", 0, yPixel, kTextSpacingX, kTextSizeYUpdated); } - char buffer[12]; - intToString(command->noteOrCC, buffer, 1); - image.drawString(buffer, kTextSpacingX * 5, yPixel, kTextSpacingX, kTextSizeYUpdated); + image.drawString(string::fromInt(command->noteOrCC), kTextSpacingX * 5, yPixel, kTextSpacingX, + kTextSizeYUpdated); } } diff --git a/src/deluge/gui/menu_item/multi_range.cpp b/src/deluge/gui/menu_item/multi_range.cpp index 6590303c7c..f42efde99e 100644 --- a/src/deluge/gui/menu_item/multi_range.cpp +++ b/src/deluge/gui/menu_item/multi_range.cpp @@ -29,6 +29,7 @@ #include "storage/multi_range/multisample_range.h" #include "util/container/static_vector.hpp" #include "util/functions.h" +#include "util/string.h" #include namespace deluge::gui::menu_item { @@ -338,40 +339,35 @@ void MultiRange::deletePress() { } } -void MultiRange::getText(char* buffer, int32_t* getLeftLength, int32_t* getRightLength, bool mayShowJustOne) { +std::string MultiRange::getText(size_t* getLeftLength, size_t* getRightLength, bool mayShowJustOne) { + std::string text; // Lower end if (this->getValue() == 0) { - strcpy(buffer, l10n::get(l10n::String::STRING_FOR_BOTTOM)); - if (getLeftLength) { - *getLeftLength = display->haveOLED() ? 6 : 3; + text = l10n::get(l10n::String::STRING_FOR_BOTTOM); + if (getLeftLength != nullptr) { + *getLeftLength = text.length(); } } else { int32_t note = soundEditor.currentSource->ranges.getElement(this->getValue() - 1)->topNote + 1; - noteCodeToString(note, buffer, getLeftLength); + text = string::fromNoteCode(note, getLeftLength); } - char* bufferPos = buffer + strlen(buffer); - if (display->haveOLED()) { - while (bufferPos < &buffer[7]) { - *bufferPos = ' '; - bufferPos++; + while (text.length() < 7) { + text += ' '; } } // Upper end if (this->getValue() == soundEditor.currentSource->ranges.getNumElements() - 1) { - *(bufferPos++) = '-'; + text += '-'; if (display->haveOLED()) { - *(bufferPos++) = ' '; + text += ' '; } - *(bufferPos++) = 't'; - *(bufferPos++) = 'o'; - *(bufferPos++) = 'p'; - *(bufferPos++) = 0; - if (getRightLength) { + text += "top"; + if (getRightLength != nullptr) { *getRightLength = 3; } } @@ -380,13 +376,14 @@ void MultiRange::getText(char* buffer, int32_t* getLeftLength, int32_t* getRight if (mayShowJustOne && this->getValue() > 0 && note == soundEditor.currentSource->ranges.getElement(this->getValue() - 1)->topNote + 1) { - return; + return text; } - *(bufferPos++) = '-'; - *(bufferPos++) = ' '; - noteCodeToString(note, bufferPos, getRightLength); + text += '-'; + text += ' '; + text += string::fromNoteCode(note, getRightLength); } + return text; } MenuItem* MultiRange::selectButtonPress() { @@ -425,8 +422,8 @@ bool MultiRange::mayEditRangeEdge(RangeEdit whichEdge) { } void MultiRange::drawPixelsForOled() { - static_vector itemNames{}; - char nameBuffers[kOLEDMenuNumOptionsVisible][20]; + std::array names; + std::array name_views{}; int32_t actualCurrentRange = this->getValue(); this->setValue(currentScroll); @@ -435,9 +432,8 @@ void MultiRange::drawPixelsForOled() { if (this->getValue() >= soundEditor.currentSource->ranges.getNumElements()) { break; } - getText(nameBuffers[idx], nullptr, nullptr, false); - itemNames.push_back(nameBuffers[idx]); - + names[idx] = getText(nullptr, nullptr, false); + name_views[idx] = names[idx]; this->setValue(this->getValue() + 1); } @@ -447,7 +443,7 @@ void MultiRange::drawPixelsForOled() { if (soundEditor.editingRangeEdge == RangeEdit::OFF) { selectedOption = this->getValue() - currentScroll; } - drawItemsForOled(itemNames, selectedOption); + drawItemsForOled(name_views, selectedOption); if (soundEditor.editingRangeEdge != RangeEdit::OFF) { int32_t highlightStartX = 0; diff --git a/src/deluge/gui/menu_item/multi_range.h b/src/deluge/gui/menu_item/multi_range.h index 2819f295b8..249286377a 100644 --- a/src/deluge/gui/menu_item/multi_range.h +++ b/src/deluge/gui/menu_item/multi_range.h @@ -18,6 +18,7 @@ #pragma once #include "menu_item.h" #include "range.h" +#include namespace deluge::gui::menu_item { @@ -34,9 +35,8 @@ class MultiRange final : public Range { MenuItem* menuItemHeadingTo; protected: - void getText(char* buffer, int32_t* getLeftLength = nullptr, int32_t* getRightLength = nullptr, - - bool mayShowJustOne = true) override; + std::string getText(size_t* getLeftLength = nullptr, size_t* getRightLength = nullptr, + bool mayShowJustOne = true) override; bool mayEditRangeEdge(RangeEdit whichEdge) override; [[nodiscard]] std::string_view getTitle() const override { diff --git a/src/deluge/gui/menu_item/patch_cable_strength.cpp b/src/deluge/gui/menu_item/patch_cable_strength.cpp index b44367d942..b222dd46dc 100644 --- a/src/deluge/gui/menu_item/patch_cable_strength.cpp +++ b/src/deluge/gui/menu_item/patch_cable_strength.cpp @@ -37,6 +37,7 @@ #include "processing/sound/sound.h" #include "source_selection.h" #include "util/functions.h" +#include "util/string.h" using deluge::hid::display::OLED; @@ -109,12 +110,11 @@ void PatchCableStrength::renderOLED() { preferBarDrawing = false; } - char buffer[12]; if (preferBarDrawing) { int32_t rounded = this->getValue() / 100; - intToString(rounded, buffer, 1); - OLED::main.drawStringAlignRight( - buffer, extraY + OLED_MAIN_TOPMOST_PIXEL + 4 + destinationDescriptor.isJustAParam(), 18, 20); + OLED::main.drawStringAlignRight(string::fromInt(rounded), + extraY + OLED_MAIN_TOPMOST_PIXEL + 4 + destinationDescriptor.isJustAParam(), 18, + 20); int32_t marginL = destinationDescriptor.isJustAParam() ? 0 : 80; int32_t yBar = destinationDescriptor.isJustAParam() ? 36 : 37; @@ -123,9 +123,9 @@ void PatchCableStrength::renderOLED() { else { const int32_t digitWidth = kTextBigSpacingX; const int32_t digitHeight = kTextBigSizeY; - intToString(this->getValue(), buffer, 3); int32_t textPixelY = extraY + OLED_MAIN_TOPMOST_PIXEL + 10 + destinationDescriptor.isJustAParam(); - OLED::main.drawStringAlignRight(buffer, textPixelY, digitWidth, digitHeight); + + OLED::main.drawStringAlignRight(string::fromInt(this->getValue(), 3), textPixelY, digitWidth, digitHeight); int32_t ourDigitStartX = OLED_MAIN_WIDTH_PIXELS - (soundEditor.numberEditPos + 1) * digitWidth; OLED::setupBlink(ourDigitStartX, digitWidth, 40, 44, movingCursor); diff --git a/src/deluge/gui/menu_item/patch_cables.cpp b/src/deluge/gui/menu_item/patch_cables.cpp index 2ebf521e1d..1eece0522b 100644 --- a/src/deluge/gui/menu_item/patch_cables.cpp +++ b/src/deluge/gui/menu_item/patch_cables.cpp @@ -10,6 +10,8 @@ #include "source_selection/range.h" #include "source_selection/regular.h" #include "util/functions.h" +#include "util/string.h" +#include "util/try.h" namespace deluge::gui::menu_item { @@ -83,8 +85,10 @@ void PatchCables::renderOptions() { float floatLevel = (float)level / 100; int floatoff = floatLevel < 0 ? 1 : 0; - floatToString(floatLevel, buf + off + 5 - floatoff, 2, 2); - // fmt::vformat_to_n(buf + off + 5, 5, "{:4}", fmt::make_format_args(); + D_TRY_CATCH(deluge::to_chars(&buf[off + 5 - floatoff], &buf[off + 9], floatLevel, 2), error, + { + // ignore, shouldn't ever happen + }); buf[off + 9] = ' '; strncpy(buf + off + 10, dest_name, item_max_len - 10 - off); diff --git a/src/deluge/gui/menu_item/range.cpp b/src/deluge/gui/menu_item/range.cpp index 84161960f8..06731f71f4 100644 --- a/src/deluge/gui/menu_item/range.cpp +++ b/src/deluge/gui/menu_item/range.cpp @@ -24,6 +24,7 @@ #include "hid/display/oled.h" #include "hid/led/indicator_leds.h" #include "util/functions.h" +#include namespace deluge::gui::menu_item { @@ -116,14 +117,13 @@ void Range::drawValue(int32_t startPos, bool renderSidebarToo) { renderUIsForOled(); } else { - char* buffer = shortStringBuffer; - getText(buffer); + std::string text = this->getText(); - if (strlen(buffer) <= kNumericDisplayLength) { - display->setText(buffer, true); + if (text.length() <= kNumericDisplayLength) { + display->setText(text, true); } else { - display->setScrollingText(buffer, startPos); + display->setScrollingText(text, startPos); } } } @@ -134,29 +134,33 @@ void Range::drawValueForEditingRange(bool blinkImmediately) { return; } - int32_t leftLength, rightLength; - char* buffer = shortStringBuffer; + size_t leftLength = 0; + size_t rightLength = 0; - getText(buffer, &leftLength, &rightLength, false); + std::string text = this->getText(&leftLength, &rightLength, false); - int32_t textLength = leftLength + rightLength + 1; + size_t textLength = leftLength + rightLength + 1; uint8_t blinkMask[kNumericDisplayLength]; if (soundEditor.editingRangeEdge == RangeEdit::LEFT) { for (int32_t i = 0; i < kNumericDisplayLength; i++) { - if (i < leftLength + kNumericDisplayLength - std::min(4_i32, textLength)) + if (i < leftLength + kNumericDisplayLength - std::min(4, textLength)) { blinkMask[i] = 0; - else + } + else { blinkMask[i] = 255; + } } } else { for (int32_t i = 0; i < kNumericDisplayLength; i++) { - if (kNumericDisplayLength - 1 - i < rightLength) + if (kNumericDisplayLength - 1 - i < rightLength) { blinkMask[i] = 0; - else + } + else { blinkMask[i] = 255; + } } } @@ -165,17 +169,17 @@ void Range::drawValueForEditingRange(bool blinkImmediately) { // Sorta hackish, to reset timing of blinking LED and always show text "on" initially on edit value indicator_leds::blinkLed(IndicatorLED::BACK, 255, 0, !blinkImmediately); - display->setText(buffer, alignRight, 255, true, blinkMask); + display->setText(text, alignRight, 255, true, blinkMask); soundEditor.possibleChangeToCurrentRangeDisplay(); } void Range::drawPixelsForOled() { deluge::hid::display::oled_canvas::Canvas& canvas = deluge::hid::display::OLED::main; - int32_t leftLength, rightLength; - char* buffer = shortStringBuffer; + size_t leftLength = 0; + size_t rightLength = 0; - getText(buffer, &leftLength, &rightLength, soundEditor.editingRangeEdge == RangeEdit::OFF); + std::string text = this->getText(&leftLength, &rightLength, soundEditor.editingRangeEdge == RangeEdit::OFF); int32_t textLength = leftLength + rightLength + (bool)rightLength; @@ -186,7 +190,7 @@ void Range::drawPixelsForOled() { int32_t stringWidth = digitWidth * textLength; int32_t stringStartX = (OLED_MAIN_WIDTH_PIXELS - stringWidth) >> 1; - canvas.drawString(buffer, stringStartX, baseY + OLED_MAIN_TOPMOST_PIXEL, digitWidth, digitHeight); + canvas.drawString(text, stringStartX, baseY + OLED_MAIN_TOPMOST_PIXEL, digitWidth, digitHeight); int32_t highlightStartX, highlightWidth; diff --git a/src/deluge/gui/menu_item/range.h b/src/deluge/gui/menu_item/range.h index ed4e6cc263..91bbd221be 100644 --- a/src/deluge/gui/menu_item/range.h +++ b/src/deluge/gui/menu_item/range.h @@ -36,8 +36,8 @@ class Range : public Value { bool cancelEditingIfItsOn(); protected: - virtual void getText(char* buffer, int32_t* getLeftLength = nullptr, int32_t* getRightLength = nullptr, - bool mayShowJustOne = true) = 0; + virtual std::string getText(size_t* getLeftLength = nullptr, size_t* getRightLength = nullptr, + bool mayShowJustOne = true) = 0; virtual bool mayEditRangeEdge(RangeEdit whichEdge) { return true; } virtual void drawValue() { this->drawValue(0); } void drawValue(int32_t startPos, bool renderSidebarToo = true); diff --git a/src/deluge/gui/menu_item/sync_level.cpp b/src/deluge/gui/menu_item/sync_level.cpp index d519bd78cc..a82e5f3b6a 100644 --- a/src/deluge/gui/menu_item/sync_level.cpp +++ b/src/deluge/gui/menu_item/sync_level.cpp @@ -28,24 +28,21 @@ void SyncLevel::drawValue() { display->setText(l10n::get(l10n::String::STRING_FOR_DISABLED)); } else { - StringBuf buffer{shortStringBuffer, kShortStringBufferSize}; - getNoteLengthName(buffer); - display->setScrollingText(buffer.data(), 0); + std::string name = getNoteLengthName(); + display->setScrollingText(name, 0); } } -void SyncLevel::getNoteLengthName(StringBuf& buffer) { - syncValueToString(this->getValue(), buffer, currentSong->getInputTickMagnitude()); +std::string SyncLevel::getNoteLengthName() { + return syncValueToString(this->getValue(), currentSong->getInputTickMagnitude()); } void SyncLevel::drawPixelsForOled() { - char const* text = l10n::get(l10n::String::STRING_FOR_OFF); - DEF_STACK_STRING_BUF(buffer, 30); + std::string name{l10n::getView(l10n::String::STRING_FOR_OFF)}; if (this->getValue() != 0) { - text = buffer.data(); - getNoteLengthName(buffer); + name = getNoteLengthName(); } - deluge::hid::display::OLED::main.drawStringCentred(text, 20 + OLED_MAIN_TOPMOST_PIXEL, kTextBigSpacingX, + deluge::hid::display::OLED::main.drawStringCentred(name, 20 + OLED_MAIN_TOPMOST_PIXEL, kTextBigSpacingX, kTextBigSizeY); } diff --git a/src/deluge/gui/menu_item/sync_level.h b/src/deluge/gui/menu_item/sync_level.h index 8e78be009c..3a8034cb3a 100644 --- a/src/deluge/gui/menu_item/sync_level.h +++ b/src/deluge/gui/menu_item/sync_level.h @@ -32,7 +32,7 @@ class SyncLevel : public Enumeration { protected: void drawValue() final; - virtual void getNoteLengthName(StringBuf& buffer); + virtual std::string getNoteLengthName(); void drawPixelsForOled() override; }; diff --git a/src/deluge/gui/menu_item/sync_level/relative_to_song.h b/src/deluge/gui/menu_item/sync_level/relative_to_song.h index 81e0e6ea7c..97c705f8f6 100644 --- a/src/deluge/gui/menu_item/sync_level/relative_to_song.h +++ b/src/deluge/gui/menu_item/sync_level/relative_to_song.h @@ -28,8 +28,6 @@ class RelativeToSong : public SyncLevel { using SyncLevel::SyncLevel; protected: - void getNoteLengthName(StringBuf& buffer) final { - getNoteLengthNameFromMagnitude(buffer, -6 + 9 - this->getValue()); - } + std::string getNoteLengthName() final { return getNoteLengthNameFromMagnitude(-6 + 9 - this->getValue()); } }; } // namespace deluge::gui::menu_item::sync_level diff --git a/src/deluge/gui/ui/keyboard/layout/chord_keyboard.cpp b/src/deluge/gui/ui/keyboard/layout/chord_keyboard.cpp index a526f9ad27..7b00c8ce39 100644 --- a/src/deluge/gui/ui/keyboard/layout/chord_keyboard.cpp +++ b/src/deluge/gui/ui/keyboard/layout/chord_keyboard.cpp @@ -18,6 +18,7 @@ #include "gui/ui/keyboard/layout/chord_keyboard.h" #include "gui/colour/colour.h" +#include "gui/l10n/strings.h" #include "gui/ui/audio_recorder.h" #include "gui/ui/browser/sample_browser.h" #include "gui/ui/keyboard/chords.h" @@ -247,13 +248,11 @@ void KeyboardLayoutChord::handleControlButton(int32_t x, int32_t y) { // } if (x == kDisplayWidth - 1 && y == kDisplayHeight - 1) { mode = ChordKeyboardMode::ROW; - char const* shortLong[2] = {"ROW", "Chord Row Mode"}; - display->displayPopup(shortLong); + display->displayPopup(l10n::get(l10n::String::STRING_FOR_CHORD_ROW_MODE)); } else if (x == kDisplayWidth - 1 && y == kDisplayHeight - 2) { mode = ChordKeyboardMode::COLUMN; - char const* shortLong[2] = {"COLM", "Chord Column Mode"}; - display->displayPopup(shortLong); + display->displayPopup(l10n::get(l10n::String::STRING_FOR_CHORD_COLUMN_MODE)); } } diff --git a/src/deluge/gui/ui/keyboard/layout/column_controls.cpp b/src/deluge/gui/ui/keyboard/layout/column_controls.cpp index ad85d95211..ca5ade346a 100644 --- a/src/deluge/gui/ui/keyboard/layout/column_controls.cpp +++ b/src/deluge/gui/ui/keyboard/layout/column_controls.cpp @@ -37,16 +37,16 @@ using namespace deluge::gui::ui::keyboard::controls; namespace deluge::gui::ui::keyboard::layout { -const char* functionNames[][2] = { - /* VELOCITY */ {"VEL", "Velocity"}, - /* MOD */ {"MOD", "Modwheel"}, - /* CHORD */ {"CHRD", "Chords"}, - /* SONG_CHORD_MEM */ {"CMEM", "Song Chord Memory"}, - /* CHORD_MEM */ {"CCME", "Clip Chord Memory"}, - /* SCALE_MODE */ {"SMOD", "Scales"}, - /* DX */ {"DX", "DX operators"}, - /* SESSION */ {"SONG", "song macros"}, - /* BEAT_REPEAT */ {"BEAT", "Beat Repeat"}, +l10n::String functionNames[] = { + /* VELOCITY */ l10n::String::STRING_FOR_VELOCITY, + /* MOD */ l10n::String::STRING_FOR_MODWHEEL, + /* CHORD */ l10n::String::STRING_FOR_CHORD, + /* SONG_CHORD_MEM */ l10n::String::STRING_FOR_SONG_CHORD_MEMORY, + /* CHORD_MEM */ l10n::String::STRING_FOR_CLIP_CHORD_MEMORY, + /* SCALE_MODE */ l10n::String::STRING_FOR_SCALE, + /* DX */ l10n::String::STRING_FOR_DX_OPERATORS, + /* SESSION */ l10n::String::STRING_FOR_SONG_MACROS, + /* BEAT_REPEAT */ l10n::String::STRING_FOR_BEAT_REPEAT, }; void ColumnControlsKeyboard::enableNote(uint8_t note, uint8_t velocity) { @@ -323,7 +323,7 @@ bool ColumnControlsKeyboard::horizontalEncoderHandledByColumns(int32_t offset, b state.leftCol->handleLeavingColumn(modelStackWithTimelineCounter, this); state.leftColFunc = (offset > 0) ? nextControlFunction(state.leftColFunc, state.rightColFunc) : prevControlFunction(state.leftColFunc, state.rightColFunc); - display->displayPopup(functionNames[state.leftColFunc]); + display->displayPopup(l10n::getView(functionNames[state.leftColFunc])); state.leftCol = state.getColumnForFunc(state.leftColFunc); keyboardScreen.killColumnSwitchKey(LEFT_COL); return true; @@ -332,7 +332,7 @@ bool ColumnControlsKeyboard::horizontalEncoderHandledByColumns(int32_t offset, b state.rightCol->handleLeavingColumn(modelStackWithTimelineCounter, this); state.rightColFunc = (offset > 0) ? nextControlFunction(state.rightColFunc, state.leftColFunc) : prevControlFunction(state.rightColFunc, state.leftColFunc); - display->displayPopup(functionNames[state.rightColFunc]); + display->displayPopup(l10n::getView(functionNames[state.rightColFunc])); state.rightCol = state.getColumnForFunc(state.rightColFunc); state.rightColSetAtRuntime = true; keyboardScreen.killColumnSwitchKey(RIGHT_COL); diff --git a/src/deluge/gui/views/session_view.cpp b/src/deluge/gui/views/session_view.cpp index 375feb4219..bf87e0a71e 100644 --- a/src/deluge/gui/views/session_view.cpp +++ b/src/deluge/gui/views/session_view.cpp @@ -83,6 +83,8 @@ #include #include #include +#include +#include extern "C" { #include "RZA1/uart/sio_char.h" @@ -2026,9 +2028,8 @@ void SessionView::renderViewDisplay() { int32_t yPos = OLED_MAIN_TOPMOST_PIXEL + 3; #endif - DEF_STACK_STRING_BUF(tempoBPM, 10); lastDisplayedTempo = playbackHandler.calculateBPM(playbackHandler.getTimePerInternalTickFloat()); - playbackHandler.getTempoStringForOLED(lastDisplayedTempo, tempoBPM); + std::string tempoBPM = playbackHandler.getTempoStringForOLED(lastDisplayedTempo); displayTempoBPM(canvas, tempoBPM, false); #if OLED_MAIN_HEIGHT_PIXELS == 64 @@ -2065,7 +2066,7 @@ void SessionView::renderViewDisplay() { deluge::hid::display::OLED::markChanged(); } -void SessionView::displayTempoBPM(deluge::hid::display::oled_canvas::Canvas& canvas, StringBuf& tempoBPM, +void SessionView::displayTempoBPM(deluge::hid::display::oled_canvas::Canvas& canvas, std::string_view tempoBPM, bool clearArea) { int32_t yPos = OLED_MAIN_TOPMOST_PIXEL + 3; @@ -2076,15 +2077,14 @@ void SessionView::displayTempoBPM(deluge::hid::display::oled_canvas::Canvas& can OLED_MAIN_TOPMOST_PIXEL, OLED_MAIN_WIDTH_PIXELS - 1, yPos + kTextSpacingY); } - canvas.drawStringAlignRight(tempoBPM.c_str(), yPos, kTextSpacingX, kTextSpacingY); + canvas.drawStringAlignRight(tempoBPM, yPos, kTextSpacingX, kTextSpacingY); - int32_t stringLength = tempoBPM.size(); - int32_t metronomeIconStartX = OLED_MAIN_WIDTH_PIXELS - (kTextSpacingX * stringLength) - metronomeIconSpacingX; + int32_t metronomeIconStartX = OLED_MAIN_WIDTH_PIXELS - (kTextSpacingX * tempoBPM.length()) - metronomeIconSpacingX; canvas.drawGraphicMultiLine(deluge::hid::display::OLED::metronomeIcon, metronomeIconStartX, yPos, 7); } void SessionView::displayCurrentRootNoteAndScaleName(deluge::hid::display::oled_canvas::Canvas& canvas, - StringBuf& rootNoteAndScaleName, bool clearArea) { + std::string_view rootNoteAndScaleName, bool clearArea) { int32_t yPos = OLED_MAIN_TOPMOST_PIXEL + 32; @@ -2092,7 +2092,7 @@ void SessionView::displayCurrentRootNoteAndScaleName(deluge::hid::display::oled_ canvas.clearAreaExact(0, yPos, OLED_MAIN_WIDTH_PIXELS - 1, yPos + kTextSpacingY); } - canvas.drawString(rootNoteAndScaleName.c_str(), 0, yPos, kTextSpacingX, kTextSpacingY); + canvas.drawString(rootNoteAndScaleName, 0, yPos, kTextSpacingX, kTextSpacingY); } // This gets called by redrawNumericDisplay() - or, if OLED, it gets called instead, because this still needs to @@ -2349,8 +2349,7 @@ void SessionView::displayPotentialTempoChange(UI* ui) { float diff = std::abs(tempo - lastDisplayedTempo); // always catch manual adjustments, limit rate of others if (diff > 0.5) { - DEF_STACK_STRING_BUF(tempoBPM, 10); - playbackHandler.getTempoStringForOLED(tempo, tempoBPM); + std::string tempoBPM = playbackHandler.getTempoStringForOLED(tempo); displayTempoBPM(deluge::hid::display::OLED::main, tempoBPM, true); deluge::hid::display::OLED::markChanged(); lastDisplayedTempo = tempo; diff --git a/src/deluge/gui/views/session_view.h b/src/deluge/gui/views/session_view.h index 53b44282a9..d6ad051c98 100644 --- a/src/deluge/gui/views/session_view.h +++ b/src/deluge/gui/views/session_view.h @@ -144,12 +144,12 @@ class SessionView final : public ClipNavigationTimelineView { // display tempo void displayPotentialTempoChange(UI* ui); - void displayTempoBPM(deluge::hid::display::oled_canvas::Canvas& canvas, StringBuf& tempoBPM, bool clearArea); + void displayTempoBPM(deluge::hid::display::oled_canvas::Canvas& canvas, std::string_view tempoBPM, bool clearArea); float lastDisplayedTempo = 0; // display root note and scale name void displayCurrentRootNoteAndScaleName(deluge::hid::display::oled_canvas::Canvas& canvas, - StringBuf& rootNoteAndScaleName, bool clearArea); + std::string_view rootNoteAndScaleName, bool clearArea); int16_t lastDisplayedRootNote = 0; // convert instrument clip to audio clip diff --git a/src/deluge/gui/views/timeline_view.cpp b/src/deluge/gui/views/timeline_view.cpp index 7cab2decbc..e8593522d9 100644 --- a/src/deluge/gui/views/timeline_view.cpp +++ b/src/deluge/gui/views/timeline_view.cpp @@ -118,10 +118,9 @@ ActionResult TimelineView::buttonAction(deluge::hid::Button b, bool on, bool inC } void TimelineView::displayZoomLevel(bool justPopup) { - DEF_STACK_STRING_BUF(text, 30); - currentSong->getNoteLengthName(text, currentSong->xZoom[getNavSysId()], "-notes", true); + std::string name = currentSong->getNoteLengthName(currentSong->xZoom[getNavSysId()], "-notes", true); - display->displayPopup(text.data(), justPopup ? 3 : 0, true); + display->displayPopup(name, justPopup ? 3 : 0, true); } bool horizontalEncoderActionLock = false; diff --git a/src/deluge/gui/views/view.cpp b/src/deluge/gui/views/view.cpp index aababdcc62..f4b4b73217 100644 --- a/src/deluge/gui/views/view.cpp +++ b/src/deluge/gui/views/view.cpp @@ -85,6 +85,7 @@ #include "storage/file_item.h" #include "storage/flash_storage.h" #include "storage/storage_manager.h" +#include "util/string.h" namespace params = deluge::modulation::params; namespace encoders = deluge::hid::encoders; @@ -2018,8 +2019,7 @@ void View::drawOutputNameFromDetails(OutputType outputType, int32_t channel, int canvas.drawStringCentred(outputTypeText, yPos, kTextSpacingX, kTextSpacingY); } - char buffer[12]; - char const* nameToDraw = nullptr; + std::string nameToDraw; if (!isNameEmpty) { if (display->haveOLED()) { @@ -2106,8 +2106,8 @@ void View::drawOutputNameFromDetails(OutputType outputType, int32_t channel, int else if (outputType == OutputType::MIDI_OUT) { if (display->haveOLED()) { if (channel < 16) { - slotToString(channel + 1, channelSuffix, buffer, 1); - goto oledOutputBuffer; + nameToDraw = string::fromSlot(channel + 1, channelSuffix, 1); + goto oledDrawString; } else if (channel == MIDI_CHANNEL_MPE_LOWER_ZONE || channel == MIDI_CHANNEL_MPE_UPPER_ZONE) { nameToDraw = (channel == MIDI_CHANNEL_MPE_LOWER_ZONE) ? "Lower" : "Upper"; @@ -2134,13 +2134,11 @@ void View::drawOutputNameFromDetails(OutputType outputType, int32_t channel, int else if (outputType == OutputType::CV) { if (display->haveOLED()) { if (channel < both) { - intToString(channel + 1, buffer); + nameToDraw = string::fromInt(channel + 1); } else { - sprintf(buffer, "1 and 2"); + nameToDraw = "1 and 2"; } -oledOutputBuffer: - nameToDraw = buffer; goto oledDrawString; } else { @@ -2403,17 +2401,17 @@ void View::navigateThroughPresetsForInstrumentClip(int32_t offset, ModelStackWit // Special case: when it is a saved MIDI preset (with a name), then we need to show the channel in a popup, as // the name will print over the midi channel and we can't see it while changing it if (outputType == OutputType::MIDI_OUT && newInstrument->name.getLength() > 0) { - char buffer[12]; + std::string text; if (newChannel < 16) { - slotToString(newChannel + 1, newChannelSuffix, buffer, 1); + text = string::fromSlot(newChannel + 1, newChannelSuffix); } else if (newChannel == MIDI_CHANNEL_MPE_LOWER_ZONE || newChannel == MIDI_CHANNEL_MPE_UPPER_ZONE) { - strcpy(buffer, (newChannel == MIDI_CHANNEL_MPE_LOWER_ZONE) ? "Lower" : "Upper"); + text = (newChannel == MIDI_CHANNEL_MPE_LOWER_ZONE) ? "Lower" : "Upper"; } else { - strcpy(buffer, "Transpose"); + text = "Transpose"; } - display->popupTextTemporary(buffer); + display->popupTextTemporary(text); } } diff --git a/src/deluge/hid/display/display.h b/src/deluge/hid/display/display.h index 542041a08b..5564b6e807 100644 --- a/src/deluge/hid/display/display.h +++ b/src/deluge/hid/display/display.h @@ -48,7 +48,7 @@ class Display { int32_t scrollPos = 0, uint8_t* blinkAddition = nullptr, bool justReplaceBottomLayer = false){}; - virtual void displayPopup(char const* newText, int8_t numFlashes = 3, bool alignRight = false, + virtual void displayPopup(std::string_view newText, int8_t numFlashes = 3, bool alignRight = false, uint8_t drawDot = 255, int32_t blinkSpeed = 1, PopupType type = PopupType::GENERAL) = 0; virtual void displayPopup(uint8_t val, int8_t numFlashes = 3, bool alignRight = false, uint8_t drawDot = 255, @@ -58,18 +58,18 @@ class Display { displayPopup(valStr, numFlashes, alignRight, drawDot, blinkSpeed, type); } - virtual void displayPopup(char const* shortLong[2], int8_t numFlashes = 3, bool alignRight = false, + virtual void displayPopup(std::string_view shortLong[2], int8_t numFlashes = 3, bool alignRight = false, uint8_t drawDot = 255, int32_t blinkSpeed = 1, PopupType type = PopupType::GENERAL) { displayPopup(have7SEG() ? shortLong[0] : shortLong[1], numFlashes, alignRight, drawDot, blinkSpeed, type); } - virtual void popupText(char const* text, PopupType type = PopupType::GENERAL) = 0; - virtual void popupTextTemporary(char const* text, PopupType type = PopupType::GENERAL) = 0; + virtual void popupText(std::string_view text, PopupType type = PopupType::GENERAL) = 0; + virtual void popupTextTemporary(std::string_view text, PopupType type = PopupType::GENERAL) = 0; virtual void setNextTransitionDirection(int8_t thisDirection){}; virtual void cancelPopup() = 0; - virtual void freezeWithError(char const* text) = 0; + virtual void freezeWithError(std::string_view text) = 0; virtual bool isLayerCurrentlyOnTop(NumericLayer* layer) = 0; virtual void displayError(Error error) = 0; @@ -77,21 +77,21 @@ class Display { // Loading animations virtual void displayLoadingAnimation(){}; - virtual void displayLoadingAnimationText(char const* text, bool delayed = false, bool transparent = false) = 0; + virtual void displayLoadingAnimationText(std::string_view text, bool delayed = false, bool transparent = false) = 0; virtual void removeLoadingAnimation() = 0; virtual bool hasPopup() = 0; virtual bool hasPopupOfType(PopupType type) = 0; - virtual void consoleText(char const* text) = 0; + virtual void consoleText(std::string_view text) = 0; virtual void timerRoutine() = 0; virtual void setTextAsNumber(int16_t number, uint8_t drawDot = 255, bool doBlink = false) {} - virtual int32_t getEncodedPosFromLeft(int32_t textPos, char const* text, bool* andAHalf) { return 0; } + virtual int32_t getEncodedPosFromLeft(int32_t textPos, std::string_view text, bool* andAHalf) { return 0; } virtual void setTextAsSlot(int16_t currentSlot, int8_t currentSubSlot, bool currentSlotExists, bool doBlink = false, int32_t blinkPos = -1, bool blinkImmediately = false) {} - virtual NumericLayerScrollingText* setScrollingText(char const* newText, int32_t startAtPos = 0, + virtual NumericLayerScrollingText* setScrollingText(std::string_view newText, int32_t startAtPos = 0, int32_t initialDelay = 600, int count = -1, uint8_t fixedDot = 255) { return nullptr; diff --git a/src/deluge/hid/display/oled.cpp b/src/deluge/hid/display/oled.cpp index 4b8e8c66b6..1cca0c381b 100644 --- a/src/deluge/hid/display/oled.cpp +++ b/src/deluge/hid/display/oled.cpp @@ -31,6 +31,8 @@ #include "storage/flash_storage.h" #include "util/cfunctions.h" #include "util/d_string.h" +#include "util/exceptions.h" +#include #include #include @@ -57,7 +59,7 @@ oled_canvas::Canvas OLED::console; bool OLED::needsSending; int32_t workingAnimationCount; -char const* workingAnimationText; // NULL means animation not active +std::optional workingAnimationText = std::nullopt; // NULL means animation not active int32_t sideScrollerDirection; // 0 means none active @@ -413,7 +415,7 @@ void OLED::removePopup() { oledPopupWidth = 0; popupType = PopupType::NONE; - workingAnimationText = nullptr; + workingAnimationText = std::nullopt; uiTimerManager.unsetTimer(TimerName::DISPLAY); markChanged(); } @@ -595,23 +597,23 @@ char const* findLineSplitPoint(char const* wordStart, int32_t maxWidthPerLine, i return space; } -void addLine(TextLineBreakdown* textLineBreakdown, char const* lineStart, int32_t lineWidth, int32_t lineLength) { +void addLine(TextLineBreakdown& textLineBreakdown, char const* lineStart, int32_t lineWidth, int32_t lineLength) { // save the start position for this line of the string - textLineBreakdown->lines[textLineBreakdown->numLines] = lineStart; + textLineBreakdown.lines[textLineBreakdown.numLines] = lineStart; // save the length in characters for this line of the string - textLineBreakdown->lineLengths[textLineBreakdown->numLines] = lineLength; + textLineBreakdown.lineLengths[textLineBreakdown.numLines] = lineLength; // check if this line is the longest line in characters, if so, save the length - if (lineLength > textLineBreakdown->longestLineLength) { - textLineBreakdown->longestLineLength = lineLength; + if (lineLength > textLineBreakdown.longestLineLength) { + textLineBreakdown.longestLineLength = lineLength; } // save the length in pixels for this line of the string - textLineBreakdown->lineWidths[textLineBreakdown->numLines] = lineWidth; + textLineBreakdown.lineWidths[textLineBreakdown.numLines] = lineWidth; // check if this line is the longest line in pixels, if so, save the width in pixels - if (lineWidth > textLineBreakdown->longestLineWidth) { - textLineBreakdown->longestLineWidth = lineWidth; + if (lineWidth > textLineBreakdown.longestLineWidth) { + textLineBreakdown.longestLineWidth = lineWidth; } // increment number of lines - textLineBreakdown->numLines++; + textLineBreakdown.numLines++; } /// this function takes a string and breaks it into multiple lines @@ -624,12 +626,12 @@ void addLine(TextLineBreakdown* textLineBreakdown, char const* lineStart, int32_ /// a) if the character is part of a word, then that word will be rendered on the next line /// b) if the character is a space, then the space gets ignored and the next character will be drawn on /// the next line -void breakStringIntoLines(char const* text, TextLineBreakdown* textLineBreakdown, int32_t textHeight) { - textLineBreakdown->numLines = 0; - textLineBreakdown->longestLineLength = 0; - textLineBreakdown->longestLineWidth = 0; +void breakStringIntoLines(std::string_view text, TextLineBreakdown& textLineBreakdown, int32_t textHeight) { + textLineBreakdown.numLines = 0; + textLineBreakdown.longestLineLength = 0; + textLineBreakdown.longestLineWidth = 0; - char const* lineStart = text; + char const* lineStart = text.begin(); char const* wordStart = lineStart; int32_t lineWidth = 0; // width in pixels of a line @@ -643,11 +645,11 @@ void breakStringIntoLines(char const* text, TextLineBreakdown* textLineBreakdown lineWidthBeforeThisWord = lineWidth; lineLengthBeforeThisWord = lineLength; - char const* space = findLineSplitPoint(wordStart, textLineBreakdown->maxWidthPerLine, textHeight, lineWidth, + char const* space = findLineSplitPoint(wordStart, textLineBreakdown.maxWidthPerLine, textHeight, lineWidth, lineLength, charSpacing); // If line not too long yet - if (lineWidth <= textLineBreakdown->maxWidthPerLine) { + if (lineWidth <= textLineBreakdown.maxWidthPerLine) { // If end of whole line, or whole string... if (*space == '\n' || *space == 0) { // if we reached line break or end of string, we don't need extra spacing after it @@ -655,7 +657,7 @@ void breakStringIntoLines(char const* text, TextLineBreakdown* textLineBreakdown addLine(textLineBreakdown, lineStart, lineWidth, lineLength); // did we reach the end of the original string? or the max number of lines? // then return, we're done - if (!*space || textLineBreakdown->numLines == TEXT_MAX_NUM_LINES) { + if (!*space || textLineBreakdown.numLines == TEXT_MAX_NUM_LINES) { return; } // set character to start drawing from on the next line @@ -678,7 +680,7 @@ void breakStringIntoLines(char const* text, TextLineBreakdown* textLineBreakdown addLine(textLineBreakdown, lineStart, lineWidthBeforeThisWord, lineLengthBeforeThisWord); // did we reach the the max number of lines? // then return, we're done - if (textLineBreakdown->numLines == TEXT_MAX_NUM_LINES) { + if (textLineBreakdown.numLines == TEXT_MAX_NUM_LINES) { return; } // if current character is a space, we won't draw it on the next line @@ -700,14 +702,14 @@ void breakStringIntoLines(char const* text, TextLineBreakdown* textLineBreakdown } } -void OLED::drawPermanentPopupLookingText(char const* text) { +void OLED::drawPermanentPopupLookingText(std::string_view text) { TextLineBreakdown textLineBreakdown; textLineBreakdown.maxCharsPerLine = 19; int32_t doubleMargin = 12; textLineBreakdown.maxWidthPerLine = OLED_MAIN_WIDTH_PIXELS - doubleMargin; - breakStringIntoLines(text, &textLineBreakdown, kTextSpacingY); + breakStringIntoLines(text, textLineBreakdown, kTextSpacingY); int32_t textWidth = textLineBreakdown.longestLineWidth; int32_t textHeight = textLineBreakdown.numLines * kTextSpacingY; @@ -735,7 +737,7 @@ void OLED::drawPermanentPopupLookingText(char const* text) { drawnPermanentPopup = true; } -void OLED::popupText(char const* text, bool persistent, PopupType type) { +void OLED::popupText(std::string_view text, bool persistent, PopupType type) { TextLineBreakdown textLineBreakdown; textLineBreakdown.maxCharsPerLine = 19; @@ -743,7 +745,7 @@ void OLED::popupText(char const* text, bool persistent, PopupType type) { int32_t doubleMargin = 12; textLineBreakdown.maxWidthPerLine = OLED_MAIN_WIDTH_PIXELS - doubleMargin; - breakStringIntoLines(text, &textLineBreakdown, kTextSpacingY); + breakStringIntoLines(text, textLineBreakdown, kTextSpacingY); int32_t textWidth = textLineBreakdown.longestLineWidth; int32_t textHeight = textLineBreakdown.numLines * kTextSpacingY; @@ -778,25 +780,19 @@ void OLED::popupText(char const* text, bool persistent, PopupType type) { } void updateWorkingAnimation() { - String textNow; - Error error = textNow.set(workingAnimationText); - if (error != Error::NONE) { + try { + std::string text{*workingAnimationText}; + for (size_t i = 0; i < 3; ++i) { + text += (i <= workingAnimationCount) ? '.' : ' '; + } + OLED::popupText(text, true, PopupType::LOADING); + } catch (deluge::exception e) { return; } - - char buffer[4]; - buffer[3] = 0; - - for (int32_t i = 0; i < 3; i++) { - buffer[i] = (i <= workingAnimationCount) ? '.' : ' '; - } - - error = textNow.concatenate(buffer); - OLED::popupText(textNow.get(), true, PopupType::LOADING); } -void OLED::displayWorkingAnimation(char const* word) { - workingAnimationText = word; +void OLED::displayWorkingAnimation(std::string_view word) { + workingAnimationText = word.data(); workingAnimationCount = 0; updateWorkingAnimation(); } @@ -806,7 +802,7 @@ void OLED::removeWorkingAnimation() { removePopup(); } else if (workingAnimationText) { - workingAnimationText = nullptr; + workingAnimationText = std::nullopt; } } @@ -850,7 +846,7 @@ void OLED::renderEmulated7Seg(const std::array& #define CONSOLE_ANIMATION_FRAME_TIME_SAMPLES (6 * 44) // 6 -void OLED::consoleText(char const* text) { +void OLED::consoleText(std::string_view text) { TextLineBreakdown textLineBreakdown; textLineBreakdown.maxCharsPerLine = 19; @@ -860,7 +856,7 @@ void OLED::consoleText(char const* text) { int32_t charWidth = 6; int32_t charHeight = 7; - breakStringIntoLines(text, &textLineBreakdown, charHeight); + breakStringIntoLines(text, textLineBreakdown, charHeight); int32_t textPixelY = setupConsole(textLineBreakdown.numLines * charHeight + 1) + 1; @@ -1196,7 +1192,7 @@ void OLED::consoleTimerEvent() { markChanged(); } -void OLED::freezeWithError(char const* text) { +void OLED::freezeWithError(std::string_view text) { OLED::clearMainImage(); int32_t yPixel = OLED_MAIN_TOPMOST_PIXEL; main.drawString("Error:", 0, yPixel, kTextSpacingX, kTextSizeYUpdated, 0, OLED_MAIN_WIDTH_PIXELS); diff --git a/src/deluge/hid/display/oled.h b/src/deluge/hid/display/oled.h index 92e1b4f85c..e445747015 100644 --- a/src/deluge/hid/display/oled.h +++ b/src/deluge/hid/display/oled.h @@ -52,12 +52,12 @@ class OLED : public Display { static void setupPopup(int32_t width, int32_t height); static void removePopup(); - static void popupText(char const* text, bool persistent = false, PopupType type = PopupType::GENERAL); + static void popupText(std::string_view text, bool persistent = false, PopupType type = PopupType::GENERAL); static bool isPopupPresent(); static bool isPopupPresentOfType(PopupType type = PopupType::GENERAL); static bool isPermanentPopupPresent(); - static void displayWorkingAnimation(char const* word); + static void displayWorkingAnimation(std::string_view word); static int32_t setupConsole(int32_t height); static void drawConsoleTopLine(); @@ -65,7 +65,7 @@ class OLED : public Display { static void stopScrollingAnimation(); static void setupSideScroller(int32_t index, std::string_view text, int32_t startX, int32_t endX, int32_t startY, int32_t endY, int32_t textSpacingX, int32_t textSizeY, bool doHighlight); - static void drawPermanentPopupLookingText(char const* text); + static void drawPermanentPopupLookingText(std::string_view text); /// Call this after doing any rendering work so the next trip through the UI rendering loop actually sends the image /// via \ref sendMainImage. @@ -107,20 +107,20 @@ class OLED : public Display { void removeWorkingAnimation() override; void timerRoutine() override; - void consoleText(char const* text) override; - void freezeWithError(char const* text) override; + void consoleText(std::string_view text) override; + void freezeWithError(std::string_view text) override; //************************ Display Interface stuff ***************************/ constexpr size_t getNumBrowserAndMenuLines() override { return 3; } - void displayPopup(char const* newText, int8_t numFlashes = 3, bool = false, uint8_t = 255, int32_t = 1, + void displayPopup(std::string_view newText, int8_t numFlashes = 3, bool = false, uint8_t = 255, int32_t = 1, PopupType type = PopupType::GENERAL) override { popupText(newText, !numFlashes, type); } - void popupText(char const* text, PopupType type = PopupType::GENERAL) override { popupText(text, true, type); } - void popupTextTemporary(char const* text, PopupType type = PopupType::GENERAL) override { + void popupText(std::string_view text, PopupType type = PopupType::GENERAL) override { popupText(text, true, type); } + void popupTextTemporary(std::string_view text, PopupType type = PopupType::GENERAL) override { popupText(text, false, type); } @@ -129,7 +129,7 @@ class OLED : public Display { void displayError(Error error) override; // Loading animations - void displayLoadingAnimationText(char const* text, bool delayed = false, bool transparent = false) override { + void displayLoadingAnimationText(std::string_view text, bool delayed = false, bool transparent = false) override { displayWorkingAnimation(text); } void removeLoadingAnimation() override { removeWorkingAnimation(); } diff --git a/src/deluge/hid/display/oled_canvas/canvas.cpp b/src/deluge/hid/display/oled_canvas/canvas.cpp index e20df2427c..053670bfd0 100644 --- a/src/deluge/hid/display/oled_canvas/canvas.cpp +++ b/src/deluge/hid/display/oled_canvas/canvas.cpp @@ -19,6 +19,7 @@ #include "definitions_cxx.hpp" #include "gui/fonts/fonts.h" #include "storage/flash_storage.h" +#include using deluge::hid::display::oled_canvas::Canvas; @@ -186,21 +187,20 @@ void Canvas::drawString(std::string_view string, int32_t pixelX, int32_t pixelY, } } -void Canvas::drawStringCentred(char const* string, int32_t pixelY, int32_t textWidth, int32_t textHeight, +void Canvas::drawStringCentred(std::string_view string, int32_t pixelY, int32_t textWidth, int32_t textHeight, int32_t centrePos) { - std::string_view str{string}; int32_t stringWidth = getStringWidthInPixels(string, textHeight); int32_t pixelX = centrePos - (stringWidth >> 1); - drawString(str, pixelX, pixelY, textWidth, textHeight); + drawString(string, pixelX, pixelY, textWidth, textHeight); } /// Draw a string, reducing its height so the string fits within the specified width /// -/// @param string A null-terminated C string +/// @param string A string_view /// @param pixelY The Y coordinate of the top of the string /// @param textWidth Requested width for each character in the string /// @param textHeight Requested height for each character in the string -void Canvas::drawStringCentredShrinkIfNecessary(char const* string, int32_t pixelY, int32_t textWidth, +void Canvas::drawStringCentredShrinkIfNecessary(std::string_view string, int32_t pixelY, int32_t textWidth, int32_t textHeight) { bool shrink = false; std::string_view str{string}; @@ -232,7 +232,7 @@ void Canvas::drawStringCentredShrinkIfNecessary(char const* string, int32_t pixe drawString(str, pixelX, pixelY, textWidth, textHeight, 0, OLED_MAIN_WIDTH_PIXELS, shrink); } -void Canvas::drawStringAlignRight(char const* string, int32_t pixelY, int32_t textWidth, int32_t textHeight, +void Canvas::drawStringAlignRight(std::string_view string, int32_t pixelY, int32_t textWidth, int32_t textHeight, int32_t rightPos) { std::string_view str{string}; int32_t stringWidth = getStringWidthInPixels(string, textHeight); @@ -384,7 +384,7 @@ int32_t Canvas::getCharSpacingInPixels(uint8_t theChar, int32_t textHeight, bool } } -int32_t Canvas::getStringWidthInPixels(char const* string, int32_t textHeight) { +int32_t Canvas::getStringWidthInPixels(std::string_view string, int32_t textHeight) { std::string_view str{string}; int32_t stringLength = str.length(); int32_t stringWidth = 0; diff --git a/src/deluge/hid/display/oled_canvas/canvas.h b/src/deluge/hid/display/oled_canvas/canvas.h index 7cb73319ef..b4ea53b6a1 100644 --- a/src/deluge/hid/display/oled_canvas/canvas.h +++ b/src/deluge/hid/display/oled_canvas/canvas.h @@ -96,32 +96,33 @@ class Canvas { /// Draw a string, centered at the provided location. /// - /// @param string A null-terminated C string + /// @param string A string_view /// @param pixelY Y coordinate of the top side of the string /// @param textWidth Base width in pixels of each character /// @param textHeight Height in pixels of each character /// @param scrollPos Offset in pixels representing how far the text has scrolled from the left. /// @param endX Maximum X coordinate after which we bail out. N.B. this means the *actual* maximum X coordinate /// rendered is endX + textWidth, as the individual character rendering work can overshoot. - void drawStringCentred(char const* string, int32_t pixelY, int32_t textWidth, int32_t textHeight, + void drawStringCentred(std::string_view string, int32_t pixelY, int32_t textWidth, int32_t textHeight, int32_t centrePos = OLED_MAIN_WIDTH_PIXELS / 2); /// Draw a string, reducing its height so the string fits within the specified width /// - /// @param string A null-terminated C string + /// @param string A string_view /// @param pixelY The Y coordinate of the top of the string /// @param textWidth Requested width for each character in the string /// @param textHeight Requested height for each character in the string - void drawStringCentredShrinkIfNecessary(char const* string, int32_t pixelY, int32_t textWidth, int32_t textHeight); + void drawStringCentredShrinkIfNecessary(std::string_view string, int32_t pixelY, int32_t textWidth, + int32_t textHeight); /// Draw a string, aligned to the right. /// - /// @param string A null-terminated C string + /// @param string A string_view /// @param pixelY The Y coordinate of the top of the string /// @param textWidth The width for each character in the string /// @param textHeight The height for each character in the string /// @param rightPos X coordinate, exclusive, of the rightmost pixel to use for the string - void drawStringAlignRight(char const* string, int32_t pixelY, int32_t textWidth, int32_t textHeight, + void drawStringAlignRight(std::string_view string, int32_t pixelY, int32_t textWidth, int32_t textHeight, int32_t rightPos = OLED_MAIN_WIDTH_PIXELS); /// Draw a single character @@ -148,9 +149,9 @@ class Canvas { /// Returns width of a string in pixels /// - /// @param string A null-terminated C string + /// @param string A string_view /// @param textHeight The height for each character in the string - int32_t getStringWidthInPixels(char const* string, int32_t textHeight); + int32_t getStringWidthInPixels(std::string_view string, int32_t textHeight); /// Draw a "graphic". /// diff --git a/src/deluge/hid/display/seven_segment.cpp b/src/deluge/hid/display/seven_segment.cpp index 2bdac2954a..11c6e9fcb5 100644 --- a/src/deluge/hid/display/seven_segment.cpp +++ b/src/deluge/hid/display/seven_segment.cpp @@ -32,9 +32,11 @@ #include "model/action/action_logger.h" #include "util/cfunctions.h" #include "util/functions.h" +#include "util/string.h" #include #include #include +#include #include extern "C" { @@ -194,7 +196,7 @@ void SevenSegment::setText(std::string_view newText, bool alignRight, uint8_t dr } } -NumericLayerScrollingText* SevenSegment::setScrollingText(char const* newText, int32_t startAtTextPos, +NumericLayerScrollingText* SevenSegment::setScrollingText(std::string_view newText, int32_t startAtTextPos, int32_t initialDelay, int count, uint8_t fixedDot) { // Paul: Render time could be lower putting this into internal void* layerSpace = GeneralMemoryAllocator::get().allocLowSpeed(sizeof(NumericLayerScrollingText)); @@ -279,7 +281,7 @@ void SevenSegment::transitionToNewLayer(NumericLayer* newLayer) { } // Automatically stops at end of string -int32_t SevenSegment::getEncodedPosFromLeft(int32_t textPos, char const* text, bool* andAHalf) { +int32_t SevenSegment::getEncodedPosFromLeft(int32_t textPos, std::string_view text, bool* andAHalf) { int32_t encodedPos = 0; bool lastSegmentHasDot = @@ -287,8 +289,8 @@ int32_t SevenSegment::getEncodedPosFromLeft(int32_t textPos, char const* text, b *andAHalf = false; for (int32_t i = 0; true; i++) { - char thisChar = *text; - if (!thisChar) { + char thisChar = text[i]; + if (thisChar == '\0') { break; // Stop at end of string } bool isDot = (thisChar == '.' || thisChar == '#' || thisChar == ','); @@ -308,7 +310,6 @@ int32_t SevenSegment::getEncodedPosFromLeft(int32_t textPos, char const* text, b break; } - text++; encodedPos++; } @@ -524,12 +525,11 @@ void SevenSegment::setTextAsNumber(int16_t number, uint8_t drawDot, bool doBlink void SevenSegment::setTextAsSlot(int16_t currentSlot, int8_t currentSubSlot, bool currentSlotExists, bool doBlink, int32_t blinkPos, bool blinkImmediately) { - char text[12]; // int32_t minNumDigits = std::max(1, blinkPos + 1); int32_t minNumDigits = (blinkPos == -1) ? -1 : 3; - slotToString(currentSlot, currentSubSlot, text, minNumDigits); + std::string text = string::fromSlot(currentSlot, currentSubSlot, minNumDigits); uint8_t blinkMask[kNumericDisplayLength]; if (blinkPos == -1) { @@ -548,7 +548,7 @@ void SevenSegment::setNextTransitionDirection(int8_t thisDirection) { nextTransitionDirection = thisDirection; } -void SevenSegment::displayPopup(char const* newText, int8_t numFlashes, bool alignRight, uint8_t drawDot, +void SevenSegment::displayPopup(std::string_view newText, int8_t numFlashes, bool alignRight, uint8_t drawDot, int32_t blinkSpeed, PopupType type) { encodeText(newText, popup.segments, alignRight, drawDot); memset(&popup.blinkedSegments, 0, kNumericDisplayLength); @@ -649,7 +649,7 @@ void SevenSegment::displayLoadingAnimation(bool delayed, bool transparent) { setTopLayer(loadingAnimation); } -void SevenSegment::setTextVeryBasicA1(char const* text) { +void SevenSegment::setTextVeryBasicA1(std::string_view text) { std::array segments; encodeText(text, segments.data(), false, 255, true, 0); PIC::update7SEG(segments); @@ -658,7 +658,7 @@ void SevenSegment::setTextVeryBasicA1(char const* text) { // Highest error code used, main branch: E453 // Highest error code used, fix branch: i041 -void SevenSegment::freezeWithError(char const* text) { +void SevenSegment::freezeWithError(std::string_view text) { setTextVeryBasicA1(text); while (1) { diff --git a/src/deluge/hid/display/seven_segment.h b/src/deluge/hid/display/seven_segment.h index f9c0bc8909..08e7741cbe 100644 --- a/src/deluge/hid/display/seven_segment.h +++ b/src/deluge/hid/display/seven_segment.h @@ -23,6 +23,7 @@ #include "hid/display/numeric_layer/numeric_layer_basic_text.h" #include #include +#include class NumericLayerScrollingText; @@ -36,9 +37,9 @@ class SevenSegment : public Display { uint8_t* newBlinkMask = nullptr, bool blinkImmediately = false, bool shouldBlinkFast = false, int32_t scrollPos = 0, uint8_t* blinkAddition = nullptr, bool justReplaceBottomLayer = false) override; void setNextTransitionDirection(int8_t thisDirection) override; - void displayPopup(char const* newText, int8_t numFlashes = 3, bool alignRight = false, uint8_t drawDot = 255, + void displayPopup(std::string_view newText, int8_t numFlashes = 3, bool alignRight = false, uint8_t drawDot = 255, int32_t blinkSpeed = 1, PopupType type = PopupType::GENERAL) override; - void freezeWithError(char const* text) override; + void freezeWithError(std::string_view text) override; void cancelPopup() override; void displayError(Error error) override; @@ -47,9 +48,10 @@ class SevenSegment : public Display { int32_t blinkPos = -1, bool blinkImmediately = false) override; void timerRoutine() override; void removeTopLayer(); - NumericLayerScrollingText* setScrollingText(char const* newText, int32_t startAtPos = 0, int32_t initialDelay = 600, - int count = -1, uint8_t fixedDot = 255) override; - int32_t getEncodedPosFromLeft(int32_t textPos, char const* text, bool* andAHalf) override; + NumericLayerScrollingText* setScrollingText(std::string_view newText, int32_t startAtPos = 0, + int32_t initialDelay = 600, int count = -1, + uint8_t fixedDot = 255) override; + int32_t getEncodedPosFromLeft(int32_t textPos, std::string_view text, bool* andAHalf) override; void render(); void displayLoadingAnimation(bool delayed = false, bool transparent = false); bool isLayerCurrentlyOnTop(NumericLayer* layer) override; @@ -60,18 +62,18 @@ class SevenSegment : public Display { constexpr size_t getNumBrowserAndMenuLines() override { return 1; } - void consoleText(char const* text) override { SevenSegment::displayPopup(text); } - void popupText(char const* text, PopupType type = PopupType::GENERAL) override { + void consoleText(std::string_view text) override { SevenSegment::displayPopup(text); } + void popupText(std::string_view text, PopupType type = PopupType::GENERAL) override { SevenSegment::displayPopup(text, 0, false, 255, 1, type); } - void popupTextTemporary(char const* text, PopupType type = PopupType::GENERAL) override { + void popupTextTemporary(std::string_view text, PopupType type = PopupType::GENERAL) override { SevenSegment::displayPopup(text, 3, false, 255, 1, type); } void removeWorkingAnimation() override {} // Loading animations - void displayLoadingAnimationText(char const* text, bool delayed = false, bool transparent = false) override { + void displayLoadingAnimationText(std::string_view text, bool delayed = false, bool transparent = false) override { SevenSegment::displayLoadingAnimation(delayed, transparent); } void removeLoadingAnimation() override { SevenSegment::removeTopLayer(); } @@ -93,7 +95,7 @@ class SevenSegment : public Display { void replaceBottomLayer(NumericLayer* newLayer); void setTopLayer(NumericLayer* newTopLayer); void transitionToNewLayer(NumericLayer* newLayer); - void setTextVeryBasicA1(char const* text); + void setTextVeryBasicA1(std::string_view text); std::array lastDisplay_ = {0}; bool use_lowercase = false; }; diff --git a/src/deluge/model/global_effectable/global_effectable.cpp b/src/deluge/model/global_effectable/global_effectable.cpp index 3261f3589c..2d84486d17 100644 --- a/src/deluge/model/global_effectable/global_effectable.cpp +++ b/src/deluge/model/global_effectable/global_effectable.cpp @@ -378,9 +378,8 @@ bool GlobalEffectable::modEncoderButtonAction(uint8_t whichModEncoder, bool on, displayDelaySettings(on); } else { - char displayName[30]; - getDelaySyncLevelDisplayName(displayName); - display->displayPopup(displayName); + std::string name = getDelaySyncLevelDisplayName(); + display->displayPopup(name); } } else { diff --git a/src/deluge/model/mod_controllable/mod_controllable_audio.cpp b/src/deluge/model/mod_controllable/mod_controllable_audio.cpp index b7a4bb7496..663e5aaad6 100644 --- a/src/deluge/model/mod_controllable/mod_controllable_audio.cpp +++ b/src/deluge/model/mod_controllable/mod_controllable_audio.cpp @@ -1197,12 +1197,10 @@ void ModControllableAudio::switchDelaySyncLevel() { delay.syncLevel = (SyncLevel)((delay.syncLevel) % SyncLevel::SYNC_LEVEL_256TH + 1); // cycle from 1 to 9 (omit 0) } -void ModControllableAudio::getDelaySyncLevelDisplayName(char* displayName) { +std::string ModControllableAudio::getDelaySyncLevelDisplayName() { // Note: SYNC_LEVEL_NONE (value 0) can't be selected delay.syncLevel = (SyncLevel)(delay.syncLevel % SyncLevel::SYNC_LEVEL_256TH); // cycle from 1 to 9 (omit 0) - StringBuf buffer{shortStringBuffer, kShortStringBufferSize}; - currentSong->getNoteLengthName(buffer, (uint32_t)3 << (SYNC_LEVEL_256TH - delay.syncLevel)); - strncpy(displayName, buffer.data(), 29); + return currentSong->getNoteLengthName((uint32_t)3 << (SYNC_LEVEL_256TH - delay.syncLevel)); } char const* ModControllableAudio::getFilterTypeDisplayName(FilterType currentFilterType) { @@ -1439,9 +1437,7 @@ void ModControllableAudio::displayDelaySettings(bool on) { popupMsg.append(getDelaySyncTypeDisplayName()); popupMsg.append("\nSync: "); - char displayName[30]; - getDelaySyncLevelDisplayName(displayName); - popupMsg.append(displayName); + popupMsg.append(getDelaySyncLevelDisplayName()); } else { popupMsg.append("Ping pong: "); @@ -1463,9 +1459,7 @@ void ModControllableAudio::displayDelaySettings(bool on) { display->displayPopup(getDelaySyncTypeDisplayName()); } else { - char displayName[30]; - getDelaySyncLevelDisplayName(displayName); - display->displayPopup(displayName); + display->displayPopup(getDelaySyncLevelDisplayName()); } } else { diff --git a/src/deluge/model/mod_controllable/mod_controllable_audio.h b/src/deluge/model/mod_controllable/mod_controllable_audio.h index 6df1f0bd9c..f4d9fc476b 100644 --- a/src/deluge/model/mod_controllable/mod_controllable_audio.h +++ b/src/deluge/model/mod_controllable/mod_controllable_audio.h @@ -150,7 +150,7 @@ class ModControllableAudio : public ModControllable { char const* getDelayTypeDisplayName(); char const* getDelayPingPongStatusDisplayName(); char const* getDelaySyncTypeDisplayName(); - void getDelaySyncLevelDisplayName(char* displayName); + std::string getDelaySyncLevelDisplayName(); char const* getSidechainDisplayName(); void displayFilterSettings(bool on, FilterType currentFilterType); diff --git a/src/deluge/model/song/song.cpp b/src/deluge/model/song/song.cpp index 025b3138b2..1590050730 100644 --- a/src/deluge/model/song/song.cpp +++ b/src/deluge/model/song/song.cpp @@ -66,6 +66,7 @@ #include #include #include +#include extern "C" {} @@ -5127,10 +5128,9 @@ void Song::replaceOutputLowLevel(Output* newOutput, Output* oldOutput) { AudioEngine::mustUpdateReverbParamsBeforeNextRender = true; } -void Song::getNoteLengthName(StringBuf& buffer, uint32_t noteLength, char const* const notesString, - bool clarifyPerColumn) const { - getNoteLengthNameFromMagnitude(buffer, getNoteMagnitudeFfromNoteLength(noteLength, getInputTickMagnitude()), - notesString, clarifyPerColumn); +std::string Song::getNoteLengthName(uint32_t noteLength, char const* const notesString, bool clarifyPerColumn) const { + return getNoteLengthNameFromMagnitude(getNoteMagnitudeFfromNoteLength(noteLength, getInputTickMagnitude()), + notesString, clarifyPerColumn); } Instrument* Song::getNonAudioInstrumentToSwitchTo(OutputType newOutputType, Availability availabilityRequirement, diff --git a/src/deluge/model/song/song.h b/src/deluge/model/song/song.h index 054712512c..581fcbdbf3 100644 --- a/src/deluge/model/song/song.h +++ b/src/deluge/model/song/song.h @@ -351,8 +351,8 @@ class Song final : public TimelineCounter { AudioOutput* getFirstAudioOutput(); AudioOutput* createNewAudioOutput(Output* replaceOutput = nullptr); /// buffer must have at least 5 characters on 7seg, or 30 for OLED - void getNoteLengthName(StringBuf& buffer, uint32_t noteLength, char const* notesString = "-notes", - bool clarifyPerColumn = false) const; + std::string getNoteLengthName(uint32_t noteLength, char const* notesString = "-notes", + bool clarifyPerColumn = false) const; void replaceOutputLowLevel(Output* newOutput, Output* oldOutput); void removeSessionClip(Clip* clip, int32_t clipIndex, bool forceClipsAboveToMoveVertically = false); bool deletePendingOverdubs(Output* onlyWithOutput = nullptr, int32_t* originalClipIndex = nullptr, diff --git a/src/deluge/model/sync.cpp b/src/deluge/model/sync.cpp index 2636134f80..e8929fe9f9 100644 --- a/src/deluge/model/sync.cpp +++ b/src/deluge/model/sync.cpp @@ -45,22 +45,20 @@ enum SyncLevel syncValueToSyncLevel(int32_t option) { if (option < SYNC_TYPE_TRIPLET) { return static_cast(option); } - else if (option < SYNC_TYPE_DOTTED) { + if (option < SYNC_TYPE_DOTTED) { return static_cast(option - SYNC_TYPE_TRIPLET + 1); } - else { - return static_cast(option - SYNC_TYPE_DOTTED + 1); - } + return static_cast(option - SYNC_TYPE_DOTTED + 1); } -void syncValueToString(uint32_t value, StringBuf& buffer, int32_t tickMagnitude) { - char const* typeStr = nullptr; - enum SyncType type { syncValueToSyncType(value) }; - enum SyncLevel level { syncValueToSyncLevel(value) }; +std::string syncValueToString(uint32_t value, int32_t tickMagnitude) { + SyncType type = syncValueToSyncType(value); + SyncLevel level = syncValueToSyncLevel(value); uint32_t shift = SYNC_LEVEL_256TH - level; uint32_t noteLength = uint32_t{3} << shift; + std::string_view typeStr; switch (type) { case SYNC_TYPE_EVEN: if (value != 0) { @@ -75,14 +73,16 @@ void syncValueToString(uint32_t value, StringBuf& buffer, int32_t tickMagnitude) break; } - getNoteLengthNameFromMagnitude(buffer, getNoteMagnitudeFfromNoteLength(noteLength, tickMagnitude), typeStr, false); - if (typeStr != nullptr) { + auto name = + getNoteLengthNameFromMagnitude(getNoteMagnitudeFfromNoteLength(noteLength, tickMagnitude), typeStr, false); + if (!typeStr.empty()) { int32_t magnitudeLevelBars = SYNC_LEVEL_8TH - tickMagnitude; if (((type == SYNC_TYPE_TRIPLET || type == SYNC_TYPE_DOTTED) && level <= magnitudeLevelBars) || display->have7SEG()) { // On OLED, getNoteLengthNameForMagniture() handles adding this for the non-bar levels. On 7seg, always // append it - buffer.append(typeStr); + name += typeStr; } } + return name; } diff --git a/src/deluge/model/sync.h b/src/deluge/model/sync.h index b77347b098..4c42749954 100644 --- a/src/deluge/model/sync.h +++ b/src/deluge/model/sync.h @@ -39,7 +39,7 @@ enum SyncLevel syncValueToSyncLevel(int32_t option); enum SyncType syncValueToSyncType(int32_t value); -void syncValueToString(uint32_t value, StringBuf& buffer, int32_t tickMagnitude); +std::string syncValueToString(uint32_t value, int32_t tickMagnitude); /** Modulus of value as a non-zero SyncLevel valid for Swing interval. */ int32_t wrapSwingIntervalSyncLevel(int32_t value); diff --git a/src/deluge/playback/playback_handler.cpp b/src/deluge/playback/playback_handler.cpp index 03045f5096..3639c4d7b4 100644 --- a/src/deluge/playback/playback_handler.cpp +++ b/src/deluge/playback/playback_handler.cpp @@ -73,6 +73,7 @@ #include "storage/storage_manager.h" #include "util/cfunctions.h" #include "util/functions.h" +#include "util/string.h" #include #include @@ -1943,17 +1944,12 @@ void PlaybackHandler::resyncMIDIClockOutTicksToInternalTicks() { void PlaybackHandler::commandDisplaySwingInterval() { DEF_STACK_STRING_BUF(text, 30); if (display->haveOLED()) { - text.append("Swing: "); - if (currentSong->swingAmount == 0) { - text.append("off"); - } - else { - text.appendInt(currentSong->swingAmount + 50); - } - text.append("\n"); + text += "Swing: "; + text += (currentSong->swingAmount == 0) ? "OFF" : deluge::string::fromInt(currentSong->swingAmount + 50); + text += "\n"; } - syncValueToString(currentSong->swingInterval, text, currentSong->getInputTickMagnitude()); - display->popupTextTemporary(text.c_str(), PopupType::SWING); + text += syncValueToString(currentSong->swingInterval, currentSong->getInputTickMagnitude()); + display->popupTextTemporary(text, PopupType::SWING); } void PlaybackHandler::commandClearTempoAutomation() { @@ -1964,25 +1960,15 @@ void PlaybackHandler::commandClearTempoAutomation() { void PlaybackHandler::commandDisplaySwingAmount() { DEF_STACK_STRING_BUF(text, 30); if (display->haveOLED()) { - text.append("Swing: "); - if (currentSong->swingAmount == 0) { - text.append("off"); - } - else { - text.appendInt(currentSong->swingAmount + 50); - } - text.append("\n"); - syncValueToString(currentSong->swingInterval, text, currentSong->getInputTickMagnitude()); + text += "Swing: "; + text += (currentSong->swingAmount == 0) ? "OFF" : deluge::string::fromInt(currentSong->swingAmount + 50); + text += "\n"; + text += syncValueToString(currentSong->swingInterval, currentSong->getInputTickMagnitude()); } else { - if (currentSong->swingAmount == 0) { - text.append("OFF"); - } - else { - text.appendInt(currentSong->swingAmount + 50); - } + text += (currentSong->swingAmount == 0) ? "OFF" : deluge::string::fromInt(currentSong->swingAmount + 50); } - display->popupTextTemporary(text.c_str(), PopupType::SWING); + display->popupTextTemporary(text, PopupType::SWING); } void PlaybackHandler::commandEditSwingInterval(int8_t offset) { @@ -2309,14 +2295,13 @@ float PlaybackHandler::calculateBPM(float timePerInternalTick) { return currentSong->calculateBPM(timePerInternalTick); } -void PlaybackHandler::getTempoStringForOLED(float tempoBPM, StringBuf& buffer) { +std::string PlaybackHandler::getTempoStringForOLED(float tempoBPM) { if (tempoBPM >= 9999.5) { - buffer.append("FAST"); - } - else { - int32_t numDecimalPlaces = (tempoBPM >= 1000 || isExternalClockActive()) ? 0 : 2; - buffer.appendFloat(tempoBPM, 0, numDecimalPlaces); + return "FAST"; } + + auto precision = (tempoBPM >= 1000 || isExternalClockActive()) ? 0 : 2; + deluge::string::fromFloat(tempoBPM, precision); } void PlaybackHandler::displayTempoBPM(float tempoBPM) { @@ -2328,14 +2313,14 @@ void PlaybackHandler::displayTempoBPM(float tempoBPM) { if ((currentUI == &sessionView || currentUI == &arrangerView) && !deluge::hid::display::OLED::isPermanentPopupPresent()) { sessionView.lastDisplayedTempo = tempoBPM; - getTempoStringForOLED(tempoBPM, text); + text += getTempoStringForOLED(tempoBPM); sessionView.displayTempoBPM(deluge::hid::display::OLED::main, text, true); deluge::hid::display::OLED::markChanged(); } else { - text.append("Tempo: "); - getTempoStringForOLED(tempoBPM, text); - display->popupTextTemporary(text.c_str(), PopupType::TEMPO); + text += "Tempo: "; + text += getTempoStringForOLED(tempoBPM); + display->popupTextTemporary(text, PopupType::TEMPO); } } else { @@ -2388,13 +2373,13 @@ void PlaybackHandler::displayTempoBPM(float tempoBPM) { // If perfect and integer... if (isPerfect && roundedBigger == roundedTempoBPM * divisor) { - text.appendInt(roundedTempoBPM); - display->popupTextTemporary(text.c_str(), PopupType::TEMPO); + text += deluge::string::fromInt(roundedTempoBPM); + display->popupTextTemporary(text, PopupType::TEMPO); } else { - text.appendInt(roundedBigger, 4); + text += string::fromInt(roundedBigger, 4); // This is what popupTextTemporary() does, except for passing in the dotMask - display->displayPopup(text.c_str(), 3, false, dotMask, 1, PopupType::TEMPO); + display->displayPopup(text, 3, false, dotMask, 1, PopupType::TEMPO); } } } diff --git a/src/deluge/playback/playback_handler.h b/src/deluge/playback/playback_handler.h index 8ae9c6dcf9..6445545e63 100644 --- a/src/deluge/playback/playback_handler.h +++ b/src/deluge/playback/playback_handler.h @@ -225,7 +225,7 @@ class PlaybackHandler { void commandDisplayTempo(int8_t offset); void commandClearTempoAutomation(); - void getTempoStringForOLED(float tempoBPM, StringBuf& buffer); + std::string getTempoStringForOLED(float tempoBPM); void tryLoopCommand(GlobalMIDICommand command); diff --git a/src/deluge/processing/sound/sound.cpp b/src/deluge/processing/sound/sound.cpp index d4ebf127a4..5d544e07d4 100644 --- a/src/deluge/processing/sound/sound.cpp +++ b/src/deluge/processing/sound/sound.cpp @@ -4412,9 +4412,7 @@ bool Sound::modEncoderButtonAction(uint8_t whichModEncoder, bool on, ModelStackW displayDelaySettings(on); } else { - char displayName[30]; - getDelaySyncLevelDisplayName(displayName); - display->displayPopup(displayName); + display->displayPopup(getDelaySyncLevelDisplayName()); } } else { diff --git a/src/deluge/util/cfunctions.c b/src/deluge/util/cfunctions.c index c315882480..d6b27e6c86 100644 --- a/src/deluge/util/cfunctions.c +++ b/src/deluge/util/cfunctions.c @@ -65,154 +65,6 @@ void intToString(int32_t number, char* __restrict__ buffer, int32_t minNumDigits } } -void floatToString(float number, char* __restrict__ buffer, int32_t minNumDecimalPlaces, int32_t maxNumDecimalPlaces) { - - uint32_t rawBinary = *(uint32_t*)&number; - char* writePos = buffer; - - if (rawBinary >> 31) { // If negative... - *writePos = '-'; - writePos++; - } - - char* leftmostDigitPos = writePos; // Not including minus sign. - - int32_t exponent = (int32_t)((rawBinary >> 23) & 255) - 127; - - if (exponent >= 0) { - - uint32_t leftOfDecimals = (rawBinary & 0x007FFFFF) | 0x00800000; - if (exponent <= 23) { - leftOfDecimals >>= (23 - exponent); - } - else if (exponent <= 30) { // Could go up to 31 if we had an unsignedIntToString(). - leftOfDecimals <<= (exponent - 23); - } - else { - *(writePos++) = 'i'; - *(writePos++) = 'n'; - *(writePos++) = 'f'; - *writePos = 0; - return; - } - intToString(leftOfDecimals, writePos, 1); - writePos = strchr(writePos, 0); - } - else { - *(writePos++) = '0'; - } - - uint32_t fractionRemaining = rawBinary & 0x007FFFFF; - fractionRemaining |= 0x00800000; // Draw in the invisible "1". - if (exponent >= -5) { - fractionRemaining <<= (exponent + 5); - } - else { - fractionRemaining >>= (-5 - exponent); // Yes, in this case, we throw away bits and lose accuracy. - } - - int32_t decimalPlace = 0; - - while (true) { - fractionRemaining &= 0x0FFFFFFF; - - if (!fractionRemaining && decimalPlace >= minNumDecimalPlaces) { - *writePos = 0; - return; - } - - if (decimalPlace >= maxNumDecimalPlaces) { - break; - } - - if (!decimalPlace) { - *writePos = '.'; - writePos++; - } - - fractionRemaining *= 10; - int32_t decimalDigit = fractionRemaining >> 28; - *writePos = '0' + decimalDigit; - writePos++; - decimalPlace++; - } - - // We've reached our max number of decimal places, but still got a remainder. - *writePos = 0; - char* oldEndPos; - - // See if we need to round up. - if (fractionRemaining >= (uint32_t)0x08000000) { - oldEndPos = writePos; -moveBackOneDigit: - // If we reached left of string, oh no, we can't move back any further. So move everything else instead. - if (writePos == leftmostDigitPos) { - goto needExtraDigitOnLeft; - } - - writePos--; - decimalPlace--; - if (*writePos == '.') { - if (minNumDecimalPlaces <= 0) { - *writePos = 0; - oldEndPos = writePos; // Update it - } - writePos--; - } - if (*writePos == '9') { - if (decimalPlace >= minNumDecimalPlaces) { - *writePos = 0; - oldEndPos = writePos; // Update it - } - else { - *writePos = '0'; - } - goto moveBackOneDigit; - } - (*writePos)++; // Increment that digit. Not moving the pointer. - } - - // Or if not rounding up, we still may have a string of zeros on the end, which may go above our min decimal places, - // so we should lose those. - else { - while (true) { - writePos--; - if (decimalPlace <= minNumDecimalPlaces) { - if (*writePos == '.') { - *writePos = - 0; // If min decimal places was 0 and we got that far back, get rid of the decimal point. - } - break; - } - decimalPlace--; - if (*writePos != '0') { - break; - } - *writePos = 0; - } - } - return; - - // If we reached left of string, oh no, we can't move back any further. So move everything else instead. -needExtraDigitOnLeft: {} - char* readPos = oldEndPos; - while (readPos >= leftmostDigitPos) { - *(readPos + 1) = *readPos; - readPos--; - } - *leftmostDigitPos = '1'; -} - -void slotToString(int32_t slot, int32_t subSlot, char* __restrict__ buffer, int32_t minNumDigits) { - intToString(slot, buffer, minNumDigits); - - if (subSlot != -1) { - int32_t stringLength = strlen(buffer); - buffer[stringLength] = subSlot + 'A'; - buffer[stringLength + 1] = 0; - } -} - uint32_t superfastTimerCountToNS(uint32_t timerCount) { return (uint64_t)timerCount * 400000000 / XTAL_SPEED_MHZ; } diff --git a/src/deluge/util/cfunctions.h b/src/deluge/util/cfunctions.h index ebf7313ea1..a132b28467 100644 --- a/src/deluge/util/cfunctions.h +++ b/src/deluge/util/cfunctions.h @@ -25,8 +25,6 @@ extern "C" { int32_t getNumDecimalDigits(uint32_t number); void intToString(int32_t number, char* buffer, int32_t minNumDigits); -void floatToString(float number, char* __restrict__ buffer, int32_t minNumDecimalPlaces, int32_t maxNumDecimalPlaces); -void slotToString(int32_t slot, int32_t subSlot, char* __restrict__ buffer, int32_t minNumDigits); uint32_t fastTimerCountToUS(uint32_t timerCount); uint32_t usToFastTimerCount(uint32_t us); uint32_t msToSlowTimerCount(uint32_t ms); diff --git a/src/deluge/util/d_string.cpp b/src/deluge/util/d_string.cpp index 17f893ec9c..5f37850bd7 100644 --- a/src/deluge/util/d_string.cpp +++ b/src/deluge/util/d_string.cpp @@ -20,6 +20,9 @@ #include "memory/general_memory_allocator.h" #include "util/cfunctions.h" #include +#include +#include +#include #include const char nothing = 0; @@ -379,3 +382,28 @@ uint32_t hexToIntFixedLength(char const* __restrict__ hexChars, int32_t length) return output; } + +StringBuf& StringBuf::appendInt(int32_t value, size_t min_digits) { + DEF_STACK_STRING_BUF(buffer, 20); + + auto [endPtr, ec] = std::to_chars(buffer.begin(), buffer.true_end() - 1, value); // Leave room for NUL + if (ec != std::errc()) { + return *this; // fail if error + } + *endPtr = '\0'; + + size_t length = endPtr - buffer.begin(); + + // calculate how many characters to copy: the minimum required digits _or_ only enough to fill the string (excluding + // NUL) + size_t num_to_copy = std::min(min_digits, capacity() - size()); + + int32_t pad_count = static_cast(num_to_copy) - length; + char* it = end(); + if (pad_count > 0) { + it = std::fill_n(it, pad_count, '0'); // literal zero! not NUL! + } + it = std::copy_n(buffer.begin(), length, it); + *it = '\0'; + return *this; +} diff --git a/src/deluge/util/d_string.h b/src/deluge/util/d_string.h index 6429b562d7..df20af70d6 100644 --- a/src/deluge/util/d_string.h +++ b/src/deluge/util/d_string.h @@ -18,8 +18,13 @@ #pragma once #include "definitions_cxx.hpp" +#include "util/exceptions.h" +#include "util/string.h" +#include "util/try.h" +#include #include #include +#include extern "C" { #include "util/cfunctions.h" @@ -110,40 +115,94 @@ class String { class StringBuf { // Not templated to optimize binary size. public: - StringBuf(char* buf, size_t capacity) : capacity_(capacity), buf_(buf) { memset(buf_, '\0', capacity_); } - - void append(const char* str) { ::strncat(buf_, str, capacity_ - size() - 1); } - void append(char c) { ::strncat(buf_, &c, 1); } - void clear() { buf_[0] = 0; } - void truncate(size_t newSize) { - if (newSize < capacity_) { - buf_[newSize] = '\0'; + constexpr StringBuf(char* buf, size_t capacity) : capacity_(capacity - 1), buf_(buf) { + std::fill_n(buf_, capacity, '\0'); + } + + constexpr void append(std::string_view str, size_t n) { + size_t to_concat = std::min({n, str.length(), capacity_ - size()}); + if (to_concat > 0) { + char* ptr = std::copy_n(str.begin(), to_concat, this->end()); + *ptr = '\0'; + } + } + + constexpr void append(std::string_view str) { append(str, str.length()); } + + constexpr void append(char c) { + if (length() != capacity()) { + char* terminal = end(); + terminal[0] = c; + terminal[1] = '\0'; + } + } + + constexpr void clear() { std::fill_n(buf_, capacity_ + 1, '\0'); } + + constexpr void truncate(size_t size) { + if (size <= capacity_) { + buf_[size] = '\0'; } } - // TODO: Validate buffer size. These can overflow - void appendInt(int i, int minChars = 1) { intToString(i, buf_ + size(), minChars); } - void appendHex(int i, int minChars = 1) { intToHex(i, buf_ + size(), minChars); } - void appendFloat(float f, int32_t minDecimals, int32_t maxDecimals) { - floatToString(f, buf_ + size(), minDecimals, maxDecimals); + StringBuf& appendInt(int32_t value, size_t min_digits = 1); + + StringBuf& appendHex(int32_t value, size_t min_digits = 1) { + intToHex(value, end(), min_digits); + return *this; + } + + StringBuf& appendFloat(float value, int32_t precision) { + char* ptr = D_TRY_CATCH(deluge::to_chars(end(), true_end(), value, precision), error, { + return *this; // fail if error + }); + *ptr = '\0'; + return *this; } - [[nodiscard]] char* data() { return buf_; } - [[nodiscard]] const char* data() const { return buf_; } - [[nodiscard]] const char* c_str() const { return buf_; } + [[nodiscard]] constexpr char* data() { return buf_; } + [[nodiscard]] constexpr const char* data() const { return buf_; } + [[nodiscard]] constexpr const char* c_str() const { return buf_; } + + [[nodiscard]] constexpr size_t capacity() const { return capacity_; } + [[nodiscard]] constexpr size_t length() const { + size_t idx = 0; + for (; idx <= capacity_; ++idx) { + if (buf_[idx] == '\0') { + break; + } + } + return idx; + } + [[nodiscard]] constexpr size_t size() const { return length(); } + [[nodiscard]] constexpr bool full() const { return size() == capacity_; } - [[nodiscard]] size_t capacity() const { return capacity_; } - [[nodiscard]] size_t size() const { return std::strlen(buf_); } - [[nodiscard]] size_t length() const { return std::strlen(buf_); } + [[nodiscard]] char* begin() { return buf_; } + [[nodiscard]] char* end() { return &buf_[size()]; } + [[nodiscard]] const char* cbegin() const { return buf_; } + [[nodiscard]] const char* cend() const { return &buf_[size()]; } [[nodiscard]] bool empty() const { return buf_[0] == '\0'; } - bool operator==(const char* rhs) const { return std::strcmp(buf_, rhs) == 0; } - bool operator==(const StringBuf& rhs) const { return std::strcmp(buf_, rhs.c_str()) == 0; } + constexpr bool operator==(const char* rhs) const { + return static_cast(*this) == std::string_view{rhs}; + } + + constexpr bool operator==(const std::string_view rhs) const { return static_cast(*this) == rhs; } + + constexpr bool operator==(const StringBuf& rhs) const { + return static_cast(*this) == static_cast(rhs); + } + + constexpr void operator+=(const char* cstr) { append(cstr); } + constexpr void operator+=(std::string_view str) { append(str); } + constexpr void operator+=(std::string& str) { append(str); } operator std::string_view() const { return std::string_view{buf_}; } + char& operator[](size_t idx) { return buf_[idx]; } private: + [[nodiscard]] constexpr char* true_end() const { return &buf_[capacity_ + 1]; } size_t capacity_; char* buf_; }; diff --git a/src/deluge/util/functions.cpp b/src/deluge/util/functions.cpp index f463678dae..1aeac3b070 100644 --- a/src/deluge/util/functions.cpp +++ b/src/deluge/util/functions.cpp @@ -29,9 +29,12 @@ #include "processing/audio_output.h" #include "processing/sound/sound.h" #include "util/lookuptables/lookuptables.h" +#include "util/string.h" #include #include -#include +#include +#include +#include extern "C" { #include "RZA1/uart/sio_char.h" @@ -2036,71 +2039,83 @@ int32_t getNoteMagnitudeFfromNoteLength(uint32_t noteLength, int32_t tickMagnitu return noteMagnitude; } -void getNoteLengthNameFromMagnitude(StringBuf& noteLengthBuf, int32_t magnitude, char const* const notesString, - bool clarifyPerColumn) { +std::string getNoteLengthNameFromMagnitudeOLED(int32_t magnitude, const std::string_view notesString, + bool clarifyPerColumn) { // Positive magnitudes are bars, negative magnitudes are divisions of bars. uint32_t division = (uint32_t)1 << (0 - magnitude); - if (display->haveOLED()) { - if (magnitude < 0) { - noteLengthBuf.appendInt(division); - // this is not fully general but since division are always a power of 2, it works out in practice (no need - // for "rd") - char const* suffix = ((division % 10) == 2) ? "nd" : "th"; - noteLengthBuf.append(suffix); - noteLengthBuf.append(notesString); + std::string name; + if (magnitude < 0) { + name += deluge::string::fromInt(division); + // this is not fully general but since division are always a power of 2, it works out in practice (no need + // for "rd") + char const* suffix = ((division % 10) == 2) ? "nd" : "th"; + name += suffix; + name += notesString; + } + else { + uint32_t numBars = (uint32_t)1 << magnitude; + name += deluge::string::fromInt(numBars); + if (clarifyPerColumn) { + name += ' '; + name += (numBars == 1) ? "bar" : "bars"; + name += " (per column)"; } else { - uint32_t numBars = (uint32_t)1 << magnitude; - noteLengthBuf.appendInt(numBars); - if (clarifyPerColumn) { - if (numBars == 1) { - noteLengthBuf.append(" bar (per column)"); - } - else { - noteLengthBuf.append(" bars (per column)"); - } + name += "-bar"; + } + } + return name; +} + +std::string getNoteLengthNameFromMagnitude7SEG(int32_t magnitude, const std::string_view notesString, + bool clarifyPerColumn) { + + // Positive magnitudes are bars, negative magnitudes are divisions of bars. + uint32_t division = (uint32_t)1 << (0 - magnitude); + + std::string name; + if (magnitude < 0) { + if (division <= 9999) { + name += deluge::string::fromInt(division); + if (division == 2 || division == 32) { + name += "ND"; } - else { - noteLengthBuf.append("-bar"); + else if (division <= 99) { + name += "TH"; + } + else if (division <= 999) { + name += "T"; } } + else { + name += "TINY"; + } } else { - if (magnitude < 0) { - if (division <= 9999) { - noteLengthBuf.appendInt(division); - if (division == 2 || division == 32) { - noteLengthBuf.append("ND"); - } - else if (division <= 99) { - noteLengthBuf.append("TH"); - } - else if (division <= 999) { - noteLengthBuf.append("T"); - } + uint32_t numBars = (uint32_t)1 << magnitude; + if (numBars <= 9999) { + name += deluge::string::fromInt(numBars); + if (name.length() == 1) { + name += "BAR"; } - else { - noteLengthBuf.append("TINY"); + else if (name.length() <= 3) { + name += "B"; } } else { - uint32_t numBars = (uint32_t)1 << magnitude; - if (numBars <= 9999) { - noteLengthBuf.appendInt(numBars); - auto size = noteLengthBuf.size(); - if (size == 1) { - noteLengthBuf.append("BAR"); - } - else if (size <= 3) { - noteLengthBuf.append("B"); - } - } - else { - noteLengthBuf.append("BIG"); - } + name += "BIG"; } } + return name; +} + +std::string getNoteLengthNameFromMagnitude(int32_t magnitude, const std::string_view notesString, + bool clarifyPerColumn) { + if (display->haveOLED()) { + return getNoteLengthNameFromMagnitudeOLED(magnitude, notesString, clarifyPerColumn); + } + return getNoteLengthNameFromMagnitude7SEG(magnitude, notesString, clarifyPerColumn); } char const* getFileNameFromEndOfPath(char const* filePathChars) { diff --git a/src/deluge/util/functions.h b/src/deluge/util/functions.h index 9a712e6a5f..4e228f927c 100644 --- a/src/deluge/util/functions.h +++ b/src/deluge/util/functions.h @@ -30,6 +30,7 @@ #include #include #include +#include class UI; @@ -414,8 +415,8 @@ bool charCaseEqual(char firstChar, char secondChar); bool shouldAbortLoading(); int32_t getNoteMagnitudeFfromNoteLength(uint32_t noteLength, int32_t tickMagnitude); /// buffer must have at least 5 characters on 7seg, or 30 for OLED -void getNoteLengthNameFromMagnitude(StringBuf& buf, int32_t magnitude, char const* durrationSuffix = "-notes", - bool clarifyPerColumn = false); +std::string getNoteLengthNameFromMagnitude(int32_t magnitude, std::string_view durrationSuffix = "-notes", + bool clarifyPerColumn = false); bool doesFilenameFitPrefixFormat(char const* fileName, char const* filePrefix, int32_t prefixLength); Error fresultToDelugeErrorCode(FRESULT result); namespace FatFS { diff --git a/src/deluge/util/lookuptables/lookuptables.cpp b/src/deluge/util/lookuptables/lookuptables.cpp index 151a63145c..37e3554941 100644 --- a/src/deluge/util/lookuptables/lookuptables.cpp +++ b/src/deluge/util/lookuptables/lookuptables.cpp @@ -482,8 +482,8 @@ const int16_t lanczosKernelA16[1025] = { -const uint8_t noteCodeToNoteLetter[12] = {67, 67, 68, 68, 69, 70, 70, 71, 71, 65, 65, 66}; -const bool noteCodeIsSharp[12] = {0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0}; +const char noteCodeToNoteLetter[12] = {'C','C','D','D','E','F','F','G','G','A','A','B'}; +const bool noteCodeIsSharp[12] = {false, true, false, true, 0, false, true, false, true, false, true, false}; /** * @brief How iterance is encoded: diff --git a/src/deluge/util/lookuptables/lookuptables.h b/src/deluge/util/lookuptables/lookuptables.h index 849a61da8a..24611c1670 100644 --- a/src/deluge/util/lookuptables/lookuptables.h +++ b/src/deluge/util/lookuptables/lookuptables.h @@ -130,7 +130,7 @@ const uint8_t presetReverbRoomSize[NUM_PRESET_REVERBS] = {16, 30, 44}; const uint8_t presetReverbDamping[NUM_PRESET_REVERBS] = {29, 36, 45}; extern deluge::l10n::String presetReverbNames[NUM_PRESET_REVERBS]; -extern const uint8_t noteCodeToNoteLetter[]; +extern const char noteCodeToNoteLetter[]; extern const bool noteCodeIsSharp[]; extern const std::array iterancePresets; diff --git a/src/deluge/util/string.cpp b/src/deluge/util/string.cpp new file mode 100644 index 0000000000..7404ba2871 --- /dev/null +++ b/src/deluge/util/string.cpp @@ -0,0 +1,83 @@ +#include "util/string.h" +#include "printf.h" +#include "util/lookuptables/lookuptables.h" +#include "util/try.h" +#include +#include +#include +#include +#include +#include + +namespace deluge { +std::expected to_chars(char* first, char* last, float value, int precision) { + if (first >= last) { + return std::unexpected{std::errc::no_buffer_space}; + } + + size_t buffer_size = last - first; + + std::array format; + snprintf_(format.data(), format.size(), "%%.%df", precision); + + int written = snprintf_(first, buffer_size, format.data(), value); + if (written < 0 || static_cast(written) >= buffer_size) { + std::unexpected{std::errc::no_buffer_space}; + } + return first + written; +} +} // namespace deluge + +namespace deluge::string { +std::string fromInt(int32_t number, size_t min_num_digits) { + // Convert number to string + std::string result = std::to_string(number); + + // Add leading zeros if needed + if (result[0] != '-' && result.size() < min_num_digits) { + result.insert(result.begin(), min_num_digits - result.size(), '0'); + } + else if (result[0] == '-' && result.size() - 1 < min_num_digits) { + result.insert(result.begin() + 1, min_num_digits - (result.size() - 1), '0'); + } + + return result; +} + +std::string fromFloat(float number, int32_t precision) { + std::array buffer; + char* ptr = D_TRY_CATCH(to_chars(buffer.begin(), buffer.end(), number, precision), error, { + return std::string{}; // + }); + + return std::string{buffer.data(), ptr}; +} + +std::string fromSlot(int32_t slot, int32_t subSlot, size_t minNumDigits) { + std::string buffer = fromInt(slot, minNumDigits); + if (subSlot != -1) { + buffer.push_back(static_cast(subSlot + 'A')); + } + return buffer; +} + +std::string fromNoteCode(int32_t noteCode, size_t* getLengthWithoutDot, bool appendOctaveNo) { + std::string output; + int32_t octave = (noteCode) / 12 - 2; + int32_t noteCodeWithinOctave = (uint16_t)(noteCode + 120) % (uint8_t)12; + + output += noteCodeToNoteLetter[noteCodeWithinOctave]; + if (noteCodeIsSharp[noteCodeWithinOctave]) { + output += display->haveOLED() ? '#' : '.'; + } + if (appendOctaveNo) { + output += std::to_string(octave); + } + + if (getLengthWithoutDot != nullptr) { + *getLengthWithoutDot = noteCodeIsSharp[noteCodeWithinOctave] ? output.length() - 1 : output.length(); + } + return output; +} + +} // namespace deluge::string diff --git a/src/deluge/util/string.h b/src/deluge/util/string.h new file mode 100644 index 0000000000..cb37dbe238 --- /dev/null +++ b/src/deluge/util/string.h @@ -0,0 +1,19 @@ +#pragma once +#include +#include +#include +#include + +namespace deluge { +std::expected to_chars(char* first, char* last, float value, int precision); +} // namespace deluge + +namespace deluge::string { + +/// @brief convert an integer into a string, left-padding with '0's +std::string fromInt(int32_t number, size_t min_num_digits = 1); +std::string fromFloat(float number, int32_t precision); +std::string fromSlot(int32_t slot, int32_t sub_slot, size_t min_num_digits = 1); +std::string fromNoteCode(int32_t noteCode, size_t* getLengthWithoutDot = nullptr, bool appendOctaveNo = true); + +} // namespace deluge::string diff --git a/src/sys_stubs.c b/src/sys_stubs.c index 7561c7db17..c8fda01911 100644 --- a/src/sys_stubs.c +++ b/src/sys_stubs.c @@ -1,58 +1,58 @@ -#include "definitions.h" -#include - -// this is not included in the build but remains as a repo of information for implementing these in the future, -// and to help troubleshoot link failures in the future - e.g. if _sbrk is required, it can be added to -// finish compilation and find out what's including it - -// this stub fails to allocate - needed for libc malloc -// Take advantage of that to ensure anything which allocates will fail to link -void* _sbrk(int incr) { - FREEZE_WITH_ERROR("SBRK"); - return (void*)-1; -} - -// needed for libc abort, raise, return from main -void _exit(int status) { - // halt execution - FREEZE_WITH_ERROR("EXIT"); - __builtin_unreachable(); -} - -// needed for libc abort -void _kill(int pid, int sig) { - return; -} - -// needed for libc abort -int _getpid(void) { - return -1; -} - -// needed for stdio, files -int _close(int file) { - return -1; -} - -// return character oriented (not block) -int _fstat(int file, struct stat* st) { - st->st_mode = S_IFCHR; - return 0; -} - -// return character oriented -int _isatty(int file) { - return 1; -} - -int _lseek(int file, int ptr, int dir) { - return 0; -} -// write nothing - note these will loop infinitely with newlib -int _write(int file, char* ptr, int len) { - return 0; -} -// read nothing -int _read(int file, char* ptr, int len) { - return 0; -} +// #include "definitions.h" +// #include + +// // this is not included in the build but remains as a repo of information for implementing these in the future, +// // and to help troubleshoot link failures in the future - e.g. if _sbrk is required, it can be added to +// // finish compilation and find out what's including it + +// // this stub fails to allocate - needed for libc malloc +// // Take advantage of that to ensure anything which allocates will fail to link +// void* _sbrk(int incr) { +// FREEZE_WITH_ERROR("SBRK"); +// return (void*)-1; +// } + +// // needed for libc abort, raise, return from main +// void _exit(int status) { +// // halt execution +// FREEZE_WITH_ERROR("EXIT"); +// __builtin_unreachable(); +// } + +// // needed for libc abort +// void _kill(int pid, int sig) { +// return; +// } + +// // needed for libc abort +// int _getpid(void) { +// return -1; +// } + +// // needed for stdio, files +// int _close(int file) { +// return -1; +// } + +// // return character oriented (not block) +// int _fstat(int file, struct stat* st) { +// st->st_mode = S_IFCHR; +// return 0; +// } + +// // return character oriented +// int _isatty(int file) { +// return 1; +// } + +// int _lseek(int file, int ptr, int dir) { +// return 0; +// } +// // write nothing - note these will loop infinitely with newlib +// int _write(int file, char* ptr, int len) { +// return 0; +// } +// // read nothing +// int _read(int file, char* ptr, int len) { +// return 0; +// } From 27e20355a2fe75a573559824bb265ba68ce40869 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Thu, 2 Jan 2025 20:02:14 -0500 Subject: [PATCH 2/7] l10n::get to std::string_view --- .../gui/context_menu/audio_input_selector.cpp | 6 +-- .../gui/context_menu/audio_input_selector.h | 4 +- src/deluge/gui/context_menu/clear_song.cpp | 8 ++-- src/deluge/gui/context_menu/clear_song.h | 4 +- .../clip_settings/clip_settings.cpp | 14 +++--- .../clip_settings/clip_settings.h | 4 +- .../clip_settings/launch_style.cpp | 10 ++--- .../context_menu/clip_settings/launch_style.h | 4 +- .../clip_settings/new_clip_type.cpp | 10 ++--- .../clip_settings/new_clip_type.h | 4 +- .../context_menu/configure_song_macros.cpp | 11 ++--- .../gui/context_menu/configure_song_macros.h | 4 +- src/deluge/gui/context_menu/context_menu.h | 4 +- src/deluge/gui/context_menu/delete_file.cpp | 13 +++--- src/deluge/gui/context_menu/delete_file.h | 4 +- .../context_menu/load_instrument_preset.cpp | 6 +-- .../gui/context_menu/load_instrument_preset.h | 4 +- .../gui/context_menu/midi_learn_mode.cpp | 8 ++-- src/deluge/gui/context_menu/midi_learn_mode.h | 4 +- .../gui/context_menu/overwrite_file.cpp | 13 +++--- src/deluge/gui/context_menu/overwrite_file.h | 4 +- .../gui/context_menu/sample_browser/kit.cpp | 6 +-- .../gui/context_menu/sample_browser/kit.h | 4 +- .../gui/context_menu/sample_browser/synth.cpp | 6 +-- .../gui/context_menu/sample_browser/synth.h | 4 +- .../context_menu/save_song_or_instrument.cpp | 6 +-- .../context_menu/save_song_or_instrument.h | 4 +- .../stem_export/cancel_stem_export.cpp | 8 ++-- .../stem_export/cancel_stem_export.h | 4 +- .../stem_export/done_stem_export.cpp | 8 ++-- .../stem_export/done_stem_export.h | 4 +- src/deluge/gui/l10n/l10n.cpp | 18 ++++---- src/deluge/gui/l10n/l10n.h | 8 ++-- .../gui/menu_item/arpeggiator/chord_type.h | 18 ++++---- src/deluge/gui/menu_item/arpeggiator/mode.h | 4 +- .../gui/menu_item/arpeggiator/mpe_velocity.h | 6 +-- .../gui/menu_item/arpeggiator/note_mode.h | 10 ++--- .../gui/menu_item/arpeggiator/octave_mode.h | 10 ++--- .../gui/menu_item/arpeggiator/preset_mode.h | 12 ++--- .../menu_item/arpeggiator/randomizer_lock.h | 4 +- .../gui/menu_item/audio_interpolation.h | 2 +- src/deluge/gui/menu_item/colour.h | 10 ++--- src/deluge/gui/menu_item/cv/cv2Mapping.h | 8 ++-- src/deluge/gui/menu_item/cv/selection.h | 4 +- .../defaults/grid_default_active_mode.h | 6 +-- .../gui/menu_item/defaults/keyboard_layout.h | 6 +-- .../gui/menu_item/defaults/session_layout.h | 4 +- .../gui/menu_item/defaults/slice_mode.h | 8 ++-- .../menu_item/defaults/startup_song_mode.h | 8 ++-- src/deluge/gui/menu_item/delay/analog.h | 2 +- src/deluge/gui/menu_item/filter/info.h | 2 +- src/deluge/gui/menu_item/filter/mode.h | 27 ++++++------ src/deluge/gui/menu_item/filter_route.h | 2 +- src/deluge/gui/menu_item/flash/status.h | 6 +-- src/deluge/gui/menu_item/gate/mode.h | 2 +- src/deluge/gui/menu_item/gate/selection.h | 18 ++++---- src/deluge/gui/menu_item/lfo/shape.h | 10 ++--- src/deluge/gui/menu_item/menu_item.h | 4 +- src/deluge/gui/menu_item/midi/command.cpp | 7 +-- src/deluge/gui/menu_item/midi/devices.cpp | 2 +- .../menu_item/midi/follow/follow_channel.h | 16 +++---- .../midi/follow/follow_feedback_automation.h | 8 ++-- .../follow/follow_feedback_channel_type.h | 8 ++-- src/deluge/gui/menu_item/midi/preset.h | 3 +- src/deluge/gui/menu_item/midi/takeover.h | 8 ++-- src/deluge/gui/menu_item/midi/transpose.h | 4 +- .../gui/menu_item/modulator/destination.h | 4 +- src/deluge/gui/menu_item/monitor/mode.h | 6 +-- .../gui/menu_item/mpe/direction_selector.h | 8 ++-- .../menu_item/mpe/zone_num_member_channels.h | 2 +- src/deluge/gui/menu_item/mpe/zone_selector.h | 4 +- src/deluge/gui/menu_item/multi_range.h | 4 +- src/deluge/gui/menu_item/osc/type.h | 26 +++++------ .../performance_session_view/editing_mode.h | 6 +-- .../gui/menu_item/record/threshold_mode.h | 8 ++-- src/deluge/gui/menu_item/reverb/model.h | 4 +- src/deluge/gui/menu_item/reverb/room_size.h | 4 +- src/deluge/gui/menu_item/reverb/width.h | 4 +- .../runtime_feature/devSysexSetting.cpp | 4 +- .../gui/menu_item/runtime_feature/setting.cpp | 4 +- .../menu_item/sample/browser_preview/mode.h | 6 +-- src/deluge/gui/menu_item/sample/pitch_speed.h | 2 +- src/deluge/gui/menu_item/sample/repeat.h | 8 ++-- src/deluge/gui/menu_item/sequence/direction.h | 8 ++-- src/deluge/gui/menu_item/shortcuts/version.h | 4 +- .../gui/menu_item/source_selection/range.h | 2 +- .../gui/menu_item/source_selection/regular.h | 2 +- src/deluge/gui/menu_item/sync_level.cpp | 2 +- src/deluge/gui/menu_item/synth_mode.h | 6 +-- src/deluge/gui/menu_item/toggle.cpp | 5 ++- src/deluge/gui/menu_item/toggle.h | 3 +- src/deluge/gui/menu_item/voice/polyphony.h | 10 ++--- src/deluge/gui/menu_item/voice/priority.h | 6 +-- .../ui/keyboard/layout/column_controls.cpp | 4 +- src/deluge/gui/ui/save/save_song_ui.cpp | 4 +- src/deluge/gui/views/automation_view.cpp | 19 ++++---- src/deluge/gui/views/instrument_clip_view.cpp | 19 +++----- src/deluge/gui/views/instrument_clip_view.h | 3 +- src/deluge/gui/views/performance_view.cpp | 30 +++++-------- src/deluge/gui/views/session_view.cpp | 16 +++---- src/deluge/gui/views/session_view.h | 3 +- src/deluge/gui/views/view.cpp | 8 ++-- src/deluge/gui/views/view.h | 2 +- src/deluge/hid/display/display.cpp | 44 +++++++++---------- src/deluge/hid/display/display.h | 5 --- src/deluge/io/midi/cable_types/din.cpp | 3 +- src/deluge/io/midi/cable_types/din.h | 3 +- .../io/midi/cable_types/usb_device_cable.cpp | 3 +- .../io/midi/cable_types/usb_device_cable.h | 3 +- src/deluge/io/midi/cable_types/usb_hosted.cpp | 3 +- src/deluge/io/midi/cable_types/usb_hosted.h | 3 +- src/deluge/io/midi/midi_device.h | 2 +- src/deluge/io/midi/midi_follow.cpp | 3 +- .../global_effectable/global_effectable.cpp | 32 +++++++------- .../global_effectable/global_effectable.h | 9 ++-- .../model/mod_controllable/ModFXProcessor.h | 5 ++- .../mod_controllable_audio.cpp | 17 +++---- .../mod_controllable/mod_controllable_audio.h | 16 +++---- src/deluge/modulation/params/param.cpp | 5 ++- src/deluge/modulation/params/param.h | 5 ++- src/deluge/util/d_string.cpp | 2 +- src/deluge/util/functions.cpp | 2 +- src/deluge/util/functions.h | 2 +- 123 files changed, 445 insertions(+), 454 deletions(-) diff --git a/src/deluge/gui/context_menu/audio_input_selector.cpp b/src/deluge/gui/context_menu/audio_input_selector.cpp index ee2e27f6a3..dd9a3e6ef3 100644 --- a/src/deluge/gui/context_menu/audio_input_selector.cpp +++ b/src/deluge/gui/context_menu/audio_input_selector.cpp @@ -41,14 +41,14 @@ constexpr size_t kNumValues = 8; AudioInputSelector audioInputSelector{}; -char const* AudioInputSelector::getTitle() { +std::string_view AudioInputSelector::getTitle() { using enum l10n::String; return l10n::get(STRING_FOR_AUDIO_SOURCE); } -Sized AudioInputSelector::getOptions() { +Sized AudioInputSelector::getOptions() { using enum l10n::String; - static const char* options[] = { + static std::string_view options[kNumValues] = { l10n::get(STRING_FOR_DISABLED), l10n::get(STRING_FOR_LEFT_INPUT), l10n::get(STRING_FOR_RIGHT_INPUT), l10n::get(STRING_FOR_STEREO_INPUT), l10n::get(STRING_FOR_BALANCED_INPUT), l10n::get(STRING_FOR_MIX_PRE_FX), l10n::get(STRING_FOR_MIX_POST_FX), l10n::get(STRING_FOR_TRACK), diff --git a/src/deluge/gui/context_menu/audio_input_selector.h b/src/deluge/gui/context_menu/audio_input_selector.h index b0491afbf0..75fa498b2a 100644 --- a/src/deluge/gui/context_menu/audio_input_selector.h +++ b/src/deluge/gui/context_menu/audio_input_selector.h @@ -35,10 +35,10 @@ class AudioInputSelector final : public ContextMenu { AudioOutput* audioOutput; /// Title - char const* getTitle() override; + std::string_view getTitle() override; /// Options - Sized getOptions() override; + Sized getOptions() override; }; extern AudioInputSelector audioInputSelector; diff --git a/src/deluge/gui/context_menu/clear_song.cpp b/src/deluge/gui/context_menu/clear_song.cpp index 9ec6287830..71f16eac95 100644 --- a/src/deluge/gui/context_menu/clear_song.cpp +++ b/src/deluge/gui/context_menu/clear_song.cpp @@ -34,19 +34,19 @@ extern void deleteOldSongBeforeLoadingNew(); namespace deluge::gui::context_menu { ClearSong clearSong{}; -char const* ClearSong::getTitle() { +std::string_view ClearSong::getTitle() { using enum l10n::String; return l10n::get(STRING_FOR_CLEAR_SONG_QMARK); } -Sized ClearSong::getOptions() { +Sized ClearSong::getOptions() { using enum l10n::String; if (display->haveOLED()) { - static char const* options[] = {l10n::get(STRING_FOR_OK)}; + static std::string_view options[] = {l10n::get(STRING_FOR_OK)}; return {options, 1}; } else { - static char const* options[] = {l10n::get(STRING_FOR_NEW)}; + static std::string_view options[] = {l10n::get(STRING_FOR_NEW)}; return {options, 1}; } } diff --git a/src/deluge/gui/context_menu/clear_song.h b/src/deluge/gui/context_menu/clear_song.h index 6cde00581d..dea3088ed1 100644 --- a/src/deluge/gui/context_menu/clear_song.h +++ b/src/deluge/gui/context_menu/clear_song.h @@ -26,9 +26,9 @@ class ClearSong final : public ContextMenuForLoading { void focusRegained() override; bool canSeeViewUnderneath() override { return true; } - char const* getTitle() override; + std::string_view getTitle() override; - Sized getOptions() override; + Sized getOptions() override; bool acceptCurrentOption() override; }; diff --git a/src/deluge/gui/context_menu/clip_settings/clip_settings.cpp b/src/deluge/gui/context_menu/clip_settings/clip_settings.cpp index a23e08ebea..1285c7d1b0 100644 --- a/src/deluge/gui/context_menu/clip_settings/clip_settings.cpp +++ b/src/deluge/gui/context_menu/clip_settings/clip_settings.cpp @@ -13,27 +13,27 @@ namespace deluge::gui::context_menu::clip_settings { ClipSettingsMenu clipSettings{}; -char const* ClipSettingsMenu::getTitle() { - static char const* title = "Clip Settings"; +std::string_view ClipSettingsMenu::getTitle() { + static std::string_view title = "Clip Settings"; return title; } -Sized ClipSettingsMenu::getOptions() { +Sized ClipSettingsMenu::getOptions() { using enum l10n::String; if (clip->type == ClipType::AUDIO) { - static const char* optionsls[] = { + static std::string_view options[] = { l10n::get(STRING_FOR_CLIP_MODE), l10n::get(STRING_FOR_CLIP_NAME), }; - return {optionsls, 2}; + return {options, 2}; } else { - static const char* optionsls[] = { + static std::string_view options[] = { l10n::get(STRING_FOR_CONVERT_TO_AUDIO), l10n::get(STRING_FOR_CLIP_MODE), l10n::get(STRING_FOR_CLIP_NAME), }; - return {optionsls, 3}; + return {options, 3}; } } diff --git a/src/deluge/gui/context_menu/clip_settings/clip_settings.h b/src/deluge/gui/context_menu/clip_settings/clip_settings.h index ecc95b3ea7..81221c390d 100644 --- a/src/deluge/gui/context_menu/clip_settings/clip_settings.h +++ b/src/deluge/gui/context_menu/clip_settings/clip_settings.h @@ -18,10 +18,10 @@ class ClipSettingsMenu final : public ContextMenu { Clip* clip = nullptr; /// Title - char const* getTitle() override; + std::string_view getTitle() override; /// Options - Sized getOptions() override; + Sized getOptions() override; ActionResult padAction(int32_t x, int32_t y, int32_t on) override; }; diff --git a/src/deluge/gui/context_menu/clip_settings/launch_style.cpp b/src/deluge/gui/context_menu/clip_settings/launch_style.cpp index ce00647ce8..6b589138c0 100644 --- a/src/deluge/gui/context_menu/clip_settings/launch_style.cpp +++ b/src/deluge/gui/context_menu/clip_settings/launch_style.cpp @@ -14,19 +14,19 @@ constexpr size_t kNumValues = 3; LaunchStyleMenu launchStyle{}; -char const* LaunchStyleMenu::getTitle() { - static char const* title = "Clip Mode"; +std::string_view LaunchStyleMenu::getTitle() { + static std::string_view title = "Clip Mode"; return title; } -Sized LaunchStyleMenu::getOptions() { +Sized LaunchStyleMenu::getOptions() { using enum l10n::String; - static const char* optionsls[] = { + static std::string_view options[] = { l10n::get(STRING_FOR_DEFAULT_LAUNCH), l10n::get(STRING_FOR_FILL_LAUNCH), l10n::get(STRING_FOR_ONCE_LAUNCH), }; - return {optionsls, kNumValues}; + return {options, kNumValues}; } bool LaunchStyleMenu::setupAndCheckAvailability() { diff --git a/src/deluge/gui/context_menu/clip_settings/launch_style.h b/src/deluge/gui/context_menu/clip_settings/launch_style.h index a9f994a37d..1eebf14de8 100644 --- a/src/deluge/gui/context_menu/clip_settings/launch_style.h +++ b/src/deluge/gui/context_menu/clip_settings/launch_style.h @@ -24,10 +24,10 @@ class LaunchStyleMenu final : public ContextMenu { Clip* clip = nullptr; /// Title - char const* getTitle() override; + std::string_view getTitle() override; /// Options - Sized getOptions() override; + Sized getOptions() override; }; extern LaunchStyleMenu launchStyle; diff --git a/src/deluge/gui/context_menu/clip_settings/new_clip_type.cpp b/src/deluge/gui/context_menu/clip_settings/new_clip_type.cpp index e251f173fa..277f31d0c3 100644 --- a/src/deluge/gui/context_menu/clip_settings/new_clip_type.cpp +++ b/src/deluge/gui/context_menu/clip_settings/new_clip_type.cpp @@ -16,21 +16,21 @@ constexpr size_t kNumValues = 5; NewClipType newClipType{}; -char const* NewClipType::getTitle() { - static char const* title = "New Clip Type"; +std::string_view NewClipType::getTitle() { + static std::string_view title = "New Clip Type"; return title; } -Sized NewClipType::getOptions() { +Sized NewClipType::getOptions() { using enum l10n::String; - static const char* optionsls[] = { + static std::string_view options[] = { "Audio", // audio "Synth", // synth "Kit", // kit "MIDI", // midi "CV", // cv }; - return {optionsls, kNumValues}; + return {options, kNumValues}; } bool NewClipType::setupAndCheckAvailability() { diff --git a/src/deluge/gui/context_menu/clip_settings/new_clip_type.h b/src/deluge/gui/context_menu/clip_settings/new_clip_type.h index d7974215a3..ca407d5897 100644 --- a/src/deluge/gui/context_menu/clip_settings/new_clip_type.h +++ b/src/deluge/gui/context_menu/clip_settings/new_clip_type.h @@ -33,10 +33,10 @@ class NewClipType final : public ContextMenu { OutputType toCreate = OutputType::NONE; /// Title - char const* getTitle() override; + std::string_view getTitle() override; /// Options - Sized getOptions() override; + Sized getOptions() override; ActionResult padAction(int32_t x, int32_t y, int32_t on) override; }; diff --git a/src/deluge/gui/context_menu/configure_song_macros.cpp b/src/deluge/gui/context_menu/configure_song_macros.cpp index 557046d3c9..e763123552 100644 --- a/src/deluge/gui/context_menu/configure_song_macros.cpp +++ b/src/deluge/gui/context_menu/configure_song_macros.cpp @@ -22,6 +22,7 @@ #include "gui/views/session_view.h" #include "hid/display/display.h" #include "model/song/song.h" +#include extern "C" { #include "fatfs/ff.h" @@ -37,20 +38,20 @@ bool ConfigureSongMacros::getGreyoutColsAndRows(uint32_t* cols, uint32_t* rows) return true; } -char const* ConfigureSongMacros::getTitle() { +std::string_view ConfigureSongMacros::getTitle() { using enum l10n::String; return l10n::get(STRING_FOR_CONFIGURE_SONG_MACROS_SHORT); } -Sized ConfigureSongMacros::getOptions() { +Sized ConfigureSongMacros::getOptions() { using enum l10n::String; if (display->haveOLED()) { - static char const* options[] = {l10n::get(STRING_FOR_CONFIGURE_SONG_MACROS_EXIT)}; + static std::string_view options[] = {l10n::get(STRING_FOR_CONFIGURE_SONG_MACROS_EXIT)}; return {options, 1}; } else { - static char const* options[] = {l10n::get(STRING_FOR_CONFIGURE_SONG_MACROS_EXIT)}; + static std::string_view options[] = {l10n::get(STRING_FOR_CONFIGURE_SONG_MACROS_EXIT)}; return {options, 1}; } } @@ -99,7 +100,7 @@ void ConfigureSongMacros::renderOLED(deluge::hid::display::oled_canvas::Canvas& ContextMenu::renderOLED(canvas); if (sessionView.selectedMacro != -1) { - const char* macroKind = + std::string_view macroKind = sessionView.getMacroKindString(currentSong->sessionMacros[sessionView.selectedMacro].kind); int32_t windowHeight = 40; int32_t windowMinY = (OLED_MAIN_HEIGHT_PIXELS - windowHeight) >> 1; diff --git a/src/deluge/gui/context_menu/configure_song_macros.h b/src/deluge/gui/context_menu/configure_song_macros.h index 1285f25b78..ff458dfa6c 100644 --- a/src/deluge/gui/context_menu/configure_song_macros.h +++ b/src/deluge/gui/context_menu/configure_song_macros.h @@ -24,8 +24,8 @@ class ConfigureSongMacros final : public ContextMenu { public: ConfigureSongMacros() = default; - char const* getTitle() override; - Sized getOptions() override; + std::string_view getTitle() override; + Sized getOptions() override; bool setupAndCheckAvailability(); bool acceptCurrentOption() override; bool canSeeViewUnderneath() override { return true; } diff --git a/src/deluge/gui/context_menu/context_menu.h b/src/deluge/gui/context_menu/context_menu.h index 4c2aad21e1..e84b833e7b 100644 --- a/src/deluge/gui/context_menu/context_menu.h +++ b/src/deluge/gui/context_menu/context_menu.h @@ -37,7 +37,7 @@ class ContextMenu : public UI { virtual bool isCurrentOptionAvailable() { return true; } virtual bool acceptCurrentOption() { return false; } // If returns false, will cause UI to exit - virtual Sized getOptions() = 0; + virtual Sized getOptions() = 0; bool getGreyoutColsAndRows(uint32_t* cols, uint32_t* rows) override; ActionResult padAction(int32_t x, int32_t y, int32_t velocity) override; @@ -49,7 +49,7 @@ class ContextMenu : public UI { void renderOLED(deluge::hid::display::oled_canvas::Canvas& canvas) override; int32_t scrollPos = 0; // Don't make static. We'll have multiple nested ContextMenus open at the same time - virtual char const* getTitle() = 0; + virtual std::string_view getTitle() = 0; // UI diff --git a/src/deluge/gui/context_menu/delete_file.cpp b/src/deluge/gui/context_menu/delete_file.cpp index c8c4589cdb..7abbd17eba 100644 --- a/src/deluge/gui/context_menu/delete_file.cpp +++ b/src/deluge/gui/context_menu/delete_file.cpp @@ -21,6 +21,7 @@ #include "gui/l10n/l10n.h" #include "gui/ui/browser/browser.h" #include "hid/display/display.h" +#include extern "C" { #include "fatfs/ff.h" @@ -30,7 +31,7 @@ namespace deluge::gui::context_menu { DeleteFile deleteFile{}; -char const* DeleteFile::getTitle() { +std::string_view DeleteFile::getTitle() { using enum l10n::String; if (getUIUpOneLevel() == &context_menu::saveSongOrInstrument) { return l10n::get(STRING_FOR_ARE_YOU_SURE_QMARK); @@ -38,20 +39,20 @@ char const* DeleteFile::getTitle() { return l10n::get(STRING_FOR_DELETE_QMARK); } -Sized DeleteFile::getOptions() { +Sized DeleteFile::getOptions() { using enum l10n::String; if (display->haveOLED()) { - static char const* options[] = {l10n::get(STRING_FOR_OK)}; + static std::string_view options[] = {l10n::get(STRING_FOR_OK)}; return {options, 1}; } else { if (getUIUpOneLevel() == &context_menu::saveSongOrInstrument) { - static char const* options[] = {l10n::get(STRING_FOR_SURE)}; + static std::string_view options[] = {l10n::get(STRING_FOR_SURE)}; return {options, 1}; } - static char const* options[] = {l10n::get(STRING_FOR_DELETE)}; + static std::string_view options[] = {l10n::get(STRING_FOR_DELETE)}; return {options, 1}; } } @@ -90,7 +91,7 @@ bool DeleteFile::acceptCurrentOption() { else if (toDelete->instrumentAlreadyInSong) { display->displayPopup(l10n::get(STRING_FOR_ERROR_PRESET_IN_USE)); } - else if (toDelete->instrument) { + else if (toDelete->instrument != nullptr) { // it has an instrument, it's not on the card, it's not in use, let's remove it browser->currentFileDeleted(); } diff --git a/src/deluge/gui/context_menu/delete_file.h b/src/deluge/gui/context_menu/delete_file.h index 0efd882c90..00eeb93d87 100644 --- a/src/deluge/gui/context_menu/delete_file.h +++ b/src/deluge/gui/context_menu/delete_file.h @@ -24,10 +24,10 @@ class DeleteFile final : public ContextMenuForSaving { public: DeleteFile() = default; - Sized getOptions() override; + Sized getOptions() override; bool acceptCurrentOption() override; - char const* getTitle() override; + std::string_view getTitle() override; }; extern DeleteFile deleteFile; diff --git a/src/deluge/gui/context_menu/load_instrument_preset.cpp b/src/deluge/gui/context_menu/load_instrument_preset.cpp index 098803ea1e..96d12aeb04 100644 --- a/src/deluge/gui/context_menu/load_instrument_preset.cpp +++ b/src/deluge/gui/context_menu/load_instrument_preset.cpp @@ -24,14 +24,14 @@ namespace deluge::gui::context_menu { LoadInstrumentPreset loadInstrumentPreset{}; -char const* LoadInstrumentPreset::getTitle() { +std::string_view LoadInstrumentPreset::getTitle() { using enum l10n::String; return l10n::get(STRING_FOR_LOAD_PRESET); } -Sized LoadInstrumentPreset::getOptions() { +Sized LoadInstrumentPreset::getOptions() { using enum l10n::String; - static char const* options[] = {l10n::get(STRING_FOR_CLONE)}; + static std::string_view options[] = {l10n::get(STRING_FOR_CLONE)}; return {options, 1}; } diff --git a/src/deluge/gui/context_menu/load_instrument_preset.h b/src/deluge/gui/context_menu/load_instrument_preset.h index c8449c0969..f924ceecef 100644 --- a/src/deluge/gui/context_menu/load_instrument_preset.h +++ b/src/deluge/gui/context_menu/load_instrument_preset.h @@ -23,9 +23,9 @@ namespace deluge::gui::context_menu { class LoadInstrumentPreset final : public ContextMenuForLoading { public: LoadInstrumentPreset() = default; - Sized getOptions() override; + Sized getOptions() override; bool acceptCurrentOption() override; - char const* getTitle() override; + std::string_view getTitle() override; }; extern LoadInstrumentPreset loadInstrumentPreset; diff --git a/src/deluge/gui/context_menu/midi_learn_mode.cpp b/src/deluge/gui/context_menu/midi_learn_mode.cpp index d81c72f690..280ec61303 100644 --- a/src/deluge/gui/context_menu/midi_learn_mode.cpp +++ b/src/deluge/gui/context_menu/midi_learn_mode.cpp @@ -39,20 +39,20 @@ bool MidiLearnMode::getGreyoutColsAndRows(uint32_t* cols, uint32_t* rows) { return true; } -char const* MidiLearnMode::getTitle() { +std::string_view MidiLearnMode::getTitle() { using enum l10n::String; return l10n::get(STRING_FOR_MIDI_LEARN); } -Sized MidiLearnMode::getOptions() { +Sized MidiLearnMode::getOptions() { using enum l10n::String; if (display->haveOLED()) { - static char const* options[] = {l10n::get(STRING_FOR_CONFIGURE_SONG_MACROS_EXIT)}; + static std::string_view options[] = {l10n::get(STRING_FOR_CONFIGURE_SONG_MACROS_EXIT)}; return {options, 1}; } else { - static char const* options[] = {l10n::get(STRING_FOR_CONFIGURE_SONG_MACROS_EXIT)}; + static std::string_view options[] = {l10n::get(STRING_FOR_CONFIGURE_SONG_MACROS_EXIT)}; return {options, 1}; } } diff --git a/src/deluge/gui/context_menu/midi_learn_mode.h b/src/deluge/gui/context_menu/midi_learn_mode.h index c23d631f7a..f209e94aa4 100644 --- a/src/deluge/gui/context_menu/midi_learn_mode.h +++ b/src/deluge/gui/context_menu/midi_learn_mode.h @@ -24,8 +24,8 @@ class MidiLearnMode final : public ContextMenu { public: MidiLearnMode() = default; - char const* getTitle() override; - Sized getOptions() override; + std::string_view getTitle() override; + Sized getOptions() override; bool setupAndCheckAvailability(); bool acceptCurrentOption() override; bool canSeeViewUnderneath() override { return true; } diff --git a/src/deluge/gui/context_menu/overwrite_file.cpp b/src/deluge/gui/context_menu/overwrite_file.cpp index 0a4bbc7613..2858fb024e 100644 --- a/src/deluge/gui/context_menu/overwrite_file.cpp +++ b/src/deluge/gui/context_menu/overwrite_file.cpp @@ -19,24 +19,25 @@ #include "gui/l10n/l10n.h" #include "gui/ui/save/save_ui.h" #include "hid/display/display.h" +#include namespace deluge::gui::context_menu { OverwriteFile overwriteFile{}; -char const* OverwriteFile::getTitle() { +std::string_view OverwriteFile::getTitle() { using enum l10n::String; return l10n::get(STRING_FOR_OVERWRITE_QMARK); } -Sized OverwriteFile::getOptions() { +Sized OverwriteFile::getOptions() { using enum l10n::String; if (display->haveOLED()) { - static char const* options[] = {l10n::get(STRING_FOR_OK)}; - return {options, 1}; + static std::string_view options[] = {l10n::get(STRING_FOR_OK)}; + return {.value = options, .size = 1}; } else { - static char const* options[] = {l10n::get(STRING_FOR_OVERWRITE)}; - return {options, 1}; + static std::string_view options[] = {l10n::get(STRING_FOR_OVERWRITE)}; + return {.value = options, .size = 1}; } } diff --git a/src/deluge/gui/context_menu/overwrite_file.h b/src/deluge/gui/context_menu/overwrite_file.h index 49863795e0..eeae700b8f 100644 --- a/src/deluge/gui/context_menu/overwrite_file.h +++ b/src/deluge/gui/context_menu/overwrite_file.h @@ -26,8 +26,8 @@ class OverwriteFile final : public ContextMenuForSaving { public: OverwriteFile() = default; - char const* getTitle() override; - Sized getOptions() override; + std::string_view getTitle() override; + Sized getOptions() override; bool acceptCurrentOption() override; ActionResult padAction(int32_t x, int32_t y, int32_t on) override; diff --git a/src/deluge/gui/context_menu/sample_browser/kit.cpp b/src/deluge/gui/context_menu/sample_browser/kit.cpp index 5b32ce0e4a..5abab14eb5 100644 --- a/src/deluge/gui/context_menu/sample_browser/kit.cpp +++ b/src/deluge/gui/context_menu/sample_browser/kit.cpp @@ -27,14 +27,14 @@ namespace deluge::gui::context_menu::sample_browser { Kit kit{}; -char const* Kit::getTitle() { +std::string_view Kit::getTitle() { using enum l10n::String; return l10n::get(STRING_FOR_SAMPLES); } -Sized Kit::getOptions() { +Sized Kit::getOptions() { using enum l10n::String; - static char const* options[] = { + static std::string_view options[] = { l10n::get(STRING_FOR_LOAD_ALL), //< l10n::get(STRING_FOR_SLICE) //< }; diff --git a/src/deluge/gui/context_menu/sample_browser/kit.h b/src/deluge/gui/context_menu/sample_browser/kit.h index fdd8e31955..d09d28c3ce 100644 --- a/src/deluge/gui/context_menu/sample_browser/kit.h +++ b/src/deluge/gui/context_menu/sample_browser/kit.h @@ -24,14 +24,14 @@ class Kit final : public ContextMenu { public: Kit() = default; - Sized getOptions() override; + Sized getOptions() override; bool isCurrentOptionAvailable() override; bool canSeeViewUnderneath() override; ActionResult padAction(int32_t x, int32_t y, int32_t velocity) override; bool acceptCurrentOption() override; - char const* getTitle() override; + std::string_view getTitle() override; }; extern Kit kit; diff --git a/src/deluge/gui/context_menu/sample_browser/synth.cpp b/src/deluge/gui/context_menu/sample_browser/synth.cpp index 5724ac6ea4..e2ba281caf 100644 --- a/src/deluge/gui/context_menu/sample_browser/synth.cpp +++ b/src/deluge/gui/context_menu/sample_browser/synth.cpp @@ -29,14 +29,14 @@ namespace deluge::gui::context_menu::sample_browser { Synth synth{}; -char const* Synth::getTitle() { +std::string_view Synth::getTitle() { using enum l10n::String; return l10n::get(STRING_FOR_LOAD_FILES); } -Sized Synth::getOptions() { +Sized Synth::getOptions() { using enum l10n::String; - static char const* options[] = { + static std::string_view options[] = { l10n::get(STRING_FOR_MULTISAMPLES), //< l10n::get(STRING_FOR_BASIC), //< l10n::get(STRING_FOR_SINGLE_CYCLE), //< diff --git a/src/deluge/gui/context_menu/sample_browser/synth.h b/src/deluge/gui/context_menu/sample_browser/synth.h index ff0dde64f6..a9f1e0cb1e 100644 --- a/src/deluge/gui/context_menu/sample_browser/synth.h +++ b/src/deluge/gui/context_menu/sample_browser/synth.h @@ -24,14 +24,14 @@ class Synth final : public ContextMenu { public: Synth() = default; - Sized getOptions() override; + Sized getOptions() override; bool isCurrentOptionAvailable() override; bool canSeeViewUnderneath() override; bool acceptCurrentOption() override; ActionResult padAction(int32_t x, int32_t y, int32_t velocity) override; - char const* getTitle() override; + std::string_view getTitle() override; }; extern Synth synth; diff --git a/src/deluge/gui/context_menu/save_song_or_instrument.cpp b/src/deluge/gui/context_menu/save_song_or_instrument.cpp index 4643d2f6f0..d5948ff7d0 100644 --- a/src/deluge/gui/context_menu/save_song_or_instrument.cpp +++ b/src/deluge/gui/context_menu/save_song_or_instrument.cpp @@ -26,14 +26,14 @@ namespace deluge::gui::context_menu { SaveSongOrInstrument saveSongOrInstrument{}; -char const* SaveSongOrInstrument::getTitle() { +std::string_view SaveSongOrInstrument::getTitle() { using enum l10n::String; return l10n::get(STRING_FOR_OPTIONS); } -Sized SaveSongOrInstrument::getOptions() { +Sized SaveSongOrInstrument::getOptions() { using enum l10n::String; - static char const* options[] = { + static std::string_view options[] = { l10n::get(STRING_FOR_COLLECT_MEDIA), //< l10n::get(STRING_FOR_CREATE_FOLDER), //< l10n::get(STRING_FOR_DELETE) //< diff --git a/src/deluge/gui/context_menu/save_song_or_instrument.h b/src/deluge/gui/context_menu/save_song_or_instrument.h index 87a58cca80..3ec7a87a0a 100644 --- a/src/deluge/gui/context_menu/save_song_or_instrument.h +++ b/src/deluge/gui/context_menu/save_song_or_instrument.h @@ -26,12 +26,12 @@ class SaveSongOrInstrument final : public ContextMenuForSaving { SaveSongOrInstrument() = default; bool acceptCurrentOption() override; - Sized getOptions() override; + Sized getOptions() override; bool isCurrentOptionAvailable() override; ActionResult padAction(int32_t x, int32_t y, int32_t velocity) override; - char const* getTitle() override; + std::string_view getTitle() override; }; extern SaveSongOrInstrument saveSongOrInstrument; diff --git a/src/deluge/gui/context_menu/stem_export/cancel_stem_export.cpp b/src/deluge/gui/context_menu/stem_export/cancel_stem_export.cpp index dff5186d2f..d466f2d67f 100644 --- a/src/deluge/gui/context_menu/stem_export/cancel_stem_export.cpp +++ b/src/deluge/gui/context_menu/stem_export/cancel_stem_export.cpp @@ -29,20 +29,20 @@ namespace deluge::gui::context_menu { CancelStemExport cancelStemExport{}; -char const* CancelStemExport::getTitle() { +std::string_view CancelStemExport::getTitle() { using enum l10n::String; return l10n::get(STRING_FOR_STOP_EXPORT_STEMS_QMARK); } -Sized CancelStemExport::getOptions() { +Sized CancelStemExport::getOptions() { using enum l10n::String; if (display->haveOLED()) { - static char const* options[] = {l10n::get(STRING_FOR_OK)}; + static std::string_view options[] = {l10n::get(STRING_FOR_OK)}; return {options, 1}; } else { - static char const* options[] = {l10n::get(STRING_FOR_SURE)}; + static std::string_view options[] = {l10n::get(STRING_FOR_SURE)}; return {options, 1}; } } diff --git a/src/deluge/gui/context_menu/stem_export/cancel_stem_export.h b/src/deluge/gui/context_menu/stem_export/cancel_stem_export.h index 48a61ffc40..6cebfb92f4 100644 --- a/src/deluge/gui/context_menu/stem_export/cancel_stem_export.h +++ b/src/deluge/gui/context_menu/stem_export/cancel_stem_export.h @@ -24,11 +24,11 @@ class CancelStemExport final : public ContextMenu { public: CancelStemExport() = default; - Sized getOptions() override; + Sized getOptions() override; bool acceptCurrentOption() override; bool canSeeViewUnderneath() override { return true; } - char const* getTitle() override; + std::string_view getTitle() override; }; extern CancelStemExport cancelStemExport; diff --git a/src/deluge/gui/context_menu/stem_export/done_stem_export.cpp b/src/deluge/gui/context_menu/stem_export/done_stem_export.cpp index 8e95581ff5..b6e392bdfc 100644 --- a/src/deluge/gui/context_menu/stem_export/done_stem_export.cpp +++ b/src/deluge/gui/context_menu/stem_export/done_stem_export.cpp @@ -28,20 +28,20 @@ namespace deluge::gui::context_menu { DoneStemExport doneStemExport{}; -char const* DoneStemExport::getTitle() { +std::string_view DoneStemExport::getTitle() { using enum l10n::String; return l10n::get(STRING_FOR_DONE_EXPORT_STEMS); } -Sized DoneStemExport::getOptions() { +Sized DoneStemExport::getOptions() { using enum l10n::String; if (display->haveOLED()) { - static char const* options[] = {l10n::get(STRING_FOR_OK)}; + static std::string_view options[] = {l10n::get(STRING_FOR_OK)}; return {options, 1}; } else { - static char const* options[] = {l10n::get(STRING_FOR_DONE_EXPORT_STEMS)}; + static std::string_view options[] = {l10n::get(STRING_FOR_DONE_EXPORT_STEMS)}; return {options, 1}; } } diff --git a/src/deluge/gui/context_menu/stem_export/done_stem_export.h b/src/deluge/gui/context_menu/stem_export/done_stem_export.h index b4c4a10fd5..b3a9026b06 100644 --- a/src/deluge/gui/context_menu/stem_export/done_stem_export.h +++ b/src/deluge/gui/context_menu/stem_export/done_stem_export.h @@ -24,11 +24,11 @@ class DoneStemExport final : public ContextMenu { public: DoneStemExport() = default; - Sized getOptions() override; + Sized getOptions() override; bool acceptCurrentOption() override; bool canSeeViewUnderneath() override { return true; } - char const* getTitle() override; + std::string_view getTitle() override; }; extern DoneStemExport doneStemExport; diff --git a/src/deluge/gui/l10n/l10n.cpp b/src/deluge/gui/l10n/l10n.cpp index 5b74178d4c..f3fa1f824d 100644 --- a/src/deluge/gui/l10n/l10n.cpp +++ b/src/deluge/gui/l10n/l10n.cpp @@ -5,29 +5,29 @@ namespace deluge::l10n { Language const* chosenLanguage = nullptr; -std::string_view getView(const deluge::l10n::Language& language, deluge::l10n::String string) { +std::string_view get(const deluge::l10n::Language& language, deluge::l10n::String string) { auto string_opt = language.get(string); if (string_opt.has_value()) { return string_opt.value(); } if (language.hasFallback()) { - return getView(language.fallback(), string); + return get(language.fallback(), string); } return built_in::english.get(deluge::l10n::String::EMPTY_STRING).value(); // EMPTY_STRING } -std::string_view getView(deluge::l10n::String string) { - return getView(*chosenLanguage, string); +std::string_view get(deluge::l10n::String string) { + return get(*chosenLanguage, string); } -const char* get(const Language& language, deluge::l10n::String string) { - return getView(language, string).data(); +const char* getRaw(const Language& language, deluge::l10n::String string) { + return get(language, string).data(); } -const char* get(deluge::l10n::String string) { - return getView(string).data(); +const char* getRaw(deluge::l10n::String string) { + return get(string).data(); } } // namespace deluge::l10n @@ -43,6 +43,6 @@ const size_t l10n_STRING_FOR_USB_DEVICE_NOT_RECOGNIZED = util::to_underlying(deluge::l10n::String::STRING_FOR_USB_DEVICE_NOT_RECOGNIZED); char const* l10n_get(size_t string) { - return deluge::l10n::get(static_cast(string)); + return deluge::l10n::getRaw(static_cast(string)); } } diff --git a/src/deluge/gui/l10n/l10n.h b/src/deluge/gui/l10n/l10n.h index 63586cdc2a..1a69f25341 100644 --- a/src/deluge/gui/l10n/l10n.h +++ b/src/deluge/gui/l10n/l10n.h @@ -7,8 +7,8 @@ #include namespace deluge::l10n { -std::string_view getView(const deluge::l10n::Language& language, deluge::l10n::String string); -std::string_view getView(deluge::l10n::String string); -const char* get(const deluge::l10n::Language& language, deluge::l10n::String string); -const char* get(deluge::l10n::String string); +std::string_view get(const deluge::l10n::Language& language, deluge::l10n::String string); +std::string_view get(deluge::l10n::String string); +const char* getRaw(const deluge::l10n::Language& language, deluge::l10n::String string); +const char* getRaw(deluge::l10n::String string); } // namespace deluge::l10n diff --git a/src/deluge/gui/menu_item/arpeggiator/chord_type.h b/src/deluge/gui/menu_item/arpeggiator/chord_type.h index 45145f6de1..4dfabc2130 100644 --- a/src/deluge/gui/menu_item/arpeggiator/chord_type.h +++ b/src/deluge/gui/menu_item/arpeggiator/chord_type.h @@ -42,15 +42,15 @@ class ChordType : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_NONE), //< - l10n::getView(STRING_FOR_FIFTH), //< - l10n::getView(STRING_FOR_SUS2), //< - l10n::getView(STRING_FOR_MINOR), //< - l10n::getView(STRING_FOR_MAJOR), //< - l10n::getView(STRING_FOR_SUS4), //< - l10n::getView(STRING_FOR_MINOR7), //< - l10n::getView(STRING_FOR_DOMINANT7), //< - l10n::getView(STRING_FOR_MAJOR7), //< + l10n::get(STRING_FOR_NONE), //< + l10n::get(STRING_FOR_FIFTH), //< + l10n::get(STRING_FOR_SUS2), //< + l10n::get(STRING_FOR_MINOR), //< + l10n::get(STRING_FOR_MAJOR), //< + l10n::get(STRING_FOR_SUS4), //< + l10n::get(STRING_FOR_MINOR7), //< + l10n::get(STRING_FOR_DOMINANT7), //< + l10n::get(STRING_FOR_MAJOR7), //< }; } }; diff --git a/src/deluge/gui/menu_item/arpeggiator/mode.h b/src/deluge/gui/menu_item/arpeggiator/mode.h index 4a0190b8a3..cd631f339f 100644 --- a/src/deluge/gui/menu_item/arpeggiator/mode.h +++ b/src/deluge/gui/menu_item/arpeggiator/mode.h @@ -66,8 +66,8 @@ class Mode final : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_OFF), //< - l10n::getView(STRING_FOR_ARP), //< + l10n::get(STRING_FOR_OFF), //< + l10n::get(STRING_FOR_ARP), //< }; } diff --git a/src/deluge/gui/menu_item/arpeggiator/mpe_velocity.h b/src/deluge/gui/menu_item/arpeggiator/mpe_velocity.h index bd56440618..8b0a23e03e 100644 --- a/src/deluge/gui/menu_item/arpeggiator/mpe_velocity.h +++ b/src/deluge/gui/menu_item/arpeggiator/mpe_velocity.h @@ -34,9 +34,9 @@ class ArpMpeVelocity final : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_DISABLED), //< - l10n::getView(STRING_FOR_PATCH_SOURCE_AFTERTOUCH), //< - l10n::getView(STRING_FOR_PATCH_SOURCE_Y), //< + l10n::get(STRING_FOR_DISABLED), //< + l10n::get(STRING_FOR_PATCH_SOURCE_AFTERTOUCH), //< + l10n::get(STRING_FOR_PATCH_SOURCE_Y), //< }; } }; diff --git a/src/deluge/gui/menu_item/arpeggiator/note_mode.h b/src/deluge/gui/menu_item/arpeggiator/note_mode.h index 4e36445bf8..38544e2696 100644 --- a/src/deluge/gui/menu_item/arpeggiator/note_mode.h +++ b/src/deluge/gui/menu_item/arpeggiator/note_mode.h @@ -39,11 +39,11 @@ class NoteMode : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_UP), //< - l10n::getView(STRING_FOR_DOWN), //< - l10n::getView(STRING_FOR_UP_DOWN), //< - l10n::getView(STRING_FOR_AS_PLAYED), //< - l10n::getView(STRING_FOR_RANDOM), //< + l10n::get(STRING_FOR_UP), //< + l10n::get(STRING_FOR_DOWN), //< + l10n::get(STRING_FOR_UP_DOWN), //< + l10n::get(STRING_FOR_AS_PLAYED), //< + l10n::get(STRING_FOR_RANDOM), //< }; } }; diff --git a/src/deluge/gui/menu_item/arpeggiator/octave_mode.h b/src/deluge/gui/menu_item/arpeggiator/octave_mode.h index a456475157..8d3404defa 100644 --- a/src/deluge/gui/menu_item/arpeggiator/octave_mode.h +++ b/src/deluge/gui/menu_item/arpeggiator/octave_mode.h @@ -39,11 +39,11 @@ class OctaveMode : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_UP), //< - l10n::getView(STRING_FOR_DOWN), //< - l10n::getView(STRING_FOR_UP_DOWN), //< - l10n::getView(STRING_FOR_ALTERNATE), //< - l10n::getView(STRING_FOR_RANDOM), //< + l10n::get(STRING_FOR_UP), //< + l10n::get(STRING_FOR_DOWN), //< + l10n::get(STRING_FOR_UP_DOWN), //< + l10n::get(STRING_FOR_ALTERNATE), //< + l10n::get(STRING_FOR_RANDOM), //< }; } }; diff --git a/src/deluge/gui/menu_item/arpeggiator/preset_mode.h b/src/deluge/gui/menu_item/arpeggiator/preset_mode.h index 63e1e41fd7..49784d5bc8 100644 --- a/src/deluge/gui/menu_item/arpeggiator/preset_mode.h +++ b/src/deluge/gui/menu_item/arpeggiator/preset_mode.h @@ -70,12 +70,12 @@ class PresetMode final : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_OFF), //< - l10n::getView(STRING_FOR_UP), //< - l10n::getView(STRING_FOR_DOWN), //< - l10n::getView(STRING_FOR_BOTH), //< - l10n::getView(STRING_FOR_RANDOM), //< - l10n::getView(STRING_FOR_CUSTOM), //< + l10n::get(STRING_FOR_OFF), //< + l10n::get(STRING_FOR_UP), //< + l10n::get(STRING_FOR_DOWN), //< + l10n::get(STRING_FOR_BOTH), //< + l10n::get(STRING_FOR_RANDOM), //< + l10n::get(STRING_FOR_CUSTOM), //< }; } diff --git a/src/deluge/gui/menu_item/arpeggiator/randomizer_lock.h b/src/deluge/gui/menu_item/arpeggiator/randomizer_lock.h index f1e1341e96..4921269c86 100644 --- a/src/deluge/gui/menu_item/arpeggiator/randomizer_lock.h +++ b/src/deluge/gui/menu_item/arpeggiator/randomizer_lock.h @@ -34,8 +34,8 @@ class RandomizerLock final : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_DISABLED), //< - l10n::getView(STRING_FOR_ENABLED), //< + l10n::get(STRING_FOR_DISABLED), //< + l10n::get(STRING_FOR_ENABLED), //< }; } diff --git a/src/deluge/gui/menu_item/audio_interpolation.h b/src/deluge/gui/menu_item/audio_interpolation.h index 1f133462be..d1be73cbaa 100644 --- a/src/deluge/gui/menu_item/audio_interpolation.h +++ b/src/deluge/gui/menu_item/audio_interpolation.h @@ -18,7 +18,7 @@ class AudioInterpolation : public Selection { } deluge::vector getOptions() override { - return {l10n::getView(l10n::String::STRING_FOR_LINEAR), l10n::getView(l10n::String::STRING_FOR_SINC)}; + return {l10n::get(l10n::String::STRING_FOR_LINEAR), l10n::get(l10n::String::STRING_FOR_SINC)}; } }; diff --git a/src/deluge/gui/menu_item/colour.h b/src/deluge/gui/menu_item/colour.h index 4d087ec10c..386d98b450 100644 --- a/src/deluge/gui/menu_item/colour.h +++ b/src/deluge/gui/menu_item/colour.h @@ -43,11 +43,11 @@ class Colour final : public Selection { }; deluge::vector getOptions() override { return { - l10n::getView(l10n::String::STRING_FOR_RED), l10n::getView(l10n::String::STRING_FOR_GREEN), - l10n::getView(l10n::String::STRING_FOR_BLUE), l10n::getView(l10n::String::STRING_FOR_YELLOW), - l10n::getView(l10n::String::STRING_FOR_CYAN), l10n::getView(l10n::String::STRING_FOR_MAGENTA), - l10n::getView(l10n::String::STRING_FOR_AMBER), l10n::getView(l10n::String::STRING_FOR_WHITE), - l10n::getView(l10n::String::STRING_FOR_PINK), + l10n::get(l10n::String::STRING_FOR_RED), l10n::get(l10n::String::STRING_FOR_GREEN), + l10n::get(l10n::String::STRING_FOR_BLUE), l10n::get(l10n::String::STRING_FOR_YELLOW), + l10n::get(l10n::String::STRING_FOR_CYAN), l10n::get(l10n::String::STRING_FOR_MAGENTA), + l10n::get(l10n::String::STRING_FOR_AMBER), l10n::get(l10n::String::STRING_FOR_WHITE), + l10n::get(l10n::String::STRING_FOR_PINK), }; } [[nodiscard]] RGB getRGB() const; diff --git a/src/deluge/gui/menu_item/cv/cv2Mapping.h b/src/deluge/gui/menu_item/cv/cv2Mapping.h index f0cfccfb77..7a3caa93d7 100644 --- a/src/deluge/gui/menu_item/cv/cv2Mapping.h +++ b/src/deluge/gui/menu_item/cv/cv2Mapping.h @@ -48,10 +48,10 @@ class DualCVSelection final : public menu_item::Selection { deluge::vector getOptions() override { using enum l10n::String; - static auto o = l10n::getView(STRING_FOR_OFF); - static auto y = l10n::getView(STRING_FOR_PATCH_SOURCE_Y); - static auto a = l10n::getView(STRING_FOR_PATCH_SOURCE_AFTERTOUCH); - static auto v = l10n::getView(STRING_FOR_VELOCITY); + static auto o = l10n::get(STRING_FOR_OFF); + static auto y = l10n::get(STRING_FOR_PATCH_SOURCE_Y); + static auto a = l10n::get(STRING_FOR_PATCH_SOURCE_AFTERTOUCH); + static auto v = l10n::get(STRING_FOR_VELOCITY); return {o, y, a, v}; } diff --git a/src/deluge/gui/menu_item/cv/selection.h b/src/deluge/gui/menu_item/cv/selection.h index 1b0677a0f8..f5ec10422b 100644 --- a/src/deluge/gui/menu_item/cv/selection.h +++ b/src/deluge/gui/menu_item/cv/selection.h @@ -46,8 +46,8 @@ class Selection final : public menu_item::Selection { deluge::vector getOptions() override { using enum l10n::String; - static auto cv1 = l10n::getView(STRING_FOR_CV_OUTPUT_1); - static auto cv2 = l10n::getView(STRING_FOR_CV_OUTPUT_2); + static auto cv1 = l10n::get(STRING_FOR_CV_OUTPUT_1); + static auto cv2 = l10n::get(STRING_FOR_CV_OUTPUT_2); return {cv1, cv2}; } diff --git a/src/deluge/gui/menu_item/defaults/grid_default_active_mode.h b/src/deluge/gui/menu_item/defaults/grid_default_active_mode.h index 99943280ff..5176fac99c 100644 --- a/src/deluge/gui/menu_item/defaults/grid_default_active_mode.h +++ b/src/deluge/gui/menu_item/defaults/grid_default_active_mode.h @@ -29,9 +29,9 @@ class DefaultGridDefaultActiveMode final : public Selection { void writeCurrentValue() override { FlashStorage::defaultGridActiveMode = this->getValue(); } deluge::vector getOptions() override { return { - l10n::getView(l10n::String::STRING_FOR_DEFAULT_UI_DEFAULT_GRID_ACTIVE_MODE_SELECTION), - l10n::getView(l10n::String::STRING_FOR_GREEN), - l10n::getView(l10n::String::STRING_FOR_BLUE), + l10n::get(l10n::String::STRING_FOR_DEFAULT_UI_DEFAULT_GRID_ACTIVE_MODE_SELECTION), + l10n::get(l10n::String::STRING_FOR_GREEN), + l10n::get(l10n::String::STRING_FOR_BLUE), }; } }; diff --git a/src/deluge/gui/menu_item/defaults/keyboard_layout.h b/src/deluge/gui/menu_item/defaults/keyboard_layout.h index 91c2020042..7b05d6373c 100644 --- a/src/deluge/gui/menu_item/defaults/keyboard_layout.h +++ b/src/deluge/gui/menu_item/defaults/keyboard_layout.h @@ -29,9 +29,9 @@ class KeyboardLayout final : public Selection { void writeCurrentValue() override { FlashStorage::defaultKeyboardLayout = this->getValue(); } deluge::vector getOptions() override { return { - l10n::getView(l10n::String::STRING_FOR_DEFAULT_UI_KEYBOARD_LAYOUT_ISOMORPHIC), - l10n::getView(l10n::String::STRING_FOR_DEFAULT_UI_KEYBOARD_LAYOUT_INKEY), - l10n::getView(l10n::String::STRING_FOR_DEFAULT_UI_KEYBOARD_LAYOUT_PIANO), + l10n::get(l10n::String::STRING_FOR_DEFAULT_UI_KEYBOARD_LAYOUT_ISOMORPHIC), + l10n::get(l10n::String::STRING_FOR_DEFAULT_UI_KEYBOARD_LAYOUT_INKEY), + l10n::get(l10n::String::STRING_FOR_DEFAULT_UI_KEYBOARD_LAYOUT_PIANO), }; } }; diff --git a/src/deluge/gui/menu_item/defaults/session_layout.h b/src/deluge/gui/menu_item/defaults/session_layout.h index 6cde3df451..0ae4e7a964 100644 --- a/src/deluge/gui/menu_item/defaults/session_layout.h +++ b/src/deluge/gui/menu_item/defaults/session_layout.h @@ -28,8 +28,8 @@ class SessionLayout final : public Selection { void readCurrentValue() override { this->setValue(FlashStorage::defaultSessionLayout); } void writeCurrentValue() override { FlashStorage::defaultSessionLayout = this->getValue(); } deluge::vector getOptions() override { - return {l10n::getView(l10n::String::STRING_FOR_DEFAULT_UI_SONG_LAYOUT_ROWS), - l10n::getView(l10n::String::STRING_FOR_DEFAULT_UI_GRID)}; + return {l10n::get(l10n::String::STRING_FOR_DEFAULT_UI_SONG_LAYOUT_ROWS), + l10n::get(l10n::String::STRING_FOR_DEFAULT_UI_GRID)}; } }; } // namespace deluge::gui::menu_item::defaults diff --git a/src/deluge/gui/menu_item/defaults/slice_mode.h b/src/deluge/gui/menu_item/defaults/slice_mode.h index 5e884ccc3b..84b7b40808 100644 --- a/src/deluge/gui/menu_item/defaults/slice_mode.h +++ b/src/deluge/gui/menu_item/defaults/slice_mode.h @@ -29,10 +29,10 @@ class SliceMode final : public Selection { void writeCurrentValue() override { FlashStorage::defaultSliceMode = this->getValue(); } deluge::vector getOptions() override { return { - l10n::getView(l10n::String::STRING_FOR_CUT), - l10n::getView(l10n::String::STRING_FOR_ONCE), - l10n::getView(l10n::String::STRING_FOR_LOOP), - l10n::getView(l10n::String::STRING_FOR_STRETCH), + l10n::get(l10n::String::STRING_FOR_CUT), + l10n::get(l10n::String::STRING_FOR_ONCE), + l10n::get(l10n::String::STRING_FOR_LOOP), + l10n::get(l10n::String::STRING_FOR_STRETCH), }; } diff --git a/src/deluge/gui/menu_item/defaults/startup_song_mode.h b/src/deluge/gui/menu_item/defaults/startup_song_mode.h index b894c8c0f4..928483f8c6 100644 --- a/src/deluge/gui/menu_item/defaults/startup_song_mode.h +++ b/src/deluge/gui/menu_item/defaults/startup_song_mode.h @@ -28,10 +28,10 @@ class StartupSongModeMenu final : public Selection { void readCurrentValue() override { this->setValue(FlashStorage::defaultStartupSongMode); } void writeCurrentValue() override { FlashStorage::defaultStartupSongMode = this->getValue(); } deluge::vector getOptions() override { - return {l10n::getView(l10n::String::STRING_FOR_DEFAULT_UI_DEFAULT_STARTUP_SONG_MODE_BLANK), - l10n::getView(l10n::String::STRING_FOR_DEFAULT_UI_DEFAULT_STARTUP_SONG_MODE_TEMPLATE), - l10n::getView(l10n::String::STRING_FOR_DEFAULT_UI_DEFAULT_STARTUP_SONG_MODE_LAST_OPENED), - l10n::getView(l10n::String::STRING_FOR_DEFAULT_UI_DEFAULT_STARTUP_SONG_MODE_LAST_SAVED)}; + return {l10n::get(l10n::String::STRING_FOR_DEFAULT_UI_DEFAULT_STARTUP_SONG_MODE_BLANK), + l10n::get(l10n::String::STRING_FOR_DEFAULT_UI_DEFAULT_STARTUP_SONG_MODE_TEMPLATE), + l10n::get(l10n::String::STRING_FOR_DEFAULT_UI_DEFAULT_STARTUP_SONG_MODE_LAST_OPENED), + l10n::get(l10n::String::STRING_FOR_DEFAULT_UI_DEFAULT_STARTUP_SONG_MODE_LAST_SAVED)}; } }; } // namespace deluge::gui::menu_item::defaults diff --git a/src/deluge/gui/menu_item/delay/analog.h b/src/deluge/gui/menu_item/delay/analog.h index c44d42015b..7ad9288511 100644 --- a/src/deluge/gui/menu_item/delay/analog.h +++ b/src/deluge/gui/menu_item/delay/analog.h @@ -29,7 +29,7 @@ class Analog final : public Selection { void writeCurrentValue() override { soundEditor.currentModControllable->delay.analog = this->getValue(); } deluge::vector getOptions() override { using enum l10n::String; - return {l10n::getView(STRING_FOR_DIGITAL), l10n::getView(STRING_FOR_ANALOG)}; + return {l10n::get(STRING_FOR_DIGITAL), l10n::get(STRING_FOR_ANALOG)}; } }; diff --git a/src/deluge/gui/menu_item/filter/info.h b/src/deluge/gui/menu_item/filter/info.h index 110f295f7c..d3e90b206f 100644 --- a/src/deluge/gui/menu_item/filter/info.h +++ b/src/deluge/gui/menu_item/filter/info.h @@ -76,7 +76,7 @@ class FilterInfo { if (type == FilterParamType::MORPH) { using enum l10n::String; auto filt = deluge::dsp::filter::SpecificFilter(getMode()); - return l10n::getView(filt.getMorphName()); + return l10n::get(filt.getMorphName()); } else { return alt; diff --git a/src/deluge/gui/menu_item/filter/mode.h b/src/deluge/gui/menu_item/filter/mode.h index aaa556f133..e5712edf0e 100644 --- a/src/deluge/gui/menu_item/filter/mode.h +++ b/src/deluge/gui/menu_item/filter/mode.h @@ -43,17 +43,16 @@ class FilterModeSelection final : public Selection { using enum l10n::String; if (info.getSlot() == FilterSlot::HPF) { return { - l10n::getView(STRING_FOR_SVF_BAND), - l10n::getView(STRING_FOR_SVF_NOTCH), - l10n::getView(STRING_FOR_HPLADDER), - l10n::getView(STRING_FOR_OFF), + l10n::get(STRING_FOR_SVF_BAND), + l10n::get(STRING_FOR_SVF_NOTCH), + l10n::get(STRING_FOR_HPLADDER), + l10n::get(STRING_FOR_OFF), }; } else { return { - l10n::getView(STRING_FOR_12DB_LADDER), l10n::getView(STRING_FOR_24DB_LADDER), - l10n::getView(STRING_FOR_DRIVE), l10n::getView(STRING_FOR_SVF_BAND), - l10n::getView(STRING_FOR_SVF_NOTCH), l10n::getView(STRING_FOR_OFF), + l10n::get(STRING_FOR_12DB_LADDER), l10n::get(STRING_FOR_24DB_LADDER), l10n::get(STRING_FOR_DRIVE), + l10n::get(STRING_FOR_SVF_BAND), l10n::get(STRING_FOR_SVF_NOTCH), l10n::get(STRING_FOR_OFF), }; } } @@ -61,17 +60,17 @@ class FilterModeSelection final : public Selection { using enum l10n::String; if (info.getSlot() == FilterSlot::HPF) { return { - l10n::getView(STRING_FOR_SVF_BAND_SHORT), - l10n::getView(STRING_FOR_SVF_NOTCH_SHORT), - l10n::getView(STRING_FOR_12DB_LADDER_SHORT), - l10n::getView(STRING_FOR_OFF), + l10n::get(STRING_FOR_SVF_BAND_SHORT), + l10n::get(STRING_FOR_SVF_NOTCH_SHORT), + l10n::get(STRING_FOR_12DB_LADDER_SHORT), + l10n::get(STRING_FOR_OFF), }; } else { return { - l10n::getView(STRING_FOR_12DB_LADDER_SHORT), l10n::getView(STRING_FOR_24DB_LADDER_SHORT), - l10n::getView(STRING_FOR_DRIVE_SHORT), l10n::getView(STRING_FOR_SVF_BAND_SHORT), - l10n::getView(STRING_FOR_SVF_NOTCH_SHORT), l10n::getView(STRING_FOR_OFF), + l10n::get(STRING_FOR_12DB_LADDER_SHORT), l10n::get(STRING_FOR_24DB_LADDER_SHORT), + l10n::get(STRING_FOR_DRIVE_SHORT), l10n::get(STRING_FOR_SVF_BAND_SHORT), + l10n::get(STRING_FOR_SVF_NOTCH_SHORT), l10n::get(STRING_FOR_OFF), }; } } diff --git a/src/deluge/gui/menu_item/filter_route.h b/src/deluge/gui/menu_item/filter_route.h index d84ef17654..da0ec1943b 100644 --- a/src/deluge/gui/menu_item/filter_route.h +++ b/src/deluge/gui/menu_item/filter_route.h @@ -30,7 +30,7 @@ class FilterRouting final : public Selection { soundEditor.currentModControllable->filterRoute = this->getValue<::FilterRoute>(); } deluge::vector getOptions() override { - return {"HPF2LPF", "LPF2HPF", l10n::getView(l10n::String::STRING_FOR_PARALLEL)}; + return {"HPF2LPF", "LPF2HPF", l10n::get(l10n::String::STRING_FOR_PARALLEL)}; } bool isRelevant(ModControllableAudio* modControllable, int32_t whichThing) override { Sound* sound = static_cast(modControllable); diff --git a/src/deluge/gui/menu_item/flash/status.h b/src/deluge/gui/menu_item/flash/status.h index b99f05ca7a..9751493a8c 100644 --- a/src/deluge/gui/menu_item/flash/status.h +++ b/src/deluge/gui/menu_item/flash/status.h @@ -33,9 +33,9 @@ class Status final : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_FAST), - l10n::getView(STRING_FOR_DISABLED), - l10n::getView(STRING_FOR_SLOW), + l10n::get(STRING_FOR_FAST), + l10n::get(STRING_FOR_DISABLED), + l10n::get(STRING_FOR_SLOW), }; } }; diff --git a/src/deluge/gui/menu_item/gate/mode.h b/src/deluge/gui/menu_item/gate/mode.h index 22839eb15d..ba13efd8ab 100644 --- a/src/deluge/gui/menu_item/gate/mode.h +++ b/src/deluge/gui/menu_item/gate/mode.h @@ -43,7 +43,7 @@ class Mode final : public Selection, public FormattedTitle { deluge::vector getOptions() override { deluge::vector output; for (l10n::String str : options_) { - output.push_back(l10n::getView(str)); + output.push_back(l10n::get(str)); } return output; } diff --git a/src/deluge/gui/menu_item/gate/selection.h b/src/deluge/gui/menu_item/gate/selection.h index d27d0f395d..e36caf6002 100644 --- a/src/deluge/gui/menu_item/gate/selection.h +++ b/src/deluge/gui/menu_item/gate/selection.h @@ -57,17 +57,17 @@ class Selection final : public menu_item::Selection { deluge::vector getOptions() override { using enum l10n::String; - static auto out1 = l10n::getView(STRING_FOR_GATE_OUTPUT_1); - static auto out2 = l10n::getView(STRING_FOR_GATE_OUTPUT_2); - static auto out3 = l10n::getView(STRING_FOR_GATE_OUTPUT_3); - static auto out4 = l10n::getView(STRING_FOR_GATE_OUTPUT_4); + static auto out1 = l10n::get(STRING_FOR_GATE_OUTPUT_1); + static auto out2 = l10n::get(STRING_FOR_GATE_OUTPUT_2); + static auto out3 = l10n::get(STRING_FOR_GATE_OUTPUT_3); + static auto out4 = l10n::get(STRING_FOR_GATE_OUTPUT_4); return { - out1, //< - out2, //< - out3, //< - out4, //< - l10n::getView(STRING_FOR_MINIMUM_OFF_TIME), //< + out1, //< + out2, //< + out3, //< + out4, //< + l10n::get(STRING_FOR_MINIMUM_OFF_TIME), //< }; } }; diff --git a/src/deluge/gui/menu_item/lfo/shape.h b/src/deluge/gui/menu_item/lfo/shape.h index daf77b24cd..aef43bbc2c 100644 --- a/src/deluge/gui/menu_item/lfo/shape.h +++ b/src/deluge/gui/menu_item/lfo/shape.h @@ -27,13 +27,9 @@ class Shape : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_SINE), - l10n::getView(STRING_FOR_TRIANGLE), - l10n::getView(STRING_FOR_SQUARE), - l10n::getView(STRING_FOR_SAW), - l10n::getView(STRING_FOR_SAMPLE_AND_HOLD), - l10n::getView(STRING_FOR_RANDOM_WALK), - l10n::getView(STRING_FOR_WARBLE), + l10n::get(STRING_FOR_SINE), l10n::get(STRING_FOR_TRIANGLE), l10n::get(STRING_FOR_SQUARE), + l10n::get(STRING_FOR_SAW), l10n::get(STRING_FOR_SAMPLE_AND_HOLD), l10n::get(STRING_FOR_RANDOM_WALK), + l10n::get(STRING_FOR_WARBLE), }; } }; diff --git a/src/deluge/gui/menu_item/menu_item.h b/src/deluge/gui/menu_item/menu_item.h index dfbf9c50d0..f81ca6e63d 100644 --- a/src/deluge/gui/menu_item/menu_item.h +++ b/src/deluge/gui/menu_item/menu_item.h @@ -214,7 +214,7 @@ class MenuItem { /// /// The returned pointer must live long enough for us to draw the title, which for practical purposes means "the /// lifetime of this menu item" - [[nodiscard]] virtual std::string_view getTitle() const { return deluge::l10n::getView(title); } + [[nodiscard]] virtual std::string_view getTitle() const { return deluge::l10n::get(title); } /// @brief Get the "draw dot state". /// @@ -240,7 +240,7 @@ class MenuItem { /// @brief Get the actual name for use on OLED for deluge::gui::menu_item::Submenu s. /// /// By default this is just the l10n string for \ref name, but can be overriden. - [[nodiscard]] virtual std::string_view getName() const { return deluge::l10n::getView(name); } + [[nodiscard]] virtual std::string_view getName() const { return deluge::l10n::get(name); } /// @brief Get the name for use on horizontal menus. /// /// By default this redirects to getName(), but can be overriden. diff --git a/src/deluge/gui/menu_item/midi/command.cpp b/src/deluge/gui/menu_item/midi/command.cpp index 0b168c5ec1..23f6afb04d 100644 --- a/src/deluge/gui/menu_item/midi/command.cpp +++ b/src/deluge/gui/menu_item/midi/command.cpp @@ -25,6 +25,7 @@ #include "util/cfunctions.h" #include "util/misc.h" #include "util/string.h" +#include namespace deluge::gui::menu_item::midi { @@ -43,7 +44,7 @@ void Command::drawPixelsForOled() { kTextSizeYUpdated); } else { - char const* deviceString = l10n::get(l10n::String::STRING_FOR_ANY_MIDI_DEVICE); + std::string_view deviceString = l10n::get(l10n::String::STRING_FOR_ANY_MIDI_DEVICE); if (command->cable) { deviceString = command->cable->getDisplayName(); } @@ -53,7 +54,7 @@ void Command::drawPixelsForOled() { yPixel += kTextSpacingY; - char const* channelText; + std::string_view channelText; if (command->channelOrZone == MIDI_CHANNEL_MPE_LOWER_ZONE) { channelText = l10n::get(l10n::String::STRING_FOR_MPE_LOWER_ZONE); } @@ -92,7 +93,7 @@ void Command::drawPixelsForOled() { } void Command::drawValue() const { - char const* output = nullptr; + std::string_view output; if (!midiEngine.globalMIDICommands[util::to_underlying(commandNumber)].containsSomething()) { output = l10n::get(l10n::String::STRING_FOR_NONE); } diff --git a/src/deluge/gui/menu_item/midi/devices.cpp b/src/deluge/gui/menu_item/midi/devices.cpp index 0e5412df7e..63a61e9a11 100644 --- a/src/deluge/gui/menu_item/midi/devices.cpp +++ b/src/deluge/gui/menu_item/midi/devices.cpp @@ -140,7 +140,7 @@ void Devices::drawValue() { renderUIsForOled(); } else { - char const* displayName = soundEditor.currentMIDICable->getDisplayName(); + std::string_view displayName = soundEditor.currentMIDICable->getDisplayName(); display->setScrollingText(displayName); } } diff --git a/src/deluge/gui/menu_item/midi/follow/follow_channel.h b/src/deluge/gui/menu_item/midi/follow/follow_channel.h index e4050704bf..0c502cfa88 100644 --- a/src/deluge/gui/menu_item/midi/follow/follow_channel.h +++ b/src/deluge/gui/menu_item/midi/follow/follow_channel.h @@ -19,6 +19,7 @@ #include "gui/ui/sound_editor.h" #include "hid/display/oled.h" #include "io/midi/midi_engine.h" +#include class MIDICable; @@ -41,18 +42,15 @@ class FollowChannel final : public Integer { yPixel = 20; - char const* differentiationString; - if (MIDIDeviceManager::differentiatingInputsByDevice) { - differentiationString = l10n::get(l10n::String::STRING_FOR_INPUT_DIFFERENTIATION_ON); - } - else { - differentiationString = l10n::get(l10n::String::STRING_FOR_INPUT_DIFFERENTIATION_OFF); - } + std::string_view differentiationString = (MIDIDeviceManager::differentiatingInputsByDevice) + ? l10n::get(l10n::String::STRING_FOR_INPUT_DIFFERENTIATION_ON) + : l10n::get(l10n::String::STRING_FOR_INPUT_DIFFERENTIATION_OFF); + canvas.drawString(differentiationString, 0, yPixel, kTextSpacingX, kTextSizeYUpdated); yPixel += kTextSpacingY; - char const* deviceString = l10n::get(l10n::String::STRING_FOR_FOLLOW_DEVICE_UNASSIGNED); + std::string_view deviceString = l10n::get(l10n::String::STRING_FOR_FOLLOW_DEVICE_UNASSIGNED); if (midiInput.cable) { deviceString = midiInput.cable->getDisplayName(); } @@ -62,7 +60,7 @@ class FollowChannel final : public Integer { yPixel += kTextSpacingY; - char const* channelText; + std::string_view channelText; if (this->getValue() == MIDI_CHANNEL_MPE_LOWER_ZONE) { channelText = l10n::get(l10n::String::STRING_FOR_MPE_LOWER_ZONE); } diff --git a/src/deluge/gui/menu_item/midi/follow/follow_feedback_automation.h b/src/deluge/gui/menu_item/midi/follow/follow_feedback_automation.h index f565afb4f6..3347f75d40 100644 --- a/src/deluge/gui/menu_item/midi/follow/follow_feedback_automation.h +++ b/src/deluge/gui/menu_item/midi/follow/follow_feedback_automation.h @@ -33,10 +33,10 @@ class FollowFeedbackAutomation final : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_DISABLED), - l10n::getView(STRING_FOR_LOW), - l10n::getView(STRING_FOR_MEDIUM), - l10n::getView(STRING_FOR_HIGH), + l10n::get(STRING_FOR_DISABLED), + l10n::get(STRING_FOR_LOW), + l10n::get(STRING_FOR_MEDIUM), + l10n::get(STRING_FOR_HIGH), }; } }; diff --git a/src/deluge/gui/menu_item/midi/follow/follow_feedback_channel_type.h b/src/deluge/gui/menu_item/midi/follow/follow_feedback_channel_type.h index 81bcea5877..f9e41856a0 100644 --- a/src/deluge/gui/menu_item/midi/follow/follow_feedback_channel_type.h +++ b/src/deluge/gui/menu_item/midi/follow/follow_feedback_channel_type.h @@ -33,10 +33,10 @@ class FollowFeedbackChannelType final : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_FOLLOW_CHANNEL_A), - l10n::getView(STRING_FOR_FOLLOW_CHANNEL_B), - l10n::getView(STRING_FOR_FOLLOW_CHANNEL_C), - l10n::getView(STRING_FOR_NONE), + l10n::get(STRING_FOR_FOLLOW_CHANNEL_A), + l10n::get(STRING_FOR_FOLLOW_CHANNEL_B), + l10n::get(STRING_FOR_FOLLOW_CHANNEL_C), + l10n::get(STRING_FOR_NONE), }; } }; diff --git a/src/deluge/gui/menu_item/midi/preset.h b/src/deluge/gui/menu_item/midi/preset.h index 81fb4d5dcb..e15a38ac07 100644 --- a/src/deluge/gui/menu_item/midi/preset.h +++ b/src/deluge/gui/menu_item/midi/preset.h @@ -22,6 +22,7 @@ #include "model/clip/instrument_clip.h" #include "model/output.h" #include "model/song/song.h" +#include namespace deluge::gui::menu_item::midi { class Preset : public Integer { @@ -33,7 +34,7 @@ class Preset : public Integer { void drawInteger(int32_t textWidth, int32_t textHeight, int32_t yPixel) override { deluge::hid::display::oled_canvas::Canvas& canvas = hid::display::OLED::main; char buffer[12]; - char const* text; + std::string_view text; if (this->getValue() == 128) { text = l10n::get(l10n::String::STRING_FOR_NONE); } diff --git a/src/deluge/gui/menu_item/midi/takeover.h b/src/deluge/gui/menu_item/midi/takeover.h index 49e729b83a..61deeb3eff 100644 --- a/src/deluge/gui/menu_item/midi/takeover.h +++ b/src/deluge/gui/menu_item/midi/takeover.h @@ -29,10 +29,10 @@ class Takeover final : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_JUMP), - l10n::getView(STRING_FOR_PICK_UP), - l10n::getView(STRING_FOR_SCALE), - l10n::getView(STRING_FOR_RELATIVE), + l10n::get(STRING_FOR_JUMP), + l10n::get(STRING_FOR_PICK_UP), + l10n::get(STRING_FOR_SCALE), + l10n::get(STRING_FOR_RELATIVE), }; } }; diff --git a/src/deluge/gui/menu_item/midi/transpose.h b/src/deluge/gui/menu_item/midi/transpose.h index eaac3ec4b4..661e122133 100644 --- a/src/deluge/gui/menu_item/midi/transpose.h +++ b/src/deluge/gui/menu_item/midi/transpose.h @@ -29,8 +29,8 @@ class Transpose final : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_TRANSPOSE_INKEY), - l10n::getView(STRING_FOR_TRANSPOSE_CHROMATIC), + l10n::get(STRING_FOR_TRANSPOSE_INKEY), + l10n::get(STRING_FOR_TRANSPOSE_CHROMATIC), }; } }; diff --git a/src/deluge/gui/menu_item/modulator/destination.h b/src/deluge/gui/menu_item/modulator/destination.h index f858d2b0aa..0ab78dfdfd 100644 --- a/src/deluge/gui/menu_item/modulator/destination.h +++ b/src/deluge/gui/menu_item/modulator/destination.h @@ -28,9 +28,9 @@ class Destination final : public Selection { void writeCurrentValue() override { soundEditor.currentSound->modulator1ToModulator0 = this->getValue(); } deluge::vector getOptions() override { using enum l10n::String; - static auto mod1 = l10n::getView(STRING_FOR_MODULATOR_1); + static auto mod1 = l10n::get(STRING_FOR_MODULATOR_1); return { - l10n::getView(STRING_FOR_CARRIERS), + l10n::get(STRING_FOR_CARRIERS), mod1, }; } diff --git a/src/deluge/gui/menu_item/monitor/mode.h b/src/deluge/gui/menu_item/monitor/mode.h index 98e698ee6b..4212c4b2d4 100644 --- a/src/deluge/gui/menu_item/monitor/mode.h +++ b/src/deluge/gui/menu_item/monitor/mode.h @@ -30,9 +30,9 @@ class Mode final : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_CONDITIONAL), - l10n::getView(STRING_FOR_ENABLED), - l10n::getView(STRING_FOR_DISABLED), + l10n::get(STRING_FOR_CONDITIONAL), + l10n::get(STRING_FOR_ENABLED), + l10n::get(STRING_FOR_DISABLED), }; } }; diff --git a/src/deluge/gui/menu_item/mpe/direction_selector.h b/src/deluge/gui/menu_item/mpe/direction_selector.h index f5e6e310a0..9174b66d9c 100644 --- a/src/deluge/gui/menu_item/mpe/direction_selector.h +++ b/src/deluge/gui/menu_item/mpe/direction_selector.h @@ -29,8 +29,8 @@ class DirectionSelector final : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_IN), - l10n::getView(STRING_FOR_OUT), + l10n::get(STRING_FOR_IN), + l10n::get(STRING_FOR_OUT), }; } void readCurrentValue() override { this->setValue(whichDirection); } @@ -38,8 +38,8 @@ class DirectionSelector final : public Selection { MenuItem* selectButtonPress() override; uint8_t whichDirection; [[nodiscard]] std::string_view getTitle() const override { - return whichDirection ? l10n::getView(l10n::String::STRING_FOR_MPE_OUTPUT) - : l10n::getView(l10n::String::STRING_FOR_MPE_INPUT); + return whichDirection ? l10n::get(l10n::String::STRING_FOR_MPE_OUTPUT) + : l10n::get(l10n::String::STRING_FOR_MPE_INPUT); } }; diff --git a/src/deluge/gui/menu_item/mpe/zone_num_member_channels.h b/src/deluge/gui/menu_item/mpe/zone_num_member_channels.h index c98c171b47..e9aaf6510b 100644 --- a/src/deluge/gui/menu_item/mpe/zone_num_member_channels.h +++ b/src/deluge/gui/menu_item/mpe/zone_num_member_channels.h @@ -32,7 +32,7 @@ class ZoneNumMemberChannels final : public IntegerWithOff { // char nameChars[16]; [[nodiscard]] std::string_view getTitle() const override { - return l10n::getView(l10n::String::STRING_FOR_NUM_MEMBER_CH_MENU_TITLE); + return l10n::get(l10n::String::STRING_FOR_NUM_MEMBER_CH_MENU_TITLE); } private: diff --git a/src/deluge/gui/menu_item/mpe/zone_selector.h b/src/deluge/gui/menu_item/mpe/zone_selector.h index 83186fb13f..f85e5a210b 100644 --- a/src/deluge/gui/menu_item/mpe/zone_selector.h +++ b/src/deluge/gui/menu_item/mpe/zone_selector.h @@ -32,8 +32,8 @@ class ZoneSelector final : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_LOWER_ZONE), - l10n::getView(STRING_FOR_UPPER_ZONE), + l10n::get(STRING_FOR_LOWER_ZONE), + l10n::get(STRING_FOR_UPPER_ZONE), }; } diff --git a/src/deluge/gui/menu_item/multi_range.h b/src/deluge/gui/menu_item/multi_range.h index 249286377a..927439e178 100644 --- a/src/deluge/gui/menu_item/multi_range.h +++ b/src/deluge/gui/menu_item/multi_range.h @@ -39,9 +39,7 @@ class MultiRange final : public Range { bool mayShowJustOne = true) override; bool mayEditRangeEdge(RangeEdit whichEdge) override; - [[nodiscard]] std::string_view getTitle() const override { - return l10n::getView(l10n::String::STRING_FOR_NOTE_RANGE); - }; + [[nodiscard]] std::string_view getTitle() const override { return l10n::get(l10n::String::STRING_FOR_NOTE_RANGE); }; void drawPixelsForOled() override; // NOTE: this isn't strictly speaking needed, but refactoring the selectEncoderAction() and diff --git a/src/deluge/gui/menu_item/osc/type.h b/src/deluge/gui/menu_item/osc/type.h index b5d95686ea..353ce87996 100644 --- a/src/deluge/gui/menu_item/osc/type.h +++ b/src/deluge/gui/menu_item/osc/type.h @@ -78,32 +78,32 @@ class Type final : public Selection, public FormattedTitle { deluge::vector getOptions() override { using enum l10n::String; deluge::vector options = { - l10n::getView(STRING_FOR_SINE), //< - l10n::getView(STRING_FOR_TRIANGLE), //< - l10n::getView(STRING_FOR_SQUARE), //< - l10n::getView(STRING_FOR_ANALOG_SQUARE), //< - l10n::getView(STRING_FOR_SAW), //< - l10n::getView(STRING_FOR_ANALOG_SAW), //< - l10n::getView(STRING_FOR_WAVETABLE), //< + l10n::get(STRING_FOR_SINE), //< + l10n::get(STRING_FOR_TRIANGLE), //< + l10n::get(STRING_FOR_SQUARE), //< + l10n::get(STRING_FOR_ANALOG_SQUARE), //< + l10n::get(STRING_FOR_SAW), //< + l10n::get(STRING_FOR_ANALOG_SAW), //< + l10n::get(STRING_FOR_WAVETABLE), //< }; if (soundEditor.currentSound->getSynthMode() == SynthMode::RINGMOD) { return options; } - options.emplace_back(l10n::getView(STRING_FOR_SAMPLE)); + options.emplace_back(l10n::get(STRING_FOR_SAMPLE)); if (mayUseDx()) { - options.emplace_back(l10n::getView(STRING_FOR_DX7)); + options.emplace_back(l10n::get(STRING_FOR_DX7)); } if (AudioEngine::micPluggedIn || AudioEngine::lineInPluggedIn) { - options.emplace_back(l10n::getView(STRING_FOR_INPUT_LEFT)); - options.emplace_back(l10n::getView(STRING_FOR_INPUT_RIGHT)); - options.emplace_back(l10n::getView(STRING_FOR_INPUT_STEREO)); + options.emplace_back(l10n::get(STRING_FOR_INPUT_LEFT)); + options.emplace_back(l10n::get(STRING_FOR_INPUT_RIGHT)); + options.emplace_back(l10n::get(STRING_FOR_INPUT_STEREO)); } else { - options.emplace_back(l10n::getView(STRING_FOR_INPUT)); + options.emplace_back(l10n::get(STRING_FOR_INPUT)); } return options; diff --git a/src/deluge/gui/menu_item/performance_session_view/editing_mode.h b/src/deluge/gui/menu_item/performance_session_view/editing_mode.h index b3e9cb3a96..e7fd4e65e9 100644 --- a/src/deluge/gui/menu_item/performance_session_view/editing_mode.h +++ b/src/deluge/gui/menu_item/performance_session_view/editing_mode.h @@ -76,9 +76,9 @@ class EditingMode final : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_DISABLED), - l10n::getView(STRING_FOR_PERFORM_EDIT_VALUE), - l10n::getView(STRING_FOR_PERFORM_EDIT_PARAM), + l10n::get(STRING_FOR_DISABLED), + l10n::get(STRING_FOR_PERFORM_EDIT_VALUE), + l10n::get(STRING_FOR_PERFORM_EDIT_PARAM), }; } }; diff --git a/src/deluge/gui/menu_item/record/threshold_mode.h b/src/deluge/gui/menu_item/record/threshold_mode.h index c53c6f317a..bc14195d12 100644 --- a/src/deluge/gui/menu_item/record/threshold_mode.h +++ b/src/deluge/gui/menu_item/record/threshold_mode.h @@ -50,10 +50,10 @@ class ThresholdMode final : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_DISABLED), - l10n::getView(STRING_FOR_LOW), - l10n::getView(STRING_FOR_MEDIUM), - l10n::getView(STRING_FOR_HIGH), + l10n::get(STRING_FOR_DISABLED), + l10n::get(STRING_FOR_LOW), + l10n::get(STRING_FOR_MEDIUM), + l10n::get(STRING_FOR_HIGH), }; } }; diff --git a/src/deluge/gui/menu_item/reverb/model.h b/src/deluge/gui/menu_item/reverb/model.h index 864a7d304e..532fdd196b 100644 --- a/src/deluge/gui/menu_item/reverb/model.h +++ b/src/deluge/gui/menu_item/reverb/model.h @@ -17,8 +17,8 @@ class Model final : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_FREEVERB), - l10n::getView(STRING_FOR_MUTABLE), + l10n::get(STRING_FOR_FREEVERB), + l10n::get(STRING_FOR_MUTABLE), }; } }; diff --git a/src/deluge/gui/menu_item/reverb/room_size.h b/src/deluge/gui/menu_item/reverb/room_size.h index fa11ce06ff..ce52310fcd 100644 --- a/src/deluge/gui/menu_item/reverb/room_size.h +++ b/src/deluge/gui/menu_item/reverb/room_size.h @@ -33,9 +33,9 @@ class RoomSize final : public Integer { using enum l10n::String; switch (AudioEngine::reverb.getModel()) { case dsp::Reverb::Model::MUTABLE: - return l10n::getView(STRING_FOR_TIME); + return l10n::get(STRING_FOR_TIME); default: - return l10n::getView(this->name); + return l10n::get(this->name); } } [[nodiscard]] std::string_view getTitle() const override { return getName(); } diff --git a/src/deluge/gui/menu_item/reverb/width.h b/src/deluge/gui/menu_item/reverb/width.h index b9591993e8..ab0c77c470 100644 --- a/src/deluge/gui/menu_item/reverb/width.h +++ b/src/deluge/gui/menu_item/reverb/width.h @@ -33,9 +33,9 @@ class Width final : public Integer { using enum l10n::String; switch (AudioEngine::reverb.getModel()) { case dsp::Reverb::Model::MUTABLE: - return l10n::getView(STRING_FOR_DIFFUSION); + return l10n::get(STRING_FOR_DIFFUSION); default: - return l10n::getView(this->name); + return l10n::get(this->name); } } [[nodiscard]] std::string_view getTitle() const override { return getName(); } diff --git a/src/deluge/gui/menu_item/runtime_feature/devSysexSetting.cpp b/src/deluge/gui/menu_item/runtime_feature/devSysexSetting.cpp index 99f1366e0f..55f76db434 100644 --- a/src/deluge/gui/menu_item/runtime_feature/devSysexSetting.cpp +++ b/src/deluge/gui/menu_item/runtime_feature/devSysexSetting.cpp @@ -58,11 +58,11 @@ deluge::vector DevSysexSetting::getOptions() { } std::string_view DevSysexSetting::getName() const { - return deluge::l10n::getView(runtimeFeatureSettings.settings[currentSettingIndex].displayName); + return deluge::l10n::get(runtimeFeatureSettings.settings[currentSettingIndex].displayName); } std::string_view DevSysexSetting::getTitle() const { - return deluge::l10n::getView(runtimeFeatureSettings.settings[currentSettingIndex].displayName); + return deluge::l10n::get(runtimeFeatureSettings.settings[currentSettingIndex].displayName); } } // namespace deluge::gui::menu_item::runtime_feature diff --git a/src/deluge/gui/menu_item/runtime_feature/setting.cpp b/src/deluge/gui/menu_item/runtime_feature/setting.cpp index 73838c02b3..b4133d9225 100644 --- a/src/deluge/gui/menu_item/runtime_feature/setting.cpp +++ b/src/deluge/gui/menu_item/runtime_feature/setting.cpp @@ -50,11 +50,11 @@ deluge::vector Setting::getOptions() { } std::string_view Setting::getName() const { - return deluge::l10n::getView(runtimeFeatureSettings.settings[currentSettingIndex].displayName); + return deluge::l10n::get(runtimeFeatureSettings.settings[currentSettingIndex].displayName); } std::string_view Setting::getTitle() const { - return deluge::l10n::getView(runtimeFeatureSettings.settings[currentSettingIndex].displayName); + return deluge::l10n::get(runtimeFeatureSettings.settings[currentSettingIndex].displayName); } } // namespace deluge::gui::menu_item::runtime_feature diff --git a/src/deluge/gui/menu_item/sample/browser_preview/mode.h b/src/deluge/gui/menu_item/sample/browser_preview/mode.h index aed28b50fa..fc31980a24 100644 --- a/src/deluge/gui/menu_item/sample/browser_preview/mode.h +++ b/src/deluge/gui/menu_item/sample/browser_preview/mode.h @@ -26,9 +26,9 @@ class Mode final : public Selection { void writeCurrentValue() override { FlashStorage::sampleBrowserPreviewMode = this->getValue(); } deluge::vector getOptions() override { return { - l10n::getView(l10n::String::STRING_FOR_DISABLED), - l10n::getView(l10n::String::STRING_FOR_CONDITIONAL), - l10n::getView(l10n::String::STRING_FOR_ENABLED), + l10n::get(l10n::String::STRING_FOR_DISABLED), + l10n::get(l10n::String::STRING_FOR_CONDITIONAL), + l10n::get(l10n::String::STRING_FOR_ENABLED), }; } }; diff --git a/src/deluge/gui/menu_item/sample/pitch_speed.h b/src/deluge/gui/menu_item/sample/pitch_speed.h index 9369b5ade9..3c0f8e783a 100644 --- a/src/deluge/gui/menu_item/sample/pitch_speed.h +++ b/src/deluge/gui/menu_item/sample/pitch_speed.h @@ -59,7 +59,7 @@ class PitchSpeed final : public Selection { } deluge::vector getOptions() override { - return {l10n::getView(l10n::String::STRING_FOR_LINKED), l10n::getView(l10n::String::STRING_FOR_INDEPENDENT)}; + return {l10n::get(l10n::String::STRING_FOR_LINKED), l10n::get(l10n::String::STRING_FOR_INDEPENDENT)}; } }; } // namespace deluge::gui::menu_item::sample diff --git a/src/deluge/gui/menu_item/sample/repeat.h b/src/deluge/gui/menu_item/sample/repeat.h index ac8ca93173..73a69f25f6 100644 --- a/src/deluge/gui/menu_item/sample/repeat.h +++ b/src/deluge/gui/menu_item/sample/repeat.h @@ -89,10 +89,10 @@ class Repeat final : public Selection, public FormattedTitle { } deluge::vector getOptions() override { return { - l10n::getView(l10n::String::STRING_FOR_CUT), - l10n::getView(l10n::String::STRING_FOR_ONCE), - l10n::getView(l10n::String::STRING_FOR_LOOP), - l10n::getView(l10n::String::STRING_FOR_STRETCH), + l10n::get(l10n::String::STRING_FOR_CUT), + l10n::get(l10n::String::STRING_FOR_ONCE), + l10n::get(l10n::String::STRING_FOR_LOOP), + l10n::get(l10n::String::STRING_FOR_STRETCH), }; } }; diff --git a/src/deluge/gui/menu_item/sequence/direction.h b/src/deluge/gui/menu_item/sequence/direction.h index 8413a1c4a1..a3b5d5b0b4 100644 --- a/src/deluge/gui/menu_item/sequence/direction.h +++ b/src/deluge/gui/menu_item/sequence/direction.h @@ -90,16 +90,16 @@ class Direction final : public Selection { deluge::vector getOptions() override { deluge::vector sequenceDirectionOptions = { - l10n::getView(l10n::String::STRING_FOR_FORWARD), - l10n::getView(l10n::String::STRING_FOR_REVERSED), - l10n::getView(l10n::String::STRING_FOR_PING_PONG), + l10n::get(l10n::String::STRING_FOR_FORWARD), + l10n::get(l10n::String::STRING_FOR_REVERSED), + l10n::get(l10n::String::STRING_FOR_PING_PONG), }; char modelStackMemory[MODEL_STACK_MAX_SIZE]; ModelStackWithTimelineCounter* modelStack = currentSong->setupModelStackWithCurrentClip(modelStackMemory); ModelStackWithNoteRow* modelStackWithNoteRow = getIndividualNoteRow(modelStack); if (modelStackWithNoteRow->getNoteRowAllowNull() != nullptr) { - sequenceDirectionOptions.push_back(l10n::getView(l10n::String::STRING_FOR_NONE)); + sequenceDirectionOptions.push_back(l10n::get(l10n::String::STRING_FOR_NONE)); } return sequenceDirectionOptions; diff --git a/src/deluge/gui/menu_item/shortcuts/version.h b/src/deluge/gui/menu_item/shortcuts/version.h index fe10fcacb8..859dbd92f7 100644 --- a/src/deluge/gui/menu_item/shortcuts/version.h +++ b/src/deluge/gui/menu_item/shortcuts/version.h @@ -28,8 +28,8 @@ class Version final : public Selection { deluge::vector getOptions() override { using enum l10n::String; return { - l10n::getView(STRING_FOR_SHORTCUTS_VERSION_1), - l10n::getView(STRING_FOR_SHORTCUTS_VERSION_3), + l10n::get(STRING_FOR_SHORTCUTS_VERSION_1), + l10n::get(STRING_FOR_SHORTCUTS_VERSION_3), }; } }; diff --git a/src/deluge/gui/menu_item/source_selection/range.h b/src/deluge/gui/menu_item/source_selection/range.h index 717fbfd145..09e111a994 100644 --- a/src/deluge/gui/menu_item/source_selection/range.h +++ b/src/deluge/gui/menu_item/source_selection/range.h @@ -24,7 +24,7 @@ class Range final : public SourceSelection { ParamDescriptor getDestinationDescriptor() override; MenuItem* selectButtonPress() override; MenuItem* patchingSourceShortcutPress(PatchSource newS, bool previousPressStillActive) override; - std::string_view getTitle() const override { return l10n::getView(l10n::String::STRING_FOR_MODULATE_DEPTH); }; + std::string_view getTitle() const override { return l10n::get(l10n::String::STRING_FOR_MODULATE_DEPTH); }; }; extern Range rangeMenu; } // namespace deluge::gui::menu_item::source_selection diff --git a/src/deluge/gui/menu_item/source_selection/regular.h b/src/deluge/gui/menu_item/source_selection/regular.h index 046d3292a8..d98b0064f8 100644 --- a/src/deluge/gui/menu_item/source_selection/regular.h +++ b/src/deluge/gui/menu_item/source_selection/regular.h @@ -26,7 +26,7 @@ class Regular final : public SourceSelection { ParamDescriptor getDestinationDescriptor() override; MenuItem* selectButtonPress() override; MenuItem* patchingSourceShortcutPress(PatchSource newS, bool previousPressStillActive) override; - std::string_view getTitle() const override { return l10n::getView(l10n::String::STRING_FOR_MODULATE_WITH); }; + std::string_view getTitle() const override { return l10n::get(l10n::String::STRING_FOR_MODULATE_WITH); }; }; extern Regular regularMenu; diff --git a/src/deluge/gui/menu_item/sync_level.cpp b/src/deluge/gui/menu_item/sync_level.cpp index a82e5f3b6a..49b72d46a4 100644 --- a/src/deluge/gui/menu_item/sync_level.cpp +++ b/src/deluge/gui/menu_item/sync_level.cpp @@ -38,7 +38,7 @@ std::string SyncLevel::getNoteLengthName() { } void SyncLevel::drawPixelsForOled() { - std::string name{l10n::getView(l10n::String::STRING_FOR_OFF)}; + std::string name{l10n::get(l10n::String::STRING_FOR_OFF)}; if (this->getValue() != 0) { name = getNoteLengthName(); } diff --git a/src/deluge/gui/menu_item/synth_mode.h b/src/deluge/gui/menu_item/synth_mode.h index c52a3f0281..cc4a20ab5b 100644 --- a/src/deluge/gui/menu_item/synth_mode.h +++ b/src/deluge/gui/menu_item/synth_mode.h @@ -34,9 +34,9 @@ class SynthMode final : public Selection { deluge::vector getOptions() override { return { - l10n::getView(l10n::String::STRING_FOR_SUBTRACTIVE), - l10n::getView(l10n::String::STRING_FOR_FM), - l10n::getView(l10n::String::STRING_FOR_RINGMOD), + l10n::get(l10n::String::STRING_FOR_SUBTRACTIVE), + l10n::get(l10n::String::STRING_FOR_FM), + l10n::get(l10n::String::STRING_FOR_RINGMOD), }; } diff --git a/src/deluge/gui/menu_item/toggle.cpp b/src/deluge/gui/menu_item/toggle.cpp index c112edf221..777c2ce374 100644 --- a/src/deluge/gui/menu_item/toggle.cpp +++ b/src/deluge/gui/menu_item/toggle.cpp @@ -3,6 +3,7 @@ #include "gui/ui/sound_editor.h" #include "hid/display/oled.h" #include +#include namespace deluge::gui::menu_item { @@ -19,7 +20,7 @@ void Toggle::selectEncoderAction(int32_t offset) { Value::selectEncoderAction(offset); } -const char* Toggle::getNameFor(bool enabled) { +std::string_view Toggle::getNameFor(bool enabled) { return enabled ? l10n::get(l10n::String::STRING_FOR_ENABLED) : l10n::get(l10n::String::STRING_FOR_DISABLED); } @@ -41,7 +42,7 @@ void Toggle::drawPixelsForOled() { bool selectedOption = getValue(); bool order[2] = {false, true}; for (bool o : order) { - const char* name = getNameFor(o); + std::string_view name = getNameFor(o); canvas.drawString(name, kTextSpacingX, yPixel, kTextSpacingX, kTextSpacingY); if (o == selectedOption) { diff --git a/src/deluge/gui/menu_item/toggle.h b/src/deluge/gui/menu_item/toggle.h index bf08bd69f8..d783cd98c2 100644 --- a/src/deluge/gui/menu_item/toggle.h +++ b/src/deluge/gui/menu_item/toggle.h @@ -2,6 +2,7 @@ #include "gui/ui/sound_editor.h" #include "value.h" +#include namespace deluge::gui::menu_item { @@ -56,7 +57,7 @@ class Toggle : public Value { } private: - const char* getNameFor(bool on); + std::string_view getNameFor(bool on); }; /// the toggle pointer passed to this class must be valid for as long as the menu exists diff --git a/src/deluge/gui/menu_item/voice/polyphony.h b/src/deluge/gui/menu_item/voice/polyphony.h index 92e3359533..c1e27c5262 100644 --- a/src/deluge/gui/menu_item/voice/polyphony.h +++ b/src/deluge/gui/menu_item/voice/polyphony.h @@ -78,14 +78,14 @@ class PolyphonyType final : public Selection { deluge::vector getOptions() override { deluge::vector options = { - l10n::getView(l10n::String::STRING_FOR_AUTO), - l10n::getView(l10n::String::STRING_FOR_POLYPHONIC), - l10n::getView(l10n::String::STRING_FOR_MONOPHONIC), - l10n::getView(l10n::String::STRING_FOR_LEGATO), + l10n::get(l10n::String::STRING_FOR_AUTO), + l10n::get(l10n::String::STRING_FOR_POLYPHONIC), + l10n::get(l10n::String::STRING_FOR_MONOPHONIC), + l10n::get(l10n::String::STRING_FOR_LEGATO), }; if (soundEditor.editingKit()) { - options.push_back(l10n::getView(l10n::String::STRING_FOR_CHOKE)); + options.push_back(l10n::get(l10n::String::STRING_FOR_CHOKE)); } return options; } diff --git a/src/deluge/gui/menu_item/voice/priority.h b/src/deluge/gui/menu_item/voice/priority.h index 4b44068795..5731cd4300 100644 --- a/src/deluge/gui/menu_item/voice/priority.h +++ b/src/deluge/gui/menu_item/voice/priority.h @@ -28,9 +28,9 @@ class Priority final : public Selection { void writeCurrentValue() override { *soundEditor.currentPriority = this->getValue(); } deluge::vector getOptions() override { return { - l10n::getView(l10n::String::STRING_FOR_LOW), - l10n::getView(l10n::String::STRING_FOR_MEDIUM), - l10n::getView(l10n::String::STRING_FOR_HIGH), + l10n::get(l10n::String::STRING_FOR_LOW), + l10n::get(l10n::String::STRING_FOR_MEDIUM), + l10n::get(l10n::String::STRING_FOR_HIGH), }; } }; diff --git a/src/deluge/gui/ui/keyboard/layout/column_controls.cpp b/src/deluge/gui/ui/keyboard/layout/column_controls.cpp index ca5ade346a..4a3bf82627 100644 --- a/src/deluge/gui/ui/keyboard/layout/column_controls.cpp +++ b/src/deluge/gui/ui/keyboard/layout/column_controls.cpp @@ -323,7 +323,7 @@ bool ColumnControlsKeyboard::horizontalEncoderHandledByColumns(int32_t offset, b state.leftCol->handleLeavingColumn(modelStackWithTimelineCounter, this); state.leftColFunc = (offset > 0) ? nextControlFunction(state.leftColFunc, state.rightColFunc) : prevControlFunction(state.leftColFunc, state.rightColFunc); - display->displayPopup(l10n::getView(functionNames[state.leftColFunc])); + display->displayPopup(l10n::get(functionNames[state.leftColFunc])); state.leftCol = state.getColumnForFunc(state.leftColFunc); keyboardScreen.killColumnSwitchKey(LEFT_COL); return true; @@ -332,7 +332,7 @@ bool ColumnControlsKeyboard::horizontalEncoderHandledByColumns(int32_t offset, b state.rightCol->handleLeavingColumn(modelStackWithTimelineCounter, this); state.rightColFunc = (offset > 0) ? nextControlFunction(state.rightColFunc, state.leftColFunc) : prevControlFunction(state.rightColFunc, state.leftColFunc); - display->displayPopup(l10n::getView(functionNames[state.rightColFunc])); + display->displayPopup(l10n::get(functionNames[state.rightColFunc])); state.rightCol = state.getColumnForFunc(state.rightColFunc); state.rightColSetAtRuntime = true; keyboardScreen.killColumnSwitchKey(RIGHT_COL); diff --git a/src/deluge/gui/ui/save/save_song_ui.cpp b/src/deluge/gui/ui/save/save_song_ui.cpp index 0f257583f5..52bd2d13d5 100644 --- a/src/deluge/gui/ui/save/save_song_ui.cpp +++ b/src/deluge/gui/ui/save/save_song_ui.cpp @@ -511,9 +511,7 @@ bool SaveSongUI::performSave(bool mayOverwrite) { } display->removeWorkingAnimation(); - char const* message = anyErrorMovingTempFiles - ? (deluge::l10n::get(deluge::l10n::String::STRING_FOR_ERROR_MOVING_TEMP_FILES)) - : (deluge::l10n::get(deluge::l10n::String::STRING_FOR_SONG_SAVED)); + // Update all of these currentSong->name.set(&enteredText); currentSong->dirPath.set(¤tDir); diff --git a/src/deluge/gui/views/automation_view.cpp b/src/deluge/gui/views/automation_view.cpp index 511bb69726..74c1791164 100644 --- a/src/deluge/gui/views/automation_view.cpp +++ b/src/deluge/gui/views/automation_view.cpp @@ -94,6 +94,7 @@ #include "util/functions.h" #include #include +#include extern "C" { #include "RZA1/uart/sio_char.h" @@ -1270,13 +1271,12 @@ void AutomationView::renderAutomationOverviewDisplayOLED(deluge::hid::display::o #endif // display Automation Overview - char const* overviewText; if (!onArrangerView && (outputType == OutputType::KIT && !getAffectEntire() && !((Kit*)output)->selectedDrum)) { - overviewText = l10n::get(l10n::String::STRING_FOR_SELECT_A_ROW_OR_AFFECT_ENTIRE); + std::string_view overviewText = l10n::get(l10n::String::STRING_FOR_SELECT_A_ROW_OR_AFFECT_ENTIRE); deluge::hid::display::OLED::drawPermanentPopupLookingText(overviewText); } else { - overviewText = l10n::get(l10n::String::STRING_FOR_AUTOMATION_OVERVIEW); + std::string_view overviewText = l10n::get(l10n::String::STRING_FOR_AUTOMATION_OVERVIEW); canvas.drawStringCentred(overviewText, yPos, kTextSpacingX, kTextSpacingY); } } @@ -1313,17 +1313,14 @@ void AutomationView::renderAutomationEditorDisplayOLED(deluge::hid::display::ole modelStackWithParam = getModelStackWithParamForClip(modelStack, clip); } - char const* isAutomated; + std::string_view isAutomated; // check if Parameter is currently automated so that the automation status can be drawn on // the screen with the Parameter Name if (modelStackWithParam && modelStackWithParam->autoParam) { - if (modelStackWithParam->autoParam->isAutomated()) { - isAutomated = l10n::get(l10n::String::STRING_FOR_AUTOMATION_ON); - } - else { - isAutomated = l10n::get(l10n::String::STRING_FOR_AUTOMATION_OFF); - } + isAutomated = (modelStackWithParam->autoParam->isAutomated()) + ? l10n::get(l10n::String::STRING_FOR_AUTOMATION_ON) + : l10n::get(l10n::String::STRING_FOR_AUTOMATION_OFF); } canvas.drawStringCentred(isAutomated, yPos, kTextSpacingX, kTextSpacingY); @@ -1458,7 +1455,7 @@ void AutomationView::renderDisplay7SEG(Clip* clip, Output* output, OutputType ou } void AutomationView::renderAutomationOverviewDisplay7SEG(Output* output, OutputType outputType) { - char const* overviewText; + std::string_view overviewText; if (!onArrangerView && (outputType == OutputType::KIT && !getAffectEntire() && !((Kit*)output)->selectedDrum)) { overviewText = l10n::get(l10n::String::STRING_FOR_SELECT_A_ROW_OR_AFFECT_ENTIRE); } diff --git a/src/deluge/gui/views/instrument_clip_view.cpp b/src/deluge/gui/views/instrument_clip_view.cpp index 22e9075f5c..dd70c173cf 100644 --- a/src/deluge/gui/views/instrument_clip_view.cpp +++ b/src/deluge/gui/views/instrument_clip_view.cpp @@ -99,6 +99,7 @@ #include #include #include +#include extern "C" { #include "RZA1/uart/sio_char.h" @@ -2432,17 +2433,12 @@ void InstrumentClipView::updateVelocityValue(int32_t& velocityValue, int32_t new // display updated velocity value for note(s) edited or generalized "velocity increased / decreased" message void InstrumentClipView::displayVelocity(int32_t velocityValue, int32_t velocityChange) { if (velocityValue) { - char buffer[22]; - char const* displayString; if (velocityValue == 255) { // this happens when you're holding two or more notes that have two different velocities, so it can't show // the current velocity value (so it just says note velocities have increased or decreased) - if (velocityChange >= 0) { - displayString = deluge::l10n::get(deluge::l10n::String::STRING_FOR_VELOCITY_INCREASED); - } - else { - displayString = deluge::l10n::get(deluge::l10n::String::STRING_FOR_VELOCITY_DECREASED); - } + std::string_view displayString = + (velocityChange >= 0) ? deluge::l10n::get(deluge::l10n::String::STRING_FOR_VELOCITY_INCREASED) + : deluge::l10n::get(deluge::l10n::String::STRING_FOR_VELOCITY_DECREASED); popupVelocity(displayString); @@ -2455,6 +2451,7 @@ void InstrumentClipView::displayVelocity(int32_t velocityValue, int32_t velocity bool inNoteEditor = currentUI == &soundEditor && soundEditor.inNoteEditor(); getCurrentInstrument()->defaultVelocity = velocityValue; if (!inAutomationView && !inNoteEditor) { + char buffer[22]; if (display->haveOLED()) { strcpy(buffer, "Velocity: "); intToString(velocityValue, buffer + strlen(buffer)); @@ -2463,16 +2460,14 @@ void InstrumentClipView::displayVelocity(int32_t velocityValue, int32_t velocity intToString(velocityValue, buffer); } - displayString = buffer; - - popupVelocity(displayString); + popupVelocity(buffer); } } } } // display velocity popup -void InstrumentClipView::popupVelocity(char const* displayString) { +void InstrumentClipView::popupVelocity(std::string_view displayString) { if (display->haveOLED()) { display->popupText(displayString); } diff --git a/src/deluge/gui/views/instrument_clip_view.h b/src/deluge/gui/views/instrument_clip_view.h index 78702df170..35ef8c1fea 100644 --- a/src/deluge/gui/views/instrument_clip_view.h +++ b/src/deluge/gui/views/instrument_clip_view.h @@ -26,6 +26,7 @@ #include "modulation/automation/copied_param_automation.h" #include "modulation/params/param_node.h" #include "util/d_string.h" +#include class InstrumentClip; class NoteRow; @@ -236,7 +237,7 @@ class InstrumentClipView final : public ClipView, public InstrumentClipMinder { void adjustVelocity(int32_t velocityChange); void updateVelocityValue(int32_t& velocityValue, int32_t newVelocity); void displayVelocity(int32_t velocityValue, int32_t velocityChange); - void popupVelocity(char const* displayString); + void popupVelocity(std::string_view displayString); void adjustNoteProbabilityWithOffset(int32_t offset); void adjustNoteIteranceWithOffset(int32_t offset, bool allowTogglingBetweenPresetsAndCustom = true); diff --git a/src/deluge/gui/views/performance_view.cpp b/src/deluge/gui/views/performance_view.cpp index 1773ed423d..c2047955d9 100644 --- a/src/deluge/gui/views/performance_view.cpp +++ b/src/deluge/gui/views/performance_view.cpp @@ -46,6 +46,7 @@ #include "storage/storage_manager.h" #include "util/d_string.h" #include "util/functions.h" +#include extern "C" {} @@ -491,15 +492,9 @@ void PerformanceView::renderViewDisplay() { yPos = yPos + 12; - char const* editingModeType; - // render "Param" or "Value" in the middle of the OLED screen - if (editingParam) { - editingModeType = l10n::get(l10n::String::STRING_FOR_PERFORM_EDIT_PARAM); - } - else { - editingModeType = l10n::get(l10n::String::STRING_FOR_PERFORM_EDIT_VALUE); - } + std::string_view editingModeType = (editingParam) ? l10n::get(l10n::String::STRING_FOR_PERFORM_EDIT_PARAM) + : l10n::get(l10n::String::STRING_FOR_PERFORM_EDIT_VALUE); image.drawStringCentred(editingModeType, yPos, kTextSpacingX, kTextSpacingY); @@ -512,13 +507,8 @@ void PerformanceView::renderViewDisplay() { deluge::hid::display::OLED::markChanged(); } else { - char const* editingModeType; - if (editingParam) { - editingModeType = l10n::get(l10n::String::STRING_FOR_PERFORM_EDIT_PARAM); - } - else { - editingModeType = l10n::get(l10n::String::STRING_FOR_PERFORM_EDIT_VALUE); - } + std::string_view editingModeType = (editingParam) ? l10n::get(l10n::String::STRING_FOR_PERFORM_EDIT_PARAM) + : l10n::get(l10n::String::STRING_FOR_PERFORM_EDIT_VALUE); display->setScrollingText(editingModeType); } } @@ -552,8 +542,9 @@ void PerformanceView::renderViewDisplay() { void PerformanceView::renderFXDisplay(params::Kind paramKind, int32_t paramID, int32_t knobPos) { if (editingParam) { // display parameter name - char parameterName[30]; - strncpy(parameterName, getParamDisplayName(paramKind, paramID), 29); + char parameterName[30] = {0}; + auto paramDisplayName = getParamDisplayName(paramKind, paramID); + strncpy(parameterName, paramDisplayName.data(), paramDisplayName.length()); if (display->haveOLED()) { deluge::hid::display::oled_canvas::Canvas& image = deluge::hid::display::OLED::main; deluge::hid::display::OLED::clearMainImage(); @@ -579,8 +570,9 @@ void PerformanceView::renderFXDisplay(params::Kind paramKind, int32_t paramID, i deluge::hid::display::OLED::clearMainImage(); // display parameter name - char parameterName[30]; - strncpy(parameterName, getParamDisplayName(paramKind, paramID), 29); + char parameterName[30] = {0}; + auto paramDisplayName = getParamDisplayName(paramKind, paramID); + strncpy(parameterName, paramDisplayName.data(), paramDisplayName.length()); #if OLED_MAIN_HEIGHT_PIXELS == 64 int32_t yPos = OLED_MAIN_TOPMOST_PIXEL + 12; diff --git a/src/deluge/gui/views/session_view.cpp b/src/deluge/gui/views/session_view.cpp index bf87e0a71e..8b9a84d589 100644 --- a/src/deluge/gui/views/session_view.cpp +++ b/src/deluge/gui/views/session_view.cpp @@ -4312,7 +4312,7 @@ ActionResult SessionView::gridHandlePadsMacros(int32_t x, int32_t y, int32_t on, renderUIsForOled(); } else { - const char* macroKind = getMacroKindString(macro.kind); + std::string_view macroKind = getMacroKindString(macro.kind); display->displayPopup(macroKind); } @@ -4327,25 +4327,23 @@ ActionResult SessionView::gridHandlePadsMacros(int32_t x, int32_t y, int32_t on, return ActionResult::ACTIONED_AND_CAUSED_CHANGE; } -char const* SessionView::getMacroKindString(SessionMacroKind kind) { - const char* macroKind; +std::string_view SessionView::getMacroKindString(SessionMacroKind kind) { // display new macro type on the screen switch (kind) { - using deluge::l10n::String; + using namespace deluge; case SessionMacroKind::CLIP_LAUNCH: - macroKind = get(String::STRING_FOR_SONG_MACRO_KIND_CLIP); + return l10n::get(l10n::String::STRING_FOR_SONG_MACRO_KIND_CLIP); break; case SessionMacroKind::OUTPUT_CYCLE: - macroKind = get(String::STRING_FOR_SONG_MACRO_KIND_OUTPUT); + return l10n::get(l10n::String::STRING_FOR_SONG_MACRO_KIND_OUTPUT); break; case SessionMacroKind::SECTION: - macroKind = get(String::STRING_FOR_SONG_MACRO_KIND_SECTION); + return l10n::get(l10n::String::STRING_FOR_SONG_MACRO_KIND_SECTION); break; default: - macroKind = get(String::STRING_FOR_SONG_MACRO_KIND_NONE); + return l10n::get(l10n::String::STRING_FOR_SONG_MACRO_KIND_NONE); break; } - return macroKind; } ActionResult SessionView::gridHandleScroll(int32_t offsetX, int32_t offsetY) { diff --git a/src/deluge/gui/views/session_view.h b/src/deluge/gui/views/session_view.h index d6ad051c98..4e7c724c6e 100644 --- a/src/deluge/gui/views/session_view.h +++ b/src/deluge/gui/views/session_view.h @@ -22,6 +22,7 @@ #include "hid/button.h" #include "model/song/song.h" #include "storage/flash_storage.h" +#include class Editor; class InstrumentClip; @@ -136,7 +137,7 @@ class SessionView final : public ClipNavigationTimelineView { // Grid macros config mode void enterMacrosConfigMode(); void exitMacrosConfigMode(); - char const* getMacroKindString(SessionMacroKind kind); + std::string_view getMacroKindString(SessionMacroKind kind); // Midi learn mode void enterMidiLearnMode(); diff --git a/src/deluge/gui/views/view.cpp b/src/deluge/gui/views/view.cpp index f4b4b73217..f425f16c03 100644 --- a/src/deluge/gui/views/view.cpp +++ b/src/deluge/gui/views/view.cpp @@ -86,6 +86,7 @@ #include "storage/flash_storage.h" #include "storage/storage_manager.h" #include "util/string.h" +#include namespace params = deluge::modulation::params; namespace encoders = deluge::hid::encoders; @@ -1020,7 +1021,8 @@ void View::getParameterNameFromModEncoder(int32_t whichModEncoder, char* paramet strncpy(parameterName, paramDisplayName.c_str(), 29); } else { - strncpy(parameterName, getParamDisplayName(kind, modelStackWithParam->paramId), 29); + auto paramDisplayName = getParamDisplayName(kind, modelStackWithParam->paramId); + strncpy(parameterName, paramDisplayName.data(), std::min(paramDisplayName.length(), 29)); } } } @@ -1101,7 +1103,7 @@ void View::displayModEncoderValuePopup(params::Kind kind, int32_t paramID, int32 } } else { - const char* name = getParamDisplayName(kind, paramID); + std::string_view name = getParamDisplayName(kind, paramID); if (name != l10n::get(l10n::String::STRING_FOR_NONE)) { popupMsg.append(name); } @@ -1908,7 +1910,7 @@ int32_t View::getCurrentReverbPreset() { return currentPreset; } -char const* View::getReverbPresetDisplayName(int32_t preset) { +std::string_view View::getReverbPresetDisplayName(int32_t preset) { return deluge::l10n::get(presetReverbNames[preset]); } diff --git a/src/deluge/gui/views/view.h b/src/deluge/gui/views/view.h index 98de1f89ea..9371c6aa58 100644 --- a/src/deluge/gui/views/view.h +++ b/src/deluge/gui/views/view.h @@ -78,7 +78,7 @@ class View { bool shouldSendMidiFeedback = true); void setActiveModControllableWithoutTimelineCounter(ModControllable* modControllable, ParamManager* paramManager); void cycleThroughReverbPresets(); - char const* getReverbPresetDisplayName(int32_t preset); + std::string_view getReverbPresetDisplayName(int32_t preset); int32_t getCurrentReverbPreset(); void setModRegion(uint32_t pos = 0xFFFFFFFF, uint32_t length = 0, int32_t noteRowId = 0); void notifyParamAutomationOccurred(ParamManager* paramManager, bool updateModLevels = true); diff --git a/src/deluge/hid/display/display.cpp b/src/deluge/hid/display/display.cpp index 30450f515b..1d3dda02fa 100644 --- a/src/deluge/hid/display/display.cpp +++ b/src/deluge/hid/display/display.cpp @@ -11,71 +11,71 @@ std::string_view getErrorMessage(Error error) { using enum l10n::String; switch (error) { case Error::INSUFFICIENT_RAM: - return l10n::getView(STRING_FOR_ERROR_INSUFFICIENT_RAM); + return l10n::get(STRING_FOR_ERROR_INSUFFICIENT_RAM); case Error::INSUFFICIENT_RAM_FOR_FOLDER_CONTENTS_SIZE: - return l10n::getView(STRING_FOR_ERROR_INSUFFICIENT_RAM_FOR_FOLDER_CONTENTS_SIZE); + return l10n::get(STRING_FOR_ERROR_INSUFFICIENT_RAM_FOR_FOLDER_CONTENTS_SIZE); case Error::SD_CARD: - return l10n::getView(STRING_FOR_ERROR_SD_CARD); + return l10n::get(STRING_FOR_ERROR_SD_CARD); case Error::SD_CARD_NOT_PRESENT: - return l10n::getView(STRING_FOR_ERROR_SD_CARD_NOT_PRESENT); + return l10n::get(STRING_FOR_ERROR_SD_CARD_NOT_PRESENT); case Error::SD_CARD_NO_FILESYSTEM: - return l10n::getView(STRING_FOR_ERROR_SD_CARD_NO_FILESYSTEM); + return l10n::get(STRING_FOR_ERROR_SD_CARD_NO_FILESYSTEM); case Error::FILE_CORRUPTED: - return l10n::getView(STRING_FOR_ERROR_FILE_CORRUPTED); + return l10n::get(STRING_FOR_ERROR_FILE_CORRUPTED); case Error::FILE_NOT_FOUND: - return l10n::getView(STRING_FOR_ERROR_FILE_NOT_FOUND); + return l10n::get(STRING_FOR_ERROR_FILE_NOT_FOUND); case Error::FILE_UNREADABLE: - return l10n::getView(STRING_FOR_ERROR_FILE_UNREADABLE); + return l10n::get(STRING_FOR_ERROR_FILE_UNREADABLE); case Error::FILE_UNSUPPORTED: - return l10n::getView(STRING_FOR_ERROR_FILE_UNSUPPORTED); + return l10n::get(STRING_FOR_ERROR_FILE_UNSUPPORTED); case Error::FILE_FIRMWARE_VERSION_TOO_NEW: - return l10n::getView(STRING_FOR_ERROR_FILE_FIRMWARE_VERSION_TOO_NEW); + return l10n::get(STRING_FOR_ERROR_FILE_FIRMWARE_VERSION_TOO_NEW); case Error::FOLDER_DOESNT_EXIST: - return l10n::getView(STRING_FOR_ERROR_FOLDER_DOESNT_EXIST); + return l10n::get(STRING_FOR_ERROR_FOLDER_DOESNT_EXIST); case Error::BUG: - return l10n::getView(STRING_FOR_ERROR_BUG); + return l10n::get(STRING_FOR_ERROR_BUG); case Error::WRITE_FAIL: - return l10n::getView(STRING_FOR_ERROR_WRITE_FAIL); + return l10n::get(STRING_FOR_ERROR_WRITE_FAIL); case Error::FILE_TOO_BIG: - return l10n::getView(STRING_FOR_ERROR_FILE_TOO_BIG); + return l10n::get(STRING_FOR_ERROR_FILE_TOO_BIG); case Error::PRESET_IN_USE: - return l10n::getView(STRING_FOR_ERROR_PRESET_IN_USE); + return l10n::get(STRING_FOR_ERROR_PRESET_IN_USE); case Error::NO_FURTHER_PRESETS: case Error::NO_FURTHER_FILES_THIS_DIRECTION: - return l10n::getView(STRING_FOR_ERROR_NO_FURTHER_FILES_THIS_DIRECTION); + return l10n::get(STRING_FOR_ERROR_NO_FURTHER_FILES_THIS_DIRECTION); case Error::MAX_FILE_SIZE_REACHED: - return l10n::getView(STRING_FOR_ERROR_MAX_FILE_SIZE_REACHED); + return l10n::get(STRING_FOR_ERROR_MAX_FILE_SIZE_REACHED); case Error::SD_CARD_FULL: - return l10n::getView(STRING_FOR_ERROR_SD_CARD_FULL); + return l10n::get(STRING_FOR_ERROR_SD_CARD_FULL); break; case Error::FILE_NOT_LOADABLE_AS_WAVETABLE: - return l10n::getView(STRING_FOR_ERROR_FILE_NOT_LOADABLE_AS_WAVETABLE); + return l10n::get(STRING_FOR_ERROR_FILE_NOT_LOADABLE_AS_WAVETABLE); case Error::FILE_NOT_LOADABLE_AS_WAVETABLE_BECAUSE_STEREO: - return l10n::getView(STRING_FOR_ERROR_FILE_NOT_LOADABLE_AS_WAVETABLE_BECAUSE_STEREO); + return l10n::get(STRING_FOR_ERROR_FILE_NOT_LOADABLE_AS_WAVETABLE_BECAUSE_STEREO); case Error::WRITE_PROTECTED: - return l10n::getView(STRING_FOR_ERROR_WRITE_PROTECTED); + return l10n::get(STRING_FOR_ERROR_WRITE_PROTECTED); default: - return l10n::getView(STRING_FOR_ERROR_GENERIC); + return l10n::get(STRING_FOR_ERROR_GENERIC); } } diff --git a/src/deluge/hid/display/display.h b/src/deluge/hid/display/display.h index 5564b6e807..8974fcb0c9 100644 --- a/src/deluge/hid/display/display.h +++ b/src/deluge/hid/display/display.h @@ -58,11 +58,6 @@ class Display { displayPopup(valStr, numFlashes, alignRight, drawDot, blinkSpeed, type); } - virtual void displayPopup(std::string_view shortLong[2], int8_t numFlashes = 3, bool alignRight = false, - uint8_t drawDot = 255, int32_t blinkSpeed = 1, PopupType type = PopupType::GENERAL) { - displayPopup(have7SEG() ? shortLong[0] : shortLong[1], numFlashes, alignRight, drawDot, blinkSpeed, type); - } - virtual void popupText(std::string_view text, PopupType type = PopupType::GENERAL) = 0; virtual void popupTextTemporary(std::string_view text, PopupType type = PopupType::GENERAL) = 0; diff --git a/src/deluge/io/midi/cable_types/din.cpp b/src/deluge/io/midi/cable_types/din.cpp index 5e90dd2a8f..f9795e54bb 100644 --- a/src/deluge/io/midi/cable_types/din.cpp +++ b/src/deluge/io/midi/cable_types/din.cpp @@ -24,6 +24,7 @@ extern "C" { #include "gui/l10n/l10n.h" #include "io/midi/midi_engine.h" #include "storage/storage_manager.h" +#include void MIDICableDINPorts::writeReferenceAttributesToFile(Serializer& writer) { // Same line. Usually the user wouldn't have default velocity sensitivity set @@ -34,7 +35,7 @@ void MIDICableDINPorts::writeToFlash(uint8_t* memory) { *(uint16_t*)memory = VENDOR_ID_DIN; } -char const* MIDICableDINPorts::getDisplayName() { +std::string_view MIDICableDINPorts::getDisplayName() { return deluge::l10n::get(deluge::l10n::String::STRING_FOR_DIN_PORTS); } diff --git a/src/deluge/io/midi/cable_types/din.h b/src/deluge/io/midi/cable_types/din.h index af41f69aeb..323920ee5b 100644 --- a/src/deluge/io/midi/cable_types/din.h +++ b/src/deluge/io/midi/cable_types/din.h @@ -18,6 +18,7 @@ #pragma once #include "deluge/io/midi/midi_device.h" +#include class MIDICableDINPorts final : public MIDICable { public: @@ -29,7 +30,7 @@ class MIDICableDINPorts final : public MIDICable { void writeReferenceAttributesToFile(Serializer& writer) override; void writeToFlash(uint8_t* memory) override; - char const* getDisplayName() override; + std::string_view getDisplayName() override; void sendMessage(MIDIMessage message) override; void sendSysex(const uint8_t* data, int32_t len) override; diff --git a/src/deluge/io/midi/cable_types/usb_device_cable.cpp b/src/deluge/io/midi/cable_types/usb_device_cable.cpp index 6407136fb4..631aabef8d 100644 --- a/src/deluge/io/midi/cable_types/usb_device_cable.cpp +++ b/src/deluge/io/midi/cable_types/usb_device_cable.cpp @@ -19,6 +19,7 @@ #include "gui/l10n/l10n.h" #include "io/debug/log.h" #include "storage/storage_manager.h" +#include void MIDICableUSBUpstream::writeReferenceAttributesToFile(Serializer& writer) { // Same line. Usually the user wouldn't have default velocity sensitivity set for their computer. @@ -30,7 +31,7 @@ void MIDICableUSBUpstream::writeToFlash(uint8_t* memory) { *(uint16_t*)memory = portNumber ? VENDOR_ID_UPSTREAM_USB2 : VENDOR_ID_UPSTREAM_USB; } -char const* MIDICableUSBUpstream::getDisplayName() { +std::string_view MIDICableUSBUpstream::getDisplayName() { switch (portNumber) { case 0: return deluge::l10n::get(deluge::l10n::String::STRING_FOR_UPSTREAM_USB_PORT_1); diff --git a/src/deluge/io/midi/cable_types/usb_device_cable.h b/src/deluge/io/midi/cable_types/usb_device_cable.h index a5a13e288b..f5f5395a1c 100644 --- a/src/deluge/io/midi/cable_types/usb_device_cable.h +++ b/src/deluge/io/midi/cable_types/usb_device_cable.h @@ -18,11 +18,12 @@ #pragma once #include "deluge/io/midi/cable_types/usb_common.h" +#include class MIDICableUSBUpstream final : public MIDICableUSB { public: MIDICableUSBUpstream(uint8_t portNum = 0) : MIDICableUSB(portNum) {} void writeReferenceAttributesToFile(Serializer& writer) override; void writeToFlash(uint8_t* memory) override; - char const* getDisplayName() override; + std::string_view getDisplayName() override; }; diff --git a/src/deluge/io/midi/cable_types/usb_hosted.cpp b/src/deluge/io/midi/cable_types/usb_hosted.cpp index 71865a0f3b..1e68cfccb8 100644 --- a/src/deluge/io/midi/cable_types/usb_hosted.cpp +++ b/src/deluge/io/midi/cable_types/usb_hosted.cpp @@ -17,6 +17,7 @@ #include "usb_hosted.h" #include "storage/storage_manager.h" +#include void MIDICableUSBHosted::writeReferenceAttributesToFile(Serializer& writer) { writer.writeAttribute("name", name.get()); @@ -29,7 +30,7 @@ void MIDICableUSBHosted::writeToFlash(uint8_t* memory) { *(uint16_t*)(memory + 2) = productId; } -char const* MIDICableUSBHosted::getDisplayName() { +std::string_view MIDICableUSBHosted::getDisplayName() { return name.get(); } diff --git a/src/deluge/io/midi/cable_types/usb_hosted.h b/src/deluge/io/midi/cable_types/usb_hosted.h index 5ae4c7d5d2..788cea4e00 100644 --- a/src/deluge/io/midi/cable_types/usb_hosted.h +++ b/src/deluge/io/midi/cable_types/usb_hosted.h @@ -18,6 +18,7 @@ #pragma once #include "deluge/io/midi/cable_types/usb_common.h" +#include class MIDICableUSBHosted : public MIDICableUSB { public: @@ -26,7 +27,7 @@ class MIDICableUSBHosted : public MIDICableUSB { void writeReferenceAttributesToFile(Serializer& writer) override; void writeToFlash(uint8_t* memory) override; - char const* getDisplayName() override; + std::string_view getDisplayName() override; /// @name Hooks /// @{ diff --git a/src/deluge/io/midi/midi_device.h b/src/deluge/io/midi/midi_device.h index b59c334dd7..719a443dcd 100644 --- a/src/deluge/io/midi/midi_device.h +++ b/src/deluge/io/midi/midi_device.h @@ -95,7 +95,7 @@ class MIDICable { public: MIDICable(); virtual void writeToFlash(uint8_t* memory) = 0; - virtual char const* getDisplayName() = 0; + virtual std::string_view getDisplayName() = 0; void dataEntryMessageReceived(ModelStack* modelStack, int32_t channel, int32_t msb); diff --git a/src/deluge/io/midi/midi_follow.cpp b/src/deluge/io/midi/midi_follow.cpp index df0dcecbec..1895a96a68 100644 --- a/src/deluge/io/midi/midi_follow.cpp +++ b/src/deluge/io/midi/midi_follow.cpp @@ -41,6 +41,7 @@ #include "processing/engines/audio_engine.h" #include "storage/storage_manager.h" #include "util/d_string.h" +#include namespace params = deluge::modulation::params; using deluge::modulation::params::kNoParamID; @@ -339,7 +340,7 @@ void MidiFollow::displayParamControlError(int32_t xDisplay, int32_t yDisplay) { if (display->haveOLED()) { DEF_STACK_STRING_BUF(popupMsg, 40); - const char* name = getParamDisplayName(paramKind, paramID); + std::string_view name = getParamDisplayName(paramKind, paramID); if (name != l10n::get(l10n::String::STRING_FOR_NONE)) { popupMsg.append("Can't control: \n"); popupMsg.append(name); diff --git a/src/deluge/model/global_effectable/global_effectable.cpp b/src/deluge/model/global_effectable/global_effectable.cpp index 2d84486d17..65c118999f 100644 --- a/src/deluge/model/global_effectable/global_effectable.cpp +++ b/src/deluge/model/global_effectable/global_effectable.cpp @@ -33,6 +33,7 @@ #include "storage/storage_manager.h" #include "util/comparison.h" #include "util/firmware_version.h" +#include using namespace deluge; namespace params = deluge::modulation::params; @@ -162,13 +163,13 @@ void GlobalEffectable::displayCompressorAndReverbSettings(bool on) { } } -char const* GlobalEffectable::getCompressorModeDisplayName() { +std::string_view GlobalEffectable::getCompressorModeDisplayName() { return editingComp ? "FULL" : "ONE"; } -char const* GlobalEffectable::getCompressorParamDisplayName() { +std::string_view GlobalEffectable::getCompressorParamDisplayName() { currentCompParam = static_cast(util::to_underlying(currentCompParam) % maxCompParam); - const char* params[util::to_underlying(CompParam::LAST)] = {"ratio", "attack", "release", "hpf", "blend"}; + std::string_view params[util::to_underlying(CompParam::LAST)] = {"ratio", "attack", "release", "hpf", "blend"}; return params[int(currentCompParam)]; } @@ -198,7 +199,7 @@ void GlobalEffectable::displayModFXSettings(bool on) { } } -char const* GlobalEffectable::getModFXTypeDisplayName() { +std::string_view GlobalEffectable::getModFXTypeDisplayName() { auto modTypeCount = kNumModFXTypes; modFXType_ = static_cast(util::to_underlying(modFXType_) % modTypeCount); @@ -206,7 +207,7 @@ char const* GlobalEffectable::getModFXTypeDisplayName() { return modfx::modFXToString(modFXType_); } -char const* GlobalEffectable::getModFXParamDisplayName() { +std::string_view GlobalEffectable::getModFXParamDisplayName() { currentModFXParam = static_cast(util::to_underlying(currentModFXParam) % kNumModFXParams); return modfx::getParamName(modFXType_, currentModFXParam); @@ -1175,18 +1176,18 @@ deluge::vector getModNames() { using enum deluge::l10n::String; using namespace deluge; return { - l10n::getView(STRING_FOR_DISABLED), //< - l10n::getView(STRING_FOR_FLANGER), //< - l10n::getView(STRING_FOR_CHORUS), //< - l10n::getView(STRING_FOR_PHASER), //< - l10n::getView(STRING_FOR_STEREO_CHORUS), //< - l10n::getView(STRING_FOR_WARBLE), - l10n::getView(STRING_FOR_DIMENSION), //< - l10n::getView(STRING_FOR_GRAIN), //< + l10n::get(STRING_FOR_DISABLED), //< + l10n::get(STRING_FOR_FLANGER), //< + l10n::get(STRING_FOR_CHORUS), //< + l10n::get(STRING_FOR_PHASER), //< + l10n::get(STRING_FOR_STEREO_CHORUS), //< + l10n::get(STRING_FOR_WARBLE), + l10n::get(STRING_FOR_DIMENSION), //< + l10n::get(STRING_FOR_GRAIN), //< }; } -const char* getParamName(ModFXType type, ModFXParam param) { +std::string_view getParamName(ModFXType type, ModFXParam param) { using enum deluge::l10n::String; using namespace deluge; switch (type) { @@ -1219,7 +1220,8 @@ const char* getParamName(ModFXType type, ModFXParam param) { } } } -const char* modFXToString(ModFXType type) { + +std::string_view modFXToString(ModFXType type) { switch (type) { using namespace deluge; using enum deluge::l10n::String; diff --git a/src/deluge/model/global_effectable/global_effectable.h b/src/deluge/model/global_effectable/global_effectable.h index 2ba39dc2e0..2d86e93bd6 100644 --- a/src/deluge/model/global_effectable/global_effectable.h +++ b/src/deluge/model/global_effectable/global_effectable.h @@ -22,6 +22,7 @@ #include "gui/l10n/l10n.h" #include "model/mod_controllable/mod_controllable_audio.h" #include "util/containers.h" +#include using namespace deluge; class Serializer; @@ -77,9 +78,9 @@ class GlobalEffectable : public ModControllableAudio { private: void ensureModFXParamIsValid(); void displayCompressorAndReverbSettings(bool on); - char const* getCompressorModeDisplayName(); - char const* getCompressorParamDisplayName(); + std::string_view getCompressorModeDisplayName(); + std::string_view getCompressorParamDisplayName(); void displayModFXSettings(bool on); - char const* getModFXTypeDisplayName(); - char const* getModFXParamDisplayName(); + std::string_view getModFXTypeDisplayName(); + std::string_view getModFXParamDisplayName(); }; diff --git a/src/deluge/model/mod_controllable/ModFXProcessor.h b/src/deluge/model/mod_controllable/ModFXProcessor.h index b3bc516085..fedc73ab1c 100644 --- a/src/deluge/model/mod_controllable/ModFXProcessor.h +++ b/src/deluge/model/mod_controllable/ModFXProcessor.h @@ -22,6 +22,7 @@ #include "dsp/stereo_sample.h" #include "modulation/lfo.h" #include "util/containers.h" +#include class ModFXProcessor { void setupChorus(const ModFXType& modFXType, int32_t modFXDepth, int32_t* postFXVolume, @@ -78,9 +79,9 @@ class ModFXProcessor { namespace modfx { deluge::vector getModNames(); -const char* getParamName(ModFXType type, ModFXParam param); +std::string_view getParamName(ModFXType type, ModFXParam param); -const char* modFXToString(ModFXType type); +std::string_view modFXToString(ModFXType type); } // namespace modfx #endif // DELUGE_MODFXPROCESSOR_H diff --git a/src/deluge/model/mod_controllable/mod_controllable_audio.cpp b/src/deluge/model/mod_controllable/mod_controllable_audio.cpp index 663e5aaad6..49114d0a1d 100644 --- a/src/deluge/model/mod_controllable/mod_controllable_audio.cpp +++ b/src/deluge/model/mod_controllable/mod_controllable_audio.cpp @@ -40,6 +40,7 @@ #include "processing/engines/audio_engine.h" #include "processing/sound/sound.h" #include "storage/storage_manager.h" +#include namespace params = deluge::modulation::params; @@ -1156,7 +1157,7 @@ void ModControllableAudio::switchDelayAnalog() { delay.analog = !delay.analog; } -char const* ModControllableAudio::getDelayTypeDisplayName() { +std::string_view ModControllableAudio::getDelayTypeDisplayName() { switch (delay.analog) { using enum deluge::l10n::String; case 0: @@ -1181,7 +1182,7 @@ void ModControllableAudio::switchDelaySyncType() { } } -char const* ModControllableAudio::getDelaySyncTypeDisplayName() { +std::string_view ModControllableAudio::getDelaySyncTypeDisplayName() { switch (delay.syncType) { case SYNC_TYPE_TRIPLET: return "Triplet"; @@ -1203,7 +1204,7 @@ std::string ModControllableAudio::getDelaySyncLevelDisplayName() { return currentSong->getNoteLengthName((uint32_t)3 << (SYNC_LEVEL_256TH - delay.syncLevel)); } -char const* ModControllableAudio::getFilterTypeDisplayName(FilterType currentFilterType) { +std::string_view ModControllableAudio::getFilterTypeDisplayName(FilterType currentFilterType) { using enum deluge::l10n::String; switch (currentFilterType) { case FilterType::LPF: @@ -1236,7 +1237,7 @@ void ModControllableAudio::switchLPFModeWithOff() { } } -char const* ModControllableAudio::getFilterModeDisplayName(FilterType currentFilterType) { +std::string_view ModControllableAudio::getFilterModeDisplayName(FilterType currentFilterType) { switch (currentFilterType) { case FilterType::LPF: return getLPFModeDisplayName(); @@ -1247,7 +1248,7 @@ char const* ModControllableAudio::getFilterModeDisplayName(FilterType currentFil } } -char const* ModControllableAudio::getLPFModeDisplayName() { +std::string_view ModControllableAudio::getLPFModeDisplayName() { using enum deluge::l10n::String; switch (lpfMode) { @@ -1282,7 +1283,7 @@ void ModControllableAudio::switchHPFModeWithOff() { } } -char const* ModControllableAudio::getHPFModeDisplayName() { +std::string_view ModControllableAudio::getHPFModeDisplayName() { using enum deluge::l10n::String; switch (hpfMode) { case FilterMode::HPLADDER: @@ -1473,7 +1474,7 @@ void ModControllableAudio::displayDelaySettings(bool on) { } } -char const* ModControllableAudio::getDelayPingPongStatusDisplayName() { +std::string_view ModControllableAudio::getDelayPingPongStatusDisplayName() { using enum deluge::l10n::String; switch (delay.pingPong) { case 0: @@ -1513,7 +1514,7 @@ void ModControllableAudio::displaySidechainAndReverbSettings(bool on) { } } -char const* ModControllableAudio::getSidechainDisplayName() { +std::string_view ModControllableAudio::getSidechainDisplayName() { int32_t insideWorldTickMagnitude; if (currentSong) { // Bit of a hack just referring to currentSong in here... insideWorldTickMagnitude = diff --git a/src/deluge/model/mod_controllable/mod_controllable_audio.h b/src/deluge/model/mod_controllable/mod_controllable_audio.h index f4d9fc476b..3ac0f7cf59 100644 --- a/src/deluge/model/mod_controllable/mod_controllable_audio.h +++ b/src/deluge/model/mod_controllable/mod_controllable_audio.h @@ -143,15 +143,15 @@ class ModControllableAudio : public ModControllable { /// subclass is deluge::modulation::params::Kind unpatchedParamKind_; - char const* getFilterTypeDisplayName(FilterType currentFilterType); - char const* getFilterModeDisplayName(FilterType currentFilterType); - char const* getLPFModeDisplayName(); - char const* getHPFModeDisplayName(); - char const* getDelayTypeDisplayName(); - char const* getDelayPingPongStatusDisplayName(); - char const* getDelaySyncTypeDisplayName(); + std::string_view getFilterTypeDisplayName(FilterType currentFilterType); + std::string_view getFilterModeDisplayName(FilterType currentFilterType); + std::string_view getLPFModeDisplayName(); + std::string_view getHPFModeDisplayName(); + std::string_view getDelayTypeDisplayName(); + std::string_view getDelayPingPongStatusDisplayName(); + std::string_view getDelaySyncTypeDisplayName(); std::string getDelaySyncLevelDisplayName(); - char const* getSidechainDisplayName(); + std::string_view getSidechainDisplayName(); void displayFilterSettings(bool on, FilterType currentFilterType); void displayDelaySettings(bool on); diff --git a/src/deluge/modulation/params/param.cpp b/src/deluge/modulation/params/param.cpp index 5184d6e4d3..b9c1945e79 100644 --- a/src/deluge/modulation/params/param.cpp +++ b/src/deluge/modulation/params/param.cpp @@ -21,6 +21,7 @@ #include "gui/l10n/strings.h" #include "model/settings/runtime_feature_settings.h" #include +#include namespace deluge::modulation::params { @@ -173,7 +174,7 @@ char const* getPatchedParamShortName(ParamType type) { } } -char const* getPatchedParamDisplayName(int32_t p) { +std::string_view getPatchedParamDisplayName(int32_t p) { using enum l10n::String; static l10n::String const NAMES[GLOBAL_NONE] = { @@ -233,7 +234,7 @@ char const* getPatchedParamDisplayName(int32_t p) { } } -char const* getParamDisplayName(Kind kind, int32_t p) { +std::string_view getParamDisplayName(Kind kind, int32_t p) { using enum l10n::String; if (kind == Kind::PATCHED) { return getPatchedParamDisplayName(p); diff --git a/src/deluge/modulation/params/param.h b/src/deluge/modulation/params/param.h index a6cd6bdfa1..2edabebb3a 100644 --- a/src/deluge/modulation/params/param.h +++ b/src/deluge/modulation/params/param.h @@ -22,6 +22,7 @@ #include "util/misc.h" #include #include +#include /// \namespace deluge::modulation::params /// "Param"s are at the heart of the Deluge's modulation capabilities. @@ -256,10 +257,10 @@ bool isSidechainPatchCableShortcut(int32_t xDisplay, int32_t yDisplay); bool isPatchCableShortcut(int32_t xDisplay, int32_t yDisplay); void getPatchCableFromShortcut(int32_t xDisplay, int32_t yDisplay, ParamDescriptor* paramDescriptor); -char const* getPatchedParamDisplayName(int32_t p); +std::string_view getPatchedParamDisplayName(int32_t p); /// Get the short version of a param name, for use in the OLED mod matrix display (maximum 10 characters) char const* getPatchedParamShortName(ParamType type); -char const* getParamDisplayName(Kind kind, int32_t p); +std::string_view getParamDisplayName(Kind kind, int32_t p); bool paramNeedsLPF(ParamType p, bool fromAutomation); diff --git a/src/deluge/util/d_string.cpp b/src/deluge/util/d_string.cpp index 5f37850bd7..0e1637d7cf 100644 --- a/src/deluge/util/d_string.cpp +++ b/src/deluge/util/d_string.cpp @@ -401,7 +401,7 @@ StringBuf& StringBuf::appendInt(int32_t value, size_t min_digits) { int32_t pad_count = static_cast(num_to_copy) - length; char* it = end(); if (pad_count > 0) { - it = std::fill_n(it, pad_count, '0'); // literal zero! not NUL! + it = std::fill_n(it, pad_count, '0'); // literal zero! not NUL! } it = std::copy_n(buffer.begin(), length, it); *it = '\0'; diff --git a/src/deluge/util/functions.cpp b/src/deluge/util/functions.cpp index 1aeac3b070..1d49ee20dc 100644 --- a/src/deluge/util/functions.cpp +++ b/src/deluge/util/functions.cpp @@ -309,7 +309,7 @@ char const* sourceToString(PatchSource source) { } } -char const* getSourceDisplayNameForOLED(PatchSource s) { +std::string_view getSourceDisplayNameForOLED(PatchSource s) { using enum l10n::String; auto lang = l10n::chosenLanguage; diff --git a/src/deluge/util/functions.h b/src/deluge/util/functions.h index 4e228f927c..7048ac4d05 100644 --- a/src/deluge/util/functions.h +++ b/src/deluge/util/functions.h @@ -221,7 +221,7 @@ int32_t getFinalParameterValueExpWithDumbEnvelopeHack(int32_t paramNeutralValue, void addAudio(StereoSample* inputBuffer, StereoSample* outputBuffer, int32_t numSamples); -char const* getSourceDisplayNameForOLED(PatchSource s); +std::string_view getSourceDisplayNameForOLED(PatchSource s); char const* sourceToString(PatchSource source); PatchSource stringToSource(char const* string); From 48a1e43de48f3d97a02a81290d18892994ae5f47 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 4 Jan 2025 09:28:41 -0500 Subject: [PATCH 3/7] little things --- src/deluge/util/d_string.h | 4 ++-- src/deluge/util/lookuptables/lookuptables.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/deluge/util/d_string.h b/src/deluge/util/d_string.h index df20af70d6..0efe823cc9 100644 --- a/src/deluge/util/d_string.h +++ b/src/deluge/util/d_string.h @@ -198,8 +198,8 @@ class StringBuf { constexpr void operator+=(std::string_view str) { append(str); } constexpr void operator+=(std::string& str) { append(str); } - operator std::string_view() const { return std::string_view{buf_}; } - char& operator[](size_t idx) { return buf_[idx]; } + constexpr operator std::string_view() const { return std::string_view{buf_}; } + constexpr char& operator[](size_t idx) { return buf_[idx]; } private: [[nodiscard]] constexpr char* true_end() const { return &buf_[capacity_ + 1]; } diff --git a/src/deluge/util/lookuptables/lookuptables.cpp b/src/deluge/util/lookuptables/lookuptables.cpp index 37e3554941..28b2536c0f 100644 --- a/src/deluge/util/lookuptables/lookuptables.cpp +++ b/src/deluge/util/lookuptables/lookuptables.cpp @@ -483,7 +483,7 @@ const int16_t lanczosKernelA16[1025] = { const char noteCodeToNoteLetter[12] = {'C','C','D','D','E','F','F','G','G','A','A','B'}; -const bool noteCodeIsSharp[12] = {false, true, false, true, 0, false, true, false, true, false, true, false}; +const bool noteCodeIsSharp[12] = {false, true, false, true, false, false, true, false, true, false, true, false}; /** * @brief How iterance is encoded: From f6cdf18a41691654c1948fd953e565f6d8d4ccc8 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 4 Jan 2025 09:31:18 -0500 Subject: [PATCH 4/7] more constexpr for StringBuf --- src/deluge/util/d_string.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/deluge/util/d_string.h b/src/deluge/util/d_string.h index 0efe823cc9..c131ac4462 100644 --- a/src/deluge/util/d_string.h +++ b/src/deluge/util/d_string.h @@ -174,15 +174,16 @@ class StringBuf { } return idx; } + [[nodiscard]] constexpr size_t size() const { return length(); } [[nodiscard]] constexpr bool full() const { return size() == capacity_; } - [[nodiscard]] char* begin() { return buf_; } - [[nodiscard]] char* end() { return &buf_[size()]; } - [[nodiscard]] const char* cbegin() const { return buf_; } - [[nodiscard]] const char* cend() const { return &buf_[size()]; } + [[nodiscard]] constexpr char* begin() { return buf_; } + [[nodiscard]] constexpr char* end() { return &buf_[size()]; } + [[nodiscard]] constexpr const char* cbegin() const { return buf_; } + [[nodiscard]] constexpr const char* cend() const { return &buf_[size()]; } - [[nodiscard]] bool empty() const { return buf_[0] == '\0'; } + [[nodiscard]] constexpr bool empty() const { return buf_[0] == '\0'; } constexpr bool operator==(const char* rhs) const { return static_cast(*this) == std::string_view{rhs}; From 73b254204dc1ec679f9f2bed1e5a84a4cf6f602f Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 4 Jan 2025 09:38:32 -0500 Subject: [PATCH 5/7] fix display mock --- tests/32bit_unit_tests/mocks/mock_display.cpp | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/tests/32bit_unit_tests/mocks/mock_display.cpp b/tests/32bit_unit_tests/mocks/mock_display.cpp index 4a39432cbe..079df3fdd2 100644 --- a/tests/32bit_unit_tests/mocks/mock_display.cpp +++ b/tests/32bit_unit_tests/mocks/mock_display.cpp @@ -2,56 +2,57 @@ #include "hid/display/oled.h" #include "util/misc.h" #include +#include -class MockDisplay : public deluge::hid::Display { +class MockDisplay final : public deluge::hid::Display { public: MockDisplay() : deluge::hid::Display(deluge::hid::DisplayType::SEVENSEG) {} ~MockDisplay() = default; - constexpr size_t getNumBrowserAndMenuLines() { return 0; }; + constexpr size_t getNumBrowserAndMenuLines() final { return 0; }; void setText(std::string_view newText, bool alignRight = false, uint8_t drawDot = 255, bool doBlink = false, uint8_t* newBlinkMask = NULL, bool blinkImmediately = false, bool shouldBlinkFast = false, - int32_t scrollPos = 0, uint8_t* blinkAddition = NULL, bool justReplaceBottomLayer = false){}; + int32_t scrollPos = 0, uint8_t* blinkAddition = NULL, bool justReplaceBottomLayer = false) {} - void displayPopup(char const* newText, int8_t numFlashes = 3, bool alignRight = false, uint8_t = 255, int32_t = 1, - PopupType type = PopupType::GENERAL){}; + void displayPopup(std::string_view newText, int8_t numFlashes = 3, bool alignRight = false, uint8_t = 255, + int32_t = 1, PopupType type = PopupType::GENERAL) {} - void popupText(char const* text, PopupType type = PopupType::GENERAL){}; - void popupTextTemporary(char const* text, PopupType type = PopupType::GENERAL){}; + void popupText(std::string_view text, PopupType type = PopupType::GENERAL) {} + void popupTextTemporary(std::string_view text, PopupType type = PopupType::GENERAL) {} - void setNextTransitionDirection(int8_t thisDirection){}; + void setNextTransitionDirection(int8_t thisDirection) final {} - void cancelPopup(){}; - void freezeWithError(char const* text) { std::cout << text << std::endl; }; - bool isLayerCurrentlyOnTop(NumericLayer* layer) { return false; }; - void displayError(Error error) { std::cout << util::to_underlying(error) << std::endl; }; + void cancelPopup() final{}; + void freezeWithError(std::string_view text) { std::cout << text << std::endl; } + bool isLayerCurrentlyOnTop(NumericLayer* layer) final { return false; } + void displayError(Error error) { std::cout << util::to_underlying(error) << std::endl; } - void removeWorkingAnimation(){}; + void removeWorkingAnimation() final {} // Loading animations - void displayLoadingAnimation(){}; - void displayLoadingAnimationText(char const* text, bool delayed = false, bool transparent = false){}; - void removeLoadingAnimation(){}; + void displayLoadingAnimation() final {} + void displayLoadingAnimationText(std::string_view text, bool delayed = false, bool transparent = false) {} + void removeLoadingAnimation() final {} - bool hasPopup() { return false; }; - bool hasPopupOfType(PopupType type) { return false; }; + bool hasPopup() final { return false; } + bool hasPopupOfType(PopupType type) final { return false; } - void consoleText(char const* text){}; + void consoleText(std::string_view text) {} - void timerRoutine(){}; + void timerRoutine() final {} - void setTextAsNumber(int16_t number, uint8_t drawDot = 255, bool doBlink = false) {} - int32_t getEncodedPosFromLeft(int32_t textPos, char const* text, bool* andAHalf) { return 0; } + void setTextAsNumber(int16_t number, uint8_t drawDot = 255, bool doBlink = false) final {} + int32_t getEncodedPosFromLeft(int32_t textPos, std::string_view text, bool* andAHalf) { return 0; } void setTextAsSlot(int16_t currentSlot, int8_t currentSubSlot, bool currentSlotExists, bool doBlink = false, - int32_t blinkPos = -1, bool blinkImmediately = false) {} - NumericLayerScrollingText* setScrollingText(char const* newText, int32_t startAtPos = 0, + int32_t blinkPos = -1, bool blinkImmediately = false) final {} + NumericLayerScrollingText* setScrollingText(std::string_view newText, int32_t startAtPos = 0, int32_t initialDelay = 600) { return nullptr; } - std::array getLast() { return {0}; }; // to match SevenSegment + std::array getLast() { return {}; }; // to match SevenSegment }; extern "C" void freezeWithError(char const* error) { From f8423d90cc59f50aa9ec7399adef729100f97bd4 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 4 Jan 2025 09:52:26 -0500 Subject: [PATCH 6/7] Add printf to tests, fix warnings --- src/deluge/util/functions.cpp | 6 +++--- tests/32bit_unit_tests/CMakeLists.txt | 3 +++ tests/unit/mocks/function_mocks.h | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/deluge/util/functions.cpp b/src/deluge/util/functions.cpp index 1d49ee20dc..0fc098720a 100644 --- a/src/deluge/util/functions.cpp +++ b/src/deluge/util/functions.cpp @@ -1344,12 +1344,12 @@ bool isAudioFilename(char const* filename) { if (filename[0] == '.') { return false; } - char* dotPos = strrchr(filename, '.'); + const char* dotPos = strrchr(filename, '.'); return (!strcasecmp(dotPos, ".WAV") || !strcasecmp(dotPos, ".AIF") || !strcasecmp(dotPos, ".AIFF")); } bool isAiffFilename(char const* filename) { - char* dotPos = strrchr(filename, '.'); + const char* dotPos = strrchr(filename, '.'); return (dotPos != NULL && (!strcasecmp(dotPos, ".AIF") || !strcasecmp(dotPos, ".AIFF"))); } @@ -2129,7 +2129,7 @@ bool doesFilenameFitPrefixFormat(char const* fileName, char const* filePrefix, i return false; } - char* dotAddress = strrchr(fileName, '.'); + const char* dotAddress = strrchr(fileName, '.'); if (!dotAddress) { return false; } diff --git a/tests/32bit_unit_tests/CMakeLists.txt b/tests/32bit_unit_tests/CMakeLists.txt index efef96be76..a4b789616b 100644 --- a/tests/32bit_unit_tests/CMakeLists.txt +++ b/tests/32bit_unit_tests/CMakeLists.txt @@ -32,6 +32,7 @@ file(GLOB_RECURSE deluge_SOURCES # Used by most other modules ../../src/deluge/util/* + ../../src/lib/printf.c ) file(GLOB_RECURSE mock_SOURCES @@ -52,6 +53,7 @@ target_include_directories(MemoryManagerTests PRIVATE mocks ../../src/deluge ../../src/NE10/inc + ../../src/lib ../../src ) @@ -90,6 +92,7 @@ target_include_directories(SmallPointerTests PRIVATE mocks ../../src/deluge ../../src/NE10/inc + ../../src/lib ../../src ) diff --git a/tests/unit/mocks/function_mocks.h b/tests/unit/mocks/function_mocks.h index 4c5071faba..10c4397836 100644 --- a/tests/unit/mocks/function_mocks.h +++ b/tests/unit/mocks/function_mocks.h @@ -8,7 +8,7 @@ int32_t getNoteMagnitudeFfromNoteLength(uint32_t noteLength, int32_t tickMagnitude) { return 1; } -void getNoteLengthNameFromMagnitude(StringBuf& buf, int32_t magnitude, char const* durrationSuffix = "-notes", - bool clarifyPerColumn = false) { - ; +std::string getNoteLengthNameFromMagnitude(int32_t magnitude, std::string_view durrationSuffix = "-notes", + bool clarifyPerColumn = false) { + return {}; } From 675258c15f571c9093b215439ba7a1fbbcd08899 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 4 Jan 2025 10:27:55 -0500 Subject: [PATCH 7/7] add putchar_ to mocks --- tests/32bit_unit_tests/mocks/mock_print.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/32bit_unit_tests/mocks/mock_print.cpp b/tests/32bit_unit_tests/mocks/mock_print.cpp index ffd06089f2..267fb990aa 100644 --- a/tests/32bit_unit_tests/mocks/mock_print.cpp +++ b/tests/32bit_unit_tests/mocks/mock_print.cpp @@ -1,4 +1,5 @@ #include "io/debug/print.h" +#include #include using namespace std; @@ -23,3 +24,7 @@ void print(int32_t number) { } } // namespace Debug + +extern "C" void putchar_(char c) { + putchar(c); +}