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"
37 #include "skin_engine/skin_engine.h"
38 #include "mp3_playback.h"
45 #ifdef HAVE_LCD_BITMAP
47 #include "peakmeter.h"
58 #include "ata_idle_notify.h"
59 #include "root_menu.h"
61 #include "quickscreen.h"
62 #include "pitchscreen.h"
63 #include "appevents.h"
66 #include "option_select.h"
68 #include "playlist_viewer.h"
71 #define RESTORE_WPS_INSTANTLY 0l
72 #define RESTORE_WPS_NEXT_SECOND ((long)(HZ+current_tick))
74 #define DEFAULT_SKIP_TRESH 3000ul
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 /* this is for the viewportmanager */
83 /* currently only one wps_state is needed */
84 static struct wps_state wps_state
;
85 static struct gui_wps gui_wps
[NB_SCREENS
];
86 static struct wps_data wps_datas
[NB_SCREENS
];
88 /* initial setup of wps_data */
89 static void wps_state_init(void);
90 static void track_changed_callback(void *param
);
91 static void nextid3available_callback(void* param
);
92 #ifdef HAVE_LCD_BITMAP
93 static void statusbar_toggle_handler(void *data
);
96 #define WPS_DEFAULTCFG WPS_DIR "/rockbox_default.wps"
97 #ifdef HAVE_REMOTE_LCD
98 #define RWPS_DEFAULTCFG WPS_DIR "/rockbox_default.rwps"
99 #define DEFAULT_WPS(screen) ((screen) == SCREEN_MAIN ? \
100 WPS_DEFAULTCFG:RWPS_DEFAULTCFG)
102 #define DEFAULT_WPS(screen) (WPS_DEFAULTCFG)
105 void wps_data_load(enum screen_type screen
, const char *buf
, bool isfile
)
109 screens
[screen
].backdrop_unload(BACKDROP_SKIN_WPS
);
113 * Hardcode loading WPS_DEFAULTCFG to cause a reset ideally this
114 * wants to be a virtual file. Feel free to modify dirbrowse()
115 * if you're feeling brave.
118 if (buf
&& ! strcmp(buf
, DEFAULT_WPS(screen
)) )
120 #ifdef HAVE_REMOTE_LCD
121 if (screen
== SCREEN_REMOTE
)
122 global_settings
.rwps_file
[0] = '\0';
125 global_settings
.wps_file
[0] = '\0';
129 #endif /* __PCTOOL__ */
131 loaded_ok
= buf
&& skin_data_load(gui_wps
[screen
].data
,
132 &screens
[screen
], buf
, isfile
);
133 if (!loaded_ok
) /* load the hardcoded default */
135 char *skin_buf
[NB_SCREENS
] = {
136 #ifdef HAVE_LCD_BITMAP
137 "%s%?it<%?in<%in. |>%it|%fn>\n"
138 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
139 "%s%?id<%id|%?d1<%d1|(root)>> %?iy<(%iy)|>\n\n"
140 "%al%pc/%pt%ar[%pp:%pe]\n"
141 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
144 "%s%pp/%pe: %?it<%it|%fn> - %?ia<%ia|%d2> - %?id<%id|%d1>\n"
147 #ifdef HAVE_REMOTE_LCD
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(gui_wps
[screen
].data
, &screens
[screen
],
156 skin_buf
[screen
], false);
158 #ifdef HAVE_REMOVE_LCD
159 gui_wps
[screen
].data
->remote_wps
= !(screen
== SCREEN_MAIN
);
163 void wps_data_init(enum screen_type screen
)
165 skin_data_init(gui_wps
[screen
].data
);
169 static bool wps_fading_out
= false;
170 void fade(bool fade_in
, bool updatewps
)
172 int fp_global_vol
= global_settings
.volume
<< 8;
173 int fp_min_vol
= sound_min(SOUND_VOLUME
) << 8;
174 int fp_step
= (fp_global_vol
- fp_min_vol
) / 30;
176 wps_fading_out
= !fade_in
;
179 int fp_volume
= fp_min_vol
;
181 /* zero out the sound */
182 sound_set_volume(fp_min_vol
>> 8);
184 sleep(HZ
/10); /* let audio thread run */
187 while (fp_volume
< fp_global_vol
- fp_step
) {
188 fp_volume
+= fp_step
;
189 sound_set_volume(fp_volume
>> 8);
193 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
197 sound_set_volume(global_settings
.volume
);
201 int fp_volume
= fp_global_vol
;
203 while (fp_volume
> fp_min_vol
+ fp_step
) {
204 fp_volume
-= fp_step
;
205 sound_set_volume(fp_volume
>> 8);
209 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
214 wps_fading_out
= false;
215 #if CONFIG_CODEC != SWCODEC
217 /* let audio thread run and wait for the mas to run out of data */
218 while (!mp3_pause_done())
223 /* reset volume to what it was before the fade */
224 sound_set_volume(global_settings
.volume
);
227 bool is_wps_fading(void)
229 return wps_fading_out
;
232 static bool update_onvol_change(struct gui_wps
* gwps
)
234 skin_update(gwps
, WPS_REFRESH_NON_STATIC
);
236 #ifdef HAVE_LCD_CHARCELLS
237 splashf(0, "Vol: %3d dB",
238 sound_val2phys(SOUND_VOLUME
, global_settings
.volume
));
245 bool ffwd_rew(int button
)
247 unsigned int step
= 0; /* current ff/rewind step */
248 unsigned int max_step
= 0; /* maximum ff/rewind step */
249 int ff_rewind_count
= 0; /* current ff/rewind count (in ticks) */
250 int direction
= -1; /* forward=1 or backward=-1 */
254 const long ff_rw_accel
= (global_settings
.ff_rewind_accel
+ 3);
256 if (button
== ACTION_NONE
)
258 status_set_ffmode(0);
265 case ACTION_WPS_SEEKFWD
:
267 case ACTION_WPS_SEEKBACK
:
268 if (wps_state
.ff_rewind
)
272 /* fast forwarding, calc max step relative to end */
273 max_step
= (wps_state
.id3
->length
-
274 (wps_state
.id3
->elapsed
+
276 FF_REWIND_MAX_PERCENT
/ 100;
280 /* rewinding, calc max step relative to start */
281 max_step
= (wps_state
.id3
->elapsed
+ ff_rewind_count
) *
282 FF_REWIND_MAX_PERCENT
/ 100;
285 max_step
= MAX(max_step
, MIN_FF_REWIND_STEP
);
290 ff_rewind_count
+= step
* direction
;
292 /* smooth seeking by multiplying step by: 1 + (2 ^ -accel) */
293 step
+= step
>> ff_rw_accel
;
297 if ( (audio_status() & AUDIO_STATUS_PLAY
) &&
298 wps_state
.id3
&& wps_state
.id3
->length
)
300 if (!wps_state
.paused
)
301 #if (CONFIG_CODEC == SWCODEC)
302 audio_pre_ff_rewind();
306 #if CONFIG_KEYPAD == PLAYER_PAD
308 gui_wps
[i
].display
->stop_scroll();
311 status_set_ffmode(STATUS_FASTFORWARD
);
313 status_set_ffmode(STATUS_FASTBACKWARD
);
315 wps_state
.ff_rewind
= true;
317 step
= 1000 * global_settings
.ff_rewind_min_step
;
324 if ((wps_state
.id3
->elapsed
+ ff_rewind_count
) >
325 wps_state
.id3
->length
)
326 ff_rewind_count
= wps_state
.id3
->length
-
327 wps_state
.id3
->elapsed
;
330 if ((int)(wps_state
.id3
->elapsed
+ ff_rewind_count
) < 0)
331 ff_rewind_count
= -wps_state
.id3
->elapsed
;
334 /* set the wps state ff_rewind_count so the progess info
336 wps_state
.ff_rewind_count
= (wps_state
.wps_time_countup
== false)?
337 ff_rewind_count
:-ff_rewind_count
;
340 skin_update(&gui_wps
[i
],
341 WPS_REFRESH_PLAYER_PROGRESS
|
342 WPS_REFRESH_DYNAMIC
);
347 case ACTION_WPS_STOPSEEK
:
348 wps_state
.id3
->elapsed
= wps_state
.id3
->elapsed
+ff_rewind_count
;
349 audio_ff_rewind(wps_state
.id3
->elapsed
);
350 wps_state
.ff_rewind_count
= 0;
351 wps_state
.ff_rewind
= false;
352 status_set_ffmode(0);
353 #if (CONFIG_CODEC != SWCODEC)
354 if (!wps_state
.paused
)
357 #ifdef HAVE_LCD_CHARCELLS
359 skin_update(&gui_wps
[i
], WPS_REFRESH_ALL
);
365 if(default_event_handler(button
) == SYS_USB_CONNECTED
) {
366 status_set_ffmode(0);
374 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_BLOCK
);
375 #ifdef HAVE_TOUCHSCREEN
376 if (button
== ACTION_TOUCHSCREEN
)
377 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
385 void display_keylock_text(bool locked
)
389 gui_wps
[i
].display
->stop_scroll();
391 splash(HZ
, locked
? ID2P(LANG_KEYLOCK_ON
) : ID2P(LANG_KEYLOCK_OFF
));
397 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
398 static void gwps_caption_backlight(struct wps_state
*state
)
400 if (state
&& state
->id3
)
402 #ifdef HAVE_BACKLIGHT
403 if (global_settings
.caption_backlight
)
405 /* turn on backlight n seconds before track ends, and turn it off n
406 seconds into the new track. n == backlight_timeout, or 5s */
407 int n
= global_settings
.backlight_timeout
* 1000;
410 n
= 5000; /* use 5s if backlight is always on or off */
412 if (((state
->id3
->elapsed
< 1000) ||
413 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
414 (state
->paused
== false))
418 #ifdef HAVE_REMOTE_LCD
419 if (global_settings
.remote_caption_backlight
)
421 /* turn on remote backlight n seconds before track ends, and turn it
422 off n seconds into the new track. n == remote_backlight_timeout,
424 int n
= global_settings
.remote_backlight_timeout
* 1000;
427 n
= 5000; /* use 5s if backlight is always on or off */
429 if (((state
->id3
->elapsed
< 1000) ||
430 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
431 (state
->paused
== false))
432 remote_backlight_on();
440 static void change_dir(int direction
)
442 if (global_settings
.prevent_skip
)
447 else if (direction
> 0)
449 /* prevent the next dir to immediatly start being ffw'd */
450 action_wait_for_release();
453 static void prev_track(unsigned long skip_thresh
)
455 if (wps_state
.id3
->elapsed
< skip_thresh
)
462 if (wps_state
.id3
->cuesheet
)
464 curr_cuesheet_skip(wps_state
.id3
->cuesheet
, -1, wps_state
.id3
->elapsed
);
468 if (!wps_state
.paused
)
469 #if (CONFIG_CODEC == SWCODEC)
470 audio_pre_ff_rewind();
477 #if (CONFIG_CODEC != SWCODEC)
478 if (!wps_state
.paused
)
484 static void next_track(void)
486 /* take care of if we're playing a cuesheet */
487 if (wps_state
.id3
->cuesheet
)
489 if (curr_cuesheet_skip(wps_state
.id3
->cuesheet
, 1, wps_state
.id3
->elapsed
))
491 /* if the result was false, then we really want
492 to skip to the next track */
500 static void play_hop(int direction
)
502 unsigned long step
= ((unsigned long)global_settings
.skip_length
)*1000;
503 unsigned long elapsed
= wps_state
.id3
->elapsed
;
504 unsigned long remaining
= wps_state
.id3
->length
- elapsed
;
506 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
);
518 if (direction
== 1 && step
>= remaining
)
520 #if CONFIG_CODEC == SWCODEC
521 if(global_settings
.beep
)
522 pcmbuf_beep(1000, 150, 1500*global_settings
.beep
);
526 else if ((direction
== -1 && elapsed
< step
))
532 elapsed
+= step
* direction
;
534 if((audio_status() & AUDIO_STATUS_PLAY
) && !wps_state
.paused
)
536 #if (CONFIG_CODEC == SWCODEC)
537 audio_pre_ff_rewind();
542 audio_ff_rewind(wps_state
.id3
->elapsed
= elapsed
);
543 #if (CONFIG_CODEC != SWCODEC)
544 if (!wps_state
.paused
)
550 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
552 * If the user is unable to see the wps, because the display is deactivated,
553 * we suppress updates until the wps is activated again (the lcd driver will
554 * call this hook to issue an instant update)
556 static void wps_lcd_activation_hook(void)
558 wps_state
.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)
566 int i
, oldbars
= VP_SB_HIDE_ALL
;
570 gui_wps
[i
].display
->stop_scroll();
571 gui_wps
[i
].display
->backdrop_show(BACKDROP_MAIN
);
572 if (statusbar_position(i
) != STATUSBAR_OFF
)
573 oldbars
|= VP_SB_ONSCREEN(i
);
576 viewportmanager_set_statusbar(oldbars
);
577 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
578 /* Play safe and unregister the hook */
579 lcd_activation_set_hook(NULL
);
581 send_event(GUI_EVENT_REFRESH
, NULL
);
584 #ifdef HAVE_TOUCHSCREEN
585 int wps_get_touchaction(struct wps_data
*data
)
589 int type
= action_get_touchscreen_press(&x
, &y
);
590 static int last_action
= ACTION_NONE
;
591 struct touchregion
*r
;
592 bool repeated
= (type
== BUTTON_REPEAT
);
593 bool released
= (type
== BUTTON_REL
);
594 struct skin_token_list
*regions
= data
->touchregions
;
597 r
= (struct touchregion
*)regions
->token
->value
.data
;
598 /* make sure this region's viewport is visible */
599 if (r
->wvp
->hidden_flags
&VP_DRAW_HIDDEN
)
601 regions
= regions
->next
;
604 /* check if it's inside this viewport */
605 if (viewport_point_within_vp(&(r
->wvp
->vp
), x
, y
))
606 { /* reposition the touch inside the viewport since touchregions
607 * are relative to a preceding viewport */
608 vx
= x
- r
->wvp
->vp
.x
;
609 vy
= y
- r
->wvp
->vp
.y
;
610 /* now see if the point is inside this region */
611 if (vx
>= r
->x
&& vx
< r
->x
+r
->width
&&
612 vy
>= r
->y
&& vy
< r
->y
+r
->height
)
614 /* reposition the touch within the area */
620 case WPS_TOUCHREGION_ACTION
:
621 if ((repeated
&& r
->repeat
) || (released
&& !r
->repeat
))
623 last_action
= r
->action
;
627 case WPS_TOUCHREGION_SCROLLBAR
:
628 if(r
->width
> r
->height
)
630 wps_state
.id3
->elapsed
= (vx
*
631 wps_state
.id3
->length
) / r
->width
;
634 wps_state
.id3
->elapsed
= (vy
*
635 wps_state
.id3
->length
) / r
->height
;
637 if (!wps_state
.paused
)
638 #if (CONFIG_CODEC == SWCODEC)
639 audio_pre_ff_rewind();
643 audio_ff_rewind(wps_state
.id3
->elapsed
);
644 #if (CONFIG_CODEC != SWCODEC)
645 if (!wps_state
.paused
)
649 case WPS_TOUCHREGION_VOLUME
:
652 const int min_vol
= sound_min(SOUND_VOLUME
);
653 const int max_vol
= sound_max(SOUND_VOLUME
);
654 if(r
->width
> r
->height
)
656 global_settings
.volume
= (vx
*
657 (max_vol
- min_vol
)) / r
->width
;
660 global_settings
.volume
= (vy
*
661 (max_vol
-min_vol
)) / r
->height
;
663 global_settings
.volume
+= min_vol
;
667 gui_wps
[i
].data
->button_time_volume
= current_tick
;
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;
701 long last_left
= 0, last_right
= 0;
703 #ifdef HAVE_LCD_CHARCELLS
704 status_set_audio(true);
705 status_set_param(false);
707 statusbar_toggle_handler(NULL
);
710 #ifdef AB_REPEAT_ENABLE
718 bool audio_paused
= (audio_status() & AUDIO_STATUS_PAUSE
)?true:false;
720 /* did someone else (i.e power thread) change audio pause mode? */
721 if (wps_state
.paused
!= audio_paused
) {
722 wps_state
.paused
= audio_paused
;
724 /* if another thread paused audio, we are probably in car mode,
725 about to shut down. lets save the settings. */
726 if (wps_state
.paused
) {
728 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
729 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
:
863 gui_wps
[i
].data
->button_time_volume
= current_tick
;
864 global_settings
.volume
++;
869 if(update_onvol_change(&gui_wps
[i
]))
874 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
878 case ACTION_WPS_VOLDOWN
:
881 gui_wps
[i
].data
->button_time_volume
= current_tick
;
882 global_settings
.volume
--;
887 if(update_onvol_change(&gui_wps
[i
]))
892 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
897 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
898 case ACTION_WPS_SEEKFWD
:
899 if (global_settings
.party_mode
)
901 if (current_tick
-last_right
< HZ
)
903 if (wps_state
.id3
->cuesheet
)
913 ffwd_rew(ACTION_WPS_SEEKFWD
);
914 last_right
= last_left
= 0;
917 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
918 case ACTION_WPS_SEEKBACK
:
919 if (global_settings
.party_mode
)
921 if (current_tick
-last_left
< HZ
)
923 if (wps_state
.id3
->cuesheet
)
925 if (!wps_state
.paused
)
926 #if (CONFIG_CODEC == SWCODEC)
927 audio_pre_ff_rewind();
939 ffwd_rew(ACTION_WPS_SEEKBACK
);
940 last_left
= last_right
= 0;
944 case ACTION_WPS_SKIPPREV
:
945 if (global_settings
.party_mode
)
947 last_left
= current_tick
;
948 #ifdef AB_REPEAT_ENABLE
949 /* if we're in A/B repeat mode and the current position
950 is past the A marker, jump back to the A marker... */
951 if ( ab_repeat_mode_enabled() )
953 if ( ab_after_A_marker(wps_state
.id3
->elapsed
) )
955 ab_jump_to_A_marker();
957 #if (AB_REPEAT_ENABLE == 2)
964 /* ...otherwise, do it normally */
970 OR if skip length set, hop by predetermined amount. */
971 case ACTION_WPS_SKIPNEXT
:
972 if (global_settings
.party_mode
)
974 last_right
= current_tick
;
975 #ifdef AB_REPEAT_ENABLE
976 /* if we're in A/B repeat mode and the current position is
977 before the A marker, jump to the A marker... */
978 if ( ab_repeat_mode_enabled() )
980 if ( ab_before_A_marker(wps_state
.id3
->elapsed
) )
982 ab_jump_to_A_marker();
984 #if (AB_REPEAT_ENABLE == 2)
991 /* ...otherwise, do it normally */
995 /* next / prev directories */
996 /* and set A-B markers if in a-b mode */
997 case ACTION_WPS_ABSETB_NEXTDIR
:
998 if (global_settings
.party_mode
)
1000 #if defined(AB_REPEAT_ENABLE)
1001 if (ab_repeat_mode_enabled())
1003 ab_set_B_marker(wps_state
.id3
->elapsed
);
1004 ab_jump_to_A_marker();
1012 case ACTION_WPS_ABSETA_PREVDIR
:
1013 if (global_settings
.party_mode
)
1015 #if defined(AB_REPEAT_ENABLE)
1016 if (ab_repeat_mode_enabled())
1017 ab_set_A_marker(wps_state
.id3
->elapsed
);
1024 /* menu key functions */
1025 case ACTION_WPS_MENU
:
1031 #ifdef HAVE_QUICKSCREEN
1032 case ACTION_WPS_QUICKSCREEN
:
1035 if (quick_screen_quick(button
))
1040 #endif /* HAVE_QUICKSCREEN */
1042 /* screen settings */
1047 if (quick_screen_f3(BUTTON_F3
))
1052 #endif /* BUTTON_F3 */
1055 #ifdef HAVE_PITCHSCREEN
1056 case ACTION_WPS_PITCHSCREEN
:
1059 if (1 == gui_syncpitchscreen_run())
1064 #endif /* HAVE_PITCHSCREEN */
1066 #ifdef AB_REPEAT_ENABLE
1067 /* reset A&B markers */
1068 case ACTION_WPS_ABRESET
:
1069 if (ab_repeat_mode_enabled())
1075 #endif /* AB_REPEAT_ENABLE */
1077 /* stop and exit wps */
1078 case ACTION_WPS_STOP
:
1079 if (global_settings
.party_mode
)
1085 case ACTION_WPS_ID3SCREEN
:
1093 #ifdef HAVE_TOUCHSCREEN
1094 case ACTION_TOUCH_SHUFFLE
: /* toggle shuffle mode */
1096 global_settings
.playlist_shuffle
=
1097 !global_settings
.playlist_shuffle
;
1098 #if CONFIG_CODEC == SWCODEC
1099 dsp_set_replaygain();
1101 if (global_settings
.playlist_shuffle
)
1102 playlist_randomise(NULL
, current_tick
, true);
1104 playlist_sort(NULL
, true);
1107 case ACTION_TOUCH_REPMODE
: /* cycle the repeat mode setting */
1109 const struct settings_list
*rep_setting
=
1110 find_setting(&global_settings
.repeat_mode
, NULL
);
1111 option_select_next_val(rep_setting
, false, true);
1112 audio_flush_and_reload_tracks();
1115 #endif /* HAVE_TOUCHSCREEN */
1116 /* this case is used by the softlock feature
1117 * it requests a full update here */
1119 wps_state
.do_full_update
= true;
1121 case ACTION_NONE
: /* Timeout, do a partial update */
1123 ffwd_rew(button
); /* hopefully fix the ffw/rwd bug */
1125 #ifdef HAVE_RECORDING
1126 case ACTION_WPS_REC
:
1131 default_event_handler(SYS_POWEROFF
);
1133 case ACTION_WPS_VIEW_PLAYLIST
:
1135 if (playlist_viewer()) /* true if USB connected */
1140 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1149 if (wps_state
.do_full_update
|| update
)
1151 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
1152 gwps_caption_backlight(&wps_state
);
1156 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1158 #ifdef HAVE_REMOTE_LCD
1159 /* currently, all remotes are readable without backlight
1160 * so still update those */
1161 || (i
== SCREEN_REMOTE
)
1166 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
1169 wps_state
.do_full_update
= false;
1173 if (restore
&& wps_state
.id3
&&
1174 ((restoretimer
== RESTORE_WPS_INSTANTLY
) ||
1175 TIME_AFTER(current_tick
, restoretimer
)))
1178 restoretimer
= RESTORE_WPS_INSTANTLY
;
1179 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1180 lcd_activation_set_hook(wps_lcd_activation_hook
);
1184 screens
[i
].stop_scroll();
1185 gui_wps_display(&gui_wps
[i
]);
1190 #ifdef HAVE_LCD_CHARCELLS
1191 status_set_record(false);
1192 status_set_audio(false);
1194 if (global_settings
.fade_on_stop
)
1198 bookmark_autobookmark();
1200 #ifdef AB_REPEAT_ENABLE
1204 #ifdef HAVE_RECORDING
1205 if (button
== ACTION_WPS_REC
)
1206 return GO_TO_RECSCREEN
;
1208 if (global_settings
.browse_current
)
1209 return GO_TO_PREVIOUS_BROWSER
;
1210 return GO_TO_PREVIOUS
;
1213 if (button
&& !IS_SYSEVENT(button
) )
1216 return GO_TO_ROOT
; /* unreachable - just to reduce compiler warnings */
1219 /* this is called from the playback thread so NO DRAWING! */
1220 static void track_changed_callback(void *param
)
1222 wps_state
.id3
= (struct mp3entry
*)param
;
1223 wps_state
.nid3
= audio_next_track();
1224 if (wps_state
.id3
->cuesheet
)
1226 cue_find_current_track(wps_state
.id3
->cuesheet
, wps_state
.id3
->elapsed
);
1227 cue_spoof_id3(wps_state
.id3
->cuesheet
, wps_state
.id3
);
1229 wps_state
.do_full_update
= true;
1231 static void nextid3available_callback(void* param
)
1234 wps_state
.nid3
= audio_next_track();
1235 wps_state
.do_full_update
= true;
1239 static void wps_state_init(void)
1241 wps_state
.ff_rewind
= false;
1242 wps_state
.paused
= false;
1243 if(audio_status() & AUDIO_STATUS_PLAY
)
1245 wps_state
.id3
= audio_current_track();
1246 wps_state
.nid3
= audio_next_track();
1250 wps_state
.id3
= NULL
;
1251 wps_state
.nid3
= NULL
;
1253 /* We'll be updating due to restore initialized with true */
1254 wps_state
.do_full_update
= false;
1255 /* add the WPS track event callbacks */
1256 add_event(PLAYBACK_EVENT_TRACK_CHANGE
, false, track_changed_callback
);
1257 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, false, nextid3available_callback
);
1261 #ifdef HAVE_LCD_BITMAP
1262 static void statusbar_toggle_handler(void *data
)
1267 wpsbars
= VP_SB_HIDE_ALL
;
1269 { /* fix viewports if needed */
1270 skin_statusbar_changed(&gui_wps
[i
]);
1274 /* fix up gui_wps::statusbars, so that the viewportmanager accepts it*/
1275 if (gui_wps
[i
].data
->wps_sb_tag
)
1276 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
1277 else if (statusbar_position(i
) != STATUSBAR_OFF
)
1281 (VP_SB_ONSCREEN(i
) | VP_SB_IGNORE_SETTING(i
));
1286 void gui_sync_wps_init(void)
1291 skin_data_init(&wps_datas
[i
]);
1292 #ifdef HAVE_ALBUMART
1293 wps_datas
[i
].albumart
= NULL
;
1295 #ifdef HAVE_REMOTE_LCD
1296 wps_datas
[i
].remote_wps
= (i
== SCREEN_REMOTE
);
1298 gui_wps
[i
].data
= &wps_datas
[i
];
1299 gui_wps
[i
].display
= &screens
[i
];
1300 /* Currently no seperate wps_state needed/possible
1301 so use the only available ( "global" ) one */
1302 gui_wps
[i
].state
= &wps_state
;
1303 gui_wps
[i
].display
->backdrop_unload(BACKDROP_SKIN_WPS
);
1304 /* only one wpsbars needed/wanted */
1305 gui_wps
[i
].statusbars
= &wpsbars
;
1307 *(gui_wps
[SCREEN_MAIN
].statusbars
) =VP_SB_ALLSCREENS
;
1308 #ifdef HAVE_LCD_BITMAP
1309 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false, statusbar_toggle_handler
);
1313 #ifdef HAVE_ALBUMART
1314 bool wps_uses_albumart(int *width
, int *height
)
1318 struct gui_wps
*gwps
= &gui_wps
[i
];
1319 struct skin_albumart
*aa
= gwps
->data
->albumart
;
1320 if (aa
&& (aa
->wps_uses_albumart
!= WPS_ALBUMART_NONE
))
1323 *width
= aa
->albumart_max_width
;
1325 *height
= aa
->albumart_max_height
;
1334 #ifdef IPOD_ACCESSORY_PROTOCOL
1335 int wps_get_ff_rewind_count(void)
1337 return wps_state
.ff_rewind_count
;