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
));
575 #ifdef HAVE_LCD_BITMAP
577 if (gui_wps
[i
].data
->wps_sb_tag
)
578 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
579 else if (statusbar_position(i
) != STATUSBAR_OFF
)
582 viewportmanager_theme_undo(i
, draw
);
586 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
587 /* Play safe and unregister the hook */
588 remove_event(LCD_EVENT_ACTIVATION
, wps_lcd_activation_hook
);
590 /* unhandle statusbar update delay */
591 sb_skin_set_update_delay(DEFAULT_UPDATE_DELAY
);
595 * display the wps on entering or restoring */
596 static void gwps_enter_wps(void)
601 struct gui_wps
*gwps
= &gui_wps
[i
];
602 struct screen
*display
= gwps
->display
;
603 #ifdef HAVE_LCD_BITMAP
605 if (gui_wps
[i
].data
->wps_sb_tag
)
606 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
607 else if (statusbar_position(i
) != STATUSBAR_OFF
)
610 display
->stop_scroll();
611 viewportmanager_theme_enable(i
, draw
, NULL
);
613 /* Update the values in the first (default) viewport - in case the user
614 has modified the statusbar or colour settings */
616 if (display
->depth
> 1)
618 struct viewport
*vp
= &find_viewport(VP_DEFAULT_LABEL
, gwps
->data
)->vp
;
619 vp
->fg_pattern
= display
->get_foreground();
620 vp
->bg_pattern
= display
->get_background();
623 /* make the backdrop actually take effect */
624 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
625 display
->backdrop_show(gwps
->data
->backdrop
);
627 display
->clear_display();
628 skin_update(gwps
, WPS_REFRESH_ALL
);
630 #ifdef HAVE_TOUCHSCREEN
631 wps_disarm_touchregions(gui_wps
[i
].data
);
634 /* force statusbar/skin update since we just cleared the whole screen */
635 send_event(GUI_EVENT_ACTIONUPDATE
, (void*)1);
638 #ifdef HAVE_TOUCHSCREEN
639 /** Disarms all touchregions. */
640 static void wps_disarm_touchregions(struct wps_data
*data
)
642 struct skin_token_list
*regions
= data
->touchregions
;
645 ((struct touchregion
*)regions
->token
->value
.data
)->armed
= false;
646 regions
= regions
->next
;
650 int wps_get_touchaction(struct wps_data
*data
)
652 int returncode
= ACTION_NONE
;
655 int type
= action_get_touchscreen_press(&x
, &y
);
656 static int last_action
= ACTION_NONE
;
657 struct touchregion
*r
;
658 bool repeated
= (type
== BUTTON_REPEAT
);
659 bool released
= (type
== BUTTON_REL
);
660 bool pressed
= (type
== BUTTON_TOUCHSCREEN
);
661 struct skin_token_list
*regions
= data
->touchregions
;
665 r
= (struct touchregion
*)regions
->token
->value
.data
;
666 /* make sure this region's viewport is visible */
667 if (r
->wvp
->hidden_flags
&VP_DRAW_HIDDEN
)
669 regions
= regions
->next
;
672 /* check if it's inside this viewport */
673 if (viewport_point_within_vp(&(r
->wvp
->vp
), x
, y
))
674 { /* reposition the touch inside the viewport since touchregions
675 * are relative to a preceding viewport */
676 vx
= x
- r
->wvp
->vp
.x
;
677 vy
= y
- r
->wvp
->vp
.y
;
678 /* now see if the point is inside this region */
679 if (vx
>= r
->x
&& vx
< r
->x
+r
->width
&&
680 vy
>= r
->y
&& vy
< r
->y
+r
->height
)
682 /* reposition the touch within the area */
688 case WPS_TOUCHREGION_ACTION
:
689 if (r
->armed
&& ((repeated
&& r
->repeat
) || (released
&& !r
->repeat
)))
691 last_action
= r
->action
;
692 returncode
= r
->action
;
697 case WPS_TOUCHREGION_SCROLLBAR
:
698 if(r
->width
> r
->height
)
700 wps_state
.id3
->elapsed
= (vx
*
701 wps_state
.id3
->length
) / r
->width
;
704 wps_state
.id3
->elapsed
= (vy
*
705 wps_state
.id3
->length
) / r
->height
;
707 if (!wps_state
.paused
)
708 #if (CONFIG_CODEC == SWCODEC)
709 audio_pre_ff_rewind();
713 audio_ff_rewind(wps_state
.id3
->elapsed
);
714 #if (CONFIG_CODEC != SWCODEC)
715 if (!wps_state
.paused
)
719 case WPS_TOUCHREGION_VOLUME
:
721 const int min_vol
= sound_min(SOUND_VOLUME
);
722 const int max_vol
= sound_max(SOUND_VOLUME
);
723 if(r
->width
> r
->height
)
725 global_settings
.volume
= (vx
*
726 (max_vol
- min_vol
)) / r
->width
;
729 global_settings
.volume
= ((r
->height
- vy
) *
730 (max_vol
-min_vol
)) / r
->height
;
732 global_settings
.volume
+= min_vol
;
734 returncode
= ACTION_REDRAW
;
739 regions
= regions
->next
;
742 /* On release, all regions are disarmed. */
744 wps_disarm_touchregions(data
);
746 if (returncode
!= ACTION_NONE
)
749 if ((last_action
== ACTION_WPS_SEEKBACK
|| last_action
== ACTION_WPS_SEEKFWD
))
750 return ACTION_WPS_STOPSEEK
;
751 last_action
= ACTION_TOUCHSCREEN
;
752 return ACTION_TOUCHSCREEN
;
755 /* The WPS can be left in two ways:
756 * a) call a function, which draws over the wps. In this case, the wps
757 * will be still active (i.e. the below function didn't return)
758 * b) return with a value evaluated by root_menu.c, in this case the wps
759 * is really left, and root_menu will handle the next screen
761 * In either way, call gwps_leave_wps(), in order to restore the correct
762 * "main screen" backdrops and statusbars
764 long gui_wps_show(void)
768 long restoretimer
= RESTORE_WPS_INSTANTLY
; /* timer to delay screen redraw temporarily */
770 bool bookmark
= false;
772 bool vol_changed
= false;
774 long last_left
= 0, last_right
= 0;
776 #ifdef HAVE_LCD_CHARCELLS
777 status_set_audio(true);
778 status_set_param(false);
781 #ifdef AB_REPEAT_ENABLE
789 bool audio_paused
= (audio_status() & AUDIO_STATUS_PAUSE
)?true:false;
791 /* did someone else (i.e power thread) change audio pause mode? */
792 if (wps_state
.paused
!= audio_paused
) {
793 wps_state
.paused
= audio_paused
;
795 /* if another thread paused audio, we are probably in car mode,
796 about to shut down. lets save the settings. */
797 if (wps_state
.paused
) {
799 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
800 call_storage_idle_notifys(true);
804 #ifdef HAVE_LCD_BITMAP
805 /* when the peak meter is enabled we want to have a
806 few extra updates to make it look smooth. On the
807 other hand we don't want to waste energy if it
812 if(gui_wps
[i
].data
->peak_meter_enabled
)
817 long next_refresh
= current_tick
;
818 long next_big_refresh
= current_tick
+ HZ
/ 5;
819 button
= BUTTON_NONE
;
820 while (TIME_BEFORE(current_tick
, next_big_refresh
)) {
821 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_NOBLOCK
);
822 /* check for restore to not let the peakmeter delay the
823 * initial draw of the wps, don't delay handling of button
825 if (button
!= ACTION_NONE
|| restore
) {
829 sleep(0); /* Sleep until end of current tick. */
831 if (TIME_AFTER(current_tick
, next_refresh
)) {
834 if(gui_wps
[i
].data
->peak_meter_enabled
)
835 skin_update(&gui_wps
[i
], WPS_REFRESH_PEAK_METER
);
836 next_refresh
+= HZ
/ PEAK_METER_FPS
;
843 /* The peak meter is disabled
844 -> no additional screen updates needed */
847 { /* 1 is the minimum timeout which lets other threads run.
848 * audio thread (apprently) needs to run before displaying the wps
849 * or bad things happen with regards to cuesheet
850 * (probably a race condition, on sh at least) */
851 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,
855 /* Exit if audio has stopped playing. This happens e.g. at end of
856 playlist or if using the sleep timer. */
857 if (!(audio_status() & AUDIO_STATUS_PLAY
))
859 #ifdef HAVE_TOUCHSCREEN
860 if (button
== ACTION_TOUCHSCREEN
)
861 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
863 /* The iPods/X5/M5 use a single button for the A-B mode markers,
864 defined as ACTION_WPSAB_SINGLE in their config files. */
865 #ifdef ACTION_WPSAB_SINGLE
866 if (!global_settings
.party_mode
&& ab_repeat_mode_enabled())
868 static int wps_ab_state
= 0;
869 if (button
== ACTION_WPSAB_SINGLE
)
871 switch (wps_ab_state
)
873 case 0: /* set the A spot */
874 button
= ACTION_WPS_ABSETA_PREVDIR
;
876 case 1: /* set the B spot */
877 button
= ACTION_WPS_ABSETB_NEXTDIR
;
880 button
= ACTION_WPS_ABRESET
;
883 wps_ab_state
= (wps_ab_state
+1) % 3;
890 case ACTION_WPS_HOTKEY
:
891 if (!global_settings
.hotkey_wps
)
895 case ACTION_WPS_CONTEXT
:
897 bool hotkey
= button
== ACTION_WPS_HOTKEY
;
899 int retval
= onplay(wps_state
.id3
->path
,
900 FILE_ATTR_AUDIO
, CONTEXT_WPS
, hotkey
);
901 /* if music is stopped in the context menu we want to exit the wps */
902 if (retval
== ONPLAY_MAINMENU
905 else if (retval
== ONPLAY_PLAYLIST
)
906 return GO_TO_PLAYLIST_VIEWER
;
911 case ACTION_WPS_BROWSE
:
912 #ifdef HAVE_LCD_CHARCELLS
913 status_set_record(false);
914 status_set_audio(false);
917 return GO_TO_PREVIOUS_BROWSER
;
921 case ACTION_WPS_PLAY
:
922 if (global_settings
.party_mode
)
924 if ( wps_state
.paused
)
926 wps_state
.paused
= false;
927 if ( global_settings
.fade_on_stop
)
934 wps_state
.paused
= true;
935 if ( global_settings
.fade_on_stop
)
940 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
941 call_storage_idle_notifys(true); /* make sure resume info is saved */
946 case ACTION_WPS_VOLUP
:
947 global_settings
.volume
++;
950 case ACTION_WPS_VOLDOWN
:
951 global_settings
.volume
--;
955 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
956 case ACTION_WPS_SEEKFWD
:
957 if (global_settings
.party_mode
)
959 if (current_tick
-last_right
< HZ
)
961 if (wps_state
.id3
->cuesheet
)
971 ffwd_rew(ACTION_WPS_SEEKFWD
);
972 last_right
= last_left
= 0;
975 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
976 case ACTION_WPS_SEEKBACK
:
977 if (global_settings
.party_mode
)
979 if (current_tick
-last_left
< HZ
)
981 if (wps_state
.id3
->cuesheet
)
983 if (!wps_state
.paused
)
984 #if (CONFIG_CODEC == SWCODEC)
985 audio_pre_ff_rewind();
997 ffwd_rew(ACTION_WPS_SEEKBACK
);
998 last_left
= last_right
= 0;
1001 /* prev / restart */
1002 case ACTION_WPS_SKIPPREV
:
1003 if (global_settings
.party_mode
)
1005 last_left
= current_tick
;
1006 #ifdef AB_REPEAT_ENABLE
1007 /* if we're in A/B repeat mode and the current position
1008 is past the A marker, jump back to the A marker... */
1009 if ( ab_repeat_mode_enabled() )
1011 if ( ab_after_A_marker(wps_state
.id3
->elapsed
) )
1013 ab_jump_to_A_marker();
1015 #if (AB_REPEAT_ENABLE == 2)
1022 /* ...otherwise, do it normally */
1028 OR if skip length set, hop by predetermined amount. */
1029 case ACTION_WPS_SKIPNEXT
:
1030 if (global_settings
.party_mode
)
1032 last_right
= current_tick
;
1033 #ifdef AB_REPEAT_ENABLE
1034 /* if we're in A/B repeat mode and the current position is
1035 before the A marker, jump to the A marker... */
1036 if ( ab_repeat_mode_enabled() )
1038 if ( ab_before_A_marker(wps_state
.id3
->elapsed
) )
1040 ab_jump_to_A_marker();
1042 #if (AB_REPEAT_ENABLE == 2)
1049 /* ...otherwise, do it normally */
1053 /* next / prev directories */
1054 /* and set A-B markers if in a-b mode */
1055 case ACTION_WPS_ABSETB_NEXTDIR
:
1056 if (global_settings
.party_mode
)
1058 #if defined(AB_REPEAT_ENABLE)
1059 if (ab_repeat_mode_enabled())
1061 ab_set_B_marker(wps_state
.id3
->elapsed
);
1062 ab_jump_to_A_marker();
1070 case ACTION_WPS_ABSETA_PREVDIR
:
1071 if (global_settings
.party_mode
)
1073 #if defined(AB_REPEAT_ENABLE)
1074 if (ab_repeat_mode_enabled())
1075 ab_set_A_marker(wps_state
.id3
->elapsed
);
1082 /* menu key functions */
1083 case ACTION_WPS_MENU
:
1089 #ifdef HAVE_QUICKSCREEN
1090 case ACTION_WPS_QUICKSCREEN
:
1093 if (quick_screen_quick(button
))
1098 #endif /* HAVE_QUICKSCREEN */
1100 /* screen settings */
1105 if (quick_screen_f3(BUTTON_F3
))
1110 #endif /* BUTTON_F3 */
1113 #ifdef HAVE_PITCHSCREEN
1114 case ACTION_WPS_PITCHSCREEN
:
1117 if (1 == gui_syncpitchscreen_run())
1122 #endif /* HAVE_PITCHSCREEN */
1124 #ifdef AB_REPEAT_ENABLE
1125 /* reset A&B markers */
1126 case ACTION_WPS_ABRESET
:
1127 if (ab_repeat_mode_enabled())
1133 #endif /* AB_REPEAT_ENABLE */
1135 /* stop and exit wps */
1136 case ACTION_WPS_STOP
:
1137 if (global_settings
.party_mode
)
1143 case ACTION_WPS_ID3SCREEN
:
1151 #ifdef HAVE_TOUCHSCREEN
1152 case ACTION_TOUCH_SHUFFLE
: /* toggle shuffle mode */
1154 global_settings
.playlist_shuffle
=
1155 !global_settings
.playlist_shuffle
;
1156 #if CONFIG_CODEC == SWCODEC
1157 dsp_set_replaygain();
1159 if (global_settings
.playlist_shuffle
)
1160 playlist_randomise(NULL
, current_tick
, true);
1162 playlist_sort(NULL
, true);
1165 case ACTION_TOUCH_REPMODE
: /* cycle the repeat mode setting */
1167 const struct settings_list
*rep_setting
=
1168 find_setting(&global_settings
.repeat_mode
, NULL
);
1169 option_select_next_val(rep_setting
, false, true);
1170 audio_flush_and_reload_tracks();
1173 #endif /* HAVE_TOUCHSCREEN */
1174 /* this case is used by the softlock feature
1175 * it requests a full update here */
1177 wps_sync_data
.do_full_update
= true;
1179 case ACTION_NONE
: /* Timeout, do a partial update */
1181 ffwd_rew(button
); /* hopefully fix the ffw/rwd bug */
1183 #ifdef HAVE_RECORDING
1184 case ACTION_WPS_REC
:
1189 default_event_handler(SYS_POWEROFF
);
1191 case ACTION_WPS_VIEW_PLAYLIST
:
1193 return GO_TO_PLAYLIST_VIEWER
;
1196 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1208 vol_changed
= false;
1212 if(update_onvol_change(&gui_wps
[i
]))
1217 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
1223 ((restoretimer
== RESTORE_WPS_INSTANTLY
) ||
1224 TIME_AFTER(current_tick
, restoretimer
)))
1227 restoretimer
= RESTORE_WPS_INSTANTLY
;
1228 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1229 add_event(LCD_EVENT_ACTIVATION
, false, wps_lcd_activation_hook
);
1231 /* we remove the update delay since it's not very usable in the wps,
1232 * e.g. during volume changing or ffwd/rewind */
1233 sb_skin_set_update_delay(0);
1234 wps_sync_data
.do_full_update
= update
= false;
1237 else if (wps_sync_data
.do_full_update
|| update
)
1239 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
1240 gwps_caption_backlight(&wps_state
);
1244 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1245 /* currently, all remotes are readable without backlight
1246 * so still update those */
1247 if (lcd_active() || (i
!= SCREEN_MAIN
))
1250 skin_update(&gui_wps
[i
], wps_sync_data
.do_full_update
?
1251 WPS_REFRESH_ALL
: WPS_REFRESH_NON_STATIC
);
1254 wps_sync_data
.do_full_update
= false;
1259 #ifdef HAVE_LCD_CHARCELLS
1260 status_set_record(false);
1261 status_set_audio(false);
1263 if (global_settings
.fade_on_stop
)
1267 bookmark_autobookmark(true);
1269 #ifdef AB_REPEAT_ENABLE
1273 #ifdef HAVE_RECORDING
1274 if (button
== ACTION_WPS_REC
)
1275 return GO_TO_RECSCREEN
;
1277 if (global_settings
.browse_current
)
1278 return GO_TO_PREVIOUS_BROWSER
;
1279 return GO_TO_PREVIOUS
;
1282 if (button
&& !IS_SYSEVENT(button
) )
1285 return GO_TO_ROOT
; /* unreachable - just to reduce compiler warnings */
1288 /* this is called from the playback thread so NO DRAWING! */
1289 static void track_changed_callback(void *param
)
1291 wps_state
.id3
= (struct mp3entry
*)param
;
1292 wps_state
.nid3
= audio_next_track();
1293 if (wps_state
.id3
->cuesheet
)
1295 cue_find_current_track(wps_state
.id3
->cuesheet
, wps_state
.id3
->elapsed
);
1296 cue_spoof_id3(wps_state
.id3
->cuesheet
, wps_state
.id3
);
1298 wps_sync_data
.do_full_update
= true;
1300 static void nextid3available_callback(void* param
)
1303 wps_state
.nid3
= audio_next_track();
1304 wps_sync_data
.do_full_update
= true;
1308 static void wps_state_init(void)
1310 wps_state
.ff_rewind
= false;
1311 wps_state
.paused
= false;
1312 if(audio_status() & AUDIO_STATUS_PLAY
)
1314 wps_state
.id3
= audio_current_track();
1315 wps_state
.nid3
= audio_next_track();
1319 wps_state
.id3
= NULL
;
1320 wps_state
.nid3
= NULL
;
1322 /* We'll be updating due to restore initialized with true */
1323 wps_sync_data
.do_full_update
= false;
1324 /* add the WPS track event callbacks */
1325 add_event(PLAYBACK_EVENT_TRACK_CHANGE
, false, track_changed_callback
);
1326 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, false, nextid3available_callback
);
1330 void gui_sync_wps_init(void)
1335 #ifdef HAVE_ALBUMART
1336 wps_datas
[i
].albumart
= NULL
;
1337 wps_datas
[i
].playback_aa_slot
= -1;
1339 gui_wps
[i
].data
= &wps_datas
[i
];
1340 gui_wps
[i
].display
= &screens
[i
];
1341 /* Currently no seperate wps_state needed/possible
1342 so use the only available ( "global" ) one */
1343 gui_wps
[i
].state
= &wps_state
;
1344 /* must point to the same struct for both screens */
1345 gui_wps
[i
].sync_data
= &wps_sync_data
;
1350 #ifdef IPOD_ACCESSORY_PROTOCOL
1351 bool is_wps_fading(void)
1353 return wps_state
.is_fading
;
1356 int wps_get_ff_rewind_count(void)
1358 return wps_state
.ff_rewind_count
;