Make skin_render_playlistviewer() noinline. This function uses lots of stack (around...
[kugel-rb.git] / apps / gui / wps.c
bloba5fe304d21d9e25dfccc2a96feaefe9fb8979800
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include "config.h"
26 #include "system.h"
27 #include "file.h"
28 #include "lcd.h"
29 #include "font.h"
30 #include "backlight.h"
31 #include "action.h"
32 #include "kernel.h"
33 #include "filetypes.h"
34 #include "settings.h"
35 #include "skin_engine/skin_engine.h"
36 #include "mp3_playback.h"
37 #include "audio.h"
38 #include "usb.h"
39 #include "status.h"
40 #include "storage.h"
41 #include "screens.h"
42 #include "playlist.h"
43 #ifdef HAVE_LCD_BITMAP
44 #include "icons.h"
45 #include "peakmeter.h"
46 #endif
47 #include "lang.h"
48 #include "bookmark.h"
49 #include "misc.h"
50 #include "sound.h"
51 #include "onplay.h"
52 #include "abrepeat.h"
53 #include "playback.h"
54 #include "splash.h"
55 #include "cuesheet.h"
56 #include "ata_idle_notify.h"
57 #include "root_menu.h"
58 #include "backdrop.h"
59 #include "quickscreen.h"
60 #include "pitchscreen.h"
61 #include "appevents.h"
62 #include "viewport.h"
63 #include "pcmbuf.h"
64 #include "option_select.h"
65 #include "dsp.h"
66 #include "playlist_viewer.h"
67 #include "wps.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 /* initial setup of wps_data */
78 static void wps_state_init(void);
79 static void track_changed_callback(void *param);
80 static void nextid3available_callback(void* param);
82 #define WPS_DEFAULTCFG WPS_DIR "/rockbox_default.wps"
83 #ifdef HAVE_REMOTE_LCD
84 #define RWPS_DEFAULTCFG WPS_DIR "/rockbox_default.rwps"
85 #define DEFAULT_WPS(screen) ((screen) == SCREEN_MAIN ? \
86 WPS_DEFAULTCFG:RWPS_DEFAULTCFG)
87 #else
88 #define DEFAULT_WPS(screen) (WPS_DEFAULTCFG)
89 #endif
91 char* wps_default_skin(enum screen_type screen)
93 static char *skin_buf[NB_SCREENS] = {
94 #ifdef HAVE_LCD_BITMAP
95 #if LCD_DEPTH > 1
96 "%X(d)\n"
97 #endif
98 "%s%?it<%?in<%in. |>%it|%fn>\n"
99 "%s%?ia<%ia|%?d(2)<%d(2)|%(root%)>>\n"
100 "%s%?id<%id|%?d(1)<%d(1)|%(root%)>> %?iy<%(%iy%)|>\n\n"
101 "%al%pc/%pt%ar[%pp:%pe]\n"
102 "%fbkBit %?fv<avg|> %?iv<%(id3v%iv%)|%(no id3%)>\n"
103 "%pb\n%pm\n",
104 #else
105 "%s%pp/%pe: %?it<%it|%fn> - %?ia<%ia|%d(2)> - %?id<%id|%d(1)>\n"
106 "%pc%?ps<*|/>%pt\n",
107 #endif
108 #ifdef HAVE_REMOTE_LCD
109 #if LCD_REMOTE_DEPTH > 1
110 "%X(d)\n"
111 #endif
112 "%s%?ia<%ia|%?d(2)<%d(2)|%(root%)>>\n"
113 "%s%?it<%?in<%in. |>%it|%fn>\n"
114 "%al%pc/%pt%ar[%pp:%pe]\n"
115 "%fbkBit %?fv<avg|> %?iv<%(id3v%iv%)|%(no id3%)>\n"
116 "%pb\n",
117 #endif
119 return skin_buf[screen];
122 void fade(bool fade_in, bool updatewps)
124 int fp_global_vol = global_settings.volume << 8;
125 int fp_min_vol = sound_min(SOUND_VOLUME) << 8;
126 int fp_step = (fp_global_vol - fp_min_vol) / 30;
127 int i;
128 skin_get_global_state()->is_fading = !fade_in;
129 if (fade_in) {
130 /* fade in */
131 int fp_volume = fp_min_vol;
133 /* zero out the sound */
134 sound_set_volume(fp_min_vol >> 8);
136 sleep(HZ/10); /* let audio thread run */
137 audio_resume();
139 while (fp_volume < fp_global_vol - fp_step) {
140 fp_volume += fp_step;
141 sound_set_volume(fp_volume >> 8);
142 if (updatewps)
144 FOR_NB_SCREENS(i)
145 skin_update(WPS, i, SKIN_REFRESH_NON_STATIC);
147 sleep(1);
149 sound_set_volume(global_settings.volume);
151 else {
152 /* fade out */
153 int fp_volume = fp_global_vol;
155 while (fp_volume > fp_min_vol + fp_step) {
156 fp_volume -= fp_step;
157 sound_set_volume(fp_volume >> 8);
158 if (updatewps)
160 FOR_NB_SCREENS(i)
161 skin_update(WPS, i, SKIN_REFRESH_NON_STATIC);
163 sleep(1);
165 audio_pause();
166 skin_get_global_state()->is_fading = false;
167 #if CONFIG_CODEC != SWCODEC
168 #ifndef SIMULATOR
169 /* let audio thread run and wait for the mas to run out of data */
170 while (!mp3_pause_done())
171 #endif
172 sleep(HZ/10);
173 #endif
175 /* reset volume to what it was before the fade */
176 sound_set_volume(global_settings.volume);
180 static bool update_onvol_change(enum screen_type screen)
182 skin_update(WPS, screen, SKIN_REFRESH_NON_STATIC);
184 #ifdef HAVE_LCD_CHARCELLS
185 splashf(0, "Vol: %3d dB",
186 sound_val2phys(SOUND_VOLUME, global_settings.volume));
187 return true;
188 #endif
189 return false;
193 #ifdef HAVE_TOUCHSCREEN
194 static int skintouch_to_wps(struct wps_data *data)
196 int offset = 0;
197 struct touchregion *region;
198 int button = skin_get_touchaction(data, &offset, &region);
199 switch (button)
201 case ACTION_STD_PREV:
202 return ACTION_WPS_SKIPPREV;
203 case ACTION_STD_PREVREPEAT:
204 return ACTION_WPS_SEEKBACK;
205 case ACTION_STD_NEXT:
206 return ACTION_WPS_SKIPNEXT;
207 case ACTION_STD_NEXTREPEAT:
208 return ACTION_WPS_SEEKFWD;
209 case ACTION_STD_MENU:
210 return ACTION_WPS_MENU;
211 case ACTION_STD_CONTEXT:
212 return ACTION_WPS_CONTEXT;
213 case ACTION_STD_QUICKSCREEN:
214 return ACTION_WPS_QUICKSCREEN;
215 #ifdef HAVE_HOTKEY
216 case ACTION_STD_HOTKEY:
217 return ACTION_WPS_HOTKEY;
218 #endif
219 case WPS_TOUCHREGION_SCROLLBAR:
220 skin_get_global_state()->id3->elapsed = skin_get_global_state()->id3->length*offset/100;
221 if (!skin_get_global_state()->paused)
222 #if (CONFIG_CODEC == SWCODEC)
223 audio_pre_ff_rewind();
224 #else
225 audio_pause();
226 #endif
227 audio_ff_rewind(skin_get_global_state()->id3->elapsed);
228 #if (CONFIG_CODEC != SWCODEC)
229 if (!skin_get_global_state()->paused)
230 audio_resume();
231 #endif
232 return ACTION_TOUCHSCREEN;
233 case WPS_TOUCHREGION_VOLUME:
235 const int min_vol = sound_min(SOUND_VOLUME);
236 const int max_vol = sound_max(SOUND_VOLUME);
237 global_settings.volume = (offset * (max_vol - min_vol)) / 100;
238 global_settings.volume += min_vol;
239 setvol();
241 return ACTION_TOUCHSCREEN;
242 case ACTION_SETTINGS_INC:
243 case ACTION_SETTINGS_DEC:
245 const struct settings_list *setting = region->extradata;
246 option_select_next_val(setting, button == ACTION_SETTINGS_DEC, true);
248 return ACTION_REDRAW;
250 return button;
252 #endif /* HAVE_TOUCHSCREEN */
254 bool ffwd_rew(int button)
256 unsigned int step = 0; /* current ff/rewind step */
257 unsigned int max_step = 0; /* maximum ff/rewind step */
258 int ff_rewind_count = 0; /* current ff/rewind count (in ticks) */
259 int direction = -1; /* forward=1 or backward=-1 */
260 bool exit = false;
261 bool usb = false;
262 int i = 0;
263 const long ff_rw_accel = (global_settings.ff_rewind_accel + 3);
265 if (button == ACTION_NONE)
267 status_set_ffmode(0);
268 return usb;
270 while (!exit)
272 switch ( button )
274 case ACTION_WPS_SEEKFWD:
275 direction = 1;
276 case ACTION_WPS_SEEKBACK:
277 if (skin_get_global_state()->ff_rewind)
279 if (direction == 1)
281 /* fast forwarding, calc max step relative to end */
282 max_step = (skin_get_global_state()->id3->length -
283 (skin_get_global_state()->id3->elapsed +
284 ff_rewind_count)) *
285 FF_REWIND_MAX_PERCENT / 100;
287 else
289 /* rewinding, calc max step relative to start */
290 max_step = (skin_get_global_state()->id3->elapsed + ff_rewind_count) *
291 FF_REWIND_MAX_PERCENT / 100;
294 max_step = MAX(max_step, MIN_FF_REWIND_STEP);
296 if (step > max_step)
297 step = max_step;
299 ff_rewind_count += step * direction;
301 /* smooth seeking by multiplying step by: 1 + (2 ^ -accel) */
302 step += step >> ff_rw_accel;
304 else
306 if ( (audio_status() & AUDIO_STATUS_PLAY) &&
307 skin_get_global_state()->id3 && skin_get_global_state()->id3->length )
309 if (!skin_get_global_state()->paused)
310 #if (CONFIG_CODEC == SWCODEC)
311 audio_pre_ff_rewind();
312 #else
313 audio_pause();
314 #endif
315 #if CONFIG_KEYPAD == PLAYER_PAD
316 FOR_NB_SCREENS(i)
317 skin_get_gwps(WPS, i)->display->stop_scroll();
318 #endif
319 if (direction > 0)
320 status_set_ffmode(STATUS_FASTFORWARD);
321 else
322 status_set_ffmode(STATUS_FASTBACKWARD);
324 skin_get_global_state()->ff_rewind = true;
326 step = 1000 * global_settings.ff_rewind_min_step;
328 else
329 break;
332 if (direction > 0) {
333 if ((skin_get_global_state()->id3->elapsed + ff_rewind_count) >
334 skin_get_global_state()->id3->length)
335 ff_rewind_count = skin_get_global_state()->id3->length -
336 skin_get_global_state()->id3->elapsed;
338 else {
339 if ((int)(skin_get_global_state()->id3->elapsed + ff_rewind_count) < 0)
340 ff_rewind_count = -skin_get_global_state()->id3->elapsed;
343 /* set the wps state ff_rewind_count so the progess info
344 displays corectly */
345 skin_get_global_state()->ff_rewind_count = (skin_get_global_state()->wps_time_countup == false)?
346 ff_rewind_count:-ff_rewind_count;
347 FOR_NB_SCREENS(i)
349 skin_update(WPS, i,
350 SKIN_REFRESH_PLAYER_PROGRESS |
351 SKIN_REFRESH_DYNAMIC);
354 break;
356 case ACTION_WPS_STOPSEEK:
357 skin_get_global_state()->id3->elapsed = skin_get_global_state()->id3->elapsed+ff_rewind_count;
358 audio_ff_rewind(skin_get_global_state()->id3->elapsed);
359 skin_get_global_state()->ff_rewind_count = 0;
360 skin_get_global_state()->ff_rewind = false;
361 status_set_ffmode(0);
362 #if (CONFIG_CODEC != SWCODEC)
363 if (!skin_get_global_state()->paused)
364 audio_resume();
365 #endif
366 #ifdef HAVE_LCD_CHARCELLS
367 FOR_NB_SCREENS(i)
368 skin_update(WPS, i, SKIN_REFRESH_ALL);
369 #endif
370 exit = true;
371 break;
373 default:
374 if(default_event_handler(button) == SYS_USB_CONNECTED) {
375 status_set_ffmode(0);
376 usb = true;
377 exit = true;
379 break;
381 if (!exit)
383 button = get_action(CONTEXT_WPS|ALLOW_SOFTLOCK,TIMEOUT_BLOCK);
384 #ifdef HAVE_TOUCHSCREEN
385 if (button == ACTION_TOUCHSCREEN)
386 button = skintouch_to_wps(skin_get_gwps(WPS, SCREEN_MAIN)->data);
387 if (button != ACTION_WPS_SEEKFWD &&
388 button != ACTION_WPS_SEEKBACK)
389 button = ACTION_WPS_STOPSEEK;
390 #endif
393 return usb;
397 void display_keylock_text(bool locked)
399 int i;
400 FOR_NB_SCREENS(i)
401 skin_get_gwps(WPS, i)->display->stop_scroll();
403 splash(HZ, locked ? ID2P(LANG_KEYLOCK_ON) : ID2P(LANG_KEYLOCK_OFF));
409 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
410 static void gwps_caption_backlight(struct wps_state *state)
412 if (state && state->id3)
414 #ifdef HAVE_BACKLIGHT
415 if (global_settings.caption_backlight)
417 /* turn on backlight n seconds before track ends, and turn it off n
418 seconds into the new track. n == backlight_timeout, or 5s */
419 int n = global_settings.backlight_timeout * 1000;
421 if ( n < 1000 )
422 n = 5000; /* use 5s if backlight is always on or off */
424 if (((state->id3->elapsed < 1000) ||
425 ((state->id3->length - state->id3->elapsed) < (unsigned)n)) &&
426 (state->paused == false))
427 backlight_on();
429 #endif
430 #ifdef HAVE_REMOTE_LCD
431 if (global_settings.remote_caption_backlight)
433 /* turn on remote backlight n seconds before track ends, and turn it
434 off n seconds into the new track. n == remote_backlight_timeout,
435 or 5s */
436 int n = global_settings.remote_backlight_timeout * 1000;
438 if ( n < 1000 )
439 n = 5000; /* use 5s if backlight is always on or off */
441 if (((state->id3->elapsed < 1000) ||
442 ((state->id3->length - state->id3->elapsed) < (unsigned)n)) &&
443 (state->paused == false))
444 remote_backlight_on();
446 #endif
449 #endif
452 static void change_dir(int direction)
454 if (global_settings.prevent_skip)
455 return;
457 if (direction < 0)
458 audio_prev_dir();
459 else if (direction > 0)
460 audio_next_dir();
461 /* prevent the next dir to immediatly start being ffw'd */
462 action_wait_for_release();
465 static void prev_track(unsigned long skip_thresh)
467 struct wps_state *state = skin_get_global_state();
468 if (state->id3->elapsed < skip_thresh)
470 audio_prev();
471 return;
473 else
475 if (state->id3->cuesheet)
477 curr_cuesheet_skip(state->id3->cuesheet, -1, state->id3->elapsed);
478 return;
481 if (!state->paused)
482 #if (CONFIG_CODEC == SWCODEC)
483 audio_pre_ff_rewind();
484 #else
485 audio_pause();
486 #endif
488 audio_ff_rewind(0);
490 #if (CONFIG_CODEC != SWCODEC)
491 if (!state->paused)
492 audio_resume();
493 #endif
497 static void next_track(void)
499 struct wps_state *state = skin_get_global_state();
500 /* take care of if we're playing a cuesheet */
501 if (state->id3->cuesheet)
503 if (curr_cuesheet_skip(state->id3->cuesheet, 1, state->id3->elapsed))
505 /* if the result was false, then we really want
506 to skip to the next track */
507 return;
511 audio_next();
514 static void play_hop(int direction)
516 struct wps_state *state = skin_get_global_state();
517 long step = global_settings.skip_length*1000;
518 long elapsed = state->id3->elapsed;
519 long remaining = state->id3->length - elapsed;
521 if (step < 0)
523 if (direction < 0)
525 prev_track(DEFAULT_SKIP_TRESH);
526 return;
528 else if (remaining < DEFAULT_SKIP_TRESH*2)
530 next_track();
531 return;
533 else
534 elapsed += (remaining - DEFAULT_SKIP_TRESH*2);
536 else if (!global_settings.prevent_skip &&
537 (!step ||
538 (direction > 0 && step >= remaining) ||
539 (direction < 0 && elapsed < DEFAULT_SKIP_TRESH)))
540 { /* Do normal track skipping */
541 if (direction > 0)
542 next_track();
543 else if (direction < 0)
544 prev_track(DEFAULT_SKIP_TRESH);
545 return;
547 else if (direction == 1 && step >= remaining)
549 #if CONFIG_CODEC == SWCODEC
550 if(global_settings.beep)
551 pcmbuf_beep(1000, 150, 1500*global_settings.beep);
552 #endif
553 return;
555 else if ((direction == -1 && elapsed < step))
557 elapsed = 0;
559 else
561 elapsed += step * direction;
563 if((audio_status() & AUDIO_STATUS_PLAY) && !state->paused)
565 #if (CONFIG_CODEC == SWCODEC)
566 audio_pre_ff_rewind();
567 #else
568 audio_pause();
569 #endif
571 audio_ff_rewind(state->id3->elapsed = elapsed);
572 #if (CONFIG_CODEC != SWCODEC)
573 if (!state->paused)
574 audio_resume();
575 #endif
579 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
581 * If the user is unable to see the wps, because the display is deactivated,
582 * we suppress updates until the wps is activated again (the lcd driver will
583 * call this hook to issue an instant update)
584 * */
585 static void wps_lcd_activation_hook(void *param)
587 (void)param;
588 skin_request_full_update(WPS);
589 /* force timeout in wps main loop, so that the update is instantly */
590 queue_post(&button_queue, BUTTON_NONE, 0);
592 #endif
594 static void gwps_leave_wps(void)
596 int i;
598 FOR_NB_SCREENS(i)
600 skin_get_gwps(WPS, i)->display->stop_scroll();
601 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
602 skin_backdrop_show(sb_get_backdrop(i));
603 #endif
604 viewportmanager_theme_undo(i, skin_has_sbs(i, skin_get_gwps(WPS, i)->data));
608 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
609 /* Play safe and unregister the hook */
610 remove_event(LCD_EVENT_ACTIVATION, wps_lcd_activation_hook);
611 #endif
612 /* unhandle statusbar update delay */
613 sb_skin_set_update_delay(DEFAULT_UPDATE_DELAY);
614 #ifdef HAVE_TOUCHSCREEN
615 touchscreen_set_mode(global_settings.touch_mode);
616 #endif
620 * display the wps on entering or restoring */
621 static void gwps_enter_wps(void)
623 int i;
624 struct gui_wps *gwps;
625 struct screen *display;
626 FOR_NB_SCREENS(i)
628 gwps = skin_get_gwps(WPS, i);
629 display = gwps->display;
630 display->stop_scroll();
631 viewportmanager_theme_enable(i, skin_has_sbs(i, skin_get_gwps(WPS, i)->data), NULL);
633 /* Update the values in the first (default) viewport - in case the user
634 has modified the statusbar or colour settings */
635 #if LCD_DEPTH > 1
636 if (display->depth > 1)
638 struct skin_viewport *svp = find_viewport(VP_DEFAULT_LABEL,
639 false, gwps->data);
640 if (svp)
642 struct viewport *vp = &svp->vp;
643 vp->fg_pattern = display->get_foreground();
644 vp->bg_pattern = display->get_background();
647 #endif
648 /* make the backdrop actually take effect */
649 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
650 skin_backdrop_show(gwps->data->backdrop_id);
651 #endif
652 display->clear_display();
653 skin_update(WPS, i, SKIN_REFRESH_ALL);
656 #ifdef HAVE_TOUCHSCREEN
657 gwps = skin_get_gwps(WPS, SCREEN_MAIN);
658 skin_disarm_touchregions(gwps->data);
659 if (!gwps->data->touchregions)
660 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
661 #endif
662 /* force statusbar/skin update since we just cleared the whole screen */
663 send_event(GUI_EVENT_ACTIONUPDATE, (void*)1);
666 /* The WPS can be left in two ways:
667 * a) call a function, which draws over the wps. In this case, the wps
668 * will be still active (i.e. the below function didn't return)
669 * b) return with a value evaluated by root_menu.c, in this case the wps
670 * is really left, and root_menu will handle the next screen
672 * In either way, call gwps_leave_wps(), in order to restore the correct
673 * "main screen" backdrops and statusbars
675 long gui_wps_show(void)
677 long button = 0;
678 bool restore = true;
679 long restoretimer = RESTORE_WPS_INSTANTLY; /* timer to delay screen redraw temporarily */
680 bool exit = false;
681 bool bookmark = false;
682 bool update = false;
683 bool vol_changed = false;
684 int i;
685 long last_left = 0, last_right = 0;
686 struct wps_state *state = skin_get_global_state();
688 #ifdef HAVE_LCD_CHARCELLS
689 status_set_audio(true);
690 status_set_param(false);
691 #endif
693 #ifdef AB_REPEAT_ENABLE
694 ab_repeat_init();
695 ab_reset_markers();
696 #endif
697 wps_state_init();
699 while ( 1 )
701 bool audio_paused = (audio_status() & AUDIO_STATUS_PAUSE)?true:false;
703 /* did someone else (i.e power thread) change audio pause mode? */
704 if (state->paused != audio_paused) {
705 state->paused = audio_paused;
707 /* if another thread paused audio, we are probably in car mode,
708 about to shut down. lets save the settings. */
709 if (state->paused) {
710 settings_save();
711 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
712 call_storage_idle_notifys(true);
713 #endif
716 button = skin_wait_for_action(WPS, CONTEXT_WPS|ALLOW_SOFTLOCK,
717 restore ? 1 : HZ/5);
719 /* Exit if audio has stopped playing. This happens e.g. at end of
720 playlist or if using the sleep timer. */
721 if (!(audio_status() & AUDIO_STATUS_PLAY))
722 exit = true;
723 #ifdef HAVE_TOUCHSCREEN
724 if (button == ACTION_TOUCHSCREEN)
725 button = skintouch_to_wps(skin_get_gwps(WPS, SCREEN_MAIN)->data);
726 #endif
727 /* The iPods/X5/M5 use a single button for the A-B mode markers,
728 defined as ACTION_WPSAB_SINGLE in their config files. */
729 #ifdef ACTION_WPSAB_SINGLE
730 if (!global_settings.party_mode && ab_repeat_mode_enabled())
732 static int wps_ab_state = 0;
733 if (button == ACTION_WPSAB_SINGLE)
735 switch (wps_ab_state)
737 case 0: /* set the A spot */
738 button = ACTION_WPS_ABSETA_PREVDIR;
739 break;
740 case 1: /* set the B spot */
741 button = ACTION_WPS_ABSETB_NEXTDIR;
742 break;
743 case 2:
744 button = ACTION_WPS_ABRESET;
745 break;
747 wps_ab_state = (wps_ab_state+1) % 3;
750 #endif
751 switch(button)
753 #ifdef HAVE_HOTKEY
754 case ACTION_WPS_HOTKEY:
755 if (!global_settings.hotkey_wps)
756 break;
757 /* fall through */
758 #endif
759 case ACTION_WPS_CONTEXT:
761 bool hotkey = button == ACTION_WPS_HOTKEY;
762 gwps_leave_wps();
763 int retval = onplay(state->id3->path,
764 FILE_ATTR_AUDIO, CONTEXT_WPS, hotkey);
765 /* if music is stopped in the context menu we want to exit the wps */
766 if (retval == ONPLAY_MAINMENU
767 || !audio_status())
768 return GO_TO_ROOT;
769 else if (retval == ONPLAY_PLAYLIST)
770 return GO_TO_PLAYLIST_VIEWER;
771 #ifdef HAVE_PICTUREFLOW_INTEGRATION
772 else if (retval == ONPLAY_PICTUREFLOW)
773 return GO_TO_PICTUREFLOW;
774 #endif
775 restore = true;
777 break;
779 case ACTION_WPS_BROWSE:
780 #ifdef HAVE_LCD_CHARCELLS
781 status_set_record(false);
782 status_set_audio(false);
783 #endif
784 gwps_leave_wps();
785 return GO_TO_PREVIOUS_BROWSER;
786 break;
788 /* play/pause */
789 case ACTION_WPS_PLAY:
790 if (global_settings.party_mode)
791 break;
792 if ( state->paused )
794 state->paused = false;
795 if ( global_settings.fade_on_stop )
796 fade(true, true);
797 else
798 audio_resume();
800 else
802 state->paused = true;
803 if ( global_settings.fade_on_stop )
804 fade(false, true);
805 else
806 audio_pause();
807 settings_save();
808 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
809 call_storage_idle_notifys(true); /* make sure resume info is saved */
810 #endif
812 break;
814 case ACTION_WPS_VOLUP:
815 global_settings.volume++;
816 vol_changed = true;
817 break;
818 case ACTION_WPS_VOLDOWN:
819 global_settings.volume--;
820 vol_changed = true;
821 break;
822 /* fast forward
823 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
824 case ACTION_WPS_SEEKFWD:
825 if (global_settings.party_mode)
826 break;
827 if (current_tick -last_right < HZ)
829 if (state->id3->cuesheet)
831 audio_next();
833 else
835 change_dir(1);
838 else
839 ffwd_rew(ACTION_WPS_SEEKFWD);
840 last_right = last_left = 0;
841 break;
842 /* fast rewind
843 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
844 case ACTION_WPS_SEEKBACK:
845 if (global_settings.party_mode)
846 break;
847 if (current_tick -last_left < HZ)
849 if (state->id3->cuesheet)
851 if (!state->paused)
852 #if (CONFIG_CODEC == SWCODEC)
853 audio_pre_ff_rewind();
854 #else
855 audio_pause();
856 #endif
857 audio_ff_rewind(0);
859 else
861 change_dir(-1);
864 else
865 ffwd_rew(ACTION_WPS_SEEKBACK);
866 last_left = last_right = 0;
867 break;
869 /* prev / restart */
870 case ACTION_WPS_SKIPPREV:
871 if (global_settings.party_mode)
872 break;
873 last_left = current_tick;
874 #ifdef AB_REPEAT_ENABLE
875 /* if we're in A/B repeat mode and the current position
876 is past the A marker, jump back to the A marker... */
877 if ( ab_repeat_mode_enabled() )
879 if ( ab_after_A_marker(state->id3->elapsed) )
881 ab_jump_to_A_marker();
882 break;
885 else
886 /* ...otherwise, do it normally */
887 #endif
888 play_hop(-1);
889 break;
891 /* next
892 OR if skip length set, hop by predetermined amount. */
893 case ACTION_WPS_SKIPNEXT:
894 if (global_settings.party_mode)
895 break;
896 last_right = current_tick;
897 #ifdef AB_REPEAT_ENABLE
898 /* if we're in A/B repeat mode and the current position is
899 before the A marker, jump to the A marker... */
900 if ( ab_repeat_mode_enabled() )
902 if ( ab_before_A_marker(state->id3->elapsed) )
904 ab_jump_to_A_marker();
905 break;
908 else
909 /* ...otherwise, do it normally */
910 #endif
911 play_hop(1);
912 break;
913 /* next / prev directories */
914 /* and set A-B markers if in a-b mode */
915 case ACTION_WPS_ABSETB_NEXTDIR:
916 if (global_settings.party_mode)
917 break;
918 #if defined(AB_REPEAT_ENABLE)
919 if (ab_repeat_mode_enabled())
921 ab_set_B_marker(state->id3->elapsed);
922 ab_jump_to_A_marker();
924 else
925 #endif
927 change_dir(1);
929 break;
930 case ACTION_WPS_ABSETA_PREVDIR:
931 if (global_settings.party_mode)
932 break;
933 #if defined(AB_REPEAT_ENABLE)
934 if (ab_repeat_mode_enabled())
935 ab_set_A_marker(state->id3->elapsed);
936 else
937 #endif
939 change_dir(-1);
941 break;
942 /* menu key functions */
943 case ACTION_WPS_MENU:
944 gwps_leave_wps();
945 return GO_TO_ROOT;
946 break;
949 #ifdef HAVE_QUICKSCREEN
950 case ACTION_WPS_QUICKSCREEN:
952 gwps_leave_wps();
953 if (quick_screen_quick(button))
954 return GO_TO_ROOT;
955 restore = true;
957 break;
958 #endif /* HAVE_QUICKSCREEN */
960 /* screen settings */
961 #ifdef BUTTON_F3
962 case ACTION_F3:
964 gwps_leave_wps();
965 if (quick_screen_f3(BUTTON_F3))
966 return GO_TO_ROOT;
967 restore = true;
969 break;
970 #endif /* BUTTON_F3 */
972 /* pitch screen */
973 #ifdef HAVE_PITCHSCREEN
974 case ACTION_WPS_PITCHSCREEN:
976 gwps_leave_wps();
977 if (1 == gui_syncpitchscreen_run())
978 return GO_TO_ROOT;
979 restore = true;
981 break;
982 #endif /* HAVE_PITCHSCREEN */
984 #ifdef AB_REPEAT_ENABLE
985 /* reset A&B markers */
986 case ACTION_WPS_ABRESET:
987 if (ab_repeat_mode_enabled())
989 ab_reset_markers();
990 update = true;
992 break;
993 #endif /* AB_REPEAT_ENABLE */
995 /* stop and exit wps */
996 case ACTION_WPS_STOP:
997 if (global_settings.party_mode)
998 break;
999 bookmark = true;
1000 exit = true;
1001 break;
1003 case ACTION_WPS_ID3SCREEN:
1005 gwps_leave_wps();
1006 if (browse_id3())
1007 return GO_TO_ROOT;
1008 restore = true;
1010 break;
1011 #ifdef HAVE_TOUCHSCREEN
1012 case ACTION_TOUCH_SHUFFLE: /* toggle shuffle mode */
1014 global_settings.playlist_shuffle =
1015 !global_settings.playlist_shuffle;
1016 #if CONFIG_CODEC == SWCODEC
1017 dsp_set_replaygain();
1018 #endif
1019 if (global_settings.playlist_shuffle)
1020 playlist_randomise(NULL, current_tick, true);
1021 else
1022 playlist_sort(NULL, true);
1024 break;
1025 case ACTION_TOUCH_REPMODE: /* cycle the repeat mode setting */
1027 const struct settings_list *rep_setting =
1028 find_setting(&global_settings.repeat_mode, NULL);
1029 option_select_next_val(rep_setting, false, true);
1030 audio_flush_and_reload_tracks();
1032 break;
1033 #endif /* HAVE_TOUCHSCREEN */
1034 /* this case is used by the softlock feature
1035 * it requests a full update here */
1036 case ACTION_REDRAW:
1037 skin_request_full_update(WPS);
1038 break;
1039 case ACTION_NONE: /* Timeout, do a partial update */
1040 update = true;
1041 ffwd_rew(button); /* hopefully fix the ffw/rwd bug */
1042 break;
1043 #ifdef HAVE_RECORDING
1044 case ACTION_WPS_REC:
1045 exit = true;
1046 break;
1047 #endif
1048 case SYS_POWEROFF:
1049 default_event_handler(SYS_POWEROFF);
1050 break;
1051 case ACTION_WPS_VIEW_PLAYLIST:
1052 gwps_leave_wps();
1053 return GO_TO_PLAYLIST_VIEWER;
1054 break;
1055 default:
1056 if(default_event_handler(button) == SYS_USB_CONNECTED)
1058 gwps_leave_wps();
1059 return GO_TO_ROOT;
1061 update = true;
1062 break;
1065 if (vol_changed)
1067 bool res = false;
1068 vol_changed = false;
1069 setvol();
1070 FOR_NB_SCREENS(i)
1072 if(update_onvol_change(i))
1073 res = true;
1075 if (res) {
1076 restore = true;
1077 restoretimer = RESTORE_WPS_NEXT_SECOND;
1082 if (restore &&
1083 ((restoretimer == RESTORE_WPS_INSTANTLY) ||
1084 TIME_AFTER(current_tick, restoretimer)))
1086 restore = false;
1087 restoretimer = RESTORE_WPS_INSTANTLY;
1088 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1089 add_event(LCD_EVENT_ACTIVATION, false, wps_lcd_activation_hook);
1090 #endif
1091 /* we remove the update delay since it's not very usable in the wps,
1092 * e.g. during volume changing or ffwd/rewind */
1093 sb_skin_set_update_delay(0);
1094 skin_request_full_update(WPS);
1095 update = true;
1096 gwps_enter_wps();
1098 else
1100 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
1101 gwps_caption_backlight(state);
1102 #endif
1103 FOR_NB_SCREENS(i)
1105 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1106 /* currently, all remotes are readable without backlight
1107 * so still update those */
1108 if (lcd_active() || (i != SCREEN_MAIN))
1109 #endif
1111 bool full_update = skin_do_full_update(WPS, i);
1112 if (update || full_update)
1114 skin_update(WPS, i, full_update ?
1115 SKIN_REFRESH_ALL : SKIN_REFRESH_NON_STATIC);
1119 update = false;
1122 if (exit) {
1123 #ifdef HAVE_LCD_CHARCELLS
1124 status_set_record(false);
1125 status_set_audio(false);
1126 #endif
1127 if (global_settings.fade_on_stop)
1128 fade(false, true);
1130 if (bookmark)
1131 bookmark_autobookmark(true);
1132 audio_stop();
1133 #ifdef AB_REPEAT_ENABLE
1134 ab_reset_markers();
1135 #endif
1136 gwps_leave_wps();
1137 #ifdef HAVE_RECORDING
1138 if (button == ACTION_WPS_REC)
1139 return GO_TO_RECSCREEN;
1140 #endif
1141 if (global_settings.browse_current)
1142 return GO_TO_PREVIOUS_BROWSER;
1143 return GO_TO_PREVIOUS;
1146 if (button && !IS_SYSEVENT(button) )
1147 storage_spin();
1149 return GO_TO_ROOT; /* unreachable - just to reduce compiler warnings */
1152 /* this is called from the playback thread so NO DRAWING! */
1153 static void track_changed_callback(void *param)
1155 struct wps_state *state = skin_get_global_state();
1156 state->id3 = (struct mp3entry*)param;
1157 state->nid3 = audio_next_track();
1158 if (state->id3->cuesheet)
1160 cue_find_current_track(state->id3->cuesheet, state->id3->elapsed);
1162 skin_request_full_update(WPS);
1164 static void nextid3available_callback(void* param)
1166 (void)param;
1167 skin_get_global_state()->nid3 = audio_next_track();
1168 skin_request_full_update(WPS);
1172 static void wps_state_init(void)
1174 struct wps_state *state = skin_get_global_state();
1175 state->ff_rewind = false;
1176 state->paused = false;
1177 if(audio_status() & AUDIO_STATUS_PLAY)
1179 state->id3 = audio_current_track();
1180 state->nid3 = audio_next_track();
1182 else
1184 state->id3 = NULL;
1185 state->nid3 = NULL;
1187 /* We'll be updating due to restore initialized with true */
1188 skin_request_full_update(WPS);
1189 /* add the WPS track event callbacks */
1190 add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, track_changed_callback);
1191 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE, false, nextid3available_callback);
1195 #ifdef IPOD_ACCESSORY_PROTOCOL
1196 bool is_wps_fading(void)
1198 return skin_get_global_state()->is_fading;
1201 int wps_get_ff_rewind_count(void)
1203 return skin_get_global_state()->ff_rewind_count;
1205 #endif