Move this call a bit up so that wpses without backdrop show none properly (the main...
[kugel-rb/myfork.git] / apps / gui / wps.c
bloba5142a072653ec9170c82993e15ff8f0065691db
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 "debug.h"
35 #include "sprintf.h"
36 #include "settings.h"
37 #include "skin_engine/skin_engine.h"
38 #include "mp3_playback.h"
39 #include "audio.h"
40 #include "usb.h"
41 #include "status.h"
42 #include "storage.h"
43 #include "screens.h"
44 #include "playlist.h"
45 #ifdef HAVE_LCD_BITMAP
46 #include "icons.h"
47 #include "peakmeter.h"
48 #endif
49 #include "lang.h"
50 #include "bookmark.h"
51 #include "misc.h"
52 #include "sound.h"
53 #include "onplay.h"
54 #include "abrepeat.h"
55 #include "playback.h"
56 #include "splash.h"
57 #include "cuesheet.h"
58 #include "ata_idle_notify.h"
59 #include "root_menu.h"
60 #include "backdrop.h"
61 #include "quickscreen.h"
62 #include "pitchscreen.h"
63 #include "appevents.h"
64 #include "viewport.h"
65 #include "pcmbuf.h"
66 #include "option_select.h"
67 #include "dsp.h"
68 #include "playlist_viewer.h"
69 #include "wps.h"
71 #define RESTORE_WPS_INSTANTLY 0l
72 #define RESTORE_WPS_NEXT_SECOND ((long)(HZ+current_tick))
73 /* in milliseconds */
74 #define DEFAULT_SKIP_TRESH 3000ul
77 #define FF_REWIND_MAX_PERCENT 3 /* cap ff/rewind step size at max % of file */
78 /* 3% of 30min file == 54s step size */
79 #define MIN_FF_REWIND_STEP 500
81 static int wpsbars;
82 /* currently only one wps_state is needed */
83 static struct wps_state wps_state;
84 static struct gui_wps gui_wps[NB_SCREENS];
85 static struct wps_data wps_datas[NB_SCREENS];
87 /* initial setup of wps_data */
88 static void wps_state_init(void);
89 static void track_changed_callback(void *param);
90 static void nextid3available_callback(void* param);
93 void wps_data_load(enum screen_type screen, const char *buf, bool isfile)
95 bool loaded_ok;
97 screens[screen].backdrop_unload(BACKDROP_SKIN_WPS);
99 loaded_ok = buf && skin_data_load(gui_wps[screen].data,
100 &screens[screen], buf, isfile);
101 if (!loaded_ok) /* load the hardcoded default */
103 char *skin_buf[NB_SCREENS] = {
104 #ifdef HAVE_LCD_BITMAP
105 "%s%?it<%?in<%in. |>%it|%fn>\n"
106 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
107 "%s%?id<%id|%?d1<%d1|(root)>> %?iy<(%iy)|>\n\n"
108 "%al%pc/%pt%ar[%pp:%pe]\n"
109 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
110 "%pb\n%pm\n",
111 #else
112 "%s%pp/%pe: %?it<%it|%fn> - %?ia<%ia|%d2> - %?id<%id|%d1>\n"
113 "%pc%?ps<*|/>%pt\n",
114 #endif
115 #ifdef HAVE_REMOTE_LCD
116 "%s%?ia<%ia|%?d2<%d2|(root)>>\n"
117 "%s%?it<%?in<%in. |>%it|%fn>\n"
118 "%al%pc/%pt%ar[%pp:%pe]\n"
119 "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n"
120 "%pb\n",
121 #endif
123 skin_data_load(gui_wps[screen].data, &screens[screen],
124 skin_buf[screen], false);
126 #ifdef HAVE_REMOVE_LCD
127 gui_wps[screen].data->remote_wps = !(screen == SCREEN_MAIN);
128 #endif
131 void wps_data_init(enum screen_type screen)
133 skin_data_init(gui_wps[screen].data);
137 static bool wps_fading_out = false;
138 void fade(bool fade_in, bool updatewps)
140 int fp_global_vol = global_settings.volume << 8;
141 int fp_min_vol = sound_min(SOUND_VOLUME) << 8;
142 int fp_step = (fp_global_vol - fp_min_vol) / 30;
143 int i;
144 wps_fading_out = !fade_in;
145 if (fade_in) {
146 /* fade in */
147 int fp_volume = fp_min_vol;
149 /* zero out the sound */
150 sound_set_volume(fp_min_vol >> 8);
152 sleep(HZ/10); /* let audio thread run */
153 audio_resume();
155 while (fp_volume < fp_global_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(&gui_wps[i], WPS_REFRESH_NON_STATIC);
163 sleep(1);
165 sound_set_volume(global_settings.volume);
167 else {
168 /* fade out */
169 int fp_volume = fp_global_vol;
171 while (fp_volume > fp_min_vol + fp_step) {
172 fp_volume -= fp_step;
173 sound_set_volume(fp_volume >> 8);
174 if (updatewps)
176 FOR_NB_SCREENS(i)
177 skin_update(&gui_wps[i], WPS_REFRESH_NON_STATIC);
179 sleep(1);
181 audio_pause();
182 wps_fading_out = false;
183 #if CONFIG_CODEC != SWCODEC
184 #ifndef SIMULATOR
185 /* let audio thread run and wait for the mas to run out of data */
186 while (!mp3_pause_done())
187 #endif
188 sleep(HZ/10);
189 #endif
191 /* reset volume to what it was before the fade */
192 sound_set_volume(global_settings.volume);
195 bool is_wps_fading(void)
197 return wps_fading_out;
200 bool update_onvol_change(struct gui_wps * gwps)
202 skin_update(gwps, WPS_REFRESH_NON_STATIC);
204 #ifdef HAVE_LCD_CHARCELLS
205 splashf(0, "Vol: %3d dB",
206 sound_val2phys(SOUND_VOLUME, global_settings.volume));
207 return true;
208 #endif
209 return false;
213 bool ffwd_rew(int button)
215 unsigned int step = 0; /* current ff/rewind step */
216 unsigned int max_step = 0; /* maximum ff/rewind step */
217 int ff_rewind_count = 0; /* current ff/rewind count (in ticks) */
218 int direction = -1; /* forward=1 or backward=-1 */
219 bool exit = false;
220 bool usb = false;
221 int i = 0;
222 const long ff_rw_accel = (global_settings.ff_rewind_accel + 3);
224 if (button == ACTION_NONE)
226 status_set_ffmode(0);
227 return usb;
229 while (!exit)
231 switch ( button )
233 case ACTION_WPS_SEEKFWD:
234 direction = 1;
235 case ACTION_WPS_SEEKBACK:
236 if (wps_state.ff_rewind)
238 if (direction == 1)
240 /* fast forwarding, calc max step relative to end */
241 max_step = (wps_state.id3->length -
242 (wps_state.id3->elapsed +
243 ff_rewind_count)) *
244 FF_REWIND_MAX_PERCENT / 100;
246 else
248 /* rewinding, calc max step relative to start */
249 max_step = (wps_state.id3->elapsed + ff_rewind_count) *
250 FF_REWIND_MAX_PERCENT / 100;
253 max_step = MAX(max_step, MIN_FF_REWIND_STEP);
255 if (step > max_step)
256 step = max_step;
258 ff_rewind_count += step * direction;
260 /* smooth seeking by multiplying step by: 1 + (2 ^ -accel) */
261 step += step >> ff_rw_accel;
263 else
265 if ( (audio_status() & AUDIO_STATUS_PLAY) &&
266 wps_state.id3 && wps_state.id3->length )
268 if (!wps_state.paused)
269 #if (CONFIG_CODEC == SWCODEC)
270 audio_pre_ff_rewind();
271 #else
272 audio_pause();
273 #endif
274 #if CONFIG_KEYPAD == PLAYER_PAD
275 FOR_NB_SCREENS(i)
276 gui_wps[i].display->stop_scroll();
277 #endif
278 if (direction > 0)
279 status_set_ffmode(STATUS_FASTFORWARD);
280 else
281 status_set_ffmode(STATUS_FASTBACKWARD);
283 wps_state.ff_rewind = true;
285 step = 1000 * global_settings.ff_rewind_min_step;
287 else
288 break;
291 if (direction > 0) {
292 if ((wps_state.id3->elapsed + ff_rewind_count) >
293 wps_state.id3->length)
294 ff_rewind_count = wps_state.id3->length -
295 wps_state.id3->elapsed;
297 else {
298 if ((int)(wps_state.id3->elapsed + ff_rewind_count) < 0)
299 ff_rewind_count = -wps_state.id3->elapsed;
302 /* set the wps state ff_rewind_count so the progess info
303 displays corectly */
304 wps_state.ff_rewind_count = (wps_state.wps_time_countup == false)?
305 ff_rewind_count:-ff_rewind_count;
306 FOR_NB_SCREENS(i)
308 skin_update(&gui_wps[i],
309 WPS_REFRESH_PLAYER_PROGRESS |
310 WPS_REFRESH_DYNAMIC);
313 break;
315 case ACTION_WPS_STOPSEEK:
316 wps_state.id3->elapsed = wps_state.id3->elapsed+ff_rewind_count;
317 audio_ff_rewind(wps_state.id3->elapsed);
318 wps_state.ff_rewind_count = 0;
319 wps_state.ff_rewind = false;
320 status_set_ffmode(0);
321 #if (CONFIG_CODEC != SWCODEC)
322 if (!wps_state.paused)
323 audio_resume();
324 #endif
325 #ifdef HAVE_LCD_CHARCELLS
326 FOR_NB_SCREENS(i)
327 skin_update(&gui_wps[i], WPS_REFRESH_ALL);
328 #endif
329 exit = true;
330 break;
332 default:
333 if(default_event_handler(button) == SYS_USB_CONNECTED) {
334 status_set_ffmode(0);
335 usb = true;
336 exit = true;
338 break;
340 if (!exit)
342 button = get_action(CONTEXT_WPS|ALLOW_SOFTLOCK,TIMEOUT_BLOCK);
343 #ifdef HAVE_TOUCHSCREEN
344 if (button == ACTION_TOUCHSCREEN)
345 button = wps_get_touchaction(gui_wps[SCREEN_MAIN].data);
346 #endif
349 return usb;
353 void display_keylock_text(bool locked)
355 int i;
356 FOR_NB_SCREENS(i)
357 gui_wps[i].display->stop_scroll();
359 splash(HZ, locked ? ID2P(LANG_KEYLOCK_ON) : ID2P(LANG_KEYLOCK_OFF));
365 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
366 static void gwps_caption_backlight(struct wps_state *state)
368 if (state && state->id3)
370 #ifdef HAVE_BACKLIGHT
371 if (global_settings.caption_backlight)
373 /* turn on backlight n seconds before track ends, and turn it off n
374 seconds into the new track. n == backlight_timeout, or 5s */
375 int n = global_settings.backlight_timeout * 1000;
377 if ( n < 1000 )
378 n = 5000; /* use 5s if backlight is always on or off */
380 if (((state->id3->elapsed < 1000) ||
381 ((state->id3->length - state->id3->elapsed) < (unsigned)n)) &&
382 (state->paused == false))
383 backlight_on();
385 #endif
386 #ifdef HAVE_REMOTE_LCD
387 if (global_settings.remote_caption_backlight)
389 /* turn on remote backlight n seconds before track ends, and turn it
390 off n seconds into the new track. n == remote_backlight_timeout,
391 or 5s */
392 int n = global_settings.remote_backlight_timeout * 1000;
394 if ( n < 1000 )
395 n = 5000; /* use 5s if backlight is always on or off */
397 if (((state->id3->elapsed < 1000) ||
398 ((state->id3->length - state->id3->elapsed) < (unsigned)n)) &&
399 (state->paused == false))
400 remote_backlight_on();
402 #endif
405 #endif
408 static void change_dir(int direction)
410 if (global_settings.prevent_skip)
411 return;
413 if (direction < 0)
414 audio_prev_dir();
415 else if (direction > 0)
416 audio_next_dir();
417 /* prevent the next dir to immediatly start being ffw'd */
418 action_wait_for_release();
421 static void prev_track(unsigned long skip_thresh)
423 if (wps_state.id3->elapsed < skip_thresh)
425 audio_prev();
426 return;
428 else
430 if (wps_state.id3->cuesheet)
432 curr_cuesheet_skip(wps_state.id3->cuesheet, -1, wps_state.id3->elapsed);
433 return;
436 if (!wps_state.paused)
437 #if (CONFIG_CODEC == SWCODEC)
438 audio_pre_ff_rewind();
439 #else
440 audio_pause();
441 #endif
443 audio_ff_rewind(0);
445 #if (CONFIG_CODEC != SWCODEC)
446 if (!wps_state.paused)
447 audio_resume();
448 #endif
452 static void next_track(void)
454 /* take care of if we're playing a cuesheet */
455 if (wps_state.id3->cuesheet)
457 if (curr_cuesheet_skip(wps_state.id3->cuesheet, 1, wps_state.id3->elapsed))
459 /* if the result was false, then we really want
460 to skip to the next track */
461 return;
465 audio_next();
468 static void play_hop(int direction)
470 unsigned long step = ((unsigned long)global_settings.skip_length)*1000;
471 unsigned long elapsed = wps_state.id3->elapsed;
472 unsigned long remaining = wps_state.id3->length - elapsed;
474 if (!global_settings.prevent_skip &&
475 (!step ||
476 (direction > 0 && step >= remaining) ||
477 (direction < 0 && elapsed < DEFAULT_SKIP_TRESH)))
478 { /* Do normal track skipping */
479 if (direction > 0)
480 next_track();
481 else if (direction < 0)
482 prev_track(DEFAULT_SKIP_TRESH);
483 return;
486 if (direction == 1 && step >= remaining)
488 #if CONFIG_CODEC == SWCODEC
489 if(global_settings.beep)
490 pcmbuf_beep(1000, 150, 1500*global_settings.beep);
491 #endif
492 return;
494 else if ((direction == -1 && elapsed < step))
496 elapsed = 0;
498 else
500 elapsed += step * direction;
502 if((audio_status() & AUDIO_STATUS_PLAY) && !wps_state.paused)
504 #if (CONFIG_CODEC == SWCODEC)
505 audio_pre_ff_rewind();
506 #else
507 audio_pause();
508 #endif
510 audio_ff_rewind(wps_state.id3->elapsed = elapsed);
511 #if (CONFIG_CODEC != SWCODEC)
512 if (!wps_state.paused)
513 audio_resume();
514 #endif
517 static void gwps_fix_statusbars(void)
519 #ifdef HAVE_LCD_BITMAP
520 int i;
521 wpsbars = VP_SB_HIDE_ALL;
522 FOR_NB_SCREENS(i)
524 bool draw = false;
525 if (gui_wps[i].data->wps_sb_tag)
526 draw = gui_wps[i].data->show_sb_on_wps;
527 else if (statusbar_position(i) != STATUSBAR_OFF)
528 draw = true;
529 if (draw)
530 wpsbars |= (VP_SB_ONSCREEN(i) | VP_SB_IGNORE_SETTING(i));
532 #else
533 wpsbars = VP_SB_ALLSCREENS;
534 #endif
537 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
539 * If the user is unable to see the wps, because the display is deactivated,
540 * we suppress updates until the wps is activated again (the lcd driver will
541 * call this hook to issue an instant update)
542 * */
543 static void wps_lcd_activation_hook(void)
545 wps_state.do_full_update = true;
546 /* force timeout in wps main loop, so that the update is instantly */
547 queue_post(&button_queue, BUTTON_NONE, 0);
549 #endif
551 static void gwps_leave_wps(void)
553 int i, oldbars = VP_SB_HIDE_ALL;
555 FOR_NB_SCREENS(i)
557 gui_wps[i].display->stop_scroll();
558 gui_wps[i].display->backdrop_show(BACKDROP_MAIN);
560 if (global_settings.statusbar)
561 oldbars = VP_SB_ALLSCREENS;
563 viewportmanager_set_statusbar(oldbars);
564 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
565 /* Play safe and unregister the hook */
566 lcd_activation_set_hook(NULL);
567 #endif
570 void gwps_draw_statusbars(void)
572 viewportmanager_set_statusbar(wpsbars);
574 #ifdef HAVE_TOUCHSCREEN
575 int wps_get_touchaction(struct wps_data *data)
577 short x,y;
578 short vx, vy;
579 int type = action_get_touchscreen_press(&x, &y);
580 int i;
581 static int last_action = ACTION_NONE;
582 struct touchregion *r;
583 bool repeated = (type == BUTTON_REPEAT);
584 bool released = (type == BUTTON_REL);
585 for (i=0; i<data->touchregion_count; i++)
587 r = &data->touchregion[i];
588 /* make sure this region's viewport is visible */
589 if (r->wvp->hidden_flags&VP_DRAW_HIDDEN)
590 continue;
591 /* reposition the touch inside the viewport */
592 vx = x - r->wvp->vp.x;
593 vy = y - r->wvp->vp.y;
594 /* check if it's inside this viewport */
595 if (vx >= 0 && vx < r->wvp->vp.x + r->wvp->vp.width &&
596 vy >= 0 && vy < r->wvp->vp.y + r->wvp->vp.height)
598 /* now see if the point is inside this region */
599 if (vx >= r->x && vx < r->x+r->width &&
600 vy >= r->y && vy < r->y+r->height)
602 if ((repeated && r->repeat) ||
603 (released && !r->repeat))
605 last_action = r->action;
606 return r->action;
611 if ((last_action == ACTION_WPS_SEEKBACK || last_action == ACTION_WPS_SEEKFWD))
612 return ACTION_WPS_STOPSEEK;
613 last_action = ACTION_TOUCHSCREEN;
614 return ACTION_TOUCHSCREEN;
616 #endif
617 /* The WPS can be left in two ways:
618 * a) call a function, which draws over the wps. In this case, the wps
619 * will be still active (i.e. the below function didn't return)
620 * b) return with a value evaluated by root_menu.c, in this case the wps
621 * is really left, and root_menu will handle the next screen
623 * In either way, call gwps_leave_wps(), in order to restore the correct
624 * "main screen" backdrops and statusbars
626 long gui_wps_show(void)
628 long button = 0;
629 bool restore = true;
630 long restoretimer = RESTORE_WPS_INSTANTLY; /* timer to delay screen redraw temporarily */
631 bool exit = false;
632 bool bookmark = false;
633 bool update = false;
634 int i;
635 long last_left = 0, last_right = 0;
637 #ifdef HAVE_LCD_CHARCELLS
638 status_set_audio(true);
639 status_set_param(false);
640 #endif
642 #ifdef AB_REPEAT_ENABLE
643 ab_repeat_init();
644 ab_reset_markers();
645 #endif
646 wps_state_init();
648 while ( 1 )
650 bool audio_paused = (audio_status() & AUDIO_STATUS_PAUSE)?true:false;
652 /* did someone else (i.e power thread) change audio pause mode? */
653 if (wps_state.paused != audio_paused) {
654 wps_state.paused = audio_paused;
656 /* if another thread paused audio, we are probably in car mode,
657 about to shut down. lets save the settings. */
658 if (wps_state.paused) {
659 settings_save();
660 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
661 call_storage_idle_notifys(true);
662 #endif
666 #ifdef HAVE_LCD_BITMAP
667 /* when the peak meter is enabled we want to have a
668 few extra updates to make it look smooth. On the
669 other hand we don't want to waste energy if it
670 isn't displayed */
671 bool pm=false;
672 FOR_NB_SCREENS(i)
674 if(gui_wps[i].data->peak_meter_enabled)
675 pm = true;
678 if (pm) {
679 long next_refresh = current_tick;
680 long next_big_refresh = current_tick + HZ / 5;
681 button = BUTTON_NONE;
682 while (TIME_BEFORE(current_tick, next_big_refresh)) {
683 button = get_action(CONTEXT_WPS|ALLOW_SOFTLOCK,TIMEOUT_NOBLOCK);
684 if (button != ACTION_NONE) {
685 break;
687 peak_meter_peek();
688 sleep(0); /* Sleep until end of current tick. */
690 if (TIME_AFTER(current_tick, next_refresh)) {
691 FOR_NB_SCREENS(i)
693 if(gui_wps[i].data->peak_meter_enabled)
694 skin_update(&gui_wps[i], WPS_REFRESH_PEAK_METER);
695 next_refresh += HZ / PEAK_METER_FPS;
702 /* The peak meter is disabled
703 -> no additional screen updates needed */
704 else
705 #endif
707 button = get_action(CONTEXT_WPS|ALLOW_SOFTLOCK,
708 restore ? HZ/100 : HZ/5);
711 /* Exit if audio has stopped playing. This happens e.g. at end of
712 playlist or if using the sleep timer. */
713 if (!(audio_status() & AUDIO_STATUS_PLAY))
714 exit = true;
715 #ifdef HAVE_TOUCHSCREEN
716 if (button == ACTION_TOUCHSCREEN)
717 button = wps_get_touchaction(gui_wps[SCREEN_MAIN].data);
718 #endif
719 /* The iPods/X5/M5 use a single button for the A-B mode markers,
720 defined as ACTION_WPSAB_SINGLE in their config files. */
721 #ifdef ACTION_WPSAB_SINGLE
722 if (!global_settings.party_mode && ab_repeat_mode_enabled())
724 static int wps_ab_state = 0;
725 if (button == ACTION_WPSAB_SINGLE)
727 switch (wps_ab_state)
729 case 0: /* set the A spot */
730 button = ACTION_WPS_ABSETA_PREVDIR;
731 break;
732 case 1: /* set the B spot */
733 button = ACTION_WPS_ABSETB_NEXTDIR;
734 break;
735 case 2:
736 button = ACTION_WPS_ABRESET;
737 break;
739 wps_ab_state = (wps_ab_state+1) % 3;
742 #endif
743 switch(button)
745 case ACTION_WPS_CONTEXT:
747 gwps_leave_wps();
748 /* if music is stopped in the context menu we want to exit the wps */
749 if (onplay(wps_state.id3->path,
750 FILE_ATTR_AUDIO, CONTEXT_WPS) == ONPLAY_MAINMENU
751 || !audio_status())
752 return GO_TO_ROOT;
753 restore = true;
755 break;
757 case ACTION_WPS_BROWSE:
758 #ifdef HAVE_LCD_CHARCELLS
759 status_set_record(false);
760 status_set_audio(false);
761 #endif
762 gwps_leave_wps();
763 return GO_TO_PREVIOUS_BROWSER;
764 break;
766 /* play/pause */
767 case ACTION_WPS_PLAY:
768 if (global_settings.party_mode)
769 break;
770 if ( wps_state.paused )
772 wps_state.paused = false;
773 if ( global_settings.fade_on_stop )
774 fade(true, true);
775 else
776 audio_resume();
778 else
780 wps_state.paused = true;
781 if ( global_settings.fade_on_stop )
782 fade(false, true);
783 else
784 audio_pause();
785 settings_save();
786 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
787 call_storage_idle_notifys(true); /* make sure resume info is saved */
788 #endif
790 break;
792 case ACTION_WPS_VOLUP:
794 FOR_NB_SCREENS(i)
795 gui_wps[i].data->button_time_volume = current_tick;
796 global_settings.volume++;
797 bool res = false;
798 setvol();
799 FOR_NB_SCREENS(i)
801 if(update_onvol_change(&gui_wps[i]))
802 res = true;
804 if (res) {
805 restore = true;
806 restoretimer = RESTORE_WPS_NEXT_SECOND;
809 break;
810 case ACTION_WPS_VOLDOWN:
812 FOR_NB_SCREENS(i)
813 gui_wps[i].data->button_time_volume = current_tick;
814 global_settings.volume--;
815 setvol();
816 bool res = false;
817 FOR_NB_SCREENS(i)
819 if(update_onvol_change(&gui_wps[i]))
820 res = true;
822 if (res) {
823 restore = true;
824 restoretimer = RESTORE_WPS_NEXT_SECOND;
827 break;
828 /* fast forward
829 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
830 case ACTION_WPS_SEEKFWD:
831 if (global_settings.party_mode)
832 break;
833 if (current_tick -last_right < HZ)
835 if (wps_state.id3->cuesheet)
837 audio_next();
839 else
841 change_dir(1);
844 else
845 ffwd_rew(ACTION_WPS_SEEKFWD);
846 last_right = last_left = 0;
847 break;
848 /* fast rewind
849 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
850 case ACTION_WPS_SEEKBACK:
851 if (global_settings.party_mode)
852 break;
853 if (current_tick -last_left < HZ)
855 if (wps_state.id3->cuesheet)
857 if (!wps_state.paused)
858 #if (CONFIG_CODEC == SWCODEC)
859 audio_pre_ff_rewind();
860 #else
861 audio_pause();
862 #endif
863 audio_ff_rewind(0);
865 else
867 change_dir(-1);
870 else
871 ffwd_rew(ACTION_WPS_SEEKBACK);
872 last_left = last_right = 0;
873 break;
875 /* prev / restart */
876 case ACTION_WPS_SKIPPREV:
877 if (global_settings.party_mode)
878 break;
879 last_left = current_tick;
880 #ifdef AB_REPEAT_ENABLE
881 /* if we're in A/B repeat mode and the current position
882 is past the A marker, jump back to the A marker... */
883 if ( ab_repeat_mode_enabled() )
885 if ( ab_after_A_marker(wps_state.id3->elapsed) )
887 ab_jump_to_A_marker();
888 break;
889 #if (AB_REPEAT_ENABLE == 2)
890 } else {
891 ab_reset_markers();
892 #endif
895 else
896 /* ...otherwise, do it normally */
897 #endif
898 play_hop(-1);
899 break;
901 /* next
902 OR if skip length set, hop by predetermined amount. */
903 case ACTION_WPS_SKIPNEXT:
904 if (global_settings.party_mode)
905 break;
906 last_right = current_tick;
907 #ifdef AB_REPEAT_ENABLE
908 /* if we're in A/B repeat mode and the current position is
909 before the A marker, jump to the A marker... */
910 if ( ab_repeat_mode_enabled() )
912 if ( ab_before_A_marker(wps_state.id3->elapsed) )
914 ab_jump_to_A_marker();
915 break;
916 #if (AB_REPEAT_ENABLE == 2)
917 } else {
918 ab_reset_markers();
919 #endif
922 else
923 /* ...otherwise, do it normally */
924 #endif
925 play_hop(1);
926 break;
927 /* next / prev directories */
928 /* and set A-B markers if in a-b mode */
929 case ACTION_WPS_ABSETB_NEXTDIR:
930 if (global_settings.party_mode)
931 break;
932 #if defined(AB_REPEAT_ENABLE)
933 if (ab_repeat_mode_enabled())
935 ab_set_B_marker(wps_state.id3->elapsed);
936 ab_jump_to_A_marker();
938 else
939 #endif
941 change_dir(1);
943 break;
944 case ACTION_WPS_ABSETA_PREVDIR:
945 if (global_settings.party_mode)
946 break;
947 #if defined(AB_REPEAT_ENABLE)
948 if (ab_repeat_mode_enabled())
949 ab_set_A_marker(wps_state.id3->elapsed);
950 else
951 #endif
953 change_dir(-1);
955 break;
956 /* menu key functions */
957 case ACTION_WPS_MENU:
958 gwps_leave_wps();
959 return GO_TO_ROOT;
960 break;
963 #ifdef HAVE_QUICKSCREEN
964 case ACTION_WPS_QUICKSCREEN:
966 gwps_leave_wps();
967 if (quick_screen_quick(button))
968 return SYS_USB_CONNECTED;
969 restore = true;
971 break;
972 #endif /* HAVE_QUICKSCREEN */
974 /* screen settings */
975 #ifdef BUTTON_F3
976 case ACTION_F3:
978 gwps_leave_wps();
979 if (quick_screen_f3(BUTTON_F3))
980 return SYS_USB_CONNECTED;
981 restore = true;
983 break;
984 #endif /* BUTTON_F3 */
986 /* pitch screen */
987 #ifdef HAVE_PITCHSCREEN
988 case ACTION_WPS_PITCHSCREEN:
990 gwps_leave_wps();
991 if (1 == gui_syncpitchscreen_run())
992 return SYS_USB_CONNECTED;
993 restore = true;
995 break;
996 #endif /* HAVE_PITCHSCREEN */
998 #ifdef AB_REPEAT_ENABLE
999 /* reset A&B markers */
1000 case ACTION_WPS_ABRESET:
1001 if (ab_repeat_mode_enabled())
1003 ab_reset_markers();
1004 update = true;
1006 break;
1007 #endif /* AB_REPEAT_ENABLE */
1009 /* stop and exit wps */
1010 case ACTION_WPS_STOP:
1011 if (global_settings.party_mode)
1012 break;
1013 bookmark = true;
1014 exit = true;
1015 break;
1017 case ACTION_WPS_ID3SCREEN:
1019 gwps_leave_wps();
1020 browse_id3();
1021 restore = true;
1023 break;
1024 #ifdef HAVE_TOUCHSCREEN
1025 case ACTION_TOUCH_SHUFFLE: /* toggle shuffle mode */
1027 global_settings.playlist_shuffle =
1028 !global_settings.playlist_shuffle;
1029 #if CONFIG_CODEC == SWCODEC
1030 dsp_set_replaygain();
1031 #endif
1032 if (global_settings.playlist_shuffle)
1033 playlist_randomise(NULL, current_tick, true);
1034 else
1035 playlist_sort(NULL, true);
1037 break;
1038 case ACTION_TOUCH_REPMODE: /* cycle the repeat mode setting */
1040 const struct settings_list *rep_setting =
1041 find_setting(&global_settings.repeat_mode, NULL);
1042 option_select_next_val(rep_setting, false, true);
1043 audio_flush_and_reload_tracks();
1045 break;
1046 #endif /* HAVE_TOUCHSCREEN */
1047 /* this case is used by the softlock feature
1048 * it requests a full update here */
1049 case ACTION_REDRAW:
1050 wps_state.do_full_update = true;
1051 break;
1052 case ACTION_NONE: /* Timeout, do a partial update */
1053 update = true;
1054 ffwd_rew(button); /* hopefully fix the ffw/rwd bug */
1055 break;
1056 #ifdef HAVE_RECORDING
1057 case ACTION_WPS_REC:
1058 exit = true;
1059 break;
1060 #endif
1061 case SYS_POWEROFF:
1062 default_event_handler(SYS_POWEROFF);
1063 break;
1064 case ACTION_WPS_VIEW_PLAYLIST:
1065 gwps_leave_wps();
1066 if (playlist_viewer()) /* true if USB connected */
1067 return SYS_USB_CONNECTED;
1068 restore = true;
1069 break;
1070 default:
1071 if(default_event_handler(button) == SYS_USB_CONNECTED)
1072 return GO_TO_ROOT;
1073 update = true;
1074 break;
1077 if (wps_state.do_full_update || update)
1079 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
1080 gwps_caption_backlight(&wps_state);
1081 #endif
1082 FOR_NB_SCREENS(i)
1084 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1085 if (lcd_active()
1086 #ifdef HAVE_REMOTE_LCD
1087 /* currently, all remotes are readable without backlight
1088 * so still update those */
1089 || (i == SCREEN_REMOTE)
1090 #endif
1092 #endif
1094 skin_update(&gui_wps[i], WPS_REFRESH_NON_STATIC);
1097 wps_state.do_full_update = false;
1098 update = false;
1101 if (restore && wps_state.id3 &&
1102 ((restoretimer == RESTORE_WPS_INSTANTLY) ||
1103 TIME_AFTER(current_tick, restoretimer)))
1105 restore = false;
1106 restoretimer = RESTORE_WPS_INSTANTLY;
1107 gwps_fix_statusbars();
1108 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
1109 lcd_activation_set_hook(wps_lcd_activation_hook);
1110 #endif
1111 FOR_NB_SCREENS(i)
1113 screens[i].stop_scroll();
1114 gui_wps_display(&gui_wps[i]);
1118 if (exit) {
1119 #ifdef HAVE_LCD_CHARCELLS
1120 status_set_record(false);
1121 status_set_audio(false);
1122 #endif
1123 if (global_settings.fade_on_stop)
1124 fade(false, true);
1126 if (bookmark)
1127 bookmark_autobookmark();
1128 audio_stop();
1129 #ifdef AB_REPEAT_ENABLE
1130 ab_reset_markers();
1131 #endif
1132 gwps_leave_wps();
1133 #ifdef HAVE_RECORDING
1134 if (button == ACTION_WPS_REC)
1135 return GO_TO_RECSCREEN;
1136 #endif
1137 if (global_settings.browse_current)
1138 return GO_TO_PREVIOUS_BROWSER;
1139 return GO_TO_PREVIOUS;
1142 if (button && !IS_SYSEVENT(button) )
1143 storage_spin();
1145 return GO_TO_ROOT; /* unreachable - just to reduce compiler warnings */
1148 /* this is called from the playback thread so NO DRAWING! */
1149 static void track_changed_callback(void *param)
1151 wps_state.id3 = (struct mp3entry*)param;
1152 wps_state.nid3 = audio_next_track();
1153 if (wps_state.id3->cuesheet)
1155 cue_find_current_track(wps_state.id3->cuesheet, wps_state.id3->elapsed);
1156 cue_spoof_id3(wps_state.id3->cuesheet, wps_state.id3);
1158 wps_state.do_full_update = true;
1160 static void nextid3available_callback(void* param)
1162 (void)param;
1163 wps_state.nid3 = audio_next_track();
1164 wps_state.do_full_update = true;
1168 static void wps_state_init(void)
1170 wps_state.ff_rewind = false;
1171 wps_state.paused = false;
1172 if(audio_status() & AUDIO_STATUS_PLAY)
1174 wps_state.id3 = audio_current_track();
1175 wps_state.nid3 = audio_next_track();
1177 else
1179 wps_state.id3 = NULL;
1180 wps_state.nid3 = NULL;
1182 /* We'll be updating due to restore initialized with true */
1183 wps_state.do_full_update = false;
1184 /* add the WPS track event callbacks */
1185 add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, track_changed_callback);
1186 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE, false, nextid3available_callback);
1190 #ifdef HAVE_LCD_BITMAP
1191 static void statusbar_toggle_handler(void *data)
1193 (void)data;
1194 int i;
1195 gwps_fix_statusbars();
1197 FOR_NB_SCREENS(i)
1199 struct viewport *vp = &gui_wps[i].data->viewports[0].vp;
1200 bool draw = wpsbars & (VP_SB_ONSCREEN(i) | VP_SB_IGNORE_SETTING(i));
1201 if (!draw)
1203 vp->y = 0;
1204 vp->height = screens[i].lcdheight;
1206 else
1208 bool bar_at_top = statusbar_position(i) != STATUSBAR_BOTTOM;
1209 vp->y = bar_at_top?STATUSBAR_HEIGHT:0;
1210 vp->height = screens[i].lcdheight - STATUSBAR_HEIGHT;
1214 #endif
1216 void gui_sync_wps_init(void)
1218 int i;
1219 FOR_NB_SCREENS(i)
1221 skin_data_init(&wps_datas[i]);
1222 #ifdef HAVE_ALBUMART
1223 wps_datas[i].wps_uses_albumart = 0;
1224 #endif
1225 #ifdef HAVE_REMOTE_LCD
1226 wps_datas[i].remote_wps = (i == SCREEN_REMOTE);
1227 #endif
1228 gui_wps[i].data = &wps_datas[i];
1229 gui_wps[i].display = &screens[i];
1230 /* Currently no seperate wps_state needed/possible
1231 so use the only available ( "global" ) one */
1232 gui_wps[i].state = &wps_state;
1233 gui_wps[i].display->backdrop_unload(BACKDROP_SKIN_WPS);
1235 #ifdef HAVE_LCD_BITMAP
1236 add_event(GUI_EVENT_STATUSBAR_TOGGLE, false, statusbar_toggle_handler);
1237 #endif
1240 #ifdef HAVE_ALBUMART
1241 bool wps_uses_albumart(int *width, int *height)
1243 int i;
1244 FOR_NB_SCREENS(i) {
1245 struct gui_wps *gwps = &gui_wps[i];
1246 if (gwps->data && (gwps->data->wps_uses_albumart != WPS_ALBUMART_NONE))
1248 if (width)
1249 *width = gui_wps[0].data->albumart_max_width;
1250 if (height)
1251 *height = gui_wps[0].data->albumart_max_height;
1252 return true;
1255 return false;
1257 #endif
1260 #ifdef IPOD_ACCESSORY_PROTOCOL
1261 int wps_get_ff_rewind_count(void)
1263 return wps_state.ff_rewind_count;
1265 #endif