1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
30 #include "backlight.h"
33 #include "filetypes.h"
38 #include "gwps-common.h"
45 #ifdef HAVE_LCD_BITMAP
47 #include "peakmeter.h"
59 #include "ata_idle_notify.h"
60 #include "root_menu.h"
62 #include "quickscreen.h"
63 #include "pitchscreen.h"
64 #include "appevents.h"
66 /* currently only on wps_state is needed */
67 struct wps_state wps_state
;
68 struct gui_wps gui_wps
[NB_SCREENS
];
69 static struct wps_data wps_datas
[NB_SCREENS
];
71 /* change the path to the current played track */
72 static void wps_state_update_ctp(const char *path
);
73 /* initial setup of wps_data */
74 static void wps_state_init(void);
75 /* initial setup of a wps */
76 static void gui_wps_init(struct gui_wps
*gui_wps
);
77 /* connects a wps with a format-description of the displayed content */
78 static void gui_wps_set_data(struct gui_wps
*gui_wps
, struct wps_data
*data
);
79 /* connects a wps with a screen */
80 static void gui_wps_set_disp(struct gui_wps
*gui_wps
, struct screen
*display
);
81 /* connects a wps with a statusbar*/
82 static void gui_wps_set_statusbar(struct gui_wps
*gui_wps
, struct gui_statusbar
*statusbar
);
84 static void prev_track(unsigned skip_thresh
)
86 if (!wps_state
.id3
|| (wps_state
.id3
->elapsed
< skip_thresh
*1000)) {
90 if (cuesheet_is_enabled() && wps_state
.id3
->cuesheet_type
)
92 curr_cuesheet_skip(-1, wps_state
.id3
->elapsed
);
96 if (!wps_state
.paused
)
97 #if (CONFIG_CODEC == SWCODEC)
98 audio_pre_ff_rewind();
105 #if (CONFIG_CODEC != SWCODEC)
106 if (!wps_state
.paused
)
112 static void next_track(void)
114 /* take care of if we're playing a cuesheet */
115 if (cuesheet_is_enabled() && wps_state
.id3
->cuesheet_type
)
117 if (curr_cuesheet_skip(1, wps_state
.id3
->elapsed
))
119 /* if the result was false, then we really want
120 to skip to the next track */
129 long gui_wps_show(void)
132 bool restore
= false;
133 long restoretimer
= 0; /* timer to delay screen redraw temporarily */
135 bool bookmark
= false;
136 bool update_track
= false;
138 long last_left
= 0, last_right
= 0;
142 #ifdef HAVE_LCD_CHARCELLS
143 status_set_audio(true);
144 status_set_param(false);
148 #endif /* LCD_DEPTH > 1 */
151 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
152 show_remote_wps_backdrop();
155 #ifdef AB_REPEAT_ENABLE
160 if(audio_status() & AUDIO_STATUS_PLAY
)
162 wps_state
.id3
= audio_current_track();
163 wps_state
.nid3
= audio_next_track();
165 if (gui_wps_display())
168 gui_wps_refresh(&gui_wps
[i
], 0, WPS_REFRESH_ALL
);
169 wps_state_update_ctp(wps_state
.id3
->path
);
176 bool audio_paused
= (audio_status() & AUDIO_STATUS_PAUSE
)?true:false;
178 /* did someone else (i.e power thread) change audio pause mode? */
179 if (wps_state
.paused
!= audio_paused
) {
180 wps_state
.paused
= audio_paused
;
182 /* if another thread paused audio, we are probably in car mode,
183 about to shut down. lets save the settings. */
184 if (wps_state
.paused
) {
186 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
187 call_storage_idle_notifys(true);
192 #ifdef HAVE_LCD_BITMAP
193 /* when the peak meter is enabled we want to have a
194 few extra updates to make it look smooth. On the
195 other hand we don't want to waste energy if it
200 if(gui_wps
[i
].data
->peak_meter_enabled
)
205 long next_refresh
= current_tick
;
206 long next_big_refresh
= current_tick
+ HZ
/ 5;
207 button
= BUTTON_NONE
;
208 while (TIME_BEFORE(current_tick
, next_big_refresh
)) {
209 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_NOBLOCK
);
210 if (button
!= ACTION_NONE
) {
214 sleep(0); /* Sleep until end of current tick. */
216 if (TIME_AFTER(current_tick
, next_refresh
)) {
219 if(gui_wps
[i
].data
->peak_meter_enabled
)
220 gui_wps_refresh(&gui_wps
[i
], 0,
221 WPS_REFRESH_PEAK_METER
);
222 next_refresh
+= HZ
/ PEAK_METER_FPS
;
229 /* The peak meter is disabled
230 -> no additional screen updates needed */
232 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,HZ
/5);
235 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,HZ
/5);
238 /* Exit if audio has stopped playing. This can happen if using the
239 sleep timer with the charger plugged or if starting a recording
243 /* The iPods/X5/M5 use a single button for the A-B mode markers,
244 defined as ACTION_WPSAB_SINGLE in their config files. */
245 #ifdef ACTION_WPSAB_SINGLE
246 if (!global_settings
.party_mode
&& ab_repeat_mode_enabled())
248 static int wps_ab_state
= 0;
249 if (button
== ACTION_WPSAB_SINGLE
)
251 switch (wps_ab_state
)
253 case 0: /* set the A spot */
254 button
= ACTION_WPS_ABSETA_PREVDIR
;
256 case 1: /* set the B spot */
257 button
= ACTION_WPS_ABSETB_NEXTDIR
;
260 button
= ACTION_WPS_ABRESET
;
263 wps_ab_state
= (wps_ab_state
+1) % 3;
269 case ACTION_WPS_CONTEXT
:
271 show_main_backdrop();
273 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
274 show_remote_main_backdrop();
276 /* if music is stopped in the context menu we want to exit the wps */
277 if (onplay(wps_state
.id3
->path
,
278 FILE_ATTR_AUDIO
, CONTEXT_WPS
) == ONPLAY_MAINMENU
282 /* track might have changed */
288 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
289 show_remote_wps_backdrop();
294 case ACTION_WPS_BROWSE
:
295 #ifdef HAVE_LCD_CHARCELLS
296 status_set_record(false);
297 status_set_audio(false);
300 gui_wps
[i
].display
->stop_scroll();
301 return GO_TO_PREVIOUS_BROWSER
;
305 case ACTION_WPS_PLAY
:
306 if (global_settings
.party_mode
)
308 if ( wps_state
.paused
)
310 wps_state
.paused
= false;
311 if ( global_settings
.fade_on_stop
)
318 wps_state
.paused
= true;
319 if ( global_settings
.fade_on_stop
)
324 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
325 call_storage_idle_notifys(true); /* make sure resume info is saved */
331 case ACTION_WPS_VOLUP
:
334 gui_wps
[i
].data
->button_time_volume
= current_tick
;
335 global_settings
.volume
++;
340 if(update_onvol_change(&gui_wps
[i
]))
345 restoretimer
= current_tick
+ HZ
;
351 case ACTION_WPS_VOLDOWN
:
354 gui_wps
[i
].data
->button_time_volume
= current_tick
;
355 global_settings
.volume
--;
360 if(update_onvol_change(&gui_wps
[i
]))
365 restoretimer
= current_tick
+ HZ
;
370 OR next dir if this is straight after ACTION_WPS_SKIPNEXT
371 OR if skip length set, next track if straight after SKIPPREV. */
372 case ACTION_WPS_SEEKFWD
:
373 if (global_settings
.party_mode
)
375 if (global_settings
.skip_length
== 0
376 && current_tick
-last_right
< HZ
)
378 if (cuesheet_is_enabled() && wps_state
.id3
->cuesheet_type
)
387 else if (global_settings
.skip_length
> 0
388 && current_tick
-last_left
< HZ
) {
392 else ffwd_rew(ACTION_WPS_SEEKFWD
);
393 last_right
= last_left
= 0;
396 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,
397 OR if skip length set, beg of track or prev track if this is
398 straight after SKIPPREV */
399 case ACTION_WPS_SEEKBACK
:
400 if (global_settings
.party_mode
)
402 if (global_settings
.skip_length
== 0
403 && current_tick
-last_left
< HZ
)
405 if (cuesheet_is_enabled() && wps_state
.id3
->cuesheet_type
)
407 if (!wps_state
.paused
)
408 #if (CONFIG_CODEC == SWCODEC)
409 audio_pre_ff_rewind();
420 else if (global_settings
.skip_length
> 0
421 && current_tick
-last_right
< HZ
)
423 prev_track(3+global_settings
.skip_length
);
426 else ffwd_rew(ACTION_WPS_SEEKBACK
);
427 last_left
= last_right
= 0;
431 case ACTION_WPS_SKIPPREV
:
432 if (global_settings
.party_mode
)
434 last_left
= current_tick
;
437 #ifdef AB_REPEAT_ENABLE
438 /* if we're in A/B repeat mode and the current position
439 is past the A marker, jump back to the A marker... */
440 if ( ab_repeat_mode_enabled() )
442 if ( ab_after_A_marker(wps_state
.id3
->elapsed
) )
444 ab_jump_to_A_marker();
446 #if (AB_REPEAT_ENABLE == 2)
452 /* ...otherwise, do it normally */
455 if (global_settings
.skip_length
> 0)
461 OR if skip length set, hop by predetermined amount. */
462 case ACTION_WPS_SKIPNEXT
:
463 if (global_settings
.party_mode
)
465 last_right
= current_tick
;
468 #ifdef AB_REPEAT_ENABLE
469 /* if we're in A/B repeat mode and the current position is
470 before the A marker, jump to the A marker... */
471 if ( ab_repeat_mode_enabled() )
473 if ( ab_before_A_marker(wps_state
.id3
->elapsed
) )
475 ab_jump_to_A_marker();
477 #if (AB_REPEAT_ENABLE == 2)
483 /* ...otherwise, do it normally */
486 if (global_settings
.skip_length
> 0)
490 /* next / prev directories */
491 /* and set A-B markers if in a-b mode */
492 case ACTION_WPS_ABSETB_NEXTDIR
:
493 if (global_settings
.party_mode
)
495 #if defined(AB_REPEAT_ENABLE)
496 if (ab_repeat_mode_enabled())
498 ab_set_B_marker(wps_state
.id3
->elapsed
);
499 ab_jump_to_A_marker();
505 if (global_settings
.skip_length
> 0)
507 else audio_next_dir();
510 case ACTION_WPS_ABSETA_PREVDIR
:
511 if (global_settings
.party_mode
)
513 #if defined(AB_REPEAT_ENABLE)
514 if (ab_repeat_mode_enabled())
515 ab_set_A_marker(wps_state
.id3
->elapsed
);
519 if (global_settings
.skip_length
> 0)
521 else audio_prev_dir();
524 /* menu key functions */
525 case ACTION_WPS_MENU
:
527 gui_wps
[i
].display
->stop_scroll();
532 #ifdef HAVE_QUICKSCREEN
533 case ACTION_WPS_QUICKSCREEN
:
535 show_main_backdrop();
537 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
538 show_remote_main_backdrop();
540 if (quick_screen_quick(button
))
541 return SYS_USB_CONNECTED
;
545 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
546 show_remote_wps_backdrop();
550 #endif /* HAVE_QUICKSCREEN */
552 /* screen settings */
556 show_main_backdrop();
558 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
559 show_remote_main_backdrop();
561 if (quick_screen_f3(BUTTON_F3
))
562 return SYS_USB_CONNECTED
;
565 #endif /* BUTTON_F3 */
568 #ifdef HAVE_PITCHSCREEN
569 case ACTION_WPS_PITCHSCREEN
:
571 show_main_backdrop();
573 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
574 show_remote_main_backdrop();
576 if (1 == gui_syncpitchscreen_run())
577 return SYS_USB_CONNECTED
;
581 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
582 show_remote_wps_backdrop();
586 #endif /* HAVE_PITCHSCREEN */
588 #ifdef AB_REPEAT_ENABLE
589 /* reset A&B markers */
590 case ACTION_WPS_ABRESET
:
591 if (ab_repeat_mode_enabled())
597 #endif /* AB_REPEAT_ENABLE */
599 /* stop and exit wps */
600 case ACTION_WPS_STOP
:
601 if (global_settings
.party_mode
)
607 case ACTION_WPS_ID3SCREEN
:
609 show_main_backdrop();
611 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
612 show_remote_main_backdrop();
618 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
619 show_remote_wps_backdrop();
624 case ACTION_REDRAW
: /* yes are locked, just redraw */
627 case ACTION_NONE
: /* Timeout */
629 ffwd_rew(button
); /* hopefully fix the ffw/rwd bug */
631 #ifdef HAVE_RECORDING
638 show_main_backdrop();
640 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
641 show_remote_main_backdrop();
643 default_event_handler(SYS_POWEROFF
);
647 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
657 if(update(&gui_wps
[i
]))
660 update_track
= false;
664 ((restoretimer
== 0) ||
665 (restoretimer
< current_tick
)))
669 if (gui_wps_display()) {
672 else if (wps_state
.id3
){
674 gui_wps_refresh(&gui_wps
[i
], 0, WPS_REFRESH_NON_STATIC
);
679 #ifdef HAVE_LCD_CHARCELLS
680 status_set_record(false);
681 status_set_audio(false);
683 if (global_settings
.fade_on_stop
)
687 gui_wps
[i
].display
->stop_scroll();
689 bookmark_autobookmark();
691 #ifdef AB_REPEAT_ENABLE
694 #ifdef HAVE_RECORDING
695 if (button
== ACTION_WPS_REC
)
696 return GO_TO_RECSCREEN
;
698 if (global_settings
.browse_current
)
699 return GO_TO_PREVIOUS_BROWSER
;
700 return GO_TO_PREVIOUS
;
706 return GO_TO_ROOT
; /* unreachable - just to reduce compiler warnings */
709 /* needs checking if needed end*/
713 static void wps_state_init(void)
715 wps_state
.ff_rewind
= false;
716 wps_state
.paused
= false;
717 wps_state
.id3
= NULL
;
718 wps_state
.nid3
= NULL
;
719 wps_state
.current_track_path
[0] = '\0';
723 /* these are obviously not used? */
725 void wps_state_update_ff_rew(bool ff_rew
)
727 wps_state
.ff_rewind
= ff_rew
;
730 void wps_state_update_paused(bool paused
)
732 wps_state
.paused
= paused
;
734 void wps_state_update_id3_nid3(struct mp3entry
*id3
, struct mp3entry
*nid3
)
737 wps_state
.nid3
= nid3
;
741 static void wps_state_update_ctp(const char *path
)
743 strncpy(wps_state
.current_track_path
, path
,
744 sizeof(wps_state
.current_track_path
));
745 wps_state
.current_track_path
[sizeof(wps_state
.current_track_path
)-1] = '\0';
749 /* initial setup of a wps */
750 static void gui_wps_init(struct gui_wps
*gui_wps
)
752 gui_wps
->data
= NULL
;
753 gui_wps
->display
= NULL
;
754 gui_wps
->statusbar
= NULL
;
755 /* Currently no seperate wps_state needed/possible
756 so use the only aviable ( "global" ) one */
757 gui_wps
->state
= &wps_state
;
760 /* connects a wps with a format-description of the displayed content */
761 static void gui_wps_set_data(struct gui_wps
*gui_wps
, struct wps_data
*data
)
763 gui_wps
->data
= data
;
766 /* connects a wps with a screen */
767 static void gui_wps_set_disp(struct gui_wps
*gui_wps
, struct screen
*display
)
769 gui_wps
->display
= display
;
772 static void gui_wps_set_statusbar(struct gui_wps
*gui_wps
, struct gui_statusbar
*statusbar
)
774 gui_wps
->statusbar
= statusbar
;
778 void gui_sync_wps_screen_init(void)
782 gui_wps_set_disp(&gui_wps
[i
], &screens
[i
]);
784 #ifdef HAVE_LCD_BITMAP
785 static void statusbar_toggle_handler(void *data
)
789 bool draw
= global_settings
.statusbar
;
793 struct wps_viewport
*vp
= &gui_wps
[i
].data
->viewports
[0];
794 if (gui_wps
[i
].data
->wps_sb_tag
)
795 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
799 vp
->vp
.height
= screens
[i
].lcdheight
;
803 vp
->vp
.y
= STATUSBAR_HEIGHT
;
804 vp
->vp
.height
= screens
[i
].lcdheight
- STATUSBAR_HEIGHT
;
810 void gui_sync_wps_init(void)
815 wps_data_init(&wps_datas
[i
]);
816 #ifdef HAVE_REMOTE_LCD
817 wps_datas
[i
].remote_wps
= (i
!= 0);
819 gui_wps_init(&gui_wps
[i
]);
820 gui_wps_set_data(&gui_wps
[i
], &wps_datas
[i
]);
821 gui_wps_set_statusbar(&gui_wps
[i
], &statusbars
.statusbars
[i
]);
823 #ifdef HAVE_LCD_BITMAP
824 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false, statusbar_toggle_handler
);
827 unload_wps_backdrop();
829 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
830 unload_remote_wps_backdrop();
835 /* Returns true if at least one of the gui_wps screens has an album art
836 tag in its wps structure */
837 bool gui_sync_wps_uses_albumart(void)
841 struct gui_wps
*gwps
= &gui_wps
[i
];
842 if (gwps
->data
&& (gwps
->data
->wps_uses_albumart
!= WPS_ALBUMART_NONE
))