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
)
102 screens
[screen
].backdrop_unload(BACKDROP_SKIN_WPS
);
106 * Hardcode loading WPS_DEFAULTCFG to cause a reset ideally this
107 * wants to be a virtual file. Feel free to modify dirbrowse()
108 * if you're feeling brave.
111 if (buf
&& ! strcmp(buf
, DEFAULT_WPS(screen
)) )
113 #ifdef HAVE_REMOTE_LCD
114 if (screen
== SCREEN_REMOTE
)
115 global_settings
.rwps_file
[0] = '\0';
118 global_settings
.wps_file
[0] = '\0';
122 #endif /* __PCTOOL__ */
124 loaded_ok
= buf
&& skin_data_load(screen
, gui_wps
[screen
].data
, buf
, isfile
);
126 if (!loaded_ok
) /* load the hardcoded default */
128 char *skin_buf
[NB_SCREENS
] = {
129 #ifdef HAVE_LCD_BITMAP
130 "%s%?it<%?in<%in. |>%it|%fn>\n"
131 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
132 "%s%?id<%id|%?d1<%d1|(root)>> %?iy<(%iy)|>\n\n"
133 "%al%pc/%pt%ar[%pp:%pe]\n"
134 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
137 "%s%pp/%pe: %?it<%it|%fn> - %?ia<%ia|%d2> - %?id<%id|%d1>\n"
140 #ifdef HAVE_REMOTE_LCD
141 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
142 "%s%?it<%?in<%in. |>%it|%fn>\n"
143 "%al%pc/%pt%ar[%pp:%pe]\n"
144 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
148 skin_data_load(screen
, gui_wps
[screen
].data
, skin_buf
[screen
], false);
152 void fade(bool fade_in
, bool updatewps
)
154 int fp_global_vol
= global_settings
.volume
<< 8;
155 int fp_min_vol
= sound_min(SOUND_VOLUME
) << 8;
156 int fp_step
= (fp_global_vol
- fp_min_vol
) / 30;
158 wps_state
.is_fading
= !fade_in
;
161 int fp_volume
= fp_min_vol
;
163 /* zero out the sound */
164 sound_set_volume(fp_min_vol
>> 8);
166 sleep(HZ
/10); /* let audio thread run */
169 while (fp_volume
< fp_global_vol
- fp_step
) {
170 fp_volume
+= fp_step
;
171 sound_set_volume(fp_volume
>> 8);
175 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
179 sound_set_volume(global_settings
.volume
);
183 int fp_volume
= fp_global_vol
;
185 while (fp_volume
> fp_min_vol
+ fp_step
) {
186 fp_volume
-= fp_step
;
187 sound_set_volume(fp_volume
>> 8);
191 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
196 wps_state
.is_fading
= false;
197 #if CONFIG_CODEC != SWCODEC
199 /* let audio thread run and wait for the mas to run out of data */
200 while (!mp3_pause_done())
205 /* reset volume to what it was before the fade */
206 sound_set_volume(global_settings
.volume
);
210 static bool update_onvol_change(struct gui_wps
* gwps
)
212 skin_update(gwps
, WPS_REFRESH_NON_STATIC
);
214 #ifdef HAVE_LCD_CHARCELLS
215 splashf(0, "Vol: %3d dB",
216 sound_val2phys(SOUND_VOLUME
, global_settings
.volume
));
223 bool ffwd_rew(int button
)
225 unsigned int step
= 0; /* current ff/rewind step */
226 unsigned int max_step
= 0; /* maximum ff/rewind step */
227 int ff_rewind_count
= 0; /* current ff/rewind count (in ticks) */
228 int direction
= -1; /* forward=1 or backward=-1 */
232 const long ff_rw_accel
= (global_settings
.ff_rewind_accel
+ 3);
234 if (button
== ACTION_NONE
)
236 status_set_ffmode(0);
243 case ACTION_WPS_SEEKFWD
:
245 case ACTION_WPS_SEEKBACK
:
246 if (wps_state
.ff_rewind
)
250 /* fast forwarding, calc max step relative to end */
251 max_step
= (wps_state
.id3
->length
-
252 (wps_state
.id3
->elapsed
+
254 FF_REWIND_MAX_PERCENT
/ 100;
258 /* rewinding, calc max step relative to start */
259 max_step
= (wps_state
.id3
->elapsed
+ ff_rewind_count
) *
260 FF_REWIND_MAX_PERCENT
/ 100;
263 max_step
= MAX(max_step
, MIN_FF_REWIND_STEP
);
268 ff_rewind_count
+= step
* direction
;
270 /* smooth seeking by multiplying step by: 1 + (2 ^ -accel) */
271 step
+= step
>> ff_rw_accel
;
275 if ( (audio_status() & AUDIO_STATUS_PLAY
) &&
276 wps_state
.id3
&& wps_state
.id3
->length
)
278 if (!wps_state
.paused
)
279 #if (CONFIG_CODEC == SWCODEC)
280 audio_pre_ff_rewind();
284 #if CONFIG_KEYPAD == PLAYER_PAD
286 gui_wps
[i
].display
->stop_scroll();
289 status_set_ffmode(STATUS_FASTFORWARD
);
291 status_set_ffmode(STATUS_FASTBACKWARD
);
293 wps_state
.ff_rewind
= true;
295 step
= 1000 * global_settings
.ff_rewind_min_step
;
302 if ((wps_state
.id3
->elapsed
+ ff_rewind_count
) >
303 wps_state
.id3
->length
)
304 ff_rewind_count
= wps_state
.id3
->length
-
305 wps_state
.id3
->elapsed
;
308 if ((int)(wps_state
.id3
->elapsed
+ ff_rewind_count
) < 0)
309 ff_rewind_count
= -wps_state
.id3
->elapsed
;
312 /* set the wps state ff_rewind_count so the progess info
314 wps_state
.ff_rewind_count
= (wps_state
.wps_time_countup
== false)?
315 ff_rewind_count
:-ff_rewind_count
;
318 skin_update(&gui_wps
[i
],
319 WPS_REFRESH_PLAYER_PROGRESS
|
320 WPS_REFRESH_DYNAMIC
);
325 case ACTION_WPS_STOPSEEK
:
326 wps_state
.id3
->elapsed
= wps_state
.id3
->elapsed
+ff_rewind_count
;
327 audio_ff_rewind(wps_state
.id3
->elapsed
);
328 wps_state
.ff_rewind_count
= 0;
329 wps_state
.ff_rewind
= false;
330 status_set_ffmode(0);
331 #if (CONFIG_CODEC != SWCODEC)
332 if (!wps_state
.paused
)
335 #ifdef HAVE_LCD_CHARCELLS
337 skin_update(&gui_wps
[i
], WPS_REFRESH_ALL
);
343 if(default_event_handler(button
) == SYS_USB_CONNECTED
) {
344 status_set_ffmode(0);
352 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_BLOCK
);
353 #ifdef HAVE_TOUCHSCREEN
354 if (button
== ACTION_TOUCHSCREEN
)
355 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
363 void display_keylock_text(bool locked
)
367 gui_wps
[i
].display
->stop_scroll();
369 splash(HZ
, locked
? ID2P(LANG_KEYLOCK_ON
) : ID2P(LANG_KEYLOCK_OFF
));
375 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
376 static void gwps_caption_backlight(struct wps_state
*state
)
378 if (state
&& state
->id3
)
380 #ifdef HAVE_BACKLIGHT
381 if (global_settings
.caption_backlight
)
383 /* turn on backlight n seconds before track ends, and turn it off n
384 seconds into the new track. n == backlight_timeout, or 5s */
385 int n
= global_settings
.backlight_timeout
* 1000;
388 n
= 5000; /* use 5s if backlight is always on or off */
390 if (((state
->id3
->elapsed
< 1000) ||
391 ((state
->id3
->length
- state
->id3
->elapsed
) < (unsigned)n
)) &&
392 (state
->paused
== false))
396 #ifdef HAVE_REMOTE_LCD
397 if (global_settings
.remote_caption_backlight
)
399 /* turn on remote backlight n seconds before track ends, and turn it
400 off n seconds into the new track. n == remote_backlight_timeout,
402 int n
= global_settings
.remote_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))
410 remote_backlight_on();
418 static void change_dir(int direction
)
420 if (global_settings
.prevent_skip
)
425 else if (direction
> 0)
427 /* prevent the next dir to immediatly start being ffw'd */
428 action_wait_for_release();
431 static void prev_track(unsigned long skip_thresh
)
433 if (wps_state
.id3
->elapsed
< skip_thresh
)
440 if (wps_state
.id3
->cuesheet
)
442 curr_cuesheet_skip(wps_state
.id3
->cuesheet
, -1, wps_state
.id3
->elapsed
);
446 if (!wps_state
.paused
)
447 #if (CONFIG_CODEC == SWCODEC)
448 audio_pre_ff_rewind();
455 #if (CONFIG_CODEC != SWCODEC)
456 if (!wps_state
.paused
)
462 static void next_track(void)
464 /* take care of if we're playing a cuesheet */
465 if (wps_state
.id3
->cuesheet
)
467 if (curr_cuesheet_skip(wps_state
.id3
->cuesheet
, 1, wps_state
.id3
->elapsed
))
469 /* if the result was false, then we really want
470 to skip to the next track */
478 static void play_hop(int direction
)
480 long step
= global_settings
.skip_length
*1000;
481 long elapsed
= wps_state
.id3
->elapsed
;
482 long remaining
= wps_state
.id3
->length
- elapsed
;
488 prev_track(DEFAULT_SKIP_TRESH
);
491 else if (remaining
< DEFAULT_SKIP_TRESH
*2)
497 elapsed
+= (remaining
- DEFAULT_SKIP_TRESH
*2);
499 else if (!global_settings
.prevent_skip
&&
501 (direction
> 0 && step
>= remaining
) ||
502 (direction
< 0 && elapsed
< DEFAULT_SKIP_TRESH
)))
503 { /* Do normal track skipping */
506 else if (direction
< 0)
507 prev_track(DEFAULT_SKIP_TRESH
);
510 else if (direction
== 1 && step
>= remaining
)
512 #if CONFIG_CODEC == SWCODEC
513 if(global_settings
.beep
)
514 pcmbuf_beep(1000, 150, 1500*global_settings
.beep
);
518 else if ((direction
== -1 && elapsed
< step
))
524 elapsed
+= step
* direction
;
526 if((audio_status() & AUDIO_STATUS_PLAY
) && !wps_state
.paused
)
528 #if (CONFIG_CODEC == SWCODEC)
529 audio_pre_ff_rewind();
534 audio_ff_rewind(wps_state
.id3
->elapsed
= elapsed
);
535 #if (CONFIG_CODEC != SWCODEC)
536 if (!wps_state
.paused
)
542 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
544 * If the user is unable to see the wps, because the display is deactivated,
545 * we suppress updates until the wps is activated again (the lcd driver will
546 * call this hook to issue an instant update)
548 static void wps_lcd_activation_hook(void *param
)
551 wps_sync_data
.do_full_update
= true;
552 /* force timeout in wps main loop, so that the update is instantly */
553 queue_post(&button_queue
, BUTTON_NONE
, 0);
557 static void gwps_leave_wps(void)
563 gui_wps
[i
].display
->stop_scroll();
564 gui_wps
[i
].display
->backdrop_show(BACKDROP_MAIN
);
566 #ifdef HAVE_LCD_BITMAP
568 if (gui_wps
[i
].data
->wps_sb_tag
)
569 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
570 else if (statusbar_position(i
) != STATUSBAR_OFF
)
573 viewportmanager_theme_undo(i
, draw
);
577 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
578 /* Play safe and unregister the hook */
579 remove_event(LCD_EVENT_ACTIVATION
, wps_lcd_activation_hook
);
581 /* unhandle statusbar update delay */
582 sb_skin_set_update_delay(DEFAULT_UPDATE_DELAY
);
586 * display the wps on entering or restoring */
587 static void gwps_enter_wps(void)
592 struct gui_wps
*gwps
= &gui_wps
[i
];
593 struct screen
*display
= gwps
->display
;
594 #ifdef HAVE_LCD_BITMAP
596 if (gui_wps
[i
].data
->wps_sb_tag
)
597 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
598 else if (statusbar_position(i
) != STATUSBAR_OFF
)
601 viewportmanager_theme_enable(i
, draw
, NULL
);
603 display
->stop_scroll();
604 /* Update the values in the first (default) viewport - in case the user
605 has modified the statusbar or colour settings */
607 if (display
->depth
> 1)
609 struct viewport
*vp
= &find_viewport(VP_DEFAULT_LABEL
, gwps
->data
)->vp
;
610 vp
->fg_pattern
= display
->get_foreground();
611 vp
->bg_pattern
= display
->get_background();
614 skin_update(gwps
, WPS_REFRESH_ALL
);
618 #ifdef HAVE_TOUCHSCREEN
619 int wps_get_touchaction(struct wps_data
*data
)
623 int type
= action_get_touchscreen_press(&x
, &y
);
624 static int last_action
= ACTION_NONE
;
625 struct touchregion
*r
;
626 bool repeated
= (type
== BUTTON_REPEAT
);
627 bool released
= (type
== BUTTON_REL
);
628 struct skin_token_list
*regions
= data
->touchregions
;
631 r
= (struct touchregion
*)regions
->token
->value
.data
;
632 /* make sure this region's viewport is visible */
633 if (r
->wvp
->hidden_flags
&VP_DRAW_HIDDEN
)
635 regions
= regions
->next
;
638 /* check if it's inside this viewport */
639 if (viewport_point_within_vp(&(r
->wvp
->vp
), x
, y
))
640 { /* reposition the touch inside the viewport since touchregions
641 * are relative to a preceding viewport */
642 vx
= x
- r
->wvp
->vp
.x
;
643 vy
= y
- r
->wvp
->vp
.y
;
644 /* now see if the point is inside this region */
645 if (vx
>= r
->x
&& vx
< r
->x
+r
->width
&&
646 vy
>= r
->y
&& vy
< r
->y
+r
->height
)
648 /* reposition the touch within the area */
654 case WPS_TOUCHREGION_ACTION
:
655 if ((repeated
&& r
->repeat
) || (released
&& !r
->repeat
))
657 last_action
= r
->action
;
661 case WPS_TOUCHREGION_SCROLLBAR
:
662 if(r
->width
> r
->height
)
664 wps_state
.id3
->elapsed
= (vx
*
665 wps_state
.id3
->length
) / r
->width
;
668 wps_state
.id3
->elapsed
= (vy
*
669 wps_state
.id3
->length
) / r
->height
;
671 if (!wps_state
.paused
)
672 #if (CONFIG_CODEC == SWCODEC)
673 audio_pre_ff_rewind();
677 audio_ff_rewind(wps_state
.id3
->elapsed
);
678 #if (CONFIG_CODEC != SWCODEC)
679 if (!wps_state
.paused
)
683 case WPS_TOUCHREGION_VOLUME
:
685 const int min_vol
= sound_min(SOUND_VOLUME
);
686 const int max_vol
= sound_max(SOUND_VOLUME
);
687 if(r
->width
> r
->height
)
689 global_settings
.volume
= (vx
*
690 (max_vol
- min_vol
)) / r
->width
;
693 global_settings
.volume
= (vy
*
694 (max_vol
-min_vol
)) / r
->height
;
696 global_settings
.volume
+= min_vol
;
698 return ACTION_REDRAW
;
703 regions
= regions
->next
;
706 if ((last_action
== ACTION_WPS_SEEKBACK
|| last_action
== ACTION_WPS_SEEKFWD
))
707 return ACTION_WPS_STOPSEEK
;
708 last_action
= ACTION_TOUCHSCREEN
;
709 return ACTION_TOUCHSCREEN
;
712 /* The WPS can be left in two ways:
713 * a) call a function, which draws over the wps. In this case, the wps
714 * will be still active (i.e. the below function didn't return)
715 * b) return with a value evaluated by root_menu.c, in this case the wps
716 * is really left, and root_menu will handle the next screen
718 * In either way, call gwps_leave_wps(), in order to restore the correct
719 * "main screen" backdrops and statusbars
721 long gui_wps_show(void)
725 long restoretimer
= RESTORE_WPS_INSTANTLY
; /* timer to delay screen redraw temporarily */
727 bool bookmark
= false;
729 bool vol_changed
= false;
731 long last_left
= 0, last_right
= 0;
733 #ifdef HAVE_LCD_CHARCELLS
734 status_set_audio(true);
735 status_set_param(false);
738 #ifdef AB_REPEAT_ENABLE
746 bool audio_paused
= (audio_status() & AUDIO_STATUS_PAUSE
)?true:false;
748 /* did someone else (i.e power thread) change audio pause mode? */
749 if (wps_state
.paused
!= audio_paused
) {
750 wps_state
.paused
= audio_paused
;
752 /* if another thread paused audio, we are probably in car mode,
753 about to shut down. lets save the settings. */
754 if (wps_state
.paused
) {
756 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
757 call_storage_idle_notifys(true);
761 #ifdef HAVE_LCD_BITMAP
762 /* when the peak meter is enabled we want to have a
763 few extra updates to make it look smooth. On the
764 other hand we don't want to waste energy if it
769 if(gui_wps
[i
].data
->peak_meter_enabled
)
774 long next_refresh
= current_tick
;
775 long next_big_refresh
= current_tick
+ HZ
/ 5;
776 button
= BUTTON_NONE
;
777 while (TIME_BEFORE(current_tick
, next_big_refresh
)) {
778 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_NOBLOCK
);
779 /* check for restore to not let the peakmeter delay the
780 * initial draw of the wps, don't delay handling of button
782 if (button
!= ACTION_NONE
|| restore
) {
786 sleep(0); /* Sleep until end of current tick. */
788 if (TIME_AFTER(current_tick
, next_refresh
)) {
791 if(gui_wps
[i
].data
->peak_meter_enabled
)
792 skin_update(&gui_wps
[i
], WPS_REFRESH_PEAK_METER
);
793 next_refresh
+= HZ
/ PEAK_METER_FPS
;
800 /* The peak meter is disabled
801 -> no additional screen updates needed */
804 { /* 1 is the minimum timeout which lets other threads run.
805 * audio thread (apprently) needs to run before displaying the wps
806 * or bad things happen with regards to cuesheet
807 * (probably a race condition, on sh at least) */
808 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,
812 /* Exit if audio has stopped playing. This happens e.g. at end of
813 playlist or if using the sleep timer. */
814 if (!(audio_status() & AUDIO_STATUS_PLAY
))
816 #ifdef HAVE_TOUCHSCREEN
817 if (button
== ACTION_TOUCHSCREEN
)
818 button
= wps_get_touchaction(gui_wps
[SCREEN_MAIN
].data
);
820 /* The iPods/X5/M5 use a single button for the A-B mode markers,
821 defined as ACTION_WPSAB_SINGLE in their config files. */
822 #ifdef ACTION_WPSAB_SINGLE
823 if (!global_settings
.party_mode
&& ab_repeat_mode_enabled())
825 static int wps_ab_state
= 0;
826 if (button
== ACTION_WPSAB_SINGLE
)
828 switch (wps_ab_state
)
830 case 0: /* set the A spot */
831 button
= ACTION_WPS_ABSETA_PREVDIR
;
833 case 1: /* set the B spot */
834 button
= ACTION_WPS_ABSETB_NEXTDIR
;
837 button
= ACTION_WPS_ABRESET
;
840 wps_ab_state
= (wps_ab_state
+1) % 3;
846 case ACTION_WPS_CONTEXT
:
849 /* if music is stopped in the context menu we want to exit the wps */
850 if (onplay(wps_state
.id3
->path
,
851 FILE_ATTR_AUDIO
, CONTEXT_WPS
) == ONPLAY_MAINMENU
858 case ACTION_WPS_BROWSE
:
859 #ifdef HAVE_LCD_CHARCELLS
860 status_set_record(false);
861 status_set_audio(false);
864 return GO_TO_PREVIOUS_BROWSER
;
868 case ACTION_WPS_PLAY
:
869 if (global_settings
.party_mode
)
871 if ( wps_state
.paused
)
873 wps_state
.paused
= false;
874 if ( global_settings
.fade_on_stop
)
881 wps_state
.paused
= true;
882 if ( global_settings
.fade_on_stop
)
887 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
888 call_storage_idle_notifys(true); /* make sure resume info is saved */
893 case ACTION_WPS_VOLUP
:
894 global_settings
.volume
++;
897 case ACTION_WPS_VOLDOWN
:
898 global_settings
.volume
--;
902 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
903 case ACTION_WPS_SEEKFWD
:
904 if (global_settings
.party_mode
)
906 if (current_tick
-last_right
< HZ
)
908 if (wps_state
.id3
->cuesheet
)
918 ffwd_rew(ACTION_WPS_SEEKFWD
);
919 last_right
= last_left
= 0;
922 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
923 case ACTION_WPS_SEEKBACK
:
924 if (global_settings
.party_mode
)
926 if (current_tick
-last_left
< HZ
)
928 if (wps_state
.id3
->cuesheet
)
930 if (!wps_state
.paused
)
931 #if (CONFIG_CODEC == SWCODEC)
932 audio_pre_ff_rewind();
944 ffwd_rew(ACTION_WPS_SEEKBACK
);
945 last_left
= last_right
= 0;
949 case ACTION_WPS_SKIPPREV
:
950 if (global_settings
.party_mode
)
952 last_left
= current_tick
;
953 #ifdef AB_REPEAT_ENABLE
954 /* if we're in A/B repeat mode and the current position
955 is past the A marker, jump back to the A marker... */
956 if ( ab_repeat_mode_enabled() )
958 if ( ab_after_A_marker(wps_state
.id3
->elapsed
) )
960 ab_jump_to_A_marker();
962 #if (AB_REPEAT_ENABLE == 2)
969 /* ...otherwise, do it normally */
975 OR if skip length set, hop by predetermined amount. */
976 case ACTION_WPS_SKIPNEXT
:
977 if (global_settings
.party_mode
)
979 last_right
= current_tick
;
980 #ifdef AB_REPEAT_ENABLE
981 /* if we're in A/B repeat mode and the current position is
982 before the A marker, jump to the A marker... */
983 if ( ab_repeat_mode_enabled() )
985 if ( ab_before_A_marker(wps_state
.id3
->elapsed
) )
987 ab_jump_to_A_marker();
989 #if (AB_REPEAT_ENABLE == 2)
996 /* ...otherwise, do it normally */
1000 /* next / prev directories */
1001 /* and set A-B markers if in a-b mode */
1002 case ACTION_WPS_ABSETB_NEXTDIR
:
1003 if (global_settings
.party_mode
)
1005 #if defined(AB_REPEAT_ENABLE)
1006 if (ab_repeat_mode_enabled())
1008 ab_set_B_marker(wps_state
.id3
->elapsed
);
1009 ab_jump_to_A_marker();
1017 case ACTION_WPS_ABSETA_PREVDIR
:
1018 if (global_settings
.party_mode
)
1020 #if defined(AB_REPEAT_ENABLE)
1021 if (ab_repeat_mode_enabled())
1022 ab_set_A_marker(wps_state
.id3
->elapsed
);
1029 /* menu key functions */
1030 case ACTION_WPS_MENU
:
1036 #ifdef HAVE_QUICKSCREEN
1037 case ACTION_WPS_QUICKSCREEN
:
1040 if (quick_screen_quick(button
))
1045 #endif /* HAVE_QUICKSCREEN */
1047 /* screen settings */
1052 if (quick_screen_f3(BUTTON_F3
))
1057 #endif /* BUTTON_F3 */
1060 #ifdef HAVE_PITCHSCREEN
1061 case ACTION_WPS_PITCHSCREEN
:
1064 if (1 == gui_syncpitchscreen_run())
1069 #endif /* HAVE_PITCHSCREEN */
1071 #ifdef AB_REPEAT_ENABLE
1072 /* reset A&B markers */
1073 case ACTION_WPS_ABRESET
:
1074 if (ab_repeat_mode_enabled())
1080 #endif /* AB_REPEAT_ENABLE */
1082 /* stop and exit wps */
1083 case ACTION_WPS_STOP
:
1084 if (global_settings
.party_mode
)
1090 case ACTION_WPS_ID3SCREEN
:
1098 #ifdef HAVE_TOUCHSCREEN
1099 case ACTION_TOUCH_SHUFFLE
: /* toggle shuffle mode */
1101 global_settings
.playlist_shuffle
=
1102 !global_settings
.playlist_shuffle
;
1103 #if CONFIG_CODEC == SWCODEC
1104 dsp_set_replaygain();
1106 if (global_settings
.playlist_shuffle
)
1107 playlist_randomise(NULL
, current_tick
, true);
1109 playlist_sort(NULL
, true);
1112 case ACTION_TOUCH_REPMODE
: /* cycle the repeat mode setting */
1114 const struct settings_list
*rep_setting
=
1115 find_setting(&global_settings
.repeat_mode
, NULL
);
1116 option_select_next_val(rep_setting
, false, true);
1117 audio_flush_and_reload_tracks();
1120 #endif /* HAVE_TOUCHSCREEN */
1121 /* this case is used by the softlock feature
1122 * it requests a full update here */
1124 wps_sync_data
.do_full_update
= true;
1126 case ACTION_NONE
: /* Timeout, do a partial update */
1128 ffwd_rew(button
); /* hopefully fix the ffw/rwd bug */
1130 #ifdef HAVE_RECORDING
1131 case ACTION_WPS_REC
:
1136 default_event_handler(SYS_POWEROFF
);
1138 case ACTION_WPS_VIEW_PLAYLIST
:
1140 if (playlist_viewer()) /* true if USB connected */
1145 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1157 vol_changed
= false;
1161 if(update_onvol_change(&gui_wps
[i
]))
1166 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
1172 ((restoretimer
== RESTORE_WPS_INSTANTLY
) ||
1173 TIME_AFTER(current_tick
, restoretimer
)))
1176 restoretimer
= RESTORE_WPS_INSTANTLY
;
1177 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1178 add_event(LCD_EVENT_ACTIVATION
, false, wps_lcd_activation_hook
);
1180 /* we remove the update delay since it's not very usable in the wps,
1181 * e.g. during volume changing or ffwd/rewind */
1182 sb_skin_set_update_delay(0);
1184 gui_wps
[i
].display
->backdrop_show(BACKDROP_SKIN_WPS
);
1185 wps_sync_data
.do_full_update
= update
= false;
1188 else if (wps_sync_data
.do_full_update
|| update
)
1190 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
1191 gwps_caption_backlight(&wps_state
);
1195 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1196 /* currently, all remotes are readable without backlight
1197 * so still update those */
1198 if (lcd_active() || (i
!= SCREEN_MAIN
))
1201 skin_update(&gui_wps
[i
], WPS_REFRESH_NON_STATIC
);
1204 wps_sync_data
.do_full_update
= false;
1209 #ifdef HAVE_LCD_CHARCELLS
1210 status_set_record(false);
1211 status_set_audio(false);
1213 if (global_settings
.fade_on_stop
)
1217 bookmark_autobookmark();
1219 #ifdef AB_REPEAT_ENABLE
1223 #ifdef HAVE_RECORDING
1224 if (button
== ACTION_WPS_REC
)
1225 return GO_TO_RECSCREEN
;
1227 if (global_settings
.browse_current
)
1228 return GO_TO_PREVIOUS_BROWSER
;
1229 return GO_TO_PREVIOUS
;
1232 if (button
&& !IS_SYSEVENT(button
) )
1235 return GO_TO_ROOT
; /* unreachable - just to reduce compiler warnings */
1238 /* this is called from the playback thread so NO DRAWING! */
1239 static void track_changed_callback(void *param
)
1241 wps_state
.id3
= (struct mp3entry
*)param
;
1242 wps_state
.nid3
= audio_next_track();
1243 if (wps_state
.id3
->cuesheet
)
1245 cue_find_current_track(wps_state
.id3
->cuesheet
, wps_state
.id3
->elapsed
);
1246 cue_spoof_id3(wps_state
.id3
->cuesheet
, wps_state
.id3
);
1248 wps_sync_data
.do_full_update
= true;
1250 static void nextid3available_callback(void* param
)
1253 wps_state
.nid3
= audio_next_track();
1254 wps_sync_data
.do_full_update
= true;
1258 static void wps_state_init(void)
1260 wps_state
.ff_rewind
= false;
1261 wps_state
.paused
= false;
1262 if(audio_status() & AUDIO_STATUS_PLAY
)
1264 wps_state
.id3
= audio_current_track();
1265 wps_state
.nid3
= audio_next_track();
1269 wps_state
.id3
= NULL
;
1270 wps_state
.nid3
= NULL
;
1272 /* We'll be updating due to restore initialized with true */
1273 wps_sync_data
.do_full_update
= false;
1274 /* add the WPS track event callbacks */
1275 add_event(PLAYBACK_EVENT_TRACK_CHANGE
, false, track_changed_callback
);
1276 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE
, false, nextid3available_callback
);
1280 void gui_sync_wps_init(void)
1285 #ifdef HAVE_ALBUMART
1286 wps_datas
[i
].albumart
= NULL
;
1287 wps_datas
[i
].playback_aa_slot
= -1;
1289 gui_wps
[i
].data
= &wps_datas
[i
];
1290 gui_wps
[i
].display
= &screens
[i
];
1291 /* Currently no seperate wps_state needed/possible
1292 so use the only available ( "global" ) one */
1293 gui_wps
[i
].state
= &wps_state
;
1294 gui_wps
[i
].display
->backdrop_unload(BACKDROP_SKIN_WPS
);
1295 /* must point to the same struct for both screens */
1296 gui_wps
[i
].sync_data
= &wps_sync_data
;
1301 #ifdef IPOD_ACCESSORY_PROTOCOL
1302 bool is_wps_fading(void)
1304 return wps_state
.is_fading
;
1307 int wps_get_ff_rewind_count(void)
1309 return wps_state
.ff_rewind_count
;