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 DEFAULT_SKIP_TRESH 3000l
77 #define FF_REWIND_MAX_PERCENT 3 /* cap ff/rewind step size at max % of file */
78 /* 3% of 30min file == 54s step size */
79 #define MIN_FF_REWIND_STEP 500
81 /* currently only one wps_state is needed, initialize to 0 */
82 struct wps_state wps_state
= { .id3
= NULL
};
83 static struct gui_wps gui_wps
[NB_SCREENS
] = {{ .data
= NULL
}};
84 static struct wps_data wps_datas
[NB_SCREENS
] = {{ .wps_loaded
= 0 }};
85 static struct wps_sync_data wps_sync_data
= { .do_full_update
= false };
87 /* initial setup of wps_data */
88 static void wps_state_init(void);
89 static void track_changed_callback(void *param
);
90 static void nextid3available_callback(void* param
);
91 #ifdef HAVE_LCD_BITMAP
92 static void statusbar_toggle_handler(void *data
);
95 #define WPS_DEFAULTCFG WPS_DIR "/rockbox_default.wps"
96 #ifdef HAVE_REMOTE_LCD
97 #define RWPS_DEFAULTCFG WPS_DIR "/rockbox_default.rwps"
98 #define DEFAULT_WPS(screen) ((screen) == SCREEN_MAIN ? \
99 WPS_DEFAULTCFG:RWPS_DEFAULTCFG)
101 #define DEFAULT_WPS(screen) (WPS_DEFAULTCFG)
104 void wps_data_load(enum screen_type screen
, const char *buf
, bool isfile
)
108 screens
[screen
].backdrop_unload(BACKDROP_SKIN_WPS
);
112 * Hardcode loading WPS_DEFAULTCFG to cause a reset ideally this
113 * wants to be a virtual file. Feel free to modify dirbrowse()
114 * if you're feeling brave.
117 if (buf
&& ! strcmp(buf
, DEFAULT_WPS(screen
)) )
119 #ifdef HAVE_REMOTE_LCD
120 if (screen
== SCREEN_REMOTE
)
121 global_settings
.rwps_file
[0] = '\0';
124 global_settings
.wps_file
[0] = '\0';
128 #endif /* __PCTOOL__ */
130 loaded_ok
= buf
&& skin_data_load(gui_wps
[screen
].data
, buf
, isfile
);
132 if (!loaded_ok
) /* load the hardcoded default */
134 char *skin_buf
[NB_SCREENS
] = {
135 #ifdef HAVE_LCD_BITMAP
136 "%s%?it<%?in<%in. |>%it|%fn>\n"
137 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
138 "%s%?id<%id|%?d1<%d1|(root)>> %?iy<(%iy)|>\n\n"
139 "%al%pc/%pt%ar[%pp:%pe]\n"
140 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
143 "%s%pp/%pe: %?it<%it|%fn> - %?ia<%ia|%d2> - %?id<%id|%d1>\n"
146 #ifdef HAVE_REMOTE_LCD
147 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
148 "%s%?it<%?in<%in. |>%it|%fn>\n"
149 "%al%pc/%pt%ar[%pp:%pe]\n"
150 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
154 skin_data_load(gui_wps
[screen
].data
, skin_buf
[screen
], false);
156 #ifdef HAVE_REMOVE_LCD
157 gui_wps
[screen
].data
->remote_wps
= !(screen
== SCREEN_MAIN
);
162 static bool wps_fading_out
= false;
163 void fade(bool fade_in
, bool updatewps
)
165 int fp_global_vol
= global_settings
.volume
<< 8;
166 int fp_min_vol
= sound_min(SOUND_VOLUME
) << 8;
167 int fp_step
= (fp_global_vol
- fp_min_vol
) / 30;
169 wps_fading_out
= !fade_in
;
172 int fp_volume
= fp_min_vol
;
174 /* zero out the sound */
175 sound_set_volume(fp_min_vol
>> 8);
177 sleep(HZ
/10); /* let audio thread run */
180 while (fp_volume
< fp_global_vol
- fp_step
) {
181 fp_volume
+= fp_step
;
182 sound_set_volume(fp_volume
>> 8);
186 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
190 sound_set_volume(global_settings
.volume
);
194 int fp_volume
= fp_global_vol
;
196 while (fp_volume
> fp_min_vol
+ fp_step
) {
197 fp_volume
-= fp_step
;
198 sound_set_volume(fp_volume
>> 8);
202 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
207 wps_fading_out
= false;
208 #if CONFIG_CODEC != SWCODEC
210 /* let audio thread run and wait for the mas to run out of data */
211 while (!mp3_pause_done())
216 /* reset volume to what it was before the fade */
217 sound_set_volume(global_settings
.volume
);
220 bool is_wps_fading(void)
222 return wps_fading_out
;
225 static bool update_onvol_change(struct gui_wps
* gwps
)
227 skin_update(gwps
, WPS_REFRESH_NON_STATIC
);
229 #ifdef HAVE_LCD_CHARCELLS
230 splashf(0, "Vol: %3d dB",
231 sound_val2phys(SOUND_VOLUME
, global_settings
.volume
));
238 bool ffwd_rew(int button
)
240 unsigned int step
= 0; /* current ff/rewind step */
241 unsigned int max_step
= 0; /* maximum ff/rewind step */
242 int ff_rewind_count
= 0; /* current ff/rewind count (in ticks) */
243 int direction
= -1; /* forward=1 or backward=-1 */
247 const long ff_rw_accel
= (global_settings
.ff_rewind_accel
+ 3);
249 if (button
== ACTION_NONE
)
251 status_set_ffmode(0);
258 case ACTION_WPS_SEEKFWD
:
260 case ACTION_WPS_SEEKBACK
:
261 if (wps_state
.ff_rewind
)
265 /* fast forwarding, calc max step relative to end */
266 max_step
= (wps_state
.id3
->length
-
267 (wps_state
.id3
->elapsed
+
269 FF_REWIND_MAX_PERCENT
/ 100;
273 /* rewinding, calc max step relative to start */
274 max_step
= (wps_state
.id3
->elapsed
+ ff_rewind_count
) *
275 FF_REWIND_MAX_PERCENT
/ 100;
278 max_step
= MAX(max_step
, MIN_FF_REWIND_STEP
);
283 ff_rewind_count
+= step
* direction
;
285 /* smooth seeking by multiplying step by: 1 + (2 ^ -accel) */
286 step
+= step
>> ff_rw_accel
;
290 if ( (audio_status() & AUDIO_STATUS_PLAY
) &&
291 wps_state
.id3
&& wps_state
.id3
->length
)
293 if (!wps_state
.paused
)
294 #if (CONFIG_CODEC == SWCODEC)
295 audio_pre_ff_rewind();
299 #if CONFIG_KEYPAD == PLAYER_PAD
301 gui_wps
[i
].display
->stop_scroll();
304 status_set_ffmode(STATUS_FASTFORWARD
);
306 status_set_ffmode(STATUS_FASTBACKWARD
);
308 wps_state
.ff_rewind
= true;
310 step
= 1000 * global_settings
.ff_rewind_min_step
;
317 if ((wps_state
.id3
->elapsed
+ ff_rewind_count
) >
318 wps_state
.id3
->length
)
319 ff_rewind_count
= wps_state
.id3
->length
-
320 wps_state
.id3
->elapsed
;
323 if ((int)(wps_state
.id3
->elapsed
+ ff_rewind_count
) < 0)
324 ff_rewind_count
= -wps_state
.id3
->elapsed
;
327 /* set the wps state ff_rewind_count so the progess info
329 wps_state
.ff_rewind_count
= (wps_state
.wps_time_countup
== false)?
330 ff_rewind_count
:-ff_rewind_count
;
333 skin_update(&gui_wps
[i
],
334 WPS_REFRESH_PLAYER_PROGRESS
|
335 WPS_REFRESH_DYNAMIC
);
340 case ACTION_WPS_STOPSEEK
:
341 wps_state
.id3
->elapsed
= wps_state
.id3
->elapsed
+ff_rewind_count
;
342 audio_ff_rewind(wps_state
.id3
->elapsed
);
343 wps_state
.ff_rewind_count
= 0;
344 wps_state
.ff_rewind
= false;
345 status_set_ffmode(0);
346 #if (CONFIG_CODEC != SWCODEC)
347 if (!wps_state
.paused
)
350 #ifdef HAVE_LCD_CHARCELLS
352 skin_update(&gui_wps
[i
], WPS_REFRESH_ALL
);
358 if(default_event_handler(button
) == SYS_USB_CONNECTED
) {
359 status_set_ffmode(0);
367 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_BLOCK
);
368 #ifdef HAVE_TOUCHSCREEN
369 if (button
== ACTION_TOUCHSCREEN
)
370 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
378 void display_keylock_text(bool locked
)
382 gui_wps
[i
].display
->stop_scroll();
384 splash(HZ
, locked
? ID2P(LANG_KEYLOCK_ON
) : ID2P(LANG_KEYLOCK_OFF
));
390 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
391 static void gwps_caption_backlight(struct wps_state
*state
)
393 if (state
&& state
->id3
)
395 #ifdef HAVE_BACKLIGHT
396 if (global_settings
.caption_backlight
)
398 /* turn on backlight n seconds before track ends, and turn it off n
399 seconds into the new track. n == backlight_timeout, or 5s */
400 int n
= global_settings
.backlight_timeout
* 1000;
403 n
= 5000; /* use 5s if backlight is always on or off */
405 if (((state
->id3
->elapsed
< 1000) ||
406 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
407 (state
->paused
== false))
411 #ifdef HAVE_REMOTE_LCD
412 if (global_settings
.remote_caption_backlight
)
414 /* turn on remote backlight n seconds before track ends, and turn it
415 off n seconds into the new track. n == remote_backlight_timeout,
417 int n
= global_settings
.remote_backlight_timeout
* 1000;
420 n
= 5000; /* use 5s if backlight is always on or off */
422 if (((state
->id3
->elapsed
< 1000) ||
423 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
424 (state
->paused
== false))
425 remote_backlight_on();
433 static void change_dir(int direction
)
435 if (global_settings
.prevent_skip
)
440 else if (direction
> 0)
442 /* prevent the next dir to immediatly start being ffw'd */
443 action_wait_for_release();
446 static void prev_track(unsigned long skip_thresh
)
448 if (wps_state
.id3
->elapsed
< skip_thresh
)
455 if (wps_state
.id3
->cuesheet
)
457 curr_cuesheet_skip(wps_state
.id3
->cuesheet
, -1, wps_state
.id3
->elapsed
);
461 if (!wps_state
.paused
)
462 #if (CONFIG_CODEC == SWCODEC)
463 audio_pre_ff_rewind();
470 #if (CONFIG_CODEC != SWCODEC)
471 if (!wps_state
.paused
)
477 static void next_track(void)
479 /* take care of if we're playing a cuesheet */
480 if (wps_state
.id3
->cuesheet
)
482 if (curr_cuesheet_skip(wps_state
.id3
->cuesheet
, 1, wps_state
.id3
->elapsed
))
484 /* if the result was false, then we really want
485 to skip to the next track */
493 static void play_hop(int direction
)
495 long step
= global_settings
.skip_length
*1000;
496 long elapsed
= wps_state
.id3
->elapsed
;
497 long remaining
= wps_state
.id3
->length
- elapsed
;
503 prev_track(DEFAULT_SKIP_TRESH
);
506 else if (remaining
< DEFAULT_SKIP_TRESH
*2)
512 elapsed
+= (remaining
- DEFAULT_SKIP_TRESH
*2);
514 else if (!global_settings
.prevent_skip
&&
516 (direction
> 0 && step
>= remaining
) ||
517 (direction
< 0 && elapsed
< DEFAULT_SKIP_TRESH
)))
518 { /* Do normal track skipping */
521 else if (direction
< 0)
522 prev_track(DEFAULT_SKIP_TRESH
);
525 else if (direction
== 1 && step
>= remaining
)
527 #if CONFIG_CODEC == SWCODEC
528 if(global_settings
.beep
)
529 pcmbuf_beep(1000, 150, 1500*global_settings
.beep
);
533 else if ((direction
== -1 && elapsed
< step
))
539 elapsed
+= step
* direction
;
541 if((audio_status() & AUDIO_STATUS_PLAY
) && !wps_state
.paused
)
543 #if (CONFIG_CODEC == SWCODEC)
544 audio_pre_ff_rewind();
549 audio_ff_rewind(wps_state
.id3
->elapsed
= elapsed
);
550 #if (CONFIG_CODEC != SWCODEC)
551 if (!wps_state
.paused
)
557 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
559 * If the user is unable to see the wps, because the display is deactivated,
560 * we suppress updates until the wps is activated again (the lcd driver will
561 * call this hook to issue an instant update)
563 static void wps_lcd_activation_hook(void *param
)
566 wps_sync_data
.do_full_update
= true;
567 /* force timeout in wps main loop, so that the update is instantly */
568 queue_post(&button_queue
, BUTTON_NONE
, 0);
572 static void gwps_leave_wps(void)
574 int i
, oldbars
= VP_SB_HIDE_ALL
;
578 gui_wps
[i
].display
->stop_scroll();
579 gui_wps
[i
].display
->backdrop_show(BACKDROP_MAIN
);
580 if (statusbar_position(i
) != STATUSBAR_OFF
)
581 oldbars
|= VP_SB_ONSCREEN(i
);
584 viewportmanager_set_statusbar(oldbars
);
585 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
586 /* Play safe and unregister the hook */
587 remove_event(LCD_EVENT_ACTIVATION
, wps_lcd_activation_hook
);
589 /* unhandle statusbar update delay */
590 sb_skin_set_update_delay(DEFAULT_UPDATE_DELAY
);
591 send_event(GUI_EVENT_REFRESH
, NULL
);
594 #ifdef HAVE_TOUCHSCREEN
595 int wps_get_touchaction(struct wps_data
*data
)
599 int type
= action_get_touchscreen_press(&x
, &y
);
600 static int last_action
= ACTION_NONE
;
601 struct touchregion
*r
;
602 bool repeated
= (type
== BUTTON_REPEAT
);
603 bool released
= (type
== BUTTON_REL
);
604 struct skin_token_list
*regions
= data
->touchregions
;
607 r
= (struct touchregion
*)regions
->token
->value
.data
;
608 /* make sure this region's viewport is visible */
609 if (r
->wvp
->hidden_flags
&VP_DRAW_HIDDEN
)
611 regions
= regions
->next
;
614 /* check if it's inside this viewport */
615 if (viewport_point_within_vp(&(r
->wvp
->vp
), x
, y
))
616 { /* reposition the touch inside the viewport since touchregions
617 * are relative to a preceding viewport */
618 vx
= x
- r
->wvp
->vp
.x
;
619 vy
= y
- r
->wvp
->vp
.y
;
620 /* now see if the point is inside this region */
621 if (vx
>= r
->x
&& vx
< r
->x
+r
->width
&&
622 vy
>= r
->y
&& vy
< r
->y
+r
->height
)
624 /* reposition the touch within the area */
630 case WPS_TOUCHREGION_ACTION
:
631 if ((repeated
&& r
->repeat
) || (released
&& !r
->repeat
))
633 last_action
= r
->action
;
637 case WPS_TOUCHREGION_SCROLLBAR
:
638 if(r
->width
> r
->height
)
640 wps_state
.id3
->elapsed
= (vx
*
641 wps_state
.id3
->length
) / r
->width
;
644 wps_state
.id3
->elapsed
= (vy
*
645 wps_state
.id3
->length
) / r
->height
;
647 if (!wps_state
.paused
)
648 #if (CONFIG_CODEC == SWCODEC)
649 audio_pre_ff_rewind();
653 audio_ff_rewind(wps_state
.id3
->elapsed
);
654 #if (CONFIG_CODEC != SWCODEC)
655 if (!wps_state
.paused
)
659 case WPS_TOUCHREGION_VOLUME
:
662 const int min_vol
= sound_min(SOUND_VOLUME
);
663 const int max_vol
= sound_max(SOUND_VOLUME
);
664 if(r
->width
> r
->height
)
666 global_settings
.volume
= (vx
*
667 (max_vol
- min_vol
)) / r
->width
;
670 global_settings
.volume
= (vy
*
671 (max_vol
-min_vol
)) / r
->height
;
673 global_settings
.volume
+= min_vol
;
677 gui_wps
[i
].data
->button_time_volume
= current_tick
;
679 return ACTION_REDRAW
;
684 regions
= regions
->next
;
687 if ((last_action
== ACTION_WPS_SEEKBACK
|| last_action
== ACTION_WPS_SEEKFWD
))
688 return ACTION_WPS_STOPSEEK
;
689 last_action
= ACTION_TOUCHSCREEN
;
690 return ACTION_TOUCHSCREEN
;
693 /* The WPS can be left in two ways:
694 * a) call a function, which draws over the wps. In this case, the wps
695 * will be still active (i.e. the below function didn't return)
696 * b) return with a value evaluated by root_menu.c, in this case the wps
697 * is really left, and root_menu will handle the next screen
699 * In either way, call gwps_leave_wps(), in order to restore the correct
700 * "main screen" backdrops and statusbars
702 long gui_wps_show(void)
706 long restoretimer
= RESTORE_WPS_INSTANTLY
; /* timer to delay screen redraw temporarily */
708 bool bookmark
= false;
710 bool vol_changed
= false;
712 long last_left
= 0, last_right
= 0;
714 #ifdef HAVE_LCD_CHARCELLS
715 status_set_audio(true);
716 status_set_param(false);
718 statusbar_toggle_handler(NULL
);
721 #ifdef AB_REPEAT_ENABLE
729 bool audio_paused
= (audio_status() & AUDIO_STATUS_PAUSE
)?true:false;
731 /* did someone else (i.e power thread) change audio pause mode? */
732 if (wps_state
.paused
!= audio_paused
) {
733 wps_state
.paused
= audio_paused
;
735 /* if another thread paused audio, we are probably in car mode,
736 about to shut down. lets save the settings. */
737 if (wps_state
.paused
) {
739 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
740 call_storage_idle_notifys(true);
744 #ifdef HAVE_LCD_BITMAP
745 /* when the peak meter is enabled we want to have a
746 few extra updates to make it look smooth. On the
747 other hand we don't want to waste energy if it
752 if(gui_wps
[i
].data
->peak_meter_enabled
)
757 long next_refresh
= current_tick
;
758 long next_big_refresh
= current_tick
+ HZ
/ 5;
759 button
= BUTTON_NONE
;
760 while (TIME_BEFORE(current_tick
, next_big_refresh
)) {
761 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_NOBLOCK
);
762 if (button
!= ACTION_NONE
) {
766 sleep(0); /* Sleep until end of current tick. */
768 if (TIME_AFTER(current_tick
, next_refresh
)) {
771 if(gui_wps
[i
].data
->peak_meter_enabled
)
772 skin_update(&gui_wps
[i
], WPS_REFRESH_PEAK_METER
);
773 next_refresh
+= HZ
/ PEAK_METER_FPS
;
780 /* The peak meter is disabled
781 -> no additional screen updates needed */
785 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,
786 restore
? HZ
/100 : HZ
/5);
789 /* Exit if audio has stopped playing. This happens e.g. at end of
790 playlist or if using the sleep timer. */
791 if (!(audio_status() & AUDIO_STATUS_PLAY
))
793 #ifdef HAVE_TOUCHSCREEN
794 if (button
== ACTION_TOUCHSCREEN
)
795 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
797 /* The iPods/X5/M5 use a single button for the A-B mode markers,
798 defined as ACTION_WPSAB_SINGLE in their config files. */
799 #ifdef ACTION_WPSAB_SINGLE
800 if (!global_settings
.party_mode
&& ab_repeat_mode_enabled())
802 static int wps_ab_state
= 0;
803 if (button
== ACTION_WPSAB_SINGLE
)
805 switch (wps_ab_state
)
807 case 0: /* set the A spot */
808 button
= ACTION_WPS_ABSETA_PREVDIR
;
810 case 1: /* set the B spot */
811 button
= ACTION_WPS_ABSETB_NEXTDIR
;
814 button
= ACTION_WPS_ABRESET
;
817 wps_ab_state
= (wps_ab_state
+1) % 3;
823 case ACTION_WPS_CONTEXT
:
826 /* if music is stopped in the context menu we want to exit the wps */
827 if (onplay(wps_state
.id3
->path
,
828 FILE_ATTR_AUDIO
, CONTEXT_WPS
) == ONPLAY_MAINMENU
835 case ACTION_WPS_BROWSE
:
836 #ifdef HAVE_LCD_CHARCELLS
837 status_set_record(false);
838 status_set_audio(false);
841 return GO_TO_PREVIOUS_BROWSER
;
845 case ACTION_WPS_PLAY
:
846 if (global_settings
.party_mode
)
848 if ( wps_state
.paused
)
850 wps_state
.paused
= false;
851 if ( global_settings
.fade_on_stop
)
858 wps_state
.paused
= true;
859 if ( global_settings
.fade_on_stop
)
864 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
865 call_storage_idle_notifys(true); /* make sure resume info is saved */
870 case ACTION_WPS_VOLUP
:
871 global_settings
.volume
++;
874 case ACTION_WPS_VOLDOWN
:
875 global_settings
.volume
--;
879 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
880 case ACTION_WPS_SEEKFWD
:
881 if (global_settings
.party_mode
)
883 if (current_tick
-last_right
< HZ
)
885 if (wps_state
.id3
->cuesheet
)
895 ffwd_rew(ACTION_WPS_SEEKFWD
);
896 last_right
= last_left
= 0;
899 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
900 case ACTION_WPS_SEEKBACK
:
901 if (global_settings
.party_mode
)
903 if (current_tick
-last_left
< HZ
)
905 if (wps_state
.id3
->cuesheet
)
907 if (!wps_state
.paused
)
908 #if (CONFIG_CODEC == SWCODEC)
909 audio_pre_ff_rewind();
921 ffwd_rew(ACTION_WPS_SEEKBACK
);
922 last_left
= last_right
= 0;
926 case ACTION_WPS_SKIPPREV
:
927 if (global_settings
.party_mode
)
929 last_left
= current_tick
;
930 #ifdef AB_REPEAT_ENABLE
931 /* if we're in A/B repeat mode and the current position
932 is past the A marker, jump back to the A marker... */
933 if ( ab_repeat_mode_enabled() )
935 if ( ab_after_A_marker(wps_state
.id3
->elapsed
) )
937 ab_jump_to_A_marker();
939 #if (AB_REPEAT_ENABLE == 2)
946 /* ...otherwise, do it normally */
952 OR if skip length set, hop by predetermined amount. */
953 case ACTION_WPS_SKIPNEXT
:
954 if (global_settings
.party_mode
)
956 last_right
= current_tick
;
957 #ifdef AB_REPEAT_ENABLE
958 /* if we're in A/B repeat mode and the current position is
959 before the A marker, jump to the A marker... */
960 if ( ab_repeat_mode_enabled() )
962 if ( ab_before_A_marker(wps_state
.id3
->elapsed
) )
964 ab_jump_to_A_marker();
966 #if (AB_REPEAT_ENABLE == 2)
973 /* ...otherwise, do it normally */
977 /* next / prev directories */
978 /* and set A-B markers if in a-b mode */
979 case ACTION_WPS_ABSETB_NEXTDIR
:
980 if (global_settings
.party_mode
)
982 #if defined(AB_REPEAT_ENABLE)
983 if (ab_repeat_mode_enabled())
985 ab_set_B_marker(wps_state
.id3
->elapsed
);
986 ab_jump_to_A_marker();
994 case ACTION_WPS_ABSETA_PREVDIR
:
995 if (global_settings
.party_mode
)
997 #if defined(AB_REPEAT_ENABLE)
998 if (ab_repeat_mode_enabled())
999 ab_set_A_marker(wps_state
.id3
->elapsed
);
1006 /* menu key functions */
1007 case ACTION_WPS_MENU
:
1013 #ifdef HAVE_QUICKSCREEN
1014 case ACTION_WPS_QUICKSCREEN
:
1017 if (quick_screen_quick(button
))
1022 #endif /* HAVE_QUICKSCREEN */
1024 /* screen settings */
1029 if (quick_screen_f3(BUTTON_F3
))
1034 #endif /* BUTTON_F3 */
1037 #ifdef HAVE_PITCHSCREEN
1038 case ACTION_WPS_PITCHSCREEN
:
1041 if (1 == gui_syncpitchscreen_run())
1046 #endif /* HAVE_PITCHSCREEN */
1048 #ifdef AB_REPEAT_ENABLE
1049 /* reset A&B markers */
1050 case ACTION_WPS_ABRESET
:
1051 if (ab_repeat_mode_enabled())
1057 #endif /* AB_REPEAT_ENABLE */
1059 /* stop and exit wps */
1060 case ACTION_WPS_STOP
:
1061 if (global_settings
.party_mode
)
1067 case ACTION_WPS_ID3SCREEN
:
1075 #ifdef HAVE_TOUCHSCREEN
1076 case ACTION_TOUCH_SHUFFLE
: /* toggle shuffle mode */
1078 global_settings
.playlist_shuffle
=
1079 !global_settings
.playlist_shuffle
;
1080 #if CONFIG_CODEC == SWCODEC
1081 dsp_set_replaygain();
1083 if (global_settings
.playlist_shuffle
)
1084 playlist_randomise(NULL
, current_tick
, true);
1086 playlist_sort(NULL
, true);
1089 case ACTION_TOUCH_REPMODE
: /* cycle the repeat mode setting */
1091 const struct settings_list
*rep_setting
=
1092 find_setting(&global_settings
.repeat_mode
, NULL
);
1093 option_select_next_val(rep_setting
, false, true);
1094 audio_flush_and_reload_tracks();
1097 #endif /* HAVE_TOUCHSCREEN */
1098 /* this case is used by the softlock feature
1099 * it requests a full update here */
1101 wps_sync_data
.do_full_update
= true;
1103 case ACTION_NONE
: /* Timeout, do a partial update */
1105 ffwd_rew(button
); /* hopefully fix the ffw/rwd bug */
1107 #ifdef HAVE_RECORDING
1108 case ACTION_WPS_REC
:
1113 default_event_handler(SYS_POWEROFF
);
1115 case ACTION_WPS_VIEW_PLAYLIST
:
1117 if (playlist_viewer()) /* true if USB connected */
1122 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1137 if(update_onvol_change(&gui_wps
[i
]))
1142 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
1146 if (wps_sync_data
.do_full_update
|| update
)
1148 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
1149 gwps_caption_backlight(&wps_state
);
1153 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1154 /* currently, all remotes are readable without backlight
1155 * so still update those */
1156 if (lcd_active() || (i
!= SCREEN_MAIN
))
1159 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
1162 wps_sync_data
.do_full_update
= false;
1166 if (restore
&& wps_state
.id3
&&
1167 ((restoretimer
== RESTORE_WPS_INSTANTLY
) ||
1168 TIME_AFTER(current_tick
, restoretimer
)))
1171 restoretimer
= RESTORE_WPS_INSTANTLY
;
1172 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1173 add_event(LCD_EVENT_ACTIVATION
, false, wps_lcd_activation_hook
);
1175 /* we remove the update delay since it's not very usable in the wps,
1176 * e.g. during volume changing or ffwd/rewind */
1177 sb_skin_set_update_delay(0);
1180 screens
[i
].stop_scroll();
1181 gui_wps_display(&gui_wps
[i
]);
1186 #ifdef HAVE_LCD_CHARCELLS
1187 status_set_record(false);
1188 status_set_audio(false);
1190 if (global_settings
.fade_on_stop
)
1194 bookmark_autobookmark();
1196 #ifdef AB_REPEAT_ENABLE
1200 #ifdef HAVE_RECORDING
1201 if (button
== ACTION_WPS_REC
)
1202 return GO_TO_RECSCREEN
;
1204 if (global_settings
.browse_current
)
1205 return GO_TO_PREVIOUS_BROWSER
;
1206 return GO_TO_PREVIOUS
;
1209 if (button
&& !IS_SYSEVENT(button
) )
1212 return GO_TO_ROOT
; /* unreachable - just to reduce compiler warnings */
1215 /* this is called from the playback thread so NO DRAWING! */
1216 static void track_changed_callback(void *param
)
1218 wps_state
.id3
= (struct mp3entry
*)param
;
1219 wps_state
.nid3
= audio_next_track();
1220 if (wps_state
.id3
->cuesheet
)
1222 cue_find_current_track(wps_state
.id3
->cuesheet
, wps_state
.id3
->elapsed
);
1223 cue_spoof_id3(wps_state
.id3
->cuesheet
, wps_state
.id3
);
1225 wps_sync_data
.do_full_update
= true;
1227 static void nextid3available_callback(void* param
)
1230 wps_state
.nid3
= audio_next_track();
1231 wps_sync_data
.do_full_update
= true;
1235 static void wps_state_init(void)
1237 wps_state
.ff_rewind
= false;
1238 wps_state
.paused
= false;
1239 if(audio_status() & AUDIO_STATUS_PLAY
)
1241 wps_state
.id3
= audio_current_track();
1242 wps_state
.nid3
= audio_next_track();
1246 wps_state
.id3
= NULL
;
1247 wps_state
.nid3
= NULL
;
1249 /* We'll be updating due to restore initialized with true */
1250 wps_sync_data
.do_full_update
= false;
1251 /* add the WPS track event callbacks */
1252 add_event(PLAYBACK_EVENT_TRACK_CHANGE
, false, track_changed_callback
);
1253 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, false, nextid3available_callback
);
1257 #ifdef HAVE_LCD_BITMAP
1258 static void statusbar_toggle_handler(void *data
)
1263 int *wpsbars
= &wps_sync_data
.statusbars
;
1264 *wpsbars
= VP_SB_HIDE_ALL
;
1266 { /* fix viewports if needed */
1267 skin_statusbar_changed(&gui_wps
[i
]);
1271 /* fix up gui_wps::statusbars, so that the viewportmanager accepts it*/
1272 if (gui_wps
[i
].data
->wps_sb_tag
)
1273 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
1274 else if (statusbar_position(i
) != STATUSBAR_OFF
)
1278 (VP_SB_ONSCREEN(i
) | VP_SB_IGNORE_SETTING(i
));
1284 void gui_sync_wps_init(void)
1289 #ifdef HAVE_ALBUMART
1290 wps_datas
[i
].albumart
= NULL
;
1291 wps_datas
[i
].playback_aa_slot
= -1;
1293 #ifdef HAVE_REMOTE_LCD
1294 wps_datas
[i
].remote_wps
= (i
== SCREEN_REMOTE
);
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
;
1301 gui_wps
[i
].display
->backdrop_unload(BACKDROP_SKIN_WPS
);
1302 /* must point to the same struct for both screens */
1303 gui_wps
[i
].sync_data
= &wps_sync_data
;
1304 gui_wps
[i
].sync_data
->statusbars
= VP_SB_ALLSCREENS
;
1306 #ifdef HAVE_LCD_BITMAP
1307 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false, statusbar_toggle_handler
);
1312 #ifdef IPOD_ACCESSORY_PROTOCOL
1313 int wps_get_ff_rewind_count(void)
1315 return wps_state
.ff_rewind_count
;