Commit part of FS#9873 - Utilise buttons for playlisting
[kugel-rb/myfork.git] / apps / gui / gwps.c
blob154864a2801fc868f345244fa51061338326beed
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 "gwps.h"
38 #include "gwps-common.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"
70 #define RESTORE_WPS_INSTANTLY 0l
71 #define RESTORE_WPS_NEXT_SECOND ((long)(HZ+current_tick))
72 /* in milliseconds */
73 #define DEFAULT_SKIP_TRESH 3000ul
75 static int wpsbars;
76 /* currently only one wps_state is needed */
77 struct wps_state wps_state;
78 struct gui_wps gui_wps[NB_SCREENS];
79 static struct wps_data wps_datas[NB_SCREENS];
81 /* initial setup of wps_data */
82 static void wps_state_init(void);
83 static void track_changed_callback(void *param);
84 static void nextid3available_callback(void* param);
87 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
88 static void gwps_caption_backlight(struct wps_state *state)
90 if (state && state->id3)
92 #ifdef HAVE_BACKLIGHT
93 if (global_settings.caption_backlight)
95 /* turn on backlight n seconds before track ends, and turn it off n
96 seconds into the new track. n == backlight_timeout, or 5s */
97 int n = global_settings.backlight_timeout * 1000;
99 if ( n < 1000 )
100 n = 5000; /* use 5s if backlight is always on or off */
102 if (((state->id3->elapsed < 1000) ||
103 ((state->id3->length - state->id3->elapsed) < (unsigned)n)) &&
104 (state->paused == false))
105 backlight_on();
107 #endif
108 #ifdef HAVE_REMOTE_LCD
109 if (global_settings.remote_caption_backlight)
111 /* turn on remote backlight n seconds before track ends, and turn it
112 off n seconds into the new track. n == remote_backlight_timeout,
113 or 5s */
114 int n = global_settings.remote_backlight_timeout * 1000;
116 if ( n < 1000 )
117 n = 5000; /* use 5s if backlight is always on or off */
119 if (((state->id3->elapsed < 1000) ||
120 ((state->id3->length - state->id3->elapsed) < (unsigned)n)) &&
121 (state->paused == false))
122 remote_backlight_on();
124 #endif
127 #endif
130 static void change_dir(int direction)
132 if (global_settings.prevent_skip)
133 return;
135 if (direction < 0)
136 audio_prev_dir();
137 else if (direction > 0)
138 audio_next_dir();
139 /* prevent the next dir to immediatly start being ffw'd */
140 action_wait_for_release();
143 static void prev_track(unsigned long skip_thresh)
145 if (wps_state.id3->elapsed < skip_thresh)
147 audio_prev();
148 return;
150 else
152 if (wps_state.id3->cuesheet)
154 curr_cuesheet_skip(-1, wps_state.id3->elapsed);
155 return;
158 if (!wps_state.paused)
159 #if (CONFIG_CODEC == SWCODEC)
160 audio_pre_ff_rewind();
161 #else
162 audio_pause();
163 #endif
165 audio_ff_rewind(0);
167 #if (CONFIG_CODEC != SWCODEC)
168 if (!wps_state.paused)
169 audio_resume();
170 #endif
174 static void next_track(void)
176 /* take care of if we're playing a cuesheet */
177 if (wps_state.id3->cuesheet)
179 if (curr_cuesheet_skip(1, wps_state.id3->elapsed))
181 /* if the result was false, then we really want
182 to skip to the next track */
183 return;
187 audio_next();
190 static void play_hop(int direction)
192 unsigned long step = ((unsigned long)global_settings.skip_length)*1000;
193 unsigned long elapsed = wps_state.id3->elapsed;
194 unsigned long remaining = wps_state.id3->length - elapsed;
196 if (!global_settings.prevent_skip &&
197 (!step ||
198 (direction > 0 && step >= remaining) ||
199 (direction < 0 && elapsed < DEFAULT_SKIP_TRESH)))
200 { /* Do normal track skipping */
201 if (direction > 0)
202 next_track();
203 else if (direction < 0)
204 prev_track(DEFAULT_SKIP_TRESH);
205 return;
208 if (direction == 1 && step >= remaining)
210 #if CONFIG_CODEC == SWCODEC
211 if(global_settings.beep)
212 pcmbuf_beep(1000, 150, 1500*global_settings.beep);
213 #endif
214 return;
216 else if ((direction == -1 && elapsed < step))
218 elapsed = 0;
220 else
222 elapsed += step * direction;
224 if((audio_status() & AUDIO_STATUS_PLAY) && !wps_state.paused)
226 #if (CONFIG_CODEC == SWCODEC)
227 audio_pre_ff_rewind();
228 #else
229 audio_pause();
230 #endif
232 audio_ff_rewind(wps_state.id3->elapsed = elapsed);
233 #if (CONFIG_CODEC != SWCODEC)
234 if (!wps_state.paused)
235 audio_resume();
236 #endif
239 static void gwps_fix_statusbars(void)
241 #ifdef HAVE_LCD_BITMAP
242 int i;
243 wpsbars = VP_SB_HIDE_ALL;
244 FOR_NB_SCREENS(i)
246 bool draw = false;
247 if (gui_wps[i].data->wps_sb_tag)
248 draw = gui_wps[i].data->show_sb_on_wps;
249 else if (statusbar_position(i) != STATUSBAR_OFF)
250 draw = true;
251 if (draw)
252 wpsbars |= (VP_SB_ONSCREEN(i) | VP_SB_IGNORE_SETTING(i));
254 #else
255 wpsbars = VP_SB_ALLSCREENS;
256 #endif
259 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
261 * If the user is unable to see the wps, because the display is deactivated,
262 * we suppress updates until the wps is activated again (the lcd driver will
263 * call this hook to issue an instant update)
264 * */
265 static void wps_lcd_activation_hook(void)
267 wps_state.do_full_update = true;
268 /* force timeout in wps main loop, so that the update is instantly */
269 queue_post(&button_queue, BUTTON_NONE, 0);
271 #endif
273 static void gwps_leave_wps(void)
275 int i, oldbars = VP_SB_HIDE_ALL;
277 FOR_NB_SCREENS(i)
278 gui_wps[i].display->stop_scroll();
279 if (global_settings.statusbar)
280 oldbars = VP_SB_ALLSCREENS;
282 #if LCD_DEPTH > 1
283 show_main_backdrop();
284 #endif
285 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
286 show_remote_main_backdrop();
287 #endif
288 viewportmanager_set_statusbar(oldbars);
289 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
290 /* Play safe and unregister the hook */
291 lcd_activation_set_hook(NULL);
292 #endif
295 void gwps_draw_statusbars(void)
297 viewportmanager_set_statusbar(wpsbars);
299 #ifdef HAVE_TOUCHSCREEN
300 int wps_get_touchaction(struct wps_data *data)
302 short x,y;
303 short vx, vy;
304 int type = action_get_touchscreen_press(&x, &y);
305 int i;
306 static int last_action = ACTION_NONE;
307 struct touchregion *r;
308 bool repeated = (type == BUTTON_REPEAT);
309 bool released = (type == BUTTON_REL);
310 for (i=0; i<data->touchregion_count; i++)
312 r = &data->touchregion[i];
313 /* make sure this region's viewport is visible */
314 if (r->wvp->hidden_flags&VP_DRAW_HIDDEN)
315 continue;
316 /* reposition the touch inside the viewport */
317 vx = x - r->wvp->vp.x;
318 vy = y - r->wvp->vp.y;
319 /* check if it's inside this viewport */
320 if (vx >= 0 && vx < r->wvp->vp.x + r->wvp->vp.width &&
321 vy >= 0 && vy < r->wvp->vp.y + r->wvp->vp.height)
323 /* now see if the point is inside this region */
324 if (vx >= r->x && vx < r->x+r->width &&
325 vy >= r->y && vy < r->y+r->height)
327 if ((repeated && r->repeat) ||
328 (released && !r->repeat))
330 last_action = r->action;
331 return r->action;
336 if ((last_action == ACTION_WPS_SEEKBACK || last_action == ACTION_WPS_SEEKFWD))
337 return ACTION_WPS_STOPSEEK;
338 last_action = ACTION_TOUCHSCREEN;
339 return ACTION_TOUCHSCREEN;
341 #endif
342 /* The WPS can be left in two ways:
343 * a) call a function, which draws over the wps. In this case, the wps
344 * will be still active (i.e. the below function didn't return)
345 * b) return with a value evaluated by root_menu.c, in this case the wps
346 * is really left, and root_menu will handle the next screen
348 * In either way, call gwps_leave_wps(), in order to restore the correct
349 * "main screen" backdrops and statusbars
351 long gui_wps_show(void)
353 long button = 0;
354 bool restore = true;
355 long restoretimer = RESTORE_WPS_INSTANTLY; /* timer to delay screen redraw temporarily */
356 bool exit = false;
357 bool bookmark = false;
358 bool update = false;
359 int i;
360 long last_left = 0, last_right = 0;
362 #ifdef HAVE_LCD_CHARCELLS
363 status_set_audio(true);
364 status_set_param(false);
365 #endif
367 #ifdef AB_REPEAT_ENABLE
368 ab_repeat_init();
369 ab_reset_markers();
370 #endif
371 wps_state_init();
373 while ( 1 )
375 bool audio_paused = (audio_status() & AUDIO_STATUS_PAUSE)?true:false;
377 /* did someone else (i.e power thread) change audio pause mode? */
378 if (wps_state.paused != audio_paused) {
379 wps_state.paused = audio_paused;
381 /* if another thread paused audio, we are probably in car mode,
382 about to shut down. lets save the settings. */
383 if (wps_state.paused) {
384 settings_save();
385 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
386 call_storage_idle_notifys(true);
387 #endif
391 #ifdef HAVE_LCD_BITMAP
392 /* when the peak meter is enabled we want to have a
393 few extra updates to make it look smooth. On the
394 other hand we don't want to waste energy if it
395 isn't displayed */
396 bool pm=false;
397 FOR_NB_SCREENS(i)
399 if(gui_wps[i].data->peak_meter_enabled)
400 pm = true;
403 if (pm) {
404 long next_refresh = current_tick;
405 long next_big_refresh = current_tick + HZ / 5;
406 button = BUTTON_NONE;
407 while (TIME_BEFORE(current_tick, next_big_refresh)) {
408 button = get_action(CONTEXT_WPS|ALLOW_SOFTLOCK,TIMEOUT_NOBLOCK);
409 if (button != ACTION_NONE) {
410 break;
412 peak_meter_peek();
413 sleep(0); /* Sleep until end of current tick. */
415 if (TIME_AFTER(current_tick, next_refresh)) {
416 FOR_NB_SCREENS(i)
418 if(gui_wps[i].data->peak_meter_enabled)
419 gui_wps_redraw(&gui_wps[i], 0,
420 WPS_REFRESH_PEAK_METER);
421 next_refresh += HZ / PEAK_METER_FPS;
428 /* The peak meter is disabled
429 -> no additional screen updates needed */
430 else
431 #endif
433 button = get_action(CONTEXT_WPS|ALLOW_SOFTLOCK,
434 restore ? HZ/100 : HZ/5);
437 /* Exit if audio has stopped playing. This happens e.g. at end of
438 playlist or if using the sleep timer. */
439 if (!(audio_status() & AUDIO_STATUS_PLAY))
440 exit = true;
441 #ifdef HAVE_TOUCHSCREEN
442 if (button == ACTION_TOUCHSCREEN)
443 button = wps_get_touchaction(gui_wps[SCREEN_MAIN].data);
444 #endif
445 /* The iPods/X5/M5 use a single button for the A-B mode markers,
446 defined as ACTION_WPSAB_SINGLE in their config files. */
447 #ifdef ACTION_WPSAB_SINGLE
448 if (!global_settings.party_mode && ab_repeat_mode_enabled())
450 static int wps_ab_state = 0;
451 if (button == ACTION_WPSAB_SINGLE)
453 switch (wps_ab_state)
455 case 0: /* set the A spot */
456 button = ACTION_WPS_ABSETA_PREVDIR;
457 break;
458 case 1: /* set the B spot */
459 button = ACTION_WPS_ABSETB_NEXTDIR;
460 break;
461 case 2:
462 button = ACTION_WPS_ABRESET;
463 break;
465 wps_ab_state = (wps_ab_state+1) % 3;
468 #endif
469 switch(button)
471 case ACTION_WPS_CONTEXT:
473 gwps_leave_wps();
474 /* if music is stopped in the context menu we want to exit the wps */
475 if (onplay(wps_state.id3->path,
476 FILE_ATTR_AUDIO, CONTEXT_WPS) == ONPLAY_MAINMENU
477 || !audio_status())
478 return GO_TO_ROOT;
479 restore = true;
481 break;
483 case ACTION_WPS_BROWSE:
484 #ifdef HAVE_LCD_CHARCELLS
485 status_set_record(false);
486 status_set_audio(false);
487 #endif
488 gwps_leave_wps();
489 return GO_TO_PREVIOUS_BROWSER;
490 break;
492 /* play/pause */
493 case ACTION_WPS_PLAY:
494 if (global_settings.party_mode)
495 break;
496 if ( wps_state.paused )
498 wps_state.paused = false;
499 if ( global_settings.fade_on_stop )
500 fade(true, true);
501 else
502 audio_resume();
504 else
506 wps_state.paused = true;
507 if ( global_settings.fade_on_stop )
508 fade(false, true);
509 else
510 audio_pause();
511 settings_save();
512 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
513 call_storage_idle_notifys(true); /* make sure resume info is saved */
514 #endif
516 break;
518 case ACTION_WPS_VOLUP:
520 FOR_NB_SCREENS(i)
521 gui_wps[i].data->button_time_volume = current_tick;
522 global_settings.volume++;
523 bool res = false;
524 setvol();
525 FOR_NB_SCREENS(i)
527 if(update_onvol_change(&gui_wps[i]))
528 res = true;
530 if (res) {
531 restore = true;
532 restoretimer = RESTORE_WPS_NEXT_SECOND;
535 break;
536 case ACTION_WPS_VOLDOWN:
538 FOR_NB_SCREENS(i)
539 gui_wps[i].data->button_time_volume = current_tick;
540 global_settings.volume--;
541 setvol();
542 bool res = false;
543 FOR_NB_SCREENS(i)
545 if(update_onvol_change(&gui_wps[i]))
546 res = true;
548 if (res) {
549 restore = true;
550 restoretimer = RESTORE_WPS_NEXT_SECOND;
553 break;
554 /* fast forward
555 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
556 case ACTION_WPS_SEEKFWD:
557 if (global_settings.party_mode)
558 break;
559 if (current_tick -last_right < HZ)
561 if (wps_state.id3->cuesheet)
563 audio_next();
565 else
567 change_dir(1);
570 else
571 ffwd_rew(ACTION_WPS_SEEKFWD);
572 last_right = last_left = 0;
573 break;
574 /* fast rewind
575 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
576 case ACTION_WPS_SEEKBACK:
577 if (global_settings.party_mode)
578 break;
579 if (current_tick -last_left < HZ)
581 if (wps_state.id3->cuesheet)
583 if (!wps_state.paused)
584 #if (CONFIG_CODEC == SWCODEC)
585 audio_pre_ff_rewind();
586 #else
587 audio_pause();
588 #endif
589 audio_ff_rewind(0);
591 else
593 change_dir(-1);
596 else
597 ffwd_rew(ACTION_WPS_SEEKBACK);
598 last_left = last_right = 0;
599 break;
601 /* prev / restart */
602 case ACTION_WPS_SKIPPREV:
603 if (global_settings.party_mode)
604 break;
605 last_left = current_tick;
606 #ifdef AB_REPEAT_ENABLE
607 /* if we're in A/B repeat mode and the current position
608 is past the A marker, jump back to the A marker... */
609 if ( ab_repeat_mode_enabled() )
611 if ( ab_after_A_marker(wps_state.id3->elapsed) )
613 ab_jump_to_A_marker();
614 break;
615 #if (AB_REPEAT_ENABLE == 2)
616 } else {
617 ab_reset_markers();
618 #endif
621 else
622 /* ...otherwise, do it normally */
623 #endif
624 play_hop(-1);
625 break;
627 /* next
628 OR if skip length set, hop by predetermined amount. */
629 case ACTION_WPS_SKIPNEXT:
630 if (global_settings.party_mode)
631 break;
632 last_right = current_tick;
633 #ifdef AB_REPEAT_ENABLE
634 /* if we're in A/B repeat mode and the current position is
635 before the A marker, jump to the A marker... */
636 if ( ab_repeat_mode_enabled() )
638 if ( ab_before_A_marker(wps_state.id3->elapsed) )
640 ab_jump_to_A_marker();
641 break;
642 #if (AB_REPEAT_ENABLE == 2)
643 } else {
644 ab_reset_markers();
645 #endif
648 else
649 /* ...otherwise, do it normally */
650 #endif
651 play_hop(1);
652 break;
653 /* next / prev directories */
654 /* and set A-B markers if in a-b mode */
655 case ACTION_WPS_ABSETB_NEXTDIR:
656 if (global_settings.party_mode)
657 break;
658 #if defined(AB_REPEAT_ENABLE)
659 if (ab_repeat_mode_enabled())
661 ab_set_B_marker(wps_state.id3->elapsed);
662 ab_jump_to_A_marker();
664 else
665 #endif
667 change_dir(1);
669 break;
670 case ACTION_WPS_ABSETA_PREVDIR:
671 if (global_settings.party_mode)
672 break;
673 #if defined(AB_REPEAT_ENABLE)
674 if (ab_repeat_mode_enabled())
675 ab_set_A_marker(wps_state.id3->elapsed);
676 else
677 #endif
679 change_dir(-1);
681 break;
682 /* menu key functions */
683 case ACTION_WPS_MENU:
684 gwps_leave_wps();
685 return GO_TO_ROOT;
686 break;
689 #ifdef HAVE_QUICKSCREEN
690 case ACTION_WPS_QUICKSCREEN:
692 gwps_leave_wps();
693 if (quick_screen_quick(button))
694 return SYS_USB_CONNECTED;
695 restore = true;
697 break;
698 #endif /* HAVE_QUICKSCREEN */
700 /* screen settings */
701 #ifdef BUTTON_F3
702 case ACTION_F3:
704 gwps_leave_wps();
705 if (quick_screen_f3(BUTTON_F3))
706 return SYS_USB_CONNECTED;
707 restore = true;
709 break;
710 #endif /* BUTTON_F3 */
712 /* pitch screen */
713 #ifdef HAVE_PITCHSCREEN
714 case ACTION_WPS_PITCHSCREEN:
716 gwps_leave_wps();
717 if (1 == gui_syncpitchscreen_run())
718 return SYS_USB_CONNECTED;
719 restore = true;
721 break;
722 #endif /* HAVE_PITCHSCREEN */
724 #ifdef AB_REPEAT_ENABLE
725 /* reset A&B markers */
726 case ACTION_WPS_ABRESET:
727 if (ab_repeat_mode_enabled())
729 ab_reset_markers();
730 update = true;
732 break;
733 #endif /* AB_REPEAT_ENABLE */
735 /* stop and exit wps */
736 case ACTION_WPS_STOP:
737 if (global_settings.party_mode)
738 break;
739 bookmark = true;
740 exit = true;
741 break;
743 case ACTION_WPS_ID3SCREEN:
745 gwps_leave_wps();
746 browse_id3();
747 restore = true;
749 break;
750 #ifdef HAVE_TOUCHSCREEN
751 case ACTION_TOUCH_SHUFFLE: /* toggle shuffle mode */
753 global_settings.playlist_shuffle =
754 !global_settings.playlist_shuffle;
755 #if CONFIG_CODEC == SWCODEC
756 dsp_set_replaygain();
757 #endif
758 if (global_settings.playlist_shuffle)
759 playlist_randomise(NULL, current_tick, true);
760 else
761 playlist_sort(NULL, true);
763 break;
764 case ACTION_TOUCH_REPMODE: /* cycle the repeat mode setting */
766 const struct settings_list *rep_setting =
767 find_setting(&global_settings.repeat_mode, NULL);
768 option_select_next_val(rep_setting, false, true);
769 audio_flush_and_reload_tracks();
771 break;
772 #endif /* HAVE_TOUCHSCREEN */
773 /* this case is used by the softlock feature
774 * it requests a full update here */
775 case ACTION_REDRAW:
776 wps_state.do_full_update = true;
777 break;
778 case ACTION_NONE: /* Timeout, do a partial update */
779 update = true;
780 ffwd_rew(button); /* hopefully fix the ffw/rwd bug */
781 break;
782 #ifdef HAVE_RECORDING
783 case ACTION_WPS_REC:
784 exit = true;
785 break;
786 #endif
787 case SYS_POWEROFF:
788 default_event_handler(SYS_POWEROFF);
789 break;
790 case ACTION_WPS_VIEW_PLAYLIST:
791 gwps_leave_wps();
792 if (playlist_viewer()) /* true if USB connected */
793 return SYS_USB_CONNECTED;
794 restore = true;
795 break;
796 default:
797 if(default_event_handler(button) == SYS_USB_CONNECTED)
798 return GO_TO_ROOT;
799 update = true;
800 break;
803 if (wps_state.do_full_update || update)
805 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
806 gwps_caption_backlight(&wps_state);
807 #endif
808 FOR_NB_SCREENS(i)
810 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
811 if (lcd_active()
812 #ifdef HAVE_REMOTE_LCD
813 /* currently, all remotes are readable without backlight
814 * so still update those */
815 || (i == SCREEN_REMOTE)
816 #endif
818 #endif
820 gui_wps_update(&gui_wps[i]);
823 wps_state.do_full_update = false;
824 update = false;
827 if (restore && wps_state.id3 &&
828 ((restoretimer == RESTORE_WPS_INSTANTLY) ||
829 TIME_AFTER(current_tick, restoretimer)))
831 restore = false;
832 restoretimer = RESTORE_WPS_INSTANTLY;
833 gwps_fix_statusbars();
834 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
835 lcd_activation_set_hook(wps_lcd_activation_hook);
836 #endif
837 FOR_NB_SCREENS(i)
839 screens[i].stop_scroll();
840 gui_wps_display(&gui_wps[i]);
844 if (exit) {
845 #ifdef HAVE_LCD_CHARCELLS
846 status_set_record(false);
847 status_set_audio(false);
848 #endif
849 if (global_settings.fade_on_stop)
850 fade(false, true);
852 if (bookmark)
853 bookmark_autobookmark();
854 audio_stop();
855 #ifdef AB_REPEAT_ENABLE
856 ab_reset_markers();
857 #endif
858 gwps_leave_wps();
859 #ifdef HAVE_RECORDING
860 if (button == ACTION_WPS_REC)
861 return GO_TO_RECSCREEN;
862 #endif
863 if (global_settings.browse_current)
864 return GO_TO_PREVIOUS_BROWSER;
865 return GO_TO_PREVIOUS;
868 if (button && !IS_SYSEVENT(button) )
869 storage_spin();
871 return GO_TO_ROOT; /* unreachable - just to reduce compiler warnings */
874 /* this is called from the playback thread so NO DRAWING! */
875 static void track_changed_callback(void *param)
877 wps_state.id3 = (struct mp3entry*)param;
878 wps_state.nid3 = audio_next_track();
879 if (wps_state.id3->cuesheet)
881 cue_find_current_track(wps_state.id3->cuesheet, wps_state.id3->elapsed);
882 cue_spoof_id3(wps_state.id3->cuesheet, wps_state.id3);
884 wps_state.do_full_update = true;
886 static void nextid3available_callback(void* param)
888 (void)param;
889 wps_state.nid3 = audio_next_track();
890 wps_state.do_full_update = true;
894 static void wps_state_init(void)
896 wps_state.ff_rewind = false;
897 wps_state.paused = false;
898 if(audio_status() & AUDIO_STATUS_PLAY)
900 wps_state.id3 = audio_current_track();
901 wps_state.nid3 = audio_next_track();
903 else
905 wps_state.id3 = NULL;
906 wps_state.nid3 = NULL;
908 /* We'll be updating due to restore initialized with true */
909 wps_state.do_full_update = false;
910 /* add the WPS track event callbacks */
911 add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, track_changed_callback);
912 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE, false, nextid3available_callback);
916 #ifdef HAVE_LCD_BITMAP
917 static void statusbar_toggle_handler(void *data)
919 (void)data;
920 int i;
921 gwps_fix_statusbars();
923 FOR_NB_SCREENS(i)
925 struct viewport *vp = &gui_wps[i].data->viewports[0].vp;
926 bool draw = wpsbars & (VP_SB_ONSCREEN(i) | VP_SB_IGNORE_SETTING(i));
927 if (!draw)
929 vp->y = 0;
930 vp->height = screens[i].lcdheight;
932 else
934 bool bar_at_top = statusbar_position(i) != STATUSBAR_BOTTOM;
935 vp->y = bar_at_top?STATUSBAR_HEIGHT:0;
936 vp->height = screens[i].lcdheight - STATUSBAR_HEIGHT;
940 #endif
942 void gui_sync_wps_init(void)
944 int i;
945 FOR_NB_SCREENS(i)
947 wps_data_init(&wps_datas[i]);
948 #ifdef HAVE_ALBUMART
949 wps_datas[i].wps_uses_albumart = 0;
950 #endif
951 #ifdef HAVE_REMOTE_LCD
952 wps_datas[i].remote_wps = (i != 0);
953 #endif
954 gui_wps[i].data = &wps_datas[i];
955 gui_wps[i].display = &screens[i];
956 /* Currently no seperate wps_state needed/possible
957 so use the only available ( "global" ) one */
958 gui_wps[i].state = &wps_state;
960 #ifdef HAVE_LCD_BITMAP
961 add_event(GUI_EVENT_STATUSBAR_TOGGLE, false, statusbar_toggle_handler);
962 #endif
963 #if LCD_DEPTH > 1
964 unload_wps_backdrop();
965 #endif
966 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
967 unload_remote_wps_backdrop();
968 #endif
971 #ifdef HAVE_ALBUMART
972 /* Returns true if at least one of the gui_wps screens has an album art
973 tag in its wps structure */
974 bool gui_sync_wps_uses_albumart(void)
976 int i;
977 FOR_NB_SCREENS(i) {
978 struct gui_wps *gwps = &gui_wps[i];
979 if (gwps->data && (gwps->data->wps_uses_albumart != WPS_ALBUMART_NONE))
980 return true;
982 return false;
984 #endif