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 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 /* 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 if (!loaded_ok
) /* load the hardcoded default */
136 char *skin_buf
[NB_SCREENS
] = {
137 #ifdef HAVE_LCD_BITMAP
138 "%s%?it<%?in<%in. |>%it|%fn>\n"
139 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
140 "%s%?id<%id|%?d1<%d1|(root)>> %?iy<(%iy)|>\n\n"
141 "%al%pc/%pt%ar[%pp:%pe]\n"
142 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
145 "%s%pp/%pe: %?it<%it|%fn> - %?ia<%ia|%d2> - %?id<%id|%d1>\n"
148 #ifdef HAVE_REMOTE_LCD
149 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
150 "%s%?it<%?in<%in. |>%it|%fn>\n"
151 "%al%pc/%pt%ar[%pp:%pe]\n"
152 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
156 skin_data_load(gui_wps
[screen
].data
, &screens
[screen
],
157 skin_buf
[screen
], false);
159 #ifdef HAVE_REMOVE_LCD
160 gui_wps
[screen
].data
->remote_wps
= !(screen
== SCREEN_MAIN
);
164 static bool wps_fading_out
= false;
165 void fade(bool fade_in
, bool updatewps
)
167 int fp_global_vol
= global_settings
.volume
<< 8;
168 int fp_min_vol
= sound_min(SOUND_VOLUME
) << 8;
169 int fp_step
= (fp_global_vol
- fp_min_vol
) / 30;
171 wps_fading_out
= !fade_in
;
174 int fp_volume
= fp_min_vol
;
176 /* zero out the sound */
177 sound_set_volume(fp_min_vol
>> 8);
179 sleep(HZ
/10); /* let audio thread run */
182 while (fp_volume
< fp_global_vol
- fp_step
) {
183 fp_volume
+= fp_step
;
184 sound_set_volume(fp_volume
>> 8);
188 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
192 sound_set_volume(global_settings
.volume
);
196 int fp_volume
= fp_global_vol
;
198 while (fp_volume
> fp_min_vol
+ fp_step
) {
199 fp_volume
-= fp_step
;
200 sound_set_volume(fp_volume
>> 8);
204 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
209 wps_fading_out
= false;
210 #if CONFIG_CODEC != SWCODEC
212 /* let audio thread run and wait for the mas to run out of data */
213 while (!mp3_pause_done())
218 /* reset volume to what it was before the fade */
219 sound_set_volume(global_settings
.volume
);
222 bool is_wps_fading(void)
224 return wps_fading_out
;
227 static bool update_onvol_change(struct gui_wps
* gwps
)
229 skin_update(gwps
, WPS_REFRESH_NON_STATIC
);
231 #ifdef HAVE_LCD_CHARCELLS
232 splashf(0, "Vol: %3d dB",
233 sound_val2phys(SOUND_VOLUME
, global_settings
.volume
));
240 bool ffwd_rew(int button
)
242 unsigned int step
= 0; /* current ff/rewind step */
243 unsigned int max_step
= 0; /* maximum ff/rewind step */
244 int ff_rewind_count
= 0; /* current ff/rewind count (in ticks) */
245 int direction
= -1; /* forward=1 or backward=-1 */
249 const long ff_rw_accel
= (global_settings
.ff_rewind_accel
+ 3);
251 if (button
== ACTION_NONE
)
253 status_set_ffmode(0);
260 case ACTION_WPS_SEEKFWD
:
262 case ACTION_WPS_SEEKBACK
:
263 if (wps_state
.ff_rewind
)
267 /* fast forwarding, calc max step relative to end */
268 max_step
= (wps_state
.id3
->length
-
269 (wps_state
.id3
->elapsed
+
271 FF_REWIND_MAX_PERCENT
/ 100;
275 /* rewinding, calc max step relative to start */
276 max_step
= (wps_state
.id3
->elapsed
+ ff_rewind_count
) *
277 FF_REWIND_MAX_PERCENT
/ 100;
280 max_step
= MAX(max_step
, MIN_FF_REWIND_STEP
);
285 ff_rewind_count
+= step
* direction
;
287 /* smooth seeking by multiplying step by: 1 + (2 ^ -accel) */
288 step
+= step
>> ff_rw_accel
;
292 if ( (audio_status() & AUDIO_STATUS_PLAY
) &&
293 wps_state
.id3
&& wps_state
.id3
->length
)
295 if (!wps_state
.paused
)
296 #if (CONFIG_CODEC == SWCODEC)
297 audio_pre_ff_rewind();
301 #if CONFIG_KEYPAD == PLAYER_PAD
303 gui_wps
[i
].display
->stop_scroll();
306 status_set_ffmode(STATUS_FASTFORWARD
);
308 status_set_ffmode(STATUS_FASTBACKWARD
);
310 wps_state
.ff_rewind
= true;
312 step
= 1000 * global_settings
.ff_rewind_min_step
;
319 if ((wps_state
.id3
->elapsed
+ ff_rewind_count
) >
320 wps_state
.id3
->length
)
321 ff_rewind_count
= wps_state
.id3
->length
-
322 wps_state
.id3
->elapsed
;
325 if ((int)(wps_state
.id3
->elapsed
+ ff_rewind_count
) < 0)
326 ff_rewind_count
= -wps_state
.id3
->elapsed
;
329 /* set the wps state ff_rewind_count so the progess info
331 wps_state
.ff_rewind_count
= (wps_state
.wps_time_countup
== false)?
332 ff_rewind_count
:-ff_rewind_count
;
335 skin_update(&gui_wps
[i
],
336 WPS_REFRESH_PLAYER_PROGRESS
|
337 WPS_REFRESH_DYNAMIC
);
342 case ACTION_WPS_STOPSEEK
:
343 wps_state
.id3
->elapsed
= wps_state
.id3
->elapsed
+ff_rewind_count
;
344 audio_ff_rewind(wps_state
.id3
->elapsed
);
345 wps_state
.ff_rewind_count
= 0;
346 wps_state
.ff_rewind
= false;
347 status_set_ffmode(0);
348 #if (CONFIG_CODEC != SWCODEC)
349 if (!wps_state
.paused
)
352 #ifdef HAVE_LCD_CHARCELLS
354 skin_update(&gui_wps
[i
], WPS_REFRESH_ALL
);
360 if(default_event_handler(button
) == SYS_USB_CONNECTED
) {
361 status_set_ffmode(0);
369 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_BLOCK
);
370 #ifdef HAVE_TOUCHSCREEN
371 if (button
== ACTION_TOUCHSCREEN
)
372 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
380 void display_keylock_text(bool locked
)
384 gui_wps
[i
].display
->stop_scroll();
386 splash(HZ
, locked
? ID2P(LANG_KEYLOCK_ON
) : ID2P(LANG_KEYLOCK_OFF
));
392 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
393 static void gwps_caption_backlight(struct wps_state
*state
)
395 if (state
&& state
->id3
)
397 #ifdef HAVE_BACKLIGHT
398 if (global_settings
.caption_backlight
)
400 /* turn on backlight n seconds before track ends, and turn it off n
401 seconds into the new track. n == backlight_timeout, or 5s */
402 int n
= global_settings
.backlight_timeout
* 1000;
405 n
= 5000; /* use 5s if backlight is always on or off */
407 if (((state
->id3
->elapsed
< 1000) ||
408 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
409 (state
->paused
== false))
413 #ifdef HAVE_REMOTE_LCD
414 if (global_settings
.remote_caption_backlight
)
416 /* turn on remote backlight n seconds before track ends, and turn it
417 off n seconds into the new track. n == remote_backlight_timeout,
419 int n
= global_settings
.remote_backlight_timeout
* 1000;
422 n
= 5000; /* use 5s if backlight is always on or off */
424 if (((state
->id3
->elapsed
< 1000) ||
425 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
426 (state
->paused
== false))
427 remote_backlight_on();
435 static void change_dir(int direction
)
437 if (global_settings
.prevent_skip
)
442 else if (direction
> 0)
444 /* prevent the next dir to immediatly start being ffw'd */
445 action_wait_for_release();
448 static void prev_track(unsigned long skip_thresh
)
450 if (wps_state
.id3
->elapsed
< skip_thresh
)
457 if (wps_state
.id3
->cuesheet
)
459 curr_cuesheet_skip(wps_state
.id3
->cuesheet
, -1, wps_state
.id3
->elapsed
);
463 if (!wps_state
.paused
)
464 #if (CONFIG_CODEC == SWCODEC)
465 audio_pre_ff_rewind();
472 #if (CONFIG_CODEC != SWCODEC)
473 if (!wps_state
.paused
)
479 static void next_track(void)
481 /* take care of if we're playing a cuesheet */
482 if (wps_state
.id3
->cuesheet
)
484 if (curr_cuesheet_skip(wps_state
.id3
->cuesheet
, 1, wps_state
.id3
->elapsed
))
486 /* if the result was false, then we really want
487 to skip to the next track */
495 static void play_hop(int direction
)
497 long step
= global_settings
.skip_length
*1000;
498 long elapsed
= wps_state
.id3
->elapsed
;
499 long remaining
= wps_state
.id3
->length
- elapsed
;
505 prev_track(DEFAULT_SKIP_TRESH
);
508 else if (remaining
< DEFAULT_SKIP_TRESH
*2)
514 elapsed
+= (remaining
- DEFAULT_SKIP_TRESH
*2);
516 else if (!global_settings
.prevent_skip
&&
518 (direction
> 0 && step
>= remaining
) ||
519 (direction
< 0 && elapsed
< DEFAULT_SKIP_TRESH
)))
520 { /* Do normal track skipping */
523 else if (direction
< 0)
524 prev_track(DEFAULT_SKIP_TRESH
);
527 else if (direction
== 1 && step
>= remaining
)
529 #if CONFIG_CODEC == SWCODEC
530 if(global_settings
.beep
)
531 pcmbuf_beep(1000, 150, 1500*global_settings
.beep
);
535 else if ((direction
== -1 && elapsed
< step
))
541 elapsed
+= step
* direction
;
543 if((audio_status() & AUDIO_STATUS_PLAY
) && !wps_state
.paused
)
545 #if (CONFIG_CODEC == SWCODEC)
546 audio_pre_ff_rewind();
551 audio_ff_rewind(wps_state
.id3
->elapsed
= elapsed
);
552 #if (CONFIG_CODEC != SWCODEC)
553 if (!wps_state
.paused
)
559 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
561 * If the user is unable to see the wps, because the display is deactivated,
562 * we suppress updates until the wps is activated again (the lcd driver will
563 * call this hook to issue an instant update)
565 static void wps_lcd_activation_hook(void)
567 wps_state
.do_full_update
= true;
568 /* force timeout in wps main loop, so that the update is instantly */
569 queue_post(&button_queue
, BUTTON_NONE
, 0);
573 static void gwps_leave_wps(void)
575 int i
, oldbars
= VP_SB_HIDE_ALL
;
579 gui_wps
[i
].display
->stop_scroll();
580 gui_wps
[i
].display
->backdrop_show(BACKDROP_MAIN
);
581 if (statusbar_position(i
) != STATUSBAR_OFF
)
582 oldbars
|= VP_SB_ONSCREEN(i
);
585 viewportmanager_set_statusbar(oldbars
);
586 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
587 /* Play safe and unregister the hook */
588 lcd_activation_set_hook(NULL
);
590 send_event(GUI_EVENT_REFRESH
, NULL
);
593 #ifdef HAVE_TOUCHSCREEN
594 int wps_get_touchaction(struct wps_data
*data
)
598 int type
= action_get_touchscreen_press(&x
, &y
);
599 static int last_action
= ACTION_NONE
;
600 struct touchregion
*r
;
601 bool repeated
= (type
== BUTTON_REPEAT
);
602 bool released
= (type
== BUTTON_REL
);
603 struct skin_token_list
*regions
= data
->touchregions
;
606 r
= (struct touchregion
*)regions
->token
->value
.data
;
607 /* make sure this region's viewport is visible */
608 if (r
->wvp
->hidden_flags
&VP_DRAW_HIDDEN
)
610 regions
= regions
->next
;
613 /* check if it's inside this viewport */
614 if (viewport_point_within_vp(&(r
->wvp
->vp
), x
, y
))
615 { /* reposition the touch inside the viewport since touchregions
616 * are relative to a preceding viewport */
617 vx
= x
- r
->wvp
->vp
.x
;
618 vy
= y
- r
->wvp
->vp
.y
;
619 /* now see if the point is inside this region */
620 if (vx
>= r
->x
&& vx
< r
->x
+r
->width
&&
621 vy
>= r
->y
&& vy
< r
->y
+r
->height
)
623 /* reposition the touch within the area */
629 case WPS_TOUCHREGION_ACTION
:
630 if ((repeated
&& r
->repeat
) || (released
&& !r
->repeat
))
632 last_action
= r
->action
;
636 case WPS_TOUCHREGION_SCROLLBAR
:
637 if(r
->width
> r
->height
)
639 wps_state
.id3
->elapsed
= (vx
*
640 wps_state
.id3
->length
) / r
->width
;
643 wps_state
.id3
->elapsed
= (vy
*
644 wps_state
.id3
->length
) / r
->height
;
646 if (!wps_state
.paused
)
647 #if (CONFIG_CODEC == SWCODEC)
648 audio_pre_ff_rewind();
652 audio_ff_rewind(wps_state
.id3
->elapsed
);
653 #if (CONFIG_CODEC != SWCODEC)
654 if (!wps_state
.paused
)
658 case WPS_TOUCHREGION_VOLUME
:
661 const int min_vol
= sound_min(SOUND_VOLUME
);
662 const int max_vol
= sound_max(SOUND_VOLUME
);
663 if(r
->width
> r
->height
)
665 global_settings
.volume
= (vx
*
666 (max_vol
- min_vol
)) / r
->width
;
669 global_settings
.volume
= (vy
*
670 (max_vol
-min_vol
)) / r
->height
;
672 global_settings
.volume
+= min_vol
;
676 gui_wps
[i
].data
->button_time_volume
= current_tick
;
678 return ACTION_REDRAW
;
683 regions
= regions
->next
;
686 if ((last_action
== ACTION_WPS_SEEKBACK
|| last_action
== ACTION_WPS_SEEKFWD
))
687 return ACTION_WPS_STOPSEEK
;
688 last_action
= ACTION_TOUCHSCREEN
;
689 return ACTION_TOUCHSCREEN
;
692 /* The WPS can be left in two ways:
693 * a) call a function, which draws over the wps. In this case, the wps
694 * will be still active (i.e. the below function didn't return)
695 * b) return with a value evaluated by root_menu.c, in this case the wps
696 * is really left, and root_menu will handle the next screen
698 * In either way, call gwps_leave_wps(), in order to restore the correct
699 * "main screen" backdrops and statusbars
701 long gui_wps_show(void)
705 long restoretimer
= RESTORE_WPS_INSTANTLY
; /* timer to delay screen redraw temporarily */
707 bool bookmark
= false;
710 long last_left
= 0, last_right
= 0;
712 #ifdef HAVE_LCD_CHARCELLS
713 status_set_audio(true);
714 status_set_param(false);
716 statusbar_toggle_handler(NULL
);
719 #ifdef AB_REPEAT_ENABLE
727 bool audio_paused
= (audio_status() & AUDIO_STATUS_PAUSE
)?true:false;
729 /* did someone else (i.e power thread) change audio pause mode? */
730 if (wps_state
.paused
!= audio_paused
) {
731 wps_state
.paused
= audio_paused
;
733 /* if another thread paused audio, we are probably in car mode,
734 about to shut down. lets save the settings. */
735 if (wps_state
.paused
) {
737 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
738 call_storage_idle_notifys(true);
743 #ifdef HAVE_LCD_BITMAP
744 /* when the peak meter is enabled we want to have a
745 few extra updates to make it look smooth. On the
746 other hand we don't want to waste energy if it
751 if(gui_wps
[i
].data
->peak_meter_enabled
)
756 long next_refresh
= current_tick
;
757 long next_big_refresh
= current_tick
+ HZ
/ 5;
758 button
= BUTTON_NONE
;
759 while (TIME_BEFORE(current_tick
, next_big_refresh
)) {
760 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_NOBLOCK
);
761 if (button
!= ACTION_NONE
) {
765 sleep(0); /* Sleep until end of current tick. */
767 if (TIME_AFTER(current_tick
, next_refresh
)) {
770 if(gui_wps
[i
].data
->peak_meter_enabled
)
771 skin_update(&gui_wps
[i
], WPS_REFRESH_PEAK_METER
);
772 next_refresh
+= HZ
/ PEAK_METER_FPS
;
779 /* The peak meter is disabled
780 -> no additional screen updates needed */
784 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,
785 restore
? HZ
/100 : HZ
/5);
788 /* Exit if audio has stopped playing. This happens e.g. at end of
789 playlist or if using the sleep timer. */
790 if (!(audio_status() & AUDIO_STATUS_PLAY
))
792 #ifdef HAVE_TOUCHSCREEN
793 if (button
== ACTION_TOUCHSCREEN
)
794 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
796 /* The iPods/X5/M5 use a single button for the A-B mode markers,
797 defined as ACTION_WPSAB_SINGLE in their config files. */
798 #ifdef ACTION_WPSAB_SINGLE
799 if (!global_settings
.party_mode
&& ab_repeat_mode_enabled())
801 static int wps_ab_state
= 0;
802 if (button
== ACTION_WPSAB_SINGLE
)
804 switch (wps_ab_state
)
806 case 0: /* set the A spot */
807 button
= ACTION_WPS_ABSETA_PREVDIR
;
809 case 1: /* set the B spot */
810 button
= ACTION_WPS_ABSETB_NEXTDIR
;
813 button
= ACTION_WPS_ABRESET
;
816 wps_ab_state
= (wps_ab_state
+1) % 3;
822 case ACTION_WPS_CONTEXT
:
825 /* if music is stopped in the context menu we want to exit the wps */
826 if (onplay(wps_state
.id3
->path
,
827 FILE_ATTR_AUDIO
, CONTEXT_WPS
) == ONPLAY_MAINMENU
834 case ACTION_WPS_BROWSE
:
835 #ifdef HAVE_LCD_CHARCELLS
836 status_set_record(false);
837 status_set_audio(false);
840 return GO_TO_PREVIOUS_BROWSER
;
844 case ACTION_WPS_PLAY
:
845 if (global_settings
.party_mode
)
847 if ( wps_state
.paused
)
849 wps_state
.paused
= false;
850 if ( global_settings
.fade_on_stop
)
857 wps_state
.paused
= true;
858 if ( global_settings
.fade_on_stop
)
863 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
864 call_storage_idle_notifys(true); /* make sure resume info is saved */
869 case ACTION_WPS_VOLUP
:
872 gui_wps
[i
].data
->button_time_volume
= current_tick
;
873 global_settings
.volume
++;
878 if(update_onvol_change(&gui_wps
[i
]))
883 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
887 case ACTION_WPS_VOLDOWN
:
890 gui_wps
[i
].data
->button_time_volume
= current_tick
;
891 global_settings
.volume
--;
896 if(update_onvol_change(&gui_wps
[i
]))
901 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
906 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
907 case ACTION_WPS_SEEKFWD
:
908 if (global_settings
.party_mode
)
910 if (current_tick
-last_right
< HZ
)
912 if (wps_state
.id3
->cuesheet
)
922 ffwd_rew(ACTION_WPS_SEEKFWD
);
923 last_right
= last_left
= 0;
926 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
927 case ACTION_WPS_SEEKBACK
:
928 if (global_settings
.party_mode
)
930 if (current_tick
-last_left
< HZ
)
932 if (wps_state
.id3
->cuesheet
)
934 if (!wps_state
.paused
)
935 #if (CONFIG_CODEC == SWCODEC)
936 audio_pre_ff_rewind();
948 ffwd_rew(ACTION_WPS_SEEKBACK
);
949 last_left
= last_right
= 0;
953 case ACTION_WPS_SKIPPREV
:
954 if (global_settings
.party_mode
)
956 last_left
= current_tick
;
957 #ifdef AB_REPEAT_ENABLE
958 /* if we're in A/B repeat mode and the current position
959 is past the A marker, jump back to the A marker... */
960 if ( ab_repeat_mode_enabled() )
962 if ( ab_after_A_marker(wps_state
.id3
->elapsed
) )
964 ab_jump_to_A_marker();
966 #if (AB_REPEAT_ENABLE == 2)
973 /* ...otherwise, do it normally */
979 OR if skip length set, hop by predetermined amount. */
980 case ACTION_WPS_SKIPNEXT
:
981 if (global_settings
.party_mode
)
983 last_right
= current_tick
;
984 #ifdef AB_REPEAT_ENABLE
985 /* if we're in A/B repeat mode and the current position is
986 before the A marker, jump to the A marker... */
987 if ( ab_repeat_mode_enabled() )
989 if ( ab_before_A_marker(wps_state
.id3
->elapsed
) )
991 ab_jump_to_A_marker();
993 #if (AB_REPEAT_ENABLE == 2)
1000 /* ...otherwise, do it normally */
1004 /* next / prev directories */
1005 /* and set A-B markers if in a-b mode */
1006 case ACTION_WPS_ABSETB_NEXTDIR
:
1007 if (global_settings
.party_mode
)
1009 #if defined(AB_REPEAT_ENABLE)
1010 if (ab_repeat_mode_enabled())
1012 ab_set_B_marker(wps_state
.id3
->elapsed
);
1013 ab_jump_to_A_marker();
1021 case ACTION_WPS_ABSETA_PREVDIR
:
1022 if (global_settings
.party_mode
)
1024 #if defined(AB_REPEAT_ENABLE)
1025 if (ab_repeat_mode_enabled())
1026 ab_set_A_marker(wps_state
.id3
->elapsed
);
1033 /* menu key functions */
1034 case ACTION_WPS_MENU
:
1040 #ifdef HAVE_QUICKSCREEN
1041 case ACTION_WPS_QUICKSCREEN
:
1044 if (quick_screen_quick(button
))
1049 #endif /* HAVE_QUICKSCREEN */
1051 /* screen settings */
1056 if (quick_screen_f3(BUTTON_F3
))
1061 #endif /* BUTTON_F3 */
1064 #ifdef HAVE_PITCHSCREEN
1065 case ACTION_WPS_PITCHSCREEN
:
1068 if (1 == gui_syncpitchscreen_run())
1073 #endif /* HAVE_PITCHSCREEN */
1075 #ifdef AB_REPEAT_ENABLE
1076 /* reset A&B markers */
1077 case ACTION_WPS_ABRESET
:
1078 if (ab_repeat_mode_enabled())
1084 #endif /* AB_REPEAT_ENABLE */
1086 /* stop and exit wps */
1087 case ACTION_WPS_STOP
:
1088 if (global_settings
.party_mode
)
1094 case ACTION_WPS_ID3SCREEN
:
1102 #ifdef HAVE_TOUCHSCREEN
1103 case ACTION_TOUCH_SHUFFLE
: /* toggle shuffle mode */
1105 global_settings
.playlist_shuffle
=
1106 !global_settings
.playlist_shuffle
;
1107 #if CONFIG_CODEC == SWCODEC
1108 dsp_set_replaygain();
1110 if (global_settings
.playlist_shuffle
)
1111 playlist_randomise(NULL
, current_tick
, true);
1113 playlist_sort(NULL
, true);
1116 case ACTION_TOUCH_REPMODE
: /* cycle the repeat mode setting */
1118 const struct settings_list
*rep_setting
=
1119 find_setting(&global_settings
.repeat_mode
, NULL
);
1120 option_select_next_val(rep_setting
, false, true);
1121 audio_flush_and_reload_tracks();
1124 #endif /* HAVE_TOUCHSCREEN */
1125 /* this case is used by the softlock feature
1126 * it requests a full update here */
1128 wps_state
.do_full_update
= true;
1130 case ACTION_NONE
: /* Timeout, do a partial update */
1132 ffwd_rew(button
); /* hopefully fix the ffw/rwd bug */
1134 #ifdef HAVE_RECORDING
1135 case ACTION_WPS_REC
:
1140 default_event_handler(SYS_POWEROFF
);
1142 case ACTION_WPS_VIEW_PLAYLIST
:
1144 if (playlist_viewer()) /* true if USB connected */
1149 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1158 if (wps_state
.do_full_update
|| update
)
1160 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
1161 gwps_caption_backlight(&wps_state
);
1165 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1167 #ifdef HAVE_REMOTE_LCD
1168 /* currently, all remotes are readable without backlight
1169 * so still update those */
1170 || (i
== SCREEN_REMOTE
)
1175 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
1178 wps_state
.do_full_update
= false;
1182 if (restore
&& wps_state
.id3
&&
1183 ((restoretimer
== RESTORE_WPS_INSTANTLY
) ||
1184 TIME_AFTER(current_tick
, restoretimer
)))
1187 restoretimer
= RESTORE_WPS_INSTANTLY
;
1188 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1189 lcd_activation_set_hook(wps_lcd_activation_hook
);
1193 screens
[i
].stop_scroll();
1194 gui_wps_display(&gui_wps
[i
]);
1199 #ifdef HAVE_LCD_CHARCELLS
1200 status_set_record(false);
1201 status_set_audio(false);
1203 if (global_settings
.fade_on_stop
)
1207 bookmark_autobookmark();
1209 #ifdef AB_REPEAT_ENABLE
1213 #ifdef HAVE_RECORDING
1214 if (button
== ACTION_WPS_REC
)
1215 return GO_TO_RECSCREEN
;
1217 if (global_settings
.browse_current
)
1218 return GO_TO_PREVIOUS_BROWSER
;
1219 return GO_TO_PREVIOUS
;
1222 if (button
&& !IS_SYSEVENT(button
) )
1225 return GO_TO_ROOT
; /* unreachable - just to reduce compiler warnings */
1228 /* this is called from the playback thread so NO DRAWING! */
1229 static void track_changed_callback(void *param
)
1231 wps_state
.id3
= (struct mp3entry
*)param
;
1232 wps_state
.nid3
= audio_next_track();
1233 if (wps_state
.id3
->cuesheet
)
1235 cue_find_current_track(wps_state
.id3
->cuesheet
, wps_state
.id3
->elapsed
);
1236 cue_spoof_id3(wps_state
.id3
->cuesheet
, wps_state
.id3
);
1238 wps_state
.do_full_update
= true;
1240 static void nextid3available_callback(void* param
)
1243 wps_state
.nid3
= audio_next_track();
1244 wps_state
.do_full_update
= true;
1248 static void wps_state_init(void)
1250 wps_state
.ff_rewind
= false;
1251 wps_state
.paused
= false;
1252 if(audio_status() & AUDIO_STATUS_PLAY
)
1254 wps_state
.id3
= audio_current_track();
1255 wps_state
.nid3
= audio_next_track();
1259 wps_state
.id3
= NULL
;
1260 wps_state
.nid3
= NULL
;
1262 /* We'll be updating due to restore initialized with true */
1263 wps_state
.do_full_update
= false;
1264 /* add the WPS track event callbacks */
1265 add_event(PLAYBACK_EVENT_TRACK_CHANGE
, false, track_changed_callback
);
1266 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, false, nextid3available_callback
);
1270 #ifdef HAVE_LCD_BITMAP
1271 static void statusbar_toggle_handler(void *data
)
1276 wpsbars
= VP_SB_HIDE_ALL
;
1278 { /* fix viewports if needed */
1279 skin_statusbar_changed(&gui_wps
[i
]);
1283 /* fix up gui_wps::statusbars, so that the viewportmanager accepts it*/
1284 if (gui_wps
[i
].data
->wps_sb_tag
)
1285 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
1286 else if (statusbar_position(i
) != STATUSBAR_OFF
)
1290 (VP_SB_ONSCREEN(i
) | VP_SB_IGNORE_SETTING(i
));
1296 void gui_sync_wps_init(void)
1301 #ifdef HAVE_ALBUMART
1302 wps_datas
[i
].albumart
= NULL
;
1303 wps_datas
[i
].playback_aa_slot
= -1;
1305 #ifdef HAVE_REMOTE_LCD
1306 wps_datas
[i
].remote_wps
= (i
== SCREEN_REMOTE
);
1308 gui_wps
[i
].data
= &wps_datas
[i
];
1309 gui_wps
[i
].display
= &screens
[i
];
1310 /* Currently no seperate wps_state needed/possible
1311 so use the only available ( "global" ) one */
1312 gui_wps
[i
].state
= &wps_state
;
1313 gui_wps
[i
].display
->backdrop_unload(BACKDROP_SKIN_WPS
);
1314 /* only one wpsbars needed/wanted */
1315 gui_wps
[i
].statusbars
= &wpsbars
;
1317 *(gui_wps
[SCREEN_MAIN
].statusbars
) =VP_SB_ALLSCREENS
;
1318 #ifdef HAVE_LCD_BITMAP
1319 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false, statusbar_toggle_handler
);
1324 #ifdef IPOD_ACCESSORY_PROTOCOL
1325 int wps_get_ff_rewind_count(void)
1327 return wps_state
.ff_rewind_count
;