* Onda VX747: add browse screen, pitchscreen, context menu, quickscreen, rewind...
[kugel-rb.git] / apps / plugins / vu_meter.c
blob80e9ccbb2053d54ec8c4126006d192a03c663789
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2003 Lee Pilgrim
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 **************************************************************************/
20 #include "plugin.h"
21 #include "lib/fixedpoint.h"
22 #include "lib/playback_control.h"
24 PLUGIN_HEADER
26 /* variable button definitions */
27 #if CONFIG_KEYPAD == RECORDER_PAD
28 #define VUMETER_QUIT BUTTON_OFF
29 #define VUMETER_HELP BUTTON_ON
30 #define VUMETER_MENU BUTTON_F1
31 #define VUMETER_MENU_EXIT BUTTON_F1
32 #define VUMETER_MENU_EXIT2 BUTTON_OFF
33 #define VUMETER_UP BUTTON_UP
34 #define VUMETER_DOWN BUTTON_DOWN
35 #define LABEL_HELP "ON"
36 #define LABEL_QUIT "OFF"
37 #define LABEL_MENU "F1"
38 #define LABEL_VOLUME "UP/DOWN"
40 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
41 #define VUMETER_QUIT BUTTON_OFF
42 #define VUMETER_HELP BUTTON_ON
43 #define VUMETER_MENU BUTTON_F1
44 #define VUMETER_MENU_EXIT BUTTON_F1
45 #define VUMETER_MENU_EXIT2 BUTTON_OFF
46 #define VUMETER_UP BUTTON_UP
47 #define VUMETER_DOWN BUTTON_DOWN
48 #define LABEL_HELP "ON"
49 #define LABEL_QUIT "OFF"
50 #define LABEL_MENU "F1"
51 #define LABEL_VOLUME "UP/DOWN"
53 #elif CONFIG_KEYPAD == ONDIO_PAD
54 #define VUMETER_QUIT BUTTON_OFF
55 #define VUMETER_HELP_PRE BUTTON_MENU
56 #define VUMETER_HELP (BUTTON_MENU | BUTTON_REL)
57 #define VUMETER_MENU_PRE BUTTON_MENU
58 #define VUMETER_MENU (BUTTON_MENU | BUTTON_REPEAT)
59 #define VUMETER_MENU_EXIT BUTTON_MENU
60 #define VUMETER_MENU_EXIT2 BUTTON_OFF
61 #define VUMETER_UP BUTTON_UP
62 #define VUMETER_DOWN BUTTON_DOWN
63 #define LABEL_HELP "MODE"
64 #define LABEL_QUIT "OFF"
65 #define LABEL_MENU "MODE.."
66 #define LABEL_VOLUME "UP/DOWN"
68 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
69 (CONFIG_KEYPAD == IRIVER_H300_PAD)
70 #define VUMETER_QUIT BUTTON_OFF
71 #define VUMETER_HELP BUTTON_ON
72 #define VUMETER_MENU BUTTON_SELECT
73 #define VUMETER_MENU2 BUTTON_MODE
74 #define VUMETER_MENU_EXIT BUTTON_SELECT
75 #define VUMETER_MENU_EXIT2 BUTTON_OFF
76 #define VUMETER_UP BUTTON_UP
77 #define VUMETER_DOWN BUTTON_DOWN
78 #define LABEL_HELP "PLAY"
79 #define LABEL_QUIT "STOP"
80 #define LABEL_MENU "SELECT,MODE"
81 #define LABEL_VOLUME "UP/DOWN"
83 #define VUMETER_RC_QUIT BUTTON_RC_STOP
85 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
86 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
87 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
88 #define VUMETER_QUIT BUTTON_MENU
89 #define VUMETER_HELP BUTTON_PLAY
90 #define VUMETER_MENU BUTTON_SELECT
91 #define VUMETER_MENU_EXIT BUTTON_SELECT
92 #define VUMETER_MENU_EXIT2 BUTTON_MENU
93 #define VUMETER_UP BUTTON_SCROLL_FWD
94 #define VUMETER_DOWN BUTTON_SCROLL_BACK
95 #define LABEL_HELP "PLAY"
96 #define LABEL_QUIT "MENU"
97 #define LABEL_MENU "SELECT"
98 #define LABEL_VOLUME "Wheel"
100 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
101 #define VUMETER_QUIT BUTTON_POWER
102 #define VUMETER_HELP BUTTON_A
103 #define VUMETER_MENU BUTTON_MENU
104 #define VUMETER_MENU_EXIT BUTTON_MENU
105 #define VUMETER_MENU_EXIT2 BUTTON_POWER
106 #define VUMETER_UP BUTTON_UP
107 #define VUMETER_DOWN BUTTON_DOWN
108 #define LABEL_HELP "A"
109 #define LABEL_QUIT "POWER"
110 #define LABEL_MENU "MENU"
111 #define LABEL_VOLUME "UP/DOWN"
113 #elif (CONFIG_KEYPAD == SANSA_E200_PAD)
114 #define VUMETER_QUIT BUTTON_POWER
115 #define VUMETER_HELP BUTTON_REC
116 #define VUMETER_MENU BUTTON_SELECT
117 #define VUMETER_MENU_EXIT BUTTON_SELECT
118 #define VUMETER_MENU_EXIT2 BUTTON_POWER
119 #define VUMETER_UP BUTTON_SCROLL_FWD
120 #define VUMETER_DOWN BUTTON_SCROLL_BACK
121 #define LABEL_HELP "REC"
122 #define LABEL_QUIT "POWER"
123 #define LABEL_MENU "SELECT"
124 #define LABEL_VOLUME "Wheel"
126 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
127 #define VUMETER_QUIT (BUTTON_HOME|BUTTON_REPEAT)
128 #define VUMETER_HELP BUTTON_SELECT|BUTTON_REPEAT
129 #define VUMETER_MENU BUTTON_SELECT|BUTTON_REL
130 #define VUMETER_MENU_EXIT BUTTON_SELECT
131 #define VUMETER_MENU_EXIT2 BUTTON_DOWN
132 #define VUMETER_UP BUTTON_SCROLL_FWD
133 #define VUMETER_DOWN BUTTON_SCROLL_BACK
134 #define LABEL_HELP "Hold Select"
135 #define LABEL_QUIT "HOME"
136 #define LABEL_MENU "Select"
137 #define LABEL_VOLUME "Scrollwheel"
139 #elif (CONFIG_KEYPAD == SANSA_C200_PAD)
140 #define VUMETER_QUIT BUTTON_POWER
141 #define VUMETER_HELP BUTTON_REC
142 #define VUMETER_MENU BUTTON_SELECT
143 #define VUMETER_MENU_EXIT BUTTON_SELECT
144 #define VUMETER_MENU_EXIT2 BUTTON_POWER
145 #define VUMETER_UP BUTTON_VOL_UP
146 #define VUMETER_DOWN BUTTON_VOL_DOWN
147 #define LABEL_HELP "REC"
148 #define LABEL_QUIT "POWER"
149 #define LABEL_MENU "SELECT"
150 #define LABEL_VOLUME "VOL UP/DN"
152 #elif (CONFIG_KEYPAD == SANSA_CLIP_PAD)
153 #define VUMETER_QUIT BUTTON_POWER
154 #define VUMETER_HELP BUTTON_HOME
155 #define VUMETER_MENU BUTTON_SELECT
156 #define VUMETER_MENU_EXIT BUTTON_SELECT
157 #define VUMETER_MENU_EXIT2 BUTTON_POWER
158 #define VUMETER_UP BUTTON_VOL_UP
159 #define VUMETER_DOWN BUTTON_VOL_DOWN
160 #define LABEL_HELP "HOME"
161 #define LABEL_QUIT "POWER"
162 #define LABEL_MENU "SELECT"
163 #define LABEL_VOLUME "VOL UP/DN"
165 #elif (CONFIG_KEYPAD == SANSA_M200_PAD)
166 #define VUMETER_QUIT BUTTON_POWER
167 #define VUMETER_HELP (BUTTON_SELECT | BUTTON_UP)
168 #define VUMETER_MENU (BUTTON_SELECT | BUTTON_REL)
169 #define VUMETER_MENU_EXIT (BUTTON_SELECT | BUTTON_REL)
170 #define VUMETER_MENU_EXIT2 BUTTON_POWER
171 #define VUMETER_UP BUTTON_VOL_UP
172 #define VUMETER_DOWN BUTTON_VOL_DOWN
173 #define LABEL_HELP "SELECT + UP"
174 #define LABEL_QUIT "POWER"
175 #define LABEL_MENU "SELECT"
176 #define LABEL_VOLUME "VOL UP/DN"
178 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
179 #define VUMETER_QUIT BUTTON_POWER
180 #define VUMETER_HELP BUTTON_PLAY
181 #define VUMETER_MENU BUTTON_SELECT
182 #define VUMETER_MENU_EXIT BUTTON_SELECT
183 #define VUMETER_MENU_EXIT2 BUTTON_POWER
184 #define VUMETER_UP BUTTON_UP
185 #define VUMETER_DOWN BUTTON_DOWN
186 #define LABEL_HELP "PLAY"
187 #define LABEL_QUIT "POWER"
188 #define LABEL_MENU "SELECT"
189 #define LABEL_VOLUME "UP/DOWN"
191 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
192 #define VUMETER_QUIT BUTTON_POWER
193 #define VUMETER_HELP BUTTON_PLAY
194 #define VUMETER_MENU BUTTON_REW
195 #define VUMETER_MENU_EXIT BUTTON_REW
196 #define VUMETER_MENU_EXIT2 BUTTON_POWER
197 #define VUMETER_UP BUTTON_SCROLL_UP
198 #define VUMETER_DOWN BUTTON_SCROLL_DOWN
199 #define LABEL_HELP "PLAY"
200 #define LABEL_QUIT "POWER"
201 #define LABEL_MENU "REW"
202 #define LABEL_VOLUME "Scroller"
204 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
205 #define VUMETER_QUIT BUTTON_BACK
206 #define VUMETER_HELP BUTTON_NEXT
207 #define VUMETER_MENU BUTTON_MENU
208 #define VUMETER_MENU_EXIT BUTTON_MENU
209 #define VUMETER_MENU_EXIT2 BUTTON_PLAY
210 #define VUMETER_UP BUTTON_UP
211 #define VUMETER_DOWN BUTTON_DOWN
212 #define LABEL_HELP "NEXT"
213 #define LABEL_QUIT "BACK"
214 #define LABEL_MENU "MENU"
215 #define LABEL_VOLUME "UP/DOWN"
217 #elif (CONFIG_KEYPAD == MROBE100_PAD)
218 #define VUMETER_QUIT BUTTON_POWER
219 #define VUMETER_HELP BUTTON_DISPLAY
220 #define VUMETER_MENU BUTTON_MENU
221 #define VUMETER_MENU_EXIT BUTTON_MENU
222 #define VUMETER_MENU_EXIT2 BUTTON_POWER
223 #define VUMETER_UP BUTTON_UP
224 #define VUMETER_DOWN BUTTON_DOWN
225 #define LABEL_HELP "DISPLAY"
226 #define LABEL_QUIT "POWER"
227 #define LABEL_MENU "MENU"
228 #define LABEL_VOLUME "UP/DOWN"
230 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
231 #define VUMETER_QUIT BUTTON_RC_REC
232 #define VUMETER_HELP BUTTON_RC_MODE
233 #define VUMETER_MENU BUTTON_RC_MENU
234 #define VUMETER_MENU_EXIT BUTTON_RC_MENU
235 #define VUMETER_MENU_EXIT2 BUTTON_RC_REC
236 #define VUMETER_UP BUTTON_RC_VOL_UP
237 #define VUMETER_DOWN BUTTON_RC_VOL_DOWN
238 #define LABEL_HELP "MODE"
239 #define LABEL_QUIT "REC"
240 #define LABEL_MENU "MENU"
241 #define LABEL_VOLUME "VOL UP/DN"
243 #elif CONFIG_KEYPAD == COWOND2_PAD
244 #define VUMETER_QUIT BUTTON_POWER
245 #define VUMETER_MENU BUTTON_MENU
246 #define VUMETER_MENU_EXIT BUTTON_POWER
247 #define LABEL_QUIT "POWER"
248 #define LABEL_MENU "MENU"
250 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
251 #define VUMETER_QUIT BUTTON_BACK
252 #define VUMETER_HELP BUTTON_SELECT
253 #define VUMETER_MENU BUTTON_MENU
254 #define VUMETER_MENU_EXIT BUTTON_MENU
255 #define VUMETER_UP BUTTON_UP
256 #define VUMETER_DOWN BUTTON_DOWN
257 #define LABEL_HELP "MIDDLE"
258 #define LABEL_QUIT "BACK"
259 #define LABEL_MENU "MENU"
260 #define LABEL_VOLUME "UP/DOWN"
262 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
263 #define VUMETER_QUIT BUTTON_POWER
264 #define VUMETER_HELP BUTTON_VIEW
265 #define VUMETER_MENU BUTTON_MENU
266 #define VUMETER_MENU_EXIT BUTTON_MENU
267 #define VUMETER_MENU_EXIT2 BUTTON_POWER
268 #define VUMETER_UP BUTTON_UP
269 #define VUMETER_DOWN BUTTON_DOWN
270 #define LABEL_HELP "VIEW"
271 #define LABEL_QUIT "POWER"
272 #define LABEL_MENU "MENU"
273 #define LABEL_VOLUME "UP/DOWN"
275 #elif CONFIG_KEYPAD == ONDAVX747_PAD
276 #define VUMETER_QUIT BUTTON_POWER
277 #define VUMETER_MENU BUTTON_MENU
278 #define VUMETER_MENU_EXIT BUTTON_POWER
279 #define LABEL_QUIT "POWER"
280 #define LABEL_MENU "MENU"
282 #elif CONFIG_KEYPAD == MROBE500_PAD
283 #define VUMETER_QUIT BUTTON_POWER
284 #define LABEL_QUIT "POWER"
286 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
287 #define VUMETER_QUIT BUTTON_REC
288 #define VUMETER_HELP BUTTON_PLAY
289 #define VUMETER_MENU BUTTON_LEFT
290 #define VUMETER_MENU_EXIT BUTTON_LEFT
291 #define VUMETER_MENU_EXIT2 BUTTON_RIGHT
292 #define VUMETER_UP BUTTON_UP
293 #define VUMETER_DOWN BUTTON_DOWN
294 #define LABEL_HELP "PLAY"
295 #define LABEL_QUIT "REC"
296 #define LABEL_MENU "LEFT"
297 #define LABEL_VOLUME "UP/DOWN"
299 #else
300 #error No keymap defined!
301 #endif
303 #ifdef HAVE_TOUCHSCREEN
304 #ifndef VUMETER_QUIT
305 #define VUMETER_QUIT BUTTON_TOPLEFT
306 #define LABEL_QUIT "TOPLEFT"
307 #endif
308 #ifndef VUMETER_HELP
309 #define VUMETER_HELP BUTTON_CENTER
310 #define LABEL_HELP "CENTRE"
311 #endif
312 #ifndef VUMETER_MENU
313 #define VUMETER_MENU BUTTON_TOPRIGHT
314 #define LABEL_MENU "TOPRIGHT"
315 #endif
316 #ifndef VUMETER_MENU_EXIT
317 #define VUMETER_MENU_EXIT BUTTON_TOPLEFT
318 #endif
319 #ifndef VUMETER_UP
320 #define VUMETER_UP BUTTON_TOPMIDDLE
321 #endif
322 #ifndef VUMETER_DOWN
323 #define VUMETER_DOWN BUTTON_BOTTOMMIDDLE
324 #endif
325 #ifndef LABEL_VOLUME
326 #define LABEL_VOLUME "UP/DOWN"
327 #endif
328 #endif
330 #if defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
331 #define mas_codec_readreg(x) rand()%MAX_PEAK
332 #endif
334 /* Defines x positions on a logarithmic (dBfs) scale. */
335 unsigned char analog_db_scale[LCD_WIDTH/2];
337 /* Define's y positions, to make the needle arch, like a real needle would. */
338 unsigned char y_values[LCD_WIDTH/2];
340 const unsigned char digital_db_scale[] =
341 {0,2,3,5,5,6,6,6,7,7,7,7,8,8,8,8,8,9,9,9,9,9,9,9,9,10,10,
342 10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11};
344 const unsigned char needle_cover[] =
345 {0x18, 0x1c, 0x1c, 0x1e, 0x1e, 0x1f, 0x1f, 0x1f, 0x1e, 0x1e, 0x1c, 0x1c, 0x18};
347 const unsigned char sound_speaker[] = {0x18,0x24,0x42,0xFF};
348 const unsigned char sound_low_level[] = {0x24,0x18};
349 const unsigned char sound_med_level[] = {0x42,0x3C};
350 const unsigned char sound_high_level[] = {0x81,0x7E};
351 const unsigned char sound_max_level[] = {0x0E,0xDF,0x0E};
353 const int half_width = LCD_WIDTH / 2;
354 const int quarter_width = LCD_WIDTH / 4;
355 const int half_height = LCD_HEIGHT / 2;
357 /* approx ratio of the previous hard coded values */
358 const int analog_mini_1 = (LCD_WIDTH / 2)*0.1;
359 const int analog_mini_2 = (LCD_WIDTH / 2)*0.25;
360 const int analog_mini_3 = (LCD_WIDTH / 2)*0.4;
361 const int analog_mini_4 = (LCD_WIDTH / 2)*0.75;
363 const int digital_block_width = LCD_WIDTH / 11;
364 const int digital_block_gap = (int)(LCD_WIDTH / 11) / 10;
365 /* ammount to lead in on left so 11x blocks are centered - is often 0 */
366 const int digital_lead = (LCD_WIDTH - (((int)(LCD_WIDTH / 11))*11) ) / 2;
368 const int digital_block_height = (LCD_HEIGHT - 54) / 2 ;
370 #define ANALOG 0 /* The two meter types */
371 #define DIGITAL 1
373 int left_needle_top_y;
374 int left_needle_top_x;
375 int last_left_needle_top_x;
376 int right_needle_top_y;
377 int right_needle_top_x;
378 int last_right_needle_top_x = LCD_WIDTH / 2;
380 int num_left_leds;
381 int num_right_leds;
382 int last_num_left_leds;
383 int last_num_right_leds;
385 int i;
386 #ifdef HAVE_LCD_COLOR
387 int screen_foreground;
388 #endif
390 #define MAX_PEAK 0x8000
392 /* gap at the top for left/right etc */
393 #define NEEDLE_TOP 25
395 /* pow(M_E, 5) * 65536 */
396 #define E_POW_5 9726404
398 struct saved_settings {
399 int meter_type;
400 bool analog_use_db_scale;
401 bool digital_use_db_scale;
402 bool analog_minimeters;
403 bool digital_minimeters;
404 int analog_decay;
405 int digital_decay;
406 } vumeter_settings;
408 void reset_settings(void) {
409 vumeter_settings.meter_type=ANALOG;
410 vumeter_settings.analog_use_db_scale=true;
411 vumeter_settings.digital_use_db_scale=true;
412 vumeter_settings.analog_minimeters=true;
413 vumeter_settings.digital_minimeters=false;
414 vumeter_settings.analog_decay=3;
415 vumeter_settings.digital_decay=0;
418 void calc_scales(void)
420 unsigned int fx_log_factor = E_POW_5/half_width;
421 unsigned int y,z;
423 long j;
424 long k;
425 int nh = LCD_HEIGHT - NEEDLE_TOP;
426 long nh2 = nh*nh;
428 for (i=1; i <= half_width; i++)
430 /* analog scale */
431 y = (half_width/5)*fp16_log(i*fx_log_factor);
433 /* better way of checking for negative values? */
434 z = y>>16;
435 if (z > LCD_WIDTH)
436 z = 0;
438 analog_db_scale[i-1] = z;
439 /* play nice */
440 rb->yield();
442 /* y values (analog needle co-ords) */
443 j = i - (int)(half_width/2);
444 k = nh2 - ( j * j );
446 /* fsqrt+1 seems to give a closer approximation */
447 y_values[i-1] = LCD_HEIGHT - (fp_sqrt(k, 16)>>8) - 1;
448 rb->yield();
452 void load_settings(void) {
453 int fp = rb->open(PLUGIN_DEMOS_DIR "/.vu_meter", O_RDONLY);
454 if(fp>=0) {
455 rb->read(fp, &vumeter_settings, sizeof(struct saved_settings));
456 rb->close(fp);
458 else {
459 reset_settings();
460 rb->splash(HZ, "Press " LABEL_HELP " for help");
464 void save_settings(void) {
465 int fp = rb->creat(PLUGIN_DEMOS_DIR "/.vu_meter");
466 if(fp >= 0) {
467 rb->write (fp, &vumeter_settings, sizeof(struct saved_settings));
468 rb->close(fp);
472 void change_volume(int delta) {
473 char curr_vol[5];
474 int minvol = rb->sound_min(SOUND_VOLUME);
475 int maxvol = rb->sound_max(SOUND_VOLUME);
476 int vol = rb->global_settings->volume + delta;
478 if (vol > maxvol) vol = maxvol;
479 else if (vol < minvol) vol = minvol;
480 if (vol != rb->global_settings->volume) {
481 rb->sound_set(SOUND_VOLUME, vol);
482 rb->global_settings->volume = vol;
483 rb->snprintf(curr_vol, sizeof(curr_vol), "%d", vol);
484 rb->lcd_putsxy(0,0, curr_vol);
485 rb->lcd_update();
486 rb->sleep(HZ/12);
490 static bool vu_meter_menu(void)
492 int selection;
493 bool menu_quit = false;
494 bool exit = false;
496 MENUITEM_STRINGLIST(menu,"VU Meter Menu",NULL,"Meter Type","Scale",
497 "Minimeters","Decay Speed","Playback Control",
498 "Quit");
500 static const struct opt_items meter_type_option[2] = {
501 { "Analog", -1 },
502 { "Digital", -1 },
505 static const struct opt_items decay_speed_option[7] = {
506 { "No Decay", -1 },
507 { "Very Fast", -1 },
508 { "Fast", -1 },
509 { "Medium", -1 },
510 { "Medium-Slow", -1 },
511 { "Slow", -1 },
512 { "Very Slow", -1 },
515 while (!menu_quit) {
516 switch(rb->do_menu(&menu, &selection, NULL, false))
518 case 0:
519 rb->set_option("Meter Type", &vumeter_settings.meter_type, INT,
520 meter_type_option, 2, NULL);
521 break;
523 case 1:
524 if(vumeter_settings.meter_type==ANALOG)
526 rb->set_bool_options("Scale", &vumeter_settings.analog_use_db_scale,
527 "dBfs", -1, "Linear", -1, NULL);
529 else
531 rb->set_bool_options("Scale", &vumeter_settings.digital_use_db_scale,
532 "dBfs", -1, "Linear", -1, NULL);
534 break;
536 case 2:
537 if(vumeter_settings.meter_type==ANALOG)
539 rb->set_bool("Enable Minimeters",
540 &vumeter_settings.analog_minimeters);
542 else
544 rb->set_bool("Enable Minimeters",
545 &vumeter_settings.digital_minimeters);
547 break;
549 case 3:
550 if(vumeter_settings.meter_type==ANALOG)
552 rb->set_option("Decay Speed", &vumeter_settings.analog_decay, INT,
553 decay_speed_option, 7, NULL);
555 else
557 rb->set_option("Decay Speed", &vumeter_settings.digital_decay, INT,
558 decay_speed_option, 7, NULL);
560 break;
562 case 4:
563 playback_control(NULL);
564 break;
566 case 5:
567 exit = true;
568 /* fall through to exit the menu */
569 default:
570 menu_quit = true;
571 break;
574 /* the menu uses the userfont, set it back to sysfont */
575 rb->lcd_setfont(FONT_SYSFIXED);
576 return exit;
579 void draw_analog_minimeters(void) {
580 rb->lcd_mono_bitmap(sound_speaker, quarter_width-28, 12, 4, 8);
581 rb->lcd_set_drawmode(DRMODE_FG);
582 if(analog_mini_1<left_needle_top_x)
583 rb->lcd_mono_bitmap(sound_low_level, quarter_width-23, 12, 2, 8);
584 if(analog_mini_2<left_needle_top_x)
585 rb->lcd_mono_bitmap(sound_med_level, quarter_width-21, 12, 2, 8);
586 if(analog_mini_3<left_needle_top_x)
587 rb->lcd_mono_bitmap(sound_high_level, quarter_width-19, 12, 2, 8);
588 if(analog_mini_4<left_needle_top_x)
589 rb->lcd_mono_bitmap(sound_max_level, quarter_width-16, 12, 3, 8);
591 rb->lcd_set_drawmode(DRMODE_SOLID);
592 rb->lcd_mono_bitmap(sound_speaker, quarter_width+half_width-30, 12, 4, 8);
593 rb->lcd_set_drawmode(DRMODE_FG);
594 if(analog_mini_1<(right_needle_top_x-half_width))
595 rb->lcd_mono_bitmap(sound_low_level, quarter_width+half_width-25, 12, 2, 8);
596 if(analog_mini_2<(right_needle_top_x-half_width))
597 rb->lcd_mono_bitmap(sound_med_level, quarter_width+half_width-23, 12, 2, 8);
598 if(analog_mini_3<(right_needle_top_x-half_width))
599 rb->lcd_mono_bitmap(sound_high_level, quarter_width+half_width-21, 12, 2, 8);
600 if(analog_mini_4<(right_needle_top_x-half_width))
601 rb->lcd_mono_bitmap(sound_max_level, quarter_width+half_width-18, 12, 3, 8);
602 rb->lcd_set_drawmode(DRMODE_SOLID);
605 void draw_digital_minimeters(void) {
606 #ifdef HAVE_LCD_COLOR
607 rb->lcd_set_foreground(LCD_RGBPACK(255, 255 - 23 * num_left_leds, 0));
608 #endif
609 rb->lcd_mono_bitmap(sound_speaker, 34, half_height-8, 4, 8);
610 rb->lcd_set_drawmode(DRMODE_FG);
611 if(1<num_left_leds)
612 rb->lcd_mono_bitmap(sound_low_level, 39, half_height-8, 2, 8);
613 if(2<num_left_leds)
614 rb->lcd_mono_bitmap(sound_med_level, 41, half_height-8, 2, 8);
615 if(5<num_left_leds)
616 rb->lcd_mono_bitmap(sound_high_level, 43, half_height-8, 2, 8);
617 if(8<num_left_leds)
618 rb->lcd_mono_bitmap(sound_max_level, 46, half_height-8, 3, 8);
620 #ifdef HAVE_LCD_COLOR
621 rb->lcd_set_foreground(LCD_RGBPACK(255, 255 - 23 * num_right_leds, 0));
622 #endif
623 rb->lcd_set_drawmode(DRMODE_SOLID);
624 rb->lcd_mono_bitmap(sound_speaker, 34, half_height+8, 4, 8);
625 rb->lcd_set_drawmode(DRMODE_FG);
626 if(1<(num_right_leds))
627 rb->lcd_mono_bitmap(sound_low_level, 39, half_height+8, 2, 8);
628 if(2<(num_right_leds))
629 rb->lcd_mono_bitmap(sound_med_level, 41, half_height+8, 2, 8);
630 if(5<(num_right_leds))
631 rb->lcd_mono_bitmap(sound_high_level, 43, half_height+8, 2, 8);
632 if(8<(num_right_leds))
633 rb->lcd_mono_bitmap(sound_max_level, 46, half_height+8, 3, 8);
634 rb->lcd_set_drawmode(DRMODE_SOLID);
636 #ifdef HAVE_LCD_COLOR
637 rb->lcd_set_foreground(screen_foreground);
638 #endif
641 void analog_meter(void) {
643 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
644 int left_peak = rb->mas_codec_readreg(0xC);
645 int right_peak = rb->mas_codec_readreg(0xD);
646 #elif (CONFIG_CODEC == SWCODEC)
647 int left_peak, right_peak;
648 rb->pcm_calculate_peaks(&left_peak, &right_peak);
649 #endif
651 if(vumeter_settings.analog_use_db_scale) {
652 left_needle_top_x = analog_db_scale[left_peak * half_width / MAX_PEAK];
653 right_needle_top_x = analog_db_scale[right_peak * half_width / MAX_PEAK] + half_width;
655 else {
656 left_needle_top_x = left_peak * half_width / MAX_PEAK;
657 right_needle_top_x = right_peak * half_width / MAX_PEAK + half_width;
660 /* Makes a decay on the needle */
661 left_needle_top_x = (left_needle_top_x+last_left_needle_top_x*vumeter_settings.analog_decay)
662 /(vumeter_settings.analog_decay+1);
663 right_needle_top_x = (right_needle_top_x+last_right_needle_top_x*vumeter_settings.analog_decay)
664 /(vumeter_settings.analog_decay+1);
666 last_left_needle_top_x = left_needle_top_x;
667 last_right_needle_top_x = right_needle_top_x;
669 left_needle_top_y = y_values[left_needle_top_x];
670 right_needle_top_y = y_values[right_needle_top_x-half_width];
672 /* Needles */
673 rb->lcd_drawline(quarter_width, LCD_HEIGHT-1, left_needle_top_x, left_needle_top_y);
674 rb->lcd_drawline((quarter_width+half_width), LCD_HEIGHT-1, right_needle_top_x, right_needle_top_y);
676 if(vumeter_settings.analog_minimeters)
677 draw_analog_minimeters();
679 /* Needle covers */
680 rb->lcd_set_drawmode(DRMODE_FG);
681 rb->lcd_mono_bitmap(needle_cover, quarter_width-6, LCD_HEIGHT-5, 13, 5);
682 rb->lcd_mono_bitmap(needle_cover, half_width+quarter_width-6, LCD_HEIGHT-5, 13, 5);
683 rb->lcd_set_drawmode(DRMODE_SOLID);
685 /* Show Left/Right */
686 rb->lcd_putsxy(quarter_width-12, 12, "Left");
687 rb->lcd_putsxy(half_width+quarter_width-12, 12, "Right");
689 /* Line above/below the Left/Right text */
690 rb->lcd_hline(0,LCD_WIDTH-1,9);
691 rb->lcd_hline(0,LCD_WIDTH-1,21);
693 for(i=0; i<half_width; i++) {
694 rb->lcd_drawpixel(i, (y_values[i])-2);
695 rb->lcd_drawpixel(i+half_width, (y_values[i])-2);
699 void digital_meter(void) {
700 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
701 int left_peak = rb->mas_codec_readreg(0xC);
702 int right_peak = rb->mas_codec_readreg(0xD);
703 #elif (CONFIG_CODEC == SWCODEC)
704 int left_peak, right_peak;
705 rb->pcm_calculate_peaks(&left_peak, &right_peak);
706 #endif
708 if(vumeter_settings.digital_use_db_scale) {
709 num_left_leds = digital_db_scale[left_peak * 44 / MAX_PEAK];
710 num_right_leds = digital_db_scale[right_peak * 44 / MAX_PEAK];
712 else {
713 num_left_leds = left_peak * 11 / MAX_PEAK;
714 num_right_leds = right_peak * 11 / MAX_PEAK;
717 num_left_leds = (num_left_leds+last_num_left_leds*vumeter_settings.digital_decay)
718 /(vumeter_settings.digital_decay+1);
719 num_right_leds = (num_right_leds+last_num_right_leds*vumeter_settings.digital_decay)
720 /(vumeter_settings.digital_decay+1);
722 last_num_left_leds = num_left_leds;
723 last_num_right_leds = num_right_leds;
725 rb->lcd_set_drawmode(DRMODE_FG);
726 /* LEDS */
727 for(i=0; i<num_left_leds; i++) {
728 #ifdef HAVE_LCD_COLOR
729 rb->lcd_set_foreground(LCD_RGBPACK(255, 255 - 23 * i, 0));
730 #endif
731 rb->lcd_fillrect((digital_lead + (i*digital_block_width)),
732 14, digital_block_width - digital_block_gap, digital_block_height);
735 for(i=0; i<num_right_leds; i++) {
736 #ifdef HAVE_LCD_COLOR
737 rb->lcd_set_foreground(LCD_RGBPACK(255, 255 - 23 * i, 0));
738 #endif
739 rb->lcd_fillrect((digital_lead + (i*digital_block_width)),
740 (half_height + 20), digital_block_width - digital_block_gap,
741 digital_block_height);
744 #ifdef HAVE_LCD_COLOR
745 rb->lcd_set_foreground(screen_foreground);
746 #endif
747 rb->lcd_set_drawmode(DRMODE_SOLID);
749 if(vumeter_settings.digital_minimeters)
750 draw_digital_minimeters();
752 /* Lines above/below where the LEDS are */
753 rb->lcd_hline(0,LCD_WIDTH-1,12);
754 rb->lcd_hline(0,LCD_WIDTH-1,half_height-12);
756 rb->lcd_hline(0,LCD_WIDTH-1,half_height+18);
757 rb->lcd_hline(0,LCD_WIDTH-1,LCD_HEIGHT-6);
759 /* Show Left/Right */
760 rb->lcd_putsxy(2, half_height-8, "Left");
761 rb->lcd_putsxy(2, half_height+8, "Right");
763 /* Line in the middle */
764 rb->lcd_hline(0,LCD_WIDTH-1,half_height+3);
767 enum plugin_status plugin_start(const void* parameter) {
768 int button;
769 int lastbutton = BUTTON_NONE;
771 (void) parameter;
773 calc_scales();
775 load_settings();
776 rb->lcd_setfont(FONT_SYSFIXED);
777 #ifdef HAVE_LCD_COLOR
778 screen_foreground = rb->lcd_get_foreground();
779 #endif
781 while (1)
783 rb->lcd_clear_display();
785 rb->lcd_putsxy(half_width-23, 0, "VU Meter");
787 if(vumeter_settings.meter_type==ANALOG)
788 analog_meter();
789 else
790 digital_meter();
792 rb->lcd_update();
794 button = rb->button_get_w_tmo(1);
795 switch (button)
797 #ifdef VUMETER_RC_QUIT
798 case VUMETER_RC_QUIT:
799 #endif
800 case VUMETER_QUIT:
801 save_settings();
802 return PLUGIN_OK;
803 break;
805 case VUMETER_HELP:
806 #ifdef VUMETER_HELP_PRE
807 if (lastbutton != VUMETER_HELP_PRE)
808 break;
809 #endif
810 rb->lcd_clear_display();
811 rb->lcd_puts(0, 0, LABEL_QUIT ": Exit");
812 rb->lcd_puts(0, 1, LABEL_MENU ": Settings");
813 rb->lcd_puts(0, 2, LABEL_VOLUME ": Volume");
814 rb->lcd_update();
815 rb->sleep(HZ*3);
816 break;
818 case VUMETER_MENU:
820 #ifdef VUMETER_MENU2
821 case VUMETER_MENU2:
822 #endif
824 #ifdef VUMETER_MENU_PRE
825 if (lastbutton != VUMETER_MENU_PRE)
826 break;
827 #endif
828 if(vu_meter_menu())
829 return PLUGIN_OK;
830 break;
832 case VUMETER_UP:
833 case VUMETER_UP | BUTTON_REPEAT:
834 change_volume(1);
835 break;
837 case VUMETER_DOWN:
838 case VUMETER_DOWN | BUTTON_REPEAT:
839 change_volume(-1);
840 break;
842 default:
843 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
844 return PLUGIN_USB_CONNECTED;
845 break;
847 if (button != BUTTON_NONE)
848 lastbutton = button;