Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

std::string_view refactoring #3211

Draft
wants to merge 7 commits into
base: community
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/deluge/gui/context_menu/audio_input_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char**> AudioInputSelector::getOptions() {
Sized<std::string_view*> 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),
Expand Down
4 changes: 2 additions & 2 deletions src/deluge/gui/context_menu/audio_input_selector.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class AudioInputSelector final : public ContextMenu {
AudioOutput* audioOutput;

/// Title
char const* getTitle() override;
std::string_view getTitle() override;

/// Options
Sized<const char**> getOptions() override;
Sized<std::string_view*> getOptions() override;
};

extern AudioInputSelector audioInputSelector;
Expand Down
8 changes: 4 additions & 4 deletions src/deluge/gui/context_menu/clear_song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char const**> ClearSong::getOptions() {
Sized<std::string_view*> 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};
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/deluge/gui/context_menu/clear_song.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<char const**> getOptions() override;
Sized<std::string_view*> getOptions() override;
bool acceptCurrentOption() override;
};

Expand Down
14 changes: 7 additions & 7 deletions src/deluge/gui/context_menu/clip_settings/clip_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char const**> ClipSettingsMenu::getOptions() {
Sized<std::string_view*> 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};
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/deluge/gui/context_menu/clip_settings/clip_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class ClipSettingsMenu final : public ContextMenu {
Clip* clip = nullptr;

/// Title
char const* getTitle() override;
std::string_view getTitle() override;

/// Options
Sized<const char**> getOptions() override;
Sized<std::string_view*> getOptions() override;

ActionResult padAction(int32_t x, int32_t y, int32_t on) override;
};
Expand Down
10 changes: 5 additions & 5 deletions src/deluge/gui/context_menu/clip_settings/launch_style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char const**> LaunchStyleMenu::getOptions() {
Sized<std::string_view*> 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() {
Expand Down
4 changes: 2 additions & 2 deletions src/deluge/gui/context_menu/clip_settings/launch_style.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class LaunchStyleMenu final : public ContextMenu {
Clip* clip = nullptr;

/// Title
char const* getTitle() override;
std::string_view getTitle() override;

/// Options
Sized<const char**> getOptions() override;
Sized<std::string_view*> getOptions() override;
};

extern LaunchStyleMenu launchStyle;
Expand Down
10 changes: 5 additions & 5 deletions src/deluge/gui/context_menu/clip_settings/new_clip_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char const**> NewClipType::getOptions() {
Sized<std::string_view*> 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() {
Expand Down
4 changes: 2 additions & 2 deletions src/deluge/gui/context_menu/clip_settings/new_clip_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char**> getOptions() override;
Sized<std::string_view*> getOptions() override;
ActionResult padAction(int32_t x, int32_t y, int32_t on) override;
};

Expand Down
11 changes: 6 additions & 5 deletions src/deluge/gui/context_menu/configure_song_macros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "gui/views/session_view.h"
#include "hid/display/display.h"
#include "model/song/song.h"
#include <string_view>

extern "C" {
#include "fatfs/ff.h"
Expand All @@ -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<char const**> ConfigureSongMacros::getOptions() {
Sized<std::string_view*> 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};
}
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/deluge/gui/context_menu/configure_song_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class ConfigureSongMacros final : public ContextMenu {
public:
ConfigureSongMacros() = default;

char const* getTitle() override;
Sized<char const**> getOptions() override;
std::string_view getTitle() override;
Sized<std::string_view*> getOptions() override;
bool setupAndCheckAvailability();
bool acceptCurrentOption() override;
bool canSeeViewUnderneath() override { return true; }
Expand Down
4 changes: 2 additions & 2 deletions src/deluge/gui/context_menu/context_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<char const**> getOptions() = 0;
virtual Sized<std::string_view*> getOptions() = 0;

bool getGreyoutColsAndRows(uint32_t* cols, uint32_t* rows) override;
ActionResult padAction(int32_t x, int32_t y, int32_t velocity) override;
Expand All @@ -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

Expand Down
13 changes: 7 additions & 6 deletions src/deluge/gui/context_menu/delete_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "gui/l10n/l10n.h"
#include "gui/ui/browser/browser.h"
#include "hid/display/display.h"
#include <string_view>

extern "C" {
#include "fatfs/ff.h"
Expand All @@ -30,28 +31,28 @@ 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);
}
return l10n::get(STRING_FOR_DELETE_QMARK);
}

Sized<char const**> DeleteFile::getOptions() {
Sized<std::string_view*> 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};
}
}
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/deluge/gui/context_menu/delete_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class DeleteFile final : public ContextMenuForSaving {
public:
DeleteFile() = default;

Sized<char const**> getOptions() override;
Sized<std::string_view*> getOptions() override;
bool acceptCurrentOption() override;

char const* getTitle() override;
std::string_view getTitle() override;
};

extern DeleteFile deleteFile;
Expand Down
6 changes: 3 additions & 3 deletions src/deluge/gui/context_menu/load_instrument_preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char const**> LoadInstrumentPreset::getOptions() {
Sized<std::string_view*> 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};
}

Expand Down
4 changes: 2 additions & 2 deletions src/deluge/gui/context_menu/load_instrument_preset.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ namespace deluge::gui::context_menu {
class LoadInstrumentPreset final : public ContextMenuForLoading {
public:
LoadInstrumentPreset() = default;
Sized<char const**> getOptions() override;
Sized<std::string_view*> getOptions() override;
bool acceptCurrentOption() override;
char const* getTitle() override;
std::string_view getTitle() override;
};

extern LoadInstrumentPreset loadInstrumentPreset;
Expand Down
8 changes: 4 additions & 4 deletions src/deluge/gui/context_menu/midi_learn_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char const**> MidiLearnMode::getOptions() {
Sized<std::string_view*> 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};
}
}
Expand Down
Loading
Loading