1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Jerome Kuptz
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
30 #include "backlight.h"
33 #include "filetypes.h"
36 #include "skin_engine/skin_engine.h"
37 #include "mp3_playback.h"
44 #ifdef HAVE_LCD_BITMAP
46 #include "peakmeter.h"
57 #include "ata_idle_notify.h"
58 #include "root_menu.h"
60 #include "quickscreen.h"
61 #include "pitchscreen.h"
62 #include "appevents.h"
65 #include "option_select.h"
67 #include "playlist_viewer.h"
69 #include "statusbar-skinned.h"
71 #define RESTORE_WPS_INSTANTLY 0l
72 #define RESTORE_WPS_NEXT_SECOND ((long)(HZ+current_tick))
74 #define FF_REWIND_MAX_PERCENT 3 /* cap ff/rewind step size at max % of file */
75 /* 3% of 30min file == 54s step size */
76 #define MIN_FF_REWIND_STEP 500
78 /* currently only one wps_state is needed, initialize to 0 */
79 struct wps_state wps_state
= { .id3
= NULL
};
80 static struct gui_wps gui_wps
[NB_SCREENS
] = {{ .data
= NULL
}};
81 static struct wps_data wps_datas
[NB_SCREENS
] = {{ .wps_loaded
= 0 }};
82 static struct wps_sync_data wps_sync_data
= { .do_full_update
= false };
84 /* initial setup of wps_data */
85 static void wps_state_init(void);
86 static void track_changed_callback(void *param
);
87 static void nextid3available_callback(void* param
);
89 #define WPS_DEFAULTCFG WPS_DIR "/rockbox_default.wps"
90 #ifdef HAVE_REMOTE_LCD
91 #define RWPS_DEFAULTCFG WPS_DIR "/rockbox_default.rwps"
92 #define DEFAULT_WPS(screen) ((screen) == SCREEN_MAIN ? \
93 WPS_DEFAULTCFG:RWPS_DEFAULTCFG)
95 #define DEFAULT_WPS(screen) (WPS_DEFAULTCFG)
98 void wps_data_load(enum screen_type screen
, const char *buf
, bool isfile
)
103 screens
[screen
].backdrop_unload(BACKDROP_SKIN_WPS
);
108 * Hardcode loading WPS_DEFAULTCFG to cause a reset ideally this
109 * wants to be a virtual file. Feel free to modify dirbrowse()
110 * if you're feeling brave.
113 if (buf
&& ! strcmp(buf
, DEFAULT_WPS(screen
)) )
115 #ifdef HAVE_REMOTE_LCD
116 if (screen
== SCREEN_REMOTE
)
117 global_settings
.rwps_file
[0] = '\0';
120 global_settings
.wps_file
[0] = '\0';
124 #endif /* __PCTOOL__ */
126 loaded_ok
= buf
&& skin_data_load(screen
, gui_wps
[screen
].data
, buf
, isfile
);
128 if (!loaded_ok
) /* load the hardcoded default */
130 char *skin_buf
[NB_SCREENS
] = {
131 #ifdef HAVE_LCD_BITMAP
132 "%s%?it<%?in<%in. |>%it|%fn>\n"
133 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
134 "%s%?id<%id|%?d1<%d1|(root)>> %?iy<(%iy)|>\n\n"
135 "%al%pc/%pt%ar[%pp:%pe]\n"
136 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
139 "%s%pp/%pe: %?it<%it|%fn> - %?ia<%ia|%d2> - %?id<%id|%d1>\n"
142 #ifdef HAVE_REMOTE_LCD
143 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
144 "%s%?it<%?in<%in. |>%it|%fn>\n"
145 "%al%pc/%pt%ar[%pp:%pe]\n"
146 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
150 skin_data_load(screen
, gui_wps
[screen
].data
, skin_buf
[screen
], false);
154 void fade(bool fade_in
, bool updatewps
)
156 int fp_global_vol
= global_settings
.volume
<< 8;
157 int fp_min_vol
= sound_min(SOUND_VOLUME
) << 8;
158 int fp_step
= (fp_global_vol
- fp_min_vol
) / 30;
160 wps_state
.is_fading
= !fade_in
;
163 int fp_volume
= fp_min_vol
;
165 /* zero out the sound */
166 sound_set_volume(fp_min_vol
>> 8);
168 sleep(HZ
/10); /* let audio thread run */
171 while (fp_volume
< fp_global_vol
- fp_step
) {
172 fp_volume
+= fp_step
;
173 sound_set_volume(fp_volume
>> 8);
177 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
181 sound_set_volume(global_settings
.volume
);
185 int fp_volume
= fp_global_vol
;
187 while (fp_volume
> fp_min_vol
+ fp_step
) {
188 fp_volume
-= fp_step
;
189 sound_set_volume(fp_volume
>> 8);
193 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
198 wps_state
.is_fading
= false;
199 #if CONFIG_CODEC != SWCODEC
201 /* let audio thread run and wait for the mas to run out of data */
202 while (!mp3_pause_done())
207 /* reset volume to what it was before the fade */
208 sound_set_volume(global_settings
.volume
);
212 static bool update_onvol_change(struct gui_wps
* gwps
)
214 skin_update(gwps
, WPS_REFRESH_NON_STATIC
);
216 #ifdef HAVE_LCD_CHARCELLS
217 splashf(0, "Vol: %3d dB",
218 sound_val2phys(SOUND_VOLUME
, global_settings
.volume
));
225 bool ffwd_rew(int button
)
227 unsigned int step
= 0; /* current ff/rewind step */
228 unsigned int max_step
= 0; /* maximum ff/rewind step */
229 int ff_rewind_count
= 0; /* current ff/rewind count (in ticks) */
230 int direction
= -1; /* forward=1 or backward=-1 */
234 const long ff_rw_accel
= (global_settings
.ff_rewind_accel
+ 3);
236 if (button
== ACTION_NONE
)
238 status_set_ffmode(0);
245 case ACTION_WPS_SEEKFWD
:
247 case ACTION_WPS_SEEKBACK
:
248 if (wps_state
.ff_rewind
)
252 /* fast forwarding, calc max step relative to end */
253 max_step
= (wps_state
.id3
->length
-
254 (wps_state
.id3
->elapsed
+
256 FF_REWIND_MAX_PERCENT
/ 100;
260 /* rewinding, calc max step relative to start */
261 max_step
= (wps_state
.id3
->elapsed
+ ff_rewind_count
) *
262 FF_REWIND_MAX_PERCENT
/ 100;
265 max_step
= MAX(max_step
, MIN_FF_REWIND_STEP
);
270 ff_rewind_count
+= step
* direction
;
272 /* smooth seeking by multiplying step by: 1 + (2 ^ -accel) */
273 step
+= step
>> ff_rw_accel
;
277 if ( (audio_status() & AUDIO_STATUS_PLAY
) &&
278 wps_state
.id3
&& wps_state
.id3
->length
)
280 if (!wps_state
.paused
)
281 #if (CONFIG_CODEC == SWCODEC)
282 audio_pre_ff_rewind();
286 #if CONFIG_KEYPAD == PLAYER_PAD
288 gui_wps
[i
].display
->stop_scroll();
291 status_set_ffmode(STATUS_FASTFORWARD
);
293 status_set_ffmode(STATUS_FASTBACKWARD
);
295 wps_state
.ff_rewind
= true;
297 step
= 1000 * global_settings
.ff_rewind_min_step
;
304 if ((wps_state
.id3
->elapsed
+ ff_rewind_count
) >
305 wps_state
.id3
->length
)
306 ff_rewind_count
= wps_state
.id3
->length
-
307 wps_state
.id3
->elapsed
;
310 if ((int)(wps_state
.id3
->elapsed
+ ff_rewind_count
) < 0)
311 ff_rewind_count
= -wps_state
.id3
->elapsed
;
314 /* set the wps state ff_rewind_count so the progess info
316 wps_state
.ff_rewind_count
= (wps_state
.wps_time_countup
== false)?
317 ff_rewind_count
:-ff_rewind_count
;
320 skin_update(&gui_wps
[i
],
321 WPS_REFRESH_PLAYER_PROGRESS
|
322 WPS_REFRESH_DYNAMIC
);
327 case ACTION_WPS_STOPSEEK
:
328 wps_state
.id3
->elapsed
= wps_state
.id3
->elapsed
+ff_rewind_count
;
329 audio_ff_rewind(wps_state
.id3
->elapsed
);
330 wps_state
.ff_rewind_count
= 0;
331 wps_state
.ff_rewind
= false;
332 status_set_ffmode(0);
333 #if (CONFIG_CODEC != SWCODEC)
334 if (!wps_state
.paused
)
337 #ifdef HAVE_LCD_CHARCELLS
339 skin_update(&gui_wps
[i
], WPS_REFRESH_ALL
);
345 if(default_event_handler(button
) == SYS_USB_CONNECTED
) {
346 status_set_ffmode(0);
354 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_BLOCK
);
355 #ifdef HAVE_TOUCHSCREEN
356 if (button
== ACTION_TOUCHSCREEN
)
357 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
365 void display_keylock_text(bool locked
)
369 gui_wps
[i
].display
->stop_scroll();
371 splash(HZ
, locked
? ID2P(LANG_KEYLOCK_ON
) : ID2P(LANG_KEYLOCK_OFF
));
377 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
378 static void gwps_caption_backlight(struct wps_state
*state
)
380 if (state
&& state
->id3
)
382 #ifdef HAVE_BACKLIGHT
383 if (global_settings
.caption_backlight
)
385 /* turn on backlight n seconds before track ends, and turn it off n
386 seconds into the new track. n == backlight_timeout, or 5s */
387 int n
= global_settings
.backlight_timeout
* 1000;
390 n
= 5000; /* use 5s if backlight is always on or off */
392 if (((state
->id3
->elapsed
< 1000) ||
393 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
394 (state
->paused
== false))
398 #ifdef HAVE_REMOTE_LCD
399 if (global_settings
.remote_caption_backlight
)
401 /* turn on remote backlight n seconds before track ends, and turn it
402 off n seconds into the new track. n == remote_backlight_timeout,
404 int n
= global_settings
.remote_backlight_timeout
* 1000;
407 n
= 5000; /* use 5s if backlight is always on or off */
409 if (((state
->id3
->elapsed
< 1000) ||
410 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
411 (state
->paused
== false))
412 remote_backlight_on();
420 static void change_dir(int direction
)
422 if (global_settings
.prevent_skip
)
427 else if (direction
> 0)
429 /* prevent the next dir to immediatly start being ffw'd */
430 action_wait_for_release();
433 static void prev_track(unsigned long skip_thresh
)
435 if (wps_state
.id3
->elapsed
< skip_thresh
)
442 if (wps_state
.id3
->cuesheet
)
444 curr_cuesheet_skip(wps_state
.id3
->cuesheet
, -1, wps_state
.id3
->elapsed
);
448 if (!wps_state
.paused
)
449 #if (CONFIG_CODEC == SWCODEC)
450 audio_pre_ff_rewind();
457 #if (CONFIG_CODEC != SWCODEC)
458 if (!wps_state
.paused
)
464 static void next_track(void)
466 /* take care of if we're playing a cuesheet */
467 if (wps_state
.id3
->cuesheet
)
469 if (curr_cuesheet_skip(wps_state
.id3
->cuesheet
, 1, wps_state
.id3
->elapsed
))
471 /* if the result was false, then we really want
472 to skip to the next track */
480 static void play_hop(int direction
)
482 long step
= global_settings
.skip_length
*1000;
483 long elapsed
= wps_state
.id3
->elapsed
;
484 long remaining
= wps_state
.id3
->length
- elapsed
;
490 prev_track(DEFAULT_SKIP_TRESH
);
493 else if (remaining
< DEFAULT_SKIP_TRESH
*2)
499 elapsed
+= (remaining
- DEFAULT_SKIP_TRESH
*2);
501 else if (!global_settings
.prevent_skip
&&
503 (direction
> 0 && step
>= remaining
) ||
504 (direction
< 0 && elapsed
< DEFAULT_SKIP_TRESH
)))
505 { /* Do normal track skipping */
508 else if (direction
< 0)
509 prev_track(DEFAULT_SKIP_TRESH
);
512 else if (direction
== 1 && step
>= remaining
)
514 #if CONFIG_CODEC == SWCODEC
515 if(global_settings
.beep
)
516 pcmbuf_beep(1000, 150, 1500*global_settings
.beep
);
520 else if ((direction
== -1 && elapsed
< step
))
526 elapsed
+= step
* direction
;
528 if((audio_status() & AUDIO_STATUS_PLAY
) && !wps_state
.paused
)
530 #if (CONFIG_CODEC == SWCODEC)
531 audio_pre_ff_rewind();
536 audio_ff_rewind(wps_state
.id3
->elapsed
= elapsed
);
537 #if (CONFIG_CODEC != SWCODEC)
538 if (!wps_state
.paused
)
544 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
546 * If the user is unable to see the wps, because the display is deactivated,
547 * we suppress updates until the wps is activated again (the lcd driver will
548 * call this hook to issue an instant update)
550 static void wps_lcd_activation_hook(void *param
)
553 wps_sync_data
.do_full_update
= true;
554 /* force timeout in wps main loop, so that the update is instantly */
555 queue_post(&button_queue
, BUTTON_NONE
, 0);
559 static void gwps_leave_wps(void)
565 gui_wps
[i
].display
->stop_scroll();
567 gui_wps
[i
].display
->backdrop_show(BACKDROP_MAIN
);
570 #ifdef HAVE_LCD_BITMAP
572 if (gui_wps
[i
].data
->wps_sb_tag
)
573 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
574 else if (statusbar_position(i
) != STATUSBAR_OFF
)
577 viewportmanager_theme_undo(i
, draw
);
581 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
582 /* Play safe and unregister the hook */
583 remove_event(LCD_EVENT_ACTIVATION
, wps_lcd_activation_hook
);
585 /* unhandle statusbar update delay */
586 sb_skin_set_update_delay(DEFAULT_UPDATE_DELAY
);
590 * display the wps on entering or restoring */
591 static void gwps_enter_wps(void)
596 struct gui_wps
*gwps
= &gui_wps
[i
];
597 struct screen
*display
= gwps
->display
;
598 #ifdef HAVE_LCD_BITMAP
600 if (gui_wps
[i
].data
->wps_sb_tag
)
601 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
602 else if (statusbar_position(i
) != STATUSBAR_OFF
)
605 viewportmanager_theme_enable(i
, draw
, NULL
);
607 display
->stop_scroll();
608 /* Update the values in the first (default) viewport - in case the user
609 has modified the statusbar or colour settings */
611 if (display
->depth
> 1)
613 struct viewport
*vp
= &find_viewport(VP_DEFAULT_LABEL
, gwps
->data
)->vp
;
614 vp
->fg_pattern
= display
->get_foreground();
615 vp
->bg_pattern
= display
->get_background();
617 display
->backdrop_show(BACKDROP_SKIN_WPS
);
619 /* make the backdrop actually take effect */
620 display
->clear_display();
621 skin_update(gwps
, WPS_REFRESH_ALL
);
623 /* force statusbar/skin update since we just cleared the whole screen */
624 send_event(GUI_EVENT_ACTIONUPDATE
, (void*)1);
627 #ifdef HAVE_TOUCHSCREEN
628 int wps_get_touchaction(struct wps_data
*data
)
632 int type
= action_get_touchscreen_press(&x
, &y
);
633 static int last_action
= ACTION_NONE
;
634 struct touchregion
*r
;
635 bool repeated
= (type
== BUTTON_REPEAT
);
636 bool released
= (type
== BUTTON_REL
);
637 struct skin_token_list
*regions
= data
->touchregions
;
640 r
= (struct touchregion
*)regions
->token
->value
.data
;
641 /* make sure this region's viewport is visible */
642 if (r
->wvp
->hidden_flags
&VP_DRAW_HIDDEN
)
644 regions
= regions
->next
;
647 /* check if it's inside this viewport */
648 if (viewport_point_within_vp(&(r
->wvp
->vp
), x
, y
))
649 { /* reposition the touch inside the viewport since touchregions
650 * are relative to a preceding viewport */
651 vx
= x
- r
->wvp
->vp
.x
;
652 vy
= y
- r
->wvp
->vp
.y
;
653 /* now see if the point is inside this region */
654 if (vx
>= r
->x
&& vx
< r
->x
+r
->width
&&
655 vy
>= r
->y
&& vy
< r
->y
+r
->height
)
657 /* reposition the touch within the area */
663 case WPS_TOUCHREGION_ACTION
:
664 if ((repeated
&& r
->repeat
) || (released
&& !r
->repeat
))
666 last_action
= r
->action
;
670 case WPS_TOUCHREGION_SCROLLBAR
:
671 if(r
->width
> r
->height
)
673 wps_state
.id3
->elapsed
= (vx
*
674 wps_state
.id3
->length
) / r
->width
;
677 wps_state
.id3
->elapsed
= (vy
*
678 wps_state
.id3
->length
) / r
->height
;
680 if (!wps_state
.paused
)
681 #if (CONFIG_CODEC == SWCODEC)
682 audio_pre_ff_rewind();
686 audio_ff_rewind(wps_state
.id3
->elapsed
);
687 #if (CONFIG_CODEC != SWCODEC)
688 if (!wps_state
.paused
)
692 case WPS_TOUCHREGION_VOLUME
:
694 const int min_vol
= sound_min(SOUND_VOLUME
);
695 const int max_vol
= sound_max(SOUND_VOLUME
);
696 if(r
->width
> r
->height
)
698 global_settings
.volume
= (vx
*
699 (max_vol
- min_vol
)) / r
->width
;
702 global_settings
.volume
= (vy
*
703 (max_vol
-min_vol
)) / r
->height
;
705 global_settings
.volume
+= min_vol
;
707 return ACTION_REDRAW
;
712 regions
= regions
->next
;
715 if ((last_action
== ACTION_WPS_SEEKBACK
|| last_action
== ACTION_WPS_SEEKFWD
))
716 return ACTION_WPS_STOPSEEK
;
717 last_action
= ACTION_TOUCHSCREEN
;
718 return ACTION_TOUCHSCREEN
;
721 /* The WPS can be left in two ways:
722 * a) call a function, which draws over the wps. In this case, the wps
723 * will be still active (i.e. the below function didn't return)
724 * b) return with a value evaluated by root_menu.c, in this case the wps
725 * is really left, and root_menu will handle the next screen
727 * In either way, call gwps_leave_wps(), in order to restore the correct
728 * "main screen" backdrops and statusbars
730 long gui_wps_show(void)
734 long restoretimer
= RESTORE_WPS_INSTANTLY
; /* timer to delay screen redraw temporarily */
736 bool bookmark
= false;
738 bool vol_changed
= false;
740 long last_left
= 0, last_right
= 0;
742 #ifdef HAVE_LCD_CHARCELLS
743 status_set_audio(true);
744 status_set_param(false);
747 #ifdef AB_REPEAT_ENABLE
755 bool audio_paused
= (audio_status() & AUDIO_STATUS_PAUSE
)?true:false;
757 /* did someone else (i.e power thread) change audio pause mode? */
758 if (wps_state
.paused
!= audio_paused
) {
759 wps_state
.paused
= audio_paused
;
761 /* if another thread paused audio, we are probably in car mode,
762 about to shut down. lets save the settings. */
763 if (wps_state
.paused
) {
765 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
766 call_storage_idle_notifys(true);
770 #ifdef HAVE_LCD_BITMAP
771 /* when the peak meter is enabled we want to have a
772 few extra updates to make it look smooth. On the
773 other hand we don't want to waste energy if it
778 if(gui_wps
[i
].data
->peak_meter_enabled
)
783 long next_refresh
= current_tick
;
784 long next_big_refresh
= current_tick
+ HZ
/ 5;
785 button
= BUTTON_NONE
;
786 while (TIME_BEFORE(current_tick
, next_big_refresh
)) {
787 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_NOBLOCK
);
788 /* check for restore to not let the peakmeter delay the
789 * initial draw of the wps, don't delay handling of button
791 if (button
!= ACTION_NONE
|| restore
) {
795 sleep(0); /* Sleep until end of current tick. */
797 if (TIME_AFTER(current_tick
, next_refresh
)) {
800 if(gui_wps
[i
].data
->peak_meter_enabled
)
801 skin_update(&gui_wps
[i
], WPS_REFRESH_PEAK_METER
);
802 next_refresh
+= HZ
/ PEAK_METER_FPS
;
809 /* The peak meter is disabled
810 -> no additional screen updates needed */
813 { /* 1 is the minimum timeout which lets other threads run.
814 * audio thread (apprently) needs to run before displaying the wps
815 * or bad things happen with regards to cuesheet
816 * (probably a race condition, on sh at least) */
817 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,
821 /* Exit if audio has stopped playing. This happens e.g. at end of
822 playlist or if using the sleep timer. */
823 if (!(audio_status() & AUDIO_STATUS_PLAY
))
825 #ifdef HAVE_TOUCHSCREEN
826 if (button
== ACTION_TOUCHSCREEN
)
827 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
829 /* The iPods/X5/M5 use a single button for the A-B mode markers,
830 defined as ACTION_WPSAB_SINGLE in their config files. */
831 #ifdef ACTION_WPSAB_SINGLE
832 if (!global_settings
.party_mode
&& ab_repeat_mode_enabled())
834 static int wps_ab_state
= 0;
835 if (button
== ACTION_WPSAB_SINGLE
)
837 switch (wps_ab_state
)
839 case 0: /* set the A spot */
840 button
= ACTION_WPS_ABSETA_PREVDIR
;
842 case 1: /* set the B spot */
843 button
= ACTION_WPS_ABSETB_NEXTDIR
;
846 button
= ACTION_WPS_ABRESET
;
849 wps_ab_state
= (wps_ab_state
+1) % 3;
855 case ACTION_WPS_CONTEXT
:
858 /* if music is stopped in the context menu we want to exit the wps */
859 if (onplay(wps_state
.id3
->path
,
860 FILE_ATTR_AUDIO
, CONTEXT_WPS
) == ONPLAY_MAINMENU
867 case ACTION_WPS_BROWSE
:
868 #ifdef HAVE_LCD_CHARCELLS
869 status_set_record(false);
870 status_set_audio(false);
873 return GO_TO_PREVIOUS_BROWSER
;
877 case ACTION_WPS_PLAY
:
878 if (global_settings
.party_mode
)
880 if ( wps_state
.paused
)
882 wps_state
.paused
= false;
883 if ( global_settings
.fade_on_stop
)
890 wps_state
.paused
= true;
891 if ( global_settings
.fade_on_stop
)
896 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
897 call_storage_idle_notifys(true); /* make sure resume info is saved */
902 case ACTION_WPS_VOLUP
:
903 global_settings
.volume
++;
906 case ACTION_WPS_VOLDOWN
:
907 global_settings
.volume
--;
911 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
912 case ACTION_WPS_SEEKFWD
:
913 if (global_settings
.party_mode
)
915 if (current_tick
-last_right
< HZ
)
917 if (wps_state
.id3
->cuesheet
)
927 ffwd_rew(ACTION_WPS_SEEKFWD
);
928 last_right
= last_left
= 0;
931 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
932 case ACTION_WPS_SEEKBACK
:
933 if (global_settings
.party_mode
)
935 if (current_tick
-last_left
< HZ
)
937 if (wps_state
.id3
->cuesheet
)
939 if (!wps_state
.paused
)
940 #if (CONFIG_CODEC == SWCODEC)
941 audio_pre_ff_rewind();
953 ffwd_rew(ACTION_WPS_SEEKBACK
);
954 last_left
= last_right
= 0;
958 case ACTION_WPS_SKIPPREV
:
959 if (global_settings
.party_mode
)
961 last_left
= current_tick
;
962 #ifdef AB_REPEAT_ENABLE
963 /* if we're in A/B repeat mode and the current position
964 is past the A marker, jump back to the A marker... */
965 if ( ab_repeat_mode_enabled() )
967 if ( ab_after_A_marker(wps_state
.id3
->elapsed
) )
969 ab_jump_to_A_marker();
971 #if (AB_REPEAT_ENABLE == 2)
978 /* ...otherwise, do it normally */
984 OR if skip length set, hop by predetermined amount. */
985 case ACTION_WPS_SKIPNEXT
:
986 if (global_settings
.party_mode
)
988 last_right
= current_tick
;
989 #ifdef AB_REPEAT_ENABLE
990 /* if we're in A/B repeat mode and the current position is
991 before the A marker, jump to the A marker... */
992 if ( ab_repeat_mode_enabled() )
994 if ( ab_before_A_marker(wps_state
.id3
->elapsed
) )
996 ab_jump_to_A_marker();
998 #if (AB_REPEAT_ENABLE == 2)
1005 /* ...otherwise, do it normally */
1009 /* next / prev directories */
1010 /* and set A-B markers if in a-b mode */
1011 case ACTION_WPS_ABSETB_NEXTDIR
:
1012 if (global_settings
.party_mode
)
1014 #if defined(AB_REPEAT_ENABLE)
1015 if (ab_repeat_mode_enabled())
1017 ab_set_B_marker(wps_state
.id3
->elapsed
);
1018 ab_jump_to_A_marker();
1026 case ACTION_WPS_ABSETA_PREVDIR
:
1027 if (global_settings
.party_mode
)
1029 #if defined(AB_REPEAT_ENABLE)
1030 if (ab_repeat_mode_enabled())
1031 ab_set_A_marker(wps_state
.id3
->elapsed
);
1038 /* menu key functions */
1039 case ACTION_WPS_MENU
:
1045 #ifdef HAVE_QUICKSCREEN
1046 case ACTION_WPS_QUICKSCREEN
:
1049 if (quick_screen_quick(button
))
1054 #endif /* HAVE_QUICKSCREEN */
1056 /* screen settings */
1061 if (quick_screen_f3(BUTTON_F3
))
1066 #endif /* BUTTON_F3 */
1069 #ifdef HAVE_PITCHSCREEN
1070 case ACTION_WPS_PITCHSCREEN
:
1073 if (1 == gui_syncpitchscreen_run())
1078 #endif /* HAVE_PITCHSCREEN */
1080 #ifdef AB_REPEAT_ENABLE
1081 /* reset A&B markers */
1082 case ACTION_WPS_ABRESET
:
1083 if (ab_repeat_mode_enabled())
1089 #endif /* AB_REPEAT_ENABLE */
1091 /* stop and exit wps */
1092 case ACTION_WPS_STOP
:
1093 if (global_settings
.party_mode
)
1099 case ACTION_WPS_ID3SCREEN
:
1107 #ifdef HAVE_TOUCHSCREEN
1108 case ACTION_TOUCH_SHUFFLE
: /* toggle shuffle mode */
1110 global_settings
.playlist_shuffle
=
1111 !global_settings
.playlist_shuffle
;
1112 #if CONFIG_CODEC == SWCODEC
1113 dsp_set_replaygain();
1115 if (global_settings
.playlist_shuffle
)
1116 playlist_randomise(NULL
, current_tick
, true);
1118 playlist_sort(NULL
, true);
1121 case ACTION_TOUCH_REPMODE
: /* cycle the repeat mode setting */
1123 const struct settings_list
*rep_setting
=
1124 find_setting(&global_settings
.repeat_mode
, NULL
);
1125 option_select_next_val(rep_setting
, false, true);
1126 audio_flush_and_reload_tracks();
1129 #endif /* HAVE_TOUCHSCREEN */
1130 /* this case is used by the softlock feature
1131 * it requests a full update here */
1133 wps_sync_data
.do_full_update
= true;
1135 case ACTION_NONE
: /* Timeout, do a partial update */
1137 ffwd_rew(button
); /* hopefully fix the ffw/rwd bug */
1139 #ifdef HAVE_RECORDING
1140 case ACTION_WPS_REC
:
1145 default_event_handler(SYS_POWEROFF
);
1147 case ACTION_WPS_VIEW_PLAYLIST
:
1149 if (playlist_viewer()) /* true if USB connected */
1154 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1166 vol_changed
= false;
1170 if(update_onvol_change(&gui_wps
[i
]))
1175 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
1181 ((restoretimer
== RESTORE_WPS_INSTANTLY
) ||
1182 TIME_AFTER(current_tick
, restoretimer
)))
1185 restoretimer
= RESTORE_WPS_INSTANTLY
;
1186 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1187 add_event(LCD_EVENT_ACTIVATION
, false, wps_lcd_activation_hook
);
1189 /* we remove the update delay since it's not very usable in the wps,
1190 * e.g. during volume changing or ffwd/rewind */
1191 sb_skin_set_update_delay(0);
1192 wps_sync_data
.do_full_update
= update
= false;
1195 else if (wps_sync_data
.do_full_update
|| update
)
1197 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
1198 gwps_caption_backlight(&wps_state
);
1202 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1203 /* currently, all remotes are readable without backlight
1204 * so still update those */
1205 if (lcd_active() || (i
!= SCREEN_MAIN
))
1208 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
1211 wps_sync_data
.do_full_update
= false;
1216 #ifdef HAVE_LCD_CHARCELLS
1217 status_set_record(false);
1218 status_set_audio(false);
1220 if (global_settings
.fade_on_stop
)
1224 bookmark_autobookmark();
1226 #ifdef AB_REPEAT_ENABLE
1230 #ifdef HAVE_RECORDING
1231 if (button
== ACTION_WPS_REC
)
1232 return GO_TO_RECSCREEN
;
1234 if (global_settings
.browse_current
)
1235 return GO_TO_PREVIOUS_BROWSER
;
1236 return GO_TO_PREVIOUS
;
1239 if (button
&& !IS_SYSEVENT(button
) )
1242 return GO_TO_ROOT
; /* unreachable - just to reduce compiler warnings */
1245 /* this is called from the playback thread so NO DRAWING! */
1246 static void track_changed_callback(void *param
)
1248 wps_state
.id3
= (struct mp3entry
*)param
;
1249 wps_state
.nid3
= audio_next_track();
1250 if (wps_state
.id3
->cuesheet
)
1252 cue_find_current_track(wps_state
.id3
->cuesheet
, wps_state
.id3
->elapsed
);
1253 cue_spoof_id3(wps_state
.id3
->cuesheet
, wps_state
.id3
);
1255 wps_sync_data
.do_full_update
= true;
1257 static void nextid3available_callback(void* param
)
1260 wps_state
.nid3
= audio_next_track();
1261 wps_sync_data
.do_full_update
= true;
1265 static void wps_state_init(void)
1267 wps_state
.ff_rewind
= false;
1268 wps_state
.paused
= false;
1269 if(audio_status() & AUDIO_STATUS_PLAY
)
1271 wps_state
.id3
= audio_current_track();
1272 wps_state
.nid3
= audio_next_track();
1276 wps_state
.id3
= NULL
;
1277 wps_state
.nid3
= NULL
;
1279 /* We'll be updating due to restore initialized with true */
1280 wps_sync_data
.do_full_update
= false;
1281 /* add the WPS track event callbacks */
1282 add_event(PLAYBACK_EVENT_TRACK_CHANGE
, false, track_changed_callback
);
1283 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, false, nextid3available_callback
);
1287 void gui_sync_wps_init(void)
1292 #ifdef HAVE_ALBUMART
1293 wps_datas
[i
].albumart
= NULL
;
1294 wps_datas
[i
].playback_aa_slot
= -1;
1296 gui_wps
[i
].data
= &wps_datas
[i
];
1297 gui_wps
[i
].display
= &screens
[i
];
1298 /* Currently no seperate wps_state needed/possible
1299 so use the only available ( "global" ) one */
1300 gui_wps
[i
].state
= &wps_state
;
1302 gui_wps
[i
].display
->backdrop_unload(BACKDROP_SKIN_WPS
);
1304 /* must point to the same struct for both screens */
1305 gui_wps
[i
].sync_data
= &wps_sync_data
;
1310 #ifdef IPOD_ACCESSORY_PROTOCOL
1311 bool is_wps_fading(void)
1313 return wps_state
.is_fading
;
1316 int wps_get_ff_rewind_count(void)
1318 return wps_state
.ff_rewind_count
;