beginings of a working touchscreen interface for the WPS. 2 new tags:
[maemo-rb.git] / apps / gui / gwps.c
blob26b531e33277006aa02e0617bab43933f4f17f0c
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 "action.h"
50 #include "lang.h"
51 #include "bookmark.h"
52 #include "misc.h"
53 #include "sound.h"
54 #include "onplay.h"
55 #include "abrepeat.h"
56 #include "playback.h"
57 #include "splash.h"
58 #include "cuesheet.h"
59 #include "ata_idle_notify.h"
60 #include "root_menu.h"
61 #include "backdrop.h"
62 #include "quickscreen.h"
63 #include "pitchscreen.h"
64 #include "appevents.h"
65 #include "viewport.h"
66 #include "pcmbuf.h"
68 #define RESTORE_WPS_INSTANTLY 0l
69 #define RESTORE_WPS_NEXT_SECOND ((long)(HZ+current_tick))
70 /* in milliseconds */
71 #define DEFAULT_SKIP_TRESH 3000ul
73 static int wpsbars;
74 /* currently only one wps_state is needed */
75 struct wps_state wps_state;
76 struct gui_wps gui_wps[NB_SCREENS];
77 static struct wps_data wps_datas[NB_SCREENS];
79 /* initial setup of wps_data */
80 static void wps_state_init(void);
81 static void track_changed_callback(void *param);
82 static void nextid3available_callback(void* param);
85 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
86 static void gwps_caption_backlight(struct wps_state *state)
88 if (state && state->id3)
90 #ifdef HAVE_BACKLIGHT
91 if (global_settings.caption_backlight)
93 /* turn on backlight n seconds before track ends, and turn it off n
94 seconds into the new track. n == backlight_timeout, or 5s */
95 int n = global_settings.backlight_timeout * 1000;
97 if ( n < 1000 )
98 n = 5000; /* use 5s if backlight is always on or off */
100 if (((state->id3->elapsed < 1000) ||
101 ((state->id3->length - state->id3->elapsed) < (unsigned)n)) &&
102 (state->paused == false))
103 backlight_on();
105 #endif
106 #ifdef HAVE_REMOTE_LCD
107 if (global_settings.remote_caption_backlight)
109 /* turn on remote backlight n seconds before track ends, and turn it
110 off n seconds into the new track. n == remote_backlight_timeout,
111 or 5s */
112 int n = global_settings.remote_backlight_timeout * 1000;
114 if ( n < 1000 )
115 n = 5000; /* use 5s if backlight is always on or off */
117 if (((state->id3->elapsed < 1000) ||
118 ((state->id3->length - state->id3->elapsed) < (unsigned)n)) &&
119 (state->paused == false))
120 remote_backlight_on();
122 #endif
125 #endif
128 static void change_dir(int direction)
130 if (global_settings.prevent_skip)
131 return;
133 if (direction < 0)
134 audio_prev_dir();
135 else if (direction > 0)
136 audio_next_dir();
139 static void prev_track(unsigned long skip_thresh)
141 if (wps_state.id3->elapsed < skip_thresh)
143 audio_prev();
144 return;
146 else
148 if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type)
150 curr_cuesheet_skip(-1, wps_state.id3->elapsed);
151 return;
154 if (!wps_state.paused)
155 #if (CONFIG_CODEC == SWCODEC)
156 audio_pre_ff_rewind();
157 #else
158 audio_pause();
159 #endif
161 audio_ff_rewind(0);
163 #if (CONFIG_CODEC != SWCODEC)
164 if (!wps_state.paused)
165 audio_resume();
166 #endif
170 static void next_track(void)
172 /* take care of if we're playing a cuesheet */
173 if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type)
175 if (curr_cuesheet_skip(1, wps_state.id3->elapsed))
177 /* if the result was false, then we really want
178 to skip to the next track */
179 return;
183 audio_next();
186 static void play_hop(int direction)
188 unsigned long step = ((unsigned long)global_settings.skip_length)*1000;
189 unsigned long elapsed = wps_state.id3->elapsed;
190 unsigned long remaining = wps_state.id3->length - elapsed;
192 if (!global_settings.prevent_skip &&
193 (!step ||
194 (direction > 0 && step >= remaining) ||
195 (direction < 0 && elapsed < DEFAULT_SKIP_TRESH)))
196 { /* Do normal track skipping */
197 if (direction > 0)
198 next_track();
199 else if (direction < 0)
200 prev_track(DEFAULT_SKIP_TRESH);
201 return;
204 if (direction == 1 && step >= remaining)
206 #if CONFIG_CODEC == SWCODEC
207 if(global_settings.beep)
208 pcmbuf_beep(1000, 150, 1500*global_settings.beep);
209 #endif
210 return;
212 else if ((direction == -1 && elapsed < step))
214 elapsed = 0;
216 else
218 elapsed += step * direction;
220 if((audio_status() & AUDIO_STATUS_PLAY) && !wps_state.paused)
222 #if (CONFIG_CODEC == SWCODEC)
223 audio_pre_ff_rewind();
224 #else
225 audio_pause();
226 #endif
228 audio_ff_rewind(wps_state.id3->elapsed = elapsed);
229 #if (CONFIG_CODEC != SWCODEC)
230 if (!wps_state.paused)
231 audio_resume();
232 #endif
235 static void gwps_fix_statusbars(void)
237 #ifdef HAVE_LCD_BITMAP
238 int i;
239 wpsbars = VP_SB_HIDE_ALL;
240 FOR_NB_SCREENS(i)
242 bool draw = false;
243 if (gui_wps[i].data->wps_sb_tag)
244 draw = gui_wps[i].data->show_sb_on_wps;
245 else if (global_settings.statusbar)
246 wpsbars |= VP_SB_ONSCREEN(i);
247 if (draw)
248 wpsbars |= (VP_SB_ONSCREEN(i) | VP_SB_IGNORE_SETTING(i));
250 #else
251 wpsbars = VP_SB_ALLSCREENS;
252 #endif
255 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
257 * If the user is unable to see the wps, because the display is deactivated,
258 * we surpress updates until the wps gets actived again (the lcd driver will
259 * call this hook)
260 * */
261 static void wps_lcd_activation_hook(void)
263 /* issue an update */
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 static 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 struct touchregion *r;
304 if (type != BUTTON_REL)
305 return ACTION_TOUCHSCREEN;
306 for (i=0; i<data->touchregion_count; i++)
308 r = &data->touchregion[i];
309 /* make sure this region's viewport is visible */
310 if (r->wvp->hidden_flags&VP_DRAW_HIDDEN)
311 continue;
312 /* reposition the touch inside the viewport */
313 vx = x - r->wvp->vp.x;
314 vy = y - r->wvp->vp.y;
315 /* check if its inside this viewport */
316 if (vx >= 0 && vx < r->wvp->vp.x + r->wvp->vp.width &&
317 vy >= 0 && vy < r->wvp->vp.y + r->wvp->vp.height)
319 /* now see if the point is inside this region */
320 if (vx >= r->x && vx < r->x+r->width &&
321 vy >= r->y && vy < r->y+r->height)
322 return r->action;
325 return ACTION_TOUCHSCREEN;
327 #endif
328 /* The WPS can be left in two ways:
329 * a) call a function, which draws over the wps. In this case, the wps
330 * will be still active (i.e. the below function didn't return)
331 * b) return with a value evaluated by root_menu.c, in this case the wps
332 * is really left, and root_menu will handle the next screen
334 * In either way, call gwps_leave_wps(), in order to restore the correct
335 * "main screen" backdrops and statusbars
337 long gui_wps_show(void)
339 long button = 0;
340 bool restore = true;
341 long restoretimer = RESTORE_WPS_INSTANTLY; /* timer to delay screen redraw temporarily */
342 bool exit = false;
343 bool bookmark = false;
344 bool update = false;
345 int i;
346 long last_left = 0, last_right = 0;
348 #ifdef HAVE_LCD_CHARCELLS
349 status_set_audio(true);
350 status_set_param(false);
351 #endif
353 #ifdef AB_REPEAT_ENABLE
354 ab_repeat_init();
355 ab_reset_markers();
356 #endif
357 wps_state_init();
359 while ( 1 )
361 bool audio_paused = (audio_status() & AUDIO_STATUS_PAUSE)?true:false;
363 /* did someone else (i.e power thread) change audio pause mode? */
364 if (wps_state.paused != audio_paused) {
365 wps_state.paused = audio_paused;
367 /* if another thread paused audio, we are probably in car mode,
368 about to shut down. lets save the settings. */
369 if (wps_state.paused) {
370 settings_save();
371 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
372 call_storage_idle_notifys(true);
373 #endif
377 #ifdef HAVE_LCD_BITMAP
378 /* when the peak meter is enabled we want to have a
379 few extra updates to make it look smooth. On the
380 other hand we don't want to waste energy if it
381 isn't displayed */
382 bool pm=false;
383 FOR_NB_SCREENS(i)
385 if(gui_wps[i].data->peak_meter_enabled)
386 pm = true;
389 if (pm) {
390 long next_refresh = current_tick;
391 long next_big_refresh = current_tick + HZ / 5;
392 button = BUTTON_NONE;
393 while (TIME_BEFORE(current_tick, next_big_refresh)) {
394 button = get_action(CONTEXT_WPS|ALLOW_SOFTLOCK,TIMEOUT_NOBLOCK);
395 if (button != ACTION_NONE) {
396 break;
398 peak_meter_peek();
399 sleep(0); /* Sleep until end of current tick. */
401 if (TIME_AFTER(current_tick, next_refresh)) {
402 FOR_NB_SCREENS(i)
404 if(gui_wps[i].data->peak_meter_enabled)
405 gui_wps_redraw(&gui_wps[i], 0,
406 WPS_REFRESH_PEAK_METER);
407 next_refresh += HZ / PEAK_METER_FPS;
414 /* The peak meter is disabled
415 -> no additional screen updates needed */
416 else
417 #endif
419 button = get_action(CONTEXT_WPS|ALLOW_SOFTLOCK,
420 restore ? HZ/100 : HZ/5);
423 /* Exit if audio has stopped playing. This happens e.g. at end of
424 playlist or if using the sleep timer. */
425 if (!(audio_status() & AUDIO_STATUS_PLAY))
426 exit = true;
427 #ifdef HAVE_TOUCHSCREEN
428 if (button == ACTION_TOUCHSCREEN)
429 button = wps_get_touchaction(gui_wps[SCREEN_MAIN].data);
430 #endif
431 /* The iPods/X5/M5 use a single button for the A-B mode markers,
432 defined as ACTION_WPSAB_SINGLE in their config files. */
433 #ifdef ACTION_WPSAB_SINGLE
434 if (!global_settings.party_mode && ab_repeat_mode_enabled())
436 static int wps_ab_state = 0;
437 if (button == ACTION_WPSAB_SINGLE)
439 switch (wps_ab_state)
441 case 0: /* set the A spot */
442 button = ACTION_WPS_ABSETA_PREVDIR;
443 break;
444 case 1: /* set the B spot */
445 button = ACTION_WPS_ABSETB_NEXTDIR;
446 break;
447 case 2:
448 button = ACTION_WPS_ABRESET;
449 break;
451 wps_ab_state = (wps_ab_state+1) % 3;
454 #endif
455 switch(button)
457 case ACTION_WPS_CONTEXT:
459 gwps_leave_wps();
460 /* if music is stopped in the context menu we want to exit the wps */
461 if (onplay(wps_state.id3->path,
462 FILE_ATTR_AUDIO, CONTEXT_WPS) == ONPLAY_MAINMENU
463 || !audio_status())
464 return GO_TO_ROOT;
465 restore = true;
467 break;
469 case ACTION_WPS_BROWSE:
470 #ifdef HAVE_LCD_CHARCELLS
471 status_set_record(false);
472 status_set_audio(false);
473 #endif
474 gwps_leave_wps();
475 return GO_TO_PREVIOUS_BROWSER;
476 break;
478 /* play/pause */
479 case ACTION_WPS_PLAY:
480 if (global_settings.party_mode)
481 break;
482 if ( wps_state.paused )
484 wps_state.paused = false;
485 if ( global_settings.fade_on_stop )
486 fade(true, true);
487 else
488 audio_resume();
490 else
492 wps_state.paused = true;
493 if ( global_settings.fade_on_stop )
494 fade(false, true);
495 else
496 audio_pause();
497 settings_save();
498 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
499 call_storage_idle_notifys(true); /* make sure resume info is saved */
500 #endif
502 break;
504 case ACTION_WPS_VOLUP:
506 FOR_NB_SCREENS(i)
507 gui_wps[i].data->button_time_volume = current_tick;
508 global_settings.volume++;
509 bool res = false;
510 setvol();
511 FOR_NB_SCREENS(i)
513 if(update_onvol_change(&gui_wps[i]))
514 res = true;
516 if (res) {
517 restore = true;
518 restoretimer = RESTORE_WPS_NEXT_SECOND;
521 break;
522 case ACTION_WPS_VOLDOWN:
524 FOR_NB_SCREENS(i)
525 gui_wps[i].data->button_time_volume = current_tick;
526 global_settings.volume--;
527 setvol();
528 bool res = false;
529 FOR_NB_SCREENS(i)
531 if(update_onvol_change(&gui_wps[i]))
532 res = true;
534 if (res) {
535 restore = true;
536 restoretimer = RESTORE_WPS_NEXT_SECOND;
539 break;
540 /* fast forward
541 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
542 case ACTION_WPS_SEEKFWD:
543 if (global_settings.party_mode)
544 break;
545 if (current_tick -last_right < HZ)
547 if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type)
549 audio_next();
551 else
553 change_dir(1);
556 else
557 ffwd_rew(ACTION_WPS_SEEKFWD);
558 last_right = last_left = 0;
559 break;
560 /* fast rewind
561 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
562 case ACTION_WPS_SEEKBACK:
563 if (global_settings.party_mode)
564 break;
565 if (current_tick -last_left < HZ)
567 if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type)
569 if (!wps_state.paused)
570 #if (CONFIG_CODEC == SWCODEC)
571 audio_pre_ff_rewind();
572 #else
573 audio_pause();
574 #endif
575 audio_ff_rewind(0);
577 else
579 change_dir(-1);
582 else
583 ffwd_rew(ACTION_WPS_SEEKBACK);
584 last_left = last_right = 0;
585 break;
587 /* prev / restart */
588 case ACTION_WPS_SKIPPREV:
589 if (global_settings.party_mode)
590 break;
591 last_left = current_tick;
592 #ifdef AB_REPEAT_ENABLE
593 /* if we're in A/B repeat mode and the current position
594 is past the A marker, jump back to the A marker... */
595 if ( ab_repeat_mode_enabled() )
597 if ( ab_after_A_marker(wps_state.id3->elapsed) )
599 ab_jump_to_A_marker();
600 break;
601 #if (AB_REPEAT_ENABLE == 2)
602 } else {
603 ab_reset_markers();
604 #endif
607 else
608 /* ...otherwise, do it normally */
609 #endif
610 play_hop(-1);
611 break;
613 /* next
614 OR if skip length set, hop by predetermined amount. */
615 case ACTION_WPS_SKIPNEXT:
616 if (global_settings.party_mode)
617 break;
618 last_right = current_tick;
619 #ifdef AB_REPEAT_ENABLE
620 /* if we're in A/B repeat mode and the current position is
621 before the A marker, jump to the A marker... */
622 if ( ab_repeat_mode_enabled() )
624 if ( ab_before_A_marker(wps_state.id3->elapsed) )
626 ab_jump_to_A_marker();
627 break;
628 #if (AB_REPEAT_ENABLE == 2)
629 } else {
630 ab_reset_markers();
631 #endif
634 else
635 /* ...otherwise, do it normally */
636 #endif
637 play_hop(1);
638 break;
639 /* next / prev directories */
640 /* and set A-B markers if in a-b mode */
641 case ACTION_WPS_ABSETB_NEXTDIR:
642 if (global_settings.party_mode)
643 break;
644 #if defined(AB_REPEAT_ENABLE)
645 if (ab_repeat_mode_enabled())
647 ab_set_B_marker(wps_state.id3->elapsed);
648 ab_jump_to_A_marker();
650 else
651 #endif
653 change_dir(1);
655 break;
656 case ACTION_WPS_ABSETA_PREVDIR:
657 if (global_settings.party_mode)
658 break;
659 #if defined(AB_REPEAT_ENABLE)
660 if (ab_repeat_mode_enabled())
661 ab_set_A_marker(wps_state.id3->elapsed);
662 else
663 #endif
665 change_dir(-1);
667 break;
668 /* menu key functions */
669 case ACTION_WPS_MENU:
670 gwps_leave_wps();
671 return GO_TO_ROOT;
672 break;
675 #ifdef HAVE_QUICKSCREEN
676 case ACTION_WPS_QUICKSCREEN:
678 gwps_leave_wps();
679 if (quick_screen_quick(button))
680 return SYS_USB_CONNECTED;
681 restore = true;
683 break;
684 #endif /* HAVE_QUICKSCREEN */
686 /* screen settings */
687 #ifdef BUTTON_F3
688 case ACTION_F3:
690 gwps_leave_wps();
691 if (quick_screen_f3(BUTTON_F3))
692 return SYS_USB_CONNECTED;
693 restore = true;
695 break;
696 #endif /* BUTTON_F3 */
698 /* pitch screen */
699 #ifdef HAVE_PITCHSCREEN
700 case ACTION_WPS_PITCHSCREEN:
702 gwps_leave_wps();
703 if (1 == gui_syncpitchscreen_run())
704 return SYS_USB_CONNECTED;
705 restore = true;
707 break;
708 #endif /* HAVE_PITCHSCREEN */
710 #ifdef AB_REPEAT_ENABLE
711 /* reset A&B markers */
712 case ACTION_WPS_ABRESET:
713 if (ab_repeat_mode_enabled())
715 ab_reset_markers();
716 update = true;
718 break;
719 #endif /* AB_REPEAT_ENABLE */
721 /* stop and exit wps */
722 case ACTION_WPS_STOP:
723 if (global_settings.party_mode)
724 break;
725 bookmark = true;
726 exit = true;
727 break;
729 case ACTION_WPS_ID3SCREEN:
731 gwps_leave_wps();
732 browse_id3();
733 restore = true;
735 break;
737 case ACTION_REDRAW: /* yes are locked, just redraw */
738 /* fall througgh */
739 case ACTION_NONE: /* Timeout, do an partial update */
740 update = true;
741 ffwd_rew(button); /* hopefully fix the ffw/rwd bug */
742 break;
743 #ifdef HAVE_RECORDING
744 case ACTION_WPS_REC:
745 exit = true;
746 break;
747 #endif
748 case SYS_POWEROFF:
749 gwps_leave_wps();
750 default_event_handler(SYS_POWEROFF);
751 break;
753 default:
754 if(default_event_handler(button) == SYS_USB_CONNECTED)
755 return GO_TO_ROOT;
756 update = true;
757 break;
760 if (wps_state.do_full_update || update)
762 #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
763 gwps_caption_backlight(&wps_state);
764 #endif
765 FOR_NB_SCREENS(i)
767 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
768 if (lcd_active()
769 #ifdef HAVE_REMOTE_LCD
770 /* currently, all remotes are readable without backlight
771 * so still update those */
772 || (i == SCREEN_REMOTE)
773 #endif
775 #endif
777 gui_wps_update(&gui_wps[i]);
780 wps_state.do_full_update = false;
781 update = false;
784 if (restore && wps_state.id3 &&
785 ((restoretimer == RESTORE_WPS_INSTANTLY) ||
786 TIME_AFTER(current_tick, restoretimer)))
788 restore = false;
789 restoretimer = RESTORE_WPS_INSTANTLY;
790 gwps_fix_statusbars();
791 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
792 lcd_activation_set_hook(wps_lcd_activation_hook);
793 #endif
794 FOR_NB_SCREENS(i)
796 screens[i].stop_scroll();
797 gui_wps_display(&gui_wps[i]);
801 if (exit) {
802 #ifdef HAVE_LCD_CHARCELLS
803 status_set_record(false);
804 status_set_audio(false);
805 #endif
806 if (global_settings.fade_on_stop)
807 fade(false, true);
809 if (bookmark)
810 bookmark_autobookmark();
811 audio_stop();
812 #ifdef AB_REPEAT_ENABLE
813 ab_reset_markers();
814 #endif
815 gwps_leave_wps();
816 #ifdef HAVE_RECORDING
817 if (button == ACTION_WPS_REC)
818 return GO_TO_RECSCREEN;
819 #endif
820 if (global_settings.browse_current)
821 return GO_TO_PREVIOUS_BROWSER;
822 return GO_TO_PREVIOUS;
825 if (button && !IS_SYSEVENT(button) )
826 storage_spin();
828 return GO_TO_ROOT; /* unreachable - just to reduce compiler warnings */
831 /* this is called from the playback thread so NO DRAWING! */
832 static void track_changed_callback(void *param)
834 wps_state.id3 = (struct mp3entry*)param;
835 wps_state.nid3 = audio_next_track();
837 if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type
838 && strcmp(wps_state.id3->path, curr_cue->audio_filename))
840 /* the current cuesheet isn't the right one any more */
841 /* We need to parse the new cuesheet */
842 char cuepath[MAX_PATH];
844 if (look_for_cuesheet_file(wps_state.id3->path, cuepath) &&
845 parse_cuesheet(cuepath, curr_cue))
847 wps_state.id3->cuesheet_type = 1;
848 strcpy(curr_cue->audio_filename, wps_state.id3->path);
851 cue_spoof_id3(curr_cue, wps_state.id3);
853 wps_state.do_full_update = true;
855 static void nextid3available_callback(void* param)
857 (void)param;
858 wps_state.nid3 = audio_next_track();
859 wps_state.do_full_update = true;
862 /* wps_state */
864 static void wps_state_init(void)
866 wps_state.ff_rewind = false;
867 wps_state.paused = false;
868 if(audio_status() & AUDIO_STATUS_PLAY)
870 wps_state.id3 = audio_current_track();
871 wps_state.nid3 = audio_next_track();
873 else
875 wps_state.id3 = NULL;
876 wps_state.nid3 = NULL;
878 /* We'll be updating due to restore initialized with true */
879 wps_state.do_full_update = false;
880 /* add the WPS track event callbacks */
881 add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, track_changed_callback);
882 add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE, false, nextid3available_callback);
885 /* wps_state end*/
887 #ifdef HAVE_LCD_BITMAP
888 static void statusbar_toggle_handler(void *data)
890 (void)data;
891 int i;
892 gwps_fix_statusbars();
894 FOR_NB_SCREENS(i)
896 struct viewport *vp = &gui_wps[i].data->viewports[0].vp;
897 bool draw = wpsbars & (VP_SB_ONSCREEN(i) | VP_SB_IGNORE_SETTING(i));
898 if (!draw)
900 vp->y = 0;
901 vp->height = screens[i].lcdheight;
903 else
905 vp->y = STATUSBAR_HEIGHT;
906 vp->height = screens[i].lcdheight - STATUSBAR_HEIGHT;
910 #endif
912 void gui_sync_wps_init(void)
914 int i;
915 FOR_NB_SCREENS(i)
917 wps_data_init(&wps_datas[i]);
918 #ifdef HAVE_ALBUMART
919 wps_datas[i].wps_uses_albumart = 0;
920 #endif
921 #ifdef HAVE_REMOTE_LCD
922 wps_datas[i].remote_wps = (i != 0);
923 #endif
924 gui_wps[i].data = &wps_datas[i];
925 gui_wps[i].display = &screens[i];
926 /* Currently no seperate wps_state needed/possible
927 so use the only aviable ( "global" ) one */
928 gui_wps[i].state = &wps_state;
930 #ifdef HAVE_LCD_BITMAP
931 add_event(GUI_EVENT_STATUSBAR_TOGGLE, false, statusbar_toggle_handler);
932 #endif
933 #if LCD_DEPTH > 1
934 unload_wps_backdrop();
935 #endif
936 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
937 unload_remote_wps_backdrop();
938 #endif
941 #ifdef HAVE_ALBUMART
942 /* Returns true if at least one of the gui_wps screens has an album art
943 tag in its wps structure */
944 bool gui_sync_wps_uses_albumart(void)
946 int i;
947 FOR_NB_SCREENS(i) {
948 struct gui_wps *gwps = &gui_wps[i];
949 if (gwps->data && (gwps->data->wps_uses_albumart != WPS_ALBUMART_NONE))
950 return true;
952 return false;
954 #endif