1
0
Fork 0
forked from len0rd/rockbox

Skin_engine optimize element switches

it takes a lot of code to check validity and dereference a pointer for every numeric tag branch in get_token_value

apparently about 900 bytes actually

Change-Id: If463e755e9bbc73cbd4a02441572d22df9206121
This commit is contained in:
William Wilgus 2020-10-28 21:34:40 -04:00 committed by William Wilgus
parent 47e1f96427
commit 6c3cc1cbb9
2 changed files with 287 additions and 279 deletions

View file

@ -470,42 +470,40 @@ static void fix_line_alignment(struct skin_draw_info *info, struct skin_element
{ {
struct align_pos *align = &info->align; struct align_pos *align = &info->align;
char *cur_pos = info->cur_align_start + strlen(info->cur_align_start); char *cur_pos = info->cur_align_start + strlen(info->cur_align_start);
char *next_pos = cur_pos + 1;
switch (element->tag->type) switch (element->tag->type)
{ {
case SKIN_TOKEN_ALIGN_LEFT: case SKIN_TOKEN_ALIGN_LEFT:
*cur_pos = '\0'; cur_pos++; *cur_pos = '\0'; align->left = next_pos;
align->left = cur_pos; info->cur_align_start = next_pos;
info->cur_align_start = cur_pos;
break; break;
case SKIN_TOKEN_ALIGN_LEFT_RTL: case SKIN_TOKEN_ALIGN_LEFT_RTL:
*cur_pos = '\0'; cur_pos++; *cur_pos = '\0'; if (UNLIKELY(lang_is_rtl()))
if (lang_is_rtl()) align->right = next_pos;
align->right = cur_pos;
else else
align->left = cur_pos; align->left = next_pos;
info->cur_align_start = cur_pos; info->cur_align_start = next_pos;
break; break;
case SKIN_TOKEN_ALIGN_CENTER: case SKIN_TOKEN_ALIGN_CENTER:
*cur_pos = '\0'; cur_pos++; *cur_pos = '\0'; align->center = next_pos;
align->center = cur_pos; info->cur_align_start = next_pos;
info->cur_align_start = cur_pos;
break; break;
case SKIN_TOKEN_ALIGN_RIGHT: case SKIN_TOKEN_ALIGN_RIGHT:
*cur_pos = '\0'; cur_pos++; *cur_pos = '\0'; align->right = next_pos;
align->right = cur_pos; info->cur_align_start = next_pos;
info->cur_align_start = cur_pos;
break; break;
case SKIN_TOKEN_ALIGN_RIGHT_RTL: case SKIN_TOKEN_ALIGN_RIGHT_RTL:
*cur_pos = '\0'; cur_pos++; *cur_pos = '\0'; if (UNLIKELY(lang_is_rtl()))
if (lang_is_rtl()) align->left = next_pos;
align->left = cur_pos;
else else
align->right = cur_pos; align->right = next_pos;
info->cur_align_start = cur_pos; info->cur_align_start = next_pos;
break; break;
default: default:
break; return;
} }
*cur_pos = '\0';
*next_pos = '\0';
} }
/* Draw a LINE element onto the display */ /* Draw a LINE element onto the display */

View file

@ -667,6 +667,9 @@ const char *get_token_value(struct gui_wps *gwps,
char *buf, int buf_size, char *buf, int buf_size,
int *intval) int *intval)
{ {
int numeric_ret = -1;
const char *numeric_buf = "?";
if (!gwps) if (!gwps)
return NULL; return NULL;
if (!token) if (!token)
@ -796,9 +799,12 @@ const char *get_token_value(struct gui_wps *gwps,
buf[byte_len] = '\0'; buf[byte_len] = '\0';
if (ss->expect_number && if (ss->expect_number &&
intval && (buf[0] >= '0' && buf[0] <= '9')) intval && (buf[0] >= '0' && buf[0] <= '9'))
*intval = atoi(buf) + 1; /* so 0 is the first item */ {
return buf; numeric_ret = atoi(buf) + 1; /* so 0 is the first item */
}
numeric_buf = buf;
goto gtv_ret_numeric_tag_info;
} }
return NULL; return NULL;
} }
@ -816,17 +822,17 @@ const char *get_token_value(struct gui_wps *gwps,
return (char*)P2STR(ID2P(token->value.i)); return (char*)P2STR(ID2P(token->value.i));
case SKIN_TOKEN_PLAYLIST_ENTRIES: case SKIN_TOKEN_PLAYLIST_ENTRIES:
snprintf(buf, buf_size, "%d", playlist_amount()); numeric_ret = playlist_amount();
if (intval) snprintf(buf, buf_size, "%d", numeric_ret);
*intval = playlist_amount(); numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_LIST_TITLE_TEXT: case SKIN_TOKEN_LIST_TITLE_TEXT:
return sb_get_title(gwps->display->screen_type); return sb_get_title(gwps->display->screen_type);
case SKIN_TOKEN_LIST_TITLE_ICON: case SKIN_TOKEN_LIST_TITLE_ICON:
if (intval) numeric_ret = sb_get_icon(gwps->display->screen_type);
*intval = sb_get_icon(gwps->display->screen_type); snprintf(buf, buf_size, "%d", numeric_ret);
snprintf(buf, buf_size, "%d",sb_get_icon(gwps->display->screen_type)); numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_LIST_ITEM_TEXT: case SKIN_TOKEN_LIST_ITEM_TEXT:
{ {
struct listitem *li = (struct listitem *)SKINOFFSETTOPTR(get_skin_buffer(data), token->value.data); struct listitem *li = (struct listitem *)SKINOFFSETTOPTR(get_skin_buffer(data), token->value.data);
@ -834,20 +840,20 @@ const char *get_token_value(struct gui_wps *gwps,
return skinlist_get_item_text(li->offset, li->wrap, buf, buf_size); return skinlist_get_item_text(li->offset, li->wrap, buf, buf_size);
} }
case SKIN_TOKEN_LIST_ITEM_ROW: case SKIN_TOKEN_LIST_ITEM_ROW:
if (intval) numeric_ret = skinlist_get_item_row() + 1;
*intval = skinlist_get_item_row() + 1; snprintf(buf, buf_size, "%d", numeric_ret);
snprintf(buf, buf_size, "%d",skinlist_get_item_row() + 1); numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_LIST_ITEM_COLUMN: case SKIN_TOKEN_LIST_ITEM_COLUMN:
if (intval) numeric_ret = skinlist_get_item_column() + 1;
*intval = skinlist_get_item_column() + 1; snprintf(buf, buf_size, "%d", numeric_ret);
snprintf(buf, buf_size, "%d",skinlist_get_item_column() + 1); numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_LIST_ITEM_NUMBER: case SKIN_TOKEN_LIST_ITEM_NUMBER:
if (intval) numeric_ret = skinlist_get_item_number() + 1;
*intval = skinlist_get_item_number() + 1; snprintf(buf, buf_size, "%d", numeric_ret);
snprintf(buf, buf_size, "%d",skinlist_get_item_number() + 1); numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_LIST_ITEM_IS_SELECTED: case SKIN_TOKEN_LIST_ITEM_IS_SELECTED:
return skinlist_is_selected_item()?"s":""; return skinlist_is_selected_item()?"s":"";
case SKIN_TOKEN_LIST_ITEM_ICON: case SKIN_TOKEN_LIST_ITEM_ICON:
@ -855,10 +861,10 @@ const char *get_token_value(struct gui_wps *gwps,
struct listitem *li = (struct listitem *)SKINOFFSETTOPTR(get_skin_buffer(data), token->value.data); struct listitem *li = (struct listitem *)SKINOFFSETTOPTR(get_skin_buffer(data), token->value.data);
if (!li) return NULL; if (!li) return NULL;
int icon = skinlist_get_item_icon(li->offset, li->wrap); int icon = skinlist_get_item_icon(li->offset, li->wrap);
if (intval) numeric_ret = icon;
*intval = icon; snprintf(buf, buf_size, "%d", numeric_ret);
snprintf(buf, buf_size, "%d", icon); numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
} }
case SKIN_TOKEN_LIST_NEEDS_SCROLLBAR: case SKIN_TOKEN_LIST_NEEDS_SCROLLBAR:
return skinlist_needs_scrollbar(gwps->display->screen_type) ? "s" : ""; return skinlist_needs_scrollbar(gwps->display->screen_type) ? "s" : "";
@ -866,10 +872,10 @@ const char *get_token_value(struct gui_wps *gwps,
return playlist_name(NULL, buf, buf_size); return playlist_name(NULL, buf, buf_size);
case SKIN_TOKEN_PLAYLIST_POSITION: case SKIN_TOKEN_PLAYLIST_POSITION:
snprintf(buf, buf_size, "%d", playlist_get_display_index()+offset); numeric_ret = playlist_get_display_index()+offset;
if (intval) snprintf(buf, buf_size, "%d", numeric_ret);
*intval = playlist_get_display_index()+offset; numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_PLAYLIST_SHUFFLE: case SKIN_TOKEN_PLAYLIST_SHUFFLE:
if ( global_settings.playlist_shuffle ) if ( global_settings.playlist_shuffle )
@ -885,27 +891,28 @@ const char *get_token_value(struct gui_wps *gwps,
int minvol = sound_min(SOUND_VOLUME); int minvol = sound_min(SOUND_VOLUME);
if (limit == TOKEN_VALUE_ONLY) if (limit == TOKEN_VALUE_ONLY)
{ {
*intval = global_settings.volume; numeric_ret = global_settings.volume;
} }
else if (global_settings.volume == minvol) else if (global_settings.volume == minvol)
{ {
*intval = 1; numeric_ret = 1;
} }
else if (global_settings.volume == 0) else if (global_settings.volume == 0)
{ {
*intval = limit - 1; numeric_ret = limit - 1;
} }
else if (global_settings.volume > 0) else if (global_settings.volume > 0)
{ {
*intval = limit; numeric_ret = limit;
} }
else else
{ {
*intval = (limit-3) * (global_settings.volume - minvol - 1) numeric_ret = (limit-3) * (global_settings.volume - minvol - 1)
/ (-1 - minvol) + 2; / (-1 - minvol) + 2;
} }
} }
return buf; numeric_buf = buf;
goto gtv_ret_numeric_tag_info;
#ifdef HAVE_ALBUMART #ifdef HAVE_ALBUMART
case SKIN_TOKEN_ALBUMART_FOUND: case SKIN_TOKEN_ALBUMART_FOUND:
if (SKINOFFSETTOPTR(get_skin_buffer(data), data->albumart)) if (SKINOFFSETTOPTR(get_skin_buffer(data), data->albumart))
@ -925,7 +932,7 @@ const char *get_token_value(struct gui_wps *gwps,
return "C"; return "C";
} }
return NULL; return NULL;
#endif #endif /* def HAVE_ALBUMART */
case SKIN_TOKEN_BATTERY_PERCENT: case SKIN_TOKEN_BATTERY_PERCENT:
{ {
@ -935,7 +942,7 @@ const char *get_token_value(struct gui_wps *gwps,
{ {
if (limit == TOKEN_VALUE_ONLY) if (limit == TOKEN_VALUE_ONLY)
{ {
*intval = l; numeric_ret = l;
} }
else else
{ {
@ -944,18 +951,20 @@ const char *get_token_value(struct gui_wps *gwps,
/* First enum is used for "unknown level", /* First enum is used for "unknown level",
* last enum is used for 100%. * last enum is used for 100%.
*/ */
*intval = (limit - 2) * l / 100 + 2; numeric_ret = (limit - 2) * l / 100 + 2;
} else { } else {
*intval = 1; numeric_ret = 1;
} }
} }
} }
if (l > -1) { if (l > -1) {
snprintf(buf, buf_size, "%d", l); snprintf(buf, buf_size, "%d", l);
return buf; numeric_buf = buf;
goto gtv_ret_numeric_tag_info;
} else { } else {
return "?"; numeric_buf = "?";
goto gtv_ret_numeric_tag_info;
} }
} }
@ -1046,20 +1055,17 @@ const char *get_token_value(struct gui_wps *gwps,
mode = 9; mode = 9;
#endif #endif
if (intval) { numeric_ret = mode;
*intval = mode;
}
snprintf(buf, buf_size, "%d", mode-1); snprintf(buf, buf_size, "%d", mode-1);
return buf; numeric_buf = buf;
goto gtv_ret_numeric_tag_info;
} }
case SKIN_TOKEN_REPEAT_MODE: case SKIN_TOKEN_REPEAT_MODE:
if (intval)
*intval = global_settings.repeat_mode + 1;
snprintf(buf, buf_size, "%d", global_settings.repeat_mode); snprintf(buf, buf_size, "%d", global_settings.repeat_mode);
return buf; numeric_ret = global_settings.repeat_mode + 1;
numeric_buf = buf;
goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_RTC_PRESENT: case SKIN_TOKEN_RTC_PRESENT:
#if CONFIG_RTC #if CONFIG_RTC
return "c"; return "c";
@ -1069,101 +1075,99 @@ const char *get_token_value(struct gui_wps *gwps,
#if CONFIG_RTC #if CONFIG_RTC
case SKIN_TOKEN_RTC_12HOUR_CFG: case SKIN_TOKEN_RTC_12HOUR_CFG:
if (intval)
*intval = global_settings.timeformat + 1;
snprintf(buf, buf_size, "%d", global_settings.timeformat); snprintf(buf, buf_size, "%d", global_settings.timeformat);
return buf; numeric_ret = global_settings.timeformat + 1;
numeric_buf = buf;
goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_RTC_DAY_OF_MONTH: case SKIN_TOKEN_RTC_DAY_OF_MONTH:
/* d: day of month (01..31) */ /* d: day of month (01..31) */
snprintf(buf, buf_size, "%02d", tm->tm_mday); snprintf(buf, buf_size, "%02d", tm->tm_mday);
if (intval) numeric_ret = tm->tm_mday - 1;
*intval = tm->tm_mday - 1; numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED: case SKIN_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED:
/* e: day of month, blank padded ( 1..31) */ /* e: day of month, blank padded ( 1..31) */
snprintf(buf, buf_size, "%2d", tm->tm_mday); snprintf(buf, buf_size, "%2d", tm->tm_mday);
if (intval) numeric_ret = tm->tm_mday - 1;
*intval = tm->tm_mday - 1; numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_RTC_HOUR_24_ZERO_PADDED: case SKIN_TOKEN_RTC_HOUR_24_ZERO_PADDED:
/* H: hour (00..23) */ /* H: hour (00..23) */
snprintf(buf, buf_size, "%02d", tm->tm_hour); numeric_ret = tm->tm_hour;
if (intval) snprintf(buf, buf_size, "%02d", numeric_ret);
*intval = tm->tm_hour; numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_RTC_HOUR_24: case SKIN_TOKEN_RTC_HOUR_24:
/* k: hour ( 0..23) */ /* k: hour ( 0..23) */
snprintf(buf, buf_size, "%2d", tm->tm_hour); numeric_ret = tm->tm_hour;
if (intval) snprintf(buf, buf_size, "%2d", numeric_ret);
*intval = tm->tm_hour; numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_RTC_HOUR_12_ZERO_PADDED: case SKIN_TOKEN_RTC_HOUR_12_ZERO_PADDED:
/* I: hour (01..12) */ /* I: hour (01..12) */
snprintf(buf, buf_size, "%02d", numeric_ret = (tm->tm_hour % 12 == 0) ? 12 : tm->tm_hour % 12;
(tm->tm_hour % 12 == 0) ? 12 : tm->tm_hour % 12); snprintf(buf, buf_size, "%02d", numeric_ret);
if (intval) numeric_buf = buf;
*intval = (tm->tm_hour % 12 == 0) ? 12 : tm->tm_hour % 12; goto gtv_ret_numeric_tag_info;
return buf;
case SKIN_TOKEN_RTC_HOUR_12: case SKIN_TOKEN_RTC_HOUR_12:
/* l: hour ( 1..12) */ /* l: hour ( 1..12) */
snprintf(buf, buf_size, "%2d", numeric_ret = (tm->tm_hour % 12 == 0) ? 12 : tm->tm_hour % 12;
(tm->tm_hour % 12 == 0) ? 12 : tm->tm_hour % 12); snprintf(buf, buf_size, "%2d", numeric_ret);
if (intval) numeric_buf = buf;
*intval = (tm->tm_hour % 12 == 0) ? 12 : tm->tm_hour % 12; goto gtv_ret_numeric_tag_info;
return buf;
case SKIN_TOKEN_RTC_MONTH: case SKIN_TOKEN_RTC_MONTH:
/* m: month (01..12) */ /* m: month (01..12) */
if (intval) numeric_ret = tm->tm_mon + 1;
*intval = tm->tm_mon + 1; snprintf(buf, buf_size, "%02d", numeric_ret);
snprintf(buf, buf_size, "%02d", tm->tm_mon + 1); numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_RTC_MINUTE: case SKIN_TOKEN_RTC_MINUTE:
/* M: minute (00..59) */ /* M: minute (00..59) */
snprintf(buf, buf_size, "%02d", tm->tm_min); numeric_ret = tm->tm_min;
if (intval) snprintf(buf, buf_size, "%02d", numeric_ret);
*intval = tm->tm_min; numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_RTC_SECOND: case SKIN_TOKEN_RTC_SECOND:
/* S: second (00..59) */ /* S: second (00..59) */
snprintf(buf, buf_size, "%02d", tm->tm_sec); numeric_ret = tm->tm_sec;
if (intval) snprintf(buf, buf_size, "%02d", numeric_ret);
*intval = tm->tm_sec; numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_RTC_YEAR_2_DIGITS: case SKIN_TOKEN_RTC_YEAR_2_DIGITS:
/* y: last two digits of year (00..99) */ /* y: last two digits of year (00..99) */
snprintf(buf, buf_size, "%02d", tm->tm_year % 100); numeric_ret = tm->tm_year % 100;
if (intval) snprintf(buf, buf_size, "%02d", numeric_ret);
*intval = tm->tm_year % 100; numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_RTC_YEAR_4_DIGITS: case SKIN_TOKEN_RTC_YEAR_4_DIGITS:
/* Y: year (1970...) */ /* Y: year (1970...) */
snprintf(buf, buf_size, "%04d", tm->tm_year + 1900); numeric_ret = tm->tm_year + 1900;
if (intval) snprintf(buf, buf_size, "%04d", numeric_ret);
*intval = tm->tm_year + 1900; numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_RTC_AM_PM_UPPER: case SKIN_TOKEN_RTC_AM_PM_UPPER:
/* p: upper case AM or PM indicator */ /* p: upper case AM or PM indicator */
if (intval) numeric_ret = tm->tm_hour/12 == 0 ? 0 : 1;
*intval = tm->tm_hour/12 == 0 ? 0 : 1; numeric_buf = numeric_ret == 0 ? "AM" : "PM";
return tm->tm_hour/12 == 0 ? "AM" : "PM"; goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_RTC_AM_PM_LOWER: case SKIN_TOKEN_RTC_AM_PM_LOWER:
/* P: lower case am or pm indicator */ /* P: lower case am or pm indicator */
if (intval) numeric_ret= tm->tm_hour/12 == 0 ? 0 : 1;
*intval = tm->tm_hour/12 == 0 ? 0 : 1; numeric_buf = numeric_ret == 0 ? "am" : "pm";
return tm->tm_hour/12 == 0 ? "am" : "pm"; goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_RTC_WEEKDAY_NAME: case SKIN_TOKEN_RTC_WEEKDAY_NAME:
/* a: abbreviated weekday name (Sun..Sat) */ /* a: abbreviated weekday name (Sun..Sat) */
@ -1175,18 +1179,18 @@ const char *get_token_value(struct gui_wps *gwps,
case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_MON: case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_MON:
/* u: day of week (1..7); 1 is Monday */ /* u: day of week (1..7); 1 is Monday */
if (intval)
*intval = (tm->tm_wday == 0) ? 7 : tm->tm_wday;
snprintf(buf, buf_size, "%1d", tm->tm_wday + 1); snprintf(buf, buf_size, "%1d", tm->tm_wday + 1);
return buf; numeric_ret = (tm->tm_wday == 0) ? 7 : tm->tm_wday;
numeric_buf = buf;
goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_SUN: case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_SUN:
/* w: day of week (0..6); 0 is Sunday */ /* w: day of week (0..6); 0 is Sunday */
if (intval)
*intval = tm->tm_wday + 1;
snprintf(buf, buf_size, "%1d", tm->tm_wday); snprintf(buf, buf_size, "%1d", tm->tm_wday);
return buf; numeric_ret = tm->tm_wday + 1;
#else numeric_buf = buf;
goto gtv_ret_numeric_tag_info;
#else /* !CONFIG_RTC */
case SKIN_TOKEN_RTC_DAY_OF_MONTH: case SKIN_TOKEN_RTC_DAY_OF_MONTH:
case SKIN_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED: case SKIN_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED:
case SKIN_TOKEN_RTC_HOUR_24_ZERO_PADDED: case SKIN_TOKEN_RTC_HOUR_24_ZERO_PADDED:
@ -1208,7 +1212,7 @@ const char *get_token_value(struct gui_wps *gwps,
case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_MON: case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_MON:
case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_SUN: case SKIN_TOKEN_RTC_DAY_OF_WEEK_START_SUN:
return "-"; return "-";
#endif #endif /* CONFIG_RTC */
/* peakmeter */ /* peakmeter */
case SKIN_TOKEN_PEAKMETER_LEFT: case SKIN_TOKEN_PEAKMETER_LEFT:
@ -1219,22 +1223,22 @@ const char *get_token_value(struct gui_wps *gwps,
val = token->type == SKIN_TOKEN_PEAKMETER_LEFT ? val = token->type == SKIN_TOKEN_PEAKMETER_LEFT ?
left : right; left : right;
val = peak_meter_scale_value(val, limit==1 ? MAX_PEAK : limit); val = peak_meter_scale_value(val, limit==1 ? MAX_PEAK : limit);
if (intval) numeric_ret = val;
*intval = val; snprintf(buf, buf_size, "%d", numeric_ret);
snprintf(buf, buf_size, "%d", val);
data->peak_meter_enabled = true; data->peak_meter_enabled = true;
return buf; numeric_buf = buf;
goto gtv_ret_numeric_tag_info;
} }
case SKIN_TOKEN_CROSSFADE: case SKIN_TOKEN_CROSSFADE:
#ifdef HAVE_CROSSFADE #ifdef HAVE_CROSSFADE
if (intval)
*intval = global_settings.crossfade + 1;
snprintf(buf, buf_size, "%d", global_settings.crossfade); snprintf(buf, buf_size, "%d", global_settings.crossfade);
numeric_ret = global_settings.crossfade + 1;
#else #else
snprintf(buf, buf_size, "%d", 0); snprintf(buf, buf_size, "%d", 0);
#endif #endif
return buf; numeric_buf = buf;
goto gtv_ret_numeric_tag_info;
case SKIN_TOKEN_REPLAYGAIN: case SKIN_TOKEN_REPLAYGAIN:
{ {
@ -1257,15 +1261,13 @@ const char *get_token_value(struct gui_wps *gwps,
val += 2; val += 2;
} }
if (intval) numeric_ret = val;
*intval = val;
switch (val) switch (val)
{ {
case 1: case 1:
case 6: case 6:
return "+0.00 dB"; numeric_buf = "+0.00 dB";;
break; goto gtv_ret_numeric_tag_info;
/* due to above, coming here with !id3 shouldn't be possible */ /* due to above, coming here with !id3 shouldn't be possible */
case 2: case 2:
case 4: case 4:
@ -1276,7 +1278,8 @@ const char *get_token_value(struct gui_wps *gwps,
replaygain_itoa(buf, buf_size, id3->album_level); replaygain_itoa(buf, buf_size, id3->album_level);
break; break;
} }
return buf; numeric_buf = buf;
goto gtv_ret_numeric_tag_info;
} }
#if defined (HAVE_PITCHCONTROL) #if defined (HAVE_PITCHCONTROL)
@ -1286,11 +1289,10 @@ const char *get_token_value(struct gui_wps *gwps,
snprintf(buf, buf_size, "%ld.%ld", snprintf(buf, buf_size, "%ld.%ld",
pitch / PITCH_SPEED_PRECISION, pitch / PITCH_SPEED_PRECISION,
(pitch % PITCH_SPEED_PRECISION) / (PITCH_SPEED_PRECISION / 10)); (pitch % PITCH_SPEED_PRECISION) / (PITCH_SPEED_PRECISION / 10));
if (intval) if (intval)
*intval = pitch_speed_enum(limit, pitch, numeric_ret = pitch_speed_enum(limit, pitch, PITCH_SPEED_PRECISION * 100);
PITCH_SPEED_PRECISION * 100); numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
} }
#endif #endif
@ -1307,9 +1309,9 @@ const char *get_token_value(struct gui_wps *gwps,
speed / PITCH_SPEED_PRECISION, speed / PITCH_SPEED_PRECISION,
(speed % PITCH_SPEED_PRECISION) / (PITCH_SPEED_PRECISION / 10)); (speed % PITCH_SPEED_PRECISION) / (PITCH_SPEED_PRECISION / 10));
if (intval) if (intval)
*intval = pitch_speed_enum(limit, speed, numeric_ret = pitch_speed_enum(limit, speed, PITCH_SPEED_PRECISION * 100);
PITCH_SPEED_PRECISION * 100); numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
} }
#endif #endif
@ -1389,57 +1391,65 @@ const char *get_token_value(struct gui_wps *gwps,
/* settings with decimals can't be used in conditionals */ /* settings with decimals can't be used in conditionals */
if (sound_numdecimals(sound_setting) == 0) if (sound_numdecimals(sound_setting) == 0)
{ {
*intval = (*(int*)s->setting-sound_min(sound_setting)) numeric_ret = (*(int*)s->setting-sound_min(sound_setting))
/sound_steps(sound_setting) + 1; /sound_steps(sound_setting) + 1;
} }
else else
*intval = -1; numeric_ret = -1;
} }
else if (s->flags&F_RGB) else if (s->flags&F_RGB)
/* %?St|name|<#000000|#000001|...|#FFFFFF> */ /* %?St|name|<#000000|#000001|...|#FFFFFF> */
/* shouldn't overflow since colors are stored /* shouldn't overflow since colors are stored
* on 16 bits ... * on 16 bits ...
* but this is pretty useless anyway */ * but this is pretty useless anyway */
*intval = *(int*)s->setting + 1; numeric_ret = *(int*)s->setting + 1;
else if (s->cfg_vals == NULL) else if (s->cfg_vals == NULL)
/* %?St|name|<1st choice|2nd choice|...> */ /* %?St|name|<1st choice|2nd choice|...> */
*intval = (*(int*)s->setting-s->int_setting->min) numeric_ret = (*(int*)s->setting-s->int_setting->min)
/s->int_setting->step + 1; /s->int_setting->step + 1;
else else
/* %?St|name|<1st choice|2nd choice|...> */ /* %?St|name|<1st choice|2nd choice|...> */
/* Not sure about this one. cfg_name/vals are /* Not sure about this one. cfg_name/vals are
* indexed from 0 right? */ * indexed from 0 right? */
*intval = *(int*)s->setting + 1; numeric_ret = *(int*)s->setting + 1;
break; break;
case F_T_BOOL: case F_T_BOOL:
/* %?St|name|<if true|if false> */ /* %?St|name|<if true|if false> */
*intval = *(bool*)s->setting?1:2; numeric_ret = *(bool*)s->setting?1:2;
break; break;
case F_T_CHARPTR: case F_T_CHARPTR:
case F_T_UCHARPTR: case F_T_UCHARPTR:
/* %?St|name|<if non empty string|if empty> /* %?St|name|<if non empty string|if empty>
* The string's emptyness discards the setting's * The string's emptyness discards the setting's
* prefix and suffix */ * prefix and suffix */
*intval = ((char*)s->setting)[0]?1:2; numeric_ret = ((char*)s->setting)[0]?1:2;
/* if there is a prefix we should ignore it here */ /* if there is a prefix we should ignore it here */
if (s->filename_setting->prefix) if (s->filename_setting->prefix)
return (char*)s->setting; {
numeric_buf = (char*)s->setting;
goto gtv_ret_numeric_tag_info;
}
break; break;
default: default:
/* This shouldn't happen ... but you never know */ /* This shouldn't happen ... but you never know */
*intval = -1; numeric_ret = -1;
break; break;
} }
} }
/* Special handlng for filenames because we dont want to show the prefix */ /* Special handlng for filenames because we dont want to show the prefix */
if ((s->flags&F_T_MASK) == F_T_CHARPTR || if ((s->flags&F_T_MASK) == F_T_CHARPTR ||
(s->flags&F_T_MASK) == F_T_UCHARPTR) (s->flags&F_T_MASK) == F_T_UCHARPTR)
{ {
if (s->filename_setting->prefix) if (s->filename_setting->prefix)
return (char*)s->setting; {
numeric_buf = (char*)s->setting;
goto gtv_ret_numeric_tag_info;
}
} }
cfg_to_string(token->value.i,buf,buf_size); cfg_to_string(token->value.i,buf,buf_size);
return buf; numeric_buf = buf;
goto gtv_ret_numeric_tag_info;
} }
case SKIN_TOKEN_HAVE_TUNER: case SKIN_TOKEN_HAVE_TUNER:
#if CONFIG_TUNER #if CONFIG_TUNER
@ -1484,50 +1494,48 @@ const char *get_token_value(struct gui_wps *gwps,
#endif #endif
samprk = rec_freq_sampr[rec_freq]; samprk = rec_freq_sampr[rec_freq];
#endif /* SIMULATOR */ #endif /* SIMULATOR */
if (intval) switch (rec_freq)
{ {
switch (rec_freq) REC_HAVE_96_(case REC_FREQ_96:
{ numeric_ret = 1;
REC_HAVE_96_(case REC_FREQ_96: break;)
*intval = 1; REC_HAVE_88_(case REC_FREQ_88:
break;) numeric_ret = 2;
REC_HAVE_88_(case REC_FREQ_88: break;)
*intval = 2; REC_HAVE_64_(case REC_FREQ_64:
break;) numeric_ret = 3;
REC_HAVE_64_(case REC_FREQ_64: break;)
*intval = 3; REC_HAVE_48_(case REC_FREQ_48:
break;) numeric_ret = 4;
REC_HAVE_48_(case REC_FREQ_48: break;)
*intval = 4; REC_HAVE_44_(case REC_FREQ_44:
break;) numeric_ret = 5;
REC_HAVE_44_(case REC_FREQ_44: break;)
*intval = 5; REC_HAVE_32_(case REC_FREQ_32:
break;) numeric_ret = 6;
REC_HAVE_32_(case REC_FREQ_32: break;)
*intval = 6; REC_HAVE_24_(case REC_FREQ_24:
break;) numeric_ret = 7;
REC_HAVE_24_(case REC_FREQ_24: break;)
*intval = 7; REC_HAVE_22_(case REC_FREQ_22:
break;) numeric_ret = 8;
REC_HAVE_22_(case REC_FREQ_22: break;)
*intval = 8; REC_HAVE_16_(case REC_FREQ_16:
break;) numeric_ret = 9;
REC_HAVE_16_(case REC_FREQ_16: break;)
*intval = 9; REC_HAVE_12_(case REC_FREQ_12:
break;) numeric_ret = 10;
REC_HAVE_12_(case REC_FREQ_12: break;)
*intval = 10; REC_HAVE_11_(case REC_FREQ_11:
break;) numeric_ret = 11;
REC_HAVE_11_(case REC_FREQ_11: break;)
*intval = 11; REC_HAVE_8_(case REC_FREQ_8:
break;) numeric_ret = 12;
REC_HAVE_8_(case REC_FREQ_8: break;)
*intval = 12;
break;)
}
} }
snprintf(buf, buf_size, "%lu.%1lu", samprk/1000,samprk%1000); snprintf(buf, buf_size, "%lu.%1lu", samprk/1000,samprk%1000);
return buf; numeric_buf = buf;
goto gtv_ret_numeric_tag_info;
} }
case SKIN_TOKEN_REC_ENCODER: case SKIN_TOKEN_REC_ENCODER:
{ {
@ -1552,62 +1560,60 @@ const char *get_token_value(struct gui_wps *gwps,
case SKIN_TOKEN_REC_BITRATE: case SKIN_TOKEN_REC_BITRATE:
if (global_settings.rec_format == REC_FORMAT_MPA_L3) if (global_settings.rec_format == REC_FORMAT_MPA_L3)
{ {
if (intval) #if 0 /* FIXME: I dont know if this is needed? */
switch (1<<global_settings.mp3_enc_config.bitrate)
{ {
#if 0 /* FIXME: I dont know if this is needed? */ case MP3_BITR_CAP_8:
switch (1<<global_settings.mp3_enc_config.bitrate) numeric_ret = 1;
{ break;
case MP3_BITR_CAP_8: case MP3_BITR_CAP_16:
*intval = 1; numeric_ret = 2;
break; break;
case MP3_BITR_CAP_16: case MP3_BITR_CAP_24:
*intval = 2; numeric_ret = 3;
break; break;
case MP3_BITR_CAP_24: case MP3_BITR_CAP_32:
*intval = 3; numeric_ret = 4;
break; break;
case MP3_BITR_CAP_32: case MP3_BITR_CAP_40:
*intval = 4; numeric_ret = 5;
break; break;
case MP3_BITR_CAP_40: case MP3_BITR_CAP_48:
*intval = 5; numeric_ret = 6;
break; break;
case MP3_BITR_CAP_48: case MP3_BITR_CAP_56:
*intval = 6; numeric_ret = 7;
break; break;
case MP3_BITR_CAP_56: case MP3_BITR_CAP_64:
*intval = 7; numeric_ret = 8;
break; break;
case MP3_BITR_CAP_64: case MP3_BITR_CAP_80:
*intval = 8; numeric_ret = 9;
break; break;
case MP3_BITR_CAP_80: case MP3_BITR_CAP_96:
*intval = 9; numeric_ret = 10;
break; break;
case MP3_BITR_CAP_96: case MP3_BITR_CAP_112:
*intval = 10; numeric_ret = 11;
break; break;
case MP3_BITR_CAP_112: case MP3_BITR_CAP_128:
*intval = 11; numeric_ret = 12;
break; break;
case MP3_BITR_CAP_128: case MP3_BITR_CAP_144:
*intval = 12; numeric_ret = 13;
break; break;
case MP3_BITR_CAP_144: case MP3_BITR_CAP_160:
*intval = 13; numeric_ret = 14;
break; break;
case MP3_BITR_CAP_160: case MP3_BITR_CAP_192:
*intval = 14; numeric_ret = 15;
break; break;
case MP3_BITR_CAP_192:
*intval = 15;
break;
}
#endif
*intval = global_settings.mp3_enc_config.bitrate+1;
} }
#endif
numeric_ret = global_settings.mp3_enc_config.bitrate+1;
snprintf(buf, buf_size, "%lu", global_settings.mp3_enc_config.bitrate+1); snprintf(buf, buf_size, "%lu", global_settings.mp3_enc_config.bitrate+1);
return buf; numeric_buf = buf;
goto gtv_ret_numeric_tag_info;
} }
else else
return NULL; /* Fixme later */ return NULL; /* Fixme later */
@ -1619,26 +1625,26 @@ const char *get_token_value(struct gui_wps *gwps,
case SKIN_TOKEN_REC_SECONDS: case SKIN_TOKEN_REC_SECONDS:
{ {
int time = (audio_recorded_time() / HZ) % 60; int time = (audio_recorded_time() / HZ) % 60;
if (intval) numeric_ret = time;
*intval = time; snprintf(buf, buf_size, "%02d", numeric_ret);
snprintf(buf, buf_size, "%02d", time); numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
} }
case SKIN_TOKEN_REC_MINUTES: case SKIN_TOKEN_REC_MINUTES:
{ {
int time = (audio_recorded_time() / HZ) / 60; int time = (audio_recorded_time() / HZ) / 60;
if (intval) numeric_ret = time;
*intval = time; snprintf(buf, buf_size, "%02d", numeric_ret);
snprintf(buf, buf_size, "%02d", time); numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
} }
case SKIN_TOKEN_REC_HOURS: case SKIN_TOKEN_REC_HOURS:
{ {
int time = (audio_recorded_time() / HZ) / 3600; int time = (audio_recorded_time() / HZ) / 3600;
if (intval) numeric_ret = time;
*intval = time; snprintf(buf, buf_size, "%02d", numeric_ret);
snprintf(buf, buf_size, "%02d", time); numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
} }
#endif /* HAVE_RECORDING */ #endif /* HAVE_RECORDING */
@ -1646,12 +1652,10 @@ const char *get_token_value(struct gui_wps *gwps,
case SKIN_TOKEN_CURRENT_SCREEN: case SKIN_TOKEN_CURRENT_SCREEN:
{ {
int curr_screen = get_current_activity(); int curr_screen = get_current_activity();
if (intval) numeric_ret = curr_screen;
{ snprintf(buf, buf_size, "%d", numeric_ret);
*intval = curr_screen; numeric_buf = buf;
} goto gtv_ret_numeric_tag_info;
snprintf(buf, buf_size, "%d", curr_screen);
return buf;
} }
case SKIN_TOKEN_LANG_IS_RTL: case SKIN_TOKEN_LANG_IS_RTL:
@ -1662,10 +1666,10 @@ const char *get_token_value(struct gui_wps *gwps,
{ {
char *skin_base = get_skin_buffer(data); char *skin_base = get_skin_buffer(data);
struct skin_var* var = SKINOFFSETTOPTR(skin_base, token->value.data); struct skin_var* var = SKINOFFSETTOPTR(skin_base, token->value.data);
if (intval) numeric_ret = var->value;
*intval = var->value; snprintf(buf, buf_size, "%d", numeric_ret);
snprintf(buf, buf_size, "%d", var->value); numeric_buf = buf;
return buf; goto gtv_ret_numeric_tag_info;
} }
break; break;
case SKIN_TOKEN_VAR_TIMEOUT: case SKIN_TOKEN_VAR_TIMEOUT:
@ -1685,4 +1689,10 @@ const char *get_token_value(struct gui_wps *gwps,
return NULL; return NULL;
} }
gtv_ret_numeric_tag_info:
if (intval)
{
*intval = numeric_ret;
}
return numeric_buf;
} }