Fix libmad compilation on MIPS with newer gcc. FS#12013
[maemo-rb.git] / apps / menus / display_menu.c
blob3e1443d02e0b07212c4773d2ec8c6a5fb37916d4
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Jonathan Gordon
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <stdbool.h>
23 #include <stddef.h>
24 #include <limits.h>
25 #include "config.h"
26 #include "appevents.h"
27 #include "lang.h"
28 #include "action.h"
29 #include "settings.h"
30 #include "menu.h"
31 #include "tree.h"
32 #include "list.h"
33 #ifdef HAVE_LCD_BITMAP
34 #include "peakmeter.h"
35 #endif
36 #include "talk.h"
37 #include "lcd.h"
38 #ifdef HAVE_REMOTE_LCD
39 #include "lcd-remote.h"
40 #endif
41 #ifdef HAVE_TOUCHSCREEN
42 #include "screens.h"
43 #endif
44 #include "viewport.h"
45 #include "statusbar.h" /* statusbar_vals enum*/
47 #ifdef HAVE_BACKLIGHT
48 static int filterfirstkeypress_callback(int action,const struct menu_item_ex *this_item)
50 (void)this_item;
51 switch (action)
53 case ACTION_EXIT_MENUITEM:
54 set_backlight_filter_keypress(global_settings.bl_filter_first_keypress);
55 #ifdef HAVE_REMOTE_LCD
56 set_remote_backlight_filter_keypress(
57 global_settings.remote_bl_filter_first_keypress);
58 #endif
60 break;
62 return action;
64 #endif
65 #ifdef HAVE_LCD_FLIP
66 static int flipdisplay_callback(int action,const struct menu_item_ex *this_item)
68 (void)this_item;
69 switch (action)
71 case ACTION_EXIT_MENUITEM:
72 button_set_flip(global_settings.flip_display);
73 lcd_set_flip(global_settings.flip_display);
74 lcd_update();
75 #ifdef HAVE_REMOTE_LCD
76 lcd_remote_set_flip(global_settings.remote_flip_display);
77 lcd_remote_update();
78 #endif
79 break;
81 return action;
83 #endif
85 /***********************************/
86 /* LCD MENU */
87 #ifdef HAVE_BACKLIGHT
88 MENUITEM_SETTING(backlight_timeout, &global_settings.backlight_timeout, NULL);
89 #if CONFIG_CHARGING
90 MENUITEM_SETTING(backlight_timeout_plugged,
91 &global_settings.backlight_timeout_plugged, NULL);
92 #endif
93 #ifdef HAS_BUTTON_HOLD
94 MENUITEM_SETTING(backlight_on_button_hold,
95 &global_settings.backlight_on_button_hold, NULL);
96 #endif
97 MENUITEM_SETTING(caption_backlight, &global_settings.caption_backlight, NULL);
98 #if defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
99 || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
100 MENUITEM_SETTING(backlight_fade_in, &global_settings.backlight_fade_in, NULL);
101 MENUITEM_SETTING(backlight_fade_out, &global_settings.backlight_fade_out, NULL);
102 #endif
103 MENUITEM_SETTING(bl_filter_first_keypress,
104 &global_settings.bl_filter_first_keypress,
105 filterfirstkeypress_callback);
106 #ifdef HAVE_LCD_SLEEP_SETTING
107 MENUITEM_SETTING(lcd_sleep_after_backlight_off,
108 &global_settings.lcd_sleep_after_backlight_off, NULL);
109 #endif
110 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
111 MENUITEM_SETTING(brightness_item, &global_settings.brightness, NULL);
112 #endif
113 #endif /* HAVE_BACKLIGHT */
114 #ifdef HAVE_LCD_CONTRAST
115 MENUITEM_SETTING(contrast, &global_settings.contrast, NULL);
116 #endif
117 #ifdef HAVE_LCD_BITMAP
118 #ifdef HAVE_LCD_INVERT
119 MENUITEM_SETTING(invert, &global_settings.invert, NULL);
120 #endif
121 #ifdef HAVE_LCD_FLIP
122 MENUITEM_SETTING(flip_display, &global_settings.flip_display, flipdisplay_callback);
123 #endif
124 #endif /* HAVE_LCD_BITMAP */
126 /* now the actual menu */
127 MAKE_MENU(lcd_settings,ID2P(LANG_LCD_MENU),
128 NULL, Icon_Display_menu
129 #ifdef HAVE_BACKLIGHT
130 ,&backlight_timeout
131 # if CONFIG_CHARGING
132 ,&backlight_timeout_plugged
133 # endif
134 # ifdef HAS_BUTTON_HOLD
135 ,&backlight_on_button_hold
136 # endif
137 ,&caption_backlight
138 #if defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
139 || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
140 ,&backlight_fade_in, &backlight_fade_out
141 #endif
142 ,&bl_filter_first_keypress
143 # ifdef HAVE_LCD_SLEEP_SETTING
144 ,&lcd_sleep_after_backlight_off
145 # endif
146 # ifdef HAVE_BACKLIGHT_BRIGHTNESS
147 ,&brightness_item
148 # endif
149 #endif /* HAVE_BACKLIGHT */
150 #ifdef HAVE_LCD_CONTRAST
151 ,&contrast
152 #endif
153 #ifdef HAVE_LCD_BITMAP
154 # ifdef HAVE_LCD_INVERT
155 ,&invert
156 # endif
157 # ifdef HAVE_LCD_FLIP
158 ,&flip_display
159 # endif
160 #endif /* HAVE_LCD_BITMAP */
162 /* LCD MENU */
163 /***********************************/
166 /********************************/
167 /* Remote LCD settings menu */
168 #ifdef HAVE_REMOTE_LCD
169 MENUITEM_SETTING(remote_backlight_timeout,
170 &global_settings.remote_backlight_timeout, NULL);
172 #if CONFIG_CHARGING
173 MENUITEM_SETTING(remote_backlight_timeout_plugged,
174 &global_settings.remote_backlight_timeout_plugged, NULL);
175 #endif
177 #ifdef HAS_REMOTE_BUTTON_HOLD
178 MENUITEM_SETTING(remote_backlight_on_button_hold,
179 &global_settings.remote_backlight_on_button_hold, NULL);
180 #endif
182 MENUITEM_SETTING(remote_caption_backlight,
183 &global_settings.remote_caption_backlight, NULL);
184 MENUITEM_SETTING(remote_bl_filter_first_keypress,
185 &global_settings.remote_bl_filter_first_keypress,
186 filterfirstkeypress_callback);
187 MENUITEM_SETTING(remote_contrast,
188 &global_settings.remote_contrast, NULL);
189 MENUITEM_SETTING(remote_invert,
190 &global_settings.remote_invert, NULL);
192 #ifdef HAVE_LCD_FLIP
193 MENUITEM_SETTING(remote_flip_display,
194 &global_settings.remote_flip_display, flipdisplay_callback);
195 #endif
197 #ifdef HAVE_REMOTE_LCD_TICKING
198 static int ticking_callback(int action,const struct menu_item_ex *this_item)
200 (void)this_item;
201 switch (action)
203 case ACTION_EXIT_MENUITEM:
204 lcd_remote_emireduce(global_settings.remote_reduce_ticking);
205 break;
207 return action;
209 MENUITEM_SETTING(remote_reduce_ticking,
210 &global_settings.remote_reduce_ticking, ticking_callback);
211 #endif
213 MAKE_MENU(lcd_remote_settings, ID2P(LANG_LCD_REMOTE_MENU),
214 NULL, Icon_Remote_Display_menu,
215 &remote_backlight_timeout,
216 #if CONFIG_CHARGING
217 &remote_backlight_timeout_plugged,
218 #endif
219 #ifdef HAS_REMOTE_BUTTON_HOLD
220 &remote_backlight_on_button_hold,
221 #endif
222 &remote_caption_backlight, &remote_bl_filter_first_keypress,
223 &remote_contrast, &remote_invert
225 #ifdef HAVE_LCD_FLIP
226 ,&remote_flip_display
227 #endif
228 #ifdef HAVE_REMOTE_LCD_TICKING
229 ,&remote_reduce_ticking
230 #endif
233 #endif /* HAVE_REMOTE_LCD */
234 /* Remote LCD settings menu */
235 /********************************/
237 /***********************************/
238 /* SCROLL MENU */
239 MENUITEM_SETTING_W_TEXT(scroll_speed, &global_settings.scroll_speed,
240 ID2P(LANG_SCROLL), NULL);
241 MENUITEM_SETTING(scroll_delay, &global_settings.scroll_delay, NULL);
242 #ifdef HAVE_LCD_BITMAP
243 MENUITEM_SETTING_W_TEXT(scroll_step, &global_settings.scroll_step,
244 ID2P(LANG_SCROLL_STEP_EXAMPLE), NULL);
245 #endif
246 MENUITEM_SETTING(bidir_limit, &global_settings.bidir_limit, NULL);
247 #ifdef HAVE_REMOTE_LCD
248 MENUITEM_SETTING_W_TEXT(remote_scroll_speed, &global_settings.remote_scroll_speed,
249 ID2P(LANG_SCROLL), NULL);
250 MENUITEM_SETTING(remote_scroll_delay, &global_settings.remote_scroll_delay, NULL);
251 MENUITEM_SETTING_W_TEXT(remote_scroll_step, &global_settings.remote_scroll_step,
252 ID2P(LANG_SCROLL_STEP_EXAMPLE), NULL);
253 MENUITEM_SETTING(remote_bidir_limit, &global_settings.remote_bidir_limit, NULL);
255 MAKE_MENU(remote_scroll_sets, ID2P(LANG_REMOTE_SCROLL_SETS), 0, Icon_NOICON,
256 &remote_scroll_speed, &remote_scroll_delay,
257 &remote_scroll_step, &remote_bidir_limit);
258 #endif /* HAVE_REMOTE_LCD */
260 /* list acceleration */
261 #ifndef HAVE_WHEEL_ACCELERATION
262 MENUITEM_SETTING(list_accel_start_delay,
263 &global_settings.list_accel_start_delay, NULL);
264 MENUITEM_SETTING(list_accel_wait, &global_settings.list_accel_wait, NULL);
265 #endif /* HAVE_WHEEL_ACCELERATION */
266 #ifdef HAVE_LCD_BITMAP
267 static int screenscroll_callback(int action,const struct menu_item_ex *this_item)
269 (void)this_item;
270 switch (action)
272 case ACTION_EXIT_MENUITEM:
273 gui_list_screen_scroll_out_of_view(global_settings.offset_out_of_view);
274 break;
276 return action;
278 MENUITEM_SETTING(offset_out_of_view, &global_settings.offset_out_of_view,
279 screenscroll_callback);
280 MENUITEM_SETTING(screen_scroll_step, &global_settings.screen_scroll_step, NULL);
281 #endif
282 MENUITEM_SETTING(scroll_paginated, &global_settings.scroll_paginated, NULL);
284 MAKE_MENU(scroll_settings_menu, ID2P(LANG_SCROLL_MENU), 0, Icon_NOICON,
285 &scroll_speed, &scroll_delay,
286 #ifdef HAVE_LCD_BITMAP
287 &scroll_step,
288 #endif
289 &bidir_limit,
290 #ifdef HAVE_REMOTE_LCD
291 &remote_scroll_sets,
292 #endif
293 #ifdef HAVE_LCD_BITMAP
294 &offset_out_of_view, &screen_scroll_step,
295 #endif
296 &scroll_paginated,
297 #ifndef HAVE_WHEEL_ACCELERATION
298 &list_accel_start_delay, &list_accel_wait
299 #endif
301 /* SCROLL MENU */
302 /***********************************/
304 /***********************************/
305 /* PEAK METER MENU */
307 #ifdef HAVE_LCD_BITMAP
308 static int peakmeter_callback(int action,const struct menu_item_ex *this_item)
310 (void)this_item;
311 switch (action)
313 case ACTION_EXIT_MENUITEM:
314 peak_meter_init_times(global_settings.peak_meter_release,
315 global_settings.peak_meter_hold,
316 global_settings.peak_meter_clip_hold);
317 break;
319 return action;
321 MENUITEM_SETTING(peak_meter_hold,
322 &global_settings.peak_meter_hold, peakmeter_callback);
323 MENUITEM_SETTING(peak_meter_clip_hold,
324 &global_settings.peak_meter_clip_hold, peakmeter_callback);
325 #ifdef HAVE_RECORDING
326 MENUITEM_SETTING(peak_meter_clipcounter,
327 &global_settings.peak_meter_clipcounter, NULL);
328 #endif
329 MENUITEM_SETTING(peak_meter_release,
330 &global_settings.peak_meter_release, peakmeter_callback);
332 * Menu to select wether the scale of the meter
333 * displays dBfs of linear values.
335 static int peak_meter_scale(void) {
336 bool retval = false;
337 bool use_dbfs = global_settings.peak_meter_dbfs;
338 retval = set_bool_options(str(LANG_PM_SCALE),
339 &use_dbfs,
340 STR(LANG_PM_DBFS), STR(LANG_PM_LINEAR),
341 NULL);
343 /* has the user really changed the scale? */
344 if (use_dbfs != global_settings.peak_meter_dbfs) {
346 /* store the change */
347 global_settings.peak_meter_dbfs = use_dbfs;
348 peak_meter_set_use_dbfs(use_dbfs);
350 /* If the user changed the scale mode the meaning of
351 peak_meter_min (peak_meter_max) has changed. Thus we have
352 to convert the values stored in global_settings. */
353 if (use_dbfs) {
355 /* we only store -dBfs */
356 global_settings.peak_meter_min = -peak_meter_get_min() / 100;
357 global_settings.peak_meter_max = -peak_meter_get_max() / 100;
359 /* limit the returned value to the allowed range */
360 if(global_settings.peak_meter_min > 89)
361 global_settings.peak_meter_min = 89;
362 } else {
363 int max;
365 /* linear percent */
366 global_settings.peak_meter_min = peak_meter_get_min();
368 /* converting dBfs -> percent results in a precision loss.
369 I assume that the user doesn't bother that conversion
370 dBfs <-> percent isn't symmetrical for odd values but that
371 he wants 0 dBfs == 100%. Thus I 'correct' the percent value
372 resulting from dBfs -> percent manually here */
373 max = peak_meter_get_max();
374 global_settings.peak_meter_max = max < 99 ? max : 100;
376 settings_apply_pm_range();
378 return retval;
382 * Adjust the min value of the value range that
383 * the peak meter shall visualize.
385 static int peak_meter_min(void) {
386 bool retval = false;
387 if (global_settings.peak_meter_dbfs) {
389 /* for dBfs scale */
390 int range_max = -global_settings.peak_meter_max;
391 int min = -global_settings.peak_meter_min;
393 retval = set_int(str(LANG_PM_MIN), str(LANG_PM_DBFS), UNIT_DB,
394 &min, NULL, 1, -89, range_max, NULL);
396 global_settings.peak_meter_min = - min;
399 /* for linear scale */
400 else {
401 int min = global_settings.peak_meter_min;
403 retval = set_int(str(LANG_PM_MIN), "%", UNIT_PERCENT,
404 &min, NULL,
405 1, 0, global_settings.peak_meter_max - 1, NULL);
407 global_settings.peak_meter_min = (unsigned char)min;
410 settings_apply_pm_range();
411 return retval;
416 * Adjust the max value of the value range that
417 * the peak meter shall visualize.
419 static int peak_meter_max(void) {
420 bool retval = false;
421 if (global_settings.peak_meter_dbfs) {
423 /* for dBfs scale */
424 int range_min = -global_settings.peak_meter_min;
425 int max = -global_settings.peak_meter_max;
427 retval = set_int(str(LANG_PM_MAX), str(LANG_PM_DBFS), UNIT_DB,
428 &max, NULL, 1, range_min, 0, NULL);
430 global_settings.peak_meter_max = - max;
434 /* for linear scale */
435 else {
436 int max = global_settings.peak_meter_max;
438 retval = set_int(str(LANG_PM_MAX), "%", UNIT_PERCENT,
439 &max, NULL,
440 1, global_settings.peak_meter_min + 1, 100, NULL);
442 global_settings.peak_meter_max = (unsigned char)max;
445 settings_apply_pm_range();
446 return retval;
449 #if defined(HAVE_HISTOGRAM)
450 static bool history_interval(void)
452 static const struct opt_items names[] = {
453 { "0s", TALK_ID(0, UNIT_SEC) },
454 { "1s", TALK_ID(1, UNIT_SEC) },
455 { "2s", TALK_ID(2, UNIT_SEC) },
456 { "4s", TALK_ID(4, UNIT_SEC) }
459 /* reconfigure histogram settings here */
461 return set_option(str(LANG_HISTOGRAM_INTERVAL),
462 &global_settings.histogram_interval,
463 INT, names, 4, NULL );
466 MENUITEM_FUNCTION(histogram, 0,
467 ID2P(LANG_HISTOGRAM_INTERVAL),
468 history_interval, NULL, NULL, Icon_Menu_setting);
470 #endif
472 MENUITEM_FUNCTION(peak_meter_scale_item, 0, ID2P(LANG_PM_SCALE),
473 peak_meter_scale, NULL, NULL, Icon_NOICON);
474 MENUITEM_FUNCTION(peak_meter_min_item, 0, ID2P(LANG_PM_MIN),
475 peak_meter_min, NULL, NULL, Icon_NOICON);
476 MENUITEM_FUNCTION(peak_meter_max_item, 0, ID2P(LANG_PM_MAX),
477 peak_meter_max, NULL, NULL, Icon_NOICON);
478 MAKE_MENU(peak_meter_menu, ID2P(LANG_PM_MENU), NULL, Icon_NOICON,
479 &peak_meter_release, &peak_meter_hold,
480 &peak_meter_clip_hold,
481 #ifdef HAVE_RECORDING
482 &peak_meter_clipcounter,
483 #endif
484 #ifdef HAVE_HISTOGRAM
485 &histogram,
486 #endif
487 &peak_meter_scale_item, &peak_meter_min_item, &peak_meter_max_item);
488 #endif /* HAVE_LCD_BITMAP */
489 /* PEAK METER MENU */
490 /***********************************/
493 #ifdef HAVE_TOUCHSCREEN
494 static int touch_mode_callback(int action,const struct menu_item_ex *this_item)
496 (void)this_item;
497 switch (action)
499 case ACTION_EXIT_MENUITEM: /* on exit */
500 touchscreen_set_mode(global_settings.touch_mode);
501 break;
503 return action;
506 static int line_padding_callback(int action,const struct menu_item_ex *this_item)
508 (void)this_item;
510 if (action == ACTION_EXIT_MENUITEM)
511 viewportmanager_theme_changed(THEME_LISTS);
512 return action;
515 MENUITEM_SETTING(touch_mode, &global_settings.touch_mode, touch_mode_callback);
517 MENUITEM_FUNCTION(touchscreen_menu_calibrate, 0, ID2P(LANG_TOUCHSCREEN_CALIBRATE), calibrate,
518 NULL, NULL, Icon_NOICON);
519 MENUITEM_FUNCTION(touchscreen_menu_reset_calibration, 0, ID2P(LANG_TOUCHSCREEN_RESET_CALIBRATION), reset_mapping,
520 NULL, NULL, Icon_NOICON);
521 MENUITEM_SETTING(list_line_padding, &global_settings.list_line_padding, line_padding_callback);
523 MAKE_MENU(touchscreen_menu, ID2P(LANG_TOUCHSCREEN_SETTINGS), NULL, Icon_NOICON, &list_line_padding, &touch_mode,
524 &touchscreen_menu_calibrate, &touchscreen_menu_reset_calibration);
525 #endif
528 MENUITEM_SETTING(codepage_setting, &global_settings.default_codepage, NULL);
531 MAKE_MENU(display_menu, ID2P(LANG_DISPLAY),
532 NULL, Icon_Display_menu,
533 &lcd_settings,
534 #ifdef HAVE_REMOTE_LCD
535 &lcd_remote_settings,
536 #endif
537 &scroll_settings_menu,
538 #ifdef HAVE_LCD_BITMAP
539 &peak_meter_menu,
540 #endif
541 &codepage_setting,
542 #ifdef HAVE_TOUCHSCREEN
543 &touchscreen_menu,
544 #endif