rbutilQt: added Talkfile creation.
[Rockbox.git] / apps / screens.c
blobb2436f00f1f4cf71cdffd4797b9e2931d3a1ef88
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].puts_scroll(0, 0, "[USB Mode]");
119 status_set_param(false);
120 status_set_audio(false);
121 status_set_usb(true);
122 #endif /* HAVE_LCD_BITMAP */
123 #if NB_SCREENS > 1
125 #endif
126 screens[i].update();
129 gui_syncstatusbar_draw(&statusbars, true);
130 #ifdef SIMULATOR
131 while (button_get(true) & BUTTON_REL);
132 #else
133 usb_acknowledge(SYS_USB_CONNECTED_ACK);
134 while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) {
135 if(usb_inserted()) {
136 #ifdef HAVE_MMC /* USB-MMC bridge can report activity */
137 led(mmc_usb_active(HZ));
138 #endif /* HAVE_MMC */
139 gui_syncstatusbar_draw(&statusbars, false);
142 #endif /* SIMULATOR */
143 #ifdef HAVE_LCD_CHARCELLS
144 status_set_usb(false);
145 #endif /* HAVE_LCD_CHARCELLS */
146 FOR_NB_SCREENS(i)
147 screens[i].backlight_on();
148 global_settings.statusbar = statusbar;
149 #endif /* USB_NONE */
152 #ifdef HAVE_MMC
153 int mmc_remove_request(void)
155 struct event ev;
156 int i;
157 FOR_NB_SCREENS(i)
158 screens[i].clear_display();
159 gui_syncsplash(1, str(LANG_REMOVE_MMC));
160 if (talk_menus_enabled())
161 talk_id(LANG_REMOVE_MMC, false);
163 while (1)
165 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
166 switch (ev.id)
168 case SYS_HOTSWAP_EXTRACTED:
169 return SYS_HOTSWAP_EXTRACTED;
171 case SYS_USB_DISCONNECTED:
172 return SYS_USB_DISCONNECTED;
176 #endif
178 /* the charging screen is only used for archos targets */
179 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
181 #ifdef HAVE_LCD_BITMAP
182 static void charging_display_info(bool animate)
184 unsigned char charging_logo[36];
185 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
186 const int pox_y = 32;
187 static unsigned phase = 3;
188 unsigned i;
189 char buf[32];
190 (void)buf;
192 #ifdef NEED_ATA_POWER_BATT_MEASURE
193 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
194 #endif
196 int battv = battery_voltage();
197 snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 100,
198 battv % 100, battery_level());
199 lcd_puts(0, 7, buf);
202 #if CONFIG_CHARGING == CHARGING_CONTROL
204 snprintf(buf, 32, "Charge mode:");
205 lcd_puts(0, 2, buf);
207 if (charge_state == CHARGING)
208 snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
209 else if (charge_state == TOPOFF)
210 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
211 else if (charge_state == TRICKLE)
212 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
213 else
214 snprintf(buf, 32, "not charging");
216 lcd_puts(0, 3, buf);
217 if (!charger_enabled)
218 animate = false;
219 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
222 /* middle part */
223 memset(charging_logo+3, 0x00, 32);
224 charging_logo[0] = 0x3C;
225 charging_logo[1] = 0x24;
226 charging_logo[2] = charging_logo[35] = 0xFF;
228 if (!animate)
229 { /* draw the outline */
230 /* middle part */
231 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, sizeof(charging_logo), 8);
232 lcd_set_drawmode(DRMODE_FG);
233 /* upper line */
234 charging_logo[0] = charging_logo[1] = 0x00;
235 memset(charging_logo+2, 0x80, 34);
236 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
237 /* lower line */
238 memset(charging_logo+2, 0x01, 34);
239 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16, sizeof(charging_logo), 8);
240 lcd_set_drawmode(DRMODE_SOLID);
242 else
243 { /* animate the middle part */
244 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
246 if ((i-phase) % 8 == 0)
247 { /* draw a "bubble" here */
248 unsigned bitpos;
249 bitpos = (phase + i/8) % 15; /* "bounce" effect */
250 if (bitpos > 7)
251 bitpos = 14 - bitpos;
252 charging_logo[i] = 0x01 << bitpos;
255 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, sizeof(charging_logo), 8);
256 phase++;
258 lcd_update();
260 #else /* not HAVE_LCD_BITMAP */
262 static unsigned long logo_chars[4];
263 static const unsigned char logo_pattern[] = {
264 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
265 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
266 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
267 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
270 static void logo_lock_patterns(bool on)
272 int i;
274 if (on)
276 for (i = 0; i < 4; i++)
277 logo_chars[i] = lcd_get_locked_pattern();
279 else
281 for (i = 0; i < 4; i++)
282 lcd_unlock_pattern(logo_chars[i]);
286 static void charging_display_info(bool animate)
288 int battv;
289 unsigned i, ypos;
290 static unsigned phase = 3;
291 char buf[32];
293 battv = battery_voltage();
294 snprintf(buf, sizeof(buf), " %d.%02dV", battv / 100, battv % 100);
295 lcd_puts(4, 1, buf);
297 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
299 if (!animate) /* build the screen */
301 lcd_double_height(false);
302 lcd_puts(0, 0, "[Charging]");
303 for (i = 0; i < 4; i++)
304 lcd_putc(i, 1, logo_chars[i]);
306 else /* animate the logo */
308 for (i = 3; i < MIN(19, phase); i++)
310 if ((i - phase) % 5 == 0)
311 { /* draw a "bubble" here */
312 ypos = (phase + i/5) % 9; /* "bounce" effect */
313 if (ypos > 4)
314 ypos = 8 - ypos;
315 buf[5 - ypos + 8 * (i/5)] |= 0x10 >> (i%5);
318 phase++;
321 for (i = 0; i < 4; i++)
322 lcd_define_pattern(logo_chars[i], buf + 8 * i);
324 lcd_update();
326 #endif /* (not) HAVE_LCD_BITMAP */
328 /* blocks while charging, returns on event:
329 1 if charger cable was removed
330 2 if Off/Stop key was pressed
331 3 if On key was pressed
332 4 if USB was connected */
334 int charging_screen(void)
336 unsigned int button;
337 int rc = 0;
339 ide_power_enable(false); /* power down the disk, else would be spinning */
341 lcd_clear_display();
342 backlight_set_timeout(global_settings.backlight_timeout);
343 #ifdef HAVE_REMOTE_LCD
344 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
345 #endif
346 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
347 gui_syncstatusbar_draw(&statusbars, true);
349 #ifdef HAVE_LCD_CHARCELLS
350 logo_lock_patterns(true);
351 #endif
352 charging_display_info(false);
356 gui_syncstatusbar_draw(&statusbars, false);
357 charging_display_info(true);
358 button = get_action(CONTEXT_STD,HZ/3);
359 if (button == ACTION_STD_OK)
360 rc = 2;
361 else if (usb_detect())
362 rc = 3;
363 else if (!charger_inserted())
364 rc = 1;
365 } while (!rc);
367 #ifdef HAVE_LCD_CHARCELLS
368 logo_lock_patterns(false);
369 #endif
370 return rc;
372 #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
374 #ifdef HAVE_PITCHSCREEN
376 #define PITCH_MAX 2000
377 #define PITCH_MIN 500
378 #define PITCH_SMALL_DELTA 1
379 #define PITCH_BIG_DELTA 10
380 #define PITCH_NUDGE_DELTA 20
382 #define PITCH_MODE_ABSOLUTE 1
383 #define PITCH_MODE_SEMITONE -PITCH_MODE_ABSOLUTE
385 static int pitch_mode = PITCH_MODE_ABSOLUTE; /* 1 - absolute, -1 - semitone */
387 /* returns:
388 0 if no key was pressed
389 1 if USB was connected */
391 static void pitch_screen_draw(struct screen *display, int pitch, int pitch_mode)
393 unsigned char* ptr;
394 unsigned char buf[32];
395 int w, h;
397 display->clear_display();
399 if (display->nb_lines < 4) /* very small screen, just show the pitch value */
401 w = snprintf((char *)buf, sizeof(buf), "%s: %d.%d%%",str(LANG_SYSFONT_PITCH),
402 pitch / 10, pitch % 10 );
403 display->putsxy((display->width-(w*display->char_width))/2,
404 display->nb_lines/2,buf);
406 else /* bigger screen, show everything... */
409 /* UP: Pitch Up */
410 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
411 ptr = str(LANG_SYSFONT_PITCH_UP);
412 } else {
413 ptr = str(LANG_SYSFONT_PITCH_UP_SEMITONE);
415 display->getstringsize(ptr,&w,&h);
416 display->putsxy((display->width-w)/2, 0, ptr);
417 display->mono_bitmap(bitmap_icons_7x8[Icon_UpArrow],
418 display->width/2 - 3, h, 7, 8);
420 /* DOWN: Pitch Down */
421 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
422 ptr = str(LANG_SYSFONT_PITCH_DOWN);
423 } else {
424 ptr = str(LANG_SYSFONT_PITCH_DOWN_SEMITONE);
426 display->getstringsize(ptr,&w,&h);
427 display->putsxy((display->width-w)/2, display->height - h, ptr);
428 display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
429 display->width/2 - 3, display->height - h*2, 7, 8);
431 /* RIGHT: +2% */
432 ptr = "+2%";
433 display->getstringsize(ptr,&w,&h);
434 display->putsxy(display->width-w, (display->height-h)/2, ptr);
435 display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
436 display->width-w-8, (display->height-h)/2, 7, 8);
438 /* LEFT: -2% */
439 ptr = "-2%";
440 display->getstringsize(ptr,&w,&h);
441 display->putsxy(0, (display->height-h)/2, ptr);
442 display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
443 w+1, (display->height-h)/2, 7, 8);
445 /* "Pitch" */
446 snprintf((char *)buf, sizeof(buf), str(LANG_SYSFONT_PITCH));
447 display->getstringsize(buf,&w,&h);
448 display->putsxy((display->width-w)/2, (display->height/2)-h, buf);
449 /* "XX.X%" */
450 snprintf((char *)buf, sizeof(buf), "%d.%d%%",
451 pitch / 10, pitch % 10 );
452 display->getstringsize(buf,&w,&h);
453 display->putsxy((display->width-w)/2, display->height/2, buf);
456 display->update();
459 static int pitch_increase(int pitch, int delta,
460 bool allow_cutoff, bool redraw_screens) {
461 int new_pitch;
462 int i;
464 if (delta < 0) {
465 if (pitch + delta >= PITCH_MIN) {
466 new_pitch = pitch + delta;
467 } else {
468 if (!allow_cutoff) {
469 return pitch;
471 new_pitch = PITCH_MIN;
473 } else if (delta > 0) {
474 if (pitch + delta <= PITCH_MAX) {
475 new_pitch = pitch + delta;
476 } else {
477 if (!allow_cutoff) {
478 return pitch;
480 new_pitch = PITCH_MAX;
482 } else {
483 /* delta == 0 -> no real change */
484 return pitch;
486 sound_set_pitch(new_pitch);
488 if (redraw_screens) {
489 FOR_NB_SCREENS(i)
490 pitch_screen_draw(&screens[i], pitch, pitch_mode);
493 return new_pitch;
496 /* Factor for changing the pitch one half tone up.
497 The exact value is 2^(1/12) = 1.05946309436
498 But we use only integer arithmetics, so take
499 rounded factor multiplied by 10^5=100,000. This is
500 enough to get the same promille values as if we
501 had used floating point (checked with a spread
502 sheet).
504 #define PITCH_SEMITONE_FACTOR 105946L
506 /* Some helpful constants. K is the scaling factor for SEMITONE.
507 N is for more accurate rounding
508 KN is K * N
510 #define PITCH_K_FCT 100000UL
511 #define PITCH_N_FCT 10
512 #define PITCH_KN_FCT 1000000UL
514 static int pitch_increase_semitone(int pitch, bool up) {
515 uint32_t tmp;
516 uint32_t round_fct; /* How much to scale down at the end */
517 tmp = pitch;
518 if (up) {
519 tmp = tmp * PITCH_SEMITONE_FACTOR;
520 round_fct = PITCH_K_FCT;
521 } else {
522 tmp = (tmp * PITCH_KN_FCT) / PITCH_SEMITONE_FACTOR;
523 round_fct = PITCH_N_FCT;
525 /* Scaling down with rounding */
526 tmp = (tmp + round_fct / 2) / round_fct;
527 return pitch_increase(pitch, tmp - pitch, false, false);
530 bool pitch_screen(void)
532 int button;
533 int pitch = sound_get_pitch();
534 int new_pitch;
535 bool nudged = false;
536 bool exit = false;
537 int i;
539 #if CONFIG_CODEC == SWCODEC
540 pcmbuf_set_low_latency(true);
541 #endif
543 while (!exit)
545 FOR_NB_SCREENS(i)
546 pitch_screen_draw(&screens[i], pitch, pitch_mode);
548 button = get_action(CONTEXT_PITCHSCREEN,TIMEOUT_BLOCK);
549 switch (button) {
550 case ACTION_PS_INC_SMALL:
551 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
552 pitch = pitch_increase(pitch, PITCH_SMALL_DELTA, true, false);
553 } else {
554 pitch = pitch_increase_semitone(pitch, true);
556 break;
558 case ACTION_PS_INC_BIG:
559 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
560 pitch = pitch_increase(pitch, PITCH_BIG_DELTA, true, false);
562 break;
564 case ACTION_PS_DEC_SMALL:
565 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
566 pitch = pitch_increase(pitch, -PITCH_SMALL_DELTA, true, false);
567 } else {
568 pitch = pitch_increase_semitone(pitch, false);
570 break;
572 case ACTION_PS_DEC_BIG:
573 if (pitch_mode == PITCH_MODE_ABSOLUTE) {
574 pitch = pitch_increase(pitch, -PITCH_BIG_DELTA, true, false);
576 break;
578 case ACTION_PS_NUDGE_RIGHT:
579 new_pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false, true);
580 nudged = (new_pitch != pitch);
581 pitch = new_pitch;
582 break;
583 case ACTION_PS_NUDGE_RIGHTOFF:
584 if (nudged) {
585 pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false, false);
587 nudged = false;
588 break;
590 case ACTION_PS_NUDGE_LEFT:
591 new_pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false, true);
592 nudged = (new_pitch != pitch);
593 pitch = new_pitch;
594 break;
596 case ACTION_PS_NUDGE_LEFTOFF:
597 if (nudged) {
598 pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false, false);
600 nudged = false;
601 break;
603 case ACTION_PS_RESET:
604 pitch = 1000;
605 sound_set_pitch( pitch );
606 break;
608 case ACTION_PS_TOGGLE_MODE:
609 pitch_mode = -pitch_mode;
610 break;
612 case ACTION_PS_EXIT:
613 exit = true;
614 break;
616 default:
617 if(default_event_handler(button) == SYS_USB_CONNECTED)
618 return 1;
619 break;
622 #if CONFIG_CODEC == SWCODEC
623 pcmbuf_set_low_latency(false);
624 #endif
625 lcd_setfont(FONT_UI);
626 return 0;
628 #endif /* HAVE_PITCHSCREEN */
630 #ifdef HAVE_QUICKSCREEN
632 #define bool_to_int(b)\
633 b?1:0
634 #define int_to_bool(i)\
635 i==0?false:true
637 static void quick_screen_quick_apply(struct gui_quickscreen *qs)
639 global_settings.playlist_shuffle=int_to_bool(qs->left_option->option);
640 global_settings.dirfilter=qs->bottom_option->option;
641 global_settings.repeat_mode=qs->right_option->option;
644 bool quick_screen_quick(int button_enter)
646 bool res, oldshuffle;
647 struct option_select left_option;
648 struct option_select bottom_option;
649 struct option_select right_option;
650 int oldrepeat, old_x_margin, old_y_margin;
652 static const struct opt_items left_items[] = {
653 [0]={ STR(LANG_SYSFONT_OFF) },
654 [1]={ STR(LANG_SYSFONT_ON) }
656 static const struct opt_items bottom_items[] = {
657 [SHOW_ALL]={ STR(LANG_SYSFONT_FILTER_ALL) },
658 [SHOW_SUPPORTED]={ STR(LANG_SYSFONT_FILTER_SUPPORTED) },
659 [SHOW_MUSIC]={ STR(LANG_SYSFONT_FILTER_MUSIC) },
660 [SHOW_PLAYLIST]={ STR(LANG_SYSFONT_FILTER_PLAYLIST) },
662 static const struct opt_items right_items[] = {
663 [REPEAT_OFF]={ STR(LANG_SYSFONT_OFF) },
664 [REPEAT_ALL]={ STR(LANG_SYSFONT_REPEAT_ALL) },
665 [REPEAT_ONE]={ STR(LANG_SYSFONT_REPEAT_ONE) },
666 [REPEAT_SHUFFLE]={ STR(LANG_SYSFONT_SHUFFLE) },
667 #ifdef AB_REPEAT_ENABLE
668 [REPEAT_AB]={ STR(LANG_SYSFONT_REPEAT_AB) }
669 #endif
671 struct gui_quickscreen qs;
673 old_x_margin = lcd_getxmargin();
674 old_y_margin = lcd_getymargin();
675 lcd_setmargins(0, 0);
677 option_select_init_items(&left_option,
678 (char *)str(LANG_SYSFONT_SHUFFLE),
679 bool_to_int(global_settings.playlist_shuffle),
680 left_items,
682 option_select_init_items(&bottom_option,
683 (char *)str(LANG_SYSFONT_FILTER),
684 global_settings.dirfilter,
685 bottom_items,
686 sizeof(bottom_items)/sizeof(struct opt_items));
687 option_select_init_items(&right_option,
688 (char *)str(LANG_SYSFONT_REPEAT),
689 global_settings.repeat_mode,
690 right_items,
691 sizeof(right_items)/sizeof(struct opt_items));
693 gui_quickscreen_init(&qs, &left_option, &bottom_option, &right_option,
694 &quick_screen_quick_apply);
695 oldrepeat=global_settings.repeat_mode;
696 oldshuffle=global_settings.playlist_shuffle;
697 res=gui_syncquickscreen_run(&qs, button_enter);
698 if(!res)
700 if ( oldrepeat != global_settings.repeat_mode &&
701 (audio_status() & AUDIO_STATUS_PLAY) )
702 audio_flush_and_reload_tracks();
703 if(oldshuffle != global_settings.playlist_shuffle
704 && audio_status() & AUDIO_STATUS_PLAY)
706 #if CONFIG_CODEC == SWCODEC
707 dsp_set_replaygain();
708 #endif
709 if (global_settings.playlist_shuffle)
710 playlist_randomise(NULL, current_tick, true);
711 else
712 playlist_sort(NULL, true);
714 settings_save();
716 lcd_setmargins(old_x_margin, old_y_margin);
717 return(res);
720 #ifdef BUTTON_F3
721 static void quick_screen_f3_apply(struct gui_quickscreen *qs)
723 global_settings.scrollbar=int_to_bool(qs->left_option->option);
725 global_settings.flip_display=int_to_bool(qs->bottom_option->option);
726 button_set_flip(global_settings.flip_display);
727 lcd_set_flip(global_settings.flip_display);
729 global_settings.statusbar=int_to_bool(qs->right_option->option);
730 gui_syncstatusbar_draw(&statusbars, true);
733 bool quick_screen_f3(int button_enter)
735 bool res;
736 struct option_select left_option;
737 struct option_select bottom_option;
738 struct option_select right_option;
739 int old_x_margin, old_y_margin;
741 static const struct opt_items onoff_items[] = {
742 [0]={ STR(LANG_SYSFONT_OFF) },
743 [1]={ STR(LANG_SYSFONT_ON) }
745 static const struct opt_items yesno_items[] = {
746 [0]={ STR(LANG_SYSFONT_SET_BOOL_NO) },
747 [1]={ STR(LANG_SYSFONT_SET_BOOL_YES) }
750 struct gui_quickscreen qs;
752 old_x_margin = lcd_getxmargin();
753 old_y_margin = lcd_getymargin();
754 lcd_setmargins(0, 0);
756 option_select_init_items(&left_option,
757 str(LANG_SYSFONT_SCROLL_BAR),
758 bool_to_int(global_settings.scrollbar),
759 onoff_items,
761 option_select_init_items(&bottom_option,
762 str(LANG_SYSFONT_FLIP_DISPLAY),
763 bool_to_int(global_settings.flip_display),
764 yesno_items,
766 option_select_init_items(&right_option,
767 str(LANG_SYSFONT_STATUS_BAR),
768 bool_to_int(global_settings.statusbar),
769 onoff_items,
771 gui_quickscreen_init(&qs, &left_option, &bottom_option, &right_option,
772 &quick_screen_f3_apply);
773 res=gui_syncquickscreen_run(&qs, button_enter);
774 if(!res)
775 settings_save();
776 lcd_setmargins(old_x_margin, old_y_margin);
777 return(res);
779 #endif /* BUTTON_F3 */
780 #endif /* CONFIG_KEYPAD in (RECORDER_PAD |IRIVER_H100_PAD | IRIVER_H300_PAD) */
782 #if CONFIG_CHARGING || defined(SIMULATOR)
783 void charging_splash(void)
785 gui_syncsplash(2*HZ, (unsigned char *)str(LANG_BATTERY_CHARGE));
786 button_clear_queue();
788 #endif
791 #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
793 const int dayname[] = {
794 LANG_WEEKDAY_SUNDAY,
795 LANG_WEEKDAY_MONDAY,
796 LANG_WEEKDAY_TUESDAY,
797 LANG_WEEKDAY_WEDNESDAY,
798 LANG_WEEKDAY_THURSDAY,
799 LANG_WEEKDAY_FRIDAY,
800 LANG_WEEKDAY_SATURDAY
803 const int monthname[] = {
804 LANG_MONTH_JANUARY,
805 LANG_MONTH_FEBRUARY,
806 LANG_MONTH_MARCH,
807 LANG_MONTH_APRIL,
808 LANG_MONTH_MAY,
809 LANG_MONTH_JUNE,
810 LANG_MONTH_JULY,
811 LANG_MONTH_AUGUST,
812 LANG_MONTH_SEPTEMBER,
813 LANG_MONTH_OCTOBER,
814 LANG_MONTH_NOVEMBER,
815 LANG_MONTH_DECEMBER
818 /* little helper function for voice output */
819 static void say_time(int cursorpos, const struct tm *tm)
821 static const int unit[] = { UNIT_HOUR, UNIT_MIN, UNIT_SEC, 0, 0, 0 };
822 int value = 0;
824 if (!talk_menus_enabled())
825 return;
827 switch(cursorpos)
829 case 0:
830 value = tm->tm_hour;
831 break;
832 case 1:
833 value = tm->tm_min;
834 break;
835 case 2:
836 value = tm->tm_sec;
837 break;
838 case 3:
839 value = tm->tm_year + 1900;
840 break;
841 case 5:
842 value = tm->tm_mday;
843 break;
846 if (cursorpos == 4) /* month */
847 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
848 else
849 talk_value(value, unit[cursorpos], false);
853 #define INDEX_X 0
854 #define INDEX_Y 1
855 #define INDEX_WIDTH 2
857 #define SEPARATOR ":"
858 bool set_time_screen(const char* title, struct tm *tm)
860 bool done = false;
861 int button;
862 unsigned int i, s;
863 unsigned int cursorpos = 0;
864 unsigned int lastcursorpos = 1;
865 unsigned int julianday;
866 unsigned int realyear;
867 unsigned int width;
868 unsigned int min = 0, steps = 0;
869 unsigned int statusbar_height = 0;
870 unsigned int separator_width, weekday_width;
871 unsigned int line_height, prev_line_height;
872 unsigned char daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
873 unsigned char buffer[20];
875 /* 6 possible cursor possitions, 3 values stored for each: x, y, width */
876 unsigned char cursor[6][3];
877 memset(cursor, 0, sizeof(cursor));
879 int *valptr = NULL;
880 unsigned char *ptr[6];
882 if(global_settings.statusbar)
883 statusbar_height = STATUSBAR_HEIGHT;
885 while ( !done ) {
886 /* for easy acess in the drawing loop */
887 ptr[0] = buffer; /* hours */
888 ptr[1] = buffer + 3; /* minutes */
889 ptr[2] = buffer + 6; /* seconds */
890 ptr[3] = buffer + 9; /* year */
891 ptr[4] = str(monthname[tm->tm_mon]); /* monthname */
892 ptr[5] = buffer + 14; /* day of month */
894 /* calculate the number of days in febuary */
895 realyear = tm->tm_year + 1900;
896 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
897 daysinmonth[1] = 29;
898 else
899 daysinmonth[1] = 28;
901 /* fix day if month or year changed */
902 if (tm->tm_mday > daysinmonth[tm->tm_mon])
903 tm->tm_mday = daysinmonth[tm->tm_mon];
905 /* calculate day of week */
906 julianday = 0;
907 for(i = 0; (int)i < tm->tm_mon; i++) {
908 julianday += daysinmonth[i];
910 julianday += tm->tm_mday;
911 tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
912 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
914 /* put all the numbers we want from the tm struct into
915 an easily printable buffer */
916 snprintf(buffer, sizeof(buffer),
917 "%02d " "%02d " "%02d " "%04d " "%02d",
918 tm->tm_hour, tm->tm_min, tm->tm_sec,
919 tm->tm_year+1900, tm->tm_mday);
921 /* convert spaces in the buffer to '\0' to make it possible to work
922 directly on the buffer */
923 for(i=0; i < sizeof(buffer); i++)
925 if(buffer[i] == ' ')
926 buffer[i] = '\0';
929 FOR_NB_SCREENS(s)
931 /* minimum lines needed is 2 + title line */
932 gui_textarea_update_nblines(&screens[s]);
933 if (screens[s].nb_lines < 4)
935 screens[s].setfont(FONT_SYSFIXED);
936 gui_textarea_update_nblines(&screens[s]);
939 /* recalculate the positions and offsets */
940 if (screens[s].nb_lines >= 3)
941 screens[s].getstringsize(title, NULL, &prev_line_height);
942 else
943 prev_line_height = 0;
944 screens[s].getstringsize(buffer, NULL, &line_height);
945 screens[s].getstringsize(SEPARATOR, &separator_width, NULL);
948 /* get width for each string except the last one and put them
949 in the cursor array */
950 for(i=0; i < 5; i++)
952 screens[s].getstringsize(ptr[i], &width, NULL);
953 cursor[i][INDEX_WIDTH] = width;
956 /* hour */
957 /* cursor[0][INDEX_X] is already 0 because of the memset */
958 cursor[0][INDEX_Y] = prev_line_height + statusbar_height;
960 /* minute */
961 cursor[1][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width;
962 cursor[1][INDEX_Y] = prev_line_height + statusbar_height;
964 /* second */
965 cursor[2][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width +
966 cursor[1][INDEX_WIDTH] + separator_width;
967 cursor[2][INDEX_Y] = prev_line_height + statusbar_height;
969 /* weekday */
970 screens[s].getstringsize(str(dayname[tm->tm_wday]), &weekday_width, NULL);
971 screens[s].getstringsize(" ", &separator_width, NULL);
973 /* year */
974 cursor[3][INDEX_X] = weekday_width + separator_width;
975 cursor[3][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
977 /* month */
978 cursor[4][INDEX_X] = weekday_width + 2 * separator_width +
979 cursor[3][INDEX_WIDTH];
980 cursor[4][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
982 /* day */
983 cursor[5][INDEX_X] = weekday_width + 3 * separator_width +
984 cursor[3][INDEX_WIDTH] +
985 cursor[4][INDEX_WIDTH];
986 cursor[5][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
988 /* draw the screen */
989 screens[s].set_drawmode(DRMODE_SOLID);
990 gui_textarea_clear(&screens[s]);
991 /* display the screen title */
992 screens[s].puts_scroll(0, 0, title);
994 /* these are not selectable, so we draw them outside the loop */
995 screens[s].putsxy(0, cursor[3][INDEX_Y], str(dayname[tm->tm_wday])); /* name of the week day */
996 screens[s].putsxy(cursor[1][INDEX_X] - separator_width,
997 cursor[0][INDEX_Y], SEPARATOR);
998 screens[s].putsxy(cursor[2][INDEX_X] - separator_width,
999 cursor[0][INDEX_Y], SEPARATOR);
1001 /* draw the selected item with drawmode set to
1002 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
1003 items with drawmode DRMODE_SOLID */
1004 for(i=0; i<6; i++)
1006 if (cursorpos == i)
1007 screens[s].set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1008 else
1009 screens[s].set_drawmode(DRMODE_SOLID);
1011 screens[s].putsxy(cursor[i][INDEX_X],
1012 cursor[i][INDEX_Y], ptr[i]);
1015 /* print help text */
1016 if (screens[s].nb_lines > 4)
1017 screens[s].puts(0, 4, str(LANG_TIME_SET));
1018 if (screens[s].nb_lines > 5)
1019 screens[s].puts(0, 5, str(LANG_TIME_REVERT));
1020 screens[s].update();
1022 gui_syncstatusbar_draw(&statusbars, true);
1024 /* calculate the minimum and maximum for the number under cursor */
1025 if(cursorpos!=lastcursorpos) {
1026 lastcursorpos=cursorpos;
1027 switch(cursorpos) {
1028 case 0: /* hour */
1029 min = 0;
1030 steps = 24;
1031 valptr = &tm->tm_hour;
1032 break;
1033 case 1: /* minute */
1034 min = 0;
1035 steps = 60;
1036 valptr = &tm->tm_min;
1037 break;
1038 case 2: /* second */
1039 min = 0;
1040 steps = 60;
1041 valptr = &tm->tm_sec;
1042 break;
1043 case 3: /* year */
1044 min = 1;
1045 steps = 200;
1046 valptr = &tm->tm_year;
1047 break;
1048 case 4: /* month */
1049 min = 0;
1050 steps = 12;
1051 valptr = &tm->tm_mon;
1052 break;
1053 case 5: /* day */
1054 min = 1;
1055 steps = daysinmonth[tm->tm_mon];
1056 valptr = &tm->tm_mday;
1057 break;
1059 say_time(cursorpos, tm);
1062 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
1063 switch ( button ) {
1064 case ACTION_STD_PREV:
1065 cursorpos = (cursorpos + 6 - 1) % 6;
1066 break;
1067 case ACTION_STD_NEXT:
1068 cursorpos = (cursorpos + 6 + 1) % 6;
1069 break;
1070 case ACTION_SETTINGS_INC:
1071 case ACTION_SETTINGS_INCREPEAT:
1072 *valptr = (*valptr + steps - min + 1) %
1073 steps + min;
1074 if(*valptr == 0)
1075 *valptr = min;
1076 say_time(cursorpos, tm);
1077 break;
1078 case ACTION_SETTINGS_DEC:
1079 case ACTION_SETTINGS_DECREPEAT:
1080 *valptr = (*valptr + steps - min - 1) %
1081 steps + min;
1082 if(*valptr == 0)
1083 *valptr = min;
1084 say_time(cursorpos, tm);
1085 break;
1087 case ACTION_STD_OK:
1088 done = true;
1089 break;
1091 case ACTION_STD_CANCEL:
1092 done = true;
1093 tm->tm_year = -1;
1094 break;
1096 default:
1097 if (default_event_handler(button) == SYS_USB_CONNECTED)
1098 return true;
1099 break;
1102 FOR_NB_SCREENS(i)
1104 screens[i].setfont(FONT_UI);
1105 gui_textarea_update_nblines(&screens[i]);
1107 return false;
1109 #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
1111 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
1112 bool shutdown_screen(void)
1114 int button;
1115 bool done = false;
1116 long time_entered = current_tick;
1118 lcd_stop_scroll();
1120 gui_syncsplash(0, str(LANG_CONFIRM_SHUTDOWN));
1122 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
1124 button = get_action(CONTEXT_STD,HZ);
1125 switch(button)
1127 case ACTION_STD_CANCEL:
1128 sys_poweroff();
1129 break;
1131 /* do nothing here, because ACTION_NONE might be caused
1132 * by timeout or button release. In case of timeout the loop
1133 * is terminated by TIME_BEFORE */
1134 case ACTION_NONE:
1135 break;
1137 default:
1138 if(default_event_handler(button) == SYS_USB_CONNECTED)
1139 return true;
1140 done = true;
1141 break;
1144 return false;
1146 #endif
1148 static const int id3_headers[]=
1150 LANG_ID3_TITLE,
1151 LANG_ID3_ARTIST,
1152 LANG_ID3_ALBUM,
1153 LANG_ID3_ALBUMARTIST,
1154 LANG_ID3_DISCNUM,
1155 LANG_ID3_TRACKNUM,
1156 LANG_ID3_COMMENT,
1157 LANG_ID3_GENRE,
1158 LANG_ID3_YEAR,
1159 LANG_ID3_LENGTH,
1160 LANG_ID3_PLAYLIST,
1161 LANG_ID3_BITRATE,
1162 LANG_ID3_FREQUENCY,
1163 #if CONFIG_CODEC == SWCODEC
1164 LANG_ID3_TRACK_GAIN,
1165 LANG_ID3_ALBUM_GAIN,
1166 #endif
1167 LANG_ID3_PATH,
1170 static char * id3_get_info(int selected_item, void* data, char *buffer)
1172 struct mp3entry* id3 =(struct mp3entry*)data;
1173 int info_no=selected_item/2;
1174 if(!(selected_item%2))
1175 {/* header */
1176 return( str(id3_headers[info_no]));
1178 else
1179 {/* data */
1181 char * info=NULL;
1182 switch(info_no)
1184 case 0:/*LANG_ID3_TITLE*/
1185 info=id3->title;
1186 break;
1187 case 1:/*LANG_ID3_ARTIST*/
1188 info=id3->artist;
1189 break;
1190 case 2:/*LANG_ID3_ALBUM*/
1191 info=id3->album;
1192 break;
1193 case 3:/*LANG_ID3_ALBUMARTIST*/
1194 info=id3->albumartist;
1195 break;
1196 case 4:/*LANG_ID3_DISCNUM*/
1197 if (id3->disc_string)
1198 info = id3->disc_string;
1199 else if (id3->discnum)
1201 snprintf(buffer, MAX_PATH, "%d", id3->discnum);
1202 info = buffer;
1204 break;
1205 case 5:/*LANG_ID3_TRACKNUM*/
1206 if (id3->track_string)
1207 info = id3->track_string;
1208 else if (id3->tracknum)
1210 snprintf(buffer, MAX_PATH, "%d", id3->tracknum);
1211 info = buffer;
1213 break;
1214 case 6:/*LANG_ID3_COMMENT*/
1215 info=id3->comment;
1216 break;
1217 case 7:/*LANG_ID3_GENRE*/
1218 info = id3->genre_string;
1219 break;
1220 case 8:/*LANG_ID3_YEAR*/
1221 if (id3->year_string)
1222 info = id3->year_string;
1223 else if (id3->year)
1225 snprintf(buffer, MAX_PATH, "%d", id3->year);
1226 info = buffer;
1228 break;
1229 case 9:/*LANG_ID3_LENGTH*/
1230 format_time(buffer, MAX_PATH, id3->length);
1231 info=buffer;
1232 break;
1233 case 10:/*LANG_ID3_PLAYLIST*/
1234 snprintf(buffer, MAX_PATH, "%d/%d", playlist_get_display_index(),
1235 playlist_amount());
1236 info=buffer;
1237 break;
1238 case 11:/*LANG_ID3_BITRATE*/
1239 snprintf(buffer, MAX_PATH, "%d kbps%s", id3->bitrate,
1240 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
1241 info=buffer;
1242 break;
1243 case 12:/*LANG_ID3_FREQUENCY*/
1244 snprintf(buffer, MAX_PATH, "%ld Hz", id3->frequency);
1245 info=buffer;
1246 break;
1247 #if CONFIG_CODEC == SWCODEC
1248 case 13:/*LANG_ID3_TRACK_GAIN*/
1249 info=id3->track_gain_string;
1250 break;
1251 case 14:/*LANG_ID3_ALBUM_GAIN*/
1252 info=id3->album_gain_string;
1253 break;
1254 case 15:/*LANG_ID3_PATH*/
1255 #else
1256 case 13:/*LANG_ID3_PATH*/
1257 #endif
1258 info=id3->path;
1259 break;
1261 return info && *info ? info : (char*) str(LANG_ID3_NO_INFO);
1265 bool browse_id3(void)
1267 struct gui_synclist id3_lists;
1268 struct mp3entry* id3 = audio_current_track();
1269 int key;
1271 gui_synclist_init(&id3_lists, &id3_get_info, id3, true, 2);
1272 gui_synclist_set_nb_items(&id3_lists,
1273 sizeof(id3_headers)/sizeof(id3_headers[0])*2);
1274 gui_synclist_draw(&id3_lists);
1275 gui_syncstatusbar_draw(&statusbars, true);
1276 while (true) {
1277 gui_syncstatusbar_draw(&statusbars, false);
1278 key = get_action(CONTEXT_LIST,HZ/2);
1279 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
1280 && !gui_synclist_do_button(&id3_lists, key,LIST_WRAP_UNLESS_HELD))
1282 return(default_event_handler(key) == SYS_USB_CONNECTED);
1287 static char* runtime_get_data(int selected_item, void* data, char* buffer)
1289 (void) data;
1290 unsigned char *headers[] = {str(LANG_RUNNING_TIME), str(LANG_TOP_TIME) };
1291 int t;
1292 if(!(selected_item%2))
1293 return headers[selected_item/2];
1295 if(selected_item/2) t = global_status.topruntime;
1296 else t = global_status.runtime;
1298 snprintf(buffer, 16, "%dh %dm %ds",
1299 t / 3600, (t % 3600) / 60, t % 60);
1300 return buffer;
1305 bool view_runtime(void)
1307 unsigned char *lines[]={str(LANG_CLEAR_TIME)};
1308 struct text_message message={(char **)lines, 1};
1310 struct gui_synclist lists;
1311 int action;
1312 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2);
1313 #if !defined(HAVE_LCD_CHARCELLS)
1314 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
1315 #else
1316 gui_synclist_set_title(&lists, NULL, NOICON);
1317 #endif
1318 gui_synclist_set_icon_callback(&lists, NULL);
1319 gui_synclist_set_nb_items(&lists, 4);
1320 while(1)
1322 #if CONFIG_CHARGING
1323 if (charger_inserted()
1324 #ifdef HAVE_USB_POWER
1325 || usb_powered()
1326 #endif
1329 global_status.runtime = 0;
1331 else
1332 #endif
1334 global_status.runtime += ((current_tick - lasttime) / HZ);
1336 lasttime = current_tick;
1337 gui_synclist_draw(&lists);
1338 gui_syncstatusbar_draw(&statusbars, true);
1339 action = get_action(CONTEXT_STD, HZ);
1340 gui_synclist_do_button(&lists, action, LIST_WRAP_UNLESS_HELD);
1341 if(action == ACTION_STD_CANCEL)
1342 break;
1343 if(action == ACTION_STD_OK) {
1344 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
1346 if (!(gui_synclist_get_sel_pos(&lists)/2))
1347 global_status.runtime = 0;
1348 else
1349 global_status.topruntime = 0;
1352 if(default_event_handler(action) == SYS_USB_CONNECTED)
1353 return true;
1355 return false;