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"
35 #include "skin_engine/skin_engine.h"
36 #include "mp3_playback.h"
43 #ifdef HAVE_LCD_BITMAP
45 #include "peakmeter.h"
56 #include "ata_idle_notify.h"
57 #include "root_menu.h"
59 #include "quickscreen.h"
60 #include "pitchscreen.h"
61 #include "appevents.h"
64 #include "option_select.h"
66 #include "playlist_viewer.h"
68 #include "statusbar-skinned.h"
70 #define RESTORE_WPS_INSTANTLY 0l
71 #define RESTORE_WPS_NEXT_SECOND ((long)(HZ+current_tick))
73 #define FF_REWIND_MAX_PERCENT 3 /* cap ff/rewind step size at max % of file */
74 /* 3% of 30min file == 54s step size */
75 #define MIN_FF_REWIND_STEP 500
77 /* currently only one wps_state is needed, initialize to 0 */
78 struct wps_state wps_state
= { .id3
= NULL
};
79 static struct gui_wps gui_wps
[NB_SCREENS
] = {{ .data
= NULL
}};
80 static struct wps_data wps_datas
[NB_SCREENS
] = {{ .wps_loaded
= 0 }};
81 static struct wps_sync_data wps_sync_data
= { .do_full_update
= false };
83 /* initial setup of wps_data */
84 static void wps_state_init(void);
85 static void track_changed_callback(void *param
);
86 static void nextid3available_callback(void* param
);
88 #ifdef HAVE_TOUCHSCREEN
89 static void wps_disarm_touchregions(struct wps_data
*data
);
92 #define WPS_DEFAULTCFG WPS_DIR "/rockbox_default.wps"
93 #ifdef HAVE_REMOTE_LCD
94 #define RWPS_DEFAULTCFG WPS_DIR "/rockbox_default.rwps"
95 #define DEFAULT_WPS(screen) ((screen) == SCREEN_MAIN ? \
96 WPS_DEFAULTCFG:RWPS_DEFAULTCFG)
98 #define DEFAULT_WPS(screen) (WPS_DEFAULTCFG)
101 void wps_data_load(enum screen_type screen
, const char *buf
, bool isfile
)
107 * Hardcode loading WPS_DEFAULTCFG to cause a reset ideally this
108 * wants to be a virtual file. Feel free to modify dirbrowse()
109 * if you're feeling brave.
112 if (buf
&& ! strcmp(buf
, DEFAULT_WPS(screen
)) )
114 #ifdef HAVE_REMOTE_LCD
115 if (screen
== SCREEN_REMOTE
)
116 global_settings
.rwps_file
[0] = '\0';
119 global_settings
.wps_file
[0] = '\0';
123 #endif /* __PCTOOL__ */
125 loaded_ok
= buf
&& skin_data_load(screen
, gui_wps
[screen
].data
, buf
, isfile
);
127 if (!loaded_ok
) /* load the hardcoded default */
129 char *skin_buf
[NB_SCREENS
] = {
130 #ifdef HAVE_LCD_BITMAP
134 "%s%?it<%?in<%in. |>%it|%fn>\n"
135 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
136 "%s%?id<%id|%?d1<%d1|(root)>> %?iy<(%iy)|>\n\n"
137 "%al%pc/%pt%ar[%pp:%pe]\n"
138 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
141 "%s%pp/%pe: %?it<%it|%fn> - %?ia<%ia|%d2> - %?id<%id|%d1>\n"
144 #ifdef HAVE_REMOTE_LCD
145 #if LCD_REMOTE_DEPTH > 1
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(screen
, gui_wps
[screen
].data
, skin_buf
[screen
], false);
159 void fade(bool fade_in
, bool updatewps
)
161 int fp_global_vol
= global_settings
.volume
<< 8;
162 int fp_min_vol
= sound_min(SOUND_VOLUME
) << 8;
163 int fp_step
= (fp_global_vol
- fp_min_vol
) / 30;
165 wps_state
.is_fading
= !fade_in
;
168 int fp_volume
= fp_min_vol
;
170 /* zero out the sound */
171 sound_set_volume(fp_min_vol
>> 8);
173 sleep(HZ
/10); /* let audio thread run */
176 while (fp_volume
< fp_global_vol
- fp_step
) {
177 fp_volume
+= fp_step
;
178 sound_set_volume(fp_volume
>> 8);
182 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
186 sound_set_volume(global_settings
.volume
);
190 int fp_volume
= fp_global_vol
;
192 while (fp_volume
> fp_min_vol
+ fp_step
) {
193 fp_volume
-= fp_step
;
194 sound_set_volume(fp_volume
>> 8);
198 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
203 wps_state
.is_fading
= false;
204 #if CONFIG_CODEC != SWCODEC
206 /* let audio thread run and wait for the mas to run out of data */
207 while (!mp3_pause_done())
212 /* reset volume to what it was before the fade */
213 sound_set_volume(global_settings
.volume
);
217 static bool update_onvol_change(struct gui_wps
* gwps
)
219 skin_update(gwps
, WPS_REFRESH_NON_STATIC
);
221 #ifdef HAVE_LCD_CHARCELLS
222 splashf(0, "Vol: %3d dB",
223 sound_val2phys(SOUND_VOLUME
, global_settings
.volume
));
230 bool ffwd_rew(int button
)
232 unsigned int step
= 0; /* current ff/rewind step */
233 unsigned int max_step
= 0; /* maximum ff/rewind step */
234 int ff_rewind_count
= 0; /* current ff/rewind count (in ticks) */
235 int direction
= -1; /* forward=1 or backward=-1 */
239 const long ff_rw_accel
= (global_settings
.ff_rewind_accel
+ 3);
241 if (button
== ACTION_NONE
)
243 status_set_ffmode(0);
250 case ACTION_WPS_SEEKFWD
:
252 case ACTION_WPS_SEEKBACK
:
253 if (wps_state
.ff_rewind
)
257 /* fast forwarding, calc max step relative to end */
258 max_step
= (wps_state
.id3
->length
-
259 (wps_state
.id3
->elapsed
+
261 FF_REWIND_MAX_PERCENT
/ 100;
265 /* rewinding, calc max step relative to start */
266 max_step
= (wps_state
.id3
->elapsed
+ ff_rewind_count
) *
267 FF_REWIND_MAX_PERCENT
/ 100;
270 max_step
= MAX(max_step
, MIN_FF_REWIND_STEP
);
275 ff_rewind_count
+= step
* direction
;
277 /* smooth seeking by multiplying step by: 1 + (2 ^ -accel) */
278 step
+= step
>> ff_rw_accel
;
282 if ( (audio_status() & AUDIO_STATUS_PLAY
) &&
283 wps_state
.id3
&& wps_state
.id3
->length
)
285 if (!wps_state
.paused
)
286 #if (CONFIG_CODEC == SWCODEC)
287 audio_pre_ff_rewind();
291 #if CONFIG_KEYPAD == PLAYER_PAD
293 gui_wps
[i
].display
->stop_scroll();
296 status_set_ffmode(STATUS_FASTFORWARD
);
298 status_set_ffmode(STATUS_FASTBACKWARD
);
300 wps_state
.ff_rewind
= true;
302 step
= 1000 * global_settings
.ff_rewind_min_step
;
309 if ((wps_state
.id3
->elapsed
+ ff_rewind_count
) >
310 wps_state
.id3
->length
)
311 ff_rewind_count
= wps_state
.id3
->length
-
312 wps_state
.id3
->elapsed
;
315 if ((int)(wps_state
.id3
->elapsed
+ ff_rewind_count
) < 0)
316 ff_rewind_count
= -wps_state
.id3
->elapsed
;
319 /* set the wps state ff_rewind_count so the progess info
321 wps_state
.ff_rewind_count
= (wps_state
.wps_time_countup
== false)?
322 ff_rewind_count
:-ff_rewind_count
;
325 skin_update(&gui_wps
[i
],
326 WPS_REFRESH_PLAYER_PROGRESS
|
327 WPS_REFRESH_DYNAMIC
);
332 case ACTION_WPS_STOPSEEK
:
333 wps_state
.id3
->elapsed
= wps_state
.id3
->elapsed
+ff_rewind_count
;
334 audio_ff_rewind(wps_state
.id3
->elapsed
);
335 wps_state
.ff_rewind_count
= 0;
336 wps_state
.ff_rewind
= false;
337 status_set_ffmode(0);
338 #if (CONFIG_CODEC != SWCODEC)
339 if (!wps_state
.paused
)
342 #ifdef HAVE_LCD_CHARCELLS
344 skin_update(&gui_wps
[i
], WPS_REFRESH_ALL
);
350 if(default_event_handler(button
) == SYS_USB_CONNECTED
) {
351 status_set_ffmode(0);
359 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_BLOCK
);
360 #ifdef HAVE_TOUCHSCREEN
361 if (button
== ACTION_TOUCHSCREEN
)
362 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
370 void display_keylock_text(bool locked
)
374 gui_wps
[i
].display
->stop_scroll();
376 splash(HZ
, locked
? ID2P(LANG_KEYLOCK_ON
) : ID2P(LANG_KEYLOCK_OFF
));
382 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
383 static void gwps_caption_backlight(struct wps_state
*state
)
385 if (state
&& state
->id3
)
387 #ifdef HAVE_BACKLIGHT
388 if (global_settings
.caption_backlight
)
390 /* turn on backlight n seconds before track ends, and turn it off n
391 seconds into the new track. n == backlight_timeout, or 5s */
392 int n
= global_settings
.backlight_timeout
* 1000;
395 n
= 5000; /* use 5s if backlight is always on or off */
397 if (((state
->id3
->elapsed
< 1000) ||
398 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
399 (state
->paused
== false))
403 #ifdef HAVE_REMOTE_LCD
404 if (global_settings
.remote_caption_backlight
)
406 /* turn on remote backlight n seconds before track ends, and turn it
407 off n seconds into the new track. n == remote_backlight_timeout,
409 int n
= global_settings
.remote_backlight_timeout
* 1000;
412 n
= 5000; /* use 5s if backlight is always on or off */
414 if (((state
->id3
->elapsed
< 1000) ||
415 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
416 (state
->paused
== false))
417 remote_backlight_on();
425 static void change_dir(int direction
)
427 if (global_settings
.prevent_skip
)
432 else if (direction
> 0)
434 /* prevent the next dir to immediatly start being ffw'd */
435 action_wait_for_release();
438 static void prev_track(unsigned long skip_thresh
)
440 if (wps_state
.id3
->elapsed
< skip_thresh
)
447 if (wps_state
.id3
->cuesheet
)
449 curr_cuesheet_skip(wps_state
.id3
->cuesheet
, -1, wps_state
.id3
->elapsed
);
453 if (!wps_state
.paused
)
454 #if (CONFIG_CODEC == SWCODEC)
455 audio_pre_ff_rewind();
462 #if (CONFIG_CODEC != SWCODEC)
463 if (!wps_state
.paused
)
469 static void next_track(void)
471 /* take care of if we're playing a cuesheet */
472 if (wps_state
.id3
->cuesheet
)
474 if (curr_cuesheet_skip(wps_state
.id3
->cuesheet
, 1, wps_state
.id3
->elapsed
))
476 /* if the result was false, then we really want
477 to skip to the next track */
485 static void play_hop(int direction
)
487 long step
= global_settings
.skip_length
*1000;
488 long elapsed
= wps_state
.id3
->elapsed
;
489 long remaining
= wps_state
.id3
->length
- elapsed
;
495 prev_track(DEFAULT_SKIP_TRESH
);
498 else if (remaining
< DEFAULT_SKIP_TRESH
*2)
504 elapsed
+= (remaining
- DEFAULT_SKIP_TRESH
*2);
506 else 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
);
517 else if (direction
== 1 && step
>= remaining
)
519 #if CONFIG_CODEC == SWCODEC
520 if(global_settings
.beep
)
521 pcmbuf_beep(1000, 150, 1500*global_settings
.beep
);
525 else if ((direction
== -1 && elapsed
< step
))
531 elapsed
+= step
* direction
;
533 if((audio_status() & AUDIO_STATUS_PLAY
) && !wps_state
.paused
)
535 #if (CONFIG_CODEC == SWCODEC)
536 audio_pre_ff_rewind();
541 audio_ff_rewind(wps_state
.id3
->elapsed
= elapsed
);
542 #if (CONFIG_CODEC != SWCODEC)
543 if (!wps_state
.paused
)
549 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
551 * If the user is unable to see the wps, because the display is deactivated,
552 * we suppress updates until the wps is activated again (the lcd driver will
553 * call this hook to issue an instant update)
555 static void wps_lcd_activation_hook(void *param
)
558 wps_sync_data
.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)
570 gui_wps
[i
].display
->stop_scroll();
571 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
572 gui_wps
[i
].display
->backdrop_show(sb_get_backdrop(i
));
574 viewportmanager_theme_undo(i
, skin_has_sbs(i
, gui_wps
[i
].data
));
578 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
579 /* Play safe and unregister the hook */
580 remove_event(LCD_EVENT_ACTIVATION
, wps_lcd_activation_hook
);
582 /* unhandle statusbar update delay */
583 sb_skin_set_update_delay(DEFAULT_UPDATE_DELAY
);
587 * display the wps on entering or restoring */
588 static void gwps_enter_wps(void)
593 struct gui_wps
*gwps
= &gui_wps
[i
];
594 struct screen
*display
= gwps
->display
;
595 display
->stop_scroll();
596 viewportmanager_theme_enable(i
, skin_has_sbs(i
, gui_wps
[i
].data
), NULL
);
598 /* Update the values in the first (default) viewport - in case the user
599 has modified the statusbar or colour settings */
601 if (display
->depth
> 1)
603 struct viewport
*vp
= &find_viewport(VP_DEFAULT_LABEL
, gwps
->data
)->vp
;
604 vp
->fg_pattern
= display
->get_foreground();
605 vp
->bg_pattern
= display
->get_background();
608 /* make the backdrop actually take effect */
609 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
610 display
->backdrop_show(gwps
->data
->backdrop
);
612 display
->clear_display();
613 skin_update(gwps
, WPS_REFRESH_ALL
);
615 #ifdef HAVE_TOUCHSCREEN
616 wps_disarm_touchregions(gui_wps
[i
].data
);
619 /* force statusbar/skin update since we just cleared the whole screen */
620 send_event(GUI_EVENT_ACTIONUPDATE
, (void*)1);
623 #ifdef HAVE_TOUCHSCREEN
624 /** Disarms all touchregions. */
625 static void wps_disarm_touchregions(struct wps_data
*data
)
627 struct skin_token_list
*regions
= data
->touchregions
;
630 ((struct touchregion
*)regions
->token
->value
.data
)->armed
= false;
631 regions
= regions
->next
;
635 int wps_get_touchaction(struct wps_data
*data
)
637 int returncode
= ACTION_NONE
;
640 int type
= action_get_touchscreen_press(&x
, &y
);
641 static int last_action
= ACTION_NONE
;
642 struct touchregion
*r
;
643 bool repeated
= (type
== BUTTON_REPEAT
);
644 bool released
= (type
== BUTTON_REL
);
645 bool pressed
= (type
== BUTTON_TOUCHSCREEN
);
646 struct skin_token_list
*regions
= data
->touchregions
;
650 r
= (struct touchregion
*)regions
->token
->value
.data
;
651 /* make sure this region's viewport is visible */
652 if (r
->wvp
->hidden_flags
&VP_DRAW_HIDDEN
)
654 regions
= regions
->next
;
657 /* check if it's inside this viewport */
658 if (viewport_point_within_vp(&(r
->wvp
->vp
), x
, y
))
659 { /* reposition the touch inside the viewport since touchregions
660 * are relative to a preceding viewport */
661 vx
= x
- r
->wvp
->vp
.x
;
662 vy
= y
- r
->wvp
->vp
.y
;
663 /* now see if the point is inside this region */
664 if (vx
>= r
->x
&& vx
< r
->x
+r
->width
&&
665 vy
>= r
->y
&& vy
< r
->y
+r
->height
)
667 /* reposition the touch within the area */
673 case WPS_TOUCHREGION_ACTION
:
674 if (r
->armed
&& ((repeated
&& r
->repeat
) || (released
&& !r
->repeat
)))
676 last_action
= r
->action
;
677 returncode
= r
->action
;
682 case WPS_TOUCHREGION_SCROLLBAR
:
683 if(r
->width
> r
->height
)
685 wps_state
.id3
->elapsed
= (vx
*
686 wps_state
.id3
->length
) / r
->width
;
689 wps_state
.id3
->elapsed
= (vy
*
690 wps_state
.id3
->length
) / r
->height
;
692 if (!wps_state
.paused
)
693 #if (CONFIG_CODEC == SWCODEC)
694 audio_pre_ff_rewind();
698 audio_ff_rewind(wps_state
.id3
->elapsed
);
699 #if (CONFIG_CODEC != SWCODEC)
700 if (!wps_state
.paused
)
704 case WPS_TOUCHREGION_VOLUME
:
706 const int min_vol
= sound_min(SOUND_VOLUME
);
707 const int max_vol
= sound_max(SOUND_VOLUME
);
708 if(r
->width
> r
->height
)
710 global_settings
.volume
= (vx
*
711 (max_vol
- min_vol
)) / r
->width
;
714 global_settings
.volume
= ((r
->height
- vy
) *
715 (max_vol
-min_vol
)) / r
->height
;
717 global_settings
.volume
+= min_vol
;
719 returncode
= ACTION_REDRAW
;
724 regions
= regions
->next
;
727 /* On release, all regions are disarmed. */
729 wps_disarm_touchregions(data
);
731 if (returncode
!= ACTION_NONE
)
734 if ((last_action
== ACTION_WPS_SEEKBACK
|| last_action
== ACTION_WPS_SEEKFWD
))
735 return ACTION_WPS_STOPSEEK
;
736 last_action
= ACTION_TOUCHSCREEN
;
737 return ACTION_TOUCHSCREEN
;
740 /* The WPS can be left in two ways:
741 * a) call a function, which draws over the wps. In this case, the wps
742 * will be still active (i.e. the below function didn't return)
743 * b) return with a value evaluated by root_menu.c, in this case the wps
744 * is really left, and root_menu will handle the next screen
746 * In either way, call gwps_leave_wps(), in order to restore the correct
747 * "main screen" backdrops and statusbars
749 long gui_wps_show(void)
753 long restoretimer
= RESTORE_WPS_INSTANTLY
; /* timer to delay screen redraw temporarily */
755 bool bookmark
= false;
757 bool vol_changed
= false;
759 long last_left
= 0, last_right
= 0;
761 #ifdef HAVE_LCD_CHARCELLS
762 status_set_audio(true);
763 status_set_param(false);
766 #ifdef AB_REPEAT_ENABLE
774 bool audio_paused
= (audio_status() & AUDIO_STATUS_PAUSE
)?true:false;
776 /* did someone else (i.e power thread) change audio pause mode? */
777 if (wps_state
.paused
!= audio_paused
) {
778 wps_state
.paused
= audio_paused
;
780 /* if another thread paused audio, we are probably in car mode,
781 about to shut down. lets save the settings. */
782 if (wps_state
.paused
) {
784 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
785 call_storage_idle_notifys(true);
789 button
= skin_wait_for_action(gui_wps
, CONTEXT_WPS
|ALLOW_SOFTLOCK
,
792 /* Exit if audio has stopped playing. This happens e.g. at end of
793 playlist or if using the sleep timer. */
794 if (!(audio_status() & AUDIO_STATUS_PLAY
))
796 #ifdef HAVE_TOUCHSCREEN
797 if (button
== ACTION_TOUCHSCREEN
)
798 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
800 /* The iPods/X5/M5 use a single button for the A-B mode markers,
801 defined as ACTION_WPSAB_SINGLE in their config files. */
802 #ifdef ACTION_WPSAB_SINGLE
803 if (!global_settings
.party_mode
&& ab_repeat_mode_enabled())
805 static int wps_ab_state
= 0;
806 if (button
== ACTION_WPSAB_SINGLE
)
808 switch (wps_ab_state
)
810 case 0: /* set the A spot */
811 button
= ACTION_WPS_ABSETA_PREVDIR
;
813 case 1: /* set the B spot */
814 button
= ACTION_WPS_ABSETB_NEXTDIR
;
817 button
= ACTION_WPS_ABRESET
;
820 wps_ab_state
= (wps_ab_state
+1) % 3;
827 case ACTION_WPS_HOTKEY
:
828 if (!global_settings
.hotkey_wps
)
832 case ACTION_WPS_CONTEXT
:
834 bool hotkey
= button
== ACTION_WPS_HOTKEY
;
836 int retval
= onplay(wps_state
.id3
->path
,
837 FILE_ATTR_AUDIO
, CONTEXT_WPS
, hotkey
);
838 /* if music is stopped in the context menu we want to exit the wps */
839 if (retval
== ONPLAY_MAINMENU
842 else if (retval
== ONPLAY_PLAYLIST
)
843 return GO_TO_PLAYLIST_VIEWER
;
848 case ACTION_WPS_BROWSE
:
849 #ifdef HAVE_LCD_CHARCELLS
850 status_set_record(false);
851 status_set_audio(false);
854 return GO_TO_PREVIOUS_BROWSER
;
858 case ACTION_WPS_PLAY
:
859 if (global_settings
.party_mode
)
861 if ( wps_state
.paused
)
863 wps_state
.paused
= false;
864 if ( global_settings
.fade_on_stop
)
871 wps_state
.paused
= true;
872 if ( global_settings
.fade_on_stop
)
877 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
878 call_storage_idle_notifys(true); /* make sure resume info is saved */
883 case ACTION_WPS_VOLUP
:
884 global_settings
.volume
++;
887 case ACTION_WPS_VOLDOWN
:
888 global_settings
.volume
--;
892 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
893 case ACTION_WPS_SEEKFWD
:
894 if (global_settings
.party_mode
)
896 if (current_tick
-last_right
< HZ
)
898 if (wps_state
.id3
->cuesheet
)
908 ffwd_rew(ACTION_WPS_SEEKFWD
);
909 last_right
= last_left
= 0;
912 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
913 case ACTION_WPS_SEEKBACK
:
914 if (global_settings
.party_mode
)
916 if (current_tick
-last_left
< HZ
)
918 if (wps_state
.id3
->cuesheet
)
920 if (!wps_state
.paused
)
921 #if (CONFIG_CODEC == SWCODEC)
922 audio_pre_ff_rewind();
934 ffwd_rew(ACTION_WPS_SEEKBACK
);
935 last_left
= last_right
= 0;
939 case ACTION_WPS_SKIPPREV
:
940 if (global_settings
.party_mode
)
942 last_left
= current_tick
;
943 #ifdef AB_REPEAT_ENABLE
944 /* if we're in A/B repeat mode and the current position
945 is past the A marker, jump back to the A marker... */
946 if ( ab_repeat_mode_enabled() )
948 if ( ab_after_A_marker(wps_state
.id3
->elapsed
) )
950 ab_jump_to_A_marker();
952 #if (AB_REPEAT_ENABLE == 2)
959 /* ...otherwise, do it normally */
965 OR if skip length set, hop by predetermined amount. */
966 case ACTION_WPS_SKIPNEXT
:
967 if (global_settings
.party_mode
)
969 last_right
= current_tick
;
970 #ifdef AB_REPEAT_ENABLE
971 /* if we're in A/B repeat mode and the current position is
972 before the A marker, jump to the A marker... */
973 if ( ab_repeat_mode_enabled() )
975 if ( ab_before_A_marker(wps_state
.id3
->elapsed
) )
977 ab_jump_to_A_marker();
979 #if (AB_REPEAT_ENABLE == 2)
986 /* ...otherwise, do it normally */
990 /* next / prev directories */
991 /* and set A-B markers if in a-b mode */
992 case ACTION_WPS_ABSETB_NEXTDIR
:
993 if (global_settings
.party_mode
)
995 #if defined(AB_REPEAT_ENABLE)
996 if (ab_repeat_mode_enabled())
998 ab_set_B_marker(wps_state
.id3
->elapsed
);
999 ab_jump_to_A_marker();
1007 case ACTION_WPS_ABSETA_PREVDIR
:
1008 if (global_settings
.party_mode
)
1010 #if defined(AB_REPEAT_ENABLE)
1011 if (ab_repeat_mode_enabled())
1012 ab_set_A_marker(wps_state
.id3
->elapsed
);
1019 /* menu key functions */
1020 case ACTION_WPS_MENU
:
1026 #ifdef HAVE_QUICKSCREEN
1027 case ACTION_WPS_QUICKSCREEN
:
1030 if (quick_screen_quick(button
))
1035 #endif /* HAVE_QUICKSCREEN */
1037 /* screen settings */
1042 if (quick_screen_f3(BUTTON_F3
))
1047 #endif /* BUTTON_F3 */
1050 #ifdef HAVE_PITCHSCREEN
1051 case ACTION_WPS_PITCHSCREEN
:
1054 if (1 == gui_syncpitchscreen_run())
1059 #endif /* HAVE_PITCHSCREEN */
1061 #ifdef AB_REPEAT_ENABLE
1062 /* reset A&B markers */
1063 case ACTION_WPS_ABRESET
:
1064 if (ab_repeat_mode_enabled())
1070 #endif /* AB_REPEAT_ENABLE */
1072 /* stop and exit wps */
1073 case ACTION_WPS_STOP
:
1074 if (global_settings
.party_mode
)
1080 case ACTION_WPS_ID3SCREEN
:
1088 #ifdef HAVE_TOUCHSCREEN
1089 case ACTION_TOUCH_SHUFFLE
: /* toggle shuffle mode */
1091 global_settings
.playlist_shuffle
=
1092 !global_settings
.playlist_shuffle
;
1093 #if CONFIG_CODEC == SWCODEC
1094 dsp_set_replaygain();
1096 if (global_settings
.playlist_shuffle
)
1097 playlist_randomise(NULL
, current_tick
, true);
1099 playlist_sort(NULL
, true);
1102 case ACTION_TOUCH_REPMODE
: /* cycle the repeat mode setting */
1104 const struct settings_list
*rep_setting
=
1105 find_setting(&global_settings
.repeat_mode
, NULL
);
1106 option_select_next_val(rep_setting
, false, true);
1107 audio_flush_and_reload_tracks();
1110 #endif /* HAVE_TOUCHSCREEN */
1111 /* this case is used by the softlock feature
1112 * it requests a full update here */
1114 wps_sync_data
.do_full_update
= true;
1116 case ACTION_NONE
: /* Timeout, do a partial update */
1118 ffwd_rew(button
); /* hopefully fix the ffw/rwd bug */
1120 #ifdef HAVE_RECORDING
1121 case ACTION_WPS_REC
:
1126 default_event_handler(SYS_POWEROFF
);
1128 case ACTION_WPS_VIEW_PLAYLIST
:
1130 return GO_TO_PLAYLIST_VIEWER
;
1133 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1145 vol_changed
= false;
1149 if(update_onvol_change(&gui_wps
[i
]))
1154 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
1160 ((restoretimer
== RESTORE_WPS_INSTANTLY
) ||
1161 TIME_AFTER(current_tick
, restoretimer
)))
1164 restoretimer
= RESTORE_WPS_INSTANTLY
;
1165 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1166 add_event(LCD_EVENT_ACTIVATION
, false, wps_lcd_activation_hook
);
1168 /* we remove the update delay since it's not very usable in the wps,
1169 * e.g. during volume changing or ffwd/rewind */
1170 sb_skin_set_update_delay(0);
1171 wps_sync_data
.do_full_update
= update
= false;
1174 else if (wps_sync_data
.do_full_update
|| update
)
1176 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
1177 gwps_caption_backlight(&wps_state
);
1181 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1182 /* currently, all remotes are readable without backlight
1183 * so still update those */
1184 if (lcd_active() || (i
!= SCREEN_MAIN
))
1187 skin_update(&gui_wps
[i
], wps_sync_data
.do_full_update
?
1188 WPS_REFRESH_ALL
: WPS_REFRESH_NON_STATIC
);
1191 wps_sync_data
.do_full_update
= false;
1196 #ifdef HAVE_LCD_CHARCELLS
1197 status_set_record(false);
1198 status_set_audio(false);
1200 if (global_settings
.fade_on_stop
)
1204 bookmark_autobookmark(true);
1206 #ifdef AB_REPEAT_ENABLE
1210 #ifdef HAVE_RECORDING
1211 if (button
== ACTION_WPS_REC
)
1212 return GO_TO_RECSCREEN
;
1214 if (global_settings
.browse_current
)
1215 return GO_TO_PREVIOUS_BROWSER
;
1216 return GO_TO_PREVIOUS
;
1219 if (button
&& !IS_SYSEVENT(button
) )
1222 return GO_TO_ROOT
; /* unreachable - just to reduce compiler warnings */
1225 /* this is called from the playback thread so NO DRAWING! */
1226 static void track_changed_callback(void *param
)
1228 wps_state
.id3
= (struct mp3entry
*)param
;
1229 wps_state
.nid3
= audio_next_track();
1230 if (wps_state
.id3
->cuesheet
)
1232 cue_find_current_track(wps_state
.id3
->cuesheet
, wps_state
.id3
->elapsed
);
1233 cue_spoof_id3(wps_state
.id3
->cuesheet
, wps_state
.id3
);
1235 wps_sync_data
.do_full_update
= true;
1237 static void nextid3available_callback(void* param
)
1240 wps_state
.nid3
= audio_next_track();
1241 wps_sync_data
.do_full_update
= true;
1245 static void wps_state_init(void)
1247 wps_state
.ff_rewind
= false;
1248 wps_state
.paused
= false;
1249 if(audio_status() & AUDIO_STATUS_PLAY
)
1251 wps_state
.id3
= audio_current_track();
1252 wps_state
.nid3
= audio_next_track();
1256 wps_state
.id3
= NULL
;
1257 wps_state
.nid3
= NULL
;
1259 /* We'll be updating due to restore initialized with true */
1260 wps_sync_data
.do_full_update
= false;
1261 /* add the WPS track event callbacks */
1262 add_event(PLAYBACK_EVENT_TRACK_CHANGE
, false, track_changed_callback
);
1263 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, false, nextid3available_callback
);
1267 void gui_sync_wps_init(void)
1272 #ifdef HAVE_ALBUMART
1273 wps_datas
[i
].albumart
= NULL
;
1274 wps_datas
[i
].playback_aa_slot
= -1;
1276 gui_wps
[i
].data
= &wps_datas
[i
];
1277 gui_wps
[i
].display
= &screens
[i
];
1278 /* Currently no seperate wps_state needed/possible
1279 so use the only available ( "global" ) one */
1280 gui_wps
[i
].state
= &wps_state
;
1281 /* must point to the same struct for both screens */
1282 gui_wps
[i
].sync_data
= &wps_sync_data
;
1287 #ifdef IPOD_ACCESSORY_PROTOCOL
1288 bool is_wps_fading(void)
1290 return wps_state
.is_fading
;
1293 int wps_get_ff_rewind_count(void)
1295 return wps_state
.ff_rewind_count
;