1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Jerome Kuptz
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
30 #include "backlight.h"
33 #include "filetypes.h"
36 #include "skin_engine/skin_engine.h"
37 #include "mp3_playback.h"
44 #ifdef HAVE_LCD_BITMAP
46 #include "peakmeter.h"
57 #include "ata_idle_notify.h"
58 #include "root_menu.h"
60 #include "quickscreen.h"
61 #include "pitchscreen.h"
62 #include "appevents.h"
65 #include "option_select.h"
67 #include "playlist_viewer.h"
69 #include "statusbar-skinned.h"
71 #define RESTORE_WPS_INSTANTLY 0l
72 #define RESTORE_WPS_NEXT_SECOND ((long)(HZ+current_tick))
74 #define DEFAULT_SKIP_TRESH 3000l
77 #define FF_REWIND_MAX_PERCENT 3 /* cap ff/rewind step size at max % of file */
78 /* 3% of 30min file == 54s step size */
79 #define MIN_FF_REWIND_STEP 500
81 /* currently only one wps_state is needed, initialize to 0 */
82 struct wps_state wps_state
= { .id3
= NULL
};
83 static struct gui_wps gui_wps
[NB_SCREENS
] = {{ .data
= NULL
}};
84 static struct wps_data wps_datas
[NB_SCREENS
] = {{ .wps_loaded
= 0 }};
85 static struct wps_sync_data wps_sync_data
= { .do_full_update
= false };
87 /* initial setup of wps_data */
88 static void wps_state_init(void);
89 static void track_changed_callback(void *param
);
90 static void nextid3available_callback(void* param
);
91 #ifdef HAVE_LCD_BITMAP
92 static void statusbar_toggle_handler(void *data
);
95 #define WPS_DEFAULTCFG WPS_DIR "/rockbox_default.wps"
96 #ifdef HAVE_REMOTE_LCD
97 #define RWPS_DEFAULTCFG WPS_DIR "/rockbox_default.rwps"
98 #define DEFAULT_WPS(screen) ((screen) == SCREEN_MAIN ? \
99 WPS_DEFAULTCFG:RWPS_DEFAULTCFG)
101 #define DEFAULT_WPS(screen) (WPS_DEFAULTCFG)
104 void wps_data_load(enum screen_type screen
, const char *buf
, bool isfile
)
108 screens
[screen
].backdrop_unload(BACKDROP_SKIN_WPS
);
112 * Hardcode loading WPS_DEFAULTCFG to cause a reset ideally this
113 * wants to be a virtual file. Feel free to modify dirbrowse()
114 * if you're feeling brave.
117 if (buf
&& ! strcmp(buf
, DEFAULT_WPS(screen
)) )
119 #ifdef HAVE_REMOTE_LCD
120 if (screen
== SCREEN_REMOTE
)
121 global_settings
.rwps_file
[0] = '\0';
124 global_settings
.wps_file
[0] = '\0';
128 #endif /* __PCTOOL__ */
130 loaded_ok
= buf
&& skin_data_load(screen
, gui_wps
[screen
].data
, buf
, isfile
);
132 if (!loaded_ok
) /* load the hardcoded default */
134 char *skin_buf
[NB_SCREENS
] = {
135 #ifdef HAVE_LCD_BITMAP
136 "%s%?it<%?in<%in. |>%it|%fn>\n"
137 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
138 "%s%?id<%id|%?d1<%d1|(root)>> %?iy<(%iy)|>\n\n"
139 "%al%pc/%pt%ar[%pp:%pe]\n"
140 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
143 "%s%pp/%pe: %?it<%it|%fn> - %?ia<%ia|%d2> - %?id<%id|%d1>\n"
146 #ifdef HAVE_REMOTE_LCD
147 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
148 "%s%?it<%?in<%in. |>%it|%fn>\n"
149 "%al%pc/%pt%ar[%pp:%pe]\n"
150 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
154 skin_data_load(screen
, gui_wps
[screen
].data
, skin_buf
[screen
], false);
158 void fade(bool fade_in
, bool updatewps
)
160 int fp_global_vol
= global_settings
.volume
<< 8;
161 int fp_min_vol
= sound_min(SOUND_VOLUME
) << 8;
162 int fp_step
= (fp_global_vol
- fp_min_vol
) / 30;
164 wps_state
.is_fading
= !fade_in
;
167 int fp_volume
= fp_min_vol
;
169 /* zero out the sound */
170 sound_set_volume(fp_min_vol
>> 8);
172 sleep(HZ
/10); /* let audio thread run */
175 while (fp_volume
< fp_global_vol
- fp_step
) {
176 fp_volume
+= fp_step
;
177 sound_set_volume(fp_volume
>> 8);
181 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
185 sound_set_volume(global_settings
.volume
);
189 int fp_volume
= fp_global_vol
;
191 while (fp_volume
> fp_min_vol
+ fp_step
) {
192 fp_volume
-= fp_step
;
193 sound_set_volume(fp_volume
>> 8);
197 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
202 wps_state
.is_fading
= false;
203 #if CONFIG_CODEC != SWCODEC
205 /* let audio thread run and wait for the mas to run out of data */
206 while (!mp3_pause_done())
211 /* reset volume to what it was before the fade */
212 sound_set_volume(global_settings
.volume
);
216 static bool update_onvol_change(struct gui_wps
* gwps
)
218 skin_update(gwps
, WPS_REFRESH_NON_STATIC
);
220 #ifdef HAVE_LCD_CHARCELLS
221 splashf(0, "Vol: %3d dB",
222 sound_val2phys(SOUND_VOLUME
, global_settings
.volume
));
229 bool ffwd_rew(int button
)
231 unsigned int step
= 0; /* current ff/rewind step */
232 unsigned int max_step
= 0; /* maximum ff/rewind step */
233 int ff_rewind_count
= 0; /* current ff/rewind count (in ticks) */
234 int direction
= -1; /* forward=1 or backward=-1 */
238 const long ff_rw_accel
= (global_settings
.ff_rewind_accel
+ 3);
240 if (button
== ACTION_NONE
)
242 status_set_ffmode(0);
249 case ACTION_WPS_SEEKFWD
:
251 case ACTION_WPS_SEEKBACK
:
252 if (wps_state
.ff_rewind
)
256 /* fast forwarding, calc max step relative to end */
257 max_step
= (wps_state
.id3
->length
-
258 (wps_state
.id3
->elapsed
+
260 FF_REWIND_MAX_PERCENT
/ 100;
264 /* rewinding, calc max step relative to start */
265 max_step
= (wps_state
.id3
->elapsed
+ ff_rewind_count
) *
266 FF_REWIND_MAX_PERCENT
/ 100;
269 max_step
= MAX(max_step
, MIN_FF_REWIND_STEP
);
274 ff_rewind_count
+= step
* direction
;
276 /* smooth seeking by multiplying step by: 1 + (2 ^ -accel) */
277 step
+= step
>> ff_rw_accel
;
281 if ( (audio_status() & AUDIO_STATUS_PLAY
) &&
282 wps_state
.id3
&& wps_state
.id3
->length
)
284 if (!wps_state
.paused
)
285 #if (CONFIG_CODEC == SWCODEC)
286 audio_pre_ff_rewind();
290 #if CONFIG_KEYPAD == PLAYER_PAD
292 gui_wps
[i
].display
->stop_scroll();
295 status_set_ffmode(STATUS_FASTFORWARD
);
297 status_set_ffmode(STATUS_FASTBACKWARD
);
299 wps_state
.ff_rewind
= true;
301 step
= 1000 * global_settings
.ff_rewind_min_step
;
308 if ((wps_state
.id3
->elapsed
+ ff_rewind_count
) >
309 wps_state
.id3
->length
)
310 ff_rewind_count
= wps_state
.id3
->length
-
311 wps_state
.id3
->elapsed
;
314 if ((int)(wps_state
.id3
->elapsed
+ ff_rewind_count
) < 0)
315 ff_rewind_count
= -wps_state
.id3
->elapsed
;
318 /* set the wps state ff_rewind_count so the progess info
320 wps_state
.ff_rewind_count
= (wps_state
.wps_time_countup
== false)?
321 ff_rewind_count
:-ff_rewind_count
;
324 skin_update(&gui_wps
[i
],
325 WPS_REFRESH_PLAYER_PROGRESS
|
326 WPS_REFRESH_DYNAMIC
);
331 case ACTION_WPS_STOPSEEK
:
332 wps_state
.id3
->elapsed
= wps_state
.id3
->elapsed
+ff_rewind_count
;
333 audio_ff_rewind(wps_state
.id3
->elapsed
);
334 wps_state
.ff_rewind_count
= 0;
335 wps_state
.ff_rewind
= false;
336 status_set_ffmode(0);
337 #if (CONFIG_CODEC != SWCODEC)
338 if (!wps_state
.paused
)
341 #ifdef HAVE_LCD_CHARCELLS
343 skin_update(&gui_wps
[i
], WPS_REFRESH_ALL
);
349 if(default_event_handler(button
) == SYS_USB_CONNECTED
) {
350 status_set_ffmode(0);
358 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_BLOCK
);
359 #ifdef HAVE_TOUCHSCREEN
360 if (button
== ACTION_TOUCHSCREEN
)
361 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
369 void display_keylock_text(bool locked
)
373 gui_wps
[i
].display
->stop_scroll();
375 splash(HZ
, locked
? ID2P(LANG_KEYLOCK_ON
) : ID2P(LANG_KEYLOCK_OFF
));
381 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
382 static void gwps_caption_backlight(struct wps_state
*state
)
384 if (state
&& state
->id3
)
386 #ifdef HAVE_BACKLIGHT
387 if (global_settings
.caption_backlight
)
389 /* turn on backlight n seconds before track ends, and turn it off n
390 seconds into the new track. n == backlight_timeout, or 5s */
391 int n
= global_settings
.backlight_timeout
* 1000;
394 n
= 5000; /* use 5s if backlight is always on or off */
396 if (((state
->id3
->elapsed
< 1000) ||
397 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
398 (state
->paused
== false))
402 #ifdef HAVE_REMOTE_LCD
403 if (global_settings
.remote_caption_backlight
)
405 /* turn on remote backlight n seconds before track ends, and turn it
406 off n seconds into the new track. n == remote_backlight_timeout,
408 int n
= global_settings
.remote_backlight_timeout
* 1000;
411 n
= 5000; /* use 5s if backlight is always on or off */
413 if (((state
->id3
->elapsed
< 1000) ||
414 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
415 (state
->paused
== false))
416 remote_backlight_on();
424 static void change_dir(int direction
)
426 if (global_settings
.prevent_skip
)
431 else if (direction
> 0)
433 /* prevent the next dir to immediatly start being ffw'd */
434 action_wait_for_release();
437 static void prev_track(unsigned long skip_thresh
)
439 if (wps_state
.id3
->elapsed
< skip_thresh
)
446 if (wps_state
.id3
->cuesheet
)
448 curr_cuesheet_skip(wps_state
.id3
->cuesheet
, -1, wps_state
.id3
->elapsed
);
452 if (!wps_state
.paused
)
453 #if (CONFIG_CODEC == SWCODEC)
454 audio_pre_ff_rewind();
461 #if (CONFIG_CODEC != SWCODEC)
462 if (!wps_state
.paused
)
468 static void next_track(void)
470 /* take care of if we're playing a cuesheet */
471 if (wps_state
.id3
->cuesheet
)
473 if (curr_cuesheet_skip(wps_state
.id3
->cuesheet
, 1, wps_state
.id3
->elapsed
))
475 /* if the result was false, then we really want
476 to skip to the next track */
484 static void play_hop(int direction
)
486 long step
= global_settings
.skip_length
*1000;
487 long elapsed
= wps_state
.id3
->elapsed
;
488 long remaining
= wps_state
.id3
->length
- elapsed
;
494 prev_track(DEFAULT_SKIP_TRESH
);
497 else if (remaining
< DEFAULT_SKIP_TRESH
*2)
503 elapsed
+= (remaining
- DEFAULT_SKIP_TRESH
*2);
505 else if (!global_settings
.prevent_skip
&&
507 (direction
> 0 && step
>= remaining
) ||
508 (direction
< 0 && elapsed
< DEFAULT_SKIP_TRESH
)))
509 { /* Do normal track skipping */
512 else if (direction
< 0)
513 prev_track(DEFAULT_SKIP_TRESH
);
516 else if (direction
== 1 && step
>= remaining
)
518 #if CONFIG_CODEC == SWCODEC
519 if(global_settings
.beep
)
520 pcmbuf_beep(1000, 150, 1500*global_settings
.beep
);
524 else if ((direction
== -1 && elapsed
< step
))
530 elapsed
+= step
* direction
;
532 if((audio_status() & AUDIO_STATUS_PLAY
) && !wps_state
.paused
)
534 #if (CONFIG_CODEC == SWCODEC)
535 audio_pre_ff_rewind();
540 audio_ff_rewind(wps_state
.id3
->elapsed
= elapsed
);
541 #if (CONFIG_CODEC != SWCODEC)
542 if (!wps_state
.paused
)
548 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
550 * If the user is unable to see the wps, because the display is deactivated,
551 * we suppress updates until the wps is activated again (the lcd driver will
552 * call this hook to issue an instant update)
554 static void wps_lcd_activation_hook(void *param
)
557 wps_sync_data
.do_full_update
= true;
558 /* force timeout in wps main loop, so that the update is instantly */
559 queue_post(&button_queue
, BUTTON_NONE
, 0);
563 static void gwps_leave_wps(void)
565 int i
, oldbars
= VP_SB_HIDE_ALL
;
569 gui_wps
[i
].display
->stop_scroll();
570 gui_wps
[i
].display
->backdrop_show(BACKDROP_MAIN
);
571 if (statusbar_position(i
) != STATUSBAR_OFF
)
572 oldbars
|= VP_SB_ONSCREEN(i
);
575 viewportmanager_set_statusbar(oldbars
);
576 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
577 /* Play safe and unregister the hook */
578 remove_event(LCD_EVENT_ACTIVATION
, wps_lcd_activation_hook
);
580 /* unhandle statusbar update delay */
581 sb_skin_set_update_delay(DEFAULT_UPDATE_DELAY
);
582 send_event(GUI_EVENT_REFRESH
, NULL
);
586 * display the wps on entering or restoring */
587 static void gwps_enter_wps(void)
592 struct gui_wps
*gwps
= &gui_wps
[i
];
593 struct screen
*display
= gwps
->display
;
595 display
->stop_scroll();
596 /* Update the values in the first (default) viewport - in case the user
597 has modified the statusbar or colour settings */
599 if (display
->depth
> 1)
601 struct viewport
*vp
= &find_viewport(VP_DEFAULT_LABEL
, gwps
->data
)->vp
;
602 vp
->fg_pattern
= display
->get_foreground();
603 vp
->bg_pattern
= display
->get_background();
606 skin_update(gwps
, WPS_REFRESH_ALL
);
610 #ifdef HAVE_TOUCHSCREEN
611 int wps_get_touchaction(struct wps_data
*data
)
615 int type
= action_get_touchscreen_press(&x
, &y
);
616 static int last_action
= ACTION_NONE
;
617 struct touchregion
*r
;
618 bool repeated
= (type
== BUTTON_REPEAT
);
619 bool released
= (type
== BUTTON_REL
);
620 struct skin_token_list
*regions
= data
->touchregions
;
623 r
= (struct touchregion
*)regions
->token
->value
.data
;
624 /* make sure this region's viewport is visible */
625 if (r
->wvp
->hidden_flags
&VP_DRAW_HIDDEN
)
627 regions
= regions
->next
;
630 /* check if it's inside this viewport */
631 if (viewport_point_within_vp(&(r
->wvp
->vp
), x
, y
))
632 { /* reposition the touch inside the viewport since touchregions
633 * are relative to a preceding viewport */
634 vx
= x
- r
->wvp
->vp
.x
;
635 vy
= y
- r
->wvp
->vp
.y
;
636 /* now see if the point is inside this region */
637 if (vx
>= r
->x
&& vx
< r
->x
+r
->width
&&
638 vy
>= r
->y
&& vy
< r
->y
+r
->height
)
640 /* reposition the touch within the area */
646 case WPS_TOUCHREGION_ACTION
:
647 if ((repeated
&& r
->repeat
) || (released
&& !r
->repeat
))
649 last_action
= r
->action
;
653 case WPS_TOUCHREGION_SCROLLBAR
:
654 if(r
->width
> r
->height
)
656 wps_state
.id3
->elapsed
= (vx
*
657 wps_state
.id3
->length
) / r
->width
;
660 wps_state
.id3
->elapsed
= (vy
*
661 wps_state
.id3
->length
) / r
->height
;
663 if (!wps_state
.paused
)
664 #if (CONFIG_CODEC == SWCODEC)
665 audio_pre_ff_rewind();
669 audio_ff_rewind(wps_state
.id3
->elapsed
);
670 #if (CONFIG_CODEC != SWCODEC)
671 if (!wps_state
.paused
)
675 case WPS_TOUCHREGION_VOLUME
:
677 const int min_vol
= sound_min(SOUND_VOLUME
);
678 const int max_vol
= sound_max(SOUND_VOLUME
);
679 if(r
->width
> r
->height
)
681 global_settings
.volume
= (vx
*
682 (max_vol
- min_vol
)) / r
->width
;
685 global_settings
.volume
= (vy
*
686 (max_vol
-min_vol
)) / r
->height
;
688 global_settings
.volume
+= min_vol
;
690 return ACTION_REDRAW
;
695 regions
= regions
->next
;
698 if ((last_action
== ACTION_WPS_SEEKBACK
|| last_action
== ACTION_WPS_SEEKFWD
))
699 return ACTION_WPS_STOPSEEK
;
700 last_action
= ACTION_TOUCHSCREEN
;
701 return ACTION_TOUCHSCREEN
;
704 /* The WPS can be left in two ways:
705 * a) call a function, which draws over the wps. In this case, the wps
706 * will be still active (i.e. the below function didn't return)
707 * b) return with a value evaluated by root_menu.c, in this case the wps
708 * is really left, and root_menu will handle the next screen
710 * In either way, call gwps_leave_wps(), in order to restore the correct
711 * "main screen" backdrops and statusbars
713 long gui_wps_show(void)
717 long restoretimer
= RESTORE_WPS_INSTANTLY
; /* timer to delay screen redraw temporarily */
719 bool bookmark
= false;
721 bool vol_changed
= false;
723 long last_left
= 0, last_right
= 0;
725 #ifdef HAVE_LCD_CHARCELLS
726 status_set_audio(true);
727 status_set_param(false);
729 statusbar_toggle_handler(NULL
);
732 #ifdef AB_REPEAT_ENABLE
740 bool audio_paused
= (audio_status() & AUDIO_STATUS_PAUSE
)?true:false;
742 /* did someone else (i.e power thread) change audio pause mode? */
743 if (wps_state
.paused
!= audio_paused
) {
744 wps_state
.paused
= audio_paused
;
746 /* if another thread paused audio, we are probably in car mode,
747 about to shut down. lets save the settings. */
748 if (wps_state
.paused
) {
750 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
751 call_storage_idle_notifys(true);
755 #ifdef HAVE_LCD_BITMAP
756 /* when the peak meter is enabled we want to have a
757 few extra updates to make it look smooth. On the
758 other hand we don't want to waste energy if it
763 if(gui_wps
[i
].data
->peak_meter_enabled
)
768 long next_refresh
= current_tick
;
769 long next_big_refresh
= current_tick
+ HZ
/ 5;
770 button
= BUTTON_NONE
;
771 while (TIME_BEFORE(current_tick
, next_big_refresh
)) {
772 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_NOBLOCK
);
773 /* check for restore to not let the peakmeter delay the
774 * initial draw of the wps, don't delay handling of button
776 if (button
!= ACTION_NONE
|| restore
) {
780 sleep(0); /* Sleep until end of current tick. */
782 if (TIME_AFTER(current_tick
, next_refresh
)) {
785 if(gui_wps
[i
].data
->peak_meter_enabled
)
786 skin_update(&gui_wps
[i
], WPS_REFRESH_PEAK_METER
);
787 next_refresh
+= HZ
/ PEAK_METER_FPS
;
794 /* The peak meter is disabled
795 -> no additional screen updates needed */
798 { /* 1 is the minimum timeout which lets other threads run.
799 * audio thread (apprently) needs to run before displaying the wps
800 * or bad things happen with regards to cuesheet
801 * (probably a race condition, on sh at least) */
802 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,
806 /* Exit if audio has stopped playing. This happens e.g. at end of
807 playlist or if using the sleep timer. */
808 if (!(audio_status() & AUDIO_STATUS_PLAY
))
810 #ifdef HAVE_TOUCHSCREEN
811 if (button
== ACTION_TOUCHSCREEN
)
812 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
814 /* The iPods/X5/M5 use a single button for the A-B mode markers,
815 defined as ACTION_WPSAB_SINGLE in their config files. */
816 #ifdef ACTION_WPSAB_SINGLE
817 if (!global_settings
.party_mode
&& ab_repeat_mode_enabled())
819 static int wps_ab_state
= 0;
820 if (button
== ACTION_WPSAB_SINGLE
)
822 switch (wps_ab_state
)
824 case 0: /* set the A spot */
825 button
= ACTION_WPS_ABSETA_PREVDIR
;
827 case 1: /* set the B spot */
828 button
= ACTION_WPS_ABSETB_NEXTDIR
;
831 button
= ACTION_WPS_ABRESET
;
834 wps_ab_state
= (wps_ab_state
+1) % 3;
840 case ACTION_WPS_CONTEXT
:
843 /* if music is stopped in the context menu we want to exit the wps */
844 if (onplay(wps_state
.id3
->path
,
845 FILE_ATTR_AUDIO
, CONTEXT_WPS
) == ONPLAY_MAINMENU
852 case ACTION_WPS_BROWSE
:
853 #ifdef HAVE_LCD_CHARCELLS
854 status_set_record(false);
855 status_set_audio(false);
858 return GO_TO_PREVIOUS_BROWSER
;
862 case ACTION_WPS_PLAY
:
863 if (global_settings
.party_mode
)
865 if ( wps_state
.paused
)
867 wps_state
.paused
= false;
868 if ( global_settings
.fade_on_stop
)
875 wps_state
.paused
= true;
876 if ( global_settings
.fade_on_stop
)
881 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
882 call_storage_idle_notifys(true); /* make sure resume info is saved */
887 case ACTION_WPS_VOLUP
:
888 global_settings
.volume
++;
891 case ACTION_WPS_VOLDOWN
:
892 global_settings
.volume
--;
896 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
897 case ACTION_WPS_SEEKFWD
:
898 if (global_settings
.party_mode
)
900 if (current_tick
-last_right
< HZ
)
902 if (wps_state
.id3
->cuesheet
)
912 ffwd_rew(ACTION_WPS_SEEKFWD
);
913 last_right
= last_left
= 0;
916 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
917 case ACTION_WPS_SEEKBACK
:
918 if (global_settings
.party_mode
)
920 if (current_tick
-last_left
< HZ
)
922 if (wps_state
.id3
->cuesheet
)
924 if (!wps_state
.paused
)
925 #if (CONFIG_CODEC == SWCODEC)
926 audio_pre_ff_rewind();
938 ffwd_rew(ACTION_WPS_SEEKBACK
);
939 last_left
= last_right
= 0;
943 case ACTION_WPS_SKIPPREV
:
944 if (global_settings
.party_mode
)
946 last_left
= current_tick
;
947 #ifdef AB_REPEAT_ENABLE
948 /* if we're in A/B repeat mode and the current position
949 is past the A marker, jump back to the A marker... */
950 if ( ab_repeat_mode_enabled() )
952 if ( ab_after_A_marker(wps_state
.id3
->elapsed
) )
954 ab_jump_to_A_marker();
956 #if (AB_REPEAT_ENABLE == 2)
963 /* ...otherwise, do it normally */
969 OR if skip length set, hop by predetermined amount. */
970 case ACTION_WPS_SKIPNEXT
:
971 if (global_settings
.party_mode
)
973 last_right
= current_tick
;
974 #ifdef AB_REPEAT_ENABLE
975 /* if we're in A/B repeat mode and the current position is
976 before the A marker, jump to the A marker... */
977 if ( ab_repeat_mode_enabled() )
979 if ( ab_before_A_marker(wps_state
.id3
->elapsed
) )
981 ab_jump_to_A_marker();
983 #if (AB_REPEAT_ENABLE == 2)
990 /* ...otherwise, do it normally */
994 /* next / prev directories */
995 /* and set A-B markers if in a-b mode */
996 case ACTION_WPS_ABSETB_NEXTDIR
:
997 if (global_settings
.party_mode
)
999 #if defined(AB_REPEAT_ENABLE)
1000 if (ab_repeat_mode_enabled())
1002 ab_set_B_marker(wps_state
.id3
->elapsed
);
1003 ab_jump_to_A_marker();
1011 case ACTION_WPS_ABSETA_PREVDIR
:
1012 if (global_settings
.party_mode
)
1014 #if defined(AB_REPEAT_ENABLE)
1015 if (ab_repeat_mode_enabled())
1016 ab_set_A_marker(wps_state
.id3
->elapsed
);
1023 /* menu key functions */
1024 case ACTION_WPS_MENU
:
1030 #ifdef HAVE_QUICKSCREEN
1031 case ACTION_WPS_QUICKSCREEN
:
1034 if (quick_screen_quick(button
))
1039 #endif /* HAVE_QUICKSCREEN */
1041 /* screen settings */
1046 if (quick_screen_f3(BUTTON_F3
))
1051 #endif /* BUTTON_F3 */
1054 #ifdef HAVE_PITCHSCREEN
1055 case ACTION_WPS_PITCHSCREEN
:
1058 if (1 == gui_syncpitchscreen_run())
1063 #endif /* HAVE_PITCHSCREEN */
1065 #ifdef AB_REPEAT_ENABLE
1066 /* reset A&B markers */
1067 case ACTION_WPS_ABRESET
:
1068 if (ab_repeat_mode_enabled())
1074 #endif /* AB_REPEAT_ENABLE */
1076 /* stop and exit wps */
1077 case ACTION_WPS_STOP
:
1078 if (global_settings
.party_mode
)
1084 case ACTION_WPS_ID3SCREEN
:
1092 #ifdef HAVE_TOUCHSCREEN
1093 case ACTION_TOUCH_SHUFFLE
: /* toggle shuffle mode */
1095 global_settings
.playlist_shuffle
=
1096 !global_settings
.playlist_shuffle
;
1097 #if CONFIG_CODEC == SWCODEC
1098 dsp_set_replaygain();
1100 if (global_settings
.playlist_shuffle
)
1101 playlist_randomise(NULL
, current_tick
, true);
1103 playlist_sort(NULL
, true);
1106 case ACTION_TOUCH_REPMODE
: /* cycle the repeat mode setting */
1108 const struct settings_list
*rep_setting
=
1109 find_setting(&global_settings
.repeat_mode
, NULL
);
1110 option_select_next_val(rep_setting
, false, true);
1111 audio_flush_and_reload_tracks();
1114 #endif /* HAVE_TOUCHSCREEN */
1115 /* this case is used by the softlock feature
1116 * it requests a full update here */
1118 wps_sync_data
.do_full_update
= true;
1120 case ACTION_NONE
: /* Timeout, do a partial update */
1122 ffwd_rew(button
); /* hopefully fix the ffw/rwd bug */
1124 #ifdef HAVE_RECORDING
1125 case ACTION_WPS_REC
:
1130 default_event_handler(SYS_POWEROFF
);
1132 case ACTION_WPS_VIEW_PLAYLIST
:
1134 if (playlist_viewer()) /* true if USB connected */
1139 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1151 vol_changed
= false;
1155 if(update_onvol_change(&gui_wps
[i
]))
1160 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
1166 ((restoretimer
== RESTORE_WPS_INSTANTLY
) ||
1167 TIME_AFTER(current_tick
, restoretimer
)))
1170 restoretimer
= RESTORE_WPS_INSTANTLY
;
1171 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1172 add_event(LCD_EVENT_ACTIVATION
, false, wps_lcd_activation_hook
);
1174 /* we remove the update delay since it's not very usable in the wps,
1175 * e.g. during volume changing or ffwd/rewind */
1176 sb_skin_set_update_delay(0);
1178 gui_wps
[i
].display
->backdrop_show(BACKDROP_SKIN_WPS
);
1179 send_event(GUI_EVENT_REFRESH
, gwps_enter_wps
);
1180 wps_sync_data
.do_full_update
= update
= false;
1182 else if (wps_sync_data
.do_full_update
|| update
)
1184 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
1185 gwps_caption_backlight(&wps_state
);
1189 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1190 /* currently, all remotes are readable without backlight
1191 * so still update those */
1192 if (lcd_active() || (i
!= SCREEN_MAIN
))
1195 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
1198 wps_sync_data
.do_full_update
= false;
1203 #ifdef HAVE_LCD_CHARCELLS
1204 status_set_record(false);
1205 status_set_audio(false);
1207 if (global_settings
.fade_on_stop
)
1211 bookmark_autobookmark();
1213 #ifdef AB_REPEAT_ENABLE
1217 #ifdef HAVE_RECORDING
1218 if (button
== ACTION_WPS_REC
)
1219 return GO_TO_RECSCREEN
;
1221 if (global_settings
.browse_current
)
1222 return GO_TO_PREVIOUS_BROWSER
;
1223 return GO_TO_PREVIOUS
;
1226 if (button
&& !IS_SYSEVENT(button
) )
1229 return GO_TO_ROOT
; /* unreachable - just to reduce compiler warnings */
1232 /* this is called from the playback thread so NO DRAWING! */
1233 static void track_changed_callback(void *param
)
1235 wps_state
.id3
= (struct mp3entry
*)param
;
1236 wps_state
.nid3
= audio_next_track();
1237 if (wps_state
.id3
->cuesheet
)
1239 cue_find_current_track(wps_state
.id3
->cuesheet
, wps_state
.id3
->elapsed
);
1240 cue_spoof_id3(wps_state
.id3
->cuesheet
, wps_state
.id3
);
1242 wps_sync_data
.do_full_update
= true;
1244 static void nextid3available_callback(void* param
)
1247 wps_state
.nid3
= audio_next_track();
1248 wps_sync_data
.do_full_update
= true;
1252 static void wps_state_init(void)
1254 wps_state
.ff_rewind
= false;
1255 wps_state
.paused
= false;
1256 if(audio_status() & AUDIO_STATUS_PLAY
)
1258 wps_state
.id3
= audio_current_track();
1259 wps_state
.nid3
= audio_next_track();
1263 wps_state
.id3
= NULL
;
1264 wps_state
.nid3
= NULL
;
1266 /* We'll be updating due to restore initialized with true */
1267 wps_sync_data
.do_full_update
= false;
1268 /* add the WPS track event callbacks */
1269 add_event(PLAYBACK_EVENT_TRACK_CHANGE
, false, track_changed_callback
);
1270 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, false, nextid3available_callback
);
1274 #ifdef HAVE_LCD_BITMAP
1275 static void statusbar_toggle_handler(void *data
)
1280 int *wpsbars
= &wps_sync_data
.statusbars
;
1281 *wpsbars
= VP_SB_HIDE_ALL
;
1283 { /* fix viewports if needed */
1284 skin_statusbar_changed(&gui_wps
[i
]);
1288 /* fix up gui_wps::statusbars, so that the viewportmanager accepts it*/
1289 if (gui_wps
[i
].data
->wps_sb_tag
)
1290 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
1291 else if (statusbar_position(i
) != STATUSBAR_OFF
)
1295 (VP_SB_ONSCREEN(i
) | VP_SB_IGNORE_SETTING(i
));
1301 void gui_sync_wps_init(void)
1306 #ifdef HAVE_ALBUMART
1307 wps_datas
[i
].albumart
= NULL
;
1308 wps_datas
[i
].playback_aa_slot
= -1;
1310 gui_wps
[i
].data
= &wps_datas
[i
];
1311 gui_wps
[i
].display
= &screens
[i
];
1312 /* Currently no seperate wps_state needed/possible
1313 so use the only available ( "global" ) one */
1314 gui_wps
[i
].state
= &wps_state
;
1315 gui_wps
[i
].display
->backdrop_unload(BACKDROP_SKIN_WPS
);
1316 /* must point to the same struct for both screens */
1317 gui_wps
[i
].sync_data
= &wps_sync_data
;
1318 gui_wps
[i
].sync_data
->statusbars
= VP_SB_ALLSCREENS
;
1320 #ifdef HAVE_LCD_BITMAP
1321 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false, statusbar_toggle_handler
);
1326 #ifdef IPOD_ACCESSORY_PROTOCOL
1327 bool is_wps_fading(void)
1329 return wps_state
.is_fading
;
1332 int wps_get_ff_rewind_count(void)
1334 return wps_state
.ff_rewind_count
;