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"
37 #include "skin_engine/skin_engine.h"
38 #include "mp3_playback.h"
45 #ifdef HAVE_LCD_BITMAP
47 #include "peakmeter.h"
58 #include "ata_idle_notify.h"
59 #include "root_menu.h"
61 #include "quickscreen.h"
62 #include "pitchscreen.h"
63 #include "appevents.h"
66 #include "option_select.h"
68 #include "playlist_viewer.h"
71 #define RESTORE_WPS_INSTANTLY 0l
72 #define RESTORE_WPS_NEXT_SECOND ((long)(HZ+current_tick))
74 #define DEFAULT_SKIP_TRESH 3000ul
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 /* this is for the viewportmanager */
83 /* currently only one wps_state is needed */
84 static struct wps_state wps_state
;
85 static struct gui_wps gui_wps
[NB_SCREENS
];
86 static struct wps_data wps_datas
[NB_SCREENS
];
88 /* initial setup of wps_data */
89 static void wps_state_init(void);
90 static void track_changed_callback(void *param
);
91 static void nextid3available_callback(void* param
);
92 #ifdef HAVE_LCD_BITMAP
93 static void statusbar_toggle_handler(void *data
);
96 #define WPS_DEFAULTCFG WPS_DIR "/rockbox_default.wps"
97 #ifdef HAVE_REMOTE_LCD
98 #define RWPS_DEFAULTCFG WPS_DIR "/rockbox_default.rwps"
99 #define DEFAULT_WPS(screen) ((screen) == SCREEN_MAIN ? \
100 WPS_DEFAULTCFG:RWPS_DEFAULTCFG)
102 #define DEFAULT_WPS(screen) (WPS_DEFAULTCFG)
105 void wps_data_load(enum screen_type screen
, const char *buf
, bool isfile
)
109 screens
[screen
].backdrop_unload(BACKDROP_SKIN_WPS
);
113 * Hardcode loading WPS_DEFAULTCFG to cause a reset ideally this
114 * wants to be a virtual file. Feel free to modify dirbrowse()
115 * if you're feeling brave.
118 if (! strcmp(buf
, DEFAULT_WPS(screen
)) )
120 #ifdef HAVE_REMOTE_LCD
121 if (screen
== SCREEN_REMOTE
)
122 global_settings
.rwps_file
[0] = '\0';
125 global_settings
.wps_file
[0] = '\0';
129 #endif /* __PCTOOL__ */
131 loaded_ok
= buf
&& skin_data_load(gui_wps
[screen
].data
,
132 &screens
[screen
], buf
, isfile
);
133 if (!loaded_ok
) /* load the hardcoded default */
135 char *skin_buf
[NB_SCREENS
] = {
136 #ifdef HAVE_LCD_BITMAP
137 "%s%?it<%?in<%in. |>%it|%fn>\n"
138 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
139 "%s%?id<%id|%?d1<%d1|(root)>> %?iy<(%iy)|>\n\n"
140 "%al%pc/%pt%ar[%pp:%pe]\n"
141 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
144 "%s%pp/%pe: %?it<%it|%fn> - %?ia<%ia|%d2> - %?id<%id|%d1>\n"
147 #ifdef HAVE_REMOTE_LCD
148 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
149 "%s%?it<%?in<%in. |>%it|%fn>\n"
150 "%al%pc/%pt%ar[%pp:%pe]\n"
151 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
155 skin_data_load(gui_wps
[screen
].data
, &screens
[screen
],
156 skin_buf
[screen
], false);
158 #ifdef HAVE_REMOVE_LCD
159 gui_wps
[screen
].data
->remote_wps
= !(screen
== SCREEN_MAIN
);
163 void wps_data_init(enum screen_type screen
)
165 skin_data_init(gui_wps
[screen
].data
);
169 static bool wps_fading_out
= false;
170 void fade(bool fade_in
, bool updatewps
)
172 int fp_global_vol
= global_settings
.volume
<< 8;
173 int fp_min_vol
= sound_min(SOUND_VOLUME
) << 8;
174 int fp_step
= (fp_global_vol
- fp_min_vol
) / 30;
176 wps_fading_out
= !fade_in
;
179 int fp_volume
= fp_min_vol
;
181 /* zero out the sound */
182 sound_set_volume(fp_min_vol
>> 8);
184 sleep(HZ
/10); /* let audio thread run */
187 while (fp_volume
< fp_global_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
);
197 sound_set_volume(global_settings
.volume
);
201 int fp_volume
= fp_global_vol
;
203 while (fp_volume
> fp_min_vol
+ fp_step
) {
204 fp_volume
-= fp_step
;
205 sound_set_volume(fp_volume
>> 8);
209 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
214 wps_fading_out
= false;
215 #if CONFIG_CODEC != SWCODEC
217 /* let audio thread run and wait for the mas to run out of data */
218 while (!mp3_pause_done())
223 /* reset volume to what it was before the fade */
224 sound_set_volume(global_settings
.volume
);
227 bool is_wps_fading(void)
229 return wps_fading_out
;
232 static bool update_onvol_change(struct gui_wps
* gwps
)
234 skin_update(gwps
, WPS_REFRESH_NON_STATIC
);
236 #ifdef HAVE_LCD_CHARCELLS
237 splashf(0, "Vol: %3d dB",
238 sound_val2phys(SOUND_VOLUME
, global_settings
.volume
));
245 bool ffwd_rew(int button
)
247 unsigned int step
= 0; /* current ff/rewind step */
248 unsigned int max_step
= 0; /* maximum ff/rewind step */
249 int ff_rewind_count
= 0; /* current ff/rewind count (in ticks) */
250 int direction
= -1; /* forward=1 or backward=-1 */
254 const long ff_rw_accel
= (global_settings
.ff_rewind_accel
+ 3);
256 if (button
== ACTION_NONE
)
258 status_set_ffmode(0);
265 case ACTION_WPS_SEEKFWD
:
267 case ACTION_WPS_SEEKBACK
:
268 if (wps_state
.ff_rewind
)
272 /* fast forwarding, calc max step relative to end */
273 max_step
= (wps_state
.id3
->length
-
274 (wps_state
.id3
->elapsed
+
276 FF_REWIND_MAX_PERCENT
/ 100;
280 /* rewinding, calc max step relative to start */
281 max_step
= (wps_state
.id3
->elapsed
+ ff_rewind_count
) *
282 FF_REWIND_MAX_PERCENT
/ 100;
285 max_step
= MAX(max_step
, MIN_FF_REWIND_STEP
);
290 ff_rewind_count
+= step
* direction
;
292 /* smooth seeking by multiplying step by: 1 + (2 ^ -accel) */
293 step
+= step
>> ff_rw_accel
;
297 if ( (audio_status() & AUDIO_STATUS_PLAY
) &&
298 wps_state
.id3
&& wps_state
.id3
->length
)
300 if (!wps_state
.paused
)
301 #if (CONFIG_CODEC == SWCODEC)
302 audio_pre_ff_rewind();
306 #if CONFIG_KEYPAD == PLAYER_PAD
308 gui_wps
[i
].display
->stop_scroll();
311 status_set_ffmode(STATUS_FASTFORWARD
);
313 status_set_ffmode(STATUS_FASTBACKWARD
);
315 wps_state
.ff_rewind
= true;
317 step
= 1000 * global_settings
.ff_rewind_min_step
;
324 if ((wps_state
.id3
->elapsed
+ ff_rewind_count
) >
325 wps_state
.id3
->length
)
326 ff_rewind_count
= wps_state
.id3
->length
-
327 wps_state
.id3
->elapsed
;
330 if ((int)(wps_state
.id3
->elapsed
+ ff_rewind_count
) < 0)
331 ff_rewind_count
= -wps_state
.id3
->elapsed
;
334 /* set the wps state ff_rewind_count so the progess info
336 wps_state
.ff_rewind_count
= (wps_state
.wps_time_countup
== false)?
337 ff_rewind_count
:-ff_rewind_count
;
340 skin_update(&gui_wps
[i
],
341 WPS_REFRESH_PLAYER_PROGRESS
|
342 WPS_REFRESH_DYNAMIC
);
347 case ACTION_WPS_STOPSEEK
:
348 wps_state
.id3
->elapsed
= wps_state
.id3
->elapsed
+ff_rewind_count
;
349 audio_ff_rewind(wps_state
.id3
->elapsed
);
350 wps_state
.ff_rewind_count
= 0;
351 wps_state
.ff_rewind
= false;
352 status_set_ffmode(0);
353 #if (CONFIG_CODEC != SWCODEC)
354 if (!wps_state
.paused
)
357 #ifdef HAVE_LCD_CHARCELLS
359 skin_update(&gui_wps
[i
], WPS_REFRESH_ALL
);
365 if(default_event_handler(button
) == SYS_USB_CONNECTED
) {
366 status_set_ffmode(0);
374 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_BLOCK
);
375 #ifdef HAVE_TOUCHSCREEN
376 if (button
== ACTION_TOUCHSCREEN
)
377 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
385 void display_keylock_text(bool locked
)
389 gui_wps
[i
].display
->stop_scroll();
391 splash(HZ
, locked
? ID2P(LANG_KEYLOCK_ON
) : ID2P(LANG_KEYLOCK_OFF
));
397 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
398 static void gwps_caption_backlight(struct wps_state
*state
)
400 if (state
&& state
->id3
)
402 #ifdef HAVE_BACKLIGHT
403 if (global_settings
.caption_backlight
)
405 /* turn on backlight n seconds before track ends, and turn it off n
406 seconds into the new track. n == backlight_timeout, or 5s */
407 int n
= global_settings
.backlight_timeout
* 1000;
410 n
= 5000; /* use 5s if backlight is always on or off */
412 if (((state
->id3
->elapsed
< 1000) ||
413 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
414 (state
->paused
== false))
418 #ifdef HAVE_REMOTE_LCD
419 if (global_settings
.remote_caption_backlight
)
421 /* turn on remote backlight n seconds before track ends, and turn it
422 off n seconds into the new track. n == remote_backlight_timeout,
424 int n
= global_settings
.remote_backlight_timeout
* 1000;
427 n
= 5000; /* use 5s if backlight is always on or off */
429 if (((state
->id3
->elapsed
< 1000) ||
430 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
431 (state
->paused
== false))
432 remote_backlight_on();
440 static void change_dir(int direction
)
442 if (global_settings
.prevent_skip
)
447 else if (direction
> 0)
449 /* prevent the next dir to immediatly start being ffw'd */
450 action_wait_for_release();
453 static void prev_track(unsigned long skip_thresh
)
455 if (wps_state
.id3
->elapsed
< skip_thresh
)
462 if (wps_state
.id3
->cuesheet
)
464 curr_cuesheet_skip(wps_state
.id3
->cuesheet
, -1, wps_state
.id3
->elapsed
);
468 if (!wps_state
.paused
)
469 #if (CONFIG_CODEC == SWCODEC)
470 audio_pre_ff_rewind();
477 #if (CONFIG_CODEC != SWCODEC)
478 if (!wps_state
.paused
)
484 static void next_track(void)
486 /* take care of if we're playing a cuesheet */
487 if (wps_state
.id3
->cuesheet
)
489 if (curr_cuesheet_skip(wps_state
.id3
->cuesheet
, 1, wps_state
.id3
->elapsed
))
491 /* if the result was false, then we really want
492 to skip to the next track */
500 static void play_hop(int direction
)
502 unsigned long step
= ((unsigned long)global_settings
.skip_length
)*1000;
503 unsigned long elapsed
= wps_state
.id3
->elapsed
;
504 unsigned long remaining
= wps_state
.id3
->length
- elapsed
;
506 if (!global_settings
.prevent_skip
&&
508 (direction
> 0 && step
>= remaining
) ||
509 (direction
< 0 && elapsed
< DEFAULT_SKIP_TRESH
)))
510 { /* Do normal track skipping */
513 else if (direction
< 0)
514 prev_track(DEFAULT_SKIP_TRESH
);
518 if (direction
== 1 && step
>= remaining
)
520 #if CONFIG_CODEC == SWCODEC
521 if(global_settings
.beep
)
522 pcmbuf_beep(1000, 150, 1500*global_settings
.beep
);
526 else if ((direction
== -1 && elapsed
< step
))
532 elapsed
+= step
* direction
;
534 if((audio_status() & AUDIO_STATUS_PLAY
) && !wps_state
.paused
)
536 #if (CONFIG_CODEC == SWCODEC)
537 audio_pre_ff_rewind();
542 audio_ff_rewind(wps_state
.id3
->elapsed
= elapsed
);
543 #if (CONFIG_CODEC != SWCODEC)
544 if (!wps_state
.paused
)
550 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
552 * If the user is unable to see the wps, because the display is deactivated,
553 * we suppress updates until the wps is activated again (the lcd driver will
554 * call this hook to issue an instant update)
556 static void wps_lcd_activation_hook(void)
558 wps_state
.do_full_update
= true;
559 /* force timeout in wps main loop, so that the update is instantly */
560 queue_post(&button_queue
, BUTTON_NONE
, 0);
564 static void gwps_leave_wps(void)
566 int i
, oldbars
= VP_SB_HIDE_ALL
;
570 gui_wps
[i
].display
->stop_scroll();
571 gui_wps
[i
].display
->backdrop_show(BACKDROP_MAIN
);
572 if (statusbar_position(i
) != STATUSBAR_OFF
)
573 oldbars
|= VP_SB_ONSCREEN(i
);
576 viewportmanager_set_statusbar(oldbars
);
577 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
578 /* Play safe and unregister the hook */
579 lcd_activation_set_hook(NULL
);
581 send_event(GUI_EVENT_REFRESH
, NULL
);
584 #ifdef HAVE_TOUCHSCREEN
585 int wps_get_touchaction(struct wps_data
*data
)
589 int type
= action_get_touchscreen_press(&x
, &y
);
590 static int last_action
= ACTION_NONE
;
591 struct touchregion
*r
;
592 bool repeated
= (type
== BUTTON_REPEAT
);
593 bool released
= (type
== BUTTON_REL
);
594 struct skin_token_list
*regions
= data
->touchregions
;
597 r
= (struct touchregion
*)regions
->token
->value
.data
;
598 /* make sure this region's viewport is visible */
599 if (r
->wvp
->hidden_flags
&VP_DRAW_HIDDEN
)
601 regions
= regions
->next
;
604 /* reposition the touch inside the viewport */
605 vx
= x
- r
->wvp
->vp
.x
;
606 vy
= y
- r
->wvp
->vp
.y
;
607 /* check if it's inside this viewport */
608 if (vx
>= 0 && vx
< r
->wvp
->vp
.x
+ r
->wvp
->vp
.width
&&
609 vy
>= 0 && vy
< r
->wvp
->vp
.y
+ r
->wvp
->vp
.height
)
611 /* now see if the point is inside this region */
612 if (vx
>= r
->x
&& vx
< r
->x
+r
->width
&&
613 vy
>= r
->y
&& vy
< r
->y
+r
->height
)
615 /* reposition the touch within the area */
621 case WPS_TOUCHREGION_ACTION
:
622 if ((repeated
&& r
->repeat
) || (released
&& !r
->repeat
))
624 last_action
= r
->action
;
628 case WPS_TOUCHREGION_SCROLLBAR
:
629 if(r
->width
> r
->height
)
631 wps_state
.id3
->elapsed
= (vx
*
632 wps_state
.id3
->length
) / r
->width
;
635 wps_state
.id3
->elapsed
= (vy
*
636 wps_state
.id3
->length
) / r
->height
;
638 audio_ff_rewind(wps_state
.id3
->elapsed
);
640 case WPS_TOUCHREGION_VOLUME
:
643 const int min_vol
= sound_min(SOUND_VOLUME
);
644 const int max_vol
= sound_max(SOUND_VOLUME
);
645 if(r
->width
> r
->height
)
647 global_settings
.volume
= (vx
*
648 (max_vol
- min_vol
)) / r
->width
;
651 global_settings
.volume
= (vy
*
652 (max_vol
-min_vol
)) / r
->height
;
654 global_settings
.volume
+= min_vol
;
658 gui_wps
[i
].data
->button_time_volume
= current_tick
;
660 return ACTION_REDRAW
;
665 regions
= regions
->next
;
668 if ((last_action
== ACTION_WPS_SEEKBACK
|| last_action
== ACTION_WPS_SEEKFWD
))
669 return ACTION_WPS_STOPSEEK
;
670 last_action
= ACTION_TOUCHSCREEN
;
671 return ACTION_TOUCHSCREEN
;
674 /* The WPS can be left in two ways:
675 * a) call a function, which draws over the wps. In this case, the wps
676 * will be still active (i.e. the below function didn't return)
677 * b) return with a value evaluated by root_menu.c, in this case the wps
678 * is really left, and root_menu will handle the next screen
680 * In either way, call gwps_leave_wps(), in order to restore the correct
681 * "main screen" backdrops and statusbars
683 long gui_wps_show(void)
687 long restoretimer
= RESTORE_WPS_INSTANTLY
; /* timer to delay screen redraw temporarily */
689 bool bookmark
= false;
692 long last_left
= 0, last_right
= 0;
694 #ifdef HAVE_LCD_CHARCELLS
695 status_set_audio(true);
696 status_set_param(false);
698 statusbar_toggle_handler(NULL
);
701 #ifdef AB_REPEAT_ENABLE
709 bool audio_paused
= (audio_status() & AUDIO_STATUS_PAUSE
)?true:false;
711 /* did someone else (i.e power thread) change audio pause mode? */
712 if (wps_state
.paused
!= audio_paused
) {
713 wps_state
.paused
= audio_paused
;
715 /* if another thread paused audio, we are probably in car mode,
716 about to shut down. lets save the settings. */
717 if (wps_state
.paused
) {
719 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
720 call_storage_idle_notifys(true);
725 #ifdef HAVE_LCD_BITMAP
726 /* when the peak meter is enabled we want to have a
727 few extra updates to make it look smooth. On the
728 other hand we don't want to waste energy if it
733 if(gui_wps
[i
].data
->peak_meter_enabled
)
738 long next_refresh
= current_tick
;
739 long next_big_refresh
= current_tick
+ HZ
/ 5;
740 button
= BUTTON_NONE
;
741 while (TIME_BEFORE(current_tick
, next_big_refresh
)) {
742 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_NOBLOCK
);
743 if (button
!= ACTION_NONE
) {
747 sleep(0); /* Sleep until end of current tick. */
749 if (TIME_AFTER(current_tick
, next_refresh
)) {
752 if(gui_wps
[i
].data
->peak_meter_enabled
)
753 skin_update(&gui_wps
[i
], WPS_REFRESH_PEAK_METER
);
754 next_refresh
+= HZ
/ PEAK_METER_FPS
;
761 /* The peak meter is disabled
762 -> no additional screen updates needed */
766 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,
767 restore
? HZ
/100 : HZ
/5);
770 /* Exit if audio has stopped playing. This happens e.g. at end of
771 playlist or if using the sleep timer. */
772 if (!(audio_status() & AUDIO_STATUS_PLAY
))
774 #ifdef HAVE_TOUCHSCREEN
775 if (button
== ACTION_TOUCHSCREEN
)
776 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
778 /* The iPods/X5/M5 use a single button for the A-B mode markers,
779 defined as ACTION_WPSAB_SINGLE in their config files. */
780 #ifdef ACTION_WPSAB_SINGLE
781 if (!global_settings
.party_mode
&& ab_repeat_mode_enabled())
783 static int wps_ab_state
= 0;
784 if (button
== ACTION_WPSAB_SINGLE
)
786 switch (wps_ab_state
)
788 case 0: /* set the A spot */
789 button
= ACTION_WPS_ABSETA_PREVDIR
;
791 case 1: /* set the B spot */
792 button
= ACTION_WPS_ABSETB_NEXTDIR
;
795 button
= ACTION_WPS_ABRESET
;
798 wps_ab_state
= (wps_ab_state
+1) % 3;
804 case ACTION_WPS_CONTEXT
:
807 /* if music is stopped in the context menu we want to exit the wps */
808 if (onplay(wps_state
.id3
->path
,
809 FILE_ATTR_AUDIO
, CONTEXT_WPS
) == ONPLAY_MAINMENU
816 case ACTION_WPS_BROWSE
:
817 #ifdef HAVE_LCD_CHARCELLS
818 status_set_record(false);
819 status_set_audio(false);
822 return GO_TO_PREVIOUS_BROWSER
;
826 case ACTION_WPS_PLAY
:
827 if (global_settings
.party_mode
)
829 if ( wps_state
.paused
)
831 wps_state
.paused
= false;
832 if ( global_settings
.fade_on_stop
)
839 wps_state
.paused
= true;
840 if ( global_settings
.fade_on_stop
)
845 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
846 call_storage_idle_notifys(true); /* make sure resume info is saved */
851 case ACTION_WPS_VOLUP
:
854 gui_wps
[i
].data
->button_time_volume
= current_tick
;
855 global_settings
.volume
++;
860 if(update_onvol_change(&gui_wps
[i
]))
865 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
869 case ACTION_WPS_VOLDOWN
:
872 gui_wps
[i
].data
->button_time_volume
= current_tick
;
873 global_settings
.volume
--;
878 if(update_onvol_change(&gui_wps
[i
]))
883 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
888 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
889 case ACTION_WPS_SEEKFWD
:
890 if (global_settings
.party_mode
)
892 if (current_tick
-last_right
< HZ
)
894 if (wps_state
.id3
->cuesheet
)
904 ffwd_rew(ACTION_WPS_SEEKFWD
);
905 last_right
= last_left
= 0;
908 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
909 case ACTION_WPS_SEEKBACK
:
910 if (global_settings
.party_mode
)
912 if (current_tick
-last_left
< HZ
)
914 if (wps_state
.id3
->cuesheet
)
916 if (!wps_state
.paused
)
917 #if (CONFIG_CODEC == SWCODEC)
918 audio_pre_ff_rewind();
930 ffwd_rew(ACTION_WPS_SEEKBACK
);
931 last_left
= last_right
= 0;
935 case ACTION_WPS_SKIPPREV
:
936 if (global_settings
.party_mode
)
938 last_left
= current_tick
;
939 #ifdef AB_REPEAT_ENABLE
940 /* if we're in A/B repeat mode and the current position
941 is past the A marker, jump back to the A marker... */
942 if ( ab_repeat_mode_enabled() )
944 if ( ab_after_A_marker(wps_state
.id3
->elapsed
) )
946 ab_jump_to_A_marker();
948 #if (AB_REPEAT_ENABLE == 2)
955 /* ...otherwise, do it normally */
961 OR if skip length set, hop by predetermined amount. */
962 case ACTION_WPS_SKIPNEXT
:
963 if (global_settings
.party_mode
)
965 last_right
= current_tick
;
966 #ifdef AB_REPEAT_ENABLE
967 /* if we're in A/B repeat mode and the current position is
968 before the A marker, jump to the A marker... */
969 if ( ab_repeat_mode_enabled() )
971 if ( ab_before_A_marker(wps_state
.id3
->elapsed
) )
973 ab_jump_to_A_marker();
975 #if (AB_REPEAT_ENABLE == 2)
982 /* ...otherwise, do it normally */
986 /* next / prev directories */
987 /* and set A-B markers if in a-b mode */
988 case ACTION_WPS_ABSETB_NEXTDIR
:
989 if (global_settings
.party_mode
)
991 #if defined(AB_REPEAT_ENABLE)
992 if (ab_repeat_mode_enabled())
994 ab_set_B_marker(wps_state
.id3
->elapsed
);
995 ab_jump_to_A_marker();
1003 case ACTION_WPS_ABSETA_PREVDIR
:
1004 if (global_settings
.party_mode
)
1006 #if defined(AB_REPEAT_ENABLE)
1007 if (ab_repeat_mode_enabled())
1008 ab_set_A_marker(wps_state
.id3
->elapsed
);
1015 /* menu key functions */
1016 case ACTION_WPS_MENU
:
1022 #ifdef HAVE_QUICKSCREEN
1023 case ACTION_WPS_QUICKSCREEN
:
1026 if (quick_screen_quick(button
))
1027 return SYS_USB_CONNECTED
;
1031 #endif /* HAVE_QUICKSCREEN */
1033 /* screen settings */
1038 if (quick_screen_f3(BUTTON_F3
))
1039 return SYS_USB_CONNECTED
;
1043 #endif /* BUTTON_F3 */
1046 #ifdef HAVE_PITCHSCREEN
1047 case ACTION_WPS_PITCHSCREEN
:
1050 if (1 == gui_syncpitchscreen_run())
1051 return SYS_USB_CONNECTED
;
1055 #endif /* HAVE_PITCHSCREEN */
1057 #ifdef AB_REPEAT_ENABLE
1058 /* reset A&B markers */
1059 case ACTION_WPS_ABRESET
:
1060 if (ab_repeat_mode_enabled())
1066 #endif /* AB_REPEAT_ENABLE */
1068 /* stop and exit wps */
1069 case ACTION_WPS_STOP
:
1070 if (global_settings
.party_mode
)
1076 case ACTION_WPS_ID3SCREEN
:
1083 #ifdef HAVE_TOUCHSCREEN
1084 case ACTION_TOUCH_SHUFFLE
: /* toggle shuffle mode */
1086 global_settings
.playlist_shuffle
=
1087 !global_settings
.playlist_shuffle
;
1088 #if CONFIG_CODEC == SWCODEC
1089 dsp_set_replaygain();
1091 if (global_settings
.playlist_shuffle
)
1092 playlist_randomise(NULL
, current_tick
, true);
1094 playlist_sort(NULL
, true);
1097 case ACTION_TOUCH_REPMODE
: /* cycle the repeat mode setting */
1099 const struct settings_list
*rep_setting
=
1100 find_setting(&global_settings
.repeat_mode
, NULL
);
1101 option_select_next_val(rep_setting
, false, true);
1102 audio_flush_and_reload_tracks();
1105 #endif /* HAVE_TOUCHSCREEN */
1106 /* this case is used by the softlock feature
1107 * it requests a full update here */
1109 wps_state
.do_full_update
= true;
1111 case ACTION_NONE
: /* Timeout, do a partial update */
1113 ffwd_rew(button
); /* hopefully fix the ffw/rwd bug */
1115 #ifdef HAVE_RECORDING
1116 case ACTION_WPS_REC
:
1121 default_event_handler(SYS_POWEROFF
);
1123 case ACTION_WPS_VIEW_PLAYLIST
:
1125 if (playlist_viewer()) /* true if USB connected */
1126 return SYS_USB_CONNECTED
;
1130 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1136 if (wps_state
.do_full_update
|| update
)
1138 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
1139 gwps_caption_backlight(&wps_state
);
1143 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1145 #ifdef HAVE_REMOTE_LCD
1146 /* currently, all remotes are readable without backlight
1147 * so still update those */
1148 || (i
== SCREEN_REMOTE
)
1153 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
1156 wps_state
.do_full_update
= false;
1160 if (restore
&& wps_state
.id3
&&
1161 ((restoretimer
== RESTORE_WPS_INSTANTLY
) ||
1162 TIME_AFTER(current_tick
, restoretimer
)))
1165 restoretimer
= RESTORE_WPS_INSTANTLY
;
1166 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1167 lcd_activation_set_hook(wps_lcd_activation_hook
);
1171 screens
[i
].stop_scroll();
1172 gui_wps_display(&gui_wps
[i
]);
1177 #ifdef HAVE_LCD_CHARCELLS
1178 status_set_record(false);
1179 status_set_audio(false);
1181 if (global_settings
.fade_on_stop
)
1185 bookmark_autobookmark();
1187 #ifdef AB_REPEAT_ENABLE
1191 #ifdef HAVE_RECORDING
1192 if (button
== ACTION_WPS_REC
)
1193 return GO_TO_RECSCREEN
;
1195 if (global_settings
.browse_current
)
1196 return GO_TO_PREVIOUS_BROWSER
;
1197 return GO_TO_PREVIOUS
;
1200 if (button
&& !IS_SYSEVENT(button
) )
1203 return GO_TO_ROOT
; /* unreachable - just to reduce compiler warnings */
1206 /* this is called from the playback thread so NO DRAWING! */
1207 static void track_changed_callback(void *param
)
1209 wps_state
.id3
= (struct mp3entry
*)param
;
1210 wps_state
.nid3
= audio_next_track();
1211 if (wps_state
.id3
->cuesheet
)
1213 cue_find_current_track(wps_state
.id3
->cuesheet
, wps_state
.id3
->elapsed
);
1214 cue_spoof_id3(wps_state
.id3
->cuesheet
, wps_state
.id3
);
1216 wps_state
.do_full_update
= true;
1218 static void nextid3available_callback(void* param
)
1221 wps_state
.nid3
= audio_next_track();
1222 wps_state
.do_full_update
= true;
1226 static void wps_state_init(void)
1228 wps_state
.ff_rewind
= false;
1229 wps_state
.paused
= false;
1230 if(audio_status() & AUDIO_STATUS_PLAY
)
1232 wps_state
.id3
= audio_current_track();
1233 wps_state
.nid3
= audio_next_track();
1237 wps_state
.id3
= NULL
;
1238 wps_state
.nid3
= NULL
;
1240 /* We'll be updating due to restore initialized with true */
1241 wps_state
.do_full_update
= false;
1242 /* add the WPS track event callbacks */
1243 add_event(PLAYBACK_EVENT_TRACK_CHANGE
, false, track_changed_callback
);
1244 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, false, nextid3available_callback
);
1248 #ifdef HAVE_LCD_BITMAP
1249 static void statusbar_toggle_handler(void *data
)
1254 wpsbars
= VP_SB_HIDE_ALL
;
1256 { /* fix viewports if needed */
1257 skin_statusbar_changed(&gui_wps
[i
]);
1261 /* fix up gui_wps::statusbars, so that the viewportmanager accepts it*/
1262 if (gui_wps
[i
].data
->wps_sb_tag
)
1263 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
1264 else if (statusbar_position(i
) != STATUSBAR_OFF
)
1268 (VP_SB_ONSCREEN(i
) | VP_SB_IGNORE_SETTING(i
));
1273 void gui_sync_wps_init(void)
1278 skin_data_init(&wps_datas
[i
]);
1279 #ifdef HAVE_ALBUMART
1280 wps_datas
[i
].wps_uses_albumart
= 0;
1282 #ifdef HAVE_REMOTE_LCD
1283 wps_datas
[i
].remote_wps
= (i
== SCREEN_REMOTE
);
1285 gui_wps
[i
].data
= &wps_datas
[i
];
1286 gui_wps
[i
].display
= &screens
[i
];
1287 /* Currently no seperate wps_state needed/possible
1288 so use the only available ( "global" ) one */
1289 gui_wps
[i
].state
= &wps_state
;
1290 gui_wps
[i
].display
->backdrop_unload(BACKDROP_SKIN_WPS
);
1291 /* only one wpsbars needed/wanted */
1292 gui_wps
[i
].statusbars
= &wpsbars
;
1294 *(gui_wps
[SCREEN_MAIN
].statusbars
) =VP_SB_ALLSCREENS
;
1295 #ifdef HAVE_LCD_BITMAP
1296 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false, statusbar_toggle_handler
);
1300 #ifdef HAVE_ALBUMART
1301 bool wps_uses_albumart(int *width
, int *height
)
1305 struct gui_wps
*gwps
= &gui_wps
[i
];
1306 if (gwps
->data
&& (gwps
->data
->wps_uses_albumart
!= WPS_ALBUMART_NONE
))
1309 *width
= gui_wps
[0].data
->albumart_max_width
;
1311 *height
= gui_wps
[0].data
->albumart_max_height
;
1320 #ifdef IPOD_ACCESSORY_PROTOCOL
1321 int wps_get_ff_rewind_count(void)
1323 return wps_state
.ff_rewind_count
;