Fix a few comments in gwps.c.
[kugel-rb/myfork.git] / apps / gui / gwps.c
blob827af655df178d83de3f86fdb2c298d7c4af30d8
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"
69 #define RESTORE_WPS_INSTANTLY 0l
70 #define RESTORE_WPS_NEXT_SECOND ((long)(HZ+current_tick))
71 /* in milliseconds */
72 #define DEFAULT_SKIP_TRESH 3000ul
74 static int wpsbars;
75 /* currently only one wps_state is needed */
76 struct wps_state wps_state;
77 struct gui_wps gui_wps[NB_SCREENS];
78 static struct wps_data wps_datas[NB_SCREENS];
80 /* initial setup of wps_data */
81 static void wps_state_init(void);
82 static void track_changed_callback(void *param);
83 static void nextid3available_callback(void* param);
86 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
87 static void gwps_caption_backlight(struct wps_state *state)
89 if (state && state->id3)
91 #ifdef HAVE_BACKLIGHT
92 if (global_settings.caption_backlight)
94 /* turn on backlight n seconds before track ends, and turn it off n
95 seconds into the new track. n == backlight_timeout, or 5s */
96 int n = global_settings.backlight_timeout * 1000;
98 if ( n < 1000 )
99 n = 5000; /* use 5s if backlight is always on or off */
101 if (((state->id3->elapsed < 1000) ||
102 ((state->id3->length - state->id3->elapsed) < (unsigned)n)) &&
103 (state->paused == false))
104 backlight_on();
106 #endif
107 #ifdef HAVE_REMOTE_LCD
108 if (global_settings.remote_caption_backlight)
110 /* turn on remote backlight n seconds before track ends, and turn it
111 off n seconds into the new track. n == remote_backlight_timeout,
112 or 5s */
113 int n = global_settings.remote_backlight_timeout * 1000;
115 if ( n < 1000 )
116 n = 5000; /* use 5s if backlight is always on or off */
118 if (((state->id3->elapsed < 1000) ||
119 ((state->id3->length - state->id3->elapsed) < (unsigned)n)) &&
120 (state->paused == false))
121 remote_backlight_on();
123 #endif
126 #endif
129 static void change_dir(int direction)
131 if (global_settings.prevent_skip)
132 return;
134 if (direction < 0)
135 audio_prev_dir();
136 else if (direction > 0)
137 audio_next_dir();
138 /* prevent the next dir to immediatly start being ffw'd */
139 action_wait_for_release();
142 static void prev_track(unsigned long skip_thresh)
144 if (wps_state.id3->elapsed < skip_thresh)
146 audio_prev();
147 return;
149 else
151 if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type)
153 curr_cuesheet_skip(-1, wps_state.id3->elapsed);
154 return;
157 if (!wps_state.paused)
158 #if (CONFIG_CODEC == SWCODEC)
159 audio_pre_ff_rewind();
160 #else
161 audio_pause();
162 #endif
164 audio_ff_rewind(0);
166 #if (CONFIG_CODEC != SWCODEC)
167 if (!wps_state.paused)
168 audio_resume();
169 #endif
173 static void next_track(void)
175 /* take care of if we're playing a cuesheet */
176 if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type)
178 if (curr_cuesheet_skip(1, wps_state.id3->elapsed))
180 /* if the result was false, then we really want
181 to skip to the next track */
182 return;
186 audio_next();
189 static void play_hop(int direction)
191 unsigned long step = ((unsigned long)global_settings.skip_length)*1000;
192 unsigned long elapsed = wps_state.id3->elapsed;
193 unsigned long remaining = wps_state.id3->length - elapsed;
195 if (!global_settings.prevent_skip &&
196 (!step ||
197 (direction > 0 && step >= remaining) ||
198 (direction < 0 && elapsed < DEFAULT_SKIP_TRESH)))
199 { /* Do normal track skipping */
200 if (direction > 0)
201 next_track();
202 else if (direction < 0)
203 prev_track(DEFAULT_SKIP_TRESH);
204 return;
207 if (direction == 1 && step >= remaining)
209 #if CONFIG_CODEC == SWCODEC
210 if(global_settings.beep)
211 pcmbuf_beep(1000, 150, 1500*global_settings.beep);
212 #endif
213 return;
215 else if ((direction == -1 && elapsed < step))
217 elapsed = 0;
219 else
221 elapsed += step * direction;
223 if((audio_status() & AUDIO_STATUS_PLAY) && !wps_state.paused)
225 #if (CONFIG_CODEC == SWCODEC)
226 audio_pre_ff_rewind();
227 #else
228 audio_pause();
229 #endif
231 audio_ff_rewind(wps_state.id3->elapsed = elapsed);
232 #if (CONFIG_CODEC != SWCODEC)
233 if (!wps_state.paused)
234 audio_resume();
235 #endif
238 static void gwps_fix_statusbars(void)
240 #ifdef HAVE_LCD_BITMAP
241 int i;
242 wpsbars = VP_SB_HIDE_ALL;
243 FOR_NB_SCREENS(i)
245 bool draw = false;
246 if (gui_wps[i].data->wps_sb_tag)
247 draw = gui_wps[i].data->show_sb_on_wps;
248 else if (statusbar_position(i) != STATUSBAR_OFF)
249 draw = true;
250 if (draw)
251 wpsbars |= (VP_SB_ONSCREEN(i) | VP_SB_IGNORE_SETTING(i));
253 #else
254 wpsbars = VP_SB_ALLSCREENS;
255 #endif
258 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
260 * If the user is unable to see the wps, because the display is deactivated,
261 * we surpress updates until the wps is actived again (the lcd driver will
262 * call this hook to issue an instant update)
263 * */
264 static void wps_lcd_activation_hook(void)
266 wps_state.do_full_update = true;
267 /* force timeout in wps main loop, so that the update is instantly */
268 queue_post(&button_queue, BUTTON_NONE, 0);
270 #endif
272 static void gwps_leave_wps(void)
274 int i, oldbars = VP_SB_HIDE_ALL;
276 FOR_NB_SCREENS(i)
277 gui_wps[i].display->stop_scroll();
278 if (global_settings.statusbar)
279 oldbars = VP_SB_ALLSCREENS;
281 #if LCD_DEPTH > 1
282 show_main_backdrop();
283 #endif
284 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
285 show_remote_main_backdrop();
286 #endif
287 viewportmanager_set_statusbar(oldbars);
288 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
289 /* Play safe and unregister the hook */
290 lcd_activation_set_hook(NULL);
291 #endif
294 void gwps_draw_statusbars(void)
296 viewportmanager_set_statusbar(wpsbars);
298 #ifdef HAVE_TOUCHSCREEN
299 int wps_get_touchaction(struct wps_data *data)
301 short x,y;
302 short vx, vy;
303 int type = action_get_touchscreen_press(&x, &y);
304 int i;
305 static int last_action = ACTION_NONE;
306 struct touchregion *r;
307 bool repeated = (type == BUTTON_REPEAT);
308 bool released = (type == BUTTON_REL);
309 for (i=0; i<data->touchregion_count; i++)
311 r = &data->touchregion[i];
312 /* make sure this region's viewport is visible */
313 if (r->wvp->hidden_flags&VP_DRAW_HIDDEN)
314 continue;
315 /* reposition the touch inside the viewport */
316 vx = x - r->wvp->vp.x;
317 vy = y - r->wvp->vp.y;
318 /* check if it's inside this viewport */
319 if (vx >= 0 && vx < r->wvp->vp.x + r->wvp->vp.width &&
320 vy >= 0 && vy < r->wvp->vp.y + r->wvp->vp.height)
322 /* now see if the point is inside this region */
323 if (vx >= r->x && vx < r->x+r->width &&
324 vy >= r->y && vy < r->y+r->height)
326 if ((repeated && r->repeat) ||
327 (released && !r->repeat))
329 last_action = r->action;
330 return r->action;
335 if ((last_action == ACTION_WPS_SEEKBACK || last_action == ACTION_WPS_SEEKFWD))
336 return ACTION_WPS_STOPSEEK;
337 last_action = ACTION_TOUCHSCREEN;
338 return ACTION_TOUCHSCREEN;
340 #endif
341 /* The WPS can be left in two ways:
342 * a) call a function, which draws over the wps. In this case, the wps
343 * will be still active (i.e. the below function didn't return)
344 * b) return with a value evaluated by root_menu.c, in this case the wps
345 * is really left, and root_menu will handle the next screen
347 * In either way, call gwps_leave_wps(), in order to restore the correct
348 * "main screen" backdrops and statusbars
350 long gui_wps_show(void)
352 long button = 0;
353 bool restore = true;
354 long restoretimer = RESTORE_WPS_INSTANTLY; /* timer to delay screen redraw temporarily */
355 bool exit = false;
356 bool bookmark = false;
357 bool update = false;
358 int i;
359 long last_left = 0, last_right = 0;
361 #ifdef HAVE_LCD_CHARCELLS
362 status_set_audio(true);
363 status_set_param(false);
364 #endif
366 #ifdef AB_REPEAT_ENABLE
367 ab_repeat_init();
368 ab_reset_markers();
369 #endif
370 wps_state_init();
372 while ( 1 )
374 bool audio_paused = (audio_status() & AUDIO_STATUS_PAUSE)?true:false;
376 /* did someone else (i.e power thread) change audio pause mode? */
377 if (wps_state.paused != audio_paused) {
378 wps_state.paused = audio_paused;
380 /* if another thread paused audio, we are probably in car mode,
381 about to shut down. lets save the settings. */
382 if (wps_state.paused) {
383 settings_save();
384 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
385 call_storage_idle_notifys(true);
386 #endif
390 #ifdef HAVE_LCD_BITMAP
391 /* when the peak meter is enabled we want to have a
392 few extra updates to make it look smooth. On the
393 other hand we don't want to waste energy if it
394 isn't displayed */
395 bool pm=false;
396 FOR_NB_SCREENS(i)
398 if(gui_wps[i].data->peak_meter_enabled)
399 pm = true;
402 if (pm) {
403 long next_refresh = current_tick;
404 long next_big_refresh = current_tick + HZ / 5;
405 button = BUTTON_NONE;
406 while (TIME_BEFORE(current_tick, next_big_refresh)) {
407 button = get_action(CONTEXT_WPS|ALLOW_SOFTLOCK,TIMEOUT_NOBLOCK);
408 if (button != ACTION_NONE) {
409 break;
411 peak_meter_peek();
412 sleep(0); /* Sleep until end of current tick. */
414 if (TIME_AFTER(current_tick, next_refresh)) {
415 FOR_NB_SCREENS(i)
417 if(gui_wps[i].data->peak_meter_enabled)
418 gui_wps_redraw(&gui_wps[i], 0,
419 WPS_REFRESH_PEAK_METER);
420 next_refresh += HZ / PEAK_METER_FPS;
427 /* The peak meter is disabled
428 -> no additional screen updates needed */
429 else
430 #endif
432 button = get_action(CONTEXT_WPS|ALLOW_SOFTLOCK,
433 restore ? HZ/100 : HZ/5);
436 /* Exit if audio has stopped playing. This happens e.g. at end of
437 playlist or if using the sleep timer. */
438 if (!(audio_status() & AUDIO_STATUS_PLAY))
439 exit = true;
440 #ifdef HAVE_TOUCHSCREEN
441 if (button == ACTION_TOUCHSCREEN)
442 button = wps_get_touchaction(gui_wps[SCREEN_MAIN].data);
443 #endif
444 /* The iPods/X5/M5 use a single button for the A-B mode markers,
445 defined as ACTION_WPSAB_SINGLE in their config files. */
446 #ifdef ACTION_WPSAB_SINGLE
447 if (!global_settings.party_mode && ab_repeat_mode_enabled())
449 static int wps_ab_state = 0;
450 if (button == ACTION_WPSAB_SINGLE)
452 switch (wps_ab_state)
454 case 0: /* set the A spot */
455 button = ACTION_WPS_ABSETA_PREVDIR;
456 break;
457 case 1: /* set the B spot */
458 button = ACTION_WPS_ABSETB_NEXTDIR;
459 break;
460 case 2:
461 button = ACTION_WPS_ABRESET;
462 break;
464 wps_ab_state = (wps_ab_state+1) % 3;
467 #endif
468 switch(button)
470 case ACTION_WPS_CONTEXT:
472 gwps_leave_wps();
473 /* if music is stopped in the context menu we want to exit the wps */
474 if (onplay(wps_state.id3->path,
475 FILE_ATTR_AUDIO, CONTEXT_WPS) == ONPLAY_MAINMENU
476 || !audio_status())
477 return GO_TO_ROOT;
478 restore = true;
480 break;
482 case ACTION_WPS_BROWSE:
483 #ifdef HAVE_LCD_CHARCELLS
484 status_set_record(false);
485 status_set_audio(false);
486 #endif
487 gwps_leave_wps();
488 return GO_TO_PREVIOUS_BROWSER;
489 break;
491 /* play/pause */
492 case ACTION_WPS_PLAY:
493 if (global_settings.party_mode)
494 break;
495 if ( wps_state.paused )
497 wps_state.paused = false;
498 if ( global_settings.fade_on_stop )
499 fade(true, true);
500 else
501 audio_resume();
503 else
505 wps_state.paused = true;
506 if ( global_settings.fade_on_stop )
507 fade(false, true);
508 else
509 audio_pause();
510 settings_save();
511 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
512 call_storage_idle_notifys(true); /* make sure resume info is saved */
513 #endif
515 break;
517 case ACTION_WPS_VOLUP:
519 FOR_NB_SCREENS(i)
520 gui_wps[i].data->button_time_volume = current_tick;
521 global_settings.volume++;
522 bool res = false;
523 setvol();
524 FOR_NB_SCREENS(i)
526 if(update_onvol_change(&gui_wps[i]))
527 res = true;
529 if (res) {
530 restore = true;
531 restoretimer = RESTORE_WPS_NEXT_SECOND;
534 break;
535 case ACTION_WPS_VOLDOWN:
537 FOR_NB_SCREENS(i)
538 gui_wps[i].data->button_time_volume = current_tick;
539 global_settings.volume--;
540 setvol();
541 bool res = false;
542 FOR_NB_SCREENS(i)
544 if(update_onvol_change(&gui_wps[i]))
545 res = true;
547 if (res) {
548 restore = true;
549 restoretimer = RESTORE_WPS_NEXT_SECOND;
552 break;
553 /* fast forward
554 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
555 case ACTION_WPS_SEEKFWD:
556 if (global_settings.party_mode)
557 break;
558 if (current_tick -last_right < HZ)
560 if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type)
562 audio_next();
564 else
566 change_dir(1);
569 else
570 ffwd_rew(ACTION_WPS_SEEKFWD);
571 last_right = last_left = 0;
572 break;
573 /* fast rewind
574 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
575 case ACTION_WPS_SEEKBACK:
576 if (global_settings.party_mode)
577 break;
578 if (current_tick -last_left < HZ)
580 if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type)
582 if (!wps_state.paused)
583 #if (CONFIG_CODEC == SWCODEC)
584 audio_pre_ff_rewind();
585 #else
586 audio_pause();
587 #endif
588 audio_ff_rewind(0);
590 else
592 change_dir(-1);
595 else
596 ffwd_rew(ACTION_WPS_SEEKBACK);
597 last_left = last_right = 0;
598 break;
600 /* prev / restart */
601 case ACTION_WPS_SKIPPREV:
602 if (global_settings.party_mode)
603 break;
604 last_left = current_tick;
605 #ifdef AB_REPEAT_ENABLE
606 /* if we're in A/B repeat mode and the current position
607 is past the A marker, jump back to the A marker... */
608 if ( ab_repeat_mode_enabled() )
610 if ( ab_after_A_marker(wps_state.id3->elapsed) )
612 ab_jump_to_A_marker();
613 break;
614 #if (AB_REPEAT_ENABLE == 2)
615 } else {
616 ab_reset_markers();
617 #endif
620 else
621 /* ...otherwise, do it normally */
622 #endif
623 play_hop(-1);
624 break;
626 /* next
627 OR if skip length set, hop by predetermined amount. */
628 case ACTION_WPS_SKIPNEXT:
629 if (global_settings.party_mode)
630 break;
631 last_right = current_tick;
632 #ifdef AB_REPEAT_ENABLE
633 /* if we're in A/B repeat mode and the current position is
634 before the A marker, jump to the A marker... */
635 if ( ab_repeat_mode_enabled() )
637 if ( ab_before_A_marker(wps_state.id3->elapsed) )
639 ab_jump_to_A_marker();
640 break;
641 #if (AB_REPEAT_ENABLE == 2)
642 } else {
643 ab_reset_markers();
644 #endif
647 else
648 /* ...otherwise, do it normally */
649 #endif
650 play_hop(1);
651 break;
652 /* next / prev directories */
653 /* and set A-B markers if in a-b mode */
654 case ACTION_WPS_ABSETB_NEXTDIR:
655 if (global_settings.party_mode)
656 break;
657 #if defined(AB_REPEAT_ENABLE)
658 if (ab_repeat_mode_enabled())
660 ab_set_B_marker(wps_state.id3->elapsed);
661 ab_jump_to_A_marker();
663 else
664 #endif
666 change_dir(1);
668 break;
669 case ACTION_WPS_ABSETA_PREVDIR:
670 if (global_settings.party_mode)
671 break;
672 #if defined(AB_REPEAT_ENABLE)
673 if (ab_repeat_mode_enabled())
674 ab_set_A_marker(wps_state.id3->elapsed);
675 else
676 #endif
678 change_dir(-1);
680 break;
681 /* menu key functions */
682 case ACTION_WPS_MENU:
683 gwps_leave_wps();
684 return GO_TO_ROOT;
685 break;
688 #ifdef HAVE_QUICKSCREEN
689 case ACTION_WPS_QUICKSCREEN:
691 gwps_leave_wps();
692 if (quick_screen_quick(button))
693 return SYS_USB_CONNECTED;
694 restore = true;
696 break;
697 #endif /* HAVE_QUICKSCREEN */
699 /* screen settings */
700 #ifdef BUTTON_F3
701 case ACTION_F3:
703 gwps_leave_wps();
704 if (quick_screen_f3(BUTTON_F3))
705 return SYS_USB_CONNECTED;
706 restore = true;
708 break;
709 #endif /* BUTTON_F3 */
711 /* pitch screen */
712 #ifdef HAVE_PITCHSCREEN
713 case ACTION_WPS_PITCHSCREEN:
715 gwps_leave_wps();
716 if (1 == gui_syncpitchscreen_run())
717 return SYS_USB_CONNECTED;
718 restore = true;
720 break;
721 #endif /* HAVE_PITCHSCREEN */
723 #ifdef AB_REPEAT_ENABLE
724 /* reset A&B markers */
725 case ACTION_WPS_ABRESET:
726 if (ab_repeat_mode_enabled())
728 ab_reset_markers();
729 update = true;
731 break;
732 #endif /* AB_REPEAT_ENABLE */
734 /* stop and exit wps */
735 case ACTION_WPS_STOP:
736 if (global_settings.party_mode)
737 break;
738 bookmark = true;
739 exit = true;
740 break;
742 case ACTION_WPS_ID3SCREEN:
744 gwps_leave_wps();
745 browse_id3();
746 restore = true;
748 break;
749 #ifdef HAVE_TOUCHSCREEN
750 case ACTION_TOUCH_SHUFFLE: /* toggle shuffle mode */
752 global_settings.playlist_shuffle =
753 !global_settings.playlist_shuffle;
754 #if CONFIG_CODEC == SWCODEC
755 dsp_set_replaygain();
756 #endif
757 if (global_settings.playlist_shuffle)
758 playlist_randomise(NULL, current_tick, true);
759 else
760 playlist_sort(NULL, true);
762 break;
763 case ACTION_TOUCH_REPMODE: /* cycle the repeat mode setting */
765 const struct settings_list *rep_setting =
766 find_setting(&global_settings.repeat_mode, NULL);
767 option_select_next_val(rep_setting, false, true);
768 audio_flush_and_reload_tracks();
770 break;
771 #endif /* HAVE_TOUCHSCREEN */
772 /* this case is used by the softlock feature
773 * it requests a full update here */
774 case ACTION_REDRAW:
775 wps_state.do_full_update = true;
776 break;
777 case ACTION_NONE: /* Timeout, do a partial update */
778 update = true;
779 ffwd_rew(button); /* hopefully fix the ffw/rwd bug */
780 break;
781 #ifdef HAVE_RECORDING
782 case ACTION_WPS_REC:
783 exit = true;
784 break;
785 #endif
786 case SYS_POWEROFF:
787 default_event_handler(SYS_POWEROFF);
788 break;
790 default:
791 if(default_event_handler(button) == SYS_USB_CONNECTED)
792 return GO_TO_ROOT;
793 update = true;
794 break;
797 if (wps_state.do_full_update || update)
799 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
800 gwps_caption_backlight(&wps_state);
801 #endif
802 FOR_NB_SCREENS(i)
804 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
805 if (lcd_active()
806 #ifdef HAVE_REMOTE_LCD
807 /* currently, all remotes are readable without backlight
808 * so still update those */
809 || (i == SCREEN_REMOTE)
810 #endif
812 #endif
814 gui_wps_update(&gui_wps[i]);
817 wps_state.do_full_update = false;
818 update = false;
821 if (restore && wps_state.id3 &&
822 ((restoretimer == RESTORE_WPS_INSTANTLY) ||
823 TIME_AFTER(current_tick, restoretimer)))
825 restore = false;
826 restoretimer = RESTORE_WPS_INSTANTLY;
827 gwps_fix_statusbars();
828 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
829 lcd_activation_set_hook(wps_lcd_activation_hook);
830 #endif
831 FOR_NB_SCREENS(i)
833 screens[i].stop_scroll();
834 gui_wps_display(&gui_wps[i]);
838 if (exit) {
839 #ifdef HAVE_LCD_CHARCELLS
840 status_set_record(false);
841 status_set_audio(false);
842 #endif
843 if (global_settings.fade_on_stop)
844 fade(false, true);
846 if (bookmark)
847 bookmark_autobookmark();
848 audio_stop();
849 #ifdef AB_REPEAT_ENABLE
850 ab_reset_markers();
851 #endif
852 gwps_leave_wps();
853 #ifdef HAVE_RECORDING
854 if (button == ACTION_WPS_REC)
855 return GO_TO_RECSCREEN;
856 #endif
857 if (global_settings.browse_current)
858 return GO_TO_PREVIOUS_BROWSER;
859 return GO_TO_PREVIOUS;
862 if (button && !IS_SYSEVENT(button) )
863 storage_spin();
865 return GO_TO_ROOT; /* unreachable - just to reduce compiler warnings */
868 /* this is called from the playback thread so NO DRAWING! */
869 static void track_changed_callback(void *param)
871 wps_state.id3 = (struct mp3entry*)param;
872 wps_state.nid3 = audio_next_track();
874 if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type
875 && strcmp(wps_state.id3->path, curr_cue->audio_filename))
877 /* the current cuesheet isn't the right one any more */
878 /* We need to parse the new cuesheet */
879 char cuepath[MAX_PATH];
881 if (look_for_cuesheet_file(wps_state.id3->path, cuepath) &&
882 parse_cuesheet(cuepath, curr_cue))
884 wps_state.id3->cuesheet_type = 1;
885 strcpy(curr_cue->audio_filename, wps_state.id3->path);
888 cue_spoof_id3(curr_cue, wps_state.id3);
890 wps_state.do_full_update = true;
892 static void nextid3available_callback(void* param)
894 (void)param;
895 wps_state.nid3 = audio_next_track();
896 wps_state.do_full_update = true;
900 static void wps_state_init(void)
902 wps_state.ff_rewind = false;
903 wps_state.paused = false;
904 if(audio_status() & AUDIO_STATUS_PLAY)
906 wps_state.id3 = audio_current_track();
907 wps_state.nid3 = audio_next_track();
909 else
911 wps_state.id3 = NULL;
912 wps_state.nid3 = NULL;
914 /* We'll be updating due to restore initialized with true */
915 wps_state.do_full_update = false;
916 /* add the WPS track event callbacks */
917 add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, track_changed_callback);
918 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE, false, nextid3available_callback);
922 #ifdef HAVE_LCD_BITMAP
923 static void statusbar_toggle_handler(void *data)
925 (void)data;
926 int i;
927 gwps_fix_statusbars();
929 FOR_NB_SCREENS(i)
931 struct viewport *vp = &gui_wps[i].data->viewports[0].vp;
932 bool draw = wpsbars & (VP_SB_ONSCREEN(i) | VP_SB_IGNORE_SETTING(i));
933 if (!draw)
935 vp->y = 0;
936 vp->height = screens[i].lcdheight;
938 else
940 bool bar_at_top = statusbar_position(i) != STATUSBAR_BOTTOM;
941 vp->y = bar_at_top?STATUSBAR_HEIGHT:0;
942 vp->height = screens[i].lcdheight - STATUSBAR_HEIGHT;
946 #endif
948 void gui_sync_wps_init(void)
950 int i;
951 FOR_NB_SCREENS(i)
953 wps_data_init(&wps_datas[i]);
954 #ifdef HAVE_ALBUMART
955 wps_datas[i].wps_uses_albumart = 0;
956 #endif
957 #ifdef HAVE_REMOTE_LCD
958 wps_datas[i].remote_wps = (i != 0);
959 #endif
960 gui_wps[i].data = &wps_datas[i];
961 gui_wps[i].display = &screens[i];
962 /* Currently no seperate wps_state needed/possible
963 so use the only available ( "global" ) one */
964 gui_wps[i].state = &wps_state;
966 #ifdef HAVE_LCD_BITMAP
967 add_event(GUI_EVENT_STATUSBAR_TOGGLE, false, statusbar_toggle_handler);
968 #endif
969 #if LCD_DEPTH > 1
970 unload_wps_backdrop();
971 #endif
972 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
973 unload_remote_wps_backdrop();
974 #endif
977 #ifdef HAVE_ALBUMART
978 /* Returns true if at least one of the gui_wps screens has an album art
979 tag in its wps structure */
980 bool gui_sync_wps_uses_albumart(void)
982 int i;
983 FOR_NB_SCREENS(i) {
984 struct gui_wps *gwps = &gui_wps[i];
985 if (gwps->data && (gwps->data->wps_uses_albumart != WPS_ALBUMART_NONE))
986 return true;
988 return false;
990 #endif