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"
35 #include "skin_engine/skin_engine.h"
36 #include "mp3_playback.h"
43 #ifdef HAVE_LCD_BITMAP
45 #include "peakmeter.h"
56 #include "ata_idle_notify.h"
57 #include "root_menu.h"
59 #include "quickscreen.h"
60 #include "pitchscreen.h"
61 #include "appevents.h"
64 #include "option_select.h"
66 #include "playlist_viewer.h"
68 #include "statusbar-skinned.h"
70 #define RESTORE_WPS_INSTANTLY 0l
71 #define RESTORE_WPS_NEXT_SECOND ((long)(HZ+current_tick))
73 #define FF_REWIND_MAX_PERCENT 3 /* cap ff/rewind step size at max % of file */
74 /* 3% of 30min file == 54s step size */
75 #define MIN_FF_REWIND_STEP 500
77 /* currently only one wps_state is needed, initialize to 0 */
78 struct wps_state wps_state
= { .id3
= NULL
};
79 static struct gui_wps gui_wps
[NB_SCREENS
] = {{ .data
= NULL
}};
80 static struct wps_data wps_datas
[NB_SCREENS
] = {{ .wps_loaded
= 0 }};
81 static struct wps_sync_data wps_sync_data
= { .do_full_update
= false };
83 /* initial setup of wps_data */
84 static void wps_state_init(void);
85 static void track_changed_callback(void *param
);
86 static void nextid3available_callback(void* param
);
87 static void wps_part_update_cb(void);
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 bool wps_fading_out
= false;
162 void wps_fade(bool fade_in
, bool updatewps
)
164 playback_fade_on_pause(fade_in
, updatewps
? wps_part_update_cb
: NULL
);
167 bool is_wps_fading(void)
169 return (audio_status() & AUDIO_STATUS_PAUSE
);
172 static bool update_onvol_change(struct gui_wps
* gwps
)
174 skin_update(gwps
, WPS_REFRESH_NON_STATIC
);
176 #ifdef HAVE_LCD_CHARCELLS
177 splashf(0, "Vol: %3d dB",
178 sound_val2phys(SOUND_VOLUME
, global_settings
.volume
));
185 bool ffwd_rew(int button
)
187 unsigned int step
= 0; /* current ff/rewind step */
188 unsigned int max_step
= 0; /* maximum ff/rewind step */
189 int ff_rewind_count
= 0; /* current ff/rewind count (in ticks) */
190 int direction
= -1; /* forward=1 or backward=-1 */
194 const long ff_rw_accel
= (global_settings
.ff_rewind_accel
+ 3);
196 if (button
== ACTION_NONE
)
198 status_set_ffmode(0);
205 case ACTION_WPS_SEEKFWD
:
207 case ACTION_WPS_SEEKBACK
:
208 if (wps_state
.ff_rewind
)
212 /* fast forwarding, calc max step relative to end */
213 max_step
= (wps_state
.id3
->length
-
214 (wps_state
.id3
->elapsed
+
216 FF_REWIND_MAX_PERCENT
/ 100;
220 /* rewinding, calc max step relative to start */
221 max_step
= (wps_state
.id3
->elapsed
+ ff_rewind_count
) *
222 FF_REWIND_MAX_PERCENT
/ 100;
225 max_step
= MAX(max_step
, MIN_FF_REWIND_STEP
);
230 ff_rewind_count
+= step
* direction
;
232 /* smooth seeking by multiplying step by: 1 + (2 ^ -accel) */
233 step
+= step
>> ff_rw_accel
;
237 if ( (audio_status() & AUDIO_STATUS_PLAY
) &&
238 wps_state
.id3
&& wps_state
.id3
->length
)
240 if (!wps_state
.paused
)
241 #if (CONFIG_CODEC == SWCODEC)
242 audio_pre_ff_rewind();
246 #if CONFIG_KEYPAD == PLAYER_PAD
248 gui_wps
[i
].display
->stop_scroll();
251 status_set_ffmode(STATUS_FASTFORWARD
);
253 status_set_ffmode(STATUS_FASTBACKWARD
);
255 wps_state
.ff_rewind
= true;
257 step
= 1000 * global_settings
.ff_rewind_min_step
;
264 if ((wps_state
.id3
->elapsed
+ ff_rewind_count
) >
265 wps_state
.id3
->length
)
266 ff_rewind_count
= wps_state
.id3
->length
-
267 wps_state
.id3
->elapsed
;
270 if ((int)(wps_state
.id3
->elapsed
+ ff_rewind_count
) < 0)
271 ff_rewind_count
= -wps_state
.id3
->elapsed
;
274 /* set the wps state ff_rewind_count so the progess info
276 wps_state
.ff_rewind_count
= (wps_state
.wps_time_countup
== false)?
277 ff_rewind_count
:-ff_rewind_count
;
280 skin_update(&gui_wps
[i
],
281 WPS_REFRESH_PLAYER_PROGRESS
|
282 WPS_REFRESH_DYNAMIC
);
287 case ACTION_WPS_STOPSEEK
:
288 wps_state
.id3
->elapsed
= wps_state
.id3
->elapsed
+ff_rewind_count
;
289 audio_ff_rewind(wps_state
.id3
->elapsed
);
290 wps_state
.ff_rewind_count
= 0;
291 wps_state
.ff_rewind
= false;
292 status_set_ffmode(0);
293 #if (CONFIG_CODEC != SWCODEC)
294 if (!wps_state
.paused
)
297 #ifdef HAVE_LCD_CHARCELLS
299 skin_update(&gui_wps
[i
], WPS_REFRESH_ALL
);
305 if(default_event_handler(button
) == SYS_USB_CONNECTED
) {
306 status_set_ffmode(0);
314 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_BLOCK
);
315 #ifdef HAVE_TOUCHSCREEN
316 if (button
== ACTION_TOUCHSCREEN
)
317 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
325 void display_keylock_text(bool locked
)
329 gui_wps
[i
].display
->stop_scroll();
331 splash(HZ
, locked
? ID2P(LANG_KEYLOCK_ON
) : ID2P(LANG_KEYLOCK_OFF
));
337 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
338 static void gwps_caption_backlight(struct wps_state
*state
)
340 if (state
&& state
->id3
)
342 #ifdef HAVE_BACKLIGHT
343 if (global_settings
.caption_backlight
)
345 /* turn on backlight n seconds before track ends, and turn it off n
346 seconds into the new track. n == backlight_timeout, or 5s */
347 int n
= global_settings
.backlight_timeout
* 1000;
350 n
= 5000; /* use 5s if backlight is always on or off */
352 if (((state
->id3
->elapsed
< 1000) ||
353 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
354 (state
->paused
== false))
358 #ifdef HAVE_REMOTE_LCD
359 if (global_settings
.remote_caption_backlight
)
361 /* turn on remote backlight n seconds before track ends, and turn it
362 off n seconds into the new track. n == remote_backlight_timeout,
364 int n
= global_settings
.remote_backlight_timeout
* 1000;
367 n
= 5000; /* use 5s if backlight is always on or off */
369 if (((state
->id3
->elapsed
< 1000) ||
370 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
371 (state
->paused
== false))
372 remote_backlight_on();
380 static void change_dir(int direction
)
382 if (global_settings
.prevent_skip
)
387 else if (direction
> 0)
389 /* prevent the next dir to immediatly start being ffw'd */
390 action_wait_for_release();
393 static void prev_track(unsigned long skip_thresh
)
395 if (wps_state
.id3
->elapsed
< skip_thresh
)
402 if (wps_state
.id3
->cuesheet
)
404 curr_cuesheet_skip(wps_state
.id3
->cuesheet
, -1, wps_state
.id3
->elapsed
);
408 if (!wps_state
.paused
)
409 #if (CONFIG_CODEC == SWCODEC)
410 audio_pre_ff_rewind();
417 #if (CONFIG_CODEC != SWCODEC)
418 if (!wps_state
.paused
)
424 static void next_track(void)
426 /* take care of if we're playing a cuesheet */
427 if (wps_state
.id3
->cuesheet
)
429 if (curr_cuesheet_skip(wps_state
.id3
->cuesheet
, 1, wps_state
.id3
->elapsed
))
431 /* if the result was false, then we really want
432 to skip to the next track */
440 static void play_hop(int direction
)
442 long step
= global_settings
.skip_length
*1000;
443 long elapsed
= wps_state
.id3
->elapsed
;
444 long remaining
= wps_state
.id3
->length
- elapsed
;
450 prev_track(DEFAULT_SKIP_TRESH
);
453 else if (remaining
< DEFAULT_SKIP_TRESH
*2)
459 elapsed
+= (remaining
- DEFAULT_SKIP_TRESH
*2);
461 else if (!global_settings
.prevent_skip
&&
463 (direction
> 0 && step
>= remaining
) ||
464 (direction
< 0 && elapsed
< DEFAULT_SKIP_TRESH
)))
465 { /* Do normal track skipping */
468 else if (direction
< 0)
469 prev_track(DEFAULT_SKIP_TRESH
);
472 else if (direction
== 1 && step
>= remaining
)
474 #if CONFIG_CODEC == SWCODEC
475 if(global_settings
.beep
)
476 pcmbuf_beep(1000, 150, 1500*global_settings
.beep
);
480 else if ((direction
== -1 && elapsed
< step
))
486 elapsed
+= step
* direction
;
488 if((audio_status() & AUDIO_STATUS_PLAY
) && !wps_state
.paused
)
490 #if (CONFIG_CODEC == SWCODEC)
491 audio_pre_ff_rewind();
496 audio_ff_rewind(wps_state
.id3
->elapsed
= elapsed
);
497 #if (CONFIG_CODEC != SWCODEC)
498 if (!wps_state
.paused
)
504 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
506 * If the user is unable to see the wps, because the display is deactivated,
507 * we suppress updates until the wps is activated again (the lcd driver will
508 * call this hook to issue an instant update)
510 static void wps_lcd_activation_hook(void *param
)
513 wps_sync_data
.do_full_update
= true;
514 /* force timeout in wps main loop, so that the update is instantly */
515 queue_post(&button_queue
, BUTTON_NONE
, 0);
519 static void wps_part_update_cb(void)
521 /* post to get an update */
522 if (queue_empty(&button_queue
))
523 queue_post(&button_queue
, BUTTON_NONE
, 0);
526 static void gwps_leave_wps(void)
532 gui_wps
[i
].display
->stop_scroll();
533 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
534 gui_wps
[i
].display
->backdrop_show(sb_get_backdrop(i
));
537 #ifdef HAVE_LCD_BITMAP
539 if (gui_wps
[i
].data
->wps_sb_tag
)
540 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
541 else if (statusbar_position(i
) != STATUSBAR_OFF
)
544 viewportmanager_theme_undo(i
, draw
);
548 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
549 /* Play safe and unregister the hook */
550 remove_event(LCD_EVENT_ACTIVATION
, wps_lcd_activation_hook
);
552 /* unhandle statusbar update delay */
553 sb_skin_set_update_delay(DEFAULT_UPDATE_DELAY
);
557 * display the wps on entering or restoring */
558 static void gwps_enter_wps(void)
563 struct gui_wps
*gwps
= &gui_wps
[i
];
564 struct screen
*display
= gwps
->display
;
565 #ifdef HAVE_LCD_BITMAP
567 if (gui_wps
[i
].data
->wps_sb_tag
)
568 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
569 else if (statusbar_position(i
) != STATUSBAR_OFF
)
572 display
->stop_scroll();
573 viewportmanager_theme_enable(i
, draw
, NULL
);
575 /* Update the values in the first (default) viewport - in case the user
576 has modified the statusbar or colour settings */
578 if (display
->depth
> 1)
580 struct viewport
*vp
= &find_viewport(VP_DEFAULT_LABEL
, gwps
->data
)->vp
;
581 vp
->fg_pattern
= display
->get_foreground();
582 vp
->bg_pattern
= display
->get_background();
585 /* make the backdrop actually take effect */
586 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
587 display
->backdrop_show(gwps
->data
->backdrop
);
589 display
->clear_display();
590 skin_update(gwps
, WPS_REFRESH_ALL
);
592 #ifdef HAVE_TOUCHSCREEN
593 wps_disarm_touchregions(gui_wps
[i
].data
);
596 /* force statusbar/skin update since we just cleared the whole screen */
597 send_event(GUI_EVENT_ACTIONUPDATE
, (void*)1);
600 #ifdef HAVE_TOUCHSCREEN
601 /** Disarms all touchregions. */
602 static void wps_disarm_touchregions(struct wps_data
*data
)
604 struct skin_token_list
*regions
= data
->touchregions
;
607 ((struct touchregion
*)regions
->token
->value
.data
)->armed
= false;
608 regions
= regions
->next
;
612 int wps_get_touchaction(struct wps_data
*data
)
614 int returncode
= ACTION_NONE
;
617 int type
= action_get_touchscreen_press(&x
, &y
);
618 static int last_action
= ACTION_NONE
;
619 struct touchregion
*r
;
620 bool repeated
= (type
== BUTTON_REPEAT
);
621 bool released
= (type
== BUTTON_REL
);
622 bool pressed
= (type
== BUTTON_TOUCHSCREEN
);
623 struct skin_token_list
*regions
= data
->touchregions
;
627 r
= (struct touchregion
*)regions
->token
->value
.data
;
628 /* make sure this region's viewport is visible */
629 if (r
->wvp
->hidden_flags
&VP_DRAW_HIDDEN
)
631 regions
= regions
->next
;
634 /* check if it's inside this viewport */
635 if (viewport_point_within_vp(&(r
->wvp
->vp
), x
, y
))
636 { /* reposition the touch inside the viewport since touchregions
637 * are relative to a preceding viewport */
638 vx
= x
- r
->wvp
->vp
.x
;
639 vy
= y
- r
->wvp
->vp
.y
;
640 /* now see if the point is inside this region */
641 if (vx
>= r
->x
&& vx
< r
->x
+r
->width
&&
642 vy
>= r
->y
&& vy
< r
->y
+r
->height
)
644 /* reposition the touch within the area */
650 case WPS_TOUCHREGION_ACTION
:
651 if (r
->armed
&& ((repeated
&& r
->repeat
) || (released
&& !r
->repeat
)))
653 last_action
= r
->action
;
654 returncode
= r
->action
;
659 case WPS_TOUCHREGION_SCROLLBAR
:
660 if(r
->width
> r
->height
)
662 wps_state
.id3
->elapsed
= (vx
*
663 wps_state
.id3
->length
) / r
->width
;
666 wps_state
.id3
->elapsed
= (vy
*
667 wps_state
.id3
->length
) / r
->height
;
669 if (!wps_state
.paused
)
670 #if (CONFIG_CODEC == SWCODEC)
671 audio_pre_ff_rewind();
675 audio_ff_rewind(wps_state
.id3
->elapsed
);
676 #if (CONFIG_CODEC != SWCODEC)
677 if (!wps_state
.paused
)
681 case WPS_TOUCHREGION_VOLUME
:
683 const int min_vol
= sound_min(SOUND_VOLUME
);
684 const int max_vol
= sound_max(SOUND_VOLUME
);
685 if(r
->width
> r
->height
)
687 global_settings
.volume
= (vx
*
688 (max_vol
- min_vol
)) / r
->width
;
691 global_settings
.volume
= ((r
->height
- vy
) *
692 (max_vol
-min_vol
)) / r
->height
;
694 global_settings
.volume
+= min_vol
;
696 returncode
= ACTION_REDRAW
;
701 regions
= regions
->next
;
704 /* On release, all regions are disarmed. */
706 wps_disarm_touchregions(data
);
708 if (returncode
!= ACTION_NONE
)
711 if ((last_action
== ACTION_WPS_SEEKBACK
|| last_action
== ACTION_WPS_SEEKFWD
))
712 return ACTION_WPS_STOPSEEK
;
713 last_action
= ACTION_TOUCHSCREEN
;
714 return ACTION_TOUCHSCREEN
;
717 /* The WPS can be left in two ways:
718 * a) call a function, which draws over the wps. In this case, the wps
719 * will be still active (i.e. the below function didn't return)
720 * b) return with a value evaluated by root_menu.c, in this case the wps
721 * is really left, and root_menu will handle the next screen
723 * In either way, call gwps_leave_wps(), in order to restore the correct
724 * "main screen" backdrops and statusbars
726 long gui_wps_show(void)
730 long restoretimer
= RESTORE_WPS_INSTANTLY
; /* timer to delay screen redraw temporarily */
732 bool bookmark
= false;
734 bool vol_changed
= false;
736 long last_left
= 0, last_right
= 0;
738 #ifdef HAVE_LCD_CHARCELLS
739 status_set_audio(true);
740 status_set_param(false);
743 #ifdef AB_REPEAT_ENABLE
751 bool audio_paused
= (audio_status() & AUDIO_STATUS_PAUSE
)?true:false;
753 /* did someone else (i.e power thread) change audio pause mode? */
754 if (wps_state
.paused
!= audio_paused
) {
755 wps_state
.paused
= audio_paused
;
757 /* if another thread paused audio, we are probably in car mode,
758 about to shut down. lets save the settings. */
759 if (wps_state
.paused
) {
761 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
762 call_storage_idle_notifys(true);
766 #ifdef HAVE_LCD_BITMAP
767 /* when the peak meter is enabled we want to have a
768 few extra updates to make it look smooth. On the
769 other hand we don't want to waste energy if it
774 if(gui_wps
[i
].data
->peak_meter_enabled
)
779 long next_refresh
= current_tick
;
780 long next_big_refresh
= current_tick
+ HZ
/ 5;
781 button
= BUTTON_NONE
;
782 while (TIME_BEFORE(current_tick
, next_big_refresh
)) {
783 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_NOBLOCK
);
784 /* check for restore to not let the peakmeter delay the
785 * initial draw of the wps, don't delay handling of button
787 if (button
!= ACTION_NONE
|| restore
) {
791 sleep(0); /* Sleep until end of current tick. */
793 if (TIME_AFTER(current_tick
, next_refresh
)) {
796 if(gui_wps
[i
].data
->peak_meter_enabled
)
797 skin_update(&gui_wps
[i
], WPS_REFRESH_PEAK_METER
);
798 next_refresh
+= HZ
/ PEAK_METER_FPS
;
805 /* The peak meter is disabled
806 -> no additional screen updates needed */
809 { /* 1 is the minimum timeout which lets other threads run.
810 * audio thread (apprently) needs to run before displaying the wps
811 * or bad things happen with regards to cuesheet
812 * (probably a race condition, on sh at least) */
813 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,
817 /* Exit if audio has stopped playing. This happens e.g. at end of
818 playlist or if using the sleep timer. */
819 if (!(audio_status() & AUDIO_STATUS_PLAY
))
821 #ifdef HAVE_TOUCHSCREEN
822 if (button
== ACTION_TOUCHSCREEN
)
823 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
825 /* The iPods/X5/M5 use a single button for the A-B mode markers,
826 defined as ACTION_WPSAB_SINGLE in their config files. */
827 #ifdef ACTION_WPSAB_SINGLE
828 if (!global_settings
.party_mode
&& ab_repeat_mode_enabled())
830 static int wps_ab_state
= 0;
831 if (button
== ACTION_WPSAB_SINGLE
)
833 switch (wps_ab_state
)
835 case 0: /* set the A spot */
836 button
= ACTION_WPS_ABSETA_PREVDIR
;
838 case 1: /* set the B spot */
839 button
= ACTION_WPS_ABSETB_NEXTDIR
;
842 button
= ACTION_WPS_ABRESET
;
845 wps_ab_state
= (wps_ab_state
+1) % 3;
852 case ACTION_WPS_HOTKEY
:
853 if (!global_settings
.hotkey_wps
)
857 case ACTION_WPS_CONTEXT
:
859 bool hotkey
= button
== ACTION_WPS_HOTKEY
;
861 int retval
= onplay(wps_state
.id3
->path
,
862 FILE_ATTR_AUDIO
, CONTEXT_WPS
, hotkey
);
863 /* if music is stopped in the context menu we want to exit the wps */
864 if (retval
== ONPLAY_MAINMENU
867 else if (retval
== ONPLAY_PLAYLIST
)
868 return GO_TO_PLAYLIST_VIEWER
;
873 case ACTION_WPS_BROWSE
:
874 #ifdef HAVE_LCD_CHARCELLS
875 status_set_record(false);
876 status_set_audio(false);
879 return GO_TO_PREVIOUS_BROWSER
;
883 case ACTION_WPS_PLAY
:
884 if (global_settings
.party_mode
)
886 if ( wps_state
.paused
)
888 wps_state
.paused
= false;
889 if ( global_settings
.fade_on_stop
)
890 wps_fade(true, true);
896 wps_state
.paused
= true;
897 if ( global_settings
.fade_on_stop
)
898 wps_fade(false, true);
902 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
903 call_storage_idle_notifys(true); /* make sure resume info is saved */
908 case ACTION_WPS_VOLUP
:
909 global_settings
.volume
++;
912 case ACTION_WPS_VOLDOWN
:
913 global_settings
.volume
--;
917 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
918 case ACTION_WPS_SEEKFWD
:
919 if (global_settings
.party_mode
)
921 if (current_tick
-last_right
< HZ
)
923 if (wps_state
.id3
->cuesheet
)
933 ffwd_rew(ACTION_WPS_SEEKFWD
);
934 last_right
= last_left
= 0;
937 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
938 case ACTION_WPS_SEEKBACK
:
939 if (global_settings
.party_mode
)
941 if (current_tick
-last_left
< HZ
)
943 if (wps_state
.id3
->cuesheet
)
945 if (!wps_state
.paused
)
946 #if (CONFIG_CODEC == SWCODEC)
947 audio_pre_ff_rewind();
959 ffwd_rew(ACTION_WPS_SEEKBACK
);
960 last_left
= last_right
= 0;
964 case ACTION_WPS_SKIPPREV
:
965 if (global_settings
.party_mode
)
967 last_left
= current_tick
;
968 #ifdef AB_REPEAT_ENABLE
969 /* if we're in A/B repeat mode and the current position
970 is past the A marker, jump back to the A marker... */
971 if ( ab_repeat_mode_enabled() )
973 if ( ab_after_A_marker(wps_state
.id3
->elapsed
) )
975 ab_jump_to_A_marker();
977 #if (AB_REPEAT_ENABLE == 2)
984 /* ...otherwise, do it normally */
990 OR if skip length set, hop by predetermined amount. */
991 case ACTION_WPS_SKIPNEXT
:
992 if (global_settings
.party_mode
)
994 last_right
= current_tick
;
995 #ifdef AB_REPEAT_ENABLE
996 /* if we're in A/B repeat mode and the current position is
997 before the A marker, jump to the A marker... */
998 if ( ab_repeat_mode_enabled() )
1000 if ( ab_before_A_marker(wps_state
.id3
->elapsed
) )
1002 ab_jump_to_A_marker();
1004 #if (AB_REPEAT_ENABLE == 2)
1011 /* ...otherwise, do it normally */
1015 /* next / prev directories */
1016 /* and set A-B markers if in a-b mode */
1017 case ACTION_WPS_ABSETB_NEXTDIR
:
1018 if (global_settings
.party_mode
)
1020 #if defined(AB_REPEAT_ENABLE)
1021 if (ab_repeat_mode_enabled())
1023 ab_set_B_marker(wps_state
.id3
->elapsed
);
1024 ab_jump_to_A_marker();
1032 case ACTION_WPS_ABSETA_PREVDIR
:
1033 if (global_settings
.party_mode
)
1035 #if defined(AB_REPEAT_ENABLE)
1036 if (ab_repeat_mode_enabled())
1037 ab_set_A_marker(wps_state
.id3
->elapsed
);
1044 /* menu key functions */
1045 case ACTION_WPS_MENU
:
1051 #ifdef HAVE_QUICKSCREEN
1052 case ACTION_WPS_QUICKSCREEN
:
1055 if (quick_screen_quick(button
))
1060 #endif /* HAVE_QUICKSCREEN */
1062 /* screen settings */
1067 if (quick_screen_f3(BUTTON_F3
))
1072 #endif /* BUTTON_F3 */
1075 #ifdef HAVE_PITCHSCREEN
1076 case ACTION_WPS_PITCHSCREEN
:
1079 if (1 == gui_syncpitchscreen_run())
1084 #endif /* HAVE_PITCHSCREEN */
1086 #ifdef AB_REPEAT_ENABLE
1087 /* reset A&B markers */
1088 case ACTION_WPS_ABRESET
:
1089 if (ab_repeat_mode_enabled())
1095 #endif /* AB_REPEAT_ENABLE */
1097 /* stop and exit wps */
1098 case ACTION_WPS_STOP
:
1099 if (global_settings
.party_mode
)
1105 case ACTION_WPS_ID3SCREEN
:
1113 #ifdef HAVE_TOUCHSCREEN
1114 case ACTION_TOUCH_SHUFFLE
: /* toggle shuffle mode */
1116 global_settings
.playlist_shuffle
=
1117 !global_settings
.playlist_shuffle
;
1118 #if CONFIG_CODEC == SWCODEC
1119 dsp_set_replaygain();
1121 if (global_settings
.playlist_shuffle
)
1122 playlist_randomise(NULL
, current_tick
, true);
1124 playlist_sort(NULL
, true);
1127 case ACTION_TOUCH_REPMODE
: /* cycle the repeat mode setting */
1129 const struct settings_list
*rep_setting
=
1130 find_setting(&global_settings
.repeat_mode
, NULL
);
1131 option_select_next_val(rep_setting
, false, true);
1132 audio_flush_and_reload_tracks();
1135 #endif /* HAVE_TOUCHSCREEN */
1136 /* this case is used by the softlock feature
1137 * it requests a full update here */
1139 wps_sync_data
.do_full_update
= true;
1141 case ACTION_NONE
: /* Timeout, do a partial update */
1143 ffwd_rew(button
); /* hopefully fix the ffw/rwd bug */
1145 #ifdef HAVE_RECORDING
1146 case ACTION_WPS_REC
:
1151 default_event_handler(SYS_POWEROFF
);
1153 case ACTION_WPS_VIEW_PLAYLIST
:
1155 return GO_TO_PLAYLIST_VIEWER
;
1158 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1170 vol_changed
= false;
1174 if(update_onvol_change(&gui_wps
[i
]))
1179 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
1185 ((restoretimer
== RESTORE_WPS_INSTANTLY
) ||
1186 TIME_AFTER(current_tick
, restoretimer
)))
1189 restoretimer
= RESTORE_WPS_INSTANTLY
;
1190 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1191 add_event(LCD_EVENT_ACTIVATION
, false, wps_lcd_activation_hook
);
1193 /* we remove the update delay since it's not very usable in the wps,
1194 * e.g. during volume changing or ffwd/rewind */
1195 sb_skin_set_update_delay(0);
1196 wps_sync_data
.do_full_update
= update
= false;
1199 else if (wps_sync_data
.do_full_update
|| update
)
1201 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
1202 gwps_caption_backlight(&wps_state
);
1206 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1207 /* currently, all remotes are readable without backlight
1208 * so still update those */
1209 if (lcd_active() || (i
!= SCREEN_MAIN
))
1212 skin_update(&gui_wps
[i
], wps_sync_data
.do_full_update
?
1213 WPS_REFRESH_ALL
: WPS_REFRESH_NON_STATIC
);
1216 wps_sync_data
.do_full_update
= false;
1221 #ifdef HAVE_LCD_CHARCELLS
1222 status_set_record(false);
1223 status_set_audio(false);
1225 if (global_settings
.fade_on_stop
)
1226 wps_fade(false, true);
1229 bookmark_autobookmark(true);
1231 #ifdef AB_REPEAT_ENABLE
1235 #ifdef HAVE_RECORDING
1236 if (button
== ACTION_WPS_REC
)
1237 return GO_TO_RECSCREEN
;
1239 if (global_settings
.browse_current
)
1240 return GO_TO_PREVIOUS_BROWSER
;
1241 return GO_TO_PREVIOUS
;
1244 if (button
&& !IS_SYSEVENT(button
) )
1247 return GO_TO_ROOT
; /* unreachable - just to reduce compiler warnings */
1250 /* this is called from the playback thread so NO DRAWING! */
1251 static void track_changed_callback(void *param
)
1253 wps_state
.id3
= (struct mp3entry
*)param
;
1254 wps_state
.nid3
= audio_next_track();
1255 if (wps_state
.id3
->cuesheet
)
1257 cue_find_current_track(wps_state
.id3
->cuesheet
, wps_state
.id3
->elapsed
);
1258 cue_spoof_id3(wps_state
.id3
->cuesheet
, wps_state
.id3
);
1260 wps_sync_data
.do_full_update
= true;
1262 static void nextid3available_callback(void* param
)
1265 wps_state
.nid3
= audio_next_track();
1266 wps_sync_data
.do_full_update
= true;
1270 static void wps_state_init(void)
1272 wps_state
.ff_rewind
= false;
1273 wps_state
.paused
= false;
1274 if(audio_status() & AUDIO_STATUS_PLAY
)
1276 wps_state
.id3
= audio_current_track();
1277 wps_state
.nid3
= audio_next_track();
1281 wps_state
.id3
= NULL
;
1282 wps_state
.nid3
= NULL
;
1284 /* We'll be updating due to restore initialized with true */
1285 wps_sync_data
.do_full_update
= false;
1286 /* add the WPS track event callbacks */
1287 add_event(PLAYBACK_EVENT_TRACK_CHANGE
, false, track_changed_callback
);
1288 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, false, nextid3available_callback
);
1292 void gui_sync_wps_init(void)
1297 #ifdef HAVE_ALBUMART
1298 wps_datas
[i
].albumart
= NULL
;
1299 wps_datas
[i
].playback_aa_slot
= -1;
1301 gui_wps
[i
].data
= &wps_datas
[i
];
1302 gui_wps
[i
].display
= &screens
[i
];
1303 /* Currently no seperate wps_state needed/possible
1304 so use the only available ( "global" ) one */
1305 gui_wps
[i
].state
= &wps_state
;
1306 /* must point to the same struct for both screens */
1307 gui_wps
[i
].sync_data
= &wps_sync_data
;
1312 #ifdef IPOD_ACCESSORY_PROTOCOL
1313 bool is_wps_fading(void)
1315 return wps_state
.is_fading
;
1318 int wps_get_ff_rewind_count(void)
1320 return wps_state
.ff_rewind_count
;