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"
68 #define RESTORE_WPS_INSTANTLY 0l
69 #define RESTORE_WPS_NEXT_SECOND ((long)(HZ+current_tick))
72 /* currently only one wps_state is needed */
73 struct wps_state wps_state
;
74 struct gui_wps gui_wps
[NB_SCREENS
];
75 static struct wps_data wps_datas
[NB_SCREENS
];
77 /* initial setup of wps_data */
78 static void wps_state_init(void);
80 static void prev_track(unsigned skip_thresh
)
82 if (!wps_state
.id3
|| (wps_state
.id3
->elapsed
< skip_thresh
*1000)) {
86 if (cuesheet_is_enabled() && wps_state
.id3
->cuesheet_type
)
88 curr_cuesheet_skip(-1, wps_state
.id3
->elapsed
);
92 if (!wps_state
.paused
)
93 #if (CONFIG_CODEC == SWCODEC)
94 audio_pre_ff_rewind();
101 #if (CONFIG_CODEC != SWCODEC)
102 if (!wps_state
.paused
)
108 static void next_track(void)
110 /* take care of if we're playing a cuesheet */
111 if (cuesheet_is_enabled() && wps_state
.id3
->cuesheet_type
)
113 if (curr_cuesheet_skip(1, wps_state
.id3
->elapsed
))
115 /* if the result was false, then we really want
116 to skip to the next track */
124 static void play_hop(int direction
)
126 unsigned step
= ((unsigned)global_settings
.skip_length
*1000);
127 unsigned long *elapsed
= &(wps_state
.id3
->elapsed
);
129 if (direction
== 1 && wps_state
.id3
->length
- *elapsed
< step
+1000) {
130 #if CONFIG_CODEC == SWCODEC
131 if(global_settings
.beep
)
132 pcmbuf_beep(1000, 150, 1500*global_settings
.beep
);
135 } else if ((direction
== -1 && *elapsed
< step
)) {
138 *elapsed
+= step
* direction
;
140 if((audio_status() & AUDIO_STATUS_PLAY
) && !wps_state
.paused
) {
141 #if (CONFIG_CODEC == SWCODEC)
142 audio_pre_ff_rewind();
147 audio_ff_rewind(*elapsed
);
148 #if (CONFIG_CODEC != SWCODEC)
149 if (!wps_state
.paused
)
154 static void gwps_fix_statusbars(void)
156 #ifdef HAVE_LCD_BITMAP
158 wpsbars
= VP_SB_HIDE_ALL
;
162 if (gui_wps
[i
].data
->wps_sb_tag
)
163 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
164 else if (global_settings
.statusbar
)
165 wpsbars
|= VP_SB_ONSCREEN(i
);
167 wpsbars
|= (VP_SB_ONSCREEN(i
) | VP_SB_IGNORE_SETTING(i
));
170 wpsbars
= VP_SB_ALLSCREENS
;
175 static void gwps_leave_wps(void)
177 int i
, oldbars
= VP_SB_HIDE_ALL
;
180 gui_wps
[i
].display
->stop_scroll();
181 if (global_settings
.statusbar
)
182 oldbars
= VP_SB_ALLSCREENS
;
185 show_main_backdrop();
187 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
188 show_remote_main_backdrop();
190 viewportmanager_set_statusbar(oldbars
);
193 void gwps_draw_statusbars(void)
195 viewportmanager_set_statusbar(wpsbars
);
198 /* The WPS can be left in two ways:
199 * a) call a function, which draws over the wps. In this case, the wps
200 * will be still active (i.e. the below function didn't return)
201 * b) return with a value evaluated by root_menu.c, in this case the wps
202 * is really left, and root_menu will handle the next screen
204 * In either way, call gwps_leave_wps(), in order to restore the correct
205 * "main screen" backdrops and statusbars
207 long gui_wps_show(void)
210 bool restore
= false;
211 long restoretimer
= RESTORE_WPS_INSTANTLY
; /* timer to delay screen redraw temporarily */
213 bool bookmark
= false;
214 bool update_track
= false;
216 long last_left
= 0, last_right
= 0;
219 #ifdef HAVE_LCD_CHARCELLS
220 status_set_audio(true);
221 status_set_param(false);
225 #endif /* LCD_DEPTH > 1 */
228 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
229 show_remote_wps_backdrop();
231 gwps_fix_statusbars();
233 #ifdef AB_REPEAT_ENABLE
237 if(audio_status() & AUDIO_STATUS_PLAY
)
239 wps_state
.id3
= audio_current_track();
240 wps_state
.nid3
= audio_next_track();
242 if (gui_wps_display())
254 bool audio_paused
= (audio_status() & AUDIO_STATUS_PAUSE
)?true:false;
256 /* did someone else (i.e power thread) change audio pause mode? */
257 if (wps_state
.paused
!= audio_paused
) {
258 wps_state
.paused
= audio_paused
;
260 /* if another thread paused audio, we are probably in car mode,
261 about to shut down. lets save the settings. */
262 if (wps_state
.paused
) {
264 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
265 call_storage_idle_notifys(true);
270 #ifdef HAVE_LCD_BITMAP
271 /* when the peak meter is enabled we want to have a
272 few extra updates to make it look smooth. On the
273 other hand we don't want to waste energy if it
278 if(gui_wps
[i
].data
->peak_meter_enabled
)
283 long next_refresh
= current_tick
;
284 long next_big_refresh
= current_tick
+ HZ
/ 5;
285 button
= BUTTON_NONE
;
286 while (TIME_BEFORE(current_tick
, next_big_refresh
)) {
287 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_NOBLOCK
);
288 if (button
!= ACTION_NONE
) {
292 sleep(0); /* Sleep until end of current tick. */
294 if (TIME_AFTER(current_tick
, next_refresh
)) {
297 if(gui_wps
[i
].data
->peak_meter_enabled
)
298 gui_wps_refresh(&gui_wps
[i
], 0,
299 WPS_REFRESH_PEAK_METER
);
300 next_refresh
+= HZ
/ PEAK_METER_FPS
;
307 /* The peak meter is disabled
308 -> no additional screen updates needed */
312 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,HZ
/5);
315 /* Exit if audio has stopped playing. This can happen if using the
316 sleep timer with the charger plugged or if starting a recording
320 /* The iPods/X5/M5 use a single button for the A-B mode markers,
321 defined as ACTION_WPSAB_SINGLE in their config files. */
322 #ifdef ACTION_WPSAB_SINGLE
323 if (!global_settings
.party_mode
&& ab_repeat_mode_enabled())
325 static int wps_ab_state
= 0;
326 if (button
== ACTION_WPSAB_SINGLE
)
328 switch (wps_ab_state
)
330 case 0: /* set the A spot */
331 button
= ACTION_WPS_ABSETA_PREVDIR
;
333 case 1: /* set the B spot */
334 button
= ACTION_WPS_ABSETB_NEXTDIR
;
337 button
= ACTION_WPS_ABRESET
;
340 wps_ab_state
= (wps_ab_state
+1) % 3;
346 case ACTION_WPS_CONTEXT
:
349 /* if music is stopped in the context menu we want to exit the wps */
350 if (onplay(wps_state
.id3
->path
,
351 FILE_ATTR_AUDIO
, CONTEXT_WPS
) == ONPLAY_MAINMENU
354 /* track might have changed */
360 case ACTION_WPS_BROWSE
:
361 #ifdef HAVE_LCD_CHARCELLS
362 status_set_record(false);
363 status_set_audio(false);
366 return GO_TO_PREVIOUS_BROWSER
;
370 case ACTION_WPS_PLAY
:
371 if (global_settings
.party_mode
)
373 if ( wps_state
.paused
)
375 wps_state
.paused
= false;
376 if ( global_settings
.fade_on_stop
)
383 wps_state
.paused
= true;
384 if ( global_settings
.fade_on_stop
)
389 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
390 call_storage_idle_notifys(true); /* make sure resume info is saved */
396 case ACTION_WPS_VOLUP
:
399 gui_wps
[i
].data
->button_time_volume
= current_tick
;
400 global_settings
.volume
++;
405 if(update_onvol_change(&gui_wps
[i
]))
410 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
416 case ACTION_WPS_VOLDOWN
:
419 gui_wps
[i
].data
->button_time_volume
= current_tick
;
420 global_settings
.volume
--;
425 if(update_onvol_change(&gui_wps
[i
]))
430 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
435 OR next dir if this is straight after ACTION_WPS_SKIPNEXT
436 OR if skip length set, next track if straight after SKIPPREV. */
437 case ACTION_WPS_SEEKFWD
:
438 if (global_settings
.party_mode
)
440 if (global_settings
.skip_length
== 0
441 && current_tick
-last_right
< HZ
)
443 if (cuesheet_is_enabled() && wps_state
.id3
->cuesheet_type
)
452 else if (global_settings
.skip_length
> 0
453 && current_tick
-last_left
< HZ
) {
457 else ffwd_rew(ACTION_WPS_SEEKFWD
);
458 last_right
= last_left
= 0;
461 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,
462 OR if skip length set, beg of track or prev track if this is
463 straight after SKIPPREV */
464 case ACTION_WPS_SEEKBACK
:
465 if (global_settings
.party_mode
)
467 if (global_settings
.skip_length
== 0
468 && current_tick
-last_left
< HZ
)
470 if (cuesheet_is_enabled() && wps_state
.id3
->cuesheet_type
)
472 if (!wps_state
.paused
)
473 #if (CONFIG_CODEC == SWCODEC)
474 audio_pre_ff_rewind();
485 else if (global_settings
.skip_length
> 0
486 && current_tick
-last_right
< HZ
)
488 prev_track(3+global_settings
.skip_length
);
491 else ffwd_rew(ACTION_WPS_SEEKBACK
);
492 last_left
= last_right
= 0;
496 case ACTION_WPS_SKIPPREV
:
497 if (global_settings
.party_mode
)
499 last_left
= current_tick
;
502 #ifdef AB_REPEAT_ENABLE
503 /* if we're in A/B repeat mode and the current position
504 is past the A marker, jump back to the A marker... */
505 if ( ab_repeat_mode_enabled() )
507 if ( ab_after_A_marker(wps_state
.id3
->elapsed
) )
509 ab_jump_to_A_marker();
511 #if (AB_REPEAT_ENABLE == 2)
517 /* ...otherwise, do it normally */
520 if (global_settings
.skip_length
> 0)
526 OR if skip length set, hop by predetermined amount. */
527 case ACTION_WPS_SKIPNEXT
:
528 if (global_settings
.party_mode
)
530 last_right
= current_tick
;
533 #ifdef AB_REPEAT_ENABLE
534 /* if we're in A/B repeat mode and the current position is
535 before the A marker, jump to the A marker... */
536 if ( ab_repeat_mode_enabled() )
538 if ( ab_before_A_marker(wps_state
.id3
->elapsed
) )
540 ab_jump_to_A_marker();
542 #if (AB_REPEAT_ENABLE == 2)
548 /* ...otherwise, do it normally */
551 if (global_settings
.skip_length
> 0)
555 /* next / prev directories */
556 /* and set A-B markers if in a-b mode */
557 case ACTION_WPS_ABSETB_NEXTDIR
:
558 if (global_settings
.party_mode
)
560 #if defined(AB_REPEAT_ENABLE)
561 if (ab_repeat_mode_enabled())
563 ab_set_B_marker(wps_state
.id3
->elapsed
);
564 ab_jump_to_A_marker();
570 if (global_settings
.skip_length
> 0)
572 else audio_next_dir();
575 case ACTION_WPS_ABSETA_PREVDIR
:
576 if (global_settings
.party_mode
)
578 #if defined(AB_REPEAT_ENABLE)
579 if (ab_repeat_mode_enabled())
580 ab_set_A_marker(wps_state
.id3
->elapsed
);
584 if (global_settings
.skip_length
> 0)
586 else audio_prev_dir();
589 /* menu key functions */
590 case ACTION_WPS_MENU
:
596 #ifdef HAVE_QUICKSCREEN
597 case ACTION_WPS_QUICKSCREEN
:
600 if (quick_screen_quick(button
))
601 return SYS_USB_CONNECTED
;
605 #endif /* HAVE_QUICKSCREEN */
607 /* screen settings */
612 if (quick_screen_f3(BUTTON_F3
))
613 return SYS_USB_CONNECTED
;
617 #endif /* BUTTON_F3 */
620 #ifdef HAVE_PITCHSCREEN
621 case ACTION_WPS_PITCHSCREEN
:
624 if (1 == gui_syncpitchscreen_run())
625 return SYS_USB_CONNECTED
;
629 #endif /* HAVE_PITCHSCREEN */
631 #ifdef AB_REPEAT_ENABLE
632 /* reset A&B markers */
633 case ACTION_WPS_ABRESET
:
634 if (ab_repeat_mode_enabled())
640 #endif /* AB_REPEAT_ENABLE */
642 /* stop and exit wps */
643 case ACTION_WPS_STOP
:
644 if (global_settings
.party_mode
)
650 case ACTION_WPS_ID3SCREEN
:
658 case ACTION_REDRAW
: /* yes are locked, just redraw */
661 case ACTION_NONE
: /* Timeout */
663 ffwd_rew(button
); /* hopefully fix the ffw/rwd bug */
665 #ifdef HAVE_RECORDING
672 default_event_handler(SYS_POWEROFF
);
676 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
686 if(update(&gui_wps
[i
]))
689 update_track
= false;
693 ((restoretimer
== RESTORE_WPS_INSTANTLY
) ||
694 TIME_AFTER(current_tick
, restoretimer
)))
696 /* restore wps backrops and statusbars */
700 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
701 show_remote_wps_backdrop();
704 restoretimer
= RESTORE_WPS_INSTANTLY
;
705 if (gui_wps_display()) {
711 #ifdef HAVE_LCD_CHARCELLS
712 status_set_record(false);
713 status_set_audio(false);
715 if (global_settings
.fade_on_stop
)
719 bookmark_autobookmark();
721 #ifdef AB_REPEAT_ENABLE
725 #ifdef HAVE_RECORDING
726 if (button
== ACTION_WPS_REC
)
727 return GO_TO_RECSCREEN
;
729 if (global_settings
.browse_current
)
730 return GO_TO_PREVIOUS_BROWSER
;
731 return GO_TO_PREVIOUS
;
734 if (button
&& !IS_SYSEVENT(button
) )
737 return GO_TO_ROOT
; /* unreachable - just to reduce compiler warnings */
740 /* needs checking if needed end*/
744 static void wps_state_init(void)
746 wps_state
.ff_rewind
= false;
747 wps_state
.paused
= false;
748 wps_state
.id3
= NULL
;
749 wps_state
.nid3
= NULL
;
754 #ifdef HAVE_LCD_BITMAP
755 static void statusbar_toggle_handler(void *data
)
759 gwps_fix_statusbars();
763 struct viewport
*vp
= &gui_wps
[i
].data
->viewports
[0].vp
;
764 bool draw
= wpsbars
& (VP_SB_ONSCREEN(i
) | VP_SB_IGNORE_SETTING(i
));
768 vp
->height
= screens
[i
].lcdheight
;
772 vp
->y
= STATUSBAR_HEIGHT
;
773 vp
->height
= screens
[i
].lcdheight
- STATUSBAR_HEIGHT
;
779 void gui_sync_wps_init(void)
784 wps_data_init(&wps_datas
[i
]);
786 wps_datas
[i
].wps_uses_albumart
= 0;
788 #ifdef HAVE_REMOTE_LCD
789 wps_datas
[i
].remote_wps
= (i
!= 0);
791 gui_wps
[i
].data
= &wps_datas
[i
];
792 gui_wps
[i
].display
= &screens
[i
];
793 /* Currently no seperate wps_state needed/possible
794 so use the only aviable ( "global" ) one */
795 gui_wps
[i
].state
= &wps_state
;
797 #ifdef HAVE_LCD_BITMAP
798 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false, statusbar_toggle_handler
);
801 unload_wps_backdrop();
803 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
804 unload_remote_wps_backdrop();
809 /* Returns true if at least one of the gui_wps screens has an album art
810 tag in its wps structure */
811 bool gui_sync_wps_uses_albumart(void)
815 struct gui_wps
*gwps
= &gui_wps
[i
];
816 if (gwps
->data
&& (gwps
->data
->wps_uses_albumart
!= WPS_ALBUMART_NONE
))