From f46657ec5a23e9ff440b603fbf8ffd55e6aa4e84 Mon Sep 17 00:00:00 2001 From: Nils Wallménius Date: Wed, 30 May 2007 17:57:32 +0000 Subject: Move the setvol wrapper function to misc.c and use it in more places instead of doing the same checks everywhere git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13524 a1c6a512-1295-4272-9138-f99709370657 --- apps/gui/gwps-common.c | 10 ---------- apps/gui/gwps-common.h | 1 - apps/gui/list.c | 8 +------- apps/misc.c | 15 +++++++++++++++ apps/misc.h | 3 +++ apps/recorder/radio.c | 10 ++-------- apps/recorder/recording.c | 12 ++++-------- 7 files changed, 25 insertions(+), 34 deletions(-) diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index 2cdb92d964..2e8f7841c0 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c @@ -126,16 +126,6 @@ void fade(bool fade_in) } } -/* set volume */ -void setvol(void) -{ - if (global_settings.volume < sound_min(SOUND_VOLUME)) - global_settings.volume = sound_min(SOUND_VOLUME); - if (global_settings.volume > sound_max(SOUND_VOLUME)) - global_settings.volume = sound_max(SOUND_VOLUME); - sound_set_volume(global_settings.volume); - settings_save(); -} /* return true if screen restore is needed return false otherwise */ diff --git a/apps/gui/gwps-common.h b/apps/gui/gwps-common.h index 1203113be1..76555c1c06 100644 --- a/apps/gui/gwps-common.h +++ b/apps/gui/gwps-common.h @@ -25,7 +25,6 @@ void fade(bool fade_in); bool gui_wps_display(void); -void setvol(void); bool update_onvol_change(struct gui_wps * gwps); bool update(struct gui_wps *gwps); bool ffwd_rew(int button); diff --git a/apps/gui/list.c b/apps/gui/list.c index 4a72c3e505..f4cb607260 100644 --- a/apps/gui/list.c +++ b/apps/gui/list.c @@ -876,13 +876,7 @@ unsigned gui_synclist_do_button(struct gui_synclist * lists, /* up two because the falthrough brings it down one */ case ACTION_LIST_VOLDOWN: global_settings.volume--; - - if (global_settings.volume < sound_min(SOUND_VOLUME)) - global_settings.volume = sound_min(SOUND_VOLUME); - if (global_settings.volume > sound_max(SOUND_VOLUME)) - global_settings.volume = sound_max(SOUND_VOLUME); - sound_set_volume(global_settings.volume); - settings_save(); + setvol(); return button; #endif case ACTION_STD_PREV: diff --git a/apps/misc.c b/apps/misc.c index 3010104cd3..0113825ac4 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -47,6 +47,7 @@ #include "splash.h" #include "tagcache.h" #include "scrobbler.h" +#include "sound.h" #ifdef HAVE_MMC #include "ata_mmc.h" #endif @@ -969,3 +970,17 @@ void check_bootfile(bool do_rolo) } #endif #endif + +/* check range, set volume and save settings */ +void setvol(void) +{ + const int min_vol = sound_min(SOUND_VOLUME); + const int max_vol = sound_max(SOUND_VOLUME); + if (global_settings.volume < min_vol) + global_settings.volume = min_vol; + if (global_settings.volume > max_vol) + global_settings.volume = max_vol; + sound_set_volume(global_settings.volume); + settings_save(); +} + diff --git a/apps/misc.h b/apps/misc.h index 959674fefd..926170ebe5 100644 --- a/apps/misc.h +++ b/apps/misc.h @@ -106,4 +106,7 @@ void check_bootfile(bool do_rolo); #endif #endif +/* check range, set volume and save settings */ +void setvol(void); + #endif /* MISC_H */ diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c index 79febc9039..575b887c2f 100644 --- a/apps/recorder/radio.c +++ b/apps/recorder/radio.c @@ -657,21 +657,15 @@ int radio_screen(void) case ACTION_SETTINGS_INC: case ACTION_SETTINGS_INCREPEAT: global_settings.volume++; - if(global_settings.volume > sound_max(SOUND_VOLUME)) - global_settings.volume = sound_max(SOUND_VOLUME); - sound_set_volume(global_settings.volume); + setvol(); update_screen = true; - settings_save(); break; case ACTION_SETTINGS_DEC: case ACTION_SETTINGS_DECREPEAT: global_settings.volume--; - if(global_settings.volume < sound_min(SOUND_VOLUME)) - global_settings.volume = sound_min(SOUND_VOLUME); - sound_set_volume(global_settings.volume); + setvol(); update_screen = true; - settings_save(); break; case ACTION_FM_PLAY: diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c index 0323ae12ff..d7bea6f898 100644 --- a/apps/recorder/recording.c +++ b/apps/recorder/recording.c @@ -1052,10 +1052,8 @@ bool recording_screen(bool no_source) switch(cursor) { case 0: - if(global_settings.volume < - sound_max(SOUND_VOLUME)) - global_settings.volume++; - sound_set_volume(global_settings.volume); + global_settings.volume++; + setvol(); break; case 1: if(global_settings.rec_source == AUDIO_SRC_MIC) @@ -1120,10 +1118,8 @@ bool recording_screen(bool no_source) switch(cursor) { case 0: - if(global_settings.volume > - sound_min(SOUND_VOLUME)) - global_settings.volume--; - sound_set_volume(global_settings.volume); + global_settings.volume--; + setvol(); break; case 1: if(global_settings.rec_source == AUDIO_SRC_MIC) -- cgit v1.2.3