From 13a4b32c38cb35b9d97cd95e41699ec4b401faa6 Mon Sep 17 00:00:00 2001 From: patrickhurtado Date: Tue, 24 Oct 2023 22:31:06 -0500 Subject: [PATCH 1/3] FEAT: Mute BGM in Tweaks --- src/common/system/settings.h | 4 ++++ src/common/theme/resources.h | 4 ++++ src/tweaks/actions.h | 5 +++++ src/tweaks/menus.h | 7 +++++++ 4 files changed, 20 insertions(+) diff --git a/src/common/system/settings.h b/src/common/system/settings.h index 46417bfa2..1f94ac11d 100644 --- a/src/common/system/settings.h +++ b/src/common/system/settings.h @@ -21,6 +21,7 @@ typedef struct settings_s { int volume; char keymap[JSON_STRING_LEN]; int mute; + bool mute_bgm; int bgm_volume; int brightness; char language[JSON_STRING_LEN]; @@ -64,6 +65,7 @@ static settings_s __default_settings = (settings_s){ .volume = 20, .keymap = "L2,L,R2,R,X,A,B,Y", .mute = 0, + .mute_bgm = false, .bgm_volume = 20, .brightness = 7, .language = "en.lang", @@ -170,6 +172,7 @@ void settings_load(void) settings.startup_auto_resume = !config_flag_get(".noAutoStart"); settings.menu_button_haptics = !config_flag_get(".noMenuHaptics"); settings.show_recents = config_flag_get(".showRecents"); + settings.mute_bgm = config_flag_get(".muteBgm"); settings.show_expert = config_flag_get(".showExpert"); settings.mute = config_flag_get(".muteVolume"); settings.disable_standby = config_flag_get(".disableStandby"); @@ -302,6 +305,7 @@ void settings_save(void) config_flag_set(".showRecents", settings.show_recents); config_flag_set(".showExpert", settings.show_expert); config_flag_set(".muteVolume", settings.mute); + config_flag_set(".muteBgm", settings.mute_bgm); config_flag_set(".disableStandby", settings.disable_standby); config_flag_set(".logging", settings.enable_logging); config_setNumber("battery/warnAt", settings.low_battery_warn_at); diff --git a/src/common/theme/resources.h b/src/common/theme/resources.h index 96d7f7c7b..8b15413f4 100644 --- a/src/common/theme/resources.h +++ b/src/common/theme/resources.h @@ -257,6 +257,10 @@ Mix_Chunk *resource_getSoundChange(void) Mix_Music *resource_getBGM(void) { + if (config_flag_get(".muteBgm")) { + resources.bgm = NULL; + return NULL; + }; if (resources.bgm == NULL) { char sound_path[STR_MAX * 2]; snprintf(sound_path, STR_MAX * 2 - 1, "%ssound/bgm.mp3", theme()->path); diff --git a/src/tweaks/actions.h b/src/tweaks/actions.h index df07bb0e9..2a6a2299d 100644 --- a/src/tweaks/actions.h +++ b/src/tweaks/actions.h @@ -239,6 +239,11 @@ void action_hideLabelsIcons(void *pt) theme_changeOverride("hideLabels", "icons", NULL, value_types[item_value]); } +void action_toggleBackgroundMusic(void *pt) +{ + settings.mute_bgm = ((ListItem *)pt)->value == 1; +}; + void action_hideLabelsHints(void *pt) { static bool applied_values[] = {false, false, true}; diff --git a/src/tweaks/menus.h b/src/tweaks/menus.h index 6fce5cf7c..77e9d3c8d 100644 --- a/src/tweaks/menus.h +++ b/src/tweaks/menus.h @@ -436,6 +436,13 @@ void menu_themeOverrides(void *_) (ListItem){ .label = "Battery percentage...", .action = menu_batteryPercentage}); + list_addItemWithInfoNote(&_menu_theme_overrides, + (ListItem){ + .label = "Mute background music", + .item_type = TOGGLE, + .value = settings.mute_bgm, + .action = action_toggleBackgroundMusic}, + "Mute background music for themes"); list_addItemWithInfoNote(&_menu_theme_overrides, (ListItem){ .label = "Hide icon labels", From 5251c04f65fedd63bebe3a07f96ad5f249ba64f5 Mon Sep 17 00:00:00 2001 From: "patrick.a.hurtado@gmail.com" Date: Sat, 28 Oct 2023 00:41:23 -0500 Subject: [PATCH 2/3] Adding muting bgm functionality --- src/common/theme/config.h | 1 - src/common/theme/resources.h | 27 +++++++++++++++++++++++++++ src/common/utils/file.c | 16 ++++++++++++++++ src/common/utils/file.h | 4 ++++ src/tweaks/actions.h | 1 + src/tweaks/tweaks.c | 1 + 6 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/common/theme/config.h b/src/common/theme/config.h index 5db9c8560..24e241f52 100644 --- a/src/common/theme/config.h +++ b/src/common/theme/config.h @@ -8,7 +8,6 @@ #include "./color.h" #include "./load.h" -#include "system/lang.h" #include "utils/file.h" #include "utils/json.h" #include "utils/str.h" diff --git a/src/common/theme/resources.h b/src/common/theme/resources.h index 8b15413f4..9225bcf7d 100644 --- a/src/common/theme/resources.h +++ b/src/common/theme/resources.h @@ -255,6 +255,33 @@ Mix_Chunk *resource_getSoundChange(void) return resources.sound_change; } +bool BGMFileExists(void) +{ + char sound_path[STR_MAX * 2]; + snprintf(sound_path, STR_MAX * 2 - 1, "%ssound/bgm.mp3", theme()->path); + return exists(sound_path); +}; + +bool muteBGM() +{ + char bgm[STR_MAX * 2]; + char mutedBGM[STR_MAX * 2]; + snprintf(bgm, STR_MAX * 2 - 1, "%ssound/bgm.mp3", theme()->path); + snprintf(mutedBGM, STR_MAX * 2 - 1, "%ssound/bgm_muted.mp3", theme()->path); + file_touch(bgm); + return file_rename(bgm, mutedBGM) == 0; +} + +bool unmuteBGM() +{ + char bgm[STR_MAX * 2]; + char mutedBGM[STR_MAX * 2]; + snprintf(bgm, STR_MAX * 2 - 1, "%ssound/bgm.mp3", theme()->path); + snprintf(mutedBGM, STR_MAX * 2 - 1, "%ssound/bgm_muted.mp3", theme()->path); + file_touch(mutedBGM); + return file_rename(mutedBGM, bgm) == 0; +} + Mix_Music *resource_getBGM(void) { if (config_flag_get(".muteBgm")) { diff --git a/src/common/utils/file.c b/src/common/utils/file.c index d2eb559aa..c050593c5 100644 --- a/src/common/utils/file.c +++ b/src/common/utils/file.c @@ -132,6 +132,22 @@ bool file_write(const char *path, const char *str, uint32_t len) return true; } +bool file_touch(const char *path) +{ + uint32_t fd; + bool is_success; + is_success = (fd = open(path, O_CREAT)) == 0; + if (is_success) + close(fd); + return is_success; +} + + +bool file_rename(const char *existing_path, const char *new_path) +{ + return rename(existing_path, new_path) == 0; +}; + void file_copy(const char *src_path, const char *dest_path) { char system_cmd[512]; diff --git a/src/common/utils/file.h b/src/common/utils/file.h index 6a4c967e4..7508971a7 100644 --- a/src/common/utils/file.h +++ b/src/common/utils/file.h @@ -80,6 +80,10 @@ const char *file_read(const char *path); bool file_write(const char *path, const char *str, uint32_t len); +bool file_touch(const char *path); + +bool file_rename(const char *existing_path, const char *new_path); + void file_copy(const char *src_path, const char *dest_path); char *file_removeExtension(char *myStr); diff --git a/src/tweaks/actions.h b/src/tweaks/actions.h index 2a6a2299d..b7f448abf 100644 --- a/src/tweaks/actions.h +++ b/src/tweaks/actions.h @@ -242,6 +242,7 @@ void action_hideLabelsIcons(void *pt) void action_toggleBackgroundMusic(void *pt) { settings.mute_bgm = ((ListItem *)pt)->value == 1; + settings.mute_bgm ? muteBGM() : unmuteBGM(); }; void action_hideLabelsHints(void *pt) diff --git a/src/tweaks/tweaks.c b/src/tweaks/tweaks.c index e3bd06409..82e3e39f3 100644 --- a/src/tweaks/tweaks.c +++ b/src/tweaks/tweaks.c @@ -78,6 +78,7 @@ int main(int argc, char *argv[]) SDL_InitDefault(true); settings_load(); + settings.mute_bgm = !BGMFileExists(); lang_load(); // Apply tool via command line From d06b2ed65bd4d5d2965d70942af60c14368b7e21 Mon Sep 17 00:00:00 2001 From: "patrick.a.hurtado@gmail.com" Date: Sat, 28 Oct 2023 14:44:28 -0500 Subject: [PATCH 3/3] moving bgm file logic to happen during runtime.sh --- src/common/system/settings.h | 9 +++++---- src/common/theme/config.h | 1 + src/common/theme/resources.h | 31 ----------------------------- src/common/utils/file.c | 16 --------------- src/common/utils/file.h | 4 ---- src/tweaks/actions.h | 3 +-- src/tweaks/menus.h | 2 +- src/tweaks/tweaks.c | 2 +- static/build/.tmp_update/runtime.sh | 19 ++++++++++++++++++ 9 files changed, 28 insertions(+), 59 deletions(-) diff --git a/src/common/system/settings.h b/src/common/system/settings.h index 1f94ac11d..5e10ef44e 100644 --- a/src/common/system/settings.h +++ b/src/common/system/settings.h @@ -21,7 +21,7 @@ typedef struct settings_s { int volume; char keymap[JSON_STRING_LEN]; int mute; - bool mute_bgm; + int bgm_mute; int bgm_volume; int brightness; char language[JSON_STRING_LEN]; @@ -65,7 +65,7 @@ static settings_s __default_settings = (settings_s){ .volume = 20, .keymap = "L2,L,R2,R,X,A,B,Y", .mute = 0, - .mute_bgm = false, + .bgm_mute = 0, .bgm_volume = 20, .brightness = 7, .language = "en.lang", @@ -144,6 +144,7 @@ void _settings_load_mainui(void) json_getInt(json_root, "vol", &settings.volume); json_getInt(json_root, "bgmvol", &settings.bgm_volume); + json_getInt(json_root, "bgmmute", &settings.bgm_mute); json_getInt(json_root, "brightness", &settings.brightness); json_getInt(json_root, "hibernate", &settings.sleep_timer); json_getInt(json_root, "lumination", &settings.lumination); @@ -172,7 +173,6 @@ void settings_load(void) settings.startup_auto_resume = !config_flag_get(".noAutoStart"); settings.menu_button_haptics = !config_flag_get(".noMenuHaptics"); settings.show_recents = config_flag_get(".showRecents"); - settings.mute_bgm = config_flag_get(".muteBgm"); settings.show_expert = config_flag_get(".showExpert"); settings.mute = config_flag_get(".muteVolume"); settings.disable_standby = config_flag_get(".disableStandby"); @@ -249,6 +249,7 @@ bool _settings_dirty_mainui(void) return settings.volume != __settings.volume || strcmp(settings.keymap, __settings.keymap) != 0 || settings.mute != __settings.mute || + settings.bgm_mute != __settings.bgm_mute || settings.bgm_volume != __settings.bgm_volume || settings.brightness != __settings.brightness || strcmp(settings.language, __settings.language) != 0 || @@ -279,6 +280,7 @@ void _settings_save_mainui(void) fprintf(fp, JSON_FORMAT_TAB_NUMBER, "vol", settings.volume); fprintf(fp, JSON_FORMAT_TAB_STRING, "keymap", settings.keymap); fprintf(fp, JSON_FORMAT_TAB_NUMBER, "mute", settings.mute); + fprintf(fp, JSON_FORMAT_TAB_NUMBER, "bgmmute", settings.bgm_mute); fprintf(fp, JSON_FORMAT_TAB_NUMBER, "bgmvol", settings.bgm_volume); fprintf(fp, JSON_FORMAT_TAB_NUMBER, "brightness", settings.brightness); fprintf(fp, JSON_FORMAT_TAB_STRING, "language", settings.language); @@ -305,7 +307,6 @@ void settings_save(void) config_flag_set(".showRecents", settings.show_recents); config_flag_set(".showExpert", settings.show_expert); config_flag_set(".muteVolume", settings.mute); - config_flag_set(".muteBgm", settings.mute_bgm); config_flag_set(".disableStandby", settings.disable_standby); config_flag_set(".logging", settings.enable_logging); config_setNumber("battery/warnAt", settings.low_battery_warn_at); diff --git a/src/common/theme/config.h b/src/common/theme/config.h index 24e241f52..5db9c8560 100644 --- a/src/common/theme/config.h +++ b/src/common/theme/config.h @@ -8,6 +8,7 @@ #include "./color.h" #include "./load.h" +#include "system/lang.h" #include "utils/file.h" #include "utils/json.h" #include "utils/str.h" diff --git a/src/common/theme/resources.h b/src/common/theme/resources.h index 9225bcf7d..96d7f7c7b 100644 --- a/src/common/theme/resources.h +++ b/src/common/theme/resources.h @@ -255,39 +255,8 @@ Mix_Chunk *resource_getSoundChange(void) return resources.sound_change; } -bool BGMFileExists(void) -{ - char sound_path[STR_MAX * 2]; - snprintf(sound_path, STR_MAX * 2 - 1, "%ssound/bgm.mp3", theme()->path); - return exists(sound_path); -}; - -bool muteBGM() -{ - char bgm[STR_MAX * 2]; - char mutedBGM[STR_MAX * 2]; - snprintf(bgm, STR_MAX * 2 - 1, "%ssound/bgm.mp3", theme()->path); - snprintf(mutedBGM, STR_MAX * 2 - 1, "%ssound/bgm_muted.mp3", theme()->path); - file_touch(bgm); - return file_rename(bgm, mutedBGM) == 0; -} - -bool unmuteBGM() -{ - char bgm[STR_MAX * 2]; - char mutedBGM[STR_MAX * 2]; - snprintf(bgm, STR_MAX * 2 - 1, "%ssound/bgm.mp3", theme()->path); - snprintf(mutedBGM, STR_MAX * 2 - 1, "%ssound/bgm_muted.mp3", theme()->path); - file_touch(mutedBGM); - return file_rename(mutedBGM, bgm) == 0; -} - Mix_Music *resource_getBGM(void) { - if (config_flag_get(".muteBgm")) { - resources.bgm = NULL; - return NULL; - }; if (resources.bgm == NULL) { char sound_path[STR_MAX * 2]; snprintf(sound_path, STR_MAX * 2 - 1, "%ssound/bgm.mp3", theme()->path); diff --git a/src/common/utils/file.c b/src/common/utils/file.c index c050593c5..d2eb559aa 100644 --- a/src/common/utils/file.c +++ b/src/common/utils/file.c @@ -132,22 +132,6 @@ bool file_write(const char *path, const char *str, uint32_t len) return true; } -bool file_touch(const char *path) -{ - uint32_t fd; - bool is_success; - is_success = (fd = open(path, O_CREAT)) == 0; - if (is_success) - close(fd); - return is_success; -} - - -bool file_rename(const char *existing_path, const char *new_path) -{ - return rename(existing_path, new_path) == 0; -}; - void file_copy(const char *src_path, const char *dest_path) { char system_cmd[512]; diff --git a/src/common/utils/file.h b/src/common/utils/file.h index 7508971a7..6a4c967e4 100644 --- a/src/common/utils/file.h +++ b/src/common/utils/file.h @@ -80,10 +80,6 @@ const char *file_read(const char *path); bool file_write(const char *path, const char *str, uint32_t len); -bool file_touch(const char *path); - -bool file_rename(const char *existing_path, const char *new_path); - void file_copy(const char *src_path, const char *dest_path); char *file_removeExtension(char *myStr); diff --git a/src/tweaks/actions.h b/src/tweaks/actions.h index b7f448abf..24b31ad10 100644 --- a/src/tweaks/actions.h +++ b/src/tweaks/actions.h @@ -241,8 +241,7 @@ void action_hideLabelsIcons(void *pt) void action_toggleBackgroundMusic(void *pt) { - settings.mute_bgm = ((ListItem *)pt)->value == 1; - settings.mute_bgm ? muteBGM() : unmuteBGM(); + settings.bgm_mute = ((ListItem *)pt)->value == 1; }; void action_hideLabelsHints(void *pt) diff --git a/src/tweaks/menus.h b/src/tweaks/menus.h index 77e9d3c8d..7119fd2f0 100644 --- a/src/tweaks/menus.h +++ b/src/tweaks/menus.h @@ -440,7 +440,7 @@ void menu_themeOverrides(void *_) (ListItem){ .label = "Mute background music", .item_type = TOGGLE, - .value = settings.mute_bgm, + .value = settings.bgm_mute, .action = action_toggleBackgroundMusic}, "Mute background music for themes"); list_addItemWithInfoNote(&_menu_theme_overrides, diff --git a/src/tweaks/tweaks.c b/src/tweaks/tweaks.c index 82e3e39f3..84bdf9d07 100644 --- a/src/tweaks/tweaks.c +++ b/src/tweaks/tweaks.c @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) SDL_InitDefault(true); settings_load(); - settings.mute_bgm = !BGMFileExists(); + lang_load(); // Apply tool via command line diff --git a/static/build/.tmp_update/runtime.sh b/static/build/.tmp_update/runtime.sh index 5be97a722..1ec9c637e 100644 --- a/static/build/.tmp_update/runtime.sh +++ b/static/build/.tmp_update/runtime.sh @@ -186,6 +186,8 @@ launch_main_ui() { start_audioserver + mute_theme_bgm + # MainUI launch cd $miyoodir/app PATH="$miyoodir/app:$PATH" \ @@ -484,6 +486,23 @@ mount_main_ui() { fi } +mute_theme_bgm() { + bgm_muted=$(/customer/app/jsonval bgmmute) + system_theme="$(/customer/app/jsonval theme)" + bgm_file="${system_theme}sound/bgm.mp3" + muted_bgm_file="${system_theme}sound/bgm_muted.mp3" + + if [ $bgm_muted -eq 1 ]; then + if [[ -f "$bgm_file" ]]; then + mv -f "$bgm_file" "$muted_bgm_file" + fi + else + if [[ -f "$muted_bgm_file" ]]; then + mv -f "$muted_bgm_file" "$bgm_file" + fi + fi +} + init_system() { log "\n:: Init system"