Add some playback controls to the SBS. 2 new touch regions wps_next/wps_prev needed...
[maemo-rb.git] / apps / gui / wps.c
blob473f0a4d758c38b8aed36c552cb246c120868c59
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) / 10;
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 if (updatewps) {
140 FOR_NB_SCREENS(i)
141 skin_update(WPS, i, SKIN_REFRESH_NON_STATIC);
144 while (fp_volume < fp_global_vol - fp_step) {
145 fp_volume += fp_step;
146 sound_set_volume(fp_volume >> 8);
147 sleep(1);
149 sound_set_volume(global_settings.volume);
151 else {
152 /* fade out */
153 int fp_volume = fp_global_vol;
155 if (updatewps) {
156 FOR_NB_SCREENS(i)
157 skin_update(WPS, i, SKIN_REFRESH_NON_STATIC);
160 while (fp_volume > fp_min_vol + fp_step) {
161 fp_volume -= fp_step;
162 sound_set_volume(fp_volume >> 8);
163 sleep(1);
165 audio_pause();
167 skin_get_global_state()->is_fading = false;
168 #if CONFIG_CODEC != SWCODEC
169 #ifndef SIMULATOR
170 /* let audio thread run and wait for the mas to run out of data */
171 while (!mp3_pause_done())
172 #endif
173 sleep(HZ/10);
174 #endif
176 /* reset volume to what it was before the fade */
177 sound_set_volume(global_settings.volume);
181 static bool update_onvol_change(enum screen_type screen)
183 skin_update(WPS, screen, SKIN_REFRESH_NON_STATIC);
185 #ifdef HAVE_LCD_CHARCELLS
186 splashf(0, "Vol: %3d dB",
187 sound_val2phys(SOUND_VOLUME, global_settings.volume));
188 return true;
189 #endif
190 return false;
194 #ifdef HAVE_TOUCHSCREEN
195 static int skintouch_to_wps(struct wps_data *data)
197 int offset = 0;
198 struct touchregion *region;
199 int button = skin_get_touchaction(data, &offset, &region);
200 switch (button)
202 case ACTION_STD_PREV:
203 return ACTION_WPS_SKIPPREV;
204 case ACTION_STD_PREVREPEAT:
205 return ACTION_WPS_SEEKBACK;
206 case ACTION_STD_NEXT:
207 return ACTION_WPS_SKIPNEXT;
208 case ACTION_STD_NEXTREPEAT:
209 return ACTION_WPS_SEEKFWD;
210 case ACTION_STD_MENU:
211 return ACTION_WPS_MENU;
212 case ACTION_STD_CONTEXT:
213 return ACTION_WPS_CONTEXT;
214 case ACTION_STD_QUICKSCREEN:
215 return ACTION_WPS_QUICKSCREEN;
216 #ifdef HAVE_HOTKEY
217 case ACTION_STD_HOTKEY:
218 return ACTION_WPS_HOTKEY;
219 #endif
220 case WPS_TOUCHREGION_SCROLLBAR:
221 skin_get_global_state()->id3->elapsed = skin_get_global_state()->id3->length*offset/100;
222 if (!skin_get_global_state()->paused)
223 #if (CONFIG_CODEC == SWCODEC)
224 audio_pre_ff_rewind();
225 #else
226 audio_pause();
227 #endif
228 audio_ff_rewind(skin_get_global_state()->id3->elapsed);
229 #if (CONFIG_CODEC != SWCODEC)
230 if (!skin_get_global_state()->paused)
231 audio_resume();
232 #endif
233 return ACTION_TOUCHSCREEN;
234 case WPS_TOUCHREGION_VOLUME:
236 const int min_vol = sound_min(SOUND_VOLUME);
237 const int max_vol = sound_max(SOUND_VOLUME);
238 global_settings.volume = (offset * (max_vol - min_vol)) / 100;
239 global_settings.volume += min_vol;
240 setvol();
242 return ACTION_TOUCHSCREEN;
244 return button;
246 #endif /* HAVE_TOUCHSCREEN */
248 bool ffwd_rew(int button)
250 unsigned int step = 0; /* current ff/rewind step */
251 unsigned int max_step = 0; /* maximum ff/rewind step */
252 int ff_rewind_count = 0; /* current ff/rewind count (in ticks) */
253 int direction = -1; /* forward=1 or backward=-1 */
254 bool exit = false;
255 bool usb = false;
256 int i = 0;
257 const long ff_rw_accel = (global_settings.ff_rewind_accel + 3);
259 if (button == ACTION_NONE)
261 status_set_ffmode(0);
262 return usb;
264 while (!exit)
266 switch ( button )
268 case ACTION_WPS_SEEKFWD:
269 direction = 1;
270 case ACTION_WPS_SEEKBACK:
271 if (skin_get_global_state()->ff_rewind)
273 if (direction == 1)
275 /* fast forwarding, calc max step relative to end */
276 max_step = (skin_get_global_state()->id3->length -
277 (skin_get_global_state()->id3->elapsed +
278 ff_rewind_count)) *
279 FF_REWIND_MAX_PERCENT / 100;
281 else
283 /* rewinding, calc max step relative to start */
284 max_step = (skin_get_global_state()->id3->elapsed + ff_rewind_count) *
285 FF_REWIND_MAX_PERCENT / 100;
288 max_step = MAX(max_step, MIN_FF_REWIND_STEP);
290 if (step > max_step)
291 step = max_step;
293 ff_rewind_count += step * direction;
295 /* smooth seeking by multiplying step by: 1 + (2 ^ -accel) */
296 step += step >> ff_rw_accel;
298 else
300 if ( (audio_status() & AUDIO_STATUS_PLAY) &&
301 skin_get_global_state()->id3 && skin_get_global_state()->id3->length )
303 if (!skin_get_global_state()->paused)
304 #if (CONFIG_CODEC == SWCODEC)
305 audio_pre_ff_rewind();
306 #else
307 audio_pause();
308 #endif
309 #if CONFIG_KEYPAD == PLAYER_PAD
310 FOR_NB_SCREENS(i)
311 skin_get_gwps(WPS, i)->display->stop_scroll();
312 #endif
313 if (direction > 0)
314 status_set_ffmode(STATUS_FASTFORWARD);
315 else
316 status_set_ffmode(STATUS_FASTBACKWARD);
318 skin_get_global_state()->ff_rewind = true;
320 step = 1000 * global_settings.ff_rewind_min_step;
322 else
323 break;
326 if (direction > 0) {
327 if ((skin_get_global_state()->id3->elapsed + ff_rewind_count) >
328 skin_get_global_state()->id3->length)
329 ff_rewind_count = skin_get_global_state()->id3->length -
330 skin_get_global_state()->id3->elapsed;
332 else {
333 if ((int)(skin_get_global_state()->id3->elapsed + ff_rewind_count) < 0)
334 ff_rewind_count = -skin_get_global_state()->id3->elapsed;
337 /* set the wps state ff_rewind_count so the progess info
338 displays corectly */
339 skin_get_global_state()->ff_rewind_count = ff_rewind_count;
341 FOR_NB_SCREENS(i)
343 skin_update(WPS, i,
344 SKIN_REFRESH_PLAYER_PROGRESS |
345 SKIN_REFRESH_DYNAMIC);
348 break;
350 case ACTION_WPS_STOPSEEK:
351 skin_get_global_state()->id3->elapsed = skin_get_global_state()->id3->elapsed+ff_rewind_count;
352 audio_ff_rewind(skin_get_global_state()->id3->elapsed);
353 skin_get_global_state()->ff_rewind_count = 0;
354 skin_get_global_state()->ff_rewind = false;
355 status_set_ffmode(0);
356 #if (CONFIG_CODEC != SWCODEC)
357 if (!skin_get_global_state()->paused)
358 audio_resume();
359 #endif
360 #ifdef HAVE_LCD_CHARCELLS
361 FOR_NB_SCREENS(i)
362 skin_update(WPS, i, SKIN_REFRESH_ALL);
363 #endif
364 exit = true;
365 break;
367 default:
368 if(default_event_handler(button) == SYS_USB_CONNECTED) {
369 status_set_ffmode(0);
370 usb = true;
371 exit = true;
373 break;
375 if (!exit)
377 button = get_action(CONTEXT_WPS|ALLOW_SOFTLOCK,TIMEOUT_BLOCK);
378 #ifdef HAVE_TOUCHSCREEN
379 if (button == ACTION_TOUCHSCREEN)
380 button = skintouch_to_wps(skin_get_gwps(WPS, SCREEN_MAIN)->data);
381 if (button != ACTION_WPS_SEEKFWD &&
382 button != ACTION_WPS_SEEKBACK)
383 button = ACTION_WPS_STOPSEEK;
384 #endif
387 return usb;
391 void display_keylock_text(bool locked)
393 int i;
394 FOR_NB_SCREENS(i)
395 skin_get_gwps(WPS, i)->display->stop_scroll();
397 splash(HZ, locked ? ID2P(LANG_KEYLOCK_ON) : ID2P(LANG_KEYLOCK_OFF));
403 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
404 static void gwps_caption_backlight(struct wps_state *state)
406 if (state && state->id3)
408 #ifdef HAVE_BACKLIGHT
409 if (global_settings.caption_backlight)
411 /* turn on backlight n seconds before track ends, and turn it off n
412 seconds into the new track. n == backlight_timeout, or 5s */
413 int n = global_settings.backlight_timeout * 1000;
415 if ( n < 1000 )
416 n = 5000; /* use 5s if backlight is always on or off */
418 if (((state->id3->elapsed < 1000) ||
419 ((state->id3->length - state->id3->elapsed) < (unsigned)n)) &&
420 (state->paused == false))
421 backlight_on();
423 #endif
424 #ifdef HAVE_REMOTE_LCD
425 if (global_settings.remote_caption_backlight)
427 /* turn on remote backlight n seconds before track ends, and turn it
428 off n seconds into the new track. n == remote_backlight_timeout,
429 or 5s */
430 int n = global_settings.remote_backlight_timeout * 1000;
432 if ( n < 1000 )
433 n = 5000; /* use 5s if backlight is always on or off */
435 if (((state->id3->elapsed < 1000) ||
436 ((state->id3->length - state->id3->elapsed) < (unsigned)n)) &&
437 (state->paused == false))
438 remote_backlight_on();
440 #endif
443 #endif
446 static void change_dir(int direction)
448 if (global_settings.prevent_skip)
449 return;
451 if (direction < 0)
452 audio_prev_dir();
453 else if (direction > 0)
454 audio_next_dir();
455 /* prevent the next dir to immediatly start being ffw'd */
456 action_wait_for_release();
459 static void prev_track(unsigned long skip_thresh)
461 struct wps_state *state = skin_get_global_state();
462 if (state->id3->elapsed < skip_thresh)
464 audio_prev();
465 return;
467 else
469 if (state->id3->cuesheet)
471 curr_cuesheet_skip(state->id3->cuesheet, -1, state->id3->elapsed);
472 return;
475 if (!state->paused)
476 #if (CONFIG_CODEC == SWCODEC)
477 audio_pre_ff_rewind();
478 #else
479 audio_pause();
480 #endif
482 audio_ff_rewind(0);
484 #if (CONFIG_CODEC != SWCODEC)
485 if (!state->paused)
486 audio_resume();
487 #endif
491 static void next_track(void)
493 struct wps_state *state = skin_get_global_state();
494 /* take care of if we're playing a cuesheet */
495 if (state->id3->cuesheet)
497 if (curr_cuesheet_skip(state->id3->cuesheet, 1, state->id3->elapsed))
499 /* if the result was false, then we really want
500 to skip to the next track */
501 return;
505 audio_next();
508 static void play_hop(int direction)
510 struct wps_state *state = skin_get_global_state();
511 long step = global_settings.skip_length*1000;
512 long elapsed = state->id3->elapsed;
513 long remaining = state->id3->length - elapsed;
515 if (step < 0)
517 if (direction < 0)
519 prev_track(DEFAULT_SKIP_TRESH);
520 return;
522 else if (remaining < DEFAULT_SKIP_TRESH*2)
524 next_track();
525 return;
527 else
528 elapsed += (remaining - DEFAULT_SKIP_TRESH*2);
530 else if (!global_settings.prevent_skip &&
531 (!step ||
532 (direction > 0 && step >= remaining) ||
533 (direction < 0 && elapsed < DEFAULT_SKIP_TRESH)))
534 { /* Do normal track skipping */
535 if (direction > 0)
536 next_track();
537 else if (direction < 0)
538 prev_track(DEFAULT_SKIP_TRESH);
539 return;
541 else if (direction == 1 && step >= remaining)
543 #if CONFIG_CODEC == SWCODEC
544 if(global_settings.beep)
545 pcmbuf_beep(1000, 150, 1500*global_settings.beep);
546 #endif
547 return;
549 else if ((direction == -1 && elapsed < step))
551 elapsed = 0;
553 else
555 elapsed += step * direction;
557 if((audio_status() & AUDIO_STATUS_PLAY) && !state->paused)
559 #if (CONFIG_CODEC == SWCODEC)
560 audio_pre_ff_rewind();
561 #else
562 audio_pause();
563 #endif
565 audio_ff_rewind(state->id3->elapsed = elapsed);
566 #if (CONFIG_CODEC != SWCODEC)
567 if (!state->paused)
568 audio_resume();
569 #endif
573 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
575 * If the user is unable to see the wps, because the display is deactivated,
576 * we suppress updates until the wps is activated again (the lcd driver will
577 * call this hook to issue an instant update)
578 * */
579 static void wps_lcd_activation_hook(void *param)
581 (void)param;
582 skin_request_full_update(WPS);
583 /* force timeout in wps main loop, so that the update is instantly */
584 queue_post(&button_queue, BUTTON_NONE, 0);
586 #endif
588 static void gwps_leave_wps(void)
590 int i;
592 FOR_NB_SCREENS(i)
594 skin_get_gwps(WPS, i)->display->stop_scroll();
595 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
596 skin_backdrop_show(sb_get_backdrop(i));
597 #endif
598 viewportmanager_theme_undo(i, skin_has_sbs(i, skin_get_gwps(WPS, i)->data));
602 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
603 /* Play safe and unregister the hook */
604 remove_event(LCD_EVENT_ACTIVATION, wps_lcd_activation_hook);
605 #endif
606 /* unhandle statusbar update delay */
607 sb_skin_set_update_delay(DEFAULT_UPDATE_DELAY);
608 #ifdef HAVE_TOUCHSCREEN
609 touchscreen_set_mode(global_settings.touch_mode);
610 #endif
614 * display the wps on entering or restoring */
615 static void gwps_enter_wps(void)
617 int i;
618 struct gui_wps *gwps;
619 struct screen *display;
620 FOR_NB_SCREENS(i)
622 gwps = skin_get_gwps(WPS, i);
623 display = gwps->display;
624 display->stop_scroll();
625 viewportmanager_theme_enable(i, skin_has_sbs(i, skin_get_gwps(WPS, i)->data), NULL);
627 /* Update the values in the first (default) viewport - in case the user
628 has modified the statusbar or colour settings */
629 #if LCD_DEPTH > 1
630 if (display->depth > 1)
632 struct skin_viewport *svp = skin_find_item(VP_DEFAULT_LABEL,
633 SKIN_FIND_VP, gwps->data);
634 if (svp)
636 struct viewport *vp = &svp->vp;
637 vp->fg_pattern = display->get_foreground();
638 vp->bg_pattern = display->get_background();
641 #endif
642 /* make the backdrop actually take effect */
643 #if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
644 skin_backdrop_show(gwps->data->backdrop_id);
645 #endif
646 display->clear_display();
647 skin_update(WPS, i, SKIN_REFRESH_ALL);
650 #ifdef HAVE_TOUCHSCREEN
651 gwps = skin_get_gwps(WPS, SCREEN_MAIN);
652 skin_disarm_touchregions(gwps->data);
653 if (!gwps->data->touchregions)
654 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
655 #endif
656 /* force statusbar/skin update since we just cleared the whole screen */
657 send_event(GUI_EVENT_ACTIONUPDATE, (void*)1);
660 void wps_do_playpause(bool updatewps)
662 struct wps_state *state = skin_get_global_state();
663 if ( state->paused )
665 state->paused = false;
666 if ( global_settings.fade_on_stop )
667 fade(true, updatewps);
668 else
669 audio_resume();
671 else
673 state->paused = true;
674 if ( global_settings.fade_on_stop )
675 fade(false, updatewps);
676 else
677 audio_pause();
678 settings_save();
679 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
680 call_storage_idle_notifys(true); /* make sure resume info is saved */
681 #endif
686 /* The WPS can be left in two ways:
687 * a) call a function, which draws over the wps. In this case, the wps
688 * will be still active (i.e. the below function didn't return)
689 * b) return with a value evaluated by root_menu.c, in this case the wps
690 * is really left, and root_menu will handle the next screen
692 * In either way, call gwps_leave_wps(), in order to restore the correct
693 * "main screen" backdrops and statusbars
695 long gui_wps_show(void)
697 long button = 0;
698 bool restore = true;
699 long restoretimer = RESTORE_WPS_INSTANTLY; /* timer to delay screen redraw temporarily */
700 bool exit = false;
701 bool bookmark = false;
702 bool update = false;
703 bool vol_changed = false;
704 int i;
705 long last_left = 0, last_right = 0;
706 struct wps_state *state = skin_get_global_state();
708 #ifdef HAVE_LCD_CHARCELLS
709 status_set_audio(true);
710 status_set_param(false);
711 #endif
713 #ifdef AB_REPEAT_ENABLE
714 ab_repeat_init();
715 ab_reset_markers();
716 #endif
717 wps_state_init();
719 while ( 1 )
721 bool audio_paused = (audio_status() & AUDIO_STATUS_PAUSE)?true:false;
723 /* did someone else (i.e power thread) change audio pause mode? */
724 if (state->paused != audio_paused) {
725 state->paused = audio_paused;
727 /* if another thread paused audio, we are probably in car mode,
728 about to shut down. lets save the settings. */
729 if (state->paused) {
730 settings_save();
731 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
732 call_storage_idle_notifys(true);
733 #endif
736 button = skin_wait_for_action(WPS, CONTEXT_WPS|ALLOW_SOFTLOCK,
737 restore ? 1 : HZ/5);
739 /* Exit if audio has stopped playing. This happens e.g. at end of
740 playlist or if using the sleep timer. */
741 if (!(audio_status() & AUDIO_STATUS_PLAY))
742 exit = true;
743 #ifdef HAVE_TOUCHSCREEN
744 if (button == ACTION_TOUCHSCREEN)
745 button = skintouch_to_wps(skin_get_gwps(WPS, SCREEN_MAIN)->data);
746 #endif
747 /* The iPods/X5/M5 use a single button for the A-B mode markers,
748 defined as ACTION_WPSAB_SINGLE in their config files. */
749 #ifdef ACTION_WPSAB_SINGLE
750 if (!global_settings.party_mode && ab_repeat_mode_enabled())
752 static int wps_ab_state = 0;
753 if (button == ACTION_WPSAB_SINGLE)
755 switch (wps_ab_state)
757 case 0: /* set the A spot */
758 button = ACTION_WPS_ABSETA_PREVDIR;
759 break;
760 case 1: /* set the B spot */
761 button = ACTION_WPS_ABSETB_NEXTDIR;
762 break;
763 case 2:
764 button = ACTION_WPS_ABRESET;
765 break;
767 wps_ab_state = (wps_ab_state+1) % 3;
770 #endif
771 switch(button)
773 #ifdef HAVE_HOTKEY
774 case ACTION_WPS_HOTKEY:
775 if (!global_settings.hotkey_wps)
776 break;
777 /* fall through */
778 #endif
779 case ACTION_WPS_CONTEXT:
781 bool hotkey = button == ACTION_WPS_HOTKEY;
782 gwps_leave_wps();
783 int retval = onplay(state->id3->path,
784 FILE_ATTR_AUDIO, CONTEXT_WPS, hotkey);
785 /* if music is stopped in the context menu we want to exit the wps */
786 if (retval == ONPLAY_MAINMENU
787 || !audio_status())
788 return GO_TO_ROOT;
789 else if (retval == ONPLAY_PLAYLIST)
790 return GO_TO_PLAYLIST_VIEWER;
791 #ifdef HAVE_PICTUREFLOW_INTEGRATION
792 else if (retval == ONPLAY_PICTUREFLOW)
793 return GO_TO_PICTUREFLOW;
794 #endif
795 restore = true;
797 break;
799 case ACTION_WPS_BROWSE:
800 #ifdef HAVE_LCD_CHARCELLS
801 status_set_record(false);
802 status_set_audio(false);
803 #endif
804 gwps_leave_wps();
805 return GO_TO_PREVIOUS_BROWSER;
806 break;
808 /* play/pause */
809 case ACTION_WPS_PLAY:
810 if (global_settings.party_mode)
811 break;
812 wps_do_playpause(true);
813 break;
815 case ACTION_WPS_VOLUP:
816 global_settings.volume++;
817 vol_changed = true;
818 break;
819 case ACTION_WPS_VOLDOWN:
820 global_settings.volume--;
821 vol_changed = true;
822 break;
823 /* fast forward
824 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
825 case ACTION_WPS_SEEKFWD:
826 if (global_settings.party_mode)
827 break;
828 if (current_tick -last_right < HZ)
830 if (state->id3->cuesheet)
832 audio_next();
834 else
836 change_dir(1);
839 else
840 ffwd_rew(ACTION_WPS_SEEKFWD);
841 last_right = last_left = 0;
842 break;
843 /* fast rewind
844 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
845 case ACTION_WPS_SEEKBACK:
846 if (global_settings.party_mode)
847 break;
848 if (current_tick -last_left < HZ)
850 if (state->id3->cuesheet)
852 if (!state->paused)
853 #if (CONFIG_CODEC == SWCODEC)
854 audio_pre_ff_rewind();
855 #else
856 audio_pause();
857 #endif
858 audio_ff_rewind(0);
860 else
862 change_dir(-1);
865 else
866 ffwd_rew(ACTION_WPS_SEEKBACK);
867 last_left = last_right = 0;
868 break;
870 /* prev / restart */
871 case ACTION_WPS_SKIPPREV:
872 if (global_settings.party_mode)
873 break;
874 last_left = current_tick;
875 #ifdef AB_REPEAT_ENABLE
876 /* if we're in A/B repeat mode and the current position
877 is past the A marker, jump back to the A marker... */
878 if ( ab_repeat_mode_enabled() )
880 if ( ab_after_A_marker(state->id3->elapsed) )
882 ab_jump_to_A_marker();
883 break;
886 else
887 /* ...otherwise, do it normally */
888 #endif
889 play_hop(-1);
890 break;
892 /* next
893 OR if skip length set, hop by predetermined amount. */
894 case ACTION_WPS_SKIPNEXT:
895 if (global_settings.party_mode)
896 break;
897 last_right = current_tick;
898 #ifdef AB_REPEAT_ENABLE
899 /* if we're in A/B repeat mode and the current position is
900 before the A marker, jump to the A marker... */
901 if ( ab_repeat_mode_enabled() )
903 if ( ab_before_A_marker(state->id3->elapsed) )
905 ab_jump_to_A_marker();
906 break;
909 else
910 /* ...otherwise, do it normally */
911 #endif
912 play_hop(1);
913 break;
914 /* next / prev directories */
915 /* and set A-B markers if in a-b mode */
916 case ACTION_WPS_ABSETB_NEXTDIR:
917 if (global_settings.party_mode)
918 break;
919 #if defined(AB_REPEAT_ENABLE)
920 if (ab_repeat_mode_enabled())
922 ab_set_B_marker(state->id3->elapsed);
923 ab_jump_to_A_marker();
925 else
926 #endif
928 change_dir(1);
930 break;
931 case ACTION_WPS_ABSETA_PREVDIR:
932 if (global_settings.party_mode)
933 break;
934 #if defined(AB_REPEAT_ENABLE)
935 if (ab_repeat_mode_enabled())
936 ab_set_A_marker(state->id3->elapsed);
937 else
938 #endif
940 change_dir(-1);
942 break;
943 /* menu key functions */
944 case ACTION_WPS_MENU:
945 gwps_leave_wps();
946 return GO_TO_ROOT;
947 break;
950 #ifdef HAVE_QUICKSCREEN
951 case ACTION_WPS_QUICKSCREEN:
953 gwps_leave_wps();
954 if (quick_screen_quick(button))
955 return GO_TO_ROOT;
956 restore = true;
958 break;
959 #endif /* HAVE_QUICKSCREEN */
961 /* screen settings */
962 #ifdef BUTTON_F3
963 case ACTION_F3:
965 gwps_leave_wps();
966 if (quick_screen_f3(BUTTON_F3))
967 return GO_TO_ROOT;
968 restore = true;
970 break;
971 #endif /* BUTTON_F3 */
973 /* pitch screen */
974 #ifdef HAVE_PITCHSCREEN
975 case ACTION_WPS_PITCHSCREEN:
977 gwps_leave_wps();
978 if (1 == gui_syncpitchscreen_run())
979 return GO_TO_ROOT;
980 restore = true;
982 break;
983 #endif /* HAVE_PITCHSCREEN */
985 #ifdef AB_REPEAT_ENABLE
986 /* reset A&B markers */
987 case ACTION_WPS_ABRESET:
988 if (ab_repeat_mode_enabled())
990 ab_reset_markers();
991 update = true;
993 break;
994 #endif /* AB_REPEAT_ENABLE */
996 /* stop and exit wps */
997 case ACTION_WPS_STOP:
998 if (global_settings.party_mode)
999 break;
1000 bookmark = true;
1001 exit = true;
1002 break;
1004 case ACTION_WPS_ID3SCREEN:
1006 gwps_leave_wps();
1007 if (browse_id3())
1008 return GO_TO_ROOT;
1009 restore = true;
1011 break;
1012 #ifdef HAVE_TOUCHSCREEN
1013 case ACTION_TOUCH_SHUFFLE: /* toggle shuffle mode */
1015 global_settings.playlist_shuffle =
1016 !global_settings.playlist_shuffle;
1017 #if CONFIG_CODEC == SWCODEC
1018 dsp_set_replaygain();
1019 #endif
1020 if (global_settings.playlist_shuffle)
1021 playlist_randomise(NULL, current_tick, true);
1022 else
1023 playlist_sort(NULL, true);
1025 break;
1026 case ACTION_TOUCH_REPMODE: /* cycle the repeat mode setting */
1028 const struct settings_list *rep_setting =
1029 find_setting(&global_settings.repeat_mode, NULL);
1030 option_select_next_val(rep_setting, false, true);
1031 audio_flush_and_reload_tracks();
1033 break;
1034 #endif /* HAVE_TOUCHSCREEN */
1035 /* this case is used by the softlock feature
1036 * it requests a full update here */
1037 case ACTION_REDRAW:
1038 skin_request_full_update(WPS);
1039 break;
1040 case ACTION_NONE: /* Timeout, do a partial update */
1041 update = true;
1042 ffwd_rew(button); /* hopefully fix the ffw/rwd bug */
1043 break;
1044 #ifdef HAVE_RECORDING
1045 case ACTION_WPS_REC:
1046 exit = true;
1047 break;
1048 #endif
1049 case ACTION_WPS_VIEW_PLAYLIST:
1050 gwps_leave_wps();
1051 return GO_TO_PLAYLIST_VIEWER;
1052 break;
1053 default:
1054 switch(default_event_handler(button))
1055 { /* music has been stopped by the default handler */
1056 case SYS_USB_CONNECTED:
1057 case SYS_CALL_INCOMING:
1058 case BUTTON_MULTIMEDIA_STOP:
1059 gwps_leave_wps();
1060 return GO_TO_ROOT;
1062 update = true;
1063 break;
1066 if (vol_changed)
1068 bool res = false;
1069 vol_changed = false;
1070 setvol();
1071 FOR_NB_SCREENS(i)
1073 if(update_onvol_change(i))
1074 res = true;
1076 if (res) {
1077 restore = true;
1078 restoretimer = RESTORE_WPS_NEXT_SECOND;
1083 if (restore &&
1084 ((restoretimer == RESTORE_WPS_INSTANTLY) ||
1085 TIME_AFTER(current_tick, restoretimer)))
1087 restore = false;
1088 restoretimer = RESTORE_WPS_INSTANTLY;
1089 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1090 add_event(LCD_EVENT_ACTIVATION, false, wps_lcd_activation_hook);
1091 #endif
1092 /* we remove the update delay since it's not very usable in the wps,
1093 * e.g. during volume changing or ffwd/rewind */
1094 sb_skin_set_update_delay(0);
1095 skin_request_full_update(WPS);
1096 update = true;
1097 gwps_enter_wps();
1099 else
1101 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
1102 gwps_caption_backlight(state);
1103 #endif
1104 FOR_NB_SCREENS(i)
1106 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1107 /* currently, all remotes are readable without backlight
1108 * so still update those */
1109 if (lcd_active() || (i != SCREEN_MAIN))
1110 #endif
1112 bool full_update = skin_do_full_update(WPS, i);
1113 if (update || full_update)
1115 skin_update(WPS, i, full_update ?
1116 SKIN_REFRESH_ALL : SKIN_REFRESH_NON_STATIC);
1120 update = false;
1123 if (exit) {
1124 #ifdef HAVE_LCD_CHARCELLS
1125 status_set_record(false);
1126 status_set_audio(false);
1127 #endif
1128 if (global_settings.fade_on_stop)
1129 fade(false, true);
1131 if (bookmark)
1132 bookmark_autobookmark(true);
1133 audio_stop();
1134 #ifdef AB_REPEAT_ENABLE
1135 ab_reset_markers();
1136 #endif
1137 gwps_leave_wps();
1138 #ifdef HAVE_RECORDING
1139 if (button == ACTION_WPS_REC)
1140 return GO_TO_RECSCREEN;
1141 #endif
1142 if (global_settings.browse_current)
1143 return GO_TO_PREVIOUS_BROWSER;
1144 return GO_TO_PREVIOUS;
1147 if (button && !IS_SYSEVENT(button) )
1148 storage_spin();
1150 return GO_TO_ROOT; /* unreachable - just to reduce compiler warnings */
1153 /* this is called from the playback thread so NO DRAWING! */
1154 static void track_changed_callback(void *param)
1156 struct wps_state *state = skin_get_global_state();
1157 state->id3 = (struct mp3entry*)param;
1158 state->nid3 = audio_next_track();
1159 if (state->id3->cuesheet)
1161 cue_find_current_track(state->id3->cuesheet, state->id3->elapsed);
1163 skin_request_full_update(WPS);
1165 static void nextid3available_callback(void* param)
1167 (void)param;
1168 skin_get_global_state()->nid3 = audio_next_track();
1169 skin_request_full_update(WPS);
1173 static void wps_state_init(void)
1175 struct wps_state *state = skin_get_global_state();
1176 state->ff_rewind = false;
1177 state->paused = false;
1178 if(audio_status() & AUDIO_STATUS_PLAY)
1180 state->id3 = audio_current_track();
1181 state->nid3 = audio_next_track();
1183 else
1185 state->id3 = NULL;
1186 state->nid3 = NULL;
1188 /* We'll be updating due to restore initialized with true */
1189 skin_request_full_update(WPS);
1190 /* add the WPS track event callbacks */
1191 add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, track_changed_callback);
1192 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE, false, nextid3available_callback);
1196 #ifdef IPOD_ACCESSORY_PROTOCOL
1197 bool is_wps_fading(void)
1199 return skin_get_global_state()->is_fading;
1202 int wps_get_ff_rewind_count(void)
1204 return skin_get_global_state()->ff_rewind_count;
1206 #endif