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 extern struct wps_state wps_state
;
75 static const char* get_codectype(const struct mp3entry
* id3
)
77 if (id3
&& id3
->codectype
< AFMT_NUM_CODECS
) {
78 return audio_formats
[id3
->codectype
].label
;
84 /* Extract a part from a path.
86 * buf - buffer extract part to.
87 * buf_size - size of buffer.
88 * path - path to extract from.
89 * level - what to extract. 0 is file name, 1 is parent of file, 2 is
90 * parent of parent, etc.
92 * Returns buf if the desired level was found, NULL otherwise.
94 char* get_dir(char* buf
, int buf_size
, const char* path
, int level
)
100 sep
= path
+ strlen(path
);
115 if (level
|| (last_sep
<= sep
))
118 len
= MIN(last_sep
- sep
, buf_size
- 1);
119 strlcpy(buf
, sep
+ 1, len
+ 1);
123 #if (CONFIG_CODEC != MAS3507D)
124 /* A helper to determine the enum value for pitch/speed.
126 When there are two choices (i.e. boolean), return 1 if the value is
127 different from normal value and 2 if the value is the same as the
128 normal value. E.g. "%?Sp<%Sp>" would show the pitch only when
129 playing at a modified pitch.
131 When there are more than two choices (i.e. enum), the left half of
132 the choices are to show 0..normal range, and the right half of the
133 choices are to show values over that. The last entry is used when
134 it is set to the normal setting, following the rockbox convention
135 to use the last entry for special values.
139 2 items: %?Sp<0..99 or 101..infinity|100>
140 3 items: %?Sp<0..99|101..infinity|100>
141 4 items: %?Sp<0..49|50..99|101..infinity|100>
142 5 items: %?Sp<0..49|50..99|101..149|150..infinity|100>
143 6 items: %?Sp<0..33|34..66|67..99|101..133|134..infinity|100>
144 7 items: %?Sp<0..33|34..66|67..99|101..133|134..167|167..infinity|100>
146 static int pitch_speed_enum(int range
, int32_t val
, int32_t normval
)
152 return (val
== normval
) + 1;
156 n
= (center
* val
) / normval
+ 1;
157 return (range
<= n
) ? (range
- 1) : n
;
161 const char *get_cuesheetid3_token(struct wps_token
*token
, struct mp3entry
*id3
,
162 int offset_tracks
, char *buf
, int buf_size
)
164 struct cuesheet
*cue
= id3
?id3
->cuesheet
:NULL
;
165 if (!cue
|| !cue
->curr_track
)
168 struct cue_track_info
*track
= cue
->curr_track
;
171 if (cue
->curr_track_idx
+offset_tracks
< cue
->track_count
)
172 track
+=offset_tracks
;
178 case SKIN_TOKEN_METADATA_ARTIST
:
179 return *track
->performer
? track
->performer
: NULL
;
180 case SKIN_TOKEN_METADATA_COMPOSER
:
181 return *track
->songwriter
? track
->songwriter
: NULL
;
182 case SKIN_TOKEN_METADATA_ALBUM
:
183 return *cue
->title
? cue
->title
: NULL
;
184 case SKIN_TOKEN_METADATA_ALBUM_ARTIST
:
185 return *cue
->performer
? cue
->performer
: NULL
;
186 case SKIN_TOKEN_METADATA_TRACK_TITLE
:
187 return *track
->title
? track
->title
: NULL
;
188 case SKIN_TOKEN_METADATA_TRACK_NUMBER
:
189 snprintf(buf
, buf_size
, "%d/%d",
190 cue
->curr_track_idx
+offset_tracks
+1, cue
->track_count
);
198 static const char* get_filename_token(struct wps_token
*token
, char* filename
,
199 char *buf
, int buf_size
)
205 case SKIN_TOKEN_FILE_PATH
:
207 case SKIN_TOKEN_FILE_NAME
:
208 if (get_dir(buf
, buf_size
, filename
, 0)) {
209 /* Remove extension */
210 char* sep
= strrchr(buf
, '.');
217 case SKIN_TOKEN_FILE_NAME_WITH_EXTENSION
:
218 return get_dir(buf
, buf_size
, filename
, 0);
219 case SKIN_TOKEN_FILE_DIRECTORY
:
220 return get_dir(buf
, buf_size
, filename
, token
->value
.i
);
228 /* All tokens which only need the info to return a value go in here */
229 const char *get_id3_token(struct wps_token
*token
, struct mp3entry
*id3
,
230 char *filename
, char *buf
, int buf_size
, int limit
, int *intval
)
232 struct wps_state
*state
= &wps_state
;
235 unsigned long length
= id3
->length
;
236 unsigned long elapsed
= id3
->elapsed
+ state
->ff_rewind_count
;
239 case SKIN_TOKEN_METADATA_ARTIST
:
241 case SKIN_TOKEN_METADATA_COMPOSER
:
242 return id3
->composer
;
243 case SKIN_TOKEN_METADATA_ALBUM
:
245 case SKIN_TOKEN_METADATA_ALBUM_ARTIST
:
246 return id3
->albumartist
;
247 case SKIN_TOKEN_METADATA_GROUPING
:
248 return id3
->grouping
;
249 case SKIN_TOKEN_METADATA_GENRE
:
250 return id3
->genre_string
;
251 case SKIN_TOKEN_METADATA_DISC_NUMBER
:
252 if (id3
->disc_string
)
253 return id3
->disc_string
;
255 snprintf(buf
, buf_size
, "%d", id3
->discnum
);
259 case SKIN_TOKEN_METADATA_TRACK_NUMBER
:
260 if (id3
->track_string
)
261 return id3
->track_string
;
263 snprintf(buf
, buf_size
, "%d", id3
->tracknum
);
267 case SKIN_TOKEN_METADATA_TRACK_TITLE
:
269 case SKIN_TOKEN_METADATA_VERSION
:
270 switch (id3
->id3version
)
286 case SKIN_TOKEN_METADATA_YEAR
:
287 if( id3
->year_string
)
288 return id3
->year_string
;
290 snprintf(buf
, buf_size
, "%d", id3
->year
);
294 case SKIN_TOKEN_METADATA_COMMENT
:
296 case SKIN_TOKEN_FILE_BITRATE
:
298 snprintf(buf
, buf_size
, "%d", id3
->bitrate
);
302 case SKIN_TOKEN_TRACK_TIME_ELAPSED
:
303 format_time(buf
, buf_size
, elapsed
);
306 case SKIN_TOKEN_TRACK_TIME_REMAINING
:
307 format_time(buf
, buf_size
, length
- elapsed
);
310 case SKIN_TOKEN_TRACK_LENGTH
:
311 format_time(buf
, buf_size
, length
);
314 case SKIN_TOKEN_TRACK_ELAPSED_PERCENT
:
320 if (limit
== TOKEN_VALUE_ONLY
)
321 limit
= 100; /* make it a percentage */
322 *intval
= limit
* elapsed
/ length
+ 1;
324 snprintf(buf
, buf_size
, "%lu", 100 * elapsed
/ length
);
327 case SKIN_TOKEN_TRACK_STARTING
:
329 unsigned long time
= token
->value
.i
* (HZ
/TIMEOUT_UNIT
);
334 case SKIN_TOKEN_TRACK_ENDING
:
336 unsigned long time
= token
->value
.i
* (HZ
/TIMEOUT_UNIT
);
337 if (length
- elapsed
< time
)
342 case SKIN_TOKEN_FILE_CODEC
:
345 if(id3
->codectype
== AFMT_UNKNOWN
)
346 *intval
= AFMT_NUM_CODECS
;
348 *intval
= id3
->codectype
;
350 return get_codectype(id3
);
352 case SKIN_TOKEN_FILE_FREQUENCY
:
353 snprintf(buf
, buf_size
, "%ld", id3
->frequency
);
355 case SKIN_TOKEN_FILE_FREQUENCY_KHZ
:
356 /* ignore remainders < 100, so 22050 Hz becomes just 22k */
357 if ((id3
->frequency
% 1000) < 100)
358 snprintf(buf
, buf_size
, "%ld", id3
->frequency
/ 1000);
360 snprintf(buf
, buf_size
, "%ld.%lu",
361 id3
->frequency
/ 1000,
362 (id3
->frequency
% 1000) / 100);
364 case SKIN_TOKEN_FILE_VBR
:
365 return (id3
->vbr
) ? "(avg)" : NULL
;
366 case SKIN_TOKEN_FILE_SIZE
:
367 snprintf(buf
, buf_size
, "%ld", id3
->filesize
/ 1024);
371 case SKIN_TOKEN_DATABASE_PLAYCOUNT
:
373 *intval
= id3
->playcount
+ 1;
374 snprintf(buf
, buf_size
, "%ld", id3
->playcount
);
376 case SKIN_TOKEN_DATABASE_RATING
:
378 *intval
= id3
->rating
+ 1;
379 snprintf(buf
, buf_size
, "%d", id3
->rating
);
381 case SKIN_TOKEN_DATABASE_AUTOSCORE
:
383 *intval
= id3
->score
+ 1;
384 snprintf(buf
, buf_size
, "%d", id3
->score
);
389 return get_filename_token(token
, id3
->path
, buf
, buf_size
);
392 else /* id3 == NULL, handle the error based on the expected return type */
396 /* Most tokens expect NULL on error so leave that for the default case,
397 * The ones that expect "0" need to be handled */
398 case SKIN_TOKEN_FILE_FREQUENCY
:
399 case SKIN_TOKEN_FILE_FREQUENCY_KHZ
:
400 case SKIN_TOKEN_FILE_SIZE
:
402 case SKIN_TOKEN_DATABASE_PLAYCOUNT
:
403 case SKIN_TOKEN_DATABASE_RATING
:
404 case SKIN_TOKEN_DATABASE_AUTOSCORE
:
410 return get_filename_token(token
, filename
, buf
, buf_size
);
418 /* Formats the frequency (specified in Hz) in MHz, */
419 /* with one or two digits after the decimal point -- */
420 /* depending on the frequency changing step. */
422 static char *format_freq_MHz(int freq
, int freq_step
, char *buf
, int buf_size
)
426 if (freq_step
< 100000)
428 /* Format with two digits after decimal point */
434 /* Format with one digit after decimal point */
438 div
= 1000000 / scale
;
440 snprintf(buf
, buf_size
, fmt
, freq
/div
, freq
%div
);
445 /* Tokens which are really only used by the radio screen go in here */
446 const char *get_radio_token(struct wps_token
*token
, int preset_offset
,
447 char *buf
, int buf_size
, int limit
, int *intval
)
449 const struct fm_region_data
*region_data
=
450 &(fm_region_data
[global_settings
.fm_region
]);
454 /* Radio/tuner tokens */
455 case SKIN_TOKEN_TUNER_TUNED
:
456 if (tuner_get(RADIO_TUNED
))
459 case SKIN_TOKEN_TUNER_SCANMODE
:
460 if (radio_scan_mode())
463 case SKIN_TOKEN_TUNER_STEREO
:
464 if (radio_is_stereo())
467 case SKIN_TOKEN_TUNER_MINFREQ
: /* changes based on "region" */
468 return format_freq_MHz(region_data
->freq_min
,
469 region_data
->freq_step
, buf
, buf_size
);
470 case SKIN_TOKEN_TUNER_MAXFREQ
: /* changes based on "region" */
471 return format_freq_MHz(region_data
->freq_max
,
472 region_data
->freq_step
, buf
, buf_size
);
473 case SKIN_TOKEN_TUNER_CURFREQ
:
474 return format_freq_MHz(radio_current_frequency(),
475 region_data
->freq_step
, buf
, buf_size
);
476 case SKIN_TOKEN_PRESET_NAME
:
477 case SKIN_TOKEN_PRESET_FREQ
:
478 case SKIN_TOKEN_PRESET_ID
:
480 int preset_count
= radio_preset_count();
481 int cur_preset
= radio_current_preset();
482 if (preset_count
== 0 || cur_preset
< 0)
484 int preset
= cur_preset
+ preset_offset
;
485 /* make sure it's in the valid range */
486 preset
%= preset_count
;
488 preset
+= preset_count
;
489 if (token
->type
== SKIN_TOKEN_PRESET_NAME
)
490 snprintf(buf
, buf_size
, "%s", radio_get_preset(preset
)->name
);
491 else if (token
->type
== SKIN_TOKEN_PRESET_FREQ
)
492 format_freq_MHz(radio_get_preset(preset
)->frequency
,
493 region_data
->freq_step
, buf
, buf_size
);
495 snprintf(buf
, buf_size
, "%d", preset
+ 1);
498 case SKIN_TOKEN_PRESET_COUNT
:
499 snprintf(buf
, buf_size
, "%d", radio_preset_count());
501 *intval
= radio_preset_count();
503 case SKIN_TOKEN_HAVE_RDS
:
506 case SKIN_TOKEN_RDS_NAME
:
507 return tuner_get_rds_info(RADIO_RDS_NAME
);
508 case SKIN_TOKEN_RDS_TEXT
:
509 return tuner_get_rds_info(RADIO_RDS_TEXT
);
511 return NULL
; /* end of the SKIN_TOKEN_HAVE_RDS case */
512 #endif /* HAVE_RDS_CAP */
520 static struct mp3entry
* get_mp3entry_from_offset(int offset
, char **filename
)
522 struct mp3entry
* pid3
= NULL
;
523 struct wps_state
*state
= skin_get_global_state();
524 struct cuesheet
*cue
= state
->id3
? state
->id3
->cuesheet
: NULL
;
525 const char *fname
= NULL
;
526 if (cue
&& cue
->curr_track_idx
+ offset
< cue
->track_count
)
528 else if (offset
== 0)
530 else if (offset
== 1)
534 static char filename_buf
[MAX_PATH
+ 1];
535 fname
= playlist_peek(offset
, filename_buf
, sizeof(filename_buf
));
536 *filename
= (char*)fname
;
537 #if CONFIG_CODEC == SWCODEC
538 #ifdef HAVE_TC_RAMCACHE
539 static struct mp3entry tempid3
;
540 if (tagcache_fill_tags(&tempid3
, fname
))
547 if (!audio_peek_track(&pid3
, offset
))
555 /* Return the tags value as text. buf should be used as temp storage if needed.
557 intval is used with conditionals/enums: when this function is called,
558 intval should contain the number of options in the conditional/enum.
559 When this function returns, intval is -1 if the tag is non numeric or,
560 if the tag is numeric, *intval is the enum case we want to go to (between 1
561 and the original value of *intval, inclusive).
562 When not treating a conditional/enum, intval should be NULL.
564 const char *get_token_value(struct gui_wps
*gwps
,
565 struct wps_token
*token
, int offset
,
566 char *buf
, int buf_size
,
572 struct wps_data
*data
= gwps
->data
;
573 struct wps_state
*state
= skin_get_global_state();
574 struct mp3entry
*id3
; /* Think very carefully about using this.
575 maybe get_id3_token() is the better place? */
576 const char *out_text
= NULL
;
577 char *filename
= NULL
;
582 id3
= get_mp3entry_from_offset(token
->next
? 1: offset
, &filename
);
584 filename
= id3
->path
;
587 struct tm
* tm
= NULL
;
589 /* if the token is an RTC one, update the time
590 and do the necessary checks */
591 if (token
->type
>= SKIN_TOKENS_RTC_BEGIN
592 && token
->type
<= SKIN_TOKENS_RTC_END
)
608 if (id3
&& id3
== state
->id3
&& id3
->cuesheet
)
610 out_text
= get_cuesheetid3_token(token
, id3
,
611 token
->next
?1:offset
, buf
, buf_size
);
615 out_text
= get_id3_token(token
, id3
, filename
, buf
, buf_size
, limit
, intval
);
619 out_text
= get_radio_token(token
, offset
, buf
, buf_size
, limit
, intval
);
626 case SKIN_TOKEN_LOGICAL_IF
:
628 struct logical_if
*lif
= token
->value
.data
;
629 int a
= lif
->num_options
;
631 out_text
= get_token_value(gwps
, lif
->token
, offset
, buf
, buf_size
, &a
);
632 if (a
== -1 && lif
->token
->type
!= SKIN_TOKEN_VOLUME
)
633 a
= (out_text
&& *out_text
) ? 1 : 0;
634 switch (lif
->operand
.type
)
637 if (lif
->op
== IF_EQUALS
)
638 return strcmp(out_text
, lif
->operand
.data
.text
) == 0 ?
645 b
= lif
->operand
.data
.number
;
649 char temp_buf
[MAX_PATH
];
651 struct wps_token
*token
= lif
->operand
.data
.code
->data
;
652 b
= lif
->num_options
;
653 outb
= get_token_value(gwps
, token
, offset
, temp_buf
,
654 sizeof(temp_buf
), &b
);
655 if (b
== -1 && lif
->token
->type
!= SKIN_TOKEN_VOLUME
)
657 if (!out_text
|| !outb
)
658 return (lif
->op
== IF_EQUALS
) ? NULL
: "neq";
659 bool equal
= strcmp(out_text
, outb
) == 0;
660 if (lif
->op
== IF_EQUALS
)
661 return equal
? "eq" : NULL
;
662 else if (lif
->op
== IF_NOTEQUALS
)
663 return !equal
? "neq" : NULL
;
665 b
= (outb
&& *outb
) ? 1 : 0;
676 return a
== b
? "eq" : NULL
;
678 return a
!= b
? "neq" : NULL
;
680 return a
< b
? "lt" : NULL
;
682 return a
<= b
? "lte" : NULL
;
684 return a
> b
? "gt" : NULL
;
685 case IF_GREATERTHAN_EQ
:
686 return a
>= b
? "gte" : NULL
;
692 case SKIN_TOKEN_CHARACTER
:
693 if (token
->value
.c
== '\n')
695 return &(token
->value
.c
);
697 case SKIN_TOKEN_STRING
:
698 return (char*)token
->value
.data
;
700 case SKIN_TOKEN_TRANSLATEDSTRING
:
701 return (char*)P2STR(ID2P(token
->value
.i
));
703 case SKIN_TOKEN_PLAYLIST_ENTRIES
:
704 snprintf(buf
, buf_size
, "%d", playlist_amount());
706 *intval
= playlist_amount();
708 #ifdef HAVE_LCD_BITMAP
709 case SKIN_TOKEN_LIST_TITLE_TEXT
:
710 return sb_get_title(gwps
->display
->screen_type
);
711 case SKIN_TOKEN_LIST_TITLE_ICON
:
713 *intval
= sb_get_icon(gwps
->display
->screen_type
);
714 snprintf(buf
, buf_size
, "%d",sb_get_icon(gwps
->display
->screen_type
));
717 case SKIN_TOKEN_PLAYLIST_NAME
:
718 return playlist_name(NULL
, buf
, buf_size
);
720 case SKIN_TOKEN_PLAYLIST_POSITION
:
721 snprintf(buf
, buf_size
, "%d", playlist_get_display_index()+offset
);
723 *intval
= playlist_get_display_index()+offset
;
726 case SKIN_TOKEN_PLAYLIST_SHUFFLE
:
727 if ( global_settings
.playlist_shuffle
)
733 case SKIN_TOKEN_VOLUME
:
734 snprintf(buf
, buf_size
, "%d", global_settings
.volume
);
737 int minvol
= sound_min(SOUND_VOLUME
);
738 if (limit
== TOKEN_VALUE_ONLY
)
740 *intval
= global_settings
.volume
;
742 else if (global_settings
.volume
== minvol
)
746 else if (global_settings
.volume
== 0)
750 else if (global_settings
.volume
> 0)
756 *intval
= (limit
-3) * (global_settings
.volume
- minvol
- 1)
762 case SKIN_TOKEN_ALBUMART_FOUND
:
766 handle
= playback_current_aa_hid(data
->playback_aa_slot
);
768 if (in_radio_screen() || (get_radio_status() != FMRADIO_OFF
))
770 struct dim dim
= {data
->albumart
->width
, data
->albumart
->height
};
771 handle
= radio_get_art_hid(&dim
);
780 case SKIN_TOKEN_BATTERY_PERCENT
:
782 int l
= battery_level();
786 if (limit
== TOKEN_VALUE_ONLY
)
792 limit
= MAX(limit
, 3);
794 /* First enum is used for "unknown level",
795 * last enum is used for 100%.
797 *intval
= (limit
- 2) * l
/ 100 + 2;
805 snprintf(buf
, buf_size
, "%d", l
);
812 case SKIN_TOKEN_BATTERY_VOLTS
:
814 unsigned int v
= battery_voltage();
815 snprintf(buf
, buf_size
, "%d.%02d", v
/ 1000, (v
% 1000) / 10);
819 case SKIN_TOKEN_BATTERY_TIME
:
821 int t
= battery_time();
823 snprintf(buf
, buf_size
, "%dh %dm", t
/ 60, t
% 60);
830 case SKIN_TOKEN_BATTERY_CHARGER_CONNECTED
:
832 if(charger_input_state
==CHARGER
)
838 #if CONFIG_CHARGING >= CHARGING_MONITOR
839 case SKIN_TOKEN_BATTERY_CHARGING
:
841 if (charge_state
== CHARGING
|| charge_state
== TOPOFF
) {
848 #ifdef HAVE_USB_POWER
849 case SKIN_TOKEN_USB_POWERED
:
854 case SKIN_TOKEN_BATTERY_SLEEPTIME
:
856 if (get_sleep_timer() == 0)
860 format_time(buf
, buf_size
, get_sleep_timer() * 1000);
865 case SKIN_TOKEN_PLAYBACK_STATUS
:
867 int status
= current_playmode();
869 int mode
= 1; /* stop */
870 if (status
== STATUS_PLAY
)
872 if (state
->is_fading
||
873 (status
== STATUS_PAUSE
&& !status_get_ffmode()))
874 mode
= 3; /* pause */
877 if (status_get_ffmode() == STATUS_FASTFORWARD
)
879 if (status_get_ffmode() == STATUS_FASTBACKWARD
)
882 #ifdef HAVE_RECORDING
884 if (status
== STATUS_RECORD
)
886 else if (status
== STATUS_RECORD_PAUSE
)
891 if (status
== STATUS_RADIO
)
893 else if (status
== STATUS_RADIO_PAUSE
)
901 snprintf(buf
, buf_size
, "%d", mode
-1);
905 case SKIN_TOKEN_REPEAT_MODE
:
907 *intval
= global_settings
.repeat_mode
+ 1;
908 snprintf(buf
, buf_size
, "%d", global_settings
.repeat_mode
);
911 case SKIN_TOKEN_RTC_PRESENT
:
919 case SKIN_TOKEN_RTC_12HOUR_CFG
:
921 *intval
= global_settings
.timeformat
+ 1;
922 snprintf(buf
, buf_size
, "%d", global_settings
.timeformat
);
925 case SKIN_TOKEN_RTC_DAY_OF_MONTH
:
926 /* d: day of month (01..31) */
927 snprintf(buf
, buf_size
, "%02d", tm
->tm_mday
);
929 *intval
= tm
->tm_mday
- 1;
932 case SKIN_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED
:
933 /* e: day of month, blank padded ( 1..31) */
934 snprintf(buf
, buf_size
, "%2d", tm
->tm_mday
);
936 *intval
= tm
->tm_mday
- 1;
939 case SKIN_TOKEN_RTC_HOUR_24_ZERO_PADDED
:
940 /* H: hour (00..23) */
941 snprintf(buf
, buf_size
, "%02d", tm
->tm_hour
);
943 *intval
= tm
->tm_hour
;
946 case SKIN_TOKEN_RTC_HOUR_24
:
947 /* k: hour ( 0..23) */
948 snprintf(buf
, buf_size
, "%2d", tm
->tm_hour
);
950 *intval
= tm
->tm_hour
;
953 case SKIN_TOKEN_RTC_HOUR_12_ZERO_PADDED
:
954 /* I: hour (01..12) */
955 snprintf(buf
, buf_size
, "%02d",
956 (tm
->tm_hour
% 12 == 0) ? 12 : tm
->tm_hour
% 12);
958 *intval
= (tm
->tm_hour
% 12 == 0) ? 12 : tm
->tm_hour
% 12;
961 case SKIN_TOKEN_RTC_HOUR_12
:
962 /* l: hour ( 1..12) */
963 snprintf(buf
, buf_size
, "%2d",
964 (tm
->tm_hour
% 12 == 0) ? 12 : tm
->tm_hour
% 12);
966 *intval
= (tm
->tm_hour
% 12 == 0) ? 12 : tm
->tm_hour
% 12;
969 case SKIN_TOKEN_RTC_MONTH
:
970 /* m: month (01..12) */
972 *intval
= tm
->tm_mon
+ 1;
973 snprintf(buf
, buf_size
, "%02d", tm
->tm_mon
+ 1);
976 case SKIN_TOKEN_RTC_MINUTE
:
977 /* M: minute (00..59) */
978 snprintf(buf
, buf_size
, "%02d", tm
->tm_min
);
980 *intval
= tm
->tm_min
;
983 case SKIN_TOKEN_RTC_SECOND
:
984 /* S: second (00..59) */
985 snprintf(buf
, buf_size
, "%02d", tm
->tm_sec
);
987 *intval
= tm
->tm_sec
;
990 case SKIN_TOKEN_RTC_YEAR_2_DIGITS
:
991 /* y: last two digits of year (00..99) */
992 snprintf(buf
, buf_size
, "%02d", tm
->tm_year
% 100);
994 *intval
= tm
->tm_year
% 100;
997 case SKIN_TOKEN_RTC_YEAR_4_DIGITS
:
998 /* Y: year (1970...) */
999 snprintf(buf
, buf_size
, "%04d", tm
->tm_year
+ 1900);
1001 *intval
= tm
->tm_year
+ 1900;
1004 case SKIN_TOKEN_RTC_AM_PM_UPPER
:
1005 /* p: upper case AM or PM indicator */
1007 *intval
= tm
->tm_hour
/12 == 0 ? 0 : 1;
1008 return tm
->tm_hour
/12 == 0 ? "AM" : "PM";
1010 case SKIN_TOKEN_RTC_AM_PM_LOWER
:
1011 /* P: lower case am or pm indicator */
1013 *intval
= tm
->tm_hour
/12 == 0 ? 0 : 1;
1014 return tm
->tm_hour
/12 == 0 ? "am" : "pm";
1016 case SKIN_TOKEN_RTC_WEEKDAY_NAME
:
1017 /* a: abbreviated weekday name (Sun..Sat) */
1018 return str(LANG_WEEKDAY_SUNDAY
+ tm
->tm_wday
);
1020 case SKIN_TOKEN_RTC_MONTH_NAME
:
1021 /* b: abbreviated month name (Jan..Dec) */
1022 return str(LANG_MONTH_JANUARY
+ tm
->tm_mon
);
1024 case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_MON
:
1025 /* u: day of week (1..7); 1 is Monday */
1027 *intval
= (tm
->tm_wday
== 0) ? 7 : tm
->tm_wday
;
1028 snprintf(buf
, buf_size
, "%1d", tm
->tm_wday
+ 1);
1031 case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_SUN
:
1032 /* w: day of week (0..6); 0 is Sunday */
1034 *intval
= tm
->tm_wday
+ 1;
1035 snprintf(buf
, buf_size
, "%1d", tm
->tm_wday
);
1038 case SKIN_TOKEN_RTC_DAY_OF_MONTH
:
1039 case SKIN_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED
:
1040 case SKIN_TOKEN_RTC_HOUR_24_ZERO_PADDED
:
1041 case SKIN_TOKEN_RTC_HOUR_24
:
1042 case SKIN_TOKEN_RTC_HOUR_12_ZERO_PADDED
:
1043 case SKIN_TOKEN_RTC_HOUR_12
:
1044 case SKIN_TOKEN_RTC_MONTH
:
1045 case SKIN_TOKEN_RTC_MINUTE
:
1046 case SKIN_TOKEN_RTC_SECOND
:
1047 case SKIN_TOKEN_RTC_AM_PM_UPPER
:
1048 case SKIN_TOKEN_RTC_AM_PM_LOWER
:
1049 case SKIN_TOKEN_RTC_YEAR_2_DIGITS
:
1051 case SKIN_TOKEN_RTC_YEAR_4_DIGITS
:
1053 case SKIN_TOKEN_RTC_WEEKDAY_NAME
:
1054 case SKIN_TOKEN_RTC_MONTH_NAME
:
1056 case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_MON
:
1057 case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_SUN
:
1061 #ifdef HAVE_LCD_CHARCELLS
1062 case SKIN_TOKEN_PROGRESSBAR
:
1064 char *end
= utf8encode(data
->wps_progress_pat
[0], buf
);
1069 case SKIN_TOKEN_PLAYER_PROGRESSBAR
:
1072 /* we need 11 characters (full line) for
1074 strlcpy(buf
, " ", buf_size
);
1078 /* Tell the user if we have an OldPlayer */
1079 strlcpy(buf
, " <Old LCD> ", buf_size
);
1086 #if (CONFIG_CODEC == SWCODEC)
1087 case SKIN_TOKEN_CROSSFADE
:
1088 #ifdef HAVE_CROSSFADE
1090 *intval
= global_settings
.crossfade
+ 1;
1091 snprintf(buf
, buf_size
, "%d", global_settings
.crossfade
);
1093 snprintf(buf
, buf_size
, "%d", 0);
1097 case SKIN_TOKEN_REPLAYGAIN
:
1101 if (global_settings
.replaygain_type
== REPLAYGAIN_OFF
)
1107 type
= get_replaygain_mode(id3
->track_gain_string
!= NULL
,
1108 id3
->album_gain_string
!= NULL
);
1113 val
= 6; /* no tag */
1117 if (global_settings
.replaygain_type
== REPLAYGAIN_SHUFFLE
)
1130 /* due to above, coming here with !id3 shouldn't be possible */
1133 strlcpy(buf
, id3
->track_gain_string
, buf_size
);
1137 strlcpy(buf
, id3
->album_gain_string
, buf_size
);
1142 #endif /* (CONFIG_CODEC == SWCODEC) */
1144 #if (CONFIG_CODEC != MAS3507D)
1145 case SKIN_TOKEN_SOUND_PITCH
:
1147 int32_t pitch
= sound_get_pitch();
1148 snprintf(buf
, buf_size
, "%ld.%ld",
1149 pitch
/ PITCH_SPEED_PRECISION
,
1150 (pitch
% PITCH_SPEED_PRECISION
) / (PITCH_SPEED_PRECISION
/ 10));
1153 *intval
= pitch_speed_enum(limit
, pitch
,
1154 PITCH_SPEED_PRECISION
* 100);
1159 #if CONFIG_CODEC == SWCODEC
1160 case SKIN_TOKEN_SOUND_SPEED
:
1162 int32_t pitch
= sound_get_pitch();
1164 if (dsp_timestretch_available())
1165 speed
= GET_SPEED(pitch
, dsp_get_timestretch());
1168 snprintf(buf
, buf_size
, "%ld.%ld",
1169 speed
/ PITCH_SPEED_PRECISION
,
1170 (speed
% PITCH_SPEED_PRECISION
) / (PITCH_SPEED_PRECISION
/ 10));
1172 *intval
= pitch_speed_enum(limit
, speed
,
1173 PITCH_SPEED_PRECISION
* 100);
1178 case SKIN_TOKEN_MAIN_HOLD
:
1179 #ifdef HAS_BUTTON_HOLD
1182 if (is_keys_locked())
1183 #endif /*hold switch or softlock*/
1188 #ifdef HAS_REMOTE_BUTTON_HOLD
1189 case SKIN_TOKEN_REMOTE_HOLD
:
1190 if (remote_button_hold())
1196 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
1197 case SKIN_TOKEN_VLED_HDD
:
1203 case SKIN_TOKEN_BUTTON_VOLUME
:
1204 if (global_status
.last_volume_change
&&
1205 TIME_BEFORE(current_tick
, global_status
.last_volume_change
+
1210 case SKIN_TOKEN_LASTTOUCH
:
1212 #ifdef HAVE_TOUCHSCREEN
1213 unsigned int last_touch
= touchscreen_last_touch();
1214 if (last_touch
!= 0xffff &&
1215 TIME_BEFORE(current_tick
, token
->value
.i
+ last_touch
))
1221 case SKIN_TOKEN_SETTING
:
1223 const struct settings_list
*s
= settings
+token
->value
.i
;
1226 /* Handle contionals */
1227 switch (s
->flags
&F_T_MASK
)
1231 if (s
->flags
&F_T_SOUND
)
1233 /* %?St|name|<min|min+1|...|max-1|max> */
1234 int sound_setting
= s
->sound_setting
->setting
;
1235 /* settings with decimals can't be used in conditionals */
1236 if (sound_numdecimals(sound_setting
) == 0)
1238 *intval
= (*(int*)s
->setting
-sound_min(sound_setting
))
1239 /sound_steps(sound_setting
) + 1;
1244 else if (s
->flags
&F_RGB
)
1245 /* %?St|name|<#000000|#000001|...|#FFFFFF> */
1246 /* shouldn't overflow since colors are stored
1248 * but this is pretty useless anyway */
1249 *intval
= *(int*)s
->setting
+ 1;
1250 else if (s
->cfg_vals
== NULL
)
1251 /* %?St|name|<1st choice|2nd choice|...> */
1252 *intval
= (*(int*)s
->setting
-s
->int_setting
->min
)
1253 /s
->int_setting
->step
+ 1;
1255 /* %?St|name|<1st choice|2nd choice|...> */
1256 /* Not sure about this one. cfg_name/vals are
1257 * indexed from 0 right? */
1258 *intval
= *(int*)s
->setting
+ 1;
1261 /* %?St|name|<if true|if false> */
1262 *intval
= *(bool*)s
->setting
?1:2;
1266 /* %?St|name|<if non empty string|if empty>
1267 * The string's emptyness discards the setting's
1268 * prefix and suffix */
1269 *intval
= ((char*)s
->setting
)[0]?1:2;
1270 /* if there is a prefix we should ignore it here */
1271 if (s
->filename_setting
->prefix
)
1272 return (char*)s
->setting
;
1275 /* This shouldn't happen ... but you never know */
1280 /* Special handlng for filenames because we dont want to show the prefix */
1281 if ((s
->flags
&F_T_MASK
) == F_T_UCHARPTR
||
1282 (s
->flags
&F_T_MASK
) == F_T_UCHARPTR
)
1284 if (s
->filename_setting
->prefix
)
1285 return (char*)s
->setting
;
1287 cfg_to_string(token
->value
.i
,buf
,buf_size
);
1290 case SKIN_TOKEN_HAVE_TUNER
:
1292 if (radio_hardware_present())
1296 /* Recording tokens */
1297 case SKIN_TOKEN_HAVE_RECORDING
:
1298 #ifdef HAVE_RECORDING
1304 #ifdef HAVE_RECORDING
1305 case SKIN_TOKEN_IS_RECORDING
:
1306 if (audio_status() == AUDIO_STATUS_RECORD
)
1309 case SKIN_TOKEN_REC_FREQ
: /* order from REC_FREQ_CFG_VAL_LIST */
1311 #if CONFIG_CODEC == SWCODEC
1312 unsigned long samprk
;
1313 int rec_freq
= global_settings
.rec_frequency
;
1318 #if defined(HAVE_SPDIF_REC)
1319 if (global_settings
.rec_source
== AUDIO_SRC_SPDIF
)
1321 /* Use rate in use, not current measured rate if it changed */
1322 samprk
= pcm_rec_sample_rate();
1324 while (rec_freq
< SAMPR_NUM_FREQ
&&
1325 audio_master_sampr_list
[rec_freq
] != samprk
)
1332 samprk
= rec_freq_sampr
[rec_freq
];
1333 #endif /* SIMULATOR */
1338 REC_HAVE_96_(case REC_FREQ_96
:
1341 REC_HAVE_88_(case REC_FREQ_88
:
1344 REC_HAVE_64_(case REC_FREQ_64
:
1347 REC_HAVE_48_(case REC_FREQ_48
:
1350 REC_HAVE_44_(case REC_FREQ_44
:
1353 REC_HAVE_32_(case REC_FREQ_32
:
1356 REC_HAVE_24_(case REC_FREQ_24
:
1359 REC_HAVE_22_(case REC_FREQ_22
:
1362 REC_HAVE_16_(case REC_FREQ_16
:
1365 REC_HAVE_12_(case REC_FREQ_12
:
1368 REC_HAVE_11_(case REC_FREQ_11
:
1371 REC_HAVE_8_(case REC_FREQ_8
:
1376 snprintf(buf
, buf_size
, "%lu.%1lu", samprk
/1000,samprk
%1000);
1379 static const char * const freq_strings
[] =
1380 {"--", "44", "48", "32", "22", "24", "16"};
1381 int freq
= 1 + global_settings
.rec_frequency
;
1382 #ifdef HAVE_SPDIF_REC
1383 if (global_settings
.rec_source
== AUDIO_SRC_SPDIF
)
1385 /* Can't measure S/PDIF sample rate on Archos/Sim yet */
1388 #endif /* HAVE_SPDIF_IN */
1390 *intval
= freq
+1; /* so the token gets a value 1<=x<=7 */
1391 snprintf(buf
, buf_size
, "%s\n",
1392 freq_strings
[global_settings
.rec_frequency
]);
1396 #if CONFIG_CODEC == SWCODEC
1397 case SKIN_TOKEN_REC_ENCODER
:
1399 int rec_format
= global_settings
.rec_format
+1; /* WAV, AIFF, WV, MPEG */
1401 *intval
= rec_format
;
1404 case REC_FORMAT_PCM_WAV
:
1406 case REC_FORMAT_AIFF
:
1408 case REC_FORMAT_WAVPACK
:
1410 case REC_FORMAT_MPA_L3
:
1418 case SKIN_TOKEN_REC_BITRATE
:
1419 #if CONFIG_CODEC == SWCODEC
1420 if (global_settings
.rec_format
== REC_FORMAT_MPA_L3
)
1424 #if 0 /* FIXME: I dont know if this is needed? */
1425 switch (1<<global_settings
.mp3_enc_config
.bitrate
)
1427 case MP3_BITR_CAP_8
:
1430 case MP3_BITR_CAP_16
:
1433 case MP3_BITR_CAP_24
:
1436 case MP3_BITR_CAP_32
:
1439 case MP3_BITR_CAP_40
:
1442 case MP3_BITR_CAP_48
:
1445 case MP3_BITR_CAP_56
:
1448 case MP3_BITR_CAP_64
:
1451 case MP3_BITR_CAP_80
:
1454 case MP3_BITR_CAP_96
:
1457 case MP3_BITR_CAP_112
:
1460 case MP3_BITR_CAP_128
:
1463 case MP3_BITR_CAP_144
:
1466 case MP3_BITR_CAP_160
:
1469 case MP3_BITR_CAP_192
:
1474 *intval
= global_settings
.mp3_enc_config
.bitrate
+1;
1476 snprintf(buf
, buf_size
, "%lu", global_settings
.mp3_enc_config
.bitrate
+1);
1480 return NULL
; /* Fixme later */
1481 #else /* CONFIG_CODEC == HWCODEC */
1483 *intval
= global_settings
.rec_quality
+1;
1484 snprintf(buf
, buf_size
, "%d", global_settings
.rec_quality
);
1487 case SKIN_TOKEN_REC_MONO
:
1488 if (!global_settings
.rec_channels
)
1492 case SKIN_TOKEN_REC_SECONDS
:
1494 int time
= (audio_recorded_time() / HZ
) % 60;
1497 snprintf(buf
, buf_size
, "%02d", time
);
1500 case SKIN_TOKEN_REC_MINUTES
:
1502 int time
= (audio_recorded_time() / HZ
) / 60;
1505 snprintf(buf
, buf_size
, "%02d", time
);
1508 case SKIN_TOKEN_REC_HOURS
:
1510 int time
= (audio_recorded_time() / HZ
) / 3600;
1513 snprintf(buf
, buf_size
, "%02d", time
);
1517 #endif /* HAVE_RECORDING */
1519 case SKIN_TOKEN_CURRENT_SCREEN
:
1521 int curr_screen
= current_screen();
1523 #ifdef HAVE_RECORDING
1524 /* override current_screen() for recording screen since it may
1525 * be entered from the radio screen */
1526 if (in_recording_screen())
1527 curr_screen
= GO_TO_RECSCREEN
;
1530 switch (curr_screen
)
1535 #ifdef HAVE_RECORDING
1536 case GO_TO_RECSCREEN
:
1545 case GO_TO_PLAYLIST_VIEWER
:
1548 default: /* lists */
1554 *intval
= curr_screen
;
1556 snprintf(buf
, buf_size
, "%d", curr_screen
);
1560 case SKIN_TOKEN_LANG_IS_RTL
:
1561 return lang_is_rtl() ? "r" : NULL
;