only build the clipcounter for targets with recording
[maemo-rb.git] / apps / screens.c
blobee804b2f9b40b06de206e0a8914258e5aef723a7
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Björn Stenberg
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 ****************************************************************************/
20 #include <stdbool.h>
21 #include <string.h>
22 #include <stdio.h>
23 #include "backlight.h"
24 #include "action.h"
25 #include "lcd.h"
26 #ifdef HAVE_REMOTE_LCD
27 #include "lcd-remote.h"
28 #endif
29 #include "lang.h"
30 #include "icons.h"
31 #include "font.h"
32 #include "audio.h"
33 #include "mp3_playback.h"
34 #include "usb.h"
35 #include "settings.h"
36 #include "status.h"
37 #include "playlist.h"
38 #include "sprintf.h"
39 #include "kernel.h"
40 #include "power.h"
41 #include "system.h"
42 #include "powermgmt.h"
43 #include "adc.h"
44 #include "action.h"
45 #include "talk.h"
46 #include "misc.h"
47 #include "id3.h"
48 #include "screens.h"
49 #include "debug.h"
50 #include "led.h"
51 #include "sound.h"
52 #include "splash.h"
53 #include "statusbar.h"
54 #include "screen_access.h"
55 #include "quickscreen.h"
56 #include "pcmbuf.h"
57 #include "list.h"
58 #include "yesno.h"
60 #ifdef HAVE_LCD_BITMAP
61 #include <bitmaps/usblogo.h>
62 #endif
64 #ifdef HAVE_REMOTE_LCD
65 #include <bitmaps/remote_usblogo.h>
66 #endif
68 #ifdef HAVE_MMC
69 #include "ata_mmc.h"
70 #endif
71 #if CONFIG_CODEC == SWCODEC
72 #include "dsp.h"
73 #endif
75 #if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
76 #include "backdrop.h"
77 #endif
79 #ifdef HAVE_LCD_BITMAP
80 #define SCROLLBAR_WIDTH 6
81 #endif
83 void usb_screen(void)
85 #ifdef USB_NONE
86 /* nothing here! */
87 #else
88 int i;
89 bool statusbar = global_settings.statusbar; /* force the statusbar */
90 global_settings.statusbar = true;
91 #if LCD_DEPTH > 1
92 show_main_backdrop();
93 #endif
94 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
95 show_remote_main_backdrop();
96 #endif
97 FOR_NB_SCREENS(i)
99 screens[i].backlight_on();
100 screens[i].clear_display();
101 #if NB_SCREENS > 1
102 if (i == SCREEN_REMOTE)
104 screens[i].bitmap(remote_usblogo,
105 (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo),
106 (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2,
107 BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo);
109 else
111 #endif
112 #ifdef HAVE_LCD_BITMAP
113 screens[i].transparent_bitmap(usblogo,
114 (LCD_WIDTH-BMPWIDTH_usblogo),
115 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
116 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
117 #else
118 screens[i].double_height(false);
119 screens[i].puts_scroll(0, 0, "[USB Mode]");
120 status_set_param(false);
121 status_set_audio(false);
122 status_set_usb(true);
123 #endif /* HAVE_LCD_BITMAP */
124 #if NB_SCREENS > 1
126 #endif
127 screens[i].update();
130 gui_syncstatusbar_draw(&statusbars, true);
131 #ifdef SIMULATOR
132 while (button_get(true) & BUTTON_REL);
133 #else
134 usb_acknowledge(SYS_USB_CONNECTED_ACK);
135 while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) {
136 if(usb_inserted()) {
137 #ifdef HAVE_MMC /* USB-MMC bridge can report activity */
138 led(mmc_usb_active(HZ));
139 #endif /* HAVE_MMC */
140 gui_syncstatusbar_draw(&statusbars, false);
143 #endif /* SIMULATOR */
144 #ifdef HAVE_LCD_CHARCELLS
145 status_set_usb(false);
146 #endif /* HAVE_LCD_CHARCELLS */
147 FOR_NB_SCREENS(i)
148 screens[i].backlight_on();
149 global_settings.statusbar = statusbar;
150 #endif /* USB_NONE */
153 #ifdef HAVE_MMC
154 int mmc_remove_request(void)
156 struct event ev;
157 int i;
158 FOR_NB_SCREENS(i)
159 screens[i].clear_display();
160 gui_syncsplash(1, str(LANG_REMOVE_MMC));
161 if (talk_menus_enabled())
162 talk_id(LANG_REMOVE_MMC, false);
164 while (1)
166 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
167 switch (ev.id)
169 case SYS_HOTSWAP_EXTRACTED:
170 return SYS_HOTSWAP_EXTRACTED;
172 case SYS_USB_DISCONNECTED:
173 return SYS_USB_DISCONNECTED;
177 #endif
179 /* the charging screen is only used for archos targets */
180 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
182 #ifdef HAVE_LCD_BITMAP
183 static void charging_display_info(bool animate)
185 unsigned char charging_logo[36];
186 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
187 const int pox_y = 32;
188 static unsigned phase = 3;
189 unsigned i;
190 char buf[32];
191 (void)buf;
193 #ifdef NEED_ATA_POWER_BATT_MEASURE
194 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
195 #endif
197 int battv = battery_voltage();
198 snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 1000,
199 (battv % 1000) / 10, battery_level());
200 lcd_puts(0, 7, buf);
203 #if CONFIG_CHARGING == CHARGING_CONTROL
205 snprintf(buf, 32, "Charge mode:");
206 lcd_puts(0, 2, buf);
208 if (charge_state == CHARGING)
209 snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
210 else if (charge_state == TOPOFF)
211 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
212 else if (charge_state == TRICKLE)
213 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
214 else
215 snprintf(buf, 32, "not charging");
217 lcd_puts(0, 3, buf);
218 if (!charger_enabled)
219 animate = false;
220 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
223 /* middle part */
224 memset(charging_logo+3, 0x00, 32);
225 charging_logo[0] = 0x3C;
226 charging_logo[1] = 0x24;
227 charging_logo[2] = charging_logo[35] = 0xFF;
229 if (!animate)
230 { /* draw the outline */
231 /* middle part */
232 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, sizeof(charging_logo), 8);
233 lcd_set_drawmode(DRMODE_FG);
234 /* upper line */
235 charging_logo[0] = charging_logo[1] = 0x00;
236 memset(charging_logo+2, 0x80, 34);
237 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
238 /* lower line */
239 memset(charging_logo+2, 0x01, 34);
240 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16, sizeof(charging_logo), 8);
241 lcd_set_drawmode(DRMODE_SOLID);
243 else
244 { /* animate the middle part */
245 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
247 if ((i-phase) % 8 == 0)
248 { /* draw a "bubble" here */
249 unsigned bitpos;
250 bitpos = (phase + i/8) % 15; /* "bounce" effect */
251 if (bitpos > 7)
252 bitpos = 14 - bitpos;
253 charging_logo[i] = 0x01 << bitpos;
256 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, sizeof(charging_logo), 8);
257 phase++;
259 lcd_update();
261 #else /* not HAVE_LCD_BITMAP */
263 static unsigned long logo_chars[4];
264 static const unsigned char logo_pattern[] = {
265 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
266 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
267 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
268 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
271 static void logo_lock_patterns(bool on)
273 int i;
275 if (on)
277 for (i = 0; i < 4; i++)
278 logo_chars[i] = lcd_get_locked_pattern();
280 else
282 for (i = 0; i < 4; i++)
283 lcd_unlock_pattern(logo_chars[i]);
287 static void charging_display_info(bool animate)
289 int battv;
290 unsigned i, ypos;
291 static unsigned phase = 3;
292 char buf[32];
294 battv = battery_voltage();
295 snprintf(buf, sizeof(buf), " %d.%02dV", battv / 1000, (battv % 1000) / 10);
296 lcd_puts(4, 1, buf);
298 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
300 if (!animate) /* build the screen */
302 lcd_double_height(false);
303 lcd_puts(0, 0, "[Charging]");
304 for (i = 0; i < 4; i++)
305 lcd_putc(i, 1, logo_chars[i]);
307 else /* animate the logo */
309 for (i = 3; i < MIN(19, phase); i++)
311 if ((i - phase) % 5 == 0)
312 { /* draw a "bubble" here */
313 ypos = (phase + i/5) % 9; /* "bounce" effect */
314 if (ypos > 4)
315 ypos = 8 - ypos;
316 buf[5 - ypos + 8 * (i/5)] |= 0x10 >> (i%5);
319 phase++;
322 for (i = 0; i < 4; i++)
323 lcd_define_pattern(logo_chars[i], buf + 8 * i);
325 lcd_update();
327 #endif /* (not) HAVE_LCD_BITMAP */
329 /* blocks while charging, returns on event:
330 1 if charger cable was removed
331 2 if Off/Stop key was pressed
332 3 if On key was pressed
333 4 if USB was connected */
335 int charging_screen(void)
337 unsigned int button;
338 int rc = 0;
340 ide_power_enable(false); /* power down the disk, else would be spinning */
342 lcd_clear_display();
343 backlight_set_timeout(global_settings.backlight_timeout);
344 #ifdef HAVE_REMOTE_LCD
345 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
346 #endif
347 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
348 gui_syncstatusbar_draw(&statusbars, true);
350 #ifdef HAVE_LCD_CHARCELLS
351 logo_lock_patterns(true);
352 #endif
353 charging_display_info(false);
357 gui_syncstatusbar_draw(&statusbars, false);
358 charging_display_info(true);
359 button = get_action(CONTEXT_STD,HZ/3);
360 if (button == ACTION_STD_OK)
361 rc = 2;
362 else if (usb_detect())
363 rc = 3;
364 else if (!charger_inserted())
365 rc = 1;
366 } while (!rc);
368 #ifdef HAVE_LCD_CHARCELLS
369 logo_lock_patterns(false);
370 #endif
371 return rc;
373 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
375 #ifdef HAVE_PITCHSCREEN
377 #define PITCH_MAX 2000
378 #define PITCH_MIN 500
379 #define PITCH_SMALL_DELTA 1
380 #define PITCH_BIG_DELTA 10
381 #define PITCH_NUDGE_DELTA 20
383 #define PITCH_MODE_ABSOLUTE 1
384 #define PITCH_MODE_SEMITONE -PITCH_MODE_ABSOLUTE
386 static int pitch_mode = PITCH_MODE_ABSOLUTE; /* 1 - absolute, -1 - semitone */
388 /* returns:
389 0 if no key was pressed
390 1 if USB was connected */
392 static void pitch_screen_draw(struct screen *display, int pitch, int pitch_mode)
394 unsigned char* ptr;
395 unsigned char buf[32];
396 int w, h;
398 display->clear_display();
400 if (display->nb_lines < 4) /* very small screen, just show the pitch value */
402 w = snprintf((char *)buf, sizeof(buf), "%s: %d.%d%%",str(LANG_PITCH),
403 pitch / 10, pitch % 10 );
404 display->putsxy((display->width-(w*display->char_width))/2,
405 display->nb_lines/2,buf);
407 else /* bigger screen, show everything... */
410 /* UP: Pitch Up */
411 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
412 ptr = str(LANG_PITCH_UP);
413 } else {
414 ptr = str(LANG_PITCH_UP_SEMITONE);
416 display->getstringsize(ptr,&w,&h);
417 display->putsxy((display->width-w)/2, 0, ptr);
418 display->mono_bitmap(bitmap_icons_7x8[Icon_UpArrow],
419 display->width/2 - 3, h, 7, 8);
421 /* DOWN: Pitch Down */
422 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
423 ptr = str(LANG_PITCH_DOWN);
424 } else {
425 ptr = str(LANG_PITCH_DOWN_SEMITONE);
427 display->getstringsize(ptr,&w,&h);
428 display->putsxy((display->width-w)/2, display->height - h, ptr);
429 display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
430 display->width/2 - 3, display->height - h*2, 7, 8);
432 /* RIGHT: +2% */
433 ptr = "+2%";
434 display->getstringsize(ptr,&w,&h);
435 display->putsxy(display->width-w, (display->height-h)/2, ptr);
436 display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
437 display->width-w-8, (display->height-h)/2, 7, 8);
439 /* LEFT: -2% */
440 ptr = "-2%";
441 display->getstringsize(ptr,&w,&h);
442 display->putsxy(0, (display->height-h)/2, ptr);
443 display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
444 w+1, (display->height-h)/2, 7, 8);
446 /* "Pitch" */
447 snprintf((char *)buf, sizeof(buf), str(LANG_PITCH));
448 display->getstringsize(buf,&w,&h);
449 display->putsxy((display->width-w)/2, (display->height/2)-h, buf);
450 /* "XX.X%" */
451 snprintf((char *)buf, sizeof(buf), "%d.%d%%",
452 pitch / 10, pitch % 10 );
453 display->getstringsize(buf,&w,&h);
454 display->putsxy((display->width-w)/2, display->height/2, buf);
457 display->update();
460 static int pitch_increase(int pitch, int delta,
461 bool allow_cutoff, bool redraw_screens) {
462 int new_pitch;
463 int i;
465 if (delta < 0) {
466 if (pitch + delta >= PITCH_MIN) {
467 new_pitch = pitch + delta;
468 } else {
469 if (!allow_cutoff) {
470 return pitch;
472 new_pitch = PITCH_MIN;
474 } else if (delta > 0) {
475 if (pitch + delta <= PITCH_MAX) {
476 new_pitch = pitch + delta;
477 } else {
478 if (!allow_cutoff) {
479 return pitch;
481 new_pitch = PITCH_MAX;
483 } else {
484 /* delta == 0 -> no real change */
485 return pitch;
487 sound_set_pitch(new_pitch);
489 if (redraw_screens) {
490 FOR_NB_SCREENS(i)
491 pitch_screen_draw(&screens[i], pitch, pitch_mode);
494 return new_pitch;
497 /* Factor for changing the pitch one half tone up.
498 The exact value is 2^(1/12) = 1.05946309436
499 But we use only integer arithmetics, so take
500 rounded factor multiplied by 10^5=100,000. This is
501 enough to get the same promille values as if we
502 had used floating point (checked with a spread
503 sheet).
505 #define PITCH_SEMITONE_FACTOR 105946L
507 /* Some helpful constants. K is the scaling factor for SEMITONE.
508 N is for more accurate rounding
509 KN is K * N
511 #define PITCH_K_FCT 100000UL
512 #define PITCH_N_FCT 10
513 #define PITCH_KN_FCT 1000000UL
515 static int pitch_increase_semitone(int pitch, bool up) {
516 uint32_t tmp;
517 uint32_t round_fct; /* How much to scale down at the end */
518 tmp = pitch;
519 if (up) {
520 tmp = tmp * PITCH_SEMITONE_FACTOR;
521 round_fct = PITCH_K_FCT;
522 } else {
523 tmp = (tmp * PITCH_KN_FCT) / PITCH_SEMITONE_FACTOR;
524 round_fct = PITCH_N_FCT;
526 /* Scaling down with rounding */
527 tmp = (tmp + round_fct / 2) / round_fct;
528 return pitch_increase(pitch, tmp - pitch, false, false);
531 bool pitch_screen(void)
533 int button;
534 int pitch = sound_get_pitch();
535 int new_pitch;
536 bool nudged = false;
537 bool exit = false;
538 int i;
540 #if CONFIG_CODEC == SWCODEC
541 pcmbuf_set_low_latency(true);
542 #endif
544 while (!exit)
546 FOR_NB_SCREENS(i)
547 pitch_screen_draw(&screens[i], pitch, pitch_mode);
549 button = get_action(CONTEXT_PITCHSCREEN,TIMEOUT_BLOCK);
550 switch (button) {
551 case ACTION_PS_INC_SMALL:
552 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
553 pitch = pitch_increase(pitch, PITCH_SMALL_DELTA, true, false);
554 } else {
555 pitch = pitch_increase_semitone(pitch, true);
557 break;
559 case ACTION_PS_INC_BIG:
560 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
561 pitch = pitch_increase(pitch, PITCH_BIG_DELTA, true, false);
563 break;
565 case ACTION_PS_DEC_SMALL:
566 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
567 pitch = pitch_increase(pitch, -PITCH_SMALL_DELTA, true, false);
568 } else {
569 pitch = pitch_increase_semitone(pitch, false);
571 break;
573 case ACTION_PS_DEC_BIG:
574 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
575 pitch = pitch_increase(pitch, -PITCH_BIG_DELTA, true, false);
577 break;
579 case ACTION_PS_NUDGE_RIGHT:
580 new_pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false, true);
581 nudged = (new_pitch != pitch);
582 pitch = new_pitch;
583 break;
584 case ACTION_PS_NUDGE_RIGHTOFF:
585 if (nudged) {
586 pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false, false);
588 nudged = false;
589 break;
591 case ACTION_PS_NUDGE_LEFT:
592 new_pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false, true);
593 nudged = (new_pitch != pitch);
594 pitch = new_pitch;
595 break;
597 case ACTION_PS_NUDGE_LEFTOFF:
598 if (nudged) {
599 pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false, false);
601 nudged = false;
602 break;
604 case ACTION_PS_RESET:
605 pitch = 1000;
606 sound_set_pitch( pitch );
607 break;
609 case ACTION_PS_TOGGLE_MODE:
610 pitch_mode = -pitch_mode;
611 break;
613 case ACTION_PS_EXIT:
614 exit = true;
615 break;
617 default:
618 if(default_event_handler(button) == SYS_USB_CONNECTED)
619 return 1;
620 break;
623 #if CONFIG_CODEC == SWCODEC
624 pcmbuf_set_low_latency(false);
625 #endif
626 lcd_setfont(FONT_UI);
627 return 0;
629 #endif /* HAVE_PITCHSCREEN */
631 #ifdef HAVE_QUICKSCREEN
633 #define bool_to_int(b)\
634 b?1:0
635 #define int_to_bool(i)\
636 i==0?false:true
638 static void quick_screen_quick_apply(struct gui_quickscreen *qs)
640 global_settings.playlist_shuffle=int_to_bool(qs->left_option->option);
641 global_settings.dirfilter=qs->bottom_option->option;
642 global_settings.repeat_mode=qs->right_option->option;
645 bool quick_screen_quick(int button_enter)
647 bool res, oldshuffle;
648 struct option_select left_option;
649 struct option_select bottom_option;
650 struct option_select right_option;
651 int oldrepeat, old_x_margin, old_y_margin;
653 static const struct opt_items left_items[] = {
654 [0]={ STR(LANG_SYSFONT_OFF) },
655 [1]={ STR(LANG_SYSFONT_ON) }
657 static const struct opt_items bottom_items[] = {
658 [SHOW_ALL]={ STR(LANG_SYSFONT_ALL) },
659 [SHOW_SUPPORTED]={ STR(LANG_SYSFONT_FILTER_SUPPORTED) },
660 [SHOW_MUSIC]={ STR(LANG_SYSFONT_FILTER_MUSIC) },
661 [SHOW_PLAYLIST]={ STR(LANG_SYSFONT_FILTER_PLAYLIST) },
663 static const struct opt_items right_items[] = {
664 [REPEAT_OFF]={ STR(LANG_SYSFONT_OFF) },
665 [REPEAT_ALL]={ STR(LANG_SYSFONT_ALL) },
666 [REPEAT_ONE]={ STR(LANG_SYSFONT_REPEAT_ONE) },
667 [REPEAT_SHUFFLE]={ STR(LANG_SYSFONT_SHUFFLE) },
668 #ifdef AB_REPEAT_ENABLE
669 [REPEAT_AB]={ STR(LANG_SYSFONT_REPEAT_AB) }
670 #endif
672 struct gui_quickscreen qs;
674 old_x_margin = lcd_getxmargin();
675 old_y_margin = lcd_getymargin();
676 lcd_setmargins(0, 0);
678 option_select_init_items(&left_option,
679 (char *)str(LANG_SYSFONT_SHUFFLE),
680 bool_to_int(global_settings.playlist_shuffle),
681 left_items,
683 option_select_init_items(&bottom_option,
684 (char *)str(LANG_SYSFONT_FILTER),
685 global_settings.dirfilter,
686 bottom_items,
687 sizeof(bottom_items)/sizeof(struct opt_items));
688 option_select_init_items(&right_option,
689 (char *)str(LANG_SYSFONT_REPEAT),
690 global_settings.repeat_mode,
691 right_items,
692 sizeof(right_items)/sizeof(struct opt_items));
694 gui_quickscreen_init(&qs, &left_option, &bottom_option, &right_option,
695 &quick_screen_quick_apply);
696 oldrepeat=global_settings.repeat_mode;
697 oldshuffle=global_settings.playlist_shuffle;
698 res=gui_syncquickscreen_run(&qs, button_enter);
699 if(!res)
701 if ( oldrepeat != global_settings.repeat_mode &&
702 (audio_status() & AUDIO_STATUS_PLAY) )
703 audio_flush_and_reload_tracks();
704 if(oldshuffle != global_settings.playlist_shuffle
705 && audio_status() & AUDIO_STATUS_PLAY)
707 #if CONFIG_CODEC == SWCODEC
708 dsp_set_replaygain();
709 #endif
710 if (global_settings.playlist_shuffle)
711 playlist_randomise(NULL, current_tick, true);
712 else
713 playlist_sort(NULL, true);
715 settings_save();
717 lcd_setmargins(old_x_margin, old_y_margin);
718 return(res);
721 #ifdef BUTTON_F3
722 static void quick_screen_f3_apply(struct gui_quickscreen *qs)
724 global_settings.scrollbar=int_to_bool(qs->left_option->option);
726 global_settings.flip_display=int_to_bool(qs->bottom_option->option);
727 button_set_flip(global_settings.flip_display);
728 lcd_set_flip(global_settings.flip_display);
730 global_settings.statusbar=int_to_bool(qs->right_option->option);
731 gui_syncstatusbar_draw(&statusbars, true);
734 bool quick_screen_f3(int button_enter)
736 bool res;
737 struct option_select left_option;
738 struct option_select bottom_option;
739 struct option_select right_option;
740 int old_x_margin, old_y_margin;
742 static const struct opt_items onoff_items[] = {
743 [0]={ STR(LANG_SYSFONT_OFF) },
744 [1]={ STR(LANG_SYSFONT_ON) }
746 static const struct opt_items yesno_items[] = {
747 [0]={ STR(LANG_SYSFONT_SET_BOOL_NO) },
748 [1]={ STR(LANG_SYSFONT_SET_BOOL_YES) }
751 struct gui_quickscreen qs;
753 old_x_margin = lcd_getxmargin();
754 old_y_margin = lcd_getymargin();
755 lcd_setmargins(0, 0);
757 option_select_init_items(&left_option,
758 str(LANG_SYSFONT_SCROLL_BAR),
759 bool_to_int(global_settings.scrollbar),
760 onoff_items,
762 option_select_init_items(&bottom_option,
763 str(LANG_SYSFONT_FLIP_DISPLAY),
764 bool_to_int(global_settings.flip_display),
765 yesno_items,
767 option_select_init_items(&right_option,
768 str(LANG_SYSFONT_STATUS_BAR),
769 bool_to_int(global_settings.statusbar),
770 onoff_items,
772 gui_quickscreen_init(&qs, &left_option, &bottom_option, &right_option,
773 &quick_screen_f3_apply);
774 res=gui_syncquickscreen_run(&qs, button_enter);
775 if(!res)
776 settings_save();
777 lcd_setmargins(old_x_margin, old_y_margin);
778 return(res);
780 #endif /* BUTTON_F3 */
781 #endif /* CONFIG_KEYPAD in (RECORDER_PAD |IRIVER_H100_PAD | IRIVER_H300_PAD) */
783 #if CONFIG_CHARGING
784 void charging_splash(void)
786 gui_syncsplash(2*HZ, (unsigned char *)str(LANG_BATTERY_CHARGE));
787 button_clear_queue();
789 #endif
792 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
794 const int dayname[] = {
795 LANG_WEEKDAY_SUNDAY,
796 LANG_WEEKDAY_MONDAY,
797 LANG_WEEKDAY_TUESDAY,
798 LANG_WEEKDAY_WEDNESDAY,
799 LANG_WEEKDAY_THURSDAY,
800 LANG_WEEKDAY_FRIDAY,
801 LANG_WEEKDAY_SATURDAY
804 const int monthname[] = {
805 LANG_MONTH_JANUARY,
806 LANG_MONTH_FEBRUARY,
807 LANG_MONTH_MARCH,
808 LANG_MONTH_APRIL,
809 LANG_MONTH_MAY,
810 LANG_MONTH_JUNE,
811 LANG_MONTH_JULY,
812 LANG_MONTH_AUGUST,
813 LANG_MONTH_SEPTEMBER,
814 LANG_MONTH_OCTOBER,
815 LANG_MONTH_NOVEMBER,
816 LANG_MONTH_DECEMBER
819 /* little helper function for voice output */
820 static void say_time(int cursorpos, const struct tm *tm)
822 static const int unit[] = { UNIT_HOUR, UNIT_MIN, UNIT_SEC, 0, 0, 0 };
823 int value = 0;
825 if (!talk_menus_enabled())
826 return;
828 switch(cursorpos)
830 case 0:
831 value = tm->tm_hour;
832 break;
833 case 1:
834 value = tm->tm_min;
835 break;
836 case 2:
837 value = tm->tm_sec;
838 break;
839 case 3:
840 value = tm->tm_year + 1900;
841 break;
842 case 5:
843 value = tm->tm_mday;
844 break;
847 if (cursorpos == 4) /* month */
848 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
849 else
850 talk_value(value, unit[cursorpos], false);
854 #define INDEX_X 0
855 #define INDEX_Y 1
856 #define INDEX_WIDTH 2
858 #define SEPARATOR ":"
859 bool set_time_screen(const char* title, struct tm *tm)
861 bool done = false;
862 int button;
863 unsigned int i, s;
864 unsigned int cursorpos = 0;
865 unsigned int lastcursorpos = 1;
866 unsigned int julianday;
867 unsigned int realyear;
868 unsigned int width;
869 unsigned int min = 0, steps = 0;
870 unsigned int statusbar_height = 0;
871 unsigned int separator_width, weekday_width;
872 unsigned int line_height, prev_line_height;
873 unsigned char daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
874 unsigned char buffer[20];
876 /* 6 possible cursor possitions, 3 values stored for each: x, y, width */
877 unsigned char cursor[6][3];
878 memset(cursor, 0, sizeof(cursor));
880 int *valptr = NULL;
881 unsigned char *ptr[6];
883 if(global_settings.statusbar)
884 statusbar_height = STATUSBAR_HEIGHT;
886 while ( !done ) {
887 /* for easy acess in the drawing loop */
888 ptr[0] = buffer; /* hours */
889 ptr[1] = buffer + 3; /* minutes */
890 ptr[2] = buffer + 6; /* seconds */
891 ptr[3] = buffer + 9; /* year */
892 ptr[4] = str(monthname[tm->tm_mon]); /* monthname */
893 ptr[5] = buffer + 14; /* day of month */
895 /* calculate the number of days in febuary */
896 realyear = tm->tm_year + 1900;
897 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
898 daysinmonth[1] = 29;
899 else
900 daysinmonth[1] = 28;
902 /* fix day if month or year changed */
903 if (tm->tm_mday > daysinmonth[tm->tm_mon])
904 tm->tm_mday = daysinmonth[tm->tm_mon];
906 /* calculate day of week */
907 julianday = 0;
908 for(i = 0; (int)i < tm->tm_mon; i++) {
909 julianday += daysinmonth[i];
911 julianday += tm->tm_mday;
912 tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
913 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
915 /* put all the numbers we want from the tm struct into
916 an easily printable buffer */
917 snprintf(buffer, sizeof(buffer),
918 "%02d " "%02d " "%02d " "%04d " "%02d",
919 tm->tm_hour, tm->tm_min, tm->tm_sec,
920 tm->tm_year+1900, tm->tm_mday);
922 /* convert spaces in the buffer to '\0' to make it possible to work
923 directly on the buffer */
924 for(i=0; i < sizeof(buffer); i++)
926 if(buffer[i] == ' ')
927 buffer[i] = '\0';
930 FOR_NB_SCREENS(s)
932 /* minimum lines needed is 2 + title line */
933 gui_textarea_update_nblines(&screens[s]);
934 if (screens[s].nb_lines < 4)
936 screens[s].setfont(FONT_SYSFIXED);
937 gui_textarea_update_nblines(&screens[s]);
940 /* recalculate the positions and offsets */
941 if (screens[s].nb_lines >= 3)
942 screens[s].getstringsize(title, NULL, &prev_line_height);
943 else
944 prev_line_height = 0;
945 screens[s].getstringsize(buffer, NULL, &line_height);
946 screens[s].getstringsize(SEPARATOR, &separator_width, NULL);
949 /* get width for each string except the last one and put them
950 in the cursor array */
951 for(i=0; i < 5; i++)
953 screens[s].getstringsize(ptr[i], &width, NULL);
954 cursor[i][INDEX_WIDTH] = width;
957 /* hour */
958 /* cursor[0][INDEX_X] is already 0 because of the memset */
959 cursor[0][INDEX_Y] = prev_line_height + statusbar_height;
961 /* minute */
962 cursor[1][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width;
963 cursor[1][INDEX_Y] = prev_line_height + statusbar_height;
965 /* second */
966 cursor[2][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width +
967 cursor[1][INDEX_WIDTH] + separator_width;
968 cursor[2][INDEX_Y] = prev_line_height + statusbar_height;
970 /* weekday */
971 screens[s].getstringsize(str(dayname[tm->tm_wday]), &weekday_width, NULL);
972 screens[s].getstringsize(" ", &separator_width, NULL);
974 /* year */
975 cursor[3][INDEX_X] = weekday_width + separator_width;
976 cursor[3][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
978 /* month */
979 cursor[4][INDEX_X] = weekday_width + 2 * separator_width +
980 cursor[3][INDEX_WIDTH];
981 cursor[4][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
983 /* day */
984 cursor[5][INDEX_X] = weekday_width + 3 * separator_width +
985 cursor[3][INDEX_WIDTH] +
986 cursor[4][INDEX_WIDTH];
987 cursor[5][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
989 /* draw the screen */
990 screens[s].set_drawmode(DRMODE_SOLID);
991 gui_textarea_clear(&screens[s]);
992 /* display the screen title */
993 screens[s].puts_scroll(0, 0, title);
995 /* these are not selectable, so we draw them outside the loop */
996 screens[s].putsxy(0, cursor[3][INDEX_Y], str(dayname[tm->tm_wday])); /* name of the week day */
997 screens[s].putsxy(cursor[1][INDEX_X] - separator_width,
998 cursor[0][INDEX_Y], SEPARATOR);
999 screens[s].putsxy(cursor[2][INDEX_X] - separator_width,
1000 cursor[0][INDEX_Y], SEPARATOR);
1002 /* draw the selected item with drawmode set to
1003 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
1004 items with drawmode DRMODE_SOLID */
1005 for(i=0; i<6; i++)
1007 if (cursorpos == i)
1008 screens[s].set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1009 else
1010 screens[s].set_drawmode(DRMODE_SOLID);
1012 screens[s].putsxy(cursor[i][INDEX_X],
1013 cursor[i][INDEX_Y], ptr[i]);
1016 /* print help text */
1017 if (screens[s].nb_lines > 4)
1018 screens[s].puts(0, 4, str(LANG_TIME_SET_BUTTON));
1019 if (screens[s].nb_lines > 5)
1020 screens[s].puts(0, 5, str(LANG_TIME_REVERT));
1021 screens[s].update();
1023 gui_syncstatusbar_draw(&statusbars, true);
1025 /* calculate the minimum and maximum for the number under cursor */
1026 if(cursorpos!=lastcursorpos) {
1027 lastcursorpos=cursorpos;
1028 switch(cursorpos) {
1029 case 0: /* hour */
1030 min = 0;
1031 steps = 24;
1032 valptr = &tm->tm_hour;
1033 break;
1034 case 1: /* minute */
1035 min = 0;
1036 steps = 60;
1037 valptr = &tm->tm_min;
1038 break;
1039 case 2: /* second */
1040 min = 0;
1041 steps = 60;
1042 valptr = &tm->tm_sec;
1043 break;
1044 case 3: /* year */
1045 min = 1;
1046 steps = 200;
1047 valptr = &tm->tm_year;
1048 break;
1049 case 4: /* month */
1050 min = 0;
1051 steps = 12;
1052 valptr = &tm->tm_mon;
1053 break;
1054 case 5: /* day */
1055 min = 1;
1056 steps = daysinmonth[tm->tm_mon];
1057 valptr = &tm->tm_mday;
1058 break;
1060 say_time(cursorpos, tm);
1063 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
1064 switch ( button ) {
1065 case ACTION_STD_PREV:
1066 cursorpos = (cursorpos + 6 - 1) % 6;
1067 break;
1068 case ACTION_STD_NEXT:
1069 cursorpos = (cursorpos + 6 + 1) % 6;
1070 break;
1071 case ACTION_SETTINGS_INC:
1072 case ACTION_SETTINGS_INCREPEAT:
1073 *valptr = (*valptr + steps - min + 1) %
1074 steps + min;
1075 if(*valptr == 0)
1076 *valptr = min;
1077 say_time(cursorpos, tm);
1078 break;
1079 case ACTION_SETTINGS_DEC:
1080 case ACTION_SETTINGS_DECREPEAT:
1081 *valptr = (*valptr + steps - min - 1) %
1082 steps + min;
1083 if(*valptr == 0)
1084 *valptr = min;
1085 say_time(cursorpos, tm);
1086 break;
1088 case ACTION_STD_OK:
1089 done = true;
1090 break;
1092 case ACTION_STD_CANCEL:
1093 done = true;
1094 tm->tm_year = -1;
1095 break;
1097 default:
1098 if (default_event_handler(button) == SYS_USB_CONNECTED)
1099 return true;
1100 break;
1103 FOR_NB_SCREENS(i)
1105 screens[i].setfont(FONT_UI);
1106 gui_textarea_update_nblines(&screens[i]);
1108 return false;
1110 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
1112 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
1113 bool shutdown_screen(void)
1115 int button;
1116 bool done = false;
1117 long time_entered = current_tick;
1119 lcd_stop_scroll();
1121 gui_syncsplash(0, str(LANG_CONFIRM_SHUTDOWN));
1123 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
1125 button = get_action(CONTEXT_STD,HZ);
1126 switch(button)
1128 case ACTION_STD_CANCEL:
1129 sys_poweroff();
1130 break;
1132 /* do nothing here, because ACTION_NONE might be caused
1133 * by timeout or button release. In case of timeout the loop
1134 * is terminated by TIME_BEFORE */
1135 case ACTION_NONE:
1136 break;
1138 default:
1139 if(default_event_handler(button) == SYS_USB_CONNECTED)
1140 return true;
1141 done = true;
1142 break;
1145 return false;
1147 #endif
1149 static const int id3_headers[]=
1151 LANG_ID3_TITLE,
1152 LANG_ID3_ARTIST,
1153 LANG_ID3_ALBUM,
1154 LANG_ID3_ALBUMARTIST,
1155 LANG_ID3_GROUPING,
1156 LANG_ID3_DISCNUM,
1157 LANG_ID3_TRACKNUM,
1158 LANG_ID3_COMMENT,
1159 LANG_ID3_GENRE,
1160 LANG_ID3_YEAR,
1161 LANG_ID3_LENGTH,
1162 LANG_ID3_PLAYLIST,
1163 LANG_ID3_BITRATE,
1164 LANG_ID3_FREQUENCY,
1165 #if CONFIG_CODEC == SWCODEC
1166 LANG_ID3_TRACK_GAIN,
1167 LANG_ID3_ALBUM_GAIN,
1168 #endif
1169 LANG_ID3_PATH,
1172 static char * id3_get_info(int selected_item, void* data, char *buffer)
1174 struct mp3entry* id3 =(struct mp3entry*)data;
1175 int info_no=selected_item/2;
1176 if(!(selected_item%2))
1177 {/* header */
1178 return( str(id3_headers[info_no]));
1180 else
1181 {/* data */
1183 char * info=NULL;
1184 switch(info_no)
1186 case 0:/*LANG_ID3_TITLE*/
1187 info=id3->title;
1188 break;
1189 case 1:/*LANG_ID3_ARTIST*/
1190 info=id3->artist;
1191 break;
1192 case 2:/*LANG_ID3_ALBUM*/
1193 info=id3->album;
1194 break;
1195 case 3:/*LANG_ID3_ALBUMARTIST*/
1196 info=id3->albumartist;
1197 break;
1198 case 4:/*LANG_ID3_GROUPING*/
1199 info=id3->grouping;
1200 break;
1201 case 5:/*LANG_ID3_DISCNUM*/
1202 if (id3->disc_string)
1203 info = id3->disc_string;
1204 else if (id3->discnum)
1206 snprintf(buffer, MAX_PATH, "%d", id3->discnum);
1207 info = buffer;
1209 break;
1210 case 6:/*LANG_ID3_TRACKNUM*/
1211 if (id3->track_string)
1212 info = id3->track_string;
1213 else if (id3->tracknum)
1215 snprintf(buffer, MAX_PATH, "%d", id3->tracknum);
1216 info = buffer;
1218 break;
1219 case 7:/*LANG_ID3_COMMENT*/
1220 info=id3->comment;
1221 break;
1222 case 8:/*LANG_ID3_GENRE*/
1223 info = id3->genre_string;
1224 break;
1225 case 9:/*LANG_ID3_YEAR*/
1226 if (id3->year_string)
1227 info = id3->year_string;
1228 else if (id3->year)
1230 snprintf(buffer, MAX_PATH, "%d", id3->year);
1231 info = buffer;
1233 break;
1234 case 10:/*LANG_ID3_LENGTH*/
1235 format_time(buffer, MAX_PATH, id3->length);
1236 info=buffer;
1237 break;
1238 case 11:/*LANG_ID3_PLAYLIST*/
1239 snprintf(buffer, MAX_PATH, "%d/%d", playlist_get_display_index(),
1240 playlist_amount());
1241 info=buffer;
1242 break;
1243 case 12:/*LANG_ID3_BITRATE*/
1244 snprintf(buffer, MAX_PATH, "%d kbps%s", id3->bitrate,
1245 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
1246 info=buffer;
1247 break;
1248 case 13:/*LANG_ID3_FREQUENCY*/
1249 snprintf(buffer, MAX_PATH, "%ld Hz", id3->frequency);
1250 info=buffer;
1251 break;
1252 #if CONFIG_CODEC == SWCODEC
1253 case 14:/*LANG_ID3_TRACK_GAIN*/
1254 info=id3->track_gain_string;
1255 break;
1256 case 15:/*LANG_ID3_ALBUM_GAIN*/
1257 info=id3->album_gain_string;
1258 break;
1259 case 16:/*LANG_ID3_PATH*/
1260 #else
1261 case 14:/*LANG_ID3_PATH*/
1262 #endif
1263 info=id3->path;
1264 break;
1266 return info && *info ? info : (char*) str(LANG_ID3_NO_INFO);
1270 bool browse_id3(void)
1272 struct gui_synclist id3_lists;
1273 struct mp3entry* id3 = audio_current_track();
1274 int key;
1276 gui_synclist_init(&id3_lists, &id3_get_info, id3, true, 2);
1277 gui_synclist_set_nb_items(&id3_lists,
1278 sizeof(id3_headers)/sizeof(id3_headers[0])*2);
1279 gui_synclist_draw(&id3_lists);
1280 gui_syncstatusbar_draw(&statusbars, true);
1281 while (true) {
1282 gui_syncstatusbar_draw(&statusbars, false);
1283 key = get_action(CONTEXT_LIST,HZ/2);
1284 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
1285 && !gui_synclist_do_button(&id3_lists, key,LIST_WRAP_UNLESS_HELD))
1287 return(default_event_handler(key) == SYS_USB_CONNECTED);
1292 static char* runtime_get_data(int selected_item, void* data, char* buffer)
1294 (void) data;
1295 unsigned char *headers[] = {str(LANG_RUNNING_TIME), str(LANG_TOP_TIME) };
1296 int t;
1297 if(!(selected_item%2))
1298 return headers[selected_item/2];
1300 if(selected_item/2) t = global_status.topruntime;
1301 else t = global_status.runtime;
1303 snprintf(buffer, 16, "%dh %dm %ds",
1304 t / 3600, (t % 3600) / 60, t % 60);
1305 return buffer;
1310 bool view_runtime(void)
1312 unsigned char *lines[]={str(LANG_CLEAR_TIME)};
1313 struct text_message message={(char **)lines, 1};
1315 struct gui_synclist lists;
1316 int action;
1317 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2);
1318 #if !defined(HAVE_LCD_CHARCELLS)
1319 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
1320 #else
1321 gui_synclist_set_title(&lists, NULL, NOICON);
1322 #endif
1323 gui_synclist_set_icon_callback(&lists, NULL);
1324 gui_synclist_set_nb_items(&lists, 4);
1325 while(1)
1327 #if CONFIG_CHARGING
1328 if (charger_inserted()
1329 #ifdef HAVE_USB_POWER
1330 || usb_powered()
1331 #endif
1334 global_status.runtime = 0;
1336 else
1337 #endif
1339 global_status.runtime += ((current_tick - lasttime) / HZ);
1341 lasttime = current_tick;
1342 gui_synclist_draw(&lists);
1343 gui_syncstatusbar_draw(&statusbars, true);
1344 action = get_action(CONTEXT_STD, HZ);
1345 gui_synclist_do_button(&lists, action, LIST_WRAP_UNLESS_HELD);
1346 if(action == ACTION_STD_CANCEL)
1347 break;
1348 if(action == ACTION_STD_OK) {
1349 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
1351 if (!(gui_synclist_get_sel_pos(&lists)/2))
1352 global_status.runtime = 0;
1353 else
1354 global_status.topruntime = 0;
1357 if(default_event_handler(action) == SYS_USB_CONNECTED)
1358 return true;
1360 return false;