1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002-2007 Björn Stenberg
11 * Copyright (C) 2007-2008 Nicolas Pennequin
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
24 #include "string-extra.h"
29 #include "settings_list.h"
30 #include "rbunicode.h"
31 #include "timefuncs.h"
34 #include "powermgmt.h"
38 #ifdef HAVE_LCD_CHARCELLS
45 #ifdef HAVE_LCD_BITMAP
51 #if CONFIG_CODEC == SWCODEC
58 #include "wps_internals.h"
59 #include "skin_engine.h"
60 #include "statusbar-skinned.h"
61 #include "root_menu.h"
63 #include "recording.h"
64 #include "pcm_record.h"
73 #define NOINLINE __attribute__ ((noinline))
75 extern struct wps_state wps_state
;
77 static const char* get_codectype(const struct mp3entry
* id3
)
79 if (id3
&& id3
->codectype
< AFMT_NUM_CODECS
) {
80 return audio_formats
[id3
->codectype
].label
;
86 /* Extract a part from a path.
88 * buf - buffer extract part to.
89 * buf_size - size of buffer.
90 * path - path to extract from.
91 * level - what to extract. 0 is file name, 1 is parent of file, 2 is
92 * parent of parent, etc.
94 * Returns buf if the desired level was found, NULL otherwise.
96 char* get_dir(char* buf
, int buf_size
, const char* path
, int level
)
102 sep
= path
+ strlen(path
);
117 if (level
|| (last_sep
<= sep
))
120 len
= MIN(last_sep
- sep
, buf_size
- 1);
121 strlcpy(buf
, sep
+ 1, len
+ 1);
125 #if (CONFIG_CODEC != MAS3507D) && defined (HAVE_PITCHSCREEN)
126 /* A helper to determine the enum value for pitch/speed.
128 When there are two choices (i.e. boolean), return 1 if the value is
129 different from normal value and 2 if the value is the same as the
130 normal value. E.g. "%?Sp<%Sp>" would show the pitch only when
131 playing at a modified pitch.
133 When there are more than two choices (i.e. enum), the left half of
134 the choices are to show 0..normal range, and the right half of the
135 choices are to show values over that. The last entry is used when
136 it is set to the normal setting, following the rockbox convention
137 to use the last entry for special values.
141 2 items: %?Sp<0..99 or 101..infinity|100>
142 3 items: %?Sp<0..99|101..infinity|100>
143 4 items: %?Sp<0..49|50..99|101..infinity|100>
144 5 items: %?Sp<0..49|50..99|101..149|150..infinity|100>
145 6 items: %?Sp<0..33|34..66|67..99|101..133|134..infinity|100>
146 7 items: %?Sp<0..33|34..66|67..99|101..133|134..167|167..infinity|100>
148 static int pitch_speed_enum(int range
, int32_t val
, int32_t normval
)
154 return (val
== normval
) + 1;
158 n
= (center
* val
) / normval
+ 1;
159 return (range
<= n
) ? (range
- 1) : n
;
163 const char *get_cuesheetid3_token(struct wps_token
*token
, struct mp3entry
*id3
,
164 int offset_tracks
, char *buf
, int buf_size
)
166 struct cuesheet
*cue
= id3
?id3
->cuesheet
:NULL
;
167 if (!cue
|| !cue
->curr_track
)
170 struct cue_track_info
*track
= cue
->curr_track
;
173 if (cue
->curr_track_idx
+offset_tracks
< cue
->track_count
)
174 track
+=offset_tracks
;
180 case SKIN_TOKEN_METADATA_ARTIST
:
181 return *track
->performer
? track
->performer
: NULL
;
182 case SKIN_TOKEN_METADATA_COMPOSER
:
183 return *track
->songwriter
? track
->songwriter
: NULL
;
184 case SKIN_TOKEN_METADATA_ALBUM
:
185 return *cue
->title
? cue
->title
: NULL
;
186 case SKIN_TOKEN_METADATA_ALBUM_ARTIST
:
187 return *cue
->performer
? cue
->performer
: NULL
;
188 case SKIN_TOKEN_METADATA_TRACK_TITLE
:
189 return *track
->title
? track
->title
: NULL
;
190 case SKIN_TOKEN_METADATA_TRACK_NUMBER
:
191 snprintf(buf
, buf_size
, "%d/%d",
192 cue
->curr_track_idx
+offset_tracks
+1, cue
->track_count
);
200 static const char* get_filename_token(struct wps_token
*token
, char* filename
,
201 char *buf
, int buf_size
)
207 case SKIN_TOKEN_FILE_PATH
:
209 case SKIN_TOKEN_FILE_NAME
:
210 if (get_dir(buf
, buf_size
, filename
, 0)) {
211 /* Remove extension */
212 char* sep
= strrchr(buf
, '.');
219 case SKIN_TOKEN_FILE_NAME_WITH_EXTENSION
:
220 return get_dir(buf
, buf_size
, filename
, 0);
221 case SKIN_TOKEN_FILE_DIRECTORY
:
222 return get_dir(buf
, buf_size
, filename
, token
->value
.i
);
230 /* All tokens which only need the info to return a value go in here */
231 const char *get_id3_token(struct wps_token
*token
, struct mp3entry
*id3
,
232 char *filename
, char *buf
, int buf_size
, int limit
, int *intval
)
234 struct wps_state
*state
= &wps_state
;
237 unsigned long length
= id3
->length
;
238 unsigned long elapsed
= id3
->elapsed
+ state
->ff_rewind_count
;
241 case SKIN_TOKEN_METADATA_ARTIST
:
243 case SKIN_TOKEN_METADATA_COMPOSER
:
244 return id3
->composer
;
245 case SKIN_TOKEN_METADATA_ALBUM
:
247 case SKIN_TOKEN_METADATA_ALBUM_ARTIST
:
248 return id3
->albumartist
;
249 case SKIN_TOKEN_METADATA_GROUPING
:
250 return id3
->grouping
;
251 case SKIN_TOKEN_METADATA_GENRE
:
252 return id3
->genre_string
;
253 case SKIN_TOKEN_METADATA_DISC_NUMBER
:
254 if (id3
->disc_string
)
255 return id3
->disc_string
;
257 snprintf(buf
, buf_size
, "%d", id3
->discnum
);
261 case SKIN_TOKEN_METADATA_TRACK_NUMBER
:
262 if (id3
->track_string
)
263 return id3
->track_string
;
265 snprintf(buf
, buf_size
, "%d", id3
->tracknum
);
269 case SKIN_TOKEN_METADATA_TRACK_TITLE
:
271 case SKIN_TOKEN_METADATA_VERSION
:
272 switch (id3
->id3version
)
288 case SKIN_TOKEN_METADATA_YEAR
:
289 if( id3
->year_string
)
290 return id3
->year_string
;
292 snprintf(buf
, buf_size
, "%d", id3
->year
);
296 case SKIN_TOKEN_METADATA_COMMENT
:
298 case SKIN_TOKEN_FILE_BITRATE
:
300 snprintf(buf
, buf_size
, "%d", id3
->bitrate
);
304 case SKIN_TOKEN_TRACK_TIME_ELAPSED
:
305 format_time(buf
, buf_size
, elapsed
);
308 case SKIN_TOKEN_TRACK_TIME_REMAINING
:
309 format_time(buf
, buf_size
, length
- elapsed
);
312 case SKIN_TOKEN_TRACK_LENGTH
:
313 format_time(buf
, buf_size
, length
);
316 case SKIN_TOKEN_TRACK_ELAPSED_PERCENT
:
322 if (limit
== TOKEN_VALUE_ONLY
)
323 limit
= 100; /* make it a percentage */
324 *intval
= limit
* elapsed
/ length
+ 1;
326 snprintf(buf
, buf_size
, "%lu", 100 * elapsed
/ length
);
329 case SKIN_TOKEN_TRACK_STARTING
:
331 unsigned long time
= token
->value
.i
* (HZ
/TIMEOUT_UNIT
);
336 case SKIN_TOKEN_TRACK_ENDING
:
338 unsigned long time
= token
->value
.i
* (HZ
/TIMEOUT_UNIT
);
339 if (length
- elapsed
< time
)
344 case SKIN_TOKEN_FILE_CODEC
:
347 if(id3
->codectype
== AFMT_UNKNOWN
)
348 *intval
= AFMT_NUM_CODECS
;
350 *intval
= id3
->codectype
;
352 return get_codectype(id3
);
354 case SKIN_TOKEN_FILE_FREQUENCY
:
355 snprintf(buf
, buf_size
, "%ld", id3
->frequency
);
357 case SKIN_TOKEN_FILE_FREQUENCY_KHZ
:
358 /* ignore remainders < 100, so 22050 Hz becomes just 22k */
359 if ((id3
->frequency
% 1000) < 100)
360 snprintf(buf
, buf_size
, "%ld", id3
->frequency
/ 1000);
362 snprintf(buf
, buf_size
, "%ld.%lu",
363 id3
->frequency
/ 1000,
364 (id3
->frequency
% 1000) / 100);
366 case SKIN_TOKEN_FILE_VBR
:
367 return (id3
->vbr
) ? "(avg)" : NULL
;
368 case SKIN_TOKEN_FILE_SIZE
:
369 snprintf(buf
, buf_size
, "%ld", id3
->filesize
/ 1024);
373 case SKIN_TOKEN_DATABASE_PLAYCOUNT
:
375 *intval
= id3
->playcount
+ 1;
376 snprintf(buf
, buf_size
, "%ld", id3
->playcount
);
378 case SKIN_TOKEN_DATABASE_RATING
:
380 *intval
= id3
->rating
+ 1;
381 snprintf(buf
, buf_size
, "%d", id3
->rating
);
383 case SKIN_TOKEN_DATABASE_AUTOSCORE
:
385 *intval
= id3
->score
+ 1;
386 snprintf(buf
, buf_size
, "%d", id3
->score
);
391 return get_filename_token(token
, id3
->path
, buf
, buf_size
);
394 else /* id3 == NULL, handle the error based on the expected return type */
398 /* Most tokens expect NULL on error so leave that for the default case,
399 * The ones that expect "0" need to be handled */
400 case SKIN_TOKEN_FILE_FREQUENCY
:
401 case SKIN_TOKEN_FILE_FREQUENCY_KHZ
:
402 case SKIN_TOKEN_FILE_SIZE
:
404 case SKIN_TOKEN_DATABASE_PLAYCOUNT
:
405 case SKIN_TOKEN_DATABASE_RATING
:
406 case SKIN_TOKEN_DATABASE_AUTOSCORE
:
412 return get_filename_token(token
, filename
, buf
, buf_size
);
420 /* Formats the frequency (specified in Hz) in MHz, */
421 /* with one or two digits after the decimal point -- */
422 /* depending on the frequency changing step. */
424 static char *format_freq_MHz(int freq
, int freq_step
, char *buf
, int buf_size
)
428 if (freq_step
< 100000)
430 /* Format with two digits after decimal point */
436 /* Format with one digit after decimal point */
440 div
= 1000000 / scale
;
442 snprintf(buf
, buf_size
, fmt
, freq
/div
, freq
%div
);
447 /* Tokens which are really only used by the radio screen go in here */
448 const char *get_radio_token(struct wps_token
*token
, int preset_offset
,
449 char *buf
, int buf_size
, int limit
, int *intval
)
451 const struct fm_region_data
*region_data
=
452 &(fm_region_data
[global_settings
.fm_region
]);
456 /* Radio/tuner tokens */
457 case SKIN_TOKEN_TUNER_TUNED
:
458 if (tuner_get(RADIO_TUNED
))
461 case SKIN_TOKEN_TUNER_SCANMODE
:
462 if (radio_scan_mode())
465 case SKIN_TOKEN_TUNER_STEREO
:
466 if (radio_is_stereo())
469 case SKIN_TOKEN_TUNER_MINFREQ
: /* changes based on "region" */
470 return format_freq_MHz(region_data
->freq_min
,
471 region_data
->freq_step
, buf
, buf_size
);
472 case SKIN_TOKEN_TUNER_MAXFREQ
: /* changes based on "region" */
473 return format_freq_MHz(region_data
->freq_max
,
474 region_data
->freq_step
, buf
, buf_size
);
475 case SKIN_TOKEN_TUNER_CURFREQ
:
476 return format_freq_MHz(radio_current_frequency(),
477 region_data
->freq_step
, buf
, buf_size
);
478 #ifdef HAVE_RADIO_RSSI
479 case SKIN_TOKEN_TUNER_RSSI
:
480 snprintf(buf
, buf_size
, "%d",tuner_get(RADIO_RSSI
));
482 case SKIN_TOKEN_TUNER_RSSI_MIN
:
483 snprintf(buf
, buf_size
, "%d",tuner_get(RADIO_RSSI_MIN
));
485 case SKIN_TOKEN_TUNER_RSSI_MAX
:
486 snprintf(buf
, buf_size
, "%d",tuner_get(RADIO_RSSI_MAX
));
489 case SKIN_TOKEN_PRESET_NAME
:
490 case SKIN_TOKEN_PRESET_FREQ
:
491 case SKIN_TOKEN_PRESET_ID
:
493 int preset_count
= radio_preset_count();
494 int cur_preset
= radio_current_preset();
495 if (preset_count
== 0 || cur_preset
< 0)
497 int preset
= cur_preset
+ preset_offset
;
498 /* make sure it's in the valid range */
499 preset
%= preset_count
;
501 preset
+= preset_count
;
502 if (token
->type
== SKIN_TOKEN_PRESET_NAME
)
503 snprintf(buf
, buf_size
, "%s", radio_get_preset(preset
)->name
);
504 else if (token
->type
== SKIN_TOKEN_PRESET_FREQ
)
505 format_freq_MHz(radio_get_preset(preset
)->frequency
,
506 region_data
->freq_step
, buf
, buf_size
);
508 snprintf(buf
, buf_size
, "%d", preset
+ 1);
511 case SKIN_TOKEN_PRESET_COUNT
:
512 snprintf(buf
, buf_size
, "%d", radio_preset_count());
514 *intval
= radio_preset_count();
516 case SKIN_TOKEN_HAVE_RDS
:
519 case SKIN_TOKEN_RDS_NAME
:
520 return tuner_get_rds_info(RADIO_RDS_NAME
);
521 case SKIN_TOKEN_RDS_TEXT
:
522 return tuner_get_rds_info(RADIO_RDS_TEXT
);
524 return NULL
; /* end of the SKIN_TOKEN_HAVE_RDS case */
525 #endif /* HAVE_RDS_CAP */
533 static struct mp3entry
* get_mp3entry_from_offset(int offset
, char **filename
)
535 struct mp3entry
* pid3
= NULL
;
536 struct wps_state
*state
= skin_get_global_state();
537 struct cuesheet
*cue
= state
->id3
? state
->id3
->cuesheet
: NULL
;
538 const char *fname
= NULL
;
539 if (cue
&& cue
->curr_track_idx
+ offset
< cue
->track_count
)
541 else if (offset
== 0)
543 else if (offset
== 1)
547 static char filename_buf
[MAX_PATH
+ 1];
548 fname
= playlist_peek(offset
, filename_buf
, sizeof(filename_buf
));
549 *filename
= (char*)fname
;
550 #if CONFIG_CODEC == SWCODEC
551 #if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
552 static struct mp3entry tempid3
;
553 if (tagcache_fill_tags(&tempid3
, fname
))
560 if (!audio_peek_track(&pid3
, offset
))
568 #ifdef HAVE_LCD_CHARCELLS
569 static void format_player_progress(struct gui_wps
*gwps
)
571 struct wps_state
*state
= skin_get_global_state();
572 struct screen
*display
= gwps
->display
;
573 unsigned char progress_pattern
[7];
578 if (LIKELY(state
->id3
))
580 elapsed
= state
->id3
->elapsed
;
581 length
= state
->id3
->length
;
590 pos
= 36 * (elapsed
+ state
->ff_rewind_count
) / length
;
592 for (i
= 0; i
< 7; i
++, pos
-= 5)
595 progress_pattern
[i
] = 0x1fu
;
597 progress_pattern
[i
] = 0x00u
;
599 progress_pattern
[i
] = 0x1fu
>> pos
;
602 display
->define_pattern(gwps
->data
->wps_progress_pat
[0], progress_pattern
);
605 static void format_player_fullbar(struct gui_wps
*gwps
, char* buf
, int buf_size
)
607 static const unsigned char numbers
[10][4] = {
608 {0x0e, 0x0a, 0x0a, 0x0e}, /* 0 */
609 {0x04, 0x0c, 0x04, 0x04}, /* 1 */
610 {0x0e, 0x02, 0x04, 0x0e}, /* 2 */
611 {0x0e, 0x02, 0x06, 0x0e}, /* 3 */
612 {0x08, 0x0c, 0x0e, 0x04}, /* 4 */
613 {0x0e, 0x0c, 0x02, 0x0c}, /* 5 */
614 {0x0e, 0x08, 0x0e, 0x0e}, /* 6 */
615 {0x0e, 0x02, 0x04, 0x08}, /* 7 */
616 {0x0e, 0x0e, 0x0a, 0x0e}, /* 8 */
617 {0x0e, 0x0e, 0x02, 0x0e} /* 9 */
620 struct wps_state
*state
= skin_get_global_state();
621 struct screen
*display
= gwps
->display
;
622 struct wps_data
*data
= gwps
->data
;
623 unsigned char progress_pattern
[7];
633 if (LIKELY(state
->id3
))
635 elapsed
= state
->id3
->elapsed
;
636 length
= state
->id3
->length
;
644 if (buf_size
< 34) /* worst case: 11x UTF-8 char + \0 */
647 time
= elapsed
+ state
->ff_rewind_count
;
649 pos
= 55 * time
/ length
;
651 memset(timestr
, 0, sizeof(timestr
));
652 format_time(timestr
, sizeof(timestr
)-2, time
);
653 timestr
[strlen(timestr
)] = ':'; /* always safe */
655 for (i
= 0; i
< 11; i
++, pos
-= 5)
658 memset(progress_pattern
, 0, sizeof(progress_pattern
));
660 if ((digit
= timestr
[time_idx
]))
665 if (timestr
[time_idx
+ 1] == ':') /* ones, left aligned */
667 memcpy(progress_pattern
, numbers
[digit
], 4);
670 else /* tens, shifted right */
672 for (j
= 0; j
< 4; j
++)
673 progress_pattern
[j
] = numbers
[digit
][j
] >> 1;
675 if (time_idx
> 0) /* not the first group, add colon in front */
677 progress_pattern
[1] |= 0x10u
;
678 progress_pattern
[3] |= 0x10u
;
684 progress_pattern
[5] = progress_pattern
[6] = 0x1fu
;
687 if (pos
> 0 && pos
< 5)
690 progress_pattern
[5] = progress_pattern
[6] = (~0x1fu
>> pos
) & 0x1fu
;
693 if (softchar
&& pat_idx
< 8)
695 display
->define_pattern(data
->wps_progress_pat
[pat_idx
],
697 buf
= utf8encode(data
->wps_progress_pat
[pat_idx
], buf
);
701 buf
= utf8encode(' ', buf
);
703 buf
= utf8encode(0xe115, buf
); /* 2/7 _ */
708 #endif /* HAVE_LCD_CHARCELLS */
710 /* Don't inline this; it was broken out of get_token_value to reduce stack
713 static const char* NOINLINE
get_lif_token_value(struct gui_wps
*gwps
,
714 struct logical_if
*lif
,
715 int offset
, char *buf
,
718 int a
= lif
->num_options
;
720 const char* out_text
= get_token_value(gwps
, lif
->token
, offset
,
722 if (a
== -1 && lif
->token
->type
!= SKIN_TOKEN_VOLUME
)
723 a
= (out_text
&& *out_text
) ? 1 : 0;
724 switch (lif
->operand
.type
)
727 if (lif
->op
== IF_EQUALS
)
728 return strcmp(out_text
, lif
->operand
.data
.text
) == 0 ?
735 b
= lif
->operand
.data
.number
;
739 char temp_buf
[MAX_PATH
];
741 struct wps_token
*token
= lif
->operand
.data
.code
->data
;
742 b
= lif
->num_options
;
743 outb
= get_token_value(gwps
, token
, offset
, temp_buf
,
744 sizeof(temp_buf
), &b
);
745 if (b
== -1 && lif
->token
->type
!= SKIN_TOKEN_VOLUME
)
747 if (!out_text
|| !outb
)
748 return (lif
->op
== IF_EQUALS
) ? NULL
: "neq";
749 bool equal
= strcmp(out_text
, outb
) == 0;
750 if (lif
->op
== IF_EQUALS
)
751 return equal
? "eq" : NULL
;
752 else if (lif
->op
== IF_NOTEQUALS
)
753 return !equal
? "neq" : NULL
;
755 b
= (outb
&& *outb
) ? 1 : 0;
766 return a
== b
? "eq" : NULL
;
768 return a
!= b
? "neq" : NULL
;
770 return a
< b
? "lt" : NULL
;
772 return a
<= b
? "lte" : NULL
;
774 return a
> b
? "gt" : NULL
;
775 case IF_GREATERTHAN_EQ
:
776 return a
>= b
? "gte" : NULL
;
781 /* Return the tags value as text. buf should be used as temp storage if needed.
783 intval is used with conditionals/enums: when this function is called,
784 intval should contain the number of options in the conditional/enum.
785 When this function returns, intval is -1 if the tag is non numeric or,
786 if the tag is numeric, *intval is the enum case we want to go to (between 1
787 and the original value of *intval, inclusive).
788 When not treating a conditional/enum, intval should be NULL.
790 const char *get_token_value(struct gui_wps
*gwps
,
791 struct wps_token
*token
, int offset
,
792 char *buf
, int buf_size
,
798 struct wps_data
*data
= gwps
->data
;
799 struct wps_state
*state
= skin_get_global_state();
800 struct mp3entry
*id3
; /* Think very carefully about using this.
801 maybe get_id3_token() is the better place? */
802 const char *out_text
= NULL
;
803 char *filename
= NULL
;
808 id3
= get_mp3entry_from_offset(token
->next
? 1: offset
, &filename
);
810 filename
= id3
->path
;
813 struct tm
* tm
= NULL
;
815 /* if the token is an RTC one, update the time
816 and do the necessary checks */
817 if (token
->type
>= SKIN_TOKENS_RTC_BEGIN
818 && token
->type
<= SKIN_TOKENS_RTC_END
)
834 if (id3
&& id3
== state
->id3
&& id3
->cuesheet
)
836 out_text
= get_cuesheetid3_token(token
, id3
,
837 token
->next
?1:offset
, buf
, buf_size
);
841 out_text
= get_id3_token(token
, id3
, filename
, buf
, buf_size
, limit
, intval
);
845 out_text
= get_radio_token(token
, offset
, buf
, buf_size
, limit
, intval
);
852 case SKIN_TOKEN_LOGICAL_IF
:
854 struct logical_if
*lif
= token
->value
.data
;
855 return get_lif_token_value(gwps
, lif
, offset
, buf
, buf_size
);
859 case SKIN_TOKEN_CHARACTER
:
860 if (token
->value
.c
== '\n')
862 return &(token
->value
.c
);
864 case SKIN_TOKEN_STRING
:
865 return (char*)token
->value
.data
;
867 case SKIN_TOKEN_TRANSLATEDSTRING
:
868 return (char*)P2STR(ID2P(token
->value
.i
));
870 case SKIN_TOKEN_PLAYLIST_ENTRIES
:
871 snprintf(buf
, buf_size
, "%d", playlist_amount());
873 *intval
= playlist_amount();
875 #ifdef HAVE_LCD_BITMAP
876 case SKIN_TOKEN_LIST_TITLE_TEXT
:
877 return sb_get_title(gwps
->display
->screen_type
);
878 case SKIN_TOKEN_LIST_TITLE_ICON
:
880 *intval
= sb_get_icon(gwps
->display
->screen_type
);
881 snprintf(buf
, buf_size
, "%d",sb_get_icon(gwps
->display
->screen_type
));
884 case SKIN_TOKEN_PLAYLIST_NAME
:
885 return playlist_name(NULL
, buf
, buf_size
);
887 case SKIN_TOKEN_PLAYLIST_POSITION
:
888 snprintf(buf
, buf_size
, "%d", playlist_get_display_index()+offset
);
890 *intval
= playlist_get_display_index()+offset
;
893 case SKIN_TOKEN_PLAYLIST_SHUFFLE
:
894 if ( global_settings
.playlist_shuffle
)
900 case SKIN_TOKEN_VOLUME
:
901 snprintf(buf
, buf_size
, "%d", global_settings
.volume
);
904 int minvol
= sound_min(SOUND_VOLUME
);
905 if (limit
== TOKEN_VALUE_ONLY
)
907 *intval
= global_settings
.volume
;
909 else if (global_settings
.volume
== minvol
)
913 else if (global_settings
.volume
== 0)
917 else if (global_settings
.volume
> 0)
923 *intval
= (limit
-3) * (global_settings
.volume
- minvol
- 1)
929 case SKIN_TOKEN_ALBUMART_FOUND
:
933 handle
= playback_current_aa_hid(data
->playback_aa_slot
);
935 if (in_radio_screen() || (get_radio_status() != FMRADIO_OFF
))
937 struct dim dim
= {data
->albumart
->width
, data
->albumart
->height
};
938 handle
= radio_get_art_hid(&dim
);
947 case SKIN_TOKEN_BATTERY_PERCENT
:
949 int l
= battery_level();
953 if (limit
== TOKEN_VALUE_ONLY
)
959 limit
= MAX(limit
, 3);
961 /* First enum is used for "unknown level",
962 * last enum is used for 100%.
964 *intval
= (limit
- 2) * l
/ 100 + 2;
972 snprintf(buf
, buf_size
, "%d", l
);
979 case SKIN_TOKEN_BATTERY_VOLTS
:
981 unsigned int v
= battery_voltage();
982 snprintf(buf
, buf_size
, "%d.%02d", v
/ 1000, (v
% 1000) / 10);
986 case SKIN_TOKEN_BATTERY_TIME
:
988 int t
= battery_time();
990 snprintf(buf
, buf_size
, "%dh %dm", t
/ 60, t
% 60);
997 case SKIN_TOKEN_BATTERY_CHARGER_CONNECTED
:
999 if(charger_input_state
==CHARGER
)
1005 #if CONFIG_CHARGING >= CHARGING_MONITOR
1006 case SKIN_TOKEN_BATTERY_CHARGING
:
1008 if (charge_state
== CHARGING
|| charge_state
== TOPOFF
) {
1015 #ifdef HAVE_USB_POWER
1016 case SKIN_TOKEN_USB_POWERED
:
1021 case SKIN_TOKEN_BATTERY_SLEEPTIME
:
1023 if (get_sleep_timer() == 0)
1027 format_time(buf
, buf_size
, get_sleep_timer() * 1000);
1032 case SKIN_TOKEN_PLAYBACK_STATUS
:
1034 int status
= current_playmode();
1036 int mode
= 1; /* stop */
1037 if (status
== STATUS_PLAY
)
1038 mode
= 2; /* play */
1039 if (state
->is_fading
||
1040 (status
== STATUS_PAUSE
&& !status_get_ffmode()))
1041 mode
= 3; /* pause */
1044 if (status_get_ffmode() == STATUS_FASTFORWARD
)
1046 if (status_get_ffmode() == STATUS_FASTBACKWARD
)
1049 #ifdef HAVE_RECORDING
1051 if (status
== STATUS_RECORD
)
1053 else if (status
== STATUS_RECORD_PAUSE
)
1058 if (status
== STATUS_RADIO
)
1060 else if (status
== STATUS_RADIO_PAUSE
)
1068 snprintf(buf
, buf_size
, "%d", mode
-1);
1072 case SKIN_TOKEN_REPEAT_MODE
:
1074 *intval
= global_settings
.repeat_mode
+ 1;
1075 snprintf(buf
, buf_size
, "%d", global_settings
.repeat_mode
);
1078 case SKIN_TOKEN_RTC_PRESENT
:
1086 case SKIN_TOKEN_RTC_12HOUR_CFG
:
1088 *intval
= global_settings
.timeformat
+ 1;
1089 snprintf(buf
, buf_size
, "%d", global_settings
.timeformat
);
1092 case SKIN_TOKEN_RTC_DAY_OF_MONTH
:
1093 /* d: day of month (01..31) */
1094 snprintf(buf
, buf_size
, "%02d", tm
->tm_mday
);
1096 *intval
= tm
->tm_mday
- 1;
1099 case SKIN_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED
:
1100 /* e: day of month, blank padded ( 1..31) */
1101 snprintf(buf
, buf_size
, "%2d", tm
->tm_mday
);
1103 *intval
= tm
->tm_mday
- 1;
1106 case SKIN_TOKEN_RTC_HOUR_24_ZERO_PADDED
:
1107 /* H: hour (00..23) */
1108 snprintf(buf
, buf_size
, "%02d", tm
->tm_hour
);
1110 *intval
= tm
->tm_hour
;
1113 case SKIN_TOKEN_RTC_HOUR_24
:
1114 /* k: hour ( 0..23) */
1115 snprintf(buf
, buf_size
, "%2d", tm
->tm_hour
);
1117 *intval
= tm
->tm_hour
;
1120 case SKIN_TOKEN_RTC_HOUR_12_ZERO_PADDED
:
1121 /* I: hour (01..12) */
1122 snprintf(buf
, buf_size
, "%02d",
1123 (tm
->tm_hour
% 12 == 0) ? 12 : tm
->tm_hour
% 12);
1125 *intval
= (tm
->tm_hour
% 12 == 0) ? 12 : tm
->tm_hour
% 12;
1128 case SKIN_TOKEN_RTC_HOUR_12
:
1129 /* l: hour ( 1..12) */
1130 snprintf(buf
, buf_size
, "%2d",
1131 (tm
->tm_hour
% 12 == 0) ? 12 : tm
->tm_hour
% 12);
1133 *intval
= (tm
->tm_hour
% 12 == 0) ? 12 : tm
->tm_hour
% 12;
1136 case SKIN_TOKEN_RTC_MONTH
:
1137 /* m: month (01..12) */
1139 *intval
= tm
->tm_mon
+ 1;
1140 snprintf(buf
, buf_size
, "%02d", tm
->tm_mon
+ 1);
1143 case SKIN_TOKEN_RTC_MINUTE
:
1144 /* M: minute (00..59) */
1145 snprintf(buf
, buf_size
, "%02d", tm
->tm_min
);
1147 *intval
= tm
->tm_min
;
1150 case SKIN_TOKEN_RTC_SECOND
:
1151 /* S: second (00..59) */
1152 snprintf(buf
, buf_size
, "%02d", tm
->tm_sec
);
1154 *intval
= tm
->tm_sec
;
1157 case SKIN_TOKEN_RTC_YEAR_2_DIGITS
:
1158 /* y: last two digits of year (00..99) */
1159 snprintf(buf
, buf_size
, "%02d", tm
->tm_year
% 100);
1161 *intval
= tm
->tm_year
% 100;
1164 case SKIN_TOKEN_RTC_YEAR_4_DIGITS
:
1165 /* Y: year (1970...) */
1166 snprintf(buf
, buf_size
, "%04d", tm
->tm_year
+ 1900);
1168 *intval
= tm
->tm_year
+ 1900;
1171 case SKIN_TOKEN_RTC_AM_PM_UPPER
:
1172 /* p: upper case AM or PM indicator */
1174 *intval
= tm
->tm_hour
/12 == 0 ? 0 : 1;
1175 return tm
->tm_hour
/12 == 0 ? "AM" : "PM";
1177 case SKIN_TOKEN_RTC_AM_PM_LOWER
:
1178 /* P: lower case am or pm indicator */
1180 *intval
= tm
->tm_hour
/12 == 0 ? 0 : 1;
1181 return tm
->tm_hour
/12 == 0 ? "am" : "pm";
1183 case SKIN_TOKEN_RTC_WEEKDAY_NAME
:
1184 /* a: abbreviated weekday name (Sun..Sat) */
1185 return str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
);
1187 case SKIN_TOKEN_RTC_MONTH_NAME
:
1188 /* b: abbreviated month name (Jan..Dec) */
1189 return str(LANG_MONTH_JANUARY
+ tm
->tm_mon
);
1191 case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_MON
:
1192 /* u: day of week (1..7); 1 is Monday */
1194 *intval
= (tm
->tm_wday
== 0) ? 7 : tm
->tm_wday
;
1195 snprintf(buf
, buf_size
, "%1d", tm
->tm_wday
+ 1);
1198 case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_SUN
:
1199 /* w: day of week (0..6); 0 is Sunday */
1201 *intval
= tm
->tm_wday
+ 1;
1202 snprintf(buf
, buf_size
, "%1d", tm
->tm_wday
);
1205 case SKIN_TOKEN_RTC_DAY_OF_MONTH
:
1206 case SKIN_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED
:
1207 case SKIN_TOKEN_RTC_HOUR_24_ZERO_PADDED
:
1208 case SKIN_TOKEN_RTC_HOUR_24
:
1209 case SKIN_TOKEN_RTC_HOUR_12_ZERO_PADDED
:
1210 case SKIN_TOKEN_RTC_HOUR_12
:
1211 case SKIN_TOKEN_RTC_MONTH
:
1212 case SKIN_TOKEN_RTC_MINUTE
:
1213 case SKIN_TOKEN_RTC_SECOND
:
1214 case SKIN_TOKEN_RTC_AM_PM_UPPER
:
1215 case SKIN_TOKEN_RTC_AM_PM_LOWER
:
1216 case SKIN_TOKEN_RTC_YEAR_2_DIGITS
:
1218 case SKIN_TOKEN_RTC_YEAR_4_DIGITS
:
1220 case SKIN_TOKEN_RTC_WEEKDAY_NAME
:
1221 case SKIN_TOKEN_RTC_MONTH_NAME
:
1223 case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_MON
:
1224 case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_SUN
:
1228 #ifdef HAVE_LCD_CHARCELLS
1229 case SKIN_TOKEN_PROGRESSBAR
:
1232 format_player_progress(gwps
);
1233 end
= utf8encode(data
->wps_progress_pat
[0], buf
);
1238 case SKIN_TOKEN_PLAYER_PROGRESSBAR
:
1241 /* we need 11 characters (full line) for
1243 strlcpy(buf
, " ", buf_size
);
1244 format_player_fullbar(gwps
,buf
,buf_size
);
1245 DEBUGF("bar='%s'\n",buf
);
1249 /* Tell the user if we have an OldPlayer */
1250 strlcpy(buf
, " <Old LCD> ", buf_size
);
1257 #if (CONFIG_CODEC == SWCODEC)
1258 case SKIN_TOKEN_CROSSFADE
:
1259 #ifdef HAVE_CROSSFADE
1261 *intval
= global_settings
.crossfade
+ 1;
1262 snprintf(buf
, buf_size
, "%d", global_settings
.crossfade
);
1264 snprintf(buf
, buf_size
, "%d", 0);
1268 case SKIN_TOKEN_REPLAYGAIN
:
1272 if (global_settings
.replaygain_type
== REPLAYGAIN_OFF
)
1278 type
= get_replaygain_mode(id3
->track_gain_string
!= NULL
,
1279 id3
->album_gain_string
!= NULL
);
1284 val
= 6; /* no tag */
1288 if (global_settings
.replaygain_type
== REPLAYGAIN_SHUFFLE
)
1301 /* due to above, coming here with !id3 shouldn't be possible */
1304 strlcpy(buf
, id3
->track_gain_string
, buf_size
);
1308 strlcpy(buf
, id3
->album_gain_string
, buf_size
);
1313 #endif /* (CONFIG_CODEC == SWCODEC) */
1315 #if (CONFIG_CODEC != MAS3507D) && defined (HAVE_PITCHSCREEN)
1316 case SKIN_TOKEN_SOUND_PITCH
:
1318 int32_t pitch
= sound_get_pitch();
1319 snprintf(buf
, buf_size
, "%ld.%ld",
1320 pitch
/ PITCH_SPEED_PRECISION
,
1321 (pitch
% PITCH_SPEED_PRECISION
) / (PITCH_SPEED_PRECISION
/ 10));
1324 *intval
= pitch_speed_enum(limit
, pitch
,
1325 PITCH_SPEED_PRECISION
* 100);
1330 #if (CONFIG_CODEC == SWCODEC) && defined (HAVE_PITCHSCREEN)
1331 case SKIN_TOKEN_SOUND_SPEED
:
1333 int32_t pitch
= sound_get_pitch();
1335 if (dsp_timestretch_available())
1336 speed
= GET_SPEED(pitch
, dsp_get_timestretch());
1339 snprintf(buf
, buf_size
, "%ld.%ld",
1340 speed
/ PITCH_SPEED_PRECISION
,
1341 (speed
% PITCH_SPEED_PRECISION
) / (PITCH_SPEED_PRECISION
/ 10));
1343 *intval
= pitch_speed_enum(limit
, speed
,
1344 PITCH_SPEED_PRECISION
* 100);
1349 case SKIN_TOKEN_MAIN_HOLD
:
1350 #ifdef HAS_BUTTON_HOLD
1353 if (is_keys_locked())
1354 #endif /*hold switch or softlock*/
1359 #ifdef HAS_REMOTE_BUTTON_HOLD
1360 case SKIN_TOKEN_REMOTE_HOLD
:
1361 if (remote_button_hold())
1367 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
1368 case SKIN_TOKEN_VLED_HDD
:
1374 case SKIN_TOKEN_BUTTON_VOLUME
:
1375 if (global_status
.last_volume_change
&&
1376 TIME_BEFORE(current_tick
, global_status
.last_volume_change
+
1381 case SKIN_TOKEN_LASTTOUCH
:
1383 #ifdef HAVE_TOUCHSCREEN
1384 unsigned int last_touch
= touchscreen_last_touch();
1385 if (last_touch
!= 0xffff &&
1386 TIME_BEFORE(current_tick
, token
->value
.i
+ last_touch
))
1391 case SKIN_TOKEN_HAVE_TOUCH
:
1392 #ifdef HAVE_TOUCHSCREEN
1398 case SKIN_TOKEN_SETTING
:
1400 const struct settings_list
*s
= settings
+token
->value
.i
;
1403 /* Handle contionals */
1404 switch (s
->flags
&F_T_MASK
)
1408 if (s
->flags
&F_T_SOUND
)
1410 /* %?St|name|<min|min+1|...|max-1|max> */
1411 int sound_setting
= s
->sound_setting
->setting
;
1412 /* settings with decimals can't be used in conditionals */
1413 if (sound_numdecimals(sound_setting
) == 0)
1415 *intval
= (*(int*)s
->setting
-sound_min(sound_setting
))
1416 /sound_steps(sound_setting
) + 1;
1421 else if (s
->flags
&F_RGB
)
1422 /* %?St|name|<#000000|#000001|...|#FFFFFF> */
1423 /* shouldn't overflow since colors are stored
1425 * but this is pretty useless anyway */
1426 *intval
= *(int*)s
->setting
+ 1;
1427 else if (s
->cfg_vals
== NULL
)
1428 /* %?St|name|<1st choice|2nd choice|...> */
1429 *intval
= (*(int*)s
->setting
-s
->int_setting
->min
)
1430 /s
->int_setting
->step
+ 1;
1432 /* %?St|name|<1st choice|2nd choice|...> */
1433 /* Not sure about this one. cfg_name/vals are
1434 * indexed from 0 right? */
1435 *intval
= *(int*)s
->setting
+ 1;
1438 /* %?St|name|<if true|if false> */
1439 *intval
= *(bool*)s
->setting
?1:2;
1443 /* %?St|name|<if non empty string|if empty>
1444 * The string's emptyness discards the setting's
1445 * prefix and suffix */
1446 *intval
= ((char*)s
->setting
)[0]?1:2;
1447 /* if there is a prefix we should ignore it here */
1448 if (s
->filename_setting
->prefix
)
1449 return (char*)s
->setting
;
1452 /* This shouldn't happen ... but you never know */
1457 /* Special handlng for filenames because we dont want to show the prefix */
1458 if ((s
->flags
&F_T_MASK
) == F_T_UCHARPTR
||
1459 (s
->flags
&F_T_MASK
) == F_T_UCHARPTR
)
1461 if (s
->filename_setting
->prefix
)
1462 return (char*)s
->setting
;
1464 cfg_to_string(token
->value
.i
,buf
,buf_size
);
1467 case SKIN_TOKEN_HAVE_TUNER
:
1469 if (radio_hardware_present())
1473 /* Recording tokens */
1474 case SKIN_TOKEN_HAVE_RECORDING
:
1475 #ifdef HAVE_RECORDING
1481 #ifdef HAVE_RECORDING
1482 case SKIN_TOKEN_IS_RECORDING
:
1483 if (audio_status() == AUDIO_STATUS_RECORD
)
1486 case SKIN_TOKEN_REC_FREQ
: /* order from REC_FREQ_CFG_VAL_LIST */
1488 #if CONFIG_CODEC == SWCODEC
1489 unsigned long samprk
;
1490 int rec_freq
= global_settings
.rec_frequency
;
1495 #if defined(HAVE_SPDIF_REC)
1496 if (global_settings
.rec_source
== AUDIO_SRC_SPDIF
)
1498 /* Use rate in use, not current measured rate if it changed */
1499 samprk
= pcm_rec_sample_rate();
1501 while (rec_freq
< SAMPR_NUM_FREQ
&&
1502 audio_master_sampr_list
[rec_freq
] != samprk
)
1509 samprk
= rec_freq_sampr
[rec_freq
];
1510 #endif /* SIMULATOR */
1515 REC_HAVE_96_(case REC_FREQ_96
:
1518 REC_HAVE_88_(case REC_FREQ_88
:
1521 REC_HAVE_64_(case REC_FREQ_64
:
1524 REC_HAVE_48_(case REC_FREQ_48
:
1527 REC_HAVE_44_(case REC_FREQ_44
:
1530 REC_HAVE_32_(case REC_FREQ_32
:
1533 REC_HAVE_24_(case REC_FREQ_24
:
1536 REC_HAVE_22_(case REC_FREQ_22
:
1539 REC_HAVE_16_(case REC_FREQ_16
:
1542 REC_HAVE_12_(case REC_FREQ_12
:
1545 REC_HAVE_11_(case REC_FREQ_11
:
1548 REC_HAVE_8_(case REC_FREQ_8
:
1553 snprintf(buf
, buf_size
, "%lu.%1lu", samprk
/1000,samprk
%1000);
1556 static const char * const freq_strings
[] =
1557 {"--", "44", "48", "32", "22", "24", "16"};
1558 int freq
= 1 + global_settings
.rec_frequency
;
1559 #ifdef HAVE_SPDIF_REC
1560 if (global_settings
.rec_source
== AUDIO_SRC_SPDIF
)
1562 /* Can't measure S/PDIF sample rate on Archos/Sim yet */
1565 #endif /* HAVE_SPDIF_IN */
1567 *intval
= freq
+1; /* so the token gets a value 1<=x<=7 */
1568 snprintf(buf
, buf_size
, "%s\n",
1569 freq_strings
[global_settings
.rec_frequency
]);
1573 #if CONFIG_CODEC == SWCODEC
1574 case SKIN_TOKEN_REC_ENCODER
:
1576 int rec_format
= global_settings
.rec_format
+1; /* WAV, AIFF, WV, MPEG */
1578 *intval
= rec_format
;
1581 case REC_FORMAT_PCM_WAV
:
1583 case REC_FORMAT_AIFF
:
1585 case REC_FORMAT_WAVPACK
:
1587 case REC_FORMAT_MPA_L3
:
1595 case SKIN_TOKEN_REC_BITRATE
:
1596 #if CONFIG_CODEC == SWCODEC
1597 if (global_settings
.rec_format
== REC_FORMAT_MPA_L3
)
1601 #if 0 /* FIXME: I dont know if this is needed? */
1602 switch (1<<global_settings
.mp3_enc_config
.bitrate
)
1604 case MP3_BITR_CAP_8
:
1607 case MP3_BITR_CAP_16
:
1610 case MP3_BITR_CAP_24
:
1613 case MP3_BITR_CAP_32
:
1616 case MP3_BITR_CAP_40
:
1619 case MP3_BITR_CAP_48
:
1622 case MP3_BITR_CAP_56
:
1625 case MP3_BITR_CAP_64
:
1628 case MP3_BITR_CAP_80
:
1631 case MP3_BITR_CAP_96
:
1634 case MP3_BITR_CAP_112
:
1637 case MP3_BITR_CAP_128
:
1640 case MP3_BITR_CAP_144
:
1643 case MP3_BITR_CAP_160
:
1646 case MP3_BITR_CAP_192
:
1651 *intval
= global_settings
.mp3_enc_config
.bitrate
+1;
1653 snprintf(buf
, buf_size
, "%lu", global_settings
.mp3_enc_config
.bitrate
+1);
1657 return NULL
; /* Fixme later */
1658 #else /* CONFIG_CODEC == HWCODEC */
1660 *intval
= global_settings
.rec_quality
+1;
1661 snprintf(buf
, buf_size
, "%d", global_settings
.rec_quality
);
1664 case SKIN_TOKEN_REC_MONO
:
1665 if (!global_settings
.rec_channels
)
1669 case SKIN_TOKEN_REC_SECONDS
:
1671 int time
= (audio_recorded_time() / HZ
) % 60;
1674 snprintf(buf
, buf_size
, "%02d", time
);
1677 case SKIN_TOKEN_REC_MINUTES
:
1679 int time
= (audio_recorded_time() / HZ
) / 60;
1682 snprintf(buf
, buf_size
, "%02d", time
);
1685 case SKIN_TOKEN_REC_HOURS
:
1687 int time
= (audio_recorded_time() / HZ
) / 3600;
1690 snprintf(buf
, buf_size
, "%02d", time
);
1694 #endif /* HAVE_RECORDING */
1696 case SKIN_TOKEN_CURRENT_SCREEN
:
1698 int curr_screen
= current_screen();
1700 #ifdef HAVE_RECORDING
1701 /* override current_screen() for recording screen since it may
1702 * be entered from the radio screen */
1703 if (in_recording_screen())
1704 curr_screen
= GO_TO_RECSCREEN
;
1707 switch (curr_screen
)
1712 #ifdef HAVE_RECORDING
1713 case GO_TO_RECSCREEN
:
1722 case GO_TO_PLAYLIST_VIEWER
:
1725 default: /* lists */
1731 *intval
= curr_screen
;
1733 snprintf(buf
, buf_size
, "%d", curr_screen
);
1737 case SKIN_TOKEN_LANG_IS_RTL
:
1738 return lang_is_rtl() ? "r" : NULL
;