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))
71 #define DEFAULT_SKIP_TRESH 3000ul
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);
82 static void change_dir(int direction
)
84 if (global_settings
.prevent_skip
)
89 else if (direction
> 0)
93 static void prev_track(unsigned long skip_thresh
)
95 if (wps_state
.id3
->elapsed
< skip_thresh
)
102 if (cuesheet_is_enabled() && wps_state
.id3
->cuesheet_type
)
104 curr_cuesheet_skip(-1, wps_state
.id3
->elapsed
);
108 if (!wps_state
.paused
)
109 #if (CONFIG_CODEC == SWCODEC)
110 audio_pre_ff_rewind();
117 #if (CONFIG_CODEC != SWCODEC)
118 if (!wps_state
.paused
)
124 static void next_track(void)
126 /* take care of if we're playing a cuesheet */
127 if (cuesheet_is_enabled() && wps_state
.id3
->cuesheet_type
)
129 if (curr_cuesheet_skip(1, wps_state
.id3
->elapsed
))
131 /* if the result was false, then we really want
132 to skip to the next track */
140 static void play_hop(int direction
)
142 unsigned long step
= ((unsigned long)global_settings
.skip_length
)*1000;
143 unsigned long elapsed
= wps_state
.id3
->elapsed
;
144 unsigned long remaining
= wps_state
.id3
->length
- elapsed
;
146 if (!global_settings
.prevent_skip
&&
148 (direction
> 0 && step
>= remaining
) ||
149 (direction
< 0 && elapsed
< DEFAULT_SKIP_TRESH
)))
150 { /* Do normal track skipping */
153 else if (direction
< 0)
154 prev_track(DEFAULT_SKIP_TRESH
);
158 if (direction
== 1 && step
>= remaining
)
160 #if CONFIG_CODEC == SWCODEC
161 if(global_settings
.beep
)
162 pcmbuf_beep(1000, 150, 1500*global_settings
.beep
);
166 else if ((direction
== -1 && elapsed
< step
))
172 elapsed
+= step
* direction
;
174 if((audio_status() & AUDIO_STATUS_PLAY
) && !wps_state
.paused
)
176 #if (CONFIG_CODEC == SWCODEC)
177 audio_pre_ff_rewind();
182 audio_ff_rewind(wps_state
.id3
->elapsed
= elapsed
);
183 #if (CONFIG_CODEC != SWCODEC)
184 if (!wps_state
.paused
)
189 static void gwps_fix_statusbars(void)
191 #ifdef HAVE_LCD_BITMAP
193 wpsbars
= VP_SB_HIDE_ALL
;
197 if (gui_wps
[i
].data
->wps_sb_tag
)
198 draw
= gui_wps
[i
].data
->show_sb_on_wps
;
199 else if (global_settings
.statusbar
)
200 wpsbars
|= VP_SB_ONSCREEN(i
);
202 wpsbars
|= (VP_SB_ONSCREEN(i
) | VP_SB_IGNORE_SETTING(i
));
205 wpsbars
= VP_SB_ALLSCREENS
;
210 static void gwps_leave_wps(void)
212 int i
, oldbars
= VP_SB_HIDE_ALL
;
215 gui_wps
[i
].display
->stop_scroll();
216 if (global_settings
.statusbar
)
217 oldbars
= VP_SB_ALLSCREENS
;
220 show_main_backdrop();
222 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
223 show_remote_main_backdrop();
225 viewportmanager_set_statusbar(oldbars
);
228 void gwps_draw_statusbars(void)
230 viewportmanager_set_statusbar(wpsbars
);
233 /* The WPS can be left in two ways:
234 * a) call a function, which draws over the wps. In this case, the wps
235 * will be still active (i.e. the below function didn't return)
236 * b) return with a value evaluated by root_menu.c, in this case the wps
237 * is really left, and root_menu will handle the next screen
239 * In either way, call gwps_leave_wps(), in order to restore the correct
240 * "main screen" backdrops and statusbars
242 long gui_wps_show(void)
245 bool restore
= false;
246 long restoretimer
= RESTORE_WPS_INSTANTLY
; /* timer to delay screen redraw temporarily */
248 bool bookmark
= false;
249 bool update_track
= false;
251 long last_left
= 0, last_right
= 0;
254 #ifdef HAVE_LCD_CHARCELLS
255 status_set_audio(true);
256 status_set_param(false);
259 gwps_fix_statusbars();
261 #ifdef AB_REPEAT_ENABLE
265 if(audio_status() & AUDIO_STATUS_PLAY
)
267 wps_state
.id3
= audio_current_track();
268 wps_state
.nid3
= audio_next_track();
269 restore
= true; /* force initial full redraw */
274 bool audio_paused
= (audio_status() & AUDIO_STATUS_PAUSE
)?true:false;
276 /* did someone else (i.e power thread) change audio pause mode? */
277 if (wps_state
.paused
!= audio_paused
) {
278 wps_state
.paused
= audio_paused
;
280 /* if another thread paused audio, we are probably in car mode,
281 about to shut down. lets save the settings. */
282 if (wps_state
.paused
) {
284 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
285 call_storage_idle_notifys(true);
290 #ifdef HAVE_LCD_BITMAP
291 /* when the peak meter is enabled we want to have a
292 few extra updates to make it look smooth. On the
293 other hand we don't want to waste energy if it
298 if(gui_wps
[i
].data
->peak_meter_enabled
)
303 long next_refresh
= current_tick
;
304 long next_big_refresh
= current_tick
+ HZ
/ 5;
305 button
= BUTTON_NONE
;
306 while (TIME_BEFORE(current_tick
, next_big_refresh
)) {
307 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_NOBLOCK
);
308 if (button
!= ACTION_NONE
) {
312 sleep(0); /* Sleep until end of current tick. */
314 if (TIME_AFTER(current_tick
, next_refresh
)) {
317 if(gui_wps
[i
].data
->peak_meter_enabled
)
318 gui_wps_redraw(&gui_wps
[i
], 0,
319 WPS_REFRESH_PEAK_METER
);
320 next_refresh
+= HZ
/ PEAK_METER_FPS
;
327 /* The peak meter is disabled
328 -> no additional screen updates needed */
332 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,HZ
/5);
335 /* Exit if audio has stopped playing. This happens e.g. at end of
336 playlist or if using the sleep timer. */
337 if (!(audio_status() & AUDIO_STATUS_PLAY
))
339 /* The iPods/X5/M5 use a single button for the A-B mode markers,
340 defined as ACTION_WPSAB_SINGLE in their config files. */
341 #ifdef ACTION_WPSAB_SINGLE
342 if (!global_settings
.party_mode
&& ab_repeat_mode_enabled())
344 static int wps_ab_state
= 0;
345 if (button
== ACTION_WPSAB_SINGLE
)
347 switch (wps_ab_state
)
349 case 0: /* set the A spot */
350 button
= ACTION_WPS_ABSETA_PREVDIR
;
352 case 1: /* set the B spot */
353 button
= ACTION_WPS_ABSETB_NEXTDIR
;
356 button
= ACTION_WPS_ABRESET
;
359 wps_ab_state
= (wps_ab_state
+1) % 3;
365 case ACTION_WPS_CONTEXT
:
368 /* if music is stopped in the context menu we want to exit the wps */
369 if (onplay(wps_state
.id3
->path
,
370 FILE_ATTR_AUDIO
, CONTEXT_WPS
) == ONPLAY_MAINMENU
373 /* track might have changed */
379 case ACTION_WPS_BROWSE
:
380 #ifdef HAVE_LCD_CHARCELLS
381 status_set_record(false);
382 status_set_audio(false);
385 return GO_TO_PREVIOUS_BROWSER
;
389 case ACTION_WPS_PLAY
:
390 if (global_settings
.party_mode
)
392 if ( wps_state
.paused
)
394 wps_state
.paused
= false;
395 if ( global_settings
.fade_on_stop
)
402 wps_state
.paused
= true;
403 if ( global_settings
.fade_on_stop
)
408 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
409 call_storage_idle_notifys(true); /* make sure resume info is saved */
414 case ACTION_WPS_VOLUP
:
417 gui_wps
[i
].data
->button_time_volume
= current_tick
;
418 global_settings
.volume
++;
423 if(update_onvol_change(&gui_wps
[i
]))
428 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
432 case ACTION_WPS_VOLDOWN
:
435 gui_wps
[i
].data
->button_time_volume
= current_tick
;
436 global_settings
.volume
--;
441 if(update_onvol_change(&gui_wps
[i
]))
446 restoretimer
= RESTORE_WPS_NEXT_SECOND
;
451 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
452 case ACTION_WPS_SEEKFWD
:
453 if (global_settings
.party_mode
)
455 if (current_tick
-last_right
< HZ
)
457 if (cuesheet_is_enabled() && wps_state
.id3
->cuesheet_type
)
467 ffwd_rew(ACTION_WPS_SEEKFWD
);
468 last_right
= last_left
= 0;
471 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,*/
472 case ACTION_WPS_SEEKBACK
:
473 if (global_settings
.party_mode
)
475 if (current_tick
-last_left
< HZ
)
477 if (cuesheet_is_enabled() && wps_state
.id3
->cuesheet_type
)
479 if (!wps_state
.paused
)
480 #if (CONFIG_CODEC == SWCODEC)
481 audio_pre_ff_rewind();
493 ffwd_rew(ACTION_WPS_SEEKBACK
);
494 last_left
= last_right
= 0;
498 case ACTION_WPS_SKIPPREV
:
499 if (global_settings
.party_mode
)
501 last_left
= current_tick
;
503 #ifdef AB_REPEAT_ENABLE
504 /* if we're in A/B repeat mode and the current position
505 is past the A marker, jump back to the A marker... */
506 if ( ab_repeat_mode_enabled() )
508 if ( ab_after_A_marker(wps_state
.id3
->elapsed
) )
510 ab_jump_to_A_marker();
512 #if (AB_REPEAT_ENABLE == 2)
519 /* ...otherwise, do it normally */
525 OR if skip length set, hop by predetermined amount. */
526 case ACTION_WPS_SKIPNEXT
:
527 if (global_settings
.party_mode
)
529 last_right
= current_tick
;
531 #ifdef AB_REPEAT_ENABLE
532 /* if we're in A/B repeat mode and the current position is
533 before the A marker, jump to the A marker... */
534 if ( ab_repeat_mode_enabled() )
536 if ( ab_before_A_marker(wps_state
.id3
->elapsed
) )
538 ab_jump_to_A_marker();
540 #if (AB_REPEAT_ENABLE == 2)
547 /* ...otherwise, do it normally */
551 /* next / prev directories */
552 /* and set A-B markers if in a-b mode */
553 case ACTION_WPS_ABSETB_NEXTDIR
:
554 if (global_settings
.party_mode
)
556 #if defined(AB_REPEAT_ENABLE)
557 if (ab_repeat_mode_enabled())
559 ab_set_B_marker(wps_state
.id3
->elapsed
);
560 ab_jump_to_A_marker();
569 case ACTION_WPS_ABSETA_PREVDIR
:
570 if (global_settings
.party_mode
)
572 #if defined(AB_REPEAT_ENABLE)
573 if (ab_repeat_mode_enabled())
574 ab_set_A_marker(wps_state
.id3
->elapsed
);
581 /* menu key functions */
582 case ACTION_WPS_MENU
:
588 #ifdef HAVE_QUICKSCREEN
589 case ACTION_WPS_QUICKSCREEN
:
592 if (quick_screen_quick(button
))
593 return SYS_USB_CONNECTED
;
597 #endif /* HAVE_QUICKSCREEN */
599 /* screen settings */
604 if (quick_screen_f3(BUTTON_F3
))
605 return SYS_USB_CONNECTED
;
609 #endif /* BUTTON_F3 */
612 #ifdef HAVE_PITCHSCREEN
613 case ACTION_WPS_PITCHSCREEN
:
616 if (1 == gui_syncpitchscreen_run())
617 return SYS_USB_CONNECTED
;
621 #endif /* HAVE_PITCHSCREEN */
623 #ifdef AB_REPEAT_ENABLE
624 /* reset A&B markers */
625 case ACTION_WPS_ABRESET
:
626 if (ab_repeat_mode_enabled())
632 #endif /* AB_REPEAT_ENABLE */
634 /* stop and exit wps */
635 case ACTION_WPS_STOP
:
636 if (global_settings
.party_mode
)
642 case ACTION_WPS_ID3SCREEN
:
650 case ACTION_REDRAW
: /* yes are locked, just redraw */
653 case ACTION_NONE
: /* Timeout */
655 ffwd_rew(button
); /* hopefully fix the ffw/rwd bug */
657 #ifdef HAVE_RECORDING
664 default_event_handler(SYS_POWEROFF
);
668 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
678 gui_wps_update(&gui_wps
[i
]);
680 update_track
= false;
683 if (restore
&& wps_state
.id3
&&
684 ((restoretimer
== RESTORE_WPS_INSTANTLY
) ||
685 TIME_AFTER(current_tick
, restoretimer
)))
688 restoretimer
= RESTORE_WPS_INSTANTLY
;
691 screens
[i
].stop_scroll();
692 gui_wps_display(&gui_wps
[i
]);
697 #ifdef HAVE_LCD_CHARCELLS
698 status_set_record(false);
699 status_set_audio(false);
701 if (global_settings
.fade_on_stop
)
705 bookmark_autobookmark();
707 #ifdef AB_REPEAT_ENABLE
711 #ifdef HAVE_RECORDING
712 if (button
== ACTION_WPS_REC
)
713 return GO_TO_RECSCREEN
;
715 if (global_settings
.browse_current
)
716 return GO_TO_PREVIOUS_BROWSER
;
717 return GO_TO_PREVIOUS
;
720 if (button
&& !IS_SYSEVENT(button
) )
723 return GO_TO_ROOT
; /* unreachable - just to reduce compiler warnings */
726 /* needs checking if needed end*/
730 static void wps_state_init(void)
732 wps_state
.ff_rewind
= false;
733 wps_state
.paused
= false;
734 wps_state
.id3
= NULL
;
735 wps_state
.nid3
= NULL
;
740 #ifdef HAVE_LCD_BITMAP
741 static void statusbar_toggle_handler(void *data
)
745 gwps_fix_statusbars();
749 struct viewport
*vp
= &gui_wps
[i
].data
->viewports
[0].vp
;
750 bool draw
= wpsbars
& (VP_SB_ONSCREEN(i
) | VP_SB_IGNORE_SETTING(i
));
754 vp
->height
= screens
[i
].lcdheight
;
758 vp
->y
= STATUSBAR_HEIGHT
;
759 vp
->height
= screens
[i
].lcdheight
- STATUSBAR_HEIGHT
;
765 void gui_sync_wps_init(void)
770 wps_data_init(&wps_datas
[i
]);
772 wps_datas
[i
].wps_uses_albumart
= 0;
774 #ifdef HAVE_REMOTE_LCD
775 wps_datas
[i
].remote_wps
= (i
!= 0);
777 gui_wps
[i
].data
= &wps_datas
[i
];
778 gui_wps
[i
].display
= &screens
[i
];
779 /* Currently no seperate wps_state needed/possible
780 so use the only aviable ( "global" ) one */
781 gui_wps
[i
].state
= &wps_state
;
783 #ifdef HAVE_LCD_BITMAP
784 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false, statusbar_toggle_handler
);
787 unload_wps_backdrop();
789 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
790 unload_remote_wps_backdrop();
795 /* Returns true if at least one of the gui_wps screens has an album art
796 tag in its wps structure */
797 bool gui_sync_wps_uses_albumart(void)
801 struct gui_wps
*gwps
= &gui_wps
[i
];
802 if (gwps
->data
&& (gwps
->data
->wps_uses_albumart
!= WPS_ALBUMART_NONE
))