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 #define WPS_DEFAULTCFG WPS_DIR "/rockbox_default.wps"
90 #ifdef HAVE_REMOTE_LCD
91 #define RWPS_DEFAULTCFG WPS_DIR "/rockbox_default.rwps"
92 #define DEFAULT_WPS(screen) ((screen) == SCREEN_MAIN ? \
93 WPS_DEFAULTCFG:RWPS_DEFAULTCFG)
95 #define DEFAULT_WPS(screen) (WPS_DEFAULTCFG)
98 void wps_data_load(enum screen_type screen
, const char *buf
, bool isfile
)
104 * Hardcode loading WPS_DEFAULTCFG to cause a reset ideally this
105 * wants to be a virtual file. Feel free to modify dirbrowse()
106 * if you're feeling brave.
109 if (buf
&& ! strcmp(buf
, DEFAULT_WPS(screen
)) )
111 #ifdef HAVE_REMOTE_LCD
112 if (screen
== SCREEN_REMOTE
)
113 global_settings
.rwps_file
[0] = '\0';
116 global_settings
.wps_file
[0] = '\0';
120 #endif /* __PCTOOL__ */
122 loaded_ok
= buf
&& skin_data_load(screen
, gui_wps
[screen
].data
, buf
, isfile
);
124 if (!loaded_ok
) /* load the hardcoded default */
126 char *skin_buf
[NB_SCREENS
] = {
127 #ifdef HAVE_LCD_BITMAP
131 "%s%?it<%?in<%in. |>%it|%fn>\n"
132 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
133 "%s%?id<%id|%?d1<%d1|(root)>> %?iy<(%iy)|>\n\n"
134 "%al%pc/%pt%ar[%pp:%pe]\n"
135 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
138 "%s%pp/%pe: %?it<%it|%fn> - %?ia<%ia|%d2> - %?id<%id|%d1>\n"
141 #ifdef HAVE_REMOTE_LCD
142 #if LCD_REMOTE_DEPTH > 1
145 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
146 "%s%?it<%?in<%in. |>%it|%fn>\n"
147 "%al%pc/%pt%ar[%pp:%pe]\n"
148 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
152 skin_data_load(screen
, gui_wps
[screen
].data
, skin_buf
[screen
], false);
156 void fade(bool fade_in
, bool updatewps
)
158 int fp_global_vol
= global_settings
.volume
<< 8;
159 int fp_min_vol
= sound_min(SOUND_VOLUME
) << 8;
160 int fp_step
= (fp_global_vol
- fp_min_vol
) / 30;
162 wps_state
.is_fading
= !fade_in
;
165 int fp_volume
= fp_min_vol
;
167 /* zero out the sound */
168 sound_set_volume(fp_min_vol
>> 8);
170 sleep(HZ
/10); /* let audio thread run */
173 while (fp_volume
< fp_global_vol
- fp_step
) {
174 fp_volume
+= fp_step
;
175 sound_set_volume(fp_volume
>> 8);
179 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
183 sound_set_volume(global_settings
.volume
);
187 int fp_volume
= fp_global_vol
;
189 while (fp_volume
> fp_min_vol
+ fp_step
) {
190 fp_volume
-= fp_step
;
191 sound_set_volume(fp_volume
>> 8);
195 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
200 wps_state
.is_fading
= false;
201 #if CONFIG_CODEC != SWCODEC
203 /* let audio thread run and wait for the mas to run out of data */
204 while (!mp3_pause_done())
209 /* reset volume to what it was before the fade */
210 sound_set_volume(global_settings
.volume
);
214 static bool update_onvol_change(struct gui_wps
* gwps
)
216 skin_update(gwps
, WPS_REFRESH_NON_STATIC
);
218 #ifdef HAVE_LCD_CHARCELLS
219 splashf(0, "Vol: %3d dB",
220 sound_val2phys(SOUND_VOLUME
, global_settings
.volume
));
227 bool ffwd_rew(int button
)
229 unsigned int step
= 0; /* current ff/rewind step */
230 unsigned int max_step
= 0; /* maximum ff/rewind step */
231 int ff_rewind_count
= 0; /* current ff/rewind count (in ticks) */
232 int direction
= -1; /* forward=1 or backward=-1 */
236 const long ff_rw_accel
= (global_settings
.ff_rewind_accel
+ 3);
238 if (button
== ACTION_NONE
)
240 status_set_ffmode(0);
247 case ACTION_WPS_SEEKFWD
:
249 case ACTION_WPS_SEEKBACK
:
250 if (wps_state
.ff_rewind
)
254 /* fast forwarding, calc max step relative to end */
255 max_step
= (wps_state
.id3
->length
-
256 (wps_state
.id3
->elapsed
+
258 FF_REWIND_MAX_PERCENT
/ 100;
262 /* rewinding, calc max step relative to start */
263 max_step
= (wps_state
.id3
->elapsed
+ ff_rewind_count
) *
264 FF_REWIND_MAX_PERCENT
/ 100;
267 max_step
= MAX(max_step
, MIN_FF_REWIND_STEP
);
272 ff_rewind_count
+= step
* direction
;
274 /* smooth seeking by multiplying step by: 1 + (2 ^ -accel) */
275 step
+= step
>> ff_rw_accel
;
279 if ( (audio_status() & AUDIO_STATUS_PLAY
) &&
280 wps_state
.id3
&& wps_state
.id3
->length
)
282 if (!wps_state
.paused
)
283 #if (CONFIG_CODEC == SWCODEC)
284 audio_pre_ff_rewind();
288 #if CONFIG_KEYPAD == PLAYER_PAD
290 gui_wps
[i
].display
->stop_scroll();
293 status_set_ffmode(STATUS_FASTFORWARD
);
295 status_set_ffmode(STATUS_FASTBACKWARD
);
297 wps_state
.ff_rewind
= true;
299 step
= 1000 * global_settings
.ff_rewind_min_step
;
306 if ((wps_state
.id3
->elapsed
+ ff_rewind_count
) >
307 wps_state
.id3
->length
)
308 ff_rewind_count
= wps_state
.id3
->length
-
309 wps_state
.id3
->elapsed
;
312 if ((int)(wps_state
.id3
->elapsed
+ ff_rewind_count
) < 0)
313 ff_rewind_count
= -wps_state
.id3
->elapsed
;
316 /* set the wps state ff_rewind_count so the progess info
318 wps_state
.ff_rewind_count
= (wps_state
.wps_time_countup
== false)?
319 ff_rewind_count
:-ff_rewind_count
;
322 skin_update(&gui_wps
[i
],
323 WPS_REFRESH_PLAYER_PROGRESS
|
324 WPS_REFRESH_DYNAMIC
);
329 case ACTION_WPS_STOPSEEK
:
330 wps_state
.id3
->elapsed
= wps_state
.id3
->elapsed
+ff_rewind_count
;
331 audio_ff_rewind(wps_state
.id3
->elapsed
);
332 wps_state
.ff_rewind_count
= 0;
333 wps_state
.ff_rewind
= false;
334 status_set_ffmode(0);
335 #if (CONFIG_CODEC != SWCODEC)
336 if (!wps_state
.paused
)
339 #ifdef HAVE_LCD_CHARCELLS
341 skin_update(&gui_wps
[i
], WPS_REFRESH_ALL
);
347 if(default_event_handler(button
) == SYS_USB_CONNECTED
) {
348 status_set_ffmode(0);
356 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_BLOCK
);
357 #ifdef HAVE_TOUCHSCREEN
358 if (button
== ACTION_TOUCHSCREEN
)
359 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
367 void display_keylock_text(bool locked
)
371 gui_wps
[i
].display
->stop_scroll();
373 splash(HZ
, locked
? ID2P(LANG_KEYLOCK_ON
) : ID2P(LANG_KEYLOCK_OFF
));
379 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
380 static void gwps_caption_backlight(struct wps_state
*state
)
382 if (state
&& state
->id3
)
384 #ifdef HAVE_BACKLIGHT
385 if (global_settings
.caption_backlight
)
387 /* turn on backlight n seconds before track ends, and turn it off n
388 seconds into the new track. n == backlight_timeout, or 5s */
389 int n
= global_settings
.backlight_timeout
* 1000;
392 n
= 5000; /* use 5s if backlight is always on or off */
394 if (((state
->id3
->elapsed
< 1000) ||
395 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
396 (state
->paused
== false))
400 #ifdef HAVE_REMOTE_LCD
401 if (global_settings
.remote_caption_backlight
)
403 /* turn on remote backlight n seconds before track ends, and turn it
404 off n seconds into the new track. n == remote_backlight_timeout,
406 int n
= global_settings
.remote_backlight_timeout
* 1000;
409 n
= 5000; /* use 5s if backlight is always on or off */
411 if (((state
->id3
->elapsed
< 1000) ||
412 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
413 (state
->paused
== false))
414 remote_backlight_on();
422 static void change_dir(int direction
)
424 if (global_settings
.prevent_skip
)
429 else if (direction
> 0)
431 /* prevent the next dir to immediatly start being ffw'd */
432 action_wait_for_release();
435 static void prev_track(unsigned long skip_thresh
)
437 if (wps_state
.id3
->elapsed
< skip_thresh
)
444 if (wps_state
.id3
->cuesheet
)
446 curr_cuesheet_skip(wps_state
.id3
->cuesheet
, -1, wps_state
.id3
->elapsed
);
450 if (!wps_state
.paused
)
451 #if (CONFIG_CODEC == SWCODEC)
452 audio_pre_ff_rewind();
459 #if (CONFIG_CODEC != SWCODEC)
460 if (!wps_state
.paused
)
466 static void next_track(void)
468 /* take care of if we're playing a cuesheet */
469 if (wps_state
.id3
->cuesheet
)
471 if (curr_cuesheet_skip(wps_state
.id3
->cuesheet
, 1, wps_state
.id3
->elapsed
))
473 /* if the result was false, then we really want
474 to skip to the next track */
482 static void play_hop(int direction
)
484 long step
= global_settings
.skip_length
*1000;
485 long elapsed
= wps_state
.id3
->elapsed
;
486 long remaining
= wps_state
.id3
->length
- elapsed
;
492 prev_track(DEFAULT_SKIP_TRESH
);
495 else if (remaining
< DEFAULT_SKIP_TRESH
*2)
501 elapsed
+= (remaining
- DEFAULT_SKIP_TRESH
*2);
503 else if (!global_settings
.prevent_skip
&&
505 (direction
> 0 && step
>= remaining
) ||
506 (direction
< 0 && elapsed
< DEFAULT_SKIP_TRESH
)))
507 { /* Do normal track skipping */
510 else if (direction
< 0)
511 prev_track(DEFAULT_SKIP_TRESH
);
514 else 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 *param
)
555 wps_sync_data
.do_full_update
= true;
556 /* force timeout in wps main loop, so that the update is instantly */
557 queue_post(&button_queue
, BUTTON_NONE
, 0);
561 static void gwps_leave_wps(void)
567 gui_wps
[i
].display
->stop_scroll();
568 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
569 gui_wps
[i
].display
->backdrop_show(sb_get_backdrop(i
));
572 #ifdef HAVE_LCD_BITMAP
574 if (gui_wps
[i
].data
->wps_sb_tag
)
575 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
576 else if (statusbar_position(i
) != STATUSBAR_OFF
)
579 viewportmanager_theme_undo(i
, draw
);
583 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
584 /* Play safe and unregister the hook */
585 remove_event(LCD_EVENT_ACTIVATION
, wps_lcd_activation_hook
);
587 /* unhandle statusbar update delay */
588 sb_skin_set_update_delay(DEFAULT_UPDATE_DELAY
);
592 * display the wps on entering or restoring */
593 static void gwps_enter_wps(void)
598 struct gui_wps
*gwps
= &gui_wps
[i
];
599 struct screen
*display
= gwps
->display
;
600 #ifdef HAVE_LCD_BITMAP
602 if (gui_wps
[i
].data
->wps_sb_tag
)
603 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
604 else if (statusbar_position(i
) != STATUSBAR_OFF
)
607 display
->stop_scroll();
608 viewportmanager_theme_enable(i
, draw
, NULL
);
610 /* Update the values in the first (default) viewport - in case the user
611 has modified the statusbar or colour settings */
613 if (display
->depth
> 1)
615 struct viewport
*vp
= &find_viewport(VP_DEFAULT_LABEL
, gwps
->data
)->vp
;
616 vp
->fg_pattern
= display
->get_foreground();
617 vp
->bg_pattern
= display
->get_background();
620 /* make the backdrop actually take effect */
621 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
622 display
->backdrop_show(gwps
->data
->backdrop
);
624 display
->clear_display();
625 skin_update(gwps
, WPS_REFRESH_ALL
);
627 /* force statusbar/skin update since we just cleared the whole screen */
628 send_event(GUI_EVENT_ACTIONUPDATE
, (void*)1);
631 #ifdef HAVE_TOUCHSCREEN
632 int wps_get_touchaction(struct wps_data
*data
)
636 int type
= action_get_touchscreen_press(&x
, &y
);
637 static int last_action
= ACTION_NONE
;
638 struct touchregion
*r
;
639 bool repeated
= (type
== BUTTON_REPEAT
);
640 bool released
= (type
== BUTTON_REL
);
641 struct skin_token_list
*regions
= data
->touchregions
;
644 r
= (struct touchregion
*)regions
->token
->value
.data
;
645 /* make sure this region's viewport is visible */
646 if (r
->wvp
->hidden_flags
&VP_DRAW_HIDDEN
)
648 regions
= regions
->next
;
651 /* check if it's inside this viewport */
652 if (viewport_point_within_vp(&(r
->wvp
->vp
), x
, y
))
653 { /* reposition the touch inside the viewport since touchregions
654 * are relative to a preceding viewport */
655 vx
= x
- r
->wvp
->vp
.x
;
656 vy
= y
- r
->wvp
->vp
.y
;
657 /* now see if the point is inside this region */
658 if (vx
>= r
->x
&& vx
< r
->x
+r
->width
&&
659 vy
>= r
->y
&& vy
< r
->y
+r
->height
)
661 /* reposition the touch within the area */
667 case WPS_TOUCHREGION_ACTION
:
668 if ((repeated
&& r
->repeat
) || (released
&& !r
->repeat
))
670 last_action
= r
->action
;
674 case WPS_TOUCHREGION_SCROLLBAR
:
675 if(r
->width
> r
->height
)
677 wps_state
.id3
->elapsed
= (vx
*
678 wps_state
.id3
->length
) / r
->width
;
681 wps_state
.id3
->elapsed
= (vy
*
682 wps_state
.id3
->length
) / r
->height
;
684 if (!wps_state
.paused
)
685 #if (CONFIG_CODEC == SWCODEC)
686 audio_pre_ff_rewind();
690 audio_ff_rewind(wps_state
.id3
->elapsed
);
691 #if (CONFIG_CODEC != SWCODEC)
692 if (!wps_state
.paused
)
696 case WPS_TOUCHREGION_VOLUME
:
698 const int min_vol
= sound_min(SOUND_VOLUME
);
699 const int max_vol
= sound_max(SOUND_VOLUME
);
700 if(r
->width
> r
->height
)
702 global_settings
.volume
= (vx
*
703 (max_vol
- min_vol
)) / r
->width
;
706 global_settings
.volume
= ((r
->height
- vy
) *
707 (max_vol
-min_vol
)) / r
->height
;
709 global_settings
.volume
+= min_vol
;
711 return ACTION_REDRAW
;
716 regions
= regions
->next
;
719 if ((last_action
== ACTION_WPS_SEEKBACK
|| last_action
== ACTION_WPS_SEEKFWD
))
720 return ACTION_WPS_STOPSEEK
;
721 last_action
= ACTION_TOUCHSCREEN
;
722 return ACTION_TOUCHSCREEN
;
725 /* The WPS can be left in two ways:
726 * a) call a function, which draws over the wps. In this case, the wps
727 * will be still active (i.e. the below function didn't return)
728 * b) return with a value evaluated by root_menu.c, in this case the wps
729 * is really left, and root_menu will handle the next screen
731 * In either way, call gwps_leave_wps(), in order to restore the correct
732 * "main screen" backdrops and statusbars
734 long gui_wps_show(void)
738 long restoretimer
= RESTORE_WPS_INSTANTLY
; /* timer to delay screen redraw temporarily */
740 bool bookmark
= false;
742 bool vol_changed
= false;
744 long last_left
= 0, last_right
= 0;
746 #ifdef HAVE_LCD_CHARCELLS
747 status_set_audio(true);
748 status_set_param(false);
751 #ifdef AB_REPEAT_ENABLE
759 bool audio_paused
= (audio_status() & AUDIO_STATUS_PAUSE
)?true:false;
761 /* did someone else (i.e power thread) change audio pause mode? */
762 if (wps_state
.paused
!= audio_paused
) {
763 wps_state
.paused
= audio_paused
;
765 /* if another thread paused audio, we are probably in car mode,
766 about to shut down. lets save the settings. */
767 if (wps_state
.paused
) {
769 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
770 call_storage_idle_notifys(true);
774 #ifdef HAVE_LCD_BITMAP
775 /* when the peak meter is enabled we want to have a
776 few extra updates to make it look smooth. On the
777 other hand we don't want to waste energy if it
782 if(gui_wps
[i
].data
->peak_meter_enabled
)
787 long next_refresh
= current_tick
;
788 long next_big_refresh
= current_tick
+ HZ
/ 5;
789 button
= BUTTON_NONE
;
790 while (TIME_BEFORE(current_tick
, next_big_refresh
)) {
791 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_NOBLOCK
);
792 /* check for restore to not let the peakmeter delay the
793 * initial draw of the wps, don't delay handling of button
795 if (button
!= ACTION_NONE
|| restore
) {
799 sleep(0); /* Sleep until end of current tick. */
801 if (TIME_AFTER(current_tick
, next_refresh
)) {
804 if(gui_wps
[i
].data
->peak_meter_enabled
)
805 skin_update(&gui_wps
[i
], WPS_REFRESH_PEAK_METER
);
806 next_refresh
+= HZ
/ PEAK_METER_FPS
;
813 /* The peak meter is disabled
814 -> no additional screen updates needed */
817 { /* 1 is the minimum timeout which lets other threads run.
818 * audio thread (apprently) needs to run before displaying the wps
819 * or bad things happen with regards to cuesheet
820 * (probably a race condition, on sh at least) */
821 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,
825 /* Exit if audio has stopped playing. This happens e.g. at end of
826 playlist or if using the sleep timer. */
827 if (!(audio_status() & AUDIO_STATUS_PLAY
))
829 #ifdef HAVE_TOUCHSCREEN
830 if (button
== ACTION_TOUCHSCREEN
)
831 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
833 /* The iPods/X5/M5 use a single button for the A-B mode markers,
834 defined as ACTION_WPSAB_SINGLE in their config files. */
835 #ifdef ACTION_WPSAB_SINGLE
836 if (!global_settings
.party_mode
&& ab_repeat_mode_enabled())
838 static int wps_ab_state
= 0;
839 if (button
== ACTION_WPSAB_SINGLE
)
841 switch (wps_ab_state
)
843 case 0: /* set the A spot */
844 button
= ACTION_WPS_ABSETA_PREVDIR
;
846 case 1: /* set the B spot */
847 button
= ACTION_WPS_ABSETB_NEXTDIR
;
850 button
= ACTION_WPS_ABRESET
;
853 wps_ab_state
= (wps_ab_state
+1) % 3;
859 case ACTION_WPS_CONTEXT
:
862 /* if music is stopped in the context menu we want to exit the wps */
863 if (onplay(wps_state
.id3
->path
,
864 FILE_ATTR_AUDIO
, CONTEXT_WPS
) == ONPLAY_MAINMENU
871 case ACTION_WPS_BROWSE
:
872 #ifdef HAVE_LCD_CHARCELLS
873 status_set_record(false);
874 status_set_audio(false);
877 return GO_TO_PREVIOUS_BROWSER
;
881 case ACTION_WPS_PLAY
:
882 if (global_settings
.party_mode
)
884 if ( wps_state
.paused
)
886 wps_state
.paused
= false;
887 if ( global_settings
.fade_on_stop
)
894 wps_state
.paused
= true;
895 if ( global_settings
.fade_on_stop
)
900 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
901 call_storage_idle_notifys(true); /* make sure resume info is saved */
906 case ACTION_WPS_VOLUP
:
907 global_settings
.volume
++;
910 case ACTION_WPS_VOLDOWN
:
911 global_settings
.volume
--;
915 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
916 case ACTION_WPS_SEEKFWD
:
917 if (global_settings
.party_mode
)
919 if (current_tick
-last_right
< HZ
)
921 if (wps_state
.id3
->cuesheet
)
931 ffwd_rew(ACTION_WPS_SEEKFWD
);
932 last_right
= last_left
= 0;
935 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
936 case ACTION_WPS_SEEKBACK
:
937 if (global_settings
.party_mode
)
939 if (current_tick
-last_left
< HZ
)
941 if (wps_state
.id3
->cuesheet
)
943 if (!wps_state
.paused
)
944 #if (CONFIG_CODEC == SWCODEC)
945 audio_pre_ff_rewind();
957 ffwd_rew(ACTION_WPS_SEEKBACK
);
958 last_left
= last_right
= 0;
962 case ACTION_WPS_SKIPPREV
:
963 if (global_settings
.party_mode
)
965 last_left
= current_tick
;
966 #ifdef AB_REPEAT_ENABLE
967 /* if we're in A/B repeat mode and the current position
968 is past the A marker, jump back to the A marker... */
969 if ( ab_repeat_mode_enabled() )
971 if ( ab_after_A_marker(wps_state
.id3
->elapsed
) )
973 ab_jump_to_A_marker();
975 #if (AB_REPEAT_ENABLE == 2)
982 /* ...otherwise, do it normally */
988 OR if skip length set, hop by predetermined amount. */
989 case ACTION_WPS_SKIPNEXT
:
990 if (global_settings
.party_mode
)
992 last_right
= current_tick
;
993 #ifdef AB_REPEAT_ENABLE
994 /* if we're in A/B repeat mode and the current position is
995 before the A marker, jump to the A marker... */
996 if ( ab_repeat_mode_enabled() )
998 if ( ab_before_A_marker(wps_state
.id3
->elapsed
) )
1000 ab_jump_to_A_marker();
1002 #if (AB_REPEAT_ENABLE == 2)
1009 /* ...otherwise, do it normally */
1013 /* next / prev directories */
1014 /* and set A-B markers if in a-b mode */
1015 case ACTION_WPS_ABSETB_NEXTDIR
:
1016 if (global_settings
.party_mode
)
1018 #if defined(AB_REPEAT_ENABLE)
1019 if (ab_repeat_mode_enabled())
1021 ab_set_B_marker(wps_state
.id3
->elapsed
);
1022 ab_jump_to_A_marker();
1030 case ACTION_WPS_ABSETA_PREVDIR
:
1031 if (global_settings
.party_mode
)
1033 #if defined(AB_REPEAT_ENABLE)
1034 if (ab_repeat_mode_enabled())
1035 ab_set_A_marker(wps_state
.id3
->elapsed
);
1042 /* menu key functions */
1043 case ACTION_WPS_MENU
:
1049 #ifdef HAVE_QUICKSCREEN
1050 case ACTION_WPS_QUICKSCREEN
:
1053 if (quick_screen_quick(button
))
1058 #endif /* HAVE_QUICKSCREEN */
1060 /* screen settings */
1065 if (quick_screen_f3(BUTTON_F3
))
1070 #endif /* BUTTON_F3 */
1073 #ifdef HAVE_PITCHSCREEN
1074 case ACTION_WPS_PITCHSCREEN
:
1077 if (1 == gui_syncpitchscreen_run())
1082 #endif /* HAVE_PITCHSCREEN */
1084 #ifdef AB_REPEAT_ENABLE
1085 /* reset A&B markers */
1086 case ACTION_WPS_ABRESET
:
1087 if (ab_repeat_mode_enabled())
1093 #endif /* AB_REPEAT_ENABLE */
1095 /* stop and exit wps */
1096 case ACTION_WPS_STOP
:
1097 if (global_settings
.party_mode
)
1103 case ACTION_WPS_ID3SCREEN
:
1111 #ifdef HAVE_TOUCHSCREEN
1112 case ACTION_TOUCH_SHUFFLE
: /* toggle shuffle mode */
1114 global_settings
.playlist_shuffle
=
1115 !global_settings
.playlist_shuffle
;
1116 #if CONFIG_CODEC == SWCODEC
1117 dsp_set_replaygain();
1119 if (global_settings
.playlist_shuffle
)
1120 playlist_randomise(NULL
, current_tick
, true);
1122 playlist_sort(NULL
, true);
1125 case ACTION_TOUCH_REPMODE
: /* cycle the repeat mode setting */
1127 const struct settings_list
*rep_setting
=
1128 find_setting(&global_settings
.repeat_mode
, NULL
);
1129 option_select_next_val(rep_setting
, false, true);
1130 audio_flush_and_reload_tracks();
1133 #endif /* HAVE_TOUCHSCREEN */
1134 /* this case is used by the softlock feature
1135 * it requests a full update here */
1137 wps_sync_data
.do_full_update
= true;
1139 case ACTION_NONE
: /* Timeout, do a partial update */
1141 ffwd_rew(button
); /* hopefully fix the ffw/rwd bug */
1143 #ifdef HAVE_RECORDING
1144 case ACTION_WPS_REC
:
1149 default_event_handler(SYS_POWEROFF
);
1151 case ACTION_WPS_VIEW_PLAYLIST
:
1153 if (playlist_viewer()) /* true if USB connected */
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_REFRESH_NON_STATIC
);
1215 wps_sync_data
.do_full_update
= false;
1220 #ifdef HAVE_LCD_CHARCELLS
1221 status_set_record(false);
1222 status_set_audio(false);
1224 if (global_settings
.fade_on_stop
)
1228 bookmark_autobookmark();
1230 #ifdef AB_REPEAT_ENABLE
1234 #ifdef HAVE_RECORDING
1235 if (button
== ACTION_WPS_REC
)
1236 return GO_TO_RECSCREEN
;
1238 if (global_settings
.browse_current
)
1239 return GO_TO_PREVIOUS_BROWSER
;
1240 return GO_TO_PREVIOUS
;
1243 if (button
&& !IS_SYSEVENT(button
) )
1246 return GO_TO_ROOT
; /* unreachable - just to reduce compiler warnings */
1249 /* this is called from the playback thread so NO DRAWING! */
1250 static void track_changed_callback(void *param
)
1252 wps_state
.id3
= (struct mp3entry
*)param
;
1253 wps_state
.nid3
= audio_next_track();
1254 if (wps_state
.id3
->cuesheet
)
1256 cue_find_current_track(wps_state
.id3
->cuesheet
, wps_state
.id3
->elapsed
);
1257 cue_spoof_id3(wps_state
.id3
->cuesheet
, wps_state
.id3
);
1259 wps_sync_data
.do_full_update
= true;
1261 static void nextid3available_callback(void* param
)
1264 wps_state
.nid3
= audio_next_track();
1265 wps_sync_data
.do_full_update
= true;
1269 static void wps_state_init(void)
1271 wps_state
.ff_rewind
= false;
1272 wps_state
.paused
= false;
1273 if(audio_status() & AUDIO_STATUS_PLAY
)
1275 wps_state
.id3
= audio_current_track();
1276 wps_state
.nid3
= audio_next_track();
1280 wps_state
.id3
= NULL
;
1281 wps_state
.nid3
= NULL
;
1283 /* We'll be updating due to restore initialized with true */
1284 wps_sync_data
.do_full_update
= false;
1285 /* add the WPS track event callbacks */
1286 add_event(PLAYBACK_EVENT_TRACK_CHANGE
, false, track_changed_callback
);
1287 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, false, nextid3available_callback
);
1291 void gui_sync_wps_init(void)
1296 #ifdef HAVE_ALBUMART
1297 wps_datas
[i
].albumart
= NULL
;
1298 wps_datas
[i
].playback_aa_slot
= -1;
1300 gui_wps
[i
].data
= &wps_datas
[i
];
1301 gui_wps
[i
].display
= &screens
[i
];
1302 /* Currently no seperate wps_state needed/possible
1303 so use the only available ( "global" ) one */
1304 gui_wps
[i
].state
= &wps_state
;
1305 /* must point to the same struct for both screens */
1306 gui_wps
[i
].sync_data
= &wps_sync_data
;
1311 #ifdef IPOD_ACCESSORY_PROTOCOL
1312 bool is_wps_fading(void)
1314 return wps_state
.is_fading
;
1317 int wps_get_ff_rewind_count(void)
1319 return wps_state
.ff_rewind_count
;