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);
156 #ifdef HAVE_REMOVE_LCD
157 gui_wps
[screen
].data
->remote_wps
= !(screen
== SCREEN_MAIN
);
162 void fade(bool fade_in
, bool updatewps
)
164 int fp_global_vol
= global_settings
.volume
<< 8;
165 int fp_min_vol
= sound_min(SOUND_VOLUME
) << 8;
166 int fp_step
= (fp_global_vol
- fp_min_vol
) / 30;
168 wps_state
.is_fading
= !fade_in
;
171 int fp_volume
= fp_min_vol
;
173 /* zero out the sound */
174 sound_set_volume(fp_min_vol
>> 8);
176 sleep(HZ
/10); /* let audio thread run */
179 while (fp_volume
< fp_global_vol
- fp_step
) {
180 fp_volume
+= fp_step
;
181 sound_set_volume(fp_volume
>> 8);
185 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
189 sound_set_volume(global_settings
.volume
);
193 int fp_volume
= fp_global_vol
;
195 while (fp_volume
> fp_min_vol
+ fp_step
) {
196 fp_volume
-= fp_step
;
197 sound_set_volume(fp_volume
>> 8);
201 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
206 wps_state
.is_fading
= false;
207 #if CONFIG_CODEC != SWCODEC
209 /* let audio thread run and wait for the mas to run out of data */
210 while (!mp3_pause_done())
215 /* reset volume to what it was before the fade */
216 sound_set_volume(global_settings
.volume
);
220 static bool update_onvol_change(struct gui_wps
* gwps
)
222 skin_update(gwps
, WPS_REFRESH_NON_STATIC
);
224 #ifdef HAVE_LCD_CHARCELLS
225 splashf(0, "Vol: %3d dB",
226 sound_val2phys(SOUND_VOLUME
, global_settings
.volume
));
233 bool ffwd_rew(int button
)
235 unsigned int step
= 0; /* current ff/rewind step */
236 unsigned int max_step
= 0; /* maximum ff/rewind step */
237 int ff_rewind_count
= 0; /* current ff/rewind count (in ticks) */
238 int direction
= -1; /* forward=1 or backward=-1 */
242 const long ff_rw_accel
= (global_settings
.ff_rewind_accel
+ 3);
244 if (button
== ACTION_NONE
)
246 status_set_ffmode(0);
253 case ACTION_WPS_SEEKFWD
:
255 case ACTION_WPS_SEEKBACK
:
256 if (wps_state
.ff_rewind
)
260 /* fast forwarding, calc max step relative to end */
261 max_step
= (wps_state
.id3
->length
-
262 (wps_state
.id3
->elapsed
+
264 FF_REWIND_MAX_PERCENT
/ 100;
268 /* rewinding, calc max step relative to start */
269 max_step
= (wps_state
.id3
->elapsed
+ ff_rewind_count
) *
270 FF_REWIND_MAX_PERCENT
/ 100;
273 max_step
= MAX(max_step
, MIN_FF_REWIND_STEP
);
278 ff_rewind_count
+= step
* direction
;
280 /* smooth seeking by multiplying step by: 1 + (2 ^ -accel) */
281 step
+= step
>> ff_rw_accel
;
285 if ( (audio_status() & AUDIO_STATUS_PLAY
) &&
286 wps_state
.id3
&& wps_state
.id3
->length
)
288 if (!wps_state
.paused
)
289 #if (CONFIG_CODEC == SWCODEC)
290 audio_pre_ff_rewind();
294 #if CONFIG_KEYPAD == PLAYER_PAD
296 gui_wps
[i
].display
->stop_scroll();
299 status_set_ffmode(STATUS_FASTFORWARD
);
301 status_set_ffmode(STATUS_FASTBACKWARD
);
303 wps_state
.ff_rewind
= true;
305 step
= 1000 * global_settings
.ff_rewind_min_step
;
312 if ((wps_state
.id3
->elapsed
+ ff_rewind_count
) >
313 wps_state
.id3
->length
)
314 ff_rewind_count
= wps_state
.id3
->length
-
315 wps_state
.id3
->elapsed
;
318 if ((int)(wps_state
.id3
->elapsed
+ ff_rewind_count
) < 0)
319 ff_rewind_count
= -wps_state
.id3
->elapsed
;
322 /* set the wps state ff_rewind_count so the progess info
324 wps_state
.ff_rewind_count
= (wps_state
.wps_time_countup
== false)?
325 ff_rewind_count
:-ff_rewind_count
;
328 skin_update(&gui_wps
[i
],
329 WPS_REFRESH_PLAYER_PROGRESS
|
330 WPS_REFRESH_DYNAMIC
);
335 case ACTION_WPS_STOPSEEK
:
336 wps_state
.id3
->elapsed
= wps_state
.id3
->elapsed
+ff_rewind_count
;
337 audio_ff_rewind(wps_state
.id3
->elapsed
);
338 wps_state
.ff_rewind_count
= 0;
339 wps_state
.ff_rewind
= false;
340 status_set_ffmode(0);
341 #if (CONFIG_CODEC != SWCODEC)
342 if (!wps_state
.paused
)
345 #ifdef HAVE_LCD_CHARCELLS
347 skin_update(&gui_wps
[i
], WPS_REFRESH_ALL
);
353 if(default_event_handler(button
) == SYS_USB_CONNECTED
) {
354 status_set_ffmode(0);
362 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_BLOCK
);
363 #ifdef HAVE_TOUCHSCREEN
364 if (button
== ACTION_TOUCHSCREEN
)
365 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
373 void display_keylock_text(bool locked
)
377 gui_wps
[i
].display
->stop_scroll();
379 splash(HZ
, locked
? ID2P(LANG_KEYLOCK_ON
) : ID2P(LANG_KEYLOCK_OFF
));
385 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
386 static void gwps_caption_backlight(struct wps_state
*state
)
388 if (state
&& state
->id3
)
390 #ifdef HAVE_BACKLIGHT
391 if (global_settings
.caption_backlight
)
393 /* turn on backlight n seconds before track ends, and turn it off n
394 seconds into the new track. n == backlight_timeout, or 5s */
395 int n
= global_settings
.backlight_timeout
* 1000;
398 n
= 5000; /* use 5s if backlight is always on or off */
400 if (((state
->id3
->elapsed
< 1000) ||
401 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
402 (state
->paused
== false))
406 #ifdef HAVE_REMOTE_LCD
407 if (global_settings
.remote_caption_backlight
)
409 /* turn on remote backlight n seconds before track ends, and turn it
410 off n seconds into the new track. n == remote_backlight_timeout,
412 int n
= global_settings
.remote_backlight_timeout
* 1000;
415 n
= 5000; /* use 5s if backlight is always on or off */
417 if (((state
->id3
->elapsed
< 1000) ||
418 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
419 (state
->paused
== false))
420 remote_backlight_on();
428 static void change_dir(int direction
)
430 if (global_settings
.prevent_skip
)
435 else if (direction
> 0)
437 /* prevent the next dir to immediatly start being ffw'd */
438 action_wait_for_release();
441 static void prev_track(unsigned long skip_thresh
)
443 if (wps_state
.id3
->elapsed
< skip_thresh
)
450 if (wps_state
.id3
->cuesheet
)
452 curr_cuesheet_skip(wps_state
.id3
->cuesheet
, -1, wps_state
.id3
->elapsed
);
456 if (!wps_state
.paused
)
457 #if (CONFIG_CODEC == SWCODEC)
458 audio_pre_ff_rewind();
465 #if (CONFIG_CODEC != SWCODEC)
466 if (!wps_state
.paused
)
472 static void next_track(void)
474 /* take care of if we're playing a cuesheet */
475 if (wps_state
.id3
->cuesheet
)
477 if (curr_cuesheet_skip(wps_state
.id3
->cuesheet
, 1, wps_state
.id3
->elapsed
))
479 /* if the result was false, then we really want
480 to skip to the next track */
488 static void play_hop(int direction
)
490 long step
= global_settings
.skip_length
*1000;
491 long elapsed
= wps_state
.id3
->elapsed
;
492 long remaining
= wps_state
.id3
->length
- elapsed
;
498 prev_track(DEFAULT_SKIP_TRESH
);
501 else if (remaining
< DEFAULT_SKIP_TRESH
*2)
507 elapsed
+= (remaining
- DEFAULT_SKIP_TRESH
*2);
509 else if (!global_settings
.prevent_skip
&&
511 (direction
> 0 && step
>= remaining
) ||
512 (direction
< 0 && elapsed
< DEFAULT_SKIP_TRESH
)))
513 { /* Do normal track skipping */
516 else if (direction
< 0)
517 prev_track(DEFAULT_SKIP_TRESH
);
520 else if (direction
== 1 && step
>= remaining
)
522 #if CONFIG_CODEC == SWCODEC
523 if(global_settings
.beep
)
524 pcmbuf_beep(1000, 150, 1500*global_settings
.beep
);
528 else if ((direction
== -1 && elapsed
< step
))
534 elapsed
+= step
* direction
;
536 if((audio_status() & AUDIO_STATUS_PLAY
) && !wps_state
.paused
)
538 #if (CONFIG_CODEC == SWCODEC)
539 audio_pre_ff_rewind();
544 audio_ff_rewind(wps_state
.id3
->elapsed
= elapsed
);
545 #if (CONFIG_CODEC != SWCODEC)
546 if (!wps_state
.paused
)
552 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
554 * If the user is unable to see the wps, because the display is deactivated,
555 * we suppress updates until the wps is activated again (the lcd driver will
556 * call this hook to issue an instant update)
558 static void wps_lcd_activation_hook(void *param
)
561 wps_sync_data
.do_full_update
= true;
562 /* force timeout in wps main loop, so that the update is instantly */
563 queue_post(&button_queue
, BUTTON_NONE
, 0);
567 static void gwps_leave_wps(void)
569 int i
, oldbars
= VP_SB_HIDE_ALL
;
573 gui_wps
[i
].display
->stop_scroll();
574 gui_wps
[i
].display
->backdrop_show(BACKDROP_MAIN
);
575 if (statusbar_position(i
) != STATUSBAR_OFF
)
576 oldbars
|= VP_SB_ONSCREEN(i
);
579 viewportmanager_set_statusbar(oldbars
);
580 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
581 /* Play safe and unregister the hook */
582 remove_event(LCD_EVENT_ACTIVATION
, wps_lcd_activation_hook
);
584 /* unhandle statusbar update delay */
585 sb_skin_set_update_delay(DEFAULT_UPDATE_DELAY
);
586 send_event(GUI_EVENT_REFRESH
, NULL
);
589 #ifdef HAVE_TOUCHSCREEN
590 int wps_get_touchaction(struct wps_data
*data
)
594 int type
= action_get_touchscreen_press(&x
, &y
);
595 static int last_action
= ACTION_NONE
;
596 struct touchregion
*r
;
597 bool repeated
= (type
== BUTTON_REPEAT
);
598 bool released
= (type
== BUTTON_REL
);
599 struct skin_token_list
*regions
= data
->touchregions
;
602 r
= (struct touchregion
*)regions
->token
->value
.data
;
603 /* make sure this region's viewport is visible */
604 if (r
->wvp
->hidden_flags
&VP_DRAW_HIDDEN
)
606 regions
= regions
->next
;
609 /* check if it's inside this viewport */
610 if (viewport_point_within_vp(&(r
->wvp
->vp
), x
, y
))
611 { /* reposition the touch inside the viewport since touchregions
612 * are relative to a preceding viewport */
613 vx
= x
- r
->wvp
->vp
.x
;
614 vy
= y
- r
->wvp
->vp
.y
;
615 /* now see if the point is inside this region */
616 if (vx
>= r
->x
&& vx
< r
->x
+r
->width
&&
617 vy
>= r
->y
&& vy
< r
->y
+r
->height
)
619 /* reposition the touch within the area */
625 case WPS_TOUCHREGION_ACTION
:
626 if ((repeated
&& r
->repeat
) || (released
&& !r
->repeat
))
628 last_action
= r
->action
;
632 case WPS_TOUCHREGION_SCROLLBAR
:
633 if(r
->width
> r
->height
)
635 wps_state
.id3
->elapsed
= (vx
*
636 wps_state
.id3
->length
) / r
->width
;
639 wps_state
.id3
->elapsed
= (vy
*
640 wps_state
.id3
->length
) / r
->height
;
642 if (!wps_state
.paused
)
643 #if (CONFIG_CODEC == SWCODEC)
644 audio_pre_ff_rewind();
648 audio_ff_rewind(wps_state
.id3
->elapsed
);
649 #if (CONFIG_CODEC != SWCODEC)
650 if (!wps_state
.paused
)
654 case WPS_TOUCHREGION_VOLUME
:
656 const int min_vol
= sound_min(SOUND_VOLUME
);
657 const int max_vol
= sound_max(SOUND_VOLUME
);
658 if(r
->width
> r
->height
)
660 global_settings
.volume
= (vx
*
661 (max_vol
- min_vol
)) / r
->width
;
664 global_settings
.volume
= (vy
*
665 (max_vol
-min_vol
)) / r
->height
;
667 global_settings
.volume
+= min_vol
;
669 return ACTION_REDRAW
;
674 regions
= regions
->next
;
677 if ((last_action
== ACTION_WPS_SEEKBACK
|| last_action
== ACTION_WPS_SEEKFWD
))
678 return ACTION_WPS_STOPSEEK
;
679 last_action
= ACTION_TOUCHSCREEN
;
680 return ACTION_TOUCHSCREEN
;
683 /* The WPS can be left in two ways:
684 * a) call a function, which draws over the wps. In this case, the wps
685 * will be still active (i.e. the below function didn't return)
686 * b) return with a value evaluated by root_menu.c, in this case the wps
687 * is really left, and root_menu will handle the next screen
689 * In either way, call gwps_leave_wps(), in order to restore the correct
690 * "main screen" backdrops and statusbars
692 long gui_wps_show(void)
696 long restoretimer
= RESTORE_WPS_INSTANTLY
; /* timer to delay screen redraw temporarily */
698 bool bookmark
= false;
700 bool vol_changed
= false;
702 long last_left
= 0, last_right
= 0;
704 #ifdef HAVE_LCD_CHARCELLS
705 status_set_audio(true);
706 status_set_param(false);
708 statusbar_toggle_handler(NULL
);
711 #ifdef AB_REPEAT_ENABLE
719 bool audio_paused
= (audio_status() & AUDIO_STATUS_PAUSE
)?true:false;
721 /* did someone else (i.e power thread) change audio pause mode? */
722 if (wps_state
.paused
!= audio_paused
) {
723 wps_state
.paused
= audio_paused
;
725 /* if another thread paused audio, we are probably in car mode,
726 about to shut down. lets save the settings. */
727 if (wps_state
.paused
) {
729 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
730 call_storage_idle_notifys(true);
734 #ifdef HAVE_LCD_BITMAP
735 /* when the peak meter is enabled we want to have a
736 few extra updates to make it look smooth. On the
737 other hand we don't want to waste energy if it
742 if(gui_wps
[i
].data
->peak_meter_enabled
)
747 long next_refresh
= current_tick
;
748 long next_big_refresh
= current_tick
+ HZ
/ 5;
749 button
= BUTTON_NONE
;
750 while (TIME_BEFORE(current_tick
, next_big_refresh
)) {
751 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_NOBLOCK
);
752 if (button
!= ACTION_NONE
) {
756 sleep(0); /* Sleep until end of current tick. */
758 if (TIME_AFTER(current_tick
, next_refresh
)) {
761 if(gui_wps
[i
].data
->peak_meter_enabled
)
762 skin_update(&gui_wps
[i
], WPS_REFRESH_PEAK_METER
);
763 next_refresh
+= HZ
/ PEAK_METER_FPS
;
770 /* The peak meter is disabled
771 -> no additional screen updates needed */
775 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,
776 restore
? HZ
/100 : HZ
/5);
779 /* Exit if audio has stopped playing. This happens e.g. at end of
780 playlist or if using the sleep timer. */
781 if (!(audio_status() & AUDIO_STATUS_PLAY
))
783 #ifdef HAVE_TOUCHSCREEN
784 if (button
== ACTION_TOUCHSCREEN
)
785 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
787 /* The iPods/X5/M5 use a single button for the A-B mode markers,
788 defined as ACTION_WPSAB_SINGLE in their config files. */
789 #ifdef ACTION_WPSAB_SINGLE
790 if (!global_settings
.party_mode
&& ab_repeat_mode_enabled())
792 static int wps_ab_state
= 0;
793 if (button
== ACTION_WPSAB_SINGLE
)
795 switch (wps_ab_state
)
797 case 0: /* set the A spot */
798 button
= ACTION_WPS_ABSETA_PREVDIR
;
800 case 1: /* set the B spot */
801 button
= ACTION_WPS_ABSETB_NEXTDIR
;
804 button
= ACTION_WPS_ABRESET
;
807 wps_ab_state
= (wps_ab_state
+1) % 3;
813 case ACTION_WPS_CONTEXT
:
816 /* if music is stopped in the context menu we want to exit the wps */
817 if (onplay(wps_state
.id3
->path
,
818 FILE_ATTR_AUDIO
, CONTEXT_WPS
) == ONPLAY_MAINMENU
825 case ACTION_WPS_BROWSE
:
826 #ifdef HAVE_LCD_CHARCELLS
827 status_set_record(false);
828 status_set_audio(false);
831 return GO_TO_PREVIOUS_BROWSER
;
835 case ACTION_WPS_PLAY
:
836 if (global_settings
.party_mode
)
838 if ( wps_state
.paused
)
840 wps_state
.paused
= false;
841 if ( global_settings
.fade_on_stop
)
848 wps_state
.paused
= true;
849 if ( global_settings
.fade_on_stop
)
854 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
855 call_storage_idle_notifys(true); /* make sure resume info is saved */
860 case ACTION_WPS_VOLUP
:
861 global_settings
.volume
++;
864 case ACTION_WPS_VOLDOWN
:
865 global_settings
.volume
--;
869 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
870 case ACTION_WPS_SEEKFWD
:
871 if (global_settings
.party_mode
)
873 if (current_tick
-last_right
< HZ
)
875 if (wps_state
.id3
->cuesheet
)
885 ffwd_rew(ACTION_WPS_SEEKFWD
);
886 last_right
= last_left
= 0;
889 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
890 case ACTION_WPS_SEEKBACK
:
891 if (global_settings
.party_mode
)
893 if (current_tick
-last_left
< HZ
)
895 if (wps_state
.id3
->cuesheet
)
897 if (!wps_state
.paused
)
898 #if (CONFIG_CODEC == SWCODEC)
899 audio_pre_ff_rewind();
911 ffwd_rew(ACTION_WPS_SEEKBACK
);
912 last_left
= last_right
= 0;
916 case ACTION_WPS_SKIPPREV
:
917 if (global_settings
.party_mode
)
919 last_left
= current_tick
;
920 #ifdef AB_REPEAT_ENABLE
921 /* if we're in A/B repeat mode and the current position
922 is past the A marker, jump back to the A marker... */
923 if ( ab_repeat_mode_enabled() )
925 if ( ab_after_A_marker(wps_state
.id3
->elapsed
) )
927 ab_jump_to_A_marker();
929 #if (AB_REPEAT_ENABLE == 2)
936 /* ...otherwise, do it normally */
942 OR if skip length set, hop by predetermined amount. */
943 case ACTION_WPS_SKIPNEXT
:
944 if (global_settings
.party_mode
)
946 last_right
= current_tick
;
947 #ifdef AB_REPEAT_ENABLE
948 /* if we're in A/B repeat mode and the current position is
949 before the A marker, jump to the A marker... */
950 if ( ab_repeat_mode_enabled() )
952 if ( ab_before_A_marker(wps_state
.id3
->elapsed
) )
954 ab_jump_to_A_marker();
956 #if (AB_REPEAT_ENABLE == 2)
963 /* ...otherwise, do it normally */
967 /* next / prev directories */
968 /* and set A-B markers if in a-b mode */
969 case ACTION_WPS_ABSETB_NEXTDIR
:
970 if (global_settings
.party_mode
)
972 #if defined(AB_REPEAT_ENABLE)
973 if (ab_repeat_mode_enabled())
975 ab_set_B_marker(wps_state
.id3
->elapsed
);
976 ab_jump_to_A_marker();
984 case ACTION_WPS_ABSETA_PREVDIR
:
985 if (global_settings
.party_mode
)
987 #if defined(AB_REPEAT_ENABLE)
988 if (ab_repeat_mode_enabled())
989 ab_set_A_marker(wps_state
.id3
->elapsed
);
996 /* menu key functions */
997 case ACTION_WPS_MENU
:
1003 #ifdef HAVE_QUICKSCREEN
1004 case ACTION_WPS_QUICKSCREEN
:
1007 if (quick_screen_quick(button
))
1012 #endif /* HAVE_QUICKSCREEN */
1014 /* screen settings */
1019 if (quick_screen_f3(BUTTON_F3
))
1024 #endif /* BUTTON_F3 */
1027 #ifdef HAVE_PITCHSCREEN
1028 case ACTION_WPS_PITCHSCREEN
:
1031 if (1 == gui_syncpitchscreen_run())
1036 #endif /* HAVE_PITCHSCREEN */
1038 #ifdef AB_REPEAT_ENABLE
1039 /* reset A&B markers */
1040 case ACTION_WPS_ABRESET
:
1041 if (ab_repeat_mode_enabled())
1047 #endif /* AB_REPEAT_ENABLE */
1049 /* stop and exit wps */
1050 case ACTION_WPS_STOP
:
1051 if (global_settings
.party_mode
)
1057 case ACTION_WPS_ID3SCREEN
:
1065 #ifdef HAVE_TOUCHSCREEN
1066 case ACTION_TOUCH_SHUFFLE
: /* toggle shuffle mode */
1068 global_settings
.playlist_shuffle
=
1069 !global_settings
.playlist_shuffle
;
1070 #if CONFIG_CODEC == SWCODEC
1071 dsp_set_replaygain();
1073 if (global_settings
.playlist_shuffle
)
1074 playlist_randomise(NULL
, current_tick
, true);
1076 playlist_sort(NULL
, true);
1079 case ACTION_TOUCH_REPMODE
: /* cycle the repeat mode setting */
1081 const struct settings_list
*rep_setting
=
1082 find_setting(&global_settings
.repeat_mode
, NULL
);
1083 option_select_next_val(rep_setting
, false, true);
1084 audio_flush_and_reload_tracks();
1087 #endif /* HAVE_TOUCHSCREEN */
1088 /* this case is used by the softlock feature
1089 * it requests a full update here */
1091 wps_sync_data
.do_full_update
= true;
1093 case ACTION_NONE
: /* Timeout, do a partial update */
1095 ffwd_rew(button
); /* hopefully fix the ffw/rwd bug */
1097 #ifdef HAVE_RECORDING
1098 case ACTION_WPS_REC
:
1103 default_event_handler(SYS_POWEROFF
);
1105 case ACTION_WPS_VIEW_PLAYLIST
:
1107 if (playlist_viewer()) /* true if USB connected */
1112 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1127 if(update_onvol_change(&gui_wps
[i
]))
1132 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
1136 if (wps_sync_data
.do_full_update
|| update
)
1138 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
1139 gwps_caption_backlight(&wps_state
);
1143 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1144 /* currently, all remotes are readable without backlight
1145 * so still update those */
1146 if (lcd_active() || (i
!= SCREEN_MAIN
))
1149 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
1152 wps_sync_data
.do_full_update
= false;
1156 if (restore
&& wps_state
.id3
&&
1157 ((restoretimer
== RESTORE_WPS_INSTANTLY
) ||
1158 TIME_AFTER(current_tick
, restoretimer
)))
1161 restoretimer
= RESTORE_WPS_INSTANTLY
;
1162 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1163 add_event(LCD_EVENT_ACTIVATION
, false, wps_lcd_activation_hook
);
1165 /* we remove the update delay since it's not very usable in the wps,
1166 * e.g. during volume changing or ffwd/rewind */
1167 sb_skin_set_update_delay(0);
1170 screens
[i
].stop_scroll();
1171 gui_wps_display(&gui_wps
[i
]);
1176 #ifdef HAVE_LCD_CHARCELLS
1177 status_set_record(false);
1178 status_set_audio(false);
1180 if (global_settings
.fade_on_stop
)
1184 bookmark_autobookmark();
1186 #ifdef AB_REPEAT_ENABLE
1190 #ifdef HAVE_RECORDING
1191 if (button
== ACTION_WPS_REC
)
1192 return GO_TO_RECSCREEN
;
1194 if (global_settings
.browse_current
)
1195 return GO_TO_PREVIOUS_BROWSER
;
1196 return GO_TO_PREVIOUS
;
1199 if (button
&& !IS_SYSEVENT(button
) )
1202 return GO_TO_ROOT
; /* unreachable - just to reduce compiler warnings */
1205 /* this is called from the playback thread so NO DRAWING! */
1206 static void track_changed_callback(void *param
)
1208 wps_state
.id3
= (struct mp3entry
*)param
;
1209 wps_state
.nid3
= audio_next_track();
1210 if (wps_state
.id3
->cuesheet
)
1212 cue_find_current_track(wps_state
.id3
->cuesheet
, wps_state
.id3
->elapsed
);
1213 cue_spoof_id3(wps_state
.id3
->cuesheet
, wps_state
.id3
);
1215 wps_sync_data
.do_full_update
= true;
1217 static void nextid3available_callback(void* param
)
1220 wps_state
.nid3
= audio_next_track();
1221 wps_sync_data
.do_full_update
= true;
1225 static void wps_state_init(void)
1227 wps_state
.ff_rewind
= false;
1228 wps_state
.paused
= false;
1229 if(audio_status() & AUDIO_STATUS_PLAY
)
1231 wps_state
.id3
= audio_current_track();
1232 wps_state
.nid3
= audio_next_track();
1236 wps_state
.id3
= NULL
;
1237 wps_state
.nid3
= NULL
;
1239 /* We'll be updating due to restore initialized with true */
1240 wps_sync_data
.do_full_update
= false;
1241 /* add the WPS track event callbacks */
1242 add_event(PLAYBACK_EVENT_TRACK_CHANGE
, false, track_changed_callback
);
1243 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, false, nextid3available_callback
);
1247 #ifdef HAVE_LCD_BITMAP
1248 static void statusbar_toggle_handler(void *data
)
1253 int *wpsbars
= &wps_sync_data
.statusbars
;
1254 *wpsbars
= VP_SB_HIDE_ALL
;
1256 { /* fix viewports if needed */
1257 skin_statusbar_changed(&gui_wps
[i
]);
1261 /* fix up gui_wps::statusbars, so that the viewportmanager accepts it*/
1262 if (gui_wps
[i
].data
->wps_sb_tag
)
1263 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
1264 else if (statusbar_position(i
) != STATUSBAR_OFF
)
1268 (VP_SB_ONSCREEN(i
) | VP_SB_IGNORE_SETTING(i
));
1274 void gui_sync_wps_init(void)
1279 #ifdef HAVE_ALBUMART
1280 wps_datas
[i
].albumart
= NULL
;
1281 wps_datas
[i
].playback_aa_slot
= -1;
1283 #ifdef HAVE_REMOTE_LCD
1284 wps_datas
[i
].remote_wps
= (i
== SCREEN_REMOTE
);
1286 gui_wps
[i
].data
= &wps_datas
[i
];
1287 gui_wps
[i
].display
= &screens
[i
];
1288 /* Currently no seperate wps_state needed/possible
1289 so use the only available ( "global" ) one */
1290 gui_wps
[i
].state
= &wps_state
;
1291 gui_wps
[i
].display
->backdrop_unload(BACKDROP_SKIN_WPS
);
1292 /* must point to the same struct for both screens */
1293 gui_wps
[i
].sync_data
= &wps_sync_data
;
1294 gui_wps
[i
].sync_data
->statusbars
= VP_SB_ALLSCREENS
;
1296 #ifdef HAVE_LCD_BITMAP
1297 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false, statusbar_toggle_handler
);
1302 #ifdef IPOD_ACCESSORY_PROTOCOL
1303 bool is_wps_fading(void)
1305 return wps_state
.is_fading
;
1308 int wps_get_ff_rewind_count(void)
1310 return wps_state
.ff_rewind_count
;