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;
889 case ACTION_WPS_CONTEXT
:
890 case ACTION_WPS_HOTKEY
:
892 bool hotkey
= button
== ACTION_WPS_HOTKEY
;
894 int retval
= onplay(wps_state
.id3
->path
,
895 FILE_ATTR_AUDIO
, CONTEXT_WPS
, hotkey
);
896 /* if music is stopped in the context menu we want to exit the wps */
897 if (retval
== ONPLAY_MAINMENU
900 else if (retval
== ONPLAY_PLAYLIST
)
901 return GO_TO_PLAYLIST_VIEWER
;
906 case ACTION_WPS_BROWSE
:
907 #ifdef HAVE_LCD_CHARCELLS
908 status_set_record(false);
909 status_set_audio(false);
912 return GO_TO_PREVIOUS_BROWSER
;
916 case ACTION_WPS_PLAY
:
917 if (global_settings
.party_mode
)
919 if ( wps_state
.paused
)
921 wps_state
.paused
= false;
922 if ( global_settings
.fade_on_stop
)
929 wps_state
.paused
= true;
930 if ( global_settings
.fade_on_stop
)
935 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
936 call_storage_idle_notifys(true); /* make sure resume info is saved */
941 case ACTION_WPS_VOLUP
:
942 global_settings
.volume
++;
945 case ACTION_WPS_VOLDOWN
:
946 global_settings
.volume
--;
950 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
951 case ACTION_WPS_SEEKFWD
:
952 if (global_settings
.party_mode
)
954 if (current_tick
-last_right
< HZ
)
956 if (wps_state
.id3
->cuesheet
)
966 ffwd_rew(ACTION_WPS_SEEKFWD
);
967 last_right
= last_left
= 0;
970 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
971 case ACTION_WPS_SEEKBACK
:
972 if (global_settings
.party_mode
)
974 if (current_tick
-last_left
< HZ
)
976 if (wps_state
.id3
->cuesheet
)
978 if (!wps_state
.paused
)
979 #if (CONFIG_CODEC == SWCODEC)
980 audio_pre_ff_rewind();
992 ffwd_rew(ACTION_WPS_SEEKBACK
);
993 last_left
= last_right
= 0;
997 case ACTION_WPS_SKIPPREV
:
998 if (global_settings
.party_mode
)
1000 last_left
= current_tick
;
1001 #ifdef AB_REPEAT_ENABLE
1002 /* if we're in A/B repeat mode and the current position
1003 is past the A marker, jump back to the A marker... */
1004 if ( ab_repeat_mode_enabled() )
1006 if ( ab_after_A_marker(wps_state
.id3
->elapsed
) )
1008 ab_jump_to_A_marker();
1010 #if (AB_REPEAT_ENABLE == 2)
1017 /* ...otherwise, do it normally */
1023 OR if skip length set, hop by predetermined amount. */
1024 case ACTION_WPS_SKIPNEXT
:
1025 if (global_settings
.party_mode
)
1027 last_right
= current_tick
;
1028 #ifdef AB_REPEAT_ENABLE
1029 /* if we're in A/B repeat mode and the current position is
1030 before the A marker, jump to the A marker... */
1031 if ( ab_repeat_mode_enabled() )
1033 if ( ab_before_A_marker(wps_state
.id3
->elapsed
) )
1035 ab_jump_to_A_marker();
1037 #if (AB_REPEAT_ENABLE == 2)
1044 /* ...otherwise, do it normally */
1048 /* next / prev directories */
1049 /* and set A-B markers if in a-b mode */
1050 case ACTION_WPS_ABSETB_NEXTDIR
:
1051 if (global_settings
.party_mode
)
1053 #if defined(AB_REPEAT_ENABLE)
1054 if (ab_repeat_mode_enabled())
1056 ab_set_B_marker(wps_state
.id3
->elapsed
);
1057 ab_jump_to_A_marker();
1065 case ACTION_WPS_ABSETA_PREVDIR
:
1066 if (global_settings
.party_mode
)
1068 #if defined(AB_REPEAT_ENABLE)
1069 if (ab_repeat_mode_enabled())
1070 ab_set_A_marker(wps_state
.id3
->elapsed
);
1077 /* menu key functions */
1078 case ACTION_WPS_MENU
:
1084 #ifdef HAVE_QUICKSCREEN
1085 case ACTION_WPS_QUICKSCREEN
:
1088 if (quick_screen_quick(button
))
1093 #endif /* HAVE_QUICKSCREEN */
1095 /* screen settings */
1100 if (quick_screen_f3(BUTTON_F3
))
1105 #endif /* BUTTON_F3 */
1108 #ifdef HAVE_PITCHSCREEN
1109 case ACTION_WPS_PITCHSCREEN
:
1112 if (1 == gui_syncpitchscreen_run())
1117 #endif /* HAVE_PITCHSCREEN */
1119 #ifdef AB_REPEAT_ENABLE
1120 /* reset A&B markers */
1121 case ACTION_WPS_ABRESET
:
1122 if (ab_repeat_mode_enabled())
1128 #endif /* AB_REPEAT_ENABLE */
1130 /* stop and exit wps */
1131 case ACTION_WPS_STOP
:
1132 if (global_settings
.party_mode
)
1138 case ACTION_WPS_ID3SCREEN
:
1146 #ifdef HAVE_TOUCHSCREEN
1147 case ACTION_TOUCH_SHUFFLE
: /* toggle shuffle mode */
1149 global_settings
.playlist_shuffle
=
1150 !global_settings
.playlist_shuffle
;
1151 #if CONFIG_CODEC == SWCODEC
1152 dsp_set_replaygain();
1154 if (global_settings
.playlist_shuffle
)
1155 playlist_randomise(NULL
, current_tick
, true);
1157 playlist_sort(NULL
, true);
1160 case ACTION_TOUCH_REPMODE
: /* cycle the repeat mode setting */
1162 const struct settings_list
*rep_setting
=
1163 find_setting(&global_settings
.repeat_mode
, NULL
);
1164 option_select_next_val(rep_setting
, false, true);
1165 audio_flush_and_reload_tracks();
1168 #endif /* HAVE_TOUCHSCREEN */
1169 /* this case is used by the softlock feature
1170 * it requests a full update here */
1172 wps_sync_data
.do_full_update
= true;
1174 case ACTION_NONE
: /* Timeout, do a partial update */
1176 ffwd_rew(button
); /* hopefully fix the ffw/rwd bug */
1178 #ifdef HAVE_RECORDING
1179 case ACTION_WPS_REC
:
1184 default_event_handler(SYS_POWEROFF
);
1186 case ACTION_WPS_VIEW_PLAYLIST
:
1188 return GO_TO_PLAYLIST_VIEWER
;
1191 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1203 vol_changed
= false;
1207 if(update_onvol_change(&gui_wps
[i
]))
1212 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
1218 ((restoretimer
== RESTORE_WPS_INSTANTLY
) ||
1219 TIME_AFTER(current_tick
, restoretimer
)))
1222 restoretimer
= RESTORE_WPS_INSTANTLY
;
1223 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1224 add_event(LCD_EVENT_ACTIVATION
, false, wps_lcd_activation_hook
);
1226 /* we remove the update delay since it's not very usable in the wps,
1227 * e.g. during volume changing or ffwd/rewind */
1228 sb_skin_set_update_delay(0);
1229 wps_sync_data
.do_full_update
= update
= false;
1232 else if (wps_sync_data
.do_full_update
|| update
)
1234 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
1235 gwps_caption_backlight(&wps_state
);
1239 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1240 /* currently, all remotes are readable without backlight
1241 * so still update those */
1242 if (lcd_active() || (i
!= SCREEN_MAIN
))
1245 skin_update(&gui_wps
[i
], wps_sync_data
.do_full_update
?
1246 WPS_REFRESH_ALL
: WPS_REFRESH_NON_STATIC
);
1249 wps_sync_data
.do_full_update
= false;
1254 #ifdef HAVE_LCD_CHARCELLS
1255 status_set_record(false);
1256 status_set_audio(false);
1258 if (global_settings
.fade_on_stop
)
1262 bookmark_autobookmark(true);
1264 #ifdef AB_REPEAT_ENABLE
1268 #ifdef HAVE_RECORDING
1269 if (button
== ACTION_WPS_REC
)
1270 return GO_TO_RECSCREEN
;
1272 if (global_settings
.browse_current
)
1273 return GO_TO_PREVIOUS_BROWSER
;
1274 return GO_TO_PREVIOUS
;
1277 if (button
&& !IS_SYSEVENT(button
) )
1280 return GO_TO_ROOT
; /* unreachable - just to reduce compiler warnings */
1283 /* this is called from the playback thread so NO DRAWING! */
1284 static void track_changed_callback(void *param
)
1286 wps_state
.id3
= (struct mp3entry
*)param
;
1287 wps_state
.nid3
= audio_next_track();
1288 if (wps_state
.id3
->cuesheet
)
1290 cue_find_current_track(wps_state
.id3
->cuesheet
, wps_state
.id3
->elapsed
);
1291 cue_spoof_id3(wps_state
.id3
->cuesheet
, wps_state
.id3
);
1293 wps_sync_data
.do_full_update
= true;
1295 static void nextid3available_callback(void* param
)
1298 wps_state
.nid3
= audio_next_track();
1299 wps_sync_data
.do_full_update
= true;
1303 static void wps_state_init(void)
1305 wps_state
.ff_rewind
= false;
1306 wps_state
.paused
= false;
1307 if(audio_status() & AUDIO_STATUS_PLAY
)
1309 wps_state
.id3
= audio_current_track();
1310 wps_state
.nid3
= audio_next_track();
1314 wps_state
.id3
= NULL
;
1315 wps_state
.nid3
= NULL
;
1317 /* We'll be updating due to restore initialized with true */
1318 wps_sync_data
.do_full_update
= false;
1319 /* add the WPS track event callbacks */
1320 add_event(PLAYBACK_EVENT_TRACK_CHANGE
, false, track_changed_callback
);
1321 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, false, nextid3available_callback
);
1325 void gui_sync_wps_init(void)
1330 #ifdef HAVE_ALBUMART
1331 wps_datas
[i
].albumart
= NULL
;
1332 wps_datas
[i
].playback_aa_slot
= -1;
1334 gui_wps
[i
].data
= &wps_datas
[i
];
1335 gui_wps
[i
].display
= &screens
[i
];
1336 /* Currently no seperate wps_state needed/possible
1337 so use the only available ( "global" ) one */
1338 gui_wps
[i
].state
= &wps_state
;
1339 /* must point to the same struct for both screens */
1340 gui_wps
[i
].sync_data
= &wps_sync_data
;
1345 #ifdef IPOD_ACCESSORY_PROTOCOL
1346 bool is_wps_fading(void)
1348 return wps_state
.is_fading
;
1351 int wps_get_ff_rewind_count(void)
1353 return wps_state
.ff_rewind_count
;