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 */
82 static int wpsbars
= 0;
84 /* currently only one wps_state is needed, initialize to 0 */
85 static struct wps_state wps_state
= { .id3
= NULL
};
86 static struct gui_wps gui_wps
[NB_SCREENS
] = {{ .data
= NULL
}};
87 static struct wps_data wps_datas
[NB_SCREENS
] = {{ .wps_loaded
= 0 }};
89 /* initial setup of wps_data */
90 static void wps_state_init(void);
91 static void track_changed_callback(void *param
);
92 static void nextid3available_callback(void* param
);
93 #ifdef HAVE_LCD_BITMAP
94 static void statusbar_toggle_handler(void *data
);
97 #define WPS_DEFAULTCFG WPS_DIR "/rockbox_default.wps"
98 #ifdef HAVE_REMOTE_LCD
99 #define RWPS_DEFAULTCFG WPS_DIR "/rockbox_default.rwps"
100 #define DEFAULT_WPS(screen) ((screen) == SCREEN_MAIN ? \
101 WPS_DEFAULTCFG:RWPS_DEFAULTCFG)
103 #define DEFAULT_WPS(screen) (WPS_DEFAULTCFG)
106 void wps_data_load(enum screen_type screen
, const char *buf
, bool isfile
)
110 screens
[screen
].backdrop_unload(BACKDROP_SKIN_WPS
);
114 * Hardcode loading WPS_DEFAULTCFG to cause a reset ideally this
115 * wants to be a virtual file. Feel free to modify dirbrowse()
116 * if you're feeling brave.
119 if (buf
&& ! strcmp(buf
, DEFAULT_WPS(screen
)) )
121 #ifdef HAVE_REMOTE_LCD
122 if (screen
== SCREEN_REMOTE
)
123 global_settings
.rwps_file
[0] = '\0';
126 global_settings
.wps_file
[0] = '\0';
130 #endif /* __PCTOOL__ */
132 loaded_ok
= buf
&& skin_data_load(gui_wps
[screen
].data
,
133 &screens
[screen
], buf
, isfile
);
134 DEBUGF("%s >> wps loading\n", __func__
);
135 if (!loaded_ok
) /* load the hardcoded default */
137 char *skin_buf
[NB_SCREENS
] = {
138 #ifdef HAVE_LCD_BITMAP
139 "%s%?it<%?in<%in. |>%it|%fn>\n"
140 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
141 "%s%?id<%id|%?d1<%d1|(root)>> %?iy<(%iy)|>\n\n"
142 "%al%pc/%pt%ar[%pp:%pe]\n"
143 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
146 "%s%pp/%pe: %?it<%it|%fn> - %?ia<%ia|%d2> - %?id<%id|%d1>\n"
149 #ifdef HAVE_REMOTE_LCD
150 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
151 "%s%?it<%?in<%in. |>%it|%fn>\n"
152 "%al%pc/%pt%ar[%pp:%pe]\n"
153 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
157 skin_data_load(gui_wps
[screen
].data
, &screens
[screen
],
158 skin_buf
[screen
], false);
160 #ifdef HAVE_REMOVE_LCD
161 gui_wps
[screen
].data
->remote_wps
= !(screen
== SCREEN_MAIN
);
165 static bool wps_fading_out
= false;
166 void fade(bool fade_in
, bool updatewps
)
168 int fp_global_vol
= global_settings
.volume
<< 8;
169 int fp_min_vol
= sound_min(SOUND_VOLUME
) << 8;
170 int fp_step
= (fp_global_vol
- fp_min_vol
) / 30;
172 wps_fading_out
= !fade_in
;
175 int fp_volume
= fp_min_vol
;
177 /* zero out the sound */
178 sound_set_volume(fp_min_vol
>> 8);
180 sleep(HZ
/10); /* let audio thread run */
183 while (fp_volume
< fp_global_vol
- fp_step
) {
184 fp_volume
+= fp_step
;
185 sound_set_volume(fp_volume
>> 8);
189 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
193 sound_set_volume(global_settings
.volume
);
197 int fp_volume
= fp_global_vol
;
199 while (fp_volume
> fp_min_vol
+ fp_step
) {
200 fp_volume
-= fp_step
;
201 sound_set_volume(fp_volume
>> 8);
205 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
210 wps_fading_out
= false;
211 #if CONFIG_CODEC != SWCODEC
213 /* let audio thread run and wait for the mas to run out of data */
214 while (!mp3_pause_done())
219 /* reset volume to what it was before the fade */
220 sound_set_volume(global_settings
.volume
);
223 bool is_wps_fading(void)
225 return wps_fading_out
;
228 static bool update_onvol_change(struct gui_wps
* gwps
)
230 skin_update(gwps
, WPS_REFRESH_NON_STATIC
);
232 #ifdef HAVE_LCD_CHARCELLS
233 splashf(0, "Vol: %3d dB",
234 sound_val2phys(SOUND_VOLUME
, global_settings
.volume
));
241 bool ffwd_rew(int button
)
243 unsigned int step
= 0; /* current ff/rewind step */
244 unsigned int max_step
= 0; /* maximum ff/rewind step */
245 int ff_rewind_count
= 0; /* current ff/rewind count (in ticks) */
246 int direction
= -1; /* forward=1 or backward=-1 */
250 const long ff_rw_accel
= (global_settings
.ff_rewind_accel
+ 3);
252 if (button
== ACTION_NONE
)
254 status_set_ffmode(0);
261 case ACTION_WPS_SEEKFWD
:
263 case ACTION_WPS_SEEKBACK
:
264 if (wps_state
.ff_rewind
)
268 /* fast forwarding, calc max step relative to end */
269 max_step
= (wps_state
.id3
->length
-
270 (wps_state
.id3
->elapsed
+
272 FF_REWIND_MAX_PERCENT
/ 100;
276 /* rewinding, calc max step relative to start */
277 max_step
= (wps_state
.id3
->elapsed
+ ff_rewind_count
) *
278 FF_REWIND_MAX_PERCENT
/ 100;
281 max_step
= MAX(max_step
, MIN_FF_REWIND_STEP
);
286 ff_rewind_count
+= step
* direction
;
288 /* smooth seeking by multiplying step by: 1 + (2 ^ -accel) */
289 step
+= step
>> ff_rw_accel
;
293 if ( (audio_status() & AUDIO_STATUS_PLAY
) &&
294 wps_state
.id3
&& wps_state
.id3
->length
)
296 if (!wps_state
.paused
)
297 #if (CONFIG_CODEC == SWCODEC)
298 audio_pre_ff_rewind();
302 #if CONFIG_KEYPAD == PLAYER_PAD
304 gui_wps
[i
].display
->stop_scroll();
307 status_set_ffmode(STATUS_FASTFORWARD
);
309 status_set_ffmode(STATUS_FASTBACKWARD
);
311 wps_state
.ff_rewind
= true;
313 step
= 1000 * global_settings
.ff_rewind_min_step
;
320 if ((wps_state
.id3
->elapsed
+ ff_rewind_count
) >
321 wps_state
.id3
->length
)
322 ff_rewind_count
= wps_state
.id3
->length
-
323 wps_state
.id3
->elapsed
;
326 if ((int)(wps_state
.id3
->elapsed
+ ff_rewind_count
) < 0)
327 ff_rewind_count
= -wps_state
.id3
->elapsed
;
330 /* set the wps state ff_rewind_count so the progess info
332 wps_state
.ff_rewind_count
= (wps_state
.wps_time_countup
== false)?
333 ff_rewind_count
:-ff_rewind_count
;
336 skin_update(&gui_wps
[i
],
337 WPS_REFRESH_PLAYER_PROGRESS
|
338 WPS_REFRESH_DYNAMIC
);
343 case ACTION_WPS_STOPSEEK
:
344 wps_state
.id3
->elapsed
= wps_state
.id3
->elapsed
+ff_rewind_count
;
345 audio_ff_rewind(wps_state
.id3
->elapsed
);
346 wps_state
.ff_rewind_count
= 0;
347 wps_state
.ff_rewind
= false;
348 status_set_ffmode(0);
349 #if (CONFIG_CODEC != SWCODEC)
350 if (!wps_state
.paused
)
353 #ifdef HAVE_LCD_CHARCELLS
355 skin_update(&gui_wps
[i
], WPS_REFRESH_ALL
);
361 if(default_event_handler(button
) == SYS_USB_CONNECTED
) {
362 status_set_ffmode(0);
370 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_BLOCK
);
371 #ifdef HAVE_TOUCHSCREEN
372 if (button
== ACTION_TOUCHSCREEN
)
373 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
381 void display_keylock_text(bool locked
)
385 gui_wps
[i
].display
->stop_scroll();
387 splash(HZ
, locked
? ID2P(LANG_KEYLOCK_ON
) : ID2P(LANG_KEYLOCK_OFF
));
393 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
394 static void gwps_caption_backlight(struct wps_state
*state
)
396 if (state
&& state
->id3
)
398 #ifdef HAVE_BACKLIGHT
399 if (global_settings
.caption_backlight
)
401 /* turn on backlight n seconds before track ends, and turn it off n
402 seconds into the new track. n == backlight_timeout, or 5s */
403 int n
= global_settings
.backlight_timeout
* 1000;
406 n
= 5000; /* use 5s if backlight is always on or off */
408 if (((state
->id3
->elapsed
< 1000) ||
409 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
410 (state
->paused
== false))
414 #ifdef HAVE_REMOTE_LCD
415 if (global_settings
.remote_caption_backlight
)
417 /* turn on remote backlight n seconds before track ends, and turn it
418 off n seconds into the new track. n == remote_backlight_timeout,
420 int n
= global_settings
.remote_backlight_timeout
* 1000;
423 n
= 5000; /* use 5s if backlight is always on or off */
425 if (((state
->id3
->elapsed
< 1000) ||
426 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
427 (state
->paused
== false))
428 remote_backlight_on();
436 static void change_dir(int direction
)
438 if (global_settings
.prevent_skip
)
443 else if (direction
> 0)
445 /* prevent the next dir to immediatly start being ffw'd */
446 action_wait_for_release();
449 static void prev_track(unsigned long skip_thresh
)
451 if (wps_state
.id3
->elapsed
< skip_thresh
)
458 if (wps_state
.id3
->cuesheet
)
460 curr_cuesheet_skip(wps_state
.id3
->cuesheet
, -1, wps_state
.id3
->elapsed
);
464 if (!wps_state
.paused
)
465 #if (CONFIG_CODEC == SWCODEC)
466 audio_pre_ff_rewind();
473 #if (CONFIG_CODEC != SWCODEC)
474 if (!wps_state
.paused
)
480 static void next_track(void)
482 /* take care of if we're playing a cuesheet */
483 if (wps_state
.id3
->cuesheet
)
485 if (curr_cuesheet_skip(wps_state
.id3
->cuesheet
, 1, wps_state
.id3
->elapsed
))
487 /* if the result was false, then we really want
488 to skip to the next track */
496 static void play_hop(int direction
)
498 unsigned long step
= ((unsigned long)global_settings
.skip_length
)*1000;
499 unsigned long elapsed
= wps_state
.id3
->elapsed
;
500 unsigned long remaining
= wps_state
.id3
->length
- elapsed
;
502 if (!global_settings
.prevent_skip
&&
504 (direction
> 0 && step
>= remaining
) ||
505 (direction
< 0 && elapsed
< DEFAULT_SKIP_TRESH
)))
506 { /* Do normal track skipping */
509 else if (direction
< 0)
510 prev_track(DEFAULT_SKIP_TRESH
);
514 if (direction
== 1 && step
>= remaining
)
516 #if CONFIG_CODEC == SWCODEC
517 if(global_settings
.beep
)
518 pcmbuf_beep(1000, 150, 1500*global_settings
.beep
);
522 else if ((direction
== -1 && elapsed
< step
))
528 elapsed
+= step
* direction
;
530 if((audio_status() & AUDIO_STATUS_PLAY
) && !wps_state
.paused
)
532 #if (CONFIG_CODEC == SWCODEC)
533 audio_pre_ff_rewind();
538 audio_ff_rewind(wps_state
.id3
->elapsed
= elapsed
);
539 #if (CONFIG_CODEC != SWCODEC)
540 if (!wps_state
.paused
)
546 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
548 * If the user is unable to see the wps, because the display is deactivated,
549 * we suppress updates until the wps is activated again (the lcd driver will
550 * call this hook to issue an instant update)
552 static void wps_lcd_activation_hook(void)
554 wps_state
.do_full_update
= true;
555 /* force timeout in wps main loop, so that the update is instantly */
556 queue_post(&button_queue
, BUTTON_NONE
, 0);
560 static void gwps_leave_wps(void)
562 int i
, oldbars
= VP_SB_HIDE_ALL
;
566 gui_wps
[i
].display
->stop_scroll();
567 gui_wps
[i
].display
->backdrop_show(BACKDROP_MAIN
);
568 if (statusbar_position(i
) != STATUSBAR_OFF
)
569 oldbars
|= VP_SB_ONSCREEN(i
);
572 viewportmanager_set_statusbar(oldbars
);
573 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
574 /* Play safe and unregister the hook */
575 lcd_activation_set_hook(NULL
);
577 send_event(GUI_EVENT_REFRESH
, NULL
);
580 #ifdef HAVE_TOUCHSCREEN
581 int wps_get_touchaction(struct wps_data
*data
)
585 int type
= action_get_touchscreen_press(&x
, &y
);
586 static int last_action
= ACTION_NONE
;
587 struct touchregion
*r
;
588 bool repeated
= (type
== BUTTON_REPEAT
);
589 bool released
= (type
== BUTTON_REL
);
590 struct skin_token_list
*regions
= data
->touchregions
;
593 r
= (struct touchregion
*)regions
->token
->value
.data
;
594 /* make sure this region's viewport is visible */
595 if (r
->wvp
->hidden_flags
&VP_DRAW_HIDDEN
)
597 regions
= regions
->next
;
600 /* check if it's inside this viewport */
601 if (viewport_point_within_vp(&(r
->wvp
->vp
), x
, y
))
602 { /* reposition the touch inside the viewport since touchregions
603 * are relative to a preceding viewport */
604 vx
= x
- r
->wvp
->vp
.x
;
605 vy
= y
- r
->wvp
->vp
.y
;
606 /* now see if the point is inside this region */
607 if (vx
>= r
->x
&& vx
< r
->x
+r
->width
&&
608 vy
>= r
->y
&& vy
< r
->y
+r
->height
)
610 /* reposition the touch within the area */
616 case WPS_TOUCHREGION_ACTION
:
617 if ((repeated
&& r
->repeat
) || (released
&& !r
->repeat
))
619 last_action
= r
->action
;
623 case WPS_TOUCHREGION_SCROLLBAR
:
624 if(r
->width
> r
->height
)
626 wps_state
.id3
->elapsed
= (vx
*
627 wps_state
.id3
->length
) / r
->width
;
630 wps_state
.id3
->elapsed
= (vy
*
631 wps_state
.id3
->length
) / r
->height
;
633 if (!wps_state
.paused
)
634 #if (CONFIG_CODEC == SWCODEC)
635 audio_pre_ff_rewind();
639 audio_ff_rewind(wps_state
.id3
->elapsed
);
640 #if (CONFIG_CODEC != SWCODEC)
641 if (!wps_state
.paused
)
645 case WPS_TOUCHREGION_VOLUME
:
648 const int min_vol
= sound_min(SOUND_VOLUME
);
649 const int max_vol
= sound_max(SOUND_VOLUME
);
650 if(r
->width
> r
->height
)
652 global_settings
.volume
= (vx
*
653 (max_vol
- min_vol
)) / r
->width
;
656 global_settings
.volume
= (vy
*
657 (max_vol
-min_vol
)) / r
->height
;
659 global_settings
.volume
+= min_vol
;
663 gui_wps
[i
].data
->button_time_volume
= current_tick
;
665 return ACTION_REDRAW
;
670 regions
= regions
->next
;
673 if ((last_action
== ACTION_WPS_SEEKBACK
|| last_action
== ACTION_WPS_SEEKFWD
))
674 return ACTION_WPS_STOPSEEK
;
675 last_action
= ACTION_TOUCHSCREEN
;
676 return ACTION_TOUCHSCREEN
;
679 /* The WPS can be left in two ways:
680 * a) call a function, which draws over the wps. In this case, the wps
681 * will be still active (i.e. the below function didn't return)
682 * b) return with a value evaluated by root_menu.c, in this case the wps
683 * is really left, and root_menu will handle the next screen
685 * In either way, call gwps_leave_wps(), in order to restore the correct
686 * "main screen" backdrops and statusbars
688 long gui_wps_show(void)
692 long restoretimer
= RESTORE_WPS_INSTANTLY
; /* timer to delay screen redraw temporarily */
694 bool bookmark
= false;
697 long last_left
= 0, last_right
= 0;
699 #ifdef HAVE_LCD_CHARCELLS
700 status_set_audio(true);
701 status_set_param(false);
703 statusbar_toggle_handler(NULL
);
706 #ifdef AB_REPEAT_ENABLE
714 bool audio_paused
= (audio_status() & AUDIO_STATUS_PAUSE
)?true:false;
716 /* did someone else (i.e power thread) change audio pause mode? */
717 if (wps_state
.paused
!= audio_paused
) {
718 wps_state
.paused
= audio_paused
;
720 /* if another thread paused audio, we are probably in car mode,
721 about to shut down. lets save the settings. */
722 if (wps_state
.paused
) {
724 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
725 call_storage_idle_notifys(true);
730 #ifdef HAVE_LCD_BITMAP
731 /* when the peak meter is enabled we want to have a
732 few extra updates to make it look smooth. On the
733 other hand we don't want to waste energy if it
738 if(gui_wps
[i
].data
->peak_meter_enabled
)
743 long next_refresh
= current_tick
;
744 long next_big_refresh
= current_tick
+ HZ
/ 5;
745 button
= BUTTON_NONE
;
746 while (TIME_BEFORE(current_tick
, next_big_refresh
)) {
747 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_NOBLOCK
);
748 if (button
!= ACTION_NONE
) {
752 sleep(0); /* Sleep until end of current tick. */
754 if (TIME_AFTER(current_tick
, next_refresh
)) {
757 if(gui_wps
[i
].data
->peak_meter_enabled
)
758 skin_update(&gui_wps
[i
], WPS_REFRESH_PEAK_METER
);
759 next_refresh
+= HZ
/ PEAK_METER_FPS
;
766 /* The peak meter is disabled
767 -> no additional screen updates needed */
771 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,
772 restore
? HZ
/100 : HZ
/5);
775 /* Exit if audio has stopped playing. This happens e.g. at end of
776 playlist or if using the sleep timer. */
777 if (!(audio_status() & AUDIO_STATUS_PLAY
))
779 #ifdef HAVE_TOUCHSCREEN
780 if (button
== ACTION_TOUCHSCREEN
)
781 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
783 /* The iPods/X5/M5 use a single button for the A-B mode markers,
784 defined as ACTION_WPSAB_SINGLE in their config files. */
785 #ifdef ACTION_WPSAB_SINGLE
786 if (!global_settings
.party_mode
&& ab_repeat_mode_enabled())
788 static int wps_ab_state
= 0;
789 if (button
== ACTION_WPSAB_SINGLE
)
791 switch (wps_ab_state
)
793 case 0: /* set the A spot */
794 button
= ACTION_WPS_ABSETA_PREVDIR
;
796 case 1: /* set the B spot */
797 button
= ACTION_WPS_ABSETB_NEXTDIR
;
800 button
= ACTION_WPS_ABRESET
;
803 wps_ab_state
= (wps_ab_state
+1) % 3;
809 case ACTION_WPS_CONTEXT
:
812 /* if music is stopped in the context menu we want to exit the wps */
813 if (onplay(wps_state
.id3
->path
,
814 FILE_ATTR_AUDIO
, CONTEXT_WPS
) == ONPLAY_MAINMENU
821 case ACTION_WPS_BROWSE
:
822 #ifdef HAVE_LCD_CHARCELLS
823 status_set_record(false);
824 status_set_audio(false);
827 return GO_TO_PREVIOUS_BROWSER
;
831 case ACTION_WPS_PLAY
:
832 if (global_settings
.party_mode
)
834 if ( wps_state
.paused
)
836 wps_state
.paused
= false;
837 if ( global_settings
.fade_on_stop
)
844 wps_state
.paused
= true;
845 if ( global_settings
.fade_on_stop
)
850 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
851 call_storage_idle_notifys(true); /* make sure resume info is saved */
856 case ACTION_WPS_VOLUP
:
859 gui_wps
[i
].data
->button_time_volume
= current_tick
;
860 global_settings
.volume
++;
865 if(update_onvol_change(&gui_wps
[i
]))
870 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
874 case ACTION_WPS_VOLDOWN
:
877 gui_wps
[i
].data
->button_time_volume
= current_tick
;
878 global_settings
.volume
--;
883 if(update_onvol_change(&gui_wps
[i
]))
888 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
893 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
894 case ACTION_WPS_SEEKFWD
:
895 if (global_settings
.party_mode
)
897 if (current_tick
-last_right
< HZ
)
899 if (wps_state
.id3
->cuesheet
)
909 ffwd_rew(ACTION_WPS_SEEKFWD
);
910 last_right
= last_left
= 0;
913 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
914 case ACTION_WPS_SEEKBACK
:
915 if (global_settings
.party_mode
)
917 if (current_tick
-last_left
< HZ
)
919 if (wps_state
.id3
->cuesheet
)
921 if (!wps_state
.paused
)
922 #if (CONFIG_CODEC == SWCODEC)
923 audio_pre_ff_rewind();
935 ffwd_rew(ACTION_WPS_SEEKBACK
);
936 last_left
= last_right
= 0;
940 case ACTION_WPS_SKIPPREV
:
941 if (global_settings
.party_mode
)
943 last_left
= current_tick
;
944 #ifdef AB_REPEAT_ENABLE
945 /* if we're in A/B repeat mode and the current position
946 is past the A marker, jump back to the A marker... */
947 if ( ab_repeat_mode_enabled() )
949 if ( ab_after_A_marker(wps_state
.id3
->elapsed
) )
951 ab_jump_to_A_marker();
953 #if (AB_REPEAT_ENABLE == 2)
960 /* ...otherwise, do it normally */
966 OR if skip length set, hop by predetermined amount. */
967 case ACTION_WPS_SKIPNEXT
:
968 if (global_settings
.party_mode
)
970 last_right
= current_tick
;
971 #ifdef AB_REPEAT_ENABLE
972 /* if we're in A/B repeat mode and the current position is
973 before the A marker, jump to the A marker... */
974 if ( ab_repeat_mode_enabled() )
976 if ( ab_before_A_marker(wps_state
.id3
->elapsed
) )
978 ab_jump_to_A_marker();
980 #if (AB_REPEAT_ENABLE == 2)
987 /* ...otherwise, do it normally */
991 /* next / prev directories */
992 /* and set A-B markers if in a-b mode */
993 case ACTION_WPS_ABSETB_NEXTDIR
:
994 if (global_settings
.party_mode
)
996 #if defined(AB_REPEAT_ENABLE)
997 if (ab_repeat_mode_enabled())
999 ab_set_B_marker(wps_state
.id3
->elapsed
);
1000 ab_jump_to_A_marker();
1008 case ACTION_WPS_ABSETA_PREVDIR
:
1009 if (global_settings
.party_mode
)
1011 #if defined(AB_REPEAT_ENABLE)
1012 if (ab_repeat_mode_enabled())
1013 ab_set_A_marker(wps_state
.id3
->elapsed
);
1020 /* menu key functions */
1021 case ACTION_WPS_MENU
:
1027 #ifdef HAVE_QUICKSCREEN
1028 case ACTION_WPS_QUICKSCREEN
:
1031 if (quick_screen_quick(button
))
1036 #endif /* HAVE_QUICKSCREEN */
1038 /* screen settings */
1043 if (quick_screen_f3(BUTTON_F3
))
1048 #endif /* BUTTON_F3 */
1051 #ifdef HAVE_PITCHSCREEN
1052 case ACTION_WPS_PITCHSCREEN
:
1055 if (1 == gui_syncpitchscreen_run())
1060 #endif /* HAVE_PITCHSCREEN */
1062 #ifdef AB_REPEAT_ENABLE
1063 /* reset A&B markers */
1064 case ACTION_WPS_ABRESET
:
1065 if (ab_repeat_mode_enabled())
1071 #endif /* AB_REPEAT_ENABLE */
1073 /* stop and exit wps */
1074 case ACTION_WPS_STOP
:
1075 if (global_settings
.party_mode
)
1081 case ACTION_WPS_ID3SCREEN
:
1089 #ifdef HAVE_TOUCHSCREEN
1090 case ACTION_TOUCH_SHUFFLE
: /* toggle shuffle mode */
1092 global_settings
.playlist_shuffle
=
1093 !global_settings
.playlist_shuffle
;
1094 #if CONFIG_CODEC == SWCODEC
1095 dsp_set_replaygain();
1097 if (global_settings
.playlist_shuffle
)
1098 playlist_randomise(NULL
, current_tick
, true);
1100 playlist_sort(NULL
, true);
1103 case ACTION_TOUCH_REPMODE
: /* cycle the repeat mode setting */
1105 const struct settings_list
*rep_setting
=
1106 find_setting(&global_settings
.repeat_mode
, NULL
);
1107 option_select_next_val(rep_setting
, false, true);
1108 audio_flush_and_reload_tracks();
1111 #endif /* HAVE_TOUCHSCREEN */
1112 /* this case is used by the softlock feature
1113 * it requests a full update here */
1115 wps_state
.do_full_update
= true;
1117 case ACTION_NONE
: /* Timeout, do a partial update */
1119 ffwd_rew(button
); /* hopefully fix the ffw/rwd bug */
1121 #ifdef HAVE_RECORDING
1122 case ACTION_WPS_REC
:
1127 default_event_handler(SYS_POWEROFF
);
1129 case ACTION_WPS_VIEW_PLAYLIST
:
1131 if (playlist_viewer()) /* true if USB connected */
1136 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1145 if (wps_state
.do_full_update
|| update
)
1147 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
1148 gwps_caption_backlight(&wps_state
);
1152 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1154 #ifdef HAVE_REMOTE_LCD
1155 /* currently, all remotes are readable without backlight
1156 * so still update those */
1157 || (i
== SCREEN_REMOTE
)
1162 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
1165 wps_state
.do_full_update
= false;
1169 if (restore
&& wps_state
.id3
&&
1170 ((restoretimer
== RESTORE_WPS_INSTANTLY
) ||
1171 TIME_AFTER(current_tick
, restoretimer
)))
1174 restoretimer
= RESTORE_WPS_INSTANTLY
;
1175 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1176 lcd_activation_set_hook(wps_lcd_activation_hook
);
1180 screens
[i
].stop_scroll();
1181 gui_wps_display(&gui_wps
[i
]);
1186 #ifdef HAVE_LCD_CHARCELLS
1187 status_set_record(false);
1188 status_set_audio(false);
1190 if (global_settings
.fade_on_stop
)
1194 bookmark_autobookmark();
1196 #ifdef AB_REPEAT_ENABLE
1200 #ifdef HAVE_RECORDING
1201 if (button
== ACTION_WPS_REC
)
1202 return GO_TO_RECSCREEN
;
1204 if (global_settings
.browse_current
)
1205 return GO_TO_PREVIOUS_BROWSER
;
1206 return GO_TO_PREVIOUS
;
1209 if (button
&& !IS_SYSEVENT(button
) )
1212 return GO_TO_ROOT
; /* unreachable - just to reduce compiler warnings */
1215 /* this is called from the playback thread so NO DRAWING! */
1216 static void track_changed_callback(void *param
)
1218 wps_state
.id3
= (struct mp3entry
*)param
;
1219 wps_state
.nid3
= audio_next_track();
1220 if (wps_state
.id3
->cuesheet
)
1222 cue_find_current_track(wps_state
.id3
->cuesheet
, wps_state
.id3
->elapsed
);
1223 cue_spoof_id3(wps_state
.id3
->cuesheet
, wps_state
.id3
);
1225 wps_state
.do_full_update
= true;
1227 static void nextid3available_callback(void* param
)
1230 wps_state
.nid3
= audio_next_track();
1231 wps_state
.do_full_update
= true;
1235 static void wps_state_init(void)
1237 wps_state
.ff_rewind
= false;
1238 wps_state
.paused
= false;
1239 if(audio_status() & AUDIO_STATUS_PLAY
)
1241 wps_state
.id3
= audio_current_track();
1242 wps_state
.nid3
= audio_next_track();
1246 wps_state
.id3
= NULL
;
1247 wps_state
.nid3
= NULL
;
1249 /* We'll be updating due to restore initialized with true */
1250 wps_state
.do_full_update
= false;
1251 /* add the WPS track event callbacks */
1252 add_event(PLAYBACK_EVENT_TRACK_CHANGE
, false, track_changed_callback
);
1253 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, false, nextid3available_callback
);
1257 #ifdef HAVE_LCD_BITMAP
1258 static void statusbar_toggle_handler(void *data
)
1263 wpsbars
= VP_SB_HIDE_ALL
;
1265 { /* fix viewports if needed */
1266 skin_statusbar_changed(&gui_wps
[i
]);
1270 /* fix up gui_wps::statusbars, so that the viewportmanager accepts it*/
1271 if (gui_wps
[i
].data
->wps_sb_tag
)
1272 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
1273 else if (statusbar_position(i
) != STATUSBAR_OFF
)
1277 (VP_SB_ONSCREEN(i
) | VP_SB_IGNORE_SETTING(i
));
1283 void gui_sync_wps_init(void)
1288 #ifdef HAVE_ALBUMART
1289 wps_datas
[i
].albumart
= NULL
;
1290 wps_datas
[i
].playback_aa_slot
= -1;
1292 #ifdef HAVE_REMOTE_LCD
1293 wps_datas
[i
].remote_wps
= (i
== SCREEN_REMOTE
);
1295 wps_datas
[i
].debug
= false;
1296 gui_wps
[i
].data
= &wps_datas
[i
];
1297 gui_wps
[i
].display
= &screens
[i
];
1298 /* Currently no seperate wps_state needed/possible
1299 so use the only available ( "global" ) one */
1300 gui_wps
[i
].state
= &wps_state
;
1301 gui_wps
[i
].display
->backdrop_unload(BACKDROP_SKIN_WPS
);
1302 /* only one wpsbars needed/wanted */
1303 gui_wps
[i
].statusbars
= &wpsbars
;
1305 *(gui_wps
[SCREEN_MAIN
].statusbars
) =VP_SB_ALLSCREENS
;
1306 #ifdef HAVE_LCD_BITMAP
1307 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false, statusbar_toggle_handler
);
1312 #ifdef IPOD_ACCESSORY_PROTOCOL
1313 int wps_get_ff_rewind_count(void)
1315 return wps_state
.ff_rewind_count
;