FS#11931 - Do a short rewind when playback is paused Patch by John Morris. --- apps/gui/wps.c | 31 +++++++++++++++++++++++-------- apps/gui/wps.h | 4 ++++ apps/lang/english.lang | 25 ++++++++++++++++++------- apps/menus/playback_menu.c | 5 +++-- apps/misc.c | 27 +++++++-------------------- apps/settings.h | 2 +- apps/settings_list.c | 6 +++--- 7 files changed, 59 insertions(+), 41 deletions(-) diff --git a/apps/gui/wps.c b/apps/gui/wps.c index c33268e..e5c2e98 100644 --- a/apps/gui/wps.c +++ b/apps/gui/wps.c @@ -119,6 +119,27 @@ char* wps_default_skin(enum screen_type screen) return skin_buf[screen]; } +void pause_action(bool may_fade, bool updatewps) +{ + int32_t newpos; + if (may_fade && global_settings.fade_on_stop) + fade (false, updatewps); + else + audio_pause(); + + newpos = audio_current_track()->elapsed + - global_settings.pause_rewind * 1000; + audio_ff_rewind(newpos > 0 ? newpos : 0); +} + +void unpause_action(bool may_fade, bool updatewps) +{ + if (may_fade && global_settings.fade_on_stop) + fade (true, updatewps); + else + audio_resume (); +} + void fade(bool fade_in, bool updatewps) { int fp_global_vol = global_settings.volume << 8; @@ -663,18 +684,12 @@ void wps_do_playpause(bool updatewps) if ( state->paused ) { state->paused = false; - if ( global_settings.fade_on_stop ) - fade(true, updatewps); - else - audio_resume(); + unpause_action(true, updatewps); } else { state->paused = true; - if ( global_settings.fade_on_stop ) - fade(false, updatewps); - else - audio_pause(); + pause_action(true, updatewps); settings_save(); #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF) call_storage_idle_notifys(true); /* make sure resume info is saved */ diff --git a/apps/gui/wps.h b/apps/gui/wps.h index 7438f1a..87a5a23 100644 --- a/apps/gui/wps.h +++ b/apps/gui/wps.h @@ -30,6 +30,10 @@ void wps_data_load(enum screen_type, const char *, bool); void gui_sync_wps_init(void) INIT_ATTR; +/* fade (if enabled) and pause the audio, optionally rewind a little */ +void pause_action(bool may_fade, bool updatewps); +void unpause_action(bool may_fade, bool updatewps); + /* fades the volume, e.g. on pause or stop */ void fade(bool fade_in, bool updatewps); diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 400ab7c..0d5f56d 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang @@ -2069,19 +2069,16 @@ id: LANG_HEADPHONE_UNPLUG_RW - desc: in pause_phones_menu. + desc: deprecated user: core - *: none - headphone_detection: "Duration to Rewind" + *: "" - *: none - headphone_detection: "Duration to Rewind" + *: "" - *: none - headphone_detection: "Duration to Rewind" + *: "" @@ -12744,3 +12741,17 @@ *: "In custom directories only" + + id: LANG_PAUSE_REWIND + desc: Seconds to rewind when rewind on pause is enabled. + user: core + + *: "Rewind on Pause" + + + *: "Rewind on Pause" + + + *: "Rewind on Pause" + + diff --git a/apps/menus/playback_menu.c b/apps/menus/playback_menu.c index 9ed0bc5..681cf53 100644 --- a/apps/menus/playback_menu.c +++ b/apps/menus/playback_menu.c @@ -169,10 +169,9 @@ MENUITEM_SETTING(cuesheet, &global_settings.cuesheet, cuesheet_callback); #ifdef HAVE_HEADPHONE_DETECTION MENUITEM_SETTING(unplug_mode, &global_settings.unplug_mode, NULL); -MENUITEM_SETTING(unplug_rw, &global_settings.unplug_rw, NULL); MENUITEM_SETTING(unplug_autoresume, &global_settings.unplug_autoresume, NULL); MAKE_MENU(unplug_menu, ID2P(LANG_HEADPHONE_UNPLUG), 0, Icon_NOICON, - &unplug_mode, &unplug_rw, &unplug_autoresume); + &unplug_mode, &unplug_autoresume); #endif MENUITEM_SETTING(skip_length, &global_settings.skip_length, NULL); @@ -180,6 +179,7 @@ MENUITEM_SETTING(prevent_skip, &global_settings.prevent_skip, NULL); #if CONFIG_CODEC == SWCODEC MENUITEM_SETTING(resume_rewind, &global_settings.resume_rewind, NULL); #endif +MENUITEM_SETTING(pause_rewind, &global_settings.pause_rewind, NULL); MAKE_MENU(playback_settings,ID2P(LANG_PLAYBACK),0, Icon_Playback_menu, @@ -210,6 +210,7 @@ MAKE_MENU(playback_settings,ID2P(LANG_PLAYBACK),0, #if CONFIG_CODEC == SWCODEC &resume_rewind, #endif + &pause_rewind, ); static int playback_callback(int action,const struct menu_item_ex *this_item) diff --git a/apps/misc.c b/apps/misc.c index e4a5c42..75ed6e7 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -451,10 +451,7 @@ static void car_adapter_mode_processing(bool inserted) if ((audio_status() & AUDIO_STATUS_PLAY) && !(audio_status() & AUDIO_STATUS_PAUSE)) { - if (global_settings.fade_on_stop) - fade(false, false); - else - audio_pause(); + pause_action(true, true); } waiting_to_resume_play = false; } @@ -492,28 +489,18 @@ static void unplug_change(bool inserted) int audio_stat = audio_status(); if (inserted) { + backlight_on(); if ((audio_stat & AUDIO_STATUS_PLAY) && headphone_caused_pause && global_settings.unplug_mode > 1 ) - audio_resume(); - backlight_on(); + unpause_action(true, true); headphone_caused_pause = false; } else { if ((audio_stat & AUDIO_STATUS_PLAY) && !(audio_stat & AUDIO_STATUS_PAUSE)) { headphone_caused_pause = true; - audio_pause(); - - if (global_settings.unplug_rw) - { - if (audio_current_track()->elapsed > - (unsigned long)(global_settings.unplug_rw*1000)) - audio_ff_rewind(audio_current_track()->elapsed - - (global_settings.unplug_rw*1000)); - else - audio_ff_rewind(0); - } + pause_action(false, false); } } } @@ -578,7 +565,7 @@ long default_event_handler_ex(long event, void (*callback)(void *), void *parame return SYS_CHARGER_DISCONNECTED; case SYS_CAR_ADAPTER_RESUME: - audio_resume(); + unpause_action(true, true); return SYS_CAR_ADAPTER_RESUME; #endif #ifdef HAVE_HOTSWAP_STORAGE_AS_MAIN @@ -655,9 +642,9 @@ long default_event_handler_ex(long event, void (*callback)(void *), void *parame if (status & AUDIO_STATUS_PLAY) { if (status & AUDIO_STATUS_PAUSE) - audio_resume(); + unpause_action(true, true); else - audio_pause(); + pause_action(true, true); } else if (playlist_resume() != -1) diff --git a/apps/settings.h b/apps/settings.h index 0734cf0..8802164 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -482,9 +482,9 @@ struct user_settings int touchpad_sensitivity; #endif + int pause_rewind; /* time in s to rewind when pausing */ #ifdef HAVE_HEADPHONE_DETECTION int unplug_mode; /* pause on headphone unplug */ - int unplug_rw; /* time in s to rewind when pausing */ bool unplug_autoresume; /* disable auto-resume if no phones */ #endif diff --git a/apps/settings_list.c b/apps/settings_list.c index 7f2cf38..4098d82 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -1537,13 +1537,13 @@ const struct settings_list settings[] = { "pause on headphone unplug", "off,pause,pause and resume", NULL, 3, ID2P(LANG_OFF), ID2P(LANG_PAUSE), ID2P(LANG_HEADPHONE_UNPLUG_RESUME)), - INT_SETTING(0, unplug_rw, LANG_HEADPHONE_UNPLUG_RW, 0, - "rewind duration on pause", UNIT_SEC, 0, 15, 1, NULL, NULL, - NULL), OFFON_SETTING(0, unplug_autoresume, LANG_HEADPHONE_UNPLUG_DISABLE_AUTORESUME, false, "disable autoresume if phones not present",NULL), #endif + INT_SETTING(0, pause_rewind, LANG_PAUSE_REWIND, 0, + "rewind duration on pause", UNIT_SEC, 0, 15, 1, NULL, NULL, + NULL), #if CONFIG_TUNER CHOICE_SETTING(0, fm_region, LANG_FM_REGION, 0, "fm_region", "eu,us,jp,kr,it,wo", set_radio_region, 6, -- 1.7.1