From 3ce6d7020bc054d440e40dd0eccc795fa6babcb2 Mon Sep 17 00:00:00 2001 From: medsouz Date: Tue, 11 Aug 2015 00:42:18 -0400 Subject: [PATCH 1/5] Pause audio when tabbing out TODO: Figure out why title music and toilet sounds are still playing Add an option to disable this feature so that people can jam out to the carousel music while tabbed out. --- src/platform/shared.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/platform/shared.c b/src/platform/shared.c index cb5dadf239..3ccc5c0825 100644 --- a/src/platform/shared.c +++ b/src/platform/shared.c @@ -19,6 +19,7 @@ *****************************************************************************/ #include "../addresses.h" +#include "../audio/audio.h" #include "../config.h" #include "../cursors.h" #include "../drawing/drawing.h" @@ -351,6 +352,16 @@ void platform_process_messages() case SDL_WINDOWEVENT: if (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) platform_resize(e.window.data1, e.window.data2); + if (e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { + if (gConfigSound.sound) { + unpause_sounds(); + } + } + if (e.window.event == SDL_WINDOWEVENT_FOCUS_LOST) { + if (gConfigSound.sound) { + pause_sounds(); + } + } break; case SDL_MOUSEMOTION: RCT2_GLOBAL(0x0142406C, int) = e.motion.x; From 6caa48d3c3a9d26bf2a8216050bcb844b6373102 Mon Sep 17 00:00:00 2001 From: medsouz Date: Tue, 11 Aug 2015 06:29:21 -0400 Subject: [PATCH 2/5] Make all game sounds respect gGameSoundsOff --- src/audio/audio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/audio/audio.c b/src/audio/audio.c index 1c8779ad40..6b265acedf 100644 --- a/src/audio/audio.c +++ b/src/audio/audio.c @@ -1423,7 +1423,7 @@ int get_dsound_devices() int sound_play_panned(int sound_id, int ebx, sint16 x, sint16 y, sint16 z) { int result = 0; - if (gConfigSound.sound) { + if (!gGameSoundsOff) { RCT2_GLOBAL(0x00F438AD, uint8) = 0; int volume = 0; if (ebx == 0x8001) { @@ -1557,7 +1557,7 @@ void start_title_music() break; } - if ((RCT2_GLOBAL(0x009AF284, uint32) & (1 << 0)) && gConfigSound.sound + if ((RCT2_GLOBAL(0x009AF284, uint32) & (1 << 0)) && !gGameSoundsOff && RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_TITLE_DEMO) { if (!RCT2_GLOBAL(0x009AF600, uint8)) { #ifdef USE_MIXER From db9ea4cdf3b11b2a2447d58b86fa9bd45eca9642 Mon Sep 17 00:00:00 2001 From: medsouz Date: Tue, 11 Aug 2015 07:06:00 -0400 Subject: [PATCH 3/5] Added toggle for audio disable on focus lost This closes #1758 --- data/language/english_us.txt | 1 + src/config.c | 3 ++- src/config.h | 1 + src/localisation/string_ids.h | 2 ++ src/platform/shared.c | 8 +++----- src/windows/options.c | 26 ++++++++++++++++++-------- 6 files changed, 27 insertions(+), 14 deletions(-) diff --git a/data/language/english_us.txt b/data/language/english_us.txt index 1d2ceb24f3..81cc076e75 100644 --- a/data/language/english_us.txt +++ b/data/language/english_us.txt @@ -3830,3 +3830,4 @@ STR_5485 :{SMALLFONT}{STRING} STR_5486 :{BLACK}{COMMA16} STR_5487 :{SMALLFONT}{BLACK}Show recent messages STR_5488 :No entrance +STR_5490 :Disable audio on focus loss diff --git a/src/config.c b/src/config.c index 5ae5a27555..f5186b7d30 100644 --- a/src/config.c +++ b/src/config.c @@ -206,7 +206,8 @@ config_property_definition _interfaceDefinitions[] = { config_property_definition _soundDefinitions[] = { { offsetof(sound_configuration, title_music), "title_music", CONFIG_VALUE_TYPE_UINT8, 2, NULL }, { offsetof(sound_configuration, sound), "sound", CONFIG_VALUE_TYPE_BOOLEAN, true, NULL }, - { offsetof(sound_configuration, ride_music), "ride_music", CONFIG_VALUE_TYPE_BOOLEAN, true, NULL }, + { offsetof(sound_configuration, ride_music), "ride_music", CONFIG_VALUE_TYPE_BOOLEAN, false, NULL }, + { offsetof(sound_configuration, audio_focus), "audio_focus", CONFIG_VALUE_TYPE_BOOLEAN, true, NULL }, { offsetof(sound_configuration, master_volume), "master_volume", CONFIG_VALUE_TYPE_UINT8, 100, NULL }, { offsetof(sound_configuration, music_volume), "music_volume", CONFIG_VALUE_TYPE_UINT8, 100, NULL }, { offsetof(sound_configuration, device), "audio_device", CONFIG_VALUE_TYPE_STRING, { .value_string = NULL }, NULL }, diff --git a/src/config.h b/src/config.h index a4c5993f67..5678b3f444 100644 --- a/src/config.h +++ b/src/config.h @@ -180,6 +180,7 @@ typedef struct { uint8 title_music; uint8 sound; uint8 ride_music; + uint8 audio_focus; uint8 master_volume; uint8 music_volume; utf8string device; diff --git a/src/localisation/string_ids.h b/src/localisation/string_ids.h index f1351da221..942ccc6b97 100644 --- a/src/localisation/string_ids.h +++ b/src/localisation/string_ids.h @@ -2025,6 +2025,8 @@ enum { STR_TRACKED_GUESTS_ONLY_TIP = 5489, + STR_AUDIO_FOCUS = 5490, + // Have to include resource strings (from scenarios and objects) for the time being now that language is partially working STR_COUNT = 32768 }; diff --git a/src/platform/shared.c b/src/platform/shared.c index 3ccc5c0825..75e9efe81c 100644 --- a/src/platform/shared.c +++ b/src/platform/shared.c @@ -352,13 +352,11 @@ void platform_process_messages() case SDL_WINDOWEVENT: if (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) platform_resize(e.window.data1, e.window.data2); - if (e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { - if (gConfigSound.sound) { + if (gConfigSound.audio_focus && gConfigSound.sound) { + if (e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { unpause_sounds(); } - } - if (e.window.event == SDL_WINDOWEVENT_FOCUS_LOST) { - if (gConfigSound.sound) { + if (e.window.event == SDL_WINDOWEVENT_FOCUS_LOST) { pause_sounds(); } } diff --git a/src/windows/options.c b/src/windows/options.c index e2f1229606..fc62925905 100644 --- a/src/windows/options.c +++ b/src/windows/options.c @@ -105,6 +105,7 @@ enum WINDOW_OPTIONS_WIDGET_IDX { WIDX_SOUND_DROPDOWN, WIDX_SOUND_CHECKBOX, WIDX_MUSIC_CHECKBOX, + WIDX_AUDIO_FOCUS_CHECKBOX, WIDX_TITLE_MUSIC, WIDX_TITLE_MUSIC_DROPDOWN, WIDX_MASTER_VOLUME, @@ -202,14 +203,15 @@ static rct_widget window_options_culture_widgets[] = { static rct_widget window_options_audio_widgets[] = { MAIN_OPTIONS_WIDGETS, - { WWT_DROPDOWN, 1, 10, 299, 53, 64, 865, STR_NONE }, // audio device - { WWT_DROPDOWN_BUTTON, 1, 288, 298, 54, 63, 876, STR_NONE }, - { WWT_CHECKBOX, 1, 10, 229, 69, 80, STR_SOUND, STR_NONE }, // enable / disable sound - { WWT_CHECKBOX, 1, 10, 229, 84, 95, STR_MUSIC, STR_NONE }, // enable / disable music - { WWT_DROPDOWN, 1, 155, 299, 98, 109, STR_NONE, STR_NONE }, // title music - { WWT_DROPDOWN_BUTTON, 1, 288, 298, 99, 108, 876, STR_NONE }, - { WWT_SCROLL, 1, 155, 299, 68, 80, 1, STR_NONE }, // master volume - { WWT_SCROLL, 1, 155, 299, 83, 95, 1, STR_NONE }, // music volume + { WWT_DROPDOWN, 1, 10, 299, 53, 64, 865, STR_NONE }, // audio device + { WWT_DROPDOWN_BUTTON, 1, 288, 298, 54, 63, 876, STR_NONE }, + { WWT_CHECKBOX, 1, 10, 229, 69, 80, STR_SOUND, STR_NONE }, // enable / disable sound + { WWT_CHECKBOX, 1, 10, 229, 84, 95, STR_MUSIC, STR_NONE }, // enable / disable music + { WWT_CHECKBOX, 1, 10, 229, 98, 110, STR_AUDIO_FOCUS, STR_NONE }, // enable / disable audio disabled on focus lost + { WWT_DROPDOWN, 1, 155, 299, 112, 124, STR_NONE, STR_NONE }, // title music + { WWT_DROPDOWN_BUTTON, 1, 288, 298, 113, 123, 876, STR_NONE }, + { WWT_SCROLL, 1, 155, 299, 68, 80, 1, STR_NONE }, // master volume + { WWT_SCROLL, 1, 155, 299, 83, 95, 1, STR_NONE }, // music volume { WIDGETS_END }, }; @@ -372,6 +374,7 @@ static uint32 window_options_page_enabled_widgets[] = { (1 << WIDX_SOUND_DROPDOWN) | (1 << WIDX_SOUND_CHECKBOX) | (1 << WIDX_MUSIC_CHECKBOX) | + (1 << WIDX_AUDIO_FOCUS_CHECKBOX) | (1 << WIDX_TITLE_MUSIC) | (1 << WIDX_TITLE_MUSIC_DROPDOWN), @@ -523,6 +526,11 @@ static void window_options_mouseup(rct_window *w, int widgetIndex) config_save_default(); window_invalidate(w); break; + case WIDX_AUDIO_FOCUS_CHECKBOX: + gConfigSound.audio_focus = !gConfigSound.audio_focus; + config_save_default(); + window_invalidate(w); + break; } break; @@ -1154,6 +1162,7 @@ static void window_options_invalidate(rct_window *w) widget_set_checkbox_value(w, WIDX_SOUND_CHECKBOX, gConfigSound.sound); widget_set_checkbox_value(w, WIDX_MUSIC_CHECKBOX, gConfigSound.ride_music); + widget_set_checkbox_value(w, WIDX_AUDIO_FOCUS_CHECKBOX, gConfigSound.audio_focus); if(w->frame_no == 0){ // initialize only on first frame, otherwise the scrollbars wont be able to be modified widget = &window_options_audio_widgets[WIDX_MASTER_VOLUME]; @@ -1169,6 +1178,7 @@ static void window_options_invalidate(rct_window *w) window_options_audio_widgets[WIDX_SOUND_DROPDOWN].type = WWT_DROPDOWN_BUTTON; window_options_audio_widgets[WIDX_SOUND_CHECKBOX].type = WWT_CHECKBOX; window_options_audio_widgets[WIDX_MUSIC_CHECKBOX].type = WWT_CHECKBOX; + window_options_audio_widgets[WIDX_AUDIO_FOCUS_CHECKBOX].type = WWT_CHECKBOX; window_options_audio_widgets[WIDX_TITLE_MUSIC].type = WWT_DROPDOWN; window_options_audio_widgets[WIDX_TITLE_MUSIC_DROPDOWN].type = WWT_DROPDOWN_BUTTON; window_options_audio_widgets[WIDX_MASTER_VOLUME].type = WWT_SCROLL; From 58aeb6c911e014000b08c62d4496cf4a455fa201 Mon Sep 17 00:00:00 2001 From: medsouz Date: Tue, 11 Aug 2015 07:17:06 -0400 Subject: [PATCH 4/5] Changed the wrong boolean I should probably sleep more... --- src/config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.c b/src/config.c index f5186b7d30..459eba5c33 100644 --- a/src/config.c +++ b/src/config.c @@ -206,8 +206,8 @@ config_property_definition _interfaceDefinitions[] = { config_property_definition _soundDefinitions[] = { { offsetof(sound_configuration, title_music), "title_music", CONFIG_VALUE_TYPE_UINT8, 2, NULL }, { offsetof(sound_configuration, sound), "sound", CONFIG_VALUE_TYPE_BOOLEAN, true, NULL }, - { offsetof(sound_configuration, ride_music), "ride_music", CONFIG_VALUE_TYPE_BOOLEAN, false, NULL }, - { offsetof(sound_configuration, audio_focus), "audio_focus", CONFIG_VALUE_TYPE_BOOLEAN, true, NULL }, + { offsetof(sound_configuration, ride_music), "ride_music", CONFIG_VALUE_TYPE_BOOLEAN, true, NULL }, + { offsetof(sound_configuration, audio_focus), "audio_focus", CONFIG_VALUE_TYPE_BOOLEAN, false, NULL }, { offsetof(sound_configuration, master_volume), "master_volume", CONFIG_VALUE_TYPE_UINT8, 100, NULL }, { offsetof(sound_configuration, music_volume), "music_volume", CONFIG_VALUE_TYPE_UINT8, 100, NULL }, { offsetof(sound_configuration, device), "audio_device", CONFIG_VALUE_TYPE_STRING, { .value_string = NULL }, NULL }, From e0e9dedb8b517524cb439e499d1cadec6fcb3dc0 Mon Sep 17 00:00:00 2001 From: medsouz Date: Tue, 11 Aug 2015 07:30:29 -0400 Subject: [PATCH 5/5] Moved strings to english_uk.txt --- data/language/english_uk.txt | 1 + data/language/english_us.txt | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/data/language/english_uk.txt b/data/language/english_uk.txt index 05125c5d16..00b93db9bc 100644 --- a/data/language/english_uk.txt +++ b/data/language/english_uk.txt @@ -3826,3 +3826,4 @@ STR_5486 :{BLACK}{COMMA16} STR_5487 :{SMALLFONT}{BLACK}Show recent messages STR_5488 :No entrance STR_5489 :{SMALLFONT}{BLACK}Show only tracked guests +STR_5490 :Disable audio on focus loss diff --git a/data/language/english_us.txt b/data/language/english_us.txt index 81cc076e75..1d2ceb24f3 100644 --- a/data/language/english_us.txt +++ b/data/language/english_us.txt @@ -3830,4 +3830,3 @@ STR_5485 :{SMALLFONT}{STRING} STR_5486 :{BLACK}{COMMA16} STR_5487 :{SMALLFONT}{BLACK}Show recent messages STR_5488 :No entrance -STR_5490 :Disable audio on focus loss