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 FF_REWIND_MAX_PERCENT 3 /* cap ff/rewind step size at max % of file */
75 /* 3% of 30min file == 54s step size */
76 #define MIN_FF_REWIND_STEP 500
78 /* currently only one wps_state is needed, initialize to 0 */
79 struct wps_state wps_state
= { .id3
= NULL
};
80 static struct gui_wps gui_wps
[NB_SCREENS
] = {{ .data
= NULL
}};
81 static struct wps_data wps_datas
[NB_SCREENS
] = {{ .wps_loaded
= 0 }};
82 static struct wps_sync_data wps_sync_data
= { .do_full_update
= false };
84 /* initial setup of wps_data */
85 static void wps_state_init(void);
86 static void track_changed_callback(void *param
);
87 static void nextid3available_callback(void* param
);
89 #ifdef HAVE_TOUCHSCREEN
90 static void wps_disarm_touchregions(struct wps_data
*data
);
93 #define WPS_DEFAULTCFG WPS_DIR "/rockbox_default.wps"
94 #ifdef HAVE_REMOTE_LCD
95 #define RWPS_DEFAULTCFG WPS_DIR "/rockbox_default.rwps"
96 #define DEFAULT_WPS(screen) ((screen) == SCREEN_MAIN ? \
97 WPS_DEFAULTCFG:RWPS_DEFAULTCFG)
99 #define DEFAULT_WPS(screen) (WPS_DEFAULTCFG)
102 void wps_data_load(enum screen_type screen
, const char *buf
, bool isfile
)
108 * Hardcode loading WPS_DEFAULTCFG to cause a reset ideally this
109 * wants to be a virtual file. Feel free to modify dirbrowse()
110 * if you're feeling brave.
113 if (buf
&& ! strcmp(buf
, DEFAULT_WPS(screen
)) )
115 #ifdef HAVE_REMOTE_LCD
116 if (screen
== SCREEN_REMOTE
)
117 global_settings
.rwps_file
[0] = '\0';
120 global_settings
.wps_file
[0] = '\0';
124 #endif /* __PCTOOL__ */
126 loaded_ok
= buf
&& skin_data_load(screen
, gui_wps
[screen
].data
, buf
, isfile
);
128 if (!loaded_ok
) /* load the hardcoded default */
130 char *skin_buf
[NB_SCREENS
] = {
131 #ifdef HAVE_LCD_BITMAP
135 "%s%?it<%?in<%in. |>%it|%fn>\n"
136 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
137 "%s%?id<%id|%?d1<%d1|(root)>> %?iy<(%iy)|>\n\n"
138 "%al%pc/%pt%ar[%pp:%pe]\n"
139 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
142 "%s%pp/%pe: %?it<%it|%fn> - %?ia<%ia|%d2> - %?id<%id|%d1>\n"
145 #ifdef HAVE_REMOTE_LCD
146 #if LCD_REMOTE_DEPTH > 1
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(screen
, gui_wps
[screen
].data
, skin_buf
[screen
], false);
160 void fade(bool fade_in
, bool updatewps
)
162 int fp_global_vol
= global_settings
.volume
<< 8;
163 int fp_min_vol
= sound_min(SOUND_VOLUME
) << 8;
164 int fp_step
= (fp_global_vol
- fp_min_vol
) / 30;
166 wps_state
.is_fading
= !fade_in
;
169 int fp_volume
= fp_min_vol
;
171 /* zero out the sound */
172 sound_set_volume(fp_min_vol
>> 8);
174 sleep(HZ
/10); /* let audio thread run */
177 while (fp_volume
< fp_global_vol
- fp_step
) {
178 fp_volume
+= fp_step
;
179 sound_set_volume(fp_volume
>> 8);
183 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
187 sound_set_volume(global_settings
.volume
);
191 int fp_volume
= fp_global_vol
;
193 while (fp_volume
> fp_min_vol
+ fp_step
) {
194 fp_volume
-= fp_step
;
195 sound_set_volume(fp_volume
>> 8);
199 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
204 wps_state
.is_fading
= false;
205 #if CONFIG_CODEC != SWCODEC
207 /* let audio thread run and wait for the mas to run out of data */
208 while (!mp3_pause_done())
213 /* reset volume to what it was before the fade */
214 sound_set_volume(global_settings
.volume
);
218 static bool update_onvol_change(struct gui_wps
* gwps
)
220 skin_update(gwps
, WPS_REFRESH_NON_STATIC
);
222 #ifdef HAVE_LCD_CHARCELLS
223 splashf(0, "Vol: %3d dB",
224 sound_val2phys(SOUND_VOLUME
, global_settings
.volume
));
231 bool ffwd_rew(int button
)
233 unsigned int step
= 0; /* current ff/rewind step */
234 unsigned int max_step
= 0; /* maximum ff/rewind step */
235 int ff_rewind_count
= 0; /* current ff/rewind count (in ticks) */
236 int direction
= -1; /* forward=1 or backward=-1 */
240 const long ff_rw_accel
= (global_settings
.ff_rewind_accel
+ 3);
242 if (button
== ACTION_NONE
)
244 status_set_ffmode(0);
251 case ACTION_WPS_SEEKFWD
:
253 case ACTION_WPS_SEEKBACK
:
254 if (wps_state
.ff_rewind
)
258 /* fast forwarding, calc max step relative to end */
259 max_step
= (wps_state
.id3
->length
-
260 (wps_state
.id3
->elapsed
+
262 FF_REWIND_MAX_PERCENT
/ 100;
266 /* rewinding, calc max step relative to start */
267 max_step
= (wps_state
.id3
->elapsed
+ ff_rewind_count
) *
268 FF_REWIND_MAX_PERCENT
/ 100;
271 max_step
= MAX(max_step
, MIN_FF_REWIND_STEP
);
276 ff_rewind_count
+= step
* direction
;
278 /* smooth seeking by multiplying step by: 1 + (2 ^ -accel) */
279 step
+= step
>> ff_rw_accel
;
283 if ( (audio_status() & AUDIO_STATUS_PLAY
) &&
284 wps_state
.id3
&& wps_state
.id3
->length
)
286 if (!wps_state
.paused
)
287 #if (CONFIG_CODEC == SWCODEC)
288 audio_pre_ff_rewind();
292 #if CONFIG_KEYPAD == PLAYER_PAD
294 gui_wps
[i
].display
->stop_scroll();
297 status_set_ffmode(STATUS_FASTFORWARD
);
299 status_set_ffmode(STATUS_FASTBACKWARD
);
301 wps_state
.ff_rewind
= true;
303 step
= 1000 * global_settings
.ff_rewind_min_step
;
310 if ((wps_state
.id3
->elapsed
+ ff_rewind_count
) >
311 wps_state
.id3
->length
)
312 ff_rewind_count
= wps_state
.id3
->length
-
313 wps_state
.id3
->elapsed
;
316 if ((int)(wps_state
.id3
->elapsed
+ ff_rewind_count
) < 0)
317 ff_rewind_count
= -wps_state
.id3
->elapsed
;
320 /* set the wps state ff_rewind_count so the progess info
322 wps_state
.ff_rewind_count
= (wps_state
.wps_time_countup
== false)?
323 ff_rewind_count
:-ff_rewind_count
;
326 skin_update(&gui_wps
[i
],
327 WPS_REFRESH_PLAYER_PROGRESS
|
328 WPS_REFRESH_DYNAMIC
);
333 case ACTION_WPS_STOPSEEK
:
334 wps_state
.id3
->elapsed
= wps_state
.id3
->elapsed
+ff_rewind_count
;
335 audio_ff_rewind(wps_state
.id3
->elapsed
);
336 wps_state
.ff_rewind_count
= 0;
337 wps_state
.ff_rewind
= false;
338 status_set_ffmode(0);
339 #if (CONFIG_CODEC != SWCODEC)
340 if (!wps_state
.paused
)
343 #ifdef HAVE_LCD_CHARCELLS
345 skin_update(&gui_wps
[i
], WPS_REFRESH_ALL
);
351 if(default_event_handler(button
) == SYS_USB_CONNECTED
) {
352 status_set_ffmode(0);
360 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_BLOCK
);
361 #ifdef HAVE_TOUCHSCREEN
362 if (button
== ACTION_TOUCHSCREEN
)
363 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
371 void display_keylock_text(bool locked
)
375 gui_wps
[i
].display
->stop_scroll();
377 splash(HZ
, locked
? ID2P(LANG_KEYLOCK_ON
) : ID2P(LANG_KEYLOCK_OFF
));
383 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
384 static void gwps_caption_backlight(struct wps_state
*state
)
386 if (state
&& state
->id3
)
388 #ifdef HAVE_BACKLIGHT
389 if (global_settings
.caption_backlight
)
391 /* turn on backlight n seconds before track ends, and turn it off n
392 seconds into the new track. n == backlight_timeout, or 5s */
393 int n
= global_settings
.backlight_timeout
* 1000;
396 n
= 5000; /* use 5s if backlight is always on or off */
398 if (((state
->id3
->elapsed
< 1000) ||
399 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
400 (state
->paused
== false))
404 #ifdef HAVE_REMOTE_LCD
405 if (global_settings
.remote_caption_backlight
)
407 /* turn on remote backlight n seconds before track ends, and turn it
408 off n seconds into the new track. n == remote_backlight_timeout,
410 int n
= global_settings
.remote_backlight_timeout
* 1000;
413 n
= 5000; /* use 5s if backlight is always on or off */
415 if (((state
->id3
->elapsed
< 1000) ||
416 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
417 (state
->paused
== false))
418 remote_backlight_on();
426 static void change_dir(int direction
)
428 if (global_settings
.prevent_skip
)
433 else if (direction
> 0)
435 /* prevent the next dir to immediatly start being ffw'd */
436 action_wait_for_release();
439 static void prev_track(unsigned long skip_thresh
)
441 if (wps_state
.id3
->elapsed
< skip_thresh
)
448 if (wps_state
.id3
->cuesheet
)
450 curr_cuesheet_skip(wps_state
.id3
->cuesheet
, -1, wps_state
.id3
->elapsed
);
454 if (!wps_state
.paused
)
455 #if (CONFIG_CODEC == SWCODEC)
456 audio_pre_ff_rewind();
463 #if (CONFIG_CODEC != SWCODEC)
464 if (!wps_state
.paused
)
470 static void next_track(void)
472 /* take care of if we're playing a cuesheet */
473 if (wps_state
.id3
->cuesheet
)
475 if (curr_cuesheet_skip(wps_state
.id3
->cuesheet
, 1, wps_state
.id3
->elapsed
))
477 /* if the result was false, then we really want
478 to skip to the next track */
486 static void play_hop(int direction
)
488 long step
= global_settings
.skip_length
*1000;
489 long elapsed
= wps_state
.id3
->elapsed
;
490 long remaining
= wps_state
.id3
->length
- elapsed
;
496 prev_track(DEFAULT_SKIP_TRESH
);
499 else if (remaining
< DEFAULT_SKIP_TRESH
*2)
505 elapsed
+= (remaining
- DEFAULT_SKIP_TRESH
*2);
507 else if (!global_settings
.prevent_skip
&&
509 (direction
> 0 && step
>= remaining
) ||
510 (direction
< 0 && elapsed
< DEFAULT_SKIP_TRESH
)))
511 { /* Do normal track skipping */
514 else if (direction
< 0)
515 prev_track(DEFAULT_SKIP_TRESH
);
518 else 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 *param
)
559 wps_sync_data
.do_full_update
= true;
560 /* force timeout in wps main loop, so that the update is instantly */
561 queue_post(&button_queue
, BUTTON_NONE
, 0);
565 static void gwps_leave_wps(void)
571 gui_wps
[i
].display
->stop_scroll();
572 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
573 gui_wps
[i
].display
->backdrop_show(sb_get_backdrop(i
));
576 #ifdef HAVE_LCD_BITMAP
578 if (gui_wps
[i
].data
->wps_sb_tag
)
579 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
580 else if (statusbar_position(i
) != STATUSBAR_OFF
)
583 viewportmanager_theme_undo(i
, draw
);
587 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
588 /* Play safe and unregister the hook */
589 remove_event(LCD_EVENT_ACTIVATION
, wps_lcd_activation_hook
);
591 /* unhandle statusbar update delay */
592 sb_skin_set_update_delay(DEFAULT_UPDATE_DELAY
);
596 * display the wps on entering or restoring */
597 static void gwps_enter_wps(void)
602 struct gui_wps
*gwps
= &gui_wps
[i
];
603 struct screen
*display
= gwps
->display
;
604 #ifdef HAVE_LCD_BITMAP
606 if (gui_wps
[i
].data
->wps_sb_tag
)
607 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
608 else if (statusbar_position(i
) != STATUSBAR_OFF
)
611 display
->stop_scroll();
612 viewportmanager_theme_enable(i
, draw
, NULL
);
614 /* Update the values in the first (default) viewport - in case the user
615 has modified the statusbar or colour settings */
617 if (display
->depth
> 1)
619 struct viewport
*vp
= &find_viewport(VP_DEFAULT_LABEL
, gwps
->data
)->vp
;
620 vp
->fg_pattern
= display
->get_foreground();
621 vp
->bg_pattern
= display
->get_background();
624 /* make the backdrop actually take effect */
625 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
626 display
->backdrop_show(gwps
->data
->backdrop
);
628 display
->clear_display();
629 skin_update(gwps
, WPS_REFRESH_ALL
);
631 #ifdef HAVE_TOUCHSCREEN
632 wps_disarm_touchregions(gui_wps
[i
].data
);
635 /* force statusbar/skin update since we just cleared the whole screen */
636 send_event(GUI_EVENT_ACTIONUPDATE
, (void*)1);
639 #ifdef HAVE_TOUCHSCREEN
640 /** Disarms all touchregions. */
641 static void wps_disarm_touchregions(struct wps_data
*data
)
643 struct skin_token_list
*regions
= data
->touchregions
;
646 ((struct touchregion
*)regions
->token
->value
.data
)->armed
= false;
647 regions
= regions
->next
;
651 int wps_get_touchaction(struct wps_data
*data
)
653 int returncode
= ACTION_NONE
;
656 int type
= action_get_touchscreen_press(&x
, &y
);
657 static int last_action
= ACTION_NONE
;
658 struct touchregion
*r
;
659 bool repeated
= (type
== BUTTON_REPEAT
);
660 bool released
= (type
== BUTTON_REL
);
661 bool pressed
= (type
== BUTTON_TOUCHSCREEN
);
662 struct skin_token_list
*regions
= data
->touchregions
;
666 r
= (struct touchregion
*)regions
->token
->value
.data
;
667 /* make sure this region's viewport is visible */
668 if (r
->wvp
->hidden_flags
&VP_DRAW_HIDDEN
)
670 regions
= regions
->next
;
673 /* check if it's inside this viewport */
674 if (viewport_point_within_vp(&(r
->wvp
->vp
), x
, y
))
675 { /* reposition the touch inside the viewport since touchregions
676 * are relative to a preceding viewport */
677 vx
= x
- r
->wvp
->vp
.x
;
678 vy
= y
- r
->wvp
->vp
.y
;
679 /* now see if the point is inside this region */
680 if (vx
>= r
->x
&& vx
< r
->x
+r
->width
&&
681 vy
>= r
->y
&& vy
< r
->y
+r
->height
)
683 /* reposition the touch within the area */
689 case WPS_TOUCHREGION_ACTION
:
690 if (r
->armed
&& ((repeated
&& r
->repeat
) || (released
&& !r
->repeat
)))
692 last_action
= r
->action
;
693 returncode
= r
->action
;
698 case WPS_TOUCHREGION_SCROLLBAR
:
699 if(r
->width
> r
->height
)
701 wps_state
.id3
->elapsed
= (vx
*
702 wps_state
.id3
->length
) / r
->width
;
705 wps_state
.id3
->elapsed
= (vy
*
706 wps_state
.id3
->length
) / r
->height
;
708 if (!wps_state
.paused
)
709 #if (CONFIG_CODEC == SWCODEC)
710 audio_pre_ff_rewind();
714 audio_ff_rewind(wps_state
.id3
->elapsed
);
715 #if (CONFIG_CODEC != SWCODEC)
716 if (!wps_state
.paused
)
720 case WPS_TOUCHREGION_VOLUME
:
722 const int min_vol
= sound_min(SOUND_VOLUME
);
723 const int max_vol
= sound_max(SOUND_VOLUME
);
724 if(r
->width
> r
->height
)
726 global_settings
.volume
= (vx
*
727 (max_vol
- min_vol
)) / r
->width
;
730 global_settings
.volume
= ((r
->height
- vy
) *
731 (max_vol
-min_vol
)) / r
->height
;
733 global_settings
.volume
+= min_vol
;
735 returncode
= ACTION_REDRAW
;
740 regions
= regions
->next
;
743 /* On release, all regions are disarmed. */
745 wps_disarm_touchregions(data
);
747 if (returncode
!= ACTION_NONE
)
750 if ((last_action
== ACTION_WPS_SEEKBACK
|| last_action
== ACTION_WPS_SEEKFWD
))
751 return ACTION_WPS_STOPSEEK
;
752 last_action
= ACTION_TOUCHSCREEN
;
753 return ACTION_TOUCHSCREEN
;
756 /* The WPS can be left in two ways:
757 * a) call a function, which draws over the wps. In this case, the wps
758 * will be still active (i.e. the below function didn't return)
759 * b) return with a value evaluated by root_menu.c, in this case the wps
760 * is really left, and root_menu will handle the next screen
762 * In either way, call gwps_leave_wps(), in order to restore the correct
763 * "main screen" backdrops and statusbars
765 long gui_wps_show(void)
769 long restoretimer
= RESTORE_WPS_INSTANTLY
; /* timer to delay screen redraw temporarily */
771 bool bookmark
= false;
773 bool vol_changed
= false;
775 long last_left
= 0, last_right
= 0;
777 #ifdef HAVE_LCD_CHARCELLS
778 status_set_audio(true);
779 status_set_param(false);
782 #ifdef AB_REPEAT_ENABLE
790 bool audio_paused
= (audio_status() & AUDIO_STATUS_PAUSE
)?true:false;
792 /* did someone else (i.e power thread) change audio pause mode? */
793 if (wps_state
.paused
!= audio_paused
) {
794 wps_state
.paused
= audio_paused
;
796 /* if another thread paused audio, we are probably in car mode,
797 about to shut down. lets save the settings. */
798 if (wps_state
.paused
) {
800 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
801 call_storage_idle_notifys(true);
805 #ifdef HAVE_LCD_BITMAP
806 /* when the peak meter is enabled we want to have a
807 few extra updates to make it look smooth. On the
808 other hand we don't want to waste energy if it
813 if(gui_wps
[i
].data
->peak_meter_enabled
)
818 long next_refresh
= current_tick
;
819 long next_big_refresh
= current_tick
+ HZ
/ 5;
820 button
= BUTTON_NONE
;
821 while (TIME_BEFORE(current_tick
, next_big_refresh
)) {
822 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_NOBLOCK
);
823 /* check for restore to not let the peakmeter delay the
824 * initial draw of the wps, don't delay handling of button
826 if (button
!= ACTION_NONE
|| restore
) {
830 sleep(0); /* Sleep until end of current tick. */
832 if (TIME_AFTER(current_tick
, next_refresh
)) {
835 if(gui_wps
[i
].data
->peak_meter_enabled
)
836 skin_update(&gui_wps
[i
], WPS_REFRESH_PEAK_METER
);
837 next_refresh
+= HZ
/ PEAK_METER_FPS
;
844 /* The peak meter is disabled
845 -> no additional screen updates needed */
848 { /* 1 is the minimum timeout which lets other threads run.
849 * audio thread (apprently) needs to run before displaying the wps
850 * or bad things happen with regards to cuesheet
851 * (probably a race condition, on sh at least) */
852 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,
856 /* Exit if audio has stopped playing. This happens e.g. at end of
857 playlist or if using the sleep timer. */
858 if (!(audio_status() & AUDIO_STATUS_PLAY
))
860 #ifdef HAVE_TOUCHSCREEN
861 if (button
== ACTION_TOUCHSCREEN
)
862 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
864 /* The iPods/X5/M5 use a single button for the A-B mode markers,
865 defined as ACTION_WPSAB_SINGLE in their config files. */
866 #ifdef ACTION_WPSAB_SINGLE
867 if (!global_settings
.party_mode
&& ab_repeat_mode_enabled())
869 static int wps_ab_state
= 0;
870 if (button
== ACTION_WPSAB_SINGLE
)
872 switch (wps_ab_state
)
874 case 0: /* set the A spot */
875 button
= ACTION_WPS_ABSETA_PREVDIR
;
877 case 1: /* set the B spot */
878 button
= ACTION_WPS_ABSETB_NEXTDIR
;
881 button
= ACTION_WPS_ABRESET
;
884 wps_ab_state
= (wps_ab_state
+1) % 3;
890 case ACTION_WPS_CONTEXT
:
893 int retval
= onplay(wps_state
.id3
->path
,
894 FILE_ATTR_AUDIO
, CONTEXT_WPS
);
895 /* if music is stopped in the context menu we want to exit the wps */
896 if (retval
== ONPLAY_MAINMENU
899 else if (retval
== ONPLAY_PLAYLIST
)
900 return GO_TO_PLAYLIST_VIEWER
;
905 case ACTION_WPS_BROWSE
:
906 #ifdef HAVE_LCD_CHARCELLS
907 status_set_record(false);
908 status_set_audio(false);
911 return GO_TO_PREVIOUS_BROWSER
;
915 case ACTION_WPS_PLAY
:
916 if (global_settings
.party_mode
)
918 if ( wps_state
.paused
)
920 wps_state
.paused
= false;
921 if ( global_settings
.fade_on_stop
)
928 wps_state
.paused
= true;
929 if ( global_settings
.fade_on_stop
)
934 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
935 call_storage_idle_notifys(true); /* make sure resume info is saved */
940 case ACTION_WPS_VOLUP
:
941 global_settings
.volume
++;
944 case ACTION_WPS_VOLDOWN
:
945 global_settings
.volume
--;
949 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
950 case ACTION_WPS_SEEKFWD
:
951 if (global_settings
.party_mode
)
953 if (current_tick
-last_right
< HZ
)
955 if (wps_state
.id3
->cuesheet
)
965 ffwd_rew(ACTION_WPS_SEEKFWD
);
966 last_right
= last_left
= 0;
969 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
970 case ACTION_WPS_SEEKBACK
:
971 if (global_settings
.party_mode
)
973 if (current_tick
-last_left
< HZ
)
975 if (wps_state
.id3
->cuesheet
)
977 if (!wps_state
.paused
)
978 #if (CONFIG_CODEC == SWCODEC)
979 audio_pre_ff_rewind();
991 ffwd_rew(ACTION_WPS_SEEKBACK
);
992 last_left
= last_right
= 0;
996 case ACTION_WPS_SKIPPREV
:
997 if (global_settings
.party_mode
)
999 last_left
= current_tick
;
1000 #ifdef AB_REPEAT_ENABLE
1001 /* if we're in A/B repeat mode and the current position
1002 is past the A marker, jump back to the A marker... */
1003 if ( ab_repeat_mode_enabled() )
1005 if ( ab_after_A_marker(wps_state
.id3
->elapsed
) )
1007 ab_jump_to_A_marker();
1009 #if (AB_REPEAT_ENABLE == 2)
1016 /* ...otherwise, do it normally */
1022 OR if skip length set, hop by predetermined amount. */
1023 case ACTION_WPS_SKIPNEXT
:
1024 if (global_settings
.party_mode
)
1026 last_right
= current_tick
;
1027 #ifdef AB_REPEAT_ENABLE
1028 /* if we're in A/B repeat mode and the current position is
1029 before the A marker, jump to the A marker... */
1030 if ( ab_repeat_mode_enabled() )
1032 if ( ab_before_A_marker(wps_state
.id3
->elapsed
) )
1034 ab_jump_to_A_marker();
1036 #if (AB_REPEAT_ENABLE == 2)
1043 /* ...otherwise, do it normally */
1047 /* next / prev directories */
1048 /* and set A-B markers if in a-b mode */
1049 case ACTION_WPS_ABSETB_NEXTDIR
:
1050 if (global_settings
.party_mode
)
1052 #if defined(AB_REPEAT_ENABLE)
1053 if (ab_repeat_mode_enabled())
1055 ab_set_B_marker(wps_state
.id3
->elapsed
);
1056 ab_jump_to_A_marker();
1064 case ACTION_WPS_ABSETA_PREVDIR
:
1065 if (global_settings
.party_mode
)
1067 #if defined(AB_REPEAT_ENABLE)
1068 if (ab_repeat_mode_enabled())
1069 ab_set_A_marker(wps_state
.id3
->elapsed
);
1076 /* menu key functions */
1077 case ACTION_WPS_MENU
:
1083 #ifdef HAVE_QUICKSCREEN
1084 case ACTION_WPS_QUICKSCREEN
:
1087 if (quick_screen_quick(button
))
1092 #endif /* HAVE_QUICKSCREEN */
1094 /* screen settings */
1099 if (quick_screen_f3(BUTTON_F3
))
1104 #endif /* BUTTON_F3 */
1107 #ifdef HAVE_PITCHSCREEN
1108 case ACTION_WPS_PITCHSCREEN
:
1111 if (1 == gui_syncpitchscreen_run())
1116 #endif /* HAVE_PITCHSCREEN */
1118 #ifdef AB_REPEAT_ENABLE
1119 /* reset A&B markers */
1120 case ACTION_WPS_ABRESET
:
1121 if (ab_repeat_mode_enabled())
1127 #endif /* AB_REPEAT_ENABLE */
1129 /* stop and exit wps */
1130 case ACTION_WPS_STOP
:
1131 if (global_settings
.party_mode
)
1137 case ACTION_WPS_ID3SCREEN
:
1145 #ifdef HAVE_TOUCHSCREEN
1146 case ACTION_TOUCH_SHUFFLE
: /* toggle shuffle mode */
1148 global_settings
.playlist_shuffle
=
1149 !global_settings
.playlist_shuffle
;
1150 #if CONFIG_CODEC == SWCODEC
1151 dsp_set_replaygain();
1153 if (global_settings
.playlist_shuffle
)
1154 playlist_randomise(NULL
, current_tick
, true);
1156 playlist_sort(NULL
, true);
1159 case ACTION_TOUCH_REPMODE
: /* cycle the repeat mode setting */
1161 const struct settings_list
*rep_setting
=
1162 find_setting(&global_settings
.repeat_mode
, NULL
);
1163 option_select_next_val(rep_setting
, false, true);
1164 audio_flush_and_reload_tracks();
1167 #endif /* HAVE_TOUCHSCREEN */
1168 /* this case is used by the softlock feature
1169 * it requests a full update here */
1171 wps_sync_data
.do_full_update
= true;
1173 case ACTION_NONE
: /* Timeout, do a partial update */
1175 ffwd_rew(button
); /* hopefully fix the ffw/rwd bug */
1177 #ifdef HAVE_RECORDING
1178 case ACTION_WPS_REC
:
1183 default_event_handler(SYS_POWEROFF
);
1185 case ACTION_WPS_VIEW_PLAYLIST
:
1187 return GO_TO_PLAYLIST_VIEWER
;
1190 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1202 vol_changed
= false;
1206 if(update_onvol_change(&gui_wps
[i
]))
1211 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
1217 ((restoretimer
== RESTORE_WPS_INSTANTLY
) ||
1218 TIME_AFTER(current_tick
, restoretimer
)))
1221 restoretimer
= RESTORE_WPS_INSTANTLY
;
1222 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1223 add_event(LCD_EVENT_ACTIVATION
, false, wps_lcd_activation_hook
);
1225 /* we remove the update delay since it's not very usable in the wps,
1226 * e.g. during volume changing or ffwd/rewind */
1227 sb_skin_set_update_delay(0);
1228 wps_sync_data
.do_full_update
= update
= false;
1231 else if (wps_sync_data
.do_full_update
|| update
)
1233 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
1234 gwps_caption_backlight(&wps_state
);
1238 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1239 /* currently, all remotes are readable without backlight
1240 * so still update those */
1241 if (lcd_active() || (i
!= SCREEN_MAIN
))
1244 skin_update(&gui_wps
[i
], wps_sync_data
.do_full_update
?
1245 WPS_REFRESH_ALL
: WPS_REFRESH_NON_STATIC
);
1248 wps_sync_data
.do_full_update
= false;
1253 #ifdef HAVE_LCD_CHARCELLS
1254 status_set_record(false);
1255 status_set_audio(false);
1257 if (global_settings
.fade_on_stop
)
1261 bookmark_autobookmark();
1263 #ifdef AB_REPEAT_ENABLE
1267 #ifdef HAVE_RECORDING
1268 if (button
== ACTION_WPS_REC
)
1269 return GO_TO_RECSCREEN
;
1271 if (global_settings
.browse_current
)
1272 return GO_TO_PREVIOUS_BROWSER
;
1273 return GO_TO_PREVIOUS
;
1276 if (button
&& !IS_SYSEVENT(button
) )
1279 return GO_TO_ROOT
; /* unreachable - just to reduce compiler warnings */
1282 /* this is called from the playback thread so NO DRAWING! */
1283 static void track_changed_callback(void *param
)
1285 wps_state
.id3
= (struct mp3entry
*)param
;
1286 wps_state
.nid3
= audio_next_track();
1287 if (wps_state
.id3
->cuesheet
)
1289 cue_find_current_track(wps_state
.id3
->cuesheet
, wps_state
.id3
->elapsed
);
1290 cue_spoof_id3(wps_state
.id3
->cuesheet
, wps_state
.id3
);
1292 wps_sync_data
.do_full_update
= true;
1294 static void nextid3available_callback(void* param
)
1297 wps_state
.nid3
= audio_next_track();
1298 wps_sync_data
.do_full_update
= true;
1302 static void wps_state_init(void)
1304 wps_state
.ff_rewind
= false;
1305 wps_state
.paused
= false;
1306 if(audio_status() & AUDIO_STATUS_PLAY
)
1308 wps_state
.id3
= audio_current_track();
1309 wps_state
.nid3
= audio_next_track();
1313 wps_state
.id3
= NULL
;
1314 wps_state
.nid3
= NULL
;
1316 /* We'll be updating due to restore initialized with true */
1317 wps_sync_data
.do_full_update
= false;
1318 /* add the WPS track event callbacks */
1319 add_event(PLAYBACK_EVENT_TRACK_CHANGE
, false, track_changed_callback
);
1320 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, false, nextid3available_callback
);
1324 void gui_sync_wps_init(void)
1329 #ifdef HAVE_ALBUMART
1330 wps_datas
[i
].albumart
= NULL
;
1331 wps_datas
[i
].playback_aa_slot
= -1;
1333 gui_wps
[i
].data
= &wps_datas
[i
];
1334 gui_wps
[i
].display
= &screens
[i
];
1335 /* Currently no seperate wps_state needed/possible
1336 so use the only available ( "global" ) one */
1337 gui_wps
[i
].state
= &wps_state
;
1338 /* must point to the same struct for both screens */
1339 gui_wps
[i
].sync_data
= &wps_sync_data
;
1344 #ifdef IPOD_ACCESSORY_PROTOCOL
1345 bool is_wps_fading(void)
1347 return wps_state
.is_fading
;
1350 int wps_get_ff_rewind_count(void)
1352 return wps_state
.ff_rewind_count
;