Restore the ACTION_REDRAW case as it was before r20661 (with a slight change as sugge...
[kugel-rb.git] / apps / gui / gwps.c
blob50382a58adf30d7c94df7d2a247b1091ec89a765
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();
140 static void prev_track(unsigned long skip_thresh)
142 if (wps_state.id3->elapsed < skip_thresh)
144 audio_prev();
145 return;
147 else
149 if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type)
151 curr_cuesheet_skip(-1, wps_state.id3->elapsed);
152 return;
155 if (!wps_state.paused)
156 #if (CONFIG_CODEC == SWCODEC)
157 audio_pre_ff_rewind();
158 #else
159 audio_pause();
160 #endif
162 audio_ff_rewind(0);
164 #if (CONFIG_CODEC != SWCODEC)
165 if (!wps_state.paused)
166 audio_resume();
167 #endif
171 static void next_track(void)
173 /* take care of if we're playing a cuesheet */
174 if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type)
176 if (curr_cuesheet_skip(1, wps_state.id3->elapsed))
178 /* if the result was false, then we really want
179 to skip to the next track */
180 return;
184 audio_next();
187 static void play_hop(int direction)
189 unsigned long step = ((unsigned long)global_settings.skip_length)*1000;
190 unsigned long elapsed = wps_state.id3->elapsed;
191 unsigned long remaining = wps_state.id3->length - elapsed;
193 if (!global_settings.prevent_skip &&
194 (!step ||
195 (direction > 0 && step >= remaining) ||
196 (direction < 0 && elapsed < DEFAULT_SKIP_TRESH)))
197 { /* Do normal track skipping */
198 if (direction > 0)
199 next_track();
200 else if (direction < 0)
201 prev_track(DEFAULT_SKIP_TRESH);
202 return;
205 if (direction == 1 && step >= remaining)
207 #if CONFIG_CODEC == SWCODEC
208 if(global_settings.beep)
209 pcmbuf_beep(1000, 150, 1500*global_settings.beep);
210 #endif
211 return;
213 else if ((direction == -1 && elapsed < step))
215 elapsed = 0;
217 else
219 elapsed += step * direction;
221 if((audio_status() & AUDIO_STATUS_PLAY) && !wps_state.paused)
223 #if (CONFIG_CODEC == SWCODEC)
224 audio_pre_ff_rewind();
225 #else
226 audio_pause();
227 #endif
229 audio_ff_rewind(wps_state.id3->elapsed = elapsed);
230 #if (CONFIG_CODEC != SWCODEC)
231 if (!wps_state.paused)
232 audio_resume();
233 #endif
236 static void gwps_fix_statusbars(void)
238 #ifdef HAVE_LCD_BITMAP
239 int i;
240 wpsbars = VP_SB_HIDE_ALL;
241 FOR_NB_SCREENS(i)
243 bool draw = false;
244 if (gui_wps[i].data->wps_sb_tag)
245 draw = gui_wps[i].data->show_sb_on_wps;
246 else if (global_settings.statusbar)
247 wpsbars |= VP_SB_ONSCREEN(i);
248 if (draw)
249 wpsbars |= (VP_SB_ONSCREEN(i) | VP_SB_IGNORE_SETTING(i));
251 #else
252 wpsbars = VP_SB_ALLSCREENS;
253 #endif
256 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
258 * If the user is unable to see the wps, because the display is deactivated,
259 * we surpress updates until the wps gets actived again (the lcd driver will
260 * call this hook to issue an instant update)
261 * */
262 static void wps_lcd_activation_hook(void)
264 wps_state.do_full_update = true;
265 /* force timeout in wps main loop, so that the update is instantly */
266 queue_post(&button_queue, BUTTON_NONE, 0);
268 #endif
270 static void gwps_leave_wps(void)
272 int i, oldbars = VP_SB_HIDE_ALL;
274 FOR_NB_SCREENS(i)
275 gui_wps[i].display->stop_scroll();
276 if (global_settings.statusbar)
277 oldbars = VP_SB_ALLSCREENS;
279 #if LCD_DEPTH > 1
280 show_main_backdrop();
281 #endif
282 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
283 show_remote_main_backdrop();
284 #endif
285 viewportmanager_set_statusbar(oldbars);
286 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
287 /* Play safe and unregister the hook */
288 lcd_activation_set_hook(NULL);
289 #endif
292 void gwps_draw_statusbars(void)
294 viewportmanager_set_statusbar(wpsbars);
296 #ifdef HAVE_TOUCHSCREEN
297 int wps_get_touchaction(struct wps_data *data)
299 short x,y;
300 short vx, vy;
301 int type = action_get_touchscreen_press(&x, &y);
302 int i;
303 static int last_action = ACTION_NONE;
304 struct touchregion *r;
305 bool repeated = (type == BUTTON_REPEAT);
306 bool released = (type == BUTTON_REL);
307 for (i=0; i<data->touchregion_count; i++)
309 r = &data->touchregion[i];
310 /* make sure this region's viewport is visible */
311 if (r->wvp->hidden_flags&VP_DRAW_HIDDEN)
312 continue;
313 /* reposition the touch inside the viewport */
314 vx = x - r->wvp->vp.x;
315 vy = y - r->wvp->vp.y;
316 /* check if its inside this viewport */
317 if (vx >= 0 && vx < r->wvp->vp.x + r->wvp->vp.width &&
318 vy >= 0 && vy < r->wvp->vp.y + r->wvp->vp.height)
320 /* now see if the point is inside this region */
321 if (vx >= r->x && vx < r->x+r->width &&
322 vy >= r->y && vy < r->y+r->height)
324 if ((repeated && r->repeat) ||
325 (released && !r->repeat))
327 last_action = r->action;
328 return r->action;
333 if ((last_action == ACTION_WPS_SEEKBACK || last_action == ACTION_WPS_SEEKFWD))
334 return ACTION_WPS_STOPSEEK;
335 last_action = ACTION_TOUCHSCREEN;
336 return ACTION_TOUCHSCREEN;
338 #endif
339 /* The WPS can be left in two ways:
340 * a) call a function, which draws over the wps. In this case, the wps
341 * will be still active (i.e. the below function didn't return)
342 * b) return with a value evaluated by root_menu.c, in this case the wps
343 * is really left, and root_menu will handle the next screen
345 * In either way, call gwps_leave_wps(), in order to restore the correct
346 * "main screen" backdrops and statusbars
348 long gui_wps_show(void)
350 long button = 0;
351 bool restore = true;
352 long restoretimer = RESTORE_WPS_INSTANTLY; /* timer to delay screen redraw temporarily */
353 bool exit = false;
354 bool bookmark = false;
355 bool update = false;
356 int i;
357 long last_left = 0, last_right = 0;
359 #ifdef HAVE_LCD_CHARCELLS
360 status_set_audio(true);
361 status_set_param(false);
362 #endif
364 #ifdef AB_REPEAT_ENABLE
365 ab_repeat_init();
366 ab_reset_markers();
367 #endif
368 wps_state_init();
370 while ( 1 )
372 bool audio_paused = (audio_status() & AUDIO_STATUS_PAUSE)?true:false;
374 /* did someone else (i.e power thread) change audio pause mode? */
375 if (wps_state.paused != audio_paused) {
376 wps_state.paused = audio_paused;
378 /* if another thread paused audio, we are probably in car mode,
379 about to shut down. lets save the settings. */
380 if (wps_state.paused) {
381 settings_save();
382 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
383 call_storage_idle_notifys(true);
384 #endif
388 #ifdef HAVE_LCD_BITMAP
389 /* when the peak meter is enabled we want to have a
390 few extra updates to make it look smooth. On the
391 other hand we don't want to waste energy if it
392 isn't displayed */
393 bool pm=false;
394 FOR_NB_SCREENS(i)
396 if(gui_wps[i].data->peak_meter_enabled)
397 pm = true;
400 if (pm) {
401 long next_refresh = current_tick;
402 long next_big_refresh = current_tick + HZ / 5;
403 button = BUTTON_NONE;
404 while (TIME_BEFORE(current_tick, next_big_refresh)) {
405 button = get_action(CONTEXT_WPS|ALLOW_SOFTLOCK,TIMEOUT_NOBLOCK);
406 if (button != ACTION_NONE) {
407 break;
409 peak_meter_peek();
410 sleep(0); /* Sleep until end of current tick. */
412 if (TIME_AFTER(current_tick, next_refresh)) {
413 FOR_NB_SCREENS(i)
415 if(gui_wps[i].data->peak_meter_enabled)
416 gui_wps_redraw(&gui_wps[i], 0,
417 WPS_REFRESH_PEAK_METER);
418 next_refresh += HZ / PEAK_METER_FPS;
425 /* The peak meter is disabled
426 -> no additional screen updates needed */
427 else
428 #endif
430 button = get_action(CONTEXT_WPS|ALLOW_SOFTLOCK,
431 restore ? HZ/100 : HZ/5);
434 /* Exit if audio has stopped playing. This happens e.g. at end of
435 playlist or if using the sleep timer. */
436 if (!(audio_status() & AUDIO_STATUS_PLAY))
437 exit = true;
438 #ifdef HAVE_TOUCHSCREEN
439 if (button == ACTION_TOUCHSCREEN)
440 button = wps_get_touchaction(gui_wps[SCREEN_MAIN].data);
441 #endif
442 /* The iPods/X5/M5 use a single button for the A-B mode markers,
443 defined as ACTION_WPSAB_SINGLE in their config files. */
444 #ifdef ACTION_WPSAB_SINGLE
445 if (!global_settings.party_mode && ab_repeat_mode_enabled())
447 static int wps_ab_state = 0;
448 if (button == ACTION_WPSAB_SINGLE)
450 switch (wps_ab_state)
452 case 0: /* set the A spot */
453 button = ACTION_WPS_ABSETA_PREVDIR;
454 break;
455 case 1: /* set the B spot */
456 button = ACTION_WPS_ABSETB_NEXTDIR;
457 break;
458 case 2:
459 button = ACTION_WPS_ABRESET;
460 break;
462 wps_ab_state = (wps_ab_state+1) % 3;
465 #endif
466 switch(button)
468 case ACTION_WPS_CONTEXT:
470 gwps_leave_wps();
471 /* if music is stopped in the context menu we want to exit the wps */
472 if (onplay(wps_state.id3->path,
473 FILE_ATTR_AUDIO, CONTEXT_WPS) == ONPLAY_MAINMENU
474 || !audio_status())
475 return GO_TO_ROOT;
476 restore = true;
478 break;
480 case ACTION_WPS_BROWSE:
481 #ifdef HAVE_LCD_CHARCELLS
482 status_set_record(false);
483 status_set_audio(false);
484 #endif
485 gwps_leave_wps();
486 return GO_TO_PREVIOUS_BROWSER;
487 break;
489 /* play/pause */
490 case ACTION_WPS_PLAY:
491 if (global_settings.party_mode)
492 break;
493 if ( wps_state.paused )
495 wps_state.paused = false;
496 if ( global_settings.fade_on_stop )
497 fade(true, true);
498 else
499 audio_resume();
501 else
503 wps_state.paused = true;
504 if ( global_settings.fade_on_stop )
505 fade(false, true);
506 else
507 audio_pause();
508 settings_save();
509 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
510 call_storage_idle_notifys(true); /* make sure resume info is saved */
511 #endif
513 break;
515 case ACTION_WPS_VOLUP:
517 FOR_NB_SCREENS(i)
518 gui_wps[i].data->button_time_volume = current_tick;
519 global_settings.volume++;
520 bool res = false;
521 setvol();
522 FOR_NB_SCREENS(i)
524 if(update_onvol_change(&gui_wps[i]))
525 res = true;
527 if (res) {
528 restore = true;
529 restoretimer = RESTORE_WPS_NEXT_SECOND;
532 break;
533 case ACTION_WPS_VOLDOWN:
535 FOR_NB_SCREENS(i)
536 gui_wps[i].data->button_time_volume = current_tick;
537 global_settings.volume--;
538 setvol();
539 bool res = false;
540 FOR_NB_SCREENS(i)
542 if(update_onvol_change(&gui_wps[i]))
543 res = true;
545 if (res) {
546 restore = true;
547 restoretimer = RESTORE_WPS_NEXT_SECOND;
550 break;
551 /* fast forward
552 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
553 case ACTION_WPS_SEEKFWD:
554 if (global_settings.party_mode)
555 break;
556 if (current_tick -last_right < HZ)
558 if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type)
560 audio_next();
562 else
564 change_dir(1);
567 else
568 ffwd_rew(ACTION_WPS_SEEKFWD);
569 last_right = last_left = 0;
570 break;
571 /* fast rewind
572 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
573 case ACTION_WPS_SEEKBACK:
574 if (global_settings.party_mode)
575 break;
576 if (current_tick -last_left < HZ)
578 if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type)
580 if (!wps_state.paused)
581 #if (CONFIG_CODEC == SWCODEC)
582 audio_pre_ff_rewind();
583 #else
584 audio_pause();
585 #endif
586 audio_ff_rewind(0);
588 else
590 change_dir(-1);
593 else
594 ffwd_rew(ACTION_WPS_SEEKBACK);
595 last_left = last_right = 0;
596 break;
598 /* prev / restart */
599 case ACTION_WPS_SKIPPREV:
600 if (global_settings.party_mode)
601 break;
602 last_left = current_tick;
603 #ifdef AB_REPEAT_ENABLE
604 /* if we're in A/B repeat mode and the current position
605 is past the A marker, jump back to the A marker... */
606 if ( ab_repeat_mode_enabled() )
608 if ( ab_after_A_marker(wps_state.id3->elapsed) )
610 ab_jump_to_A_marker();
611 break;
612 #if (AB_REPEAT_ENABLE == 2)
613 } else {
614 ab_reset_markers();
615 #endif
618 else
619 /* ...otherwise, do it normally */
620 #endif
621 play_hop(-1);
622 break;
624 /* next
625 OR if skip length set, hop by predetermined amount. */
626 case ACTION_WPS_SKIPNEXT:
627 if (global_settings.party_mode)
628 break;
629 last_right = current_tick;
630 #ifdef AB_REPEAT_ENABLE
631 /* if we're in A/B repeat mode and the current position is
632 before the A marker, jump to the A marker... */
633 if ( ab_repeat_mode_enabled() )
635 if ( ab_before_A_marker(wps_state.id3->elapsed) )
637 ab_jump_to_A_marker();
638 break;
639 #if (AB_REPEAT_ENABLE == 2)
640 } else {
641 ab_reset_markers();
642 #endif
645 else
646 /* ...otherwise, do it normally */
647 #endif
648 play_hop(1);
649 break;
650 /* next / prev directories */
651 /* and set A-B markers if in a-b mode */
652 case ACTION_WPS_ABSETB_NEXTDIR:
653 if (global_settings.party_mode)
654 break;
655 #if defined(AB_REPEAT_ENABLE)
656 if (ab_repeat_mode_enabled())
658 ab_set_B_marker(wps_state.id3->elapsed);
659 ab_jump_to_A_marker();
661 else
662 #endif
664 change_dir(1);
666 break;
667 case ACTION_WPS_ABSETA_PREVDIR:
668 if (global_settings.party_mode)
669 break;
670 #if defined(AB_REPEAT_ENABLE)
671 if (ab_repeat_mode_enabled())
672 ab_set_A_marker(wps_state.id3->elapsed);
673 else
674 #endif
676 change_dir(-1);
678 break;
679 /* menu key functions */
680 case ACTION_WPS_MENU:
681 gwps_leave_wps();
682 return GO_TO_ROOT;
683 break;
686 #ifdef HAVE_QUICKSCREEN
687 case ACTION_WPS_QUICKSCREEN:
689 gwps_leave_wps();
690 if (quick_screen_quick(button))
691 return SYS_USB_CONNECTED;
692 restore = true;
694 break;
695 #endif /* HAVE_QUICKSCREEN */
697 /* screen settings */
698 #ifdef BUTTON_F3
699 case ACTION_F3:
701 gwps_leave_wps();
702 if (quick_screen_f3(BUTTON_F3))
703 return SYS_USB_CONNECTED;
704 restore = true;
706 break;
707 #endif /* BUTTON_F3 */
709 /* pitch screen */
710 #ifdef HAVE_PITCHSCREEN
711 case ACTION_WPS_PITCHSCREEN:
713 gwps_leave_wps();
714 if (1 == gui_syncpitchscreen_run())
715 return SYS_USB_CONNECTED;
716 restore = true;
718 break;
719 #endif /* HAVE_PITCHSCREEN */
721 #ifdef AB_REPEAT_ENABLE
722 /* reset A&B markers */
723 case ACTION_WPS_ABRESET:
724 if (ab_repeat_mode_enabled())
726 ab_reset_markers();
727 update = true;
729 break;
730 #endif /* AB_REPEAT_ENABLE */
732 /* stop and exit wps */
733 case ACTION_WPS_STOP:
734 if (global_settings.party_mode)
735 break;
736 bookmark = true;
737 exit = true;
738 break;
740 case ACTION_WPS_ID3SCREEN:
742 gwps_leave_wps();
743 browse_id3();
744 restore = true;
746 break;
747 #ifdef HAVE_TOUCHSCREEN
748 case ACTION_TOUCH_SHUFFLE: /* toggle shuffle mode */
750 global_settings.playlist_shuffle =
751 !global_settings.playlist_shuffle;
752 #if CONFIG_CODEC == SWCODEC
753 dsp_set_replaygain();
754 #endif
755 if (global_settings.playlist_shuffle)
756 playlist_randomise(NULL, current_tick, true);
757 else
758 playlist_sort(NULL, true);
760 break;
761 case ACTION_TOUCH_REPMODE: /* cycle the repeat mode setting */
763 const struct settings_list *rep_setting =
764 find_setting(&global_settings.repeat_mode, NULL);
765 option_select_next_val(rep_setting, false, true);
766 audio_flush_and_reload_tracks();
768 break;
769 #endif /* HAVE_TOUCHSCREEN */
770 case ACTION_REDRAW: /* yes are locked, just redraw */
771 wps_state.do_full_update = true;
772 break;
773 case ACTION_NONE: /* Timeout, do a partial update */
774 update = true;
775 ffwd_rew(button); /* hopefully fix the ffw/rwd bug */
776 break;
777 #ifdef HAVE_RECORDING
778 case ACTION_WPS_REC:
779 exit = true;
780 break;
781 #endif
782 case SYS_POWEROFF:
783 default_event_handler(SYS_POWEROFF);
784 break;
786 default:
787 if(default_event_handler(button) == SYS_USB_CONNECTED)
788 return GO_TO_ROOT;
789 update = true;
790 break;
793 if (wps_state.do_full_update || update)
795 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
796 gwps_caption_backlight(&wps_state);
797 #endif
798 FOR_NB_SCREENS(i)
800 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
801 if (lcd_active()
802 #ifdef HAVE_REMOTE_LCD
803 /* currently, all remotes are readable without backlight
804 * so still update those */
805 || (i == SCREEN_REMOTE)
806 #endif
808 #endif
810 gui_wps_update(&gui_wps[i]);
813 wps_state.do_full_update = false;
814 update = false;
817 if (restore && wps_state.id3 &&
818 ((restoretimer == RESTORE_WPS_INSTANTLY) ||
819 TIME_AFTER(current_tick, restoretimer)))
821 restore = false;
822 restoretimer = RESTORE_WPS_INSTANTLY;
823 gwps_fix_statusbars();
824 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
825 lcd_activation_set_hook(wps_lcd_activation_hook);
826 #endif
827 FOR_NB_SCREENS(i)
829 screens[i].stop_scroll();
830 gui_wps_display(&gui_wps[i]);
834 if (exit) {
835 #ifdef HAVE_LCD_CHARCELLS
836 status_set_record(false);
837 status_set_audio(false);
838 #endif
839 if (global_settings.fade_on_stop)
840 fade(false, true);
842 if (bookmark)
843 bookmark_autobookmark();
844 audio_stop();
845 #ifdef AB_REPEAT_ENABLE
846 ab_reset_markers();
847 #endif
848 gwps_leave_wps();
849 #ifdef HAVE_RECORDING
850 if (button == ACTION_WPS_REC)
851 return GO_TO_RECSCREEN;
852 #endif
853 if (global_settings.browse_current)
854 return GO_TO_PREVIOUS_BROWSER;
855 return GO_TO_PREVIOUS;
858 if (button && !IS_SYSEVENT(button) )
859 storage_spin();
861 return GO_TO_ROOT; /* unreachable - just to reduce compiler warnings */
864 /* this is called from the playback thread so NO DRAWING! */
865 static void track_changed_callback(void *param)
867 wps_state.id3 = (struct mp3entry*)param;
868 wps_state.nid3 = audio_next_track();
870 if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type
871 && strcmp(wps_state.id3->path, curr_cue->audio_filename))
873 /* the current cuesheet isn't the right one any more */
874 /* We need to parse the new cuesheet */
875 char cuepath[MAX_PATH];
877 if (look_for_cuesheet_file(wps_state.id3->path, cuepath) &&
878 parse_cuesheet(cuepath, curr_cue))
880 wps_state.id3->cuesheet_type = 1;
881 strcpy(curr_cue->audio_filename, wps_state.id3->path);
884 cue_spoof_id3(curr_cue, wps_state.id3);
886 wps_state.do_full_update = true;
888 static void nextid3available_callback(void* param)
890 (void)param;
891 wps_state.nid3 = audio_next_track();
892 wps_state.do_full_update = true;
895 /* wps_state */
897 static void wps_state_init(void)
899 wps_state.ff_rewind = false;
900 wps_state.paused = false;
901 if(audio_status() & AUDIO_STATUS_PLAY)
903 wps_state.id3 = audio_current_track();
904 wps_state.nid3 = audio_next_track();
906 else
908 wps_state.id3 = NULL;
909 wps_state.nid3 = NULL;
911 /* We'll be updating due to restore initialized with true */
912 wps_state.do_full_update = false;
913 /* add the WPS track event callbacks */
914 add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, track_changed_callback);
915 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE, false, nextid3available_callback);
918 /* wps_state end*/
920 #ifdef HAVE_LCD_BITMAP
921 static void statusbar_toggle_handler(void *data)
923 (void)data;
924 int i;
925 gwps_fix_statusbars();
927 FOR_NB_SCREENS(i)
929 struct viewport *vp = &gui_wps[i].data->viewports[0].vp;
930 bool draw = wpsbars & (VP_SB_ONSCREEN(i) | VP_SB_IGNORE_SETTING(i));
931 if (!draw)
933 vp->y = 0;
934 vp->height = screens[i].lcdheight;
936 else
938 vp->y = STATUSBAR_HEIGHT;
939 vp->height = screens[i].lcdheight - STATUSBAR_HEIGHT;
943 #endif
945 void gui_sync_wps_init(void)
947 int i;
948 FOR_NB_SCREENS(i)
950 wps_data_init(&wps_datas[i]);
951 #ifdef HAVE_ALBUMART
952 wps_datas[i].wps_uses_albumart = 0;
953 #endif
954 #ifdef HAVE_REMOTE_LCD
955 wps_datas[i].remote_wps = (i != 0);
956 #endif
957 gui_wps[i].data = &wps_datas[i];
958 gui_wps[i].display = &screens[i];
959 /* Currently no seperate wps_state needed/possible
960 so use the only aviable ( "global" ) one */
961 gui_wps[i].state = &wps_state;
963 #ifdef HAVE_LCD_BITMAP
964 add_event(GUI_EVENT_STATUSBAR_TOGGLE, false, statusbar_toggle_handler);
965 #endif
966 #if LCD_DEPTH > 1
967 unload_wps_backdrop();
968 #endif
969 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
970 unload_remote_wps_backdrop();
971 #endif
974 #ifdef HAVE_ALBUMART
975 /* Returns true if at least one of the gui_wps screens has an album art
976 tag in its wps structure */
977 bool gui_sync_wps_uses_albumart(void)
979 int i;
980 FOR_NB_SCREENS(i) {
981 struct gui_wps *gwps = &gui_wps[i];
982 if (gwps->data && (gwps->data->wps_uses_albumart != WPS_ALBUMART_NONE))
983 return true;
985 return false;
987 #endif