1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Jerome Kuptz
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
28 #include "backlight.h"
31 #include "filetypes.h"
36 #include "gwps-common.h"
43 #ifdef HAVE_LCD_BITMAP
45 #include "peakmeter.h"
57 #include "ata_idle_notify.h"
58 #include "root_menu.h"
60 #include "quickscreen.h"
62 /* currently only on wps_state is needed */
63 struct wps_state wps_state
;
64 struct gui_wps gui_wps
[NB_SCREENS
];
65 static struct wps_data wps_datas
[NB_SCREENS
];
67 /* change the path to the current played track */
68 static void wps_state_update_ctp(const char *path
);
69 /* initial setup of wps_data */
70 static void wps_state_init(void);
71 /* initial setup of a wps */
72 static void gui_wps_init(struct gui_wps
*gui_wps
);
73 /* connects a wps with a format-description of the displayed content */
74 static void gui_wps_set_data(struct gui_wps
*gui_wps
, struct wps_data
*data
);
75 /* connects a wps with a screen */
76 static void gui_wps_set_disp(struct gui_wps
*gui_wps
, struct screen
*display
);
77 /* connects a wps with a statusbar*/
78 static void gui_wps_set_statusbar(struct gui_wps
*gui_wps
, struct gui_statusbar
*statusbar
);
80 #ifdef HAVE_LCD_BITMAP
81 static void gui_wps_set_margin(struct gui_wps
*gwps
)
84 struct wps_data
*data
= gwps
->data
;
85 if(data
->wps_sb_tag
&& data
->show_sb_on_wps
)
86 offset
= STATUSBAR_HEIGHT
;
87 else if ( global_settings
.statusbar
&& !data
->wps_sb_tag
)
88 offset
= STATUSBAR_HEIGHT
;
89 gwps
->display
->setmargins(0, offset
);
93 long gui_wps_show(void)
97 long restoretimer
= 0; /* timer to delay screen redraw temporarily */
99 bool bookmark
= false;
100 bool update_track
= false;
102 long last_left
= 0, last_right
= 0;
106 #ifdef HAVE_LCD_CHARCELLS
107 status_set_audio(true);
108 status_set_param(false);
112 gui_wps_set_margin(&gui_wps
[i
]);
116 #endif /* LCD_DEPTH > 1 */
119 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
120 show_remote_wps_backdrop();
123 #ifdef AB_REPEAT_ENABLE
128 if(audio_status() & AUDIO_STATUS_PLAY
)
130 wps_state
.id3
= audio_current_track();
131 wps_state
.nid3
= audio_next_track();
133 if (gui_wps_display())
136 gui_wps_refresh(&gui_wps
[i
], 0, WPS_REFRESH_ALL
);
137 wps_state_update_ctp(wps_state
.id3
->path
);
144 bool audio_paused
= (audio_status() & AUDIO_STATUS_PAUSE
)?true:false;
146 /* did someone else (i.e power thread) change audio pause mode? */
147 if (wps_state
.paused
!= audio_paused
) {
148 wps_state
.paused
= audio_paused
;
150 /* if another thread paused audio, we are probably in car mode,
151 about to shut down. lets save the settings. */
152 if (wps_state
.paused
) {
154 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
155 call_ata_idle_notifys(true);
160 #ifdef HAVE_LCD_BITMAP
161 /* when the peak meter is enabled we want to have a
162 few extra updates to make it look smooth. On the
163 other hand we don't want to waste energy if it
168 if(gui_wps
[i
].data
->peak_meter_enabled
)
173 long next_refresh
= current_tick
;
174 long next_big_refresh
= current_tick
+ HZ
/ 5;
175 button
= BUTTON_NONE
;
176 while (TIME_BEFORE(current_tick
, next_big_refresh
)) {
177 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,TIMEOUT_NOBLOCK
);
178 if (button
!= ACTION_NONE
) {
182 sleep(0); /* Sleep until end of current tick. */
184 if (TIME_AFTER(current_tick
, next_refresh
)) {
187 if(gui_wps
[i
].data
->peak_meter_enabled
)
188 gui_wps_refresh(&gui_wps
[i
], 0,
189 WPS_REFRESH_PEAK_METER
);
190 next_refresh
+= HZ
/ PEAK_METER_FPS
;
197 /* The peak meter is disabled
198 -> no additional screen updates needed */
200 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,HZ
/5);
203 button
= get_action(CONTEXT_WPS
|ALLOW_SOFTLOCK
,HZ
/5);
206 /* Exit if audio has stopped playing. This can happen if using the
207 sleep timer with the charger plugged or if starting a recording
211 #ifdef ACTION_WPSAB_SINGLE
212 if (!global_settings
.party_mode
&& ab_repeat_mode_enabled())
214 static int wps_ab_state
= 0;
215 if (button
== ACTION_WPSAB_SINGLE
)
217 switch (wps_ab_state
)
219 case 0: /* set the A spot */
220 button
= ACTION_WPS_ABSETA_PREVDIR
;
222 case 1: /* set the B spot */
223 button
= ACTION_WPS_ABSETB_NEXTDIR
;
226 button
= ACTION_WPS_ABRESET
;
229 wps_ab_state
= (wps_ab_state
+1) % 3;
235 case ACTION_WPS_CONTEXT
:
237 show_main_backdrop();
239 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
240 show_remote_main_backdrop();
242 /* if music is stopped in the context menu we want to exit the wps */
243 if (onplay(wps_state
.id3
->path
,
244 FILE_ATTR_AUDIO
, CONTEXT_WPS
) == ONPLAY_MAINMENU
248 /* track might have changed */
254 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
255 show_remote_wps_backdrop();
257 #ifdef HAVE_LCD_BITMAP
260 gui_wps_set_margin(&gui_wps
[i
]);
266 case ACTION_WPS_BROWSE
:
267 #ifdef HAVE_LCD_CHARCELLS
268 status_set_record(false);
269 status_set_audio(false);
272 gui_wps
[i
].display
->stop_scroll();
273 return GO_TO_PREVIOUS_BROWSER
;
277 case ACTION_WPS_PLAY
:
278 if (global_settings
.party_mode
)
280 if ( wps_state
.paused
)
282 wps_state
.paused
= false;
283 if ( global_settings
.fade_on_stop
)
290 wps_state
.paused
= true;
291 if ( global_settings
.fade_on_stop
)
296 #if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
297 call_ata_idle_notifys(true); /* make sure resume info is saved */
303 case ACTION_WPS_VOLUP
:
305 global_settings
.volume
++;
310 if(update_onvol_change(&gui_wps
[i
]))
315 restoretimer
= current_tick
+ HZ
;
321 case ACTION_WPS_VOLDOWN
:
323 global_settings
.volume
--;
328 if(update_onvol_change(&gui_wps
[i
]))
333 restoretimer
= current_tick
+ HZ
;
338 OR next dir if this is straight after ACTION_WPS_SKIPNEXT */
339 case ACTION_WPS_SEEKFWD
:
340 if (global_settings
.party_mode
)
342 if (current_tick
-last_right
< HZ
)
344 if (cuesheet_is_enabled() && wps_state
.id3
->cuesheet_type
)
353 else ffwd_rew(ACTION_WPS_SEEKFWD
);
357 OR prev dir if this is straight after ACTION_WPS_SKIPPREV */
358 case ACTION_WPS_SEEKBACK
:
359 if (global_settings
.party_mode
)
361 if (current_tick
-last_left
< HZ
)
363 if (cuesheet_is_enabled() && wps_state
.id3
->cuesheet_type
)
365 if (!wps_state
.paused
)
366 #if (CONFIG_CODEC == SWCODEC)
367 audio_pre_ff_rewind();
378 else ffwd_rew(ACTION_WPS_SEEKBACK
);
383 case ACTION_WPS_SKIPPREV
:
384 if (global_settings
.party_mode
)
386 last_left
= current_tick
;
389 #ifdef AB_REPEAT_ENABLE
390 /* if we're in A/B repeat mode and the current position
391 is past the A marker, jump back to the A marker... */
392 if ( ab_repeat_mode_enabled() )
394 if ( ab_after_A_marker(wps_state
.id3
->elapsed
) )
396 ab_jump_to_A_marker();
398 #if (AB_REPEAT_ENABLE == 2)
404 /* ...otherwise, do it normally */
407 if (!wps_state
.id3
|| (wps_state
.id3
->elapsed
< 3*1000)) {
412 if (cuesheet_is_enabled() && wps_state
.id3
->cuesheet_type
)
414 curr_cuesheet_skip(-1, wps_state
.id3
->elapsed
);
418 if (!wps_state
.paused
)
419 #if (CONFIG_CODEC == SWCODEC)
420 audio_pre_ff_rewind();
427 #if (CONFIG_CODEC != SWCODEC)
428 if (!wps_state
.paused
)
435 case ACTION_WPS_SKIPNEXT
:
436 if (global_settings
.party_mode
)
438 last_right
= current_tick
;
441 #ifdef AB_REPEAT_ENABLE
442 /* if we're in A/B repeat mode and the current position is
443 before the A marker, jump to the A marker... */
444 if ( ab_repeat_mode_enabled() )
446 if ( ab_before_A_marker(wps_state
.id3
->elapsed
) )
448 ab_jump_to_A_marker();
450 #if (AB_REPEAT_ENABLE == 2)
456 /* ...otherwise, do it normally */
459 /* take care of if we're playing a cuesheet */
460 if (cuesheet_is_enabled() && wps_state
.id3
->cuesheet_type
)
462 if (curr_cuesheet_skip(1, wps_state
.id3
->elapsed
))
464 /* if the result was false, then we really want
465 to skip to the next track */
472 /* next / prev directories */
473 /* and set A-B markers if in a-b mode */
474 case ACTION_WPS_ABSETB_NEXTDIR
:
475 if (global_settings
.party_mode
)
477 #if defined(AB_REPEAT_ENABLE)
478 if (ab_repeat_mode_enabled())
480 ab_set_B_marker(wps_state
.id3
->elapsed
);
481 ab_jump_to_A_marker();
490 case ACTION_WPS_ABSETA_PREVDIR
:
491 if (global_settings
.party_mode
)
493 #if defined(AB_REPEAT_ENABLE)
494 if (ab_repeat_mode_enabled())
495 ab_set_A_marker(wps_state
.id3
->elapsed
);
502 /* menu key functions */
503 case ACTION_WPS_MENU
:
505 gui_wps
[i
].display
->stop_scroll();
510 #ifdef HAVE_QUICKSCREEN
511 case ACTION_WPS_QUICKSCREEN
:
513 show_main_backdrop();
515 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
516 show_remote_main_backdrop();
518 if (quick_screen_quick(button
))
519 return SYS_USB_CONNECTED
;
523 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
524 show_remote_wps_backdrop();
526 #ifdef HAVE_LCD_BITMAP
529 gui_wps_set_margin(&gui_wps
[i
]);
534 #endif /* HAVE_QUICKSCREEN */
536 /* screen settings */
540 show_main_backdrop();
542 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
543 show_remote_main_backdrop();
545 if (quick_screen_f3(BUTTON_F3
))
546 return SYS_USB_CONNECTED
;
547 #ifdef HAVE_LCD_BITMAP
550 gui_wps_set_margin(&gui_wps
[i
]);
555 #endif /* BUTTON_F3 */
558 #ifdef HAVE_PITCHSCREEN
559 case ACTION_WPS_PITCHSCREEN
:
561 show_main_backdrop();
563 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
564 show_remote_main_backdrop();
566 if (1 == pitch_screen())
567 return SYS_USB_CONNECTED
;
571 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
572 show_remote_wps_backdrop();
576 #endif /* HAVE_PITCHSCREEN */
578 #ifdef AB_REPEAT_ENABLE
579 /* reset A&B markers */
580 case ACTION_WPS_ABRESET
:
581 if (ab_repeat_mode_enabled())
587 #endif /* AB_REPEAT_ENABLE */
589 /* stop and exit wps */
590 case ACTION_WPS_STOP
:
591 if (global_settings
.party_mode
)
597 case ACTION_WPS_ID3SCREEN
:
599 show_main_backdrop();
601 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
602 show_remote_main_backdrop();
608 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
609 show_remote_wps_backdrop();
611 #ifdef HAVE_LCD_BITMAP
614 gui_wps_set_margin(&gui_wps
[i
]);
620 case ACTION_REDRAW
: /* yes are locked, just redraw */
623 case ACTION_NONE
: /* Timeout */
625 ffwd_rew(button
); /* hopefully fix the ffw/rwd bug */
627 #ifdef HAVE_RECORDING
634 show_main_backdrop();
636 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
637 show_remote_main_backdrop();
639 default_event_handler(SYS_POWEROFF
);
643 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
653 if(update(&gui_wps
[i
]))
656 update_track
= false;
660 ((restoretimer
== 0) ||
661 (restoretimer
< current_tick
)))
665 if (gui_wps_display()) {
668 else if (wps_state
.id3
){
670 gui_wps_refresh(&gui_wps
[i
], 0, WPS_REFRESH_NON_STATIC
);
675 #ifdef HAVE_LCD_CHARCELLS
676 status_set_record(false);
677 status_set_audio(false);
679 if (global_settings
.fade_on_stop
)
683 gui_wps
[i
].display
->stop_scroll();
685 bookmark_autobookmark();
687 #ifdef AB_REPEAT_ENABLE
690 #ifdef HAVE_RECORDING
691 if (button
== ACTION_WPS_REC
)
692 return GO_TO_RECSCREEN
;
694 if (global_settings
.browse_current
)
695 return GO_TO_PREVIOUS_BROWSER
;
696 return GO_TO_PREVIOUS
;
702 return GO_TO_ROOT
; /* unreachable - just to reduce compiler warnings */
705 /* needs checking if needed end*/
709 static void wps_state_init(void)
711 wps_state
.ff_rewind
= false;
712 wps_state
.paused
= false;
713 wps_state
.id3
= NULL
;
714 wps_state
.nid3
= NULL
;
715 wps_state
.current_track_path
[0] = '\0';
719 /* these are obviously not used? */
721 void wps_state_update_ff_rew(bool ff_rew
)
723 wps_state
.ff_rewind
= ff_rew
;
726 void wps_state_update_paused(bool paused
)
728 wps_state
.paused
= paused
;
730 void wps_state_update_id3_nid3(struct mp3entry
*id3
, struct mp3entry
*nid3
)
733 wps_state
.nid3
= nid3
;
737 static void wps_state_update_ctp(const char *path
)
739 strncpy(wps_state
.current_track_path
, path
,
740 sizeof(wps_state
.current_track_path
));
741 wps_state
.current_track_path
[sizeof(wps_state
.current_track_path
)-1] = '\0';
745 /* initial setup of a wps */
746 static void gui_wps_init(struct gui_wps
*gui_wps
)
748 gui_wps
->data
= NULL
;
749 gui_wps
->display
= NULL
;
750 gui_wps
->statusbar
= NULL
;
751 /* Currently no seperate wps_state needed/possible
752 so use the only aviable ( "global" ) one */
753 gui_wps
->state
= &wps_state
;
756 /* connects a wps with a format-description of the displayed content */
757 static void gui_wps_set_data(struct gui_wps
*gui_wps
, struct wps_data
*data
)
759 gui_wps
->data
= data
;
762 /* connects a wps with a screen */
763 static void gui_wps_set_disp(struct gui_wps
*gui_wps
, struct screen
*display
)
765 gui_wps
->display
= display
;
768 static void gui_wps_set_statusbar(struct gui_wps
*gui_wps
, struct gui_statusbar
*statusbar
)
770 gui_wps
->statusbar
= statusbar
;
774 void gui_sync_wps_screen_init(void)
778 gui_wps_set_disp(&gui_wps
[i
], &screens
[i
]);
781 void gui_sync_wps_init(void)
786 wps_data_init(&wps_datas
[i
]);
787 #ifdef HAVE_REMOTE_LCD
788 wps_datas
[i
].remote_wps
= (i
!= 0);
790 gui_wps_init(&gui_wps
[i
]);
791 gui_wps_set_data(&gui_wps
[i
], &wps_datas
[i
]);
792 gui_wps_set_statusbar(&gui_wps
[i
], &statusbars
.statusbars
[i
]);
795 unload_wps_backdrop();
797 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
798 unload_remote_wps_backdrop();
803 /* Returns true if at least one of the gui_wps screens has an album art
804 tag in its wps structure */
805 bool gui_sync_wps_uses_albumart(void)
809 struct gui_wps
*gwps
= &gui_wps
[i
];
810 if (gwps
->data
&& (gwps
->data
->wps_uses_albumart
!= WPS_ALBUMART_NONE
))