FS#8708: D2/m:robe500 touchscreen keymaps by Andreas Mueller.
[kugel-rb.git] / apps / plugins / vu_meter.c
blobbdbab8ccf578474c19529644c3c9a23b82c8b8dc
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2003 Lee Pilgrim
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 **************************************************************************/
18 #include "plugin.h"
19 #include "fixedpoint.h"
21 #if defined(HAVE_LCD_BITMAP)
23 PLUGIN_HEADER
25 /* variable button definitions */
26 #if CONFIG_KEYPAD == RECORDER_PAD
27 #define VUMETER_QUIT BUTTON_OFF
28 #define VUMETER_HELP BUTTON_ON
29 #define VUMETER_MENU BUTTON_F1
30 #define VUMETER_MENU_EXIT BUTTON_F1
31 #define VUMETER_MENU_EXIT2 BUTTON_OFF
32 #define VUMETER_UP BUTTON_UP
33 #define VUMETER_DOWN BUTTON_DOWN
34 #define LABEL_HELP "ON"
35 #define LABEL_QUIT "OFF"
36 #define LABEL_MENU "F1"
37 #define LABEL_VOLUME "UP/DOWN"
39 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
40 #define VUMETER_QUIT BUTTON_OFF
41 #define VUMETER_HELP BUTTON_ON
42 #define VUMETER_MENU BUTTON_F1
43 #define VUMETER_MENU_EXIT BUTTON_F1
44 #define VUMETER_MENU_EXIT2 BUTTON_OFF
45 #define VUMETER_UP BUTTON_UP
46 #define VUMETER_DOWN BUTTON_DOWN
47 #define LABEL_HELP "ON"
48 #define LABEL_QUIT "OFF"
49 #define LABEL_MENU "F1"
50 #define LABEL_VOLUME "UP/DOWN"
52 #elif CONFIG_KEYPAD == ONDIO_PAD
53 #define VUMETER_QUIT BUTTON_OFF
54 #define VUMETER_HELP_PRE BUTTON_MENU
55 #define VUMETER_HELP (BUTTON_MENU | BUTTON_REL)
56 #define VUMETER_MENU_PRE BUTTON_MENU
57 #define VUMETER_MENU (BUTTON_MENU | BUTTON_REPEAT)
58 #define VUMETER_MENU_EXIT BUTTON_MENU
59 #define VUMETER_MENU_EXIT2 BUTTON_OFF
60 #define VUMETER_UP BUTTON_UP
61 #define VUMETER_DOWN BUTTON_DOWN
62 #define LABEL_HELP "MODE"
63 #define LABEL_QUIT "OFF"
64 #define LABEL_MENU "MODE.."
65 #define LABEL_VOLUME "UP/DOWN"
67 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
68 (CONFIG_KEYPAD == IRIVER_H300_PAD)
69 #define VUMETER_QUIT BUTTON_OFF
70 #define VUMETER_HELP BUTTON_ON
71 #define VUMETER_MENU BUTTON_SELECT
72 #define VUMETER_MENU2 BUTTON_MODE
73 #define VUMETER_MENU_EXIT BUTTON_SELECT
74 #define VUMETER_MENU_EXIT2 BUTTON_OFF
75 #define VUMETER_UP BUTTON_UP
76 #define VUMETER_DOWN BUTTON_DOWN
77 #define LABEL_HELP "PLAY"
78 #define LABEL_QUIT "STOP"
79 #define LABEL_MENU "SELECT,MODE"
80 #define LABEL_VOLUME "UP/DOWN"
82 #define VUMETER_RC_QUIT BUTTON_RC_STOP
84 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
85 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
86 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
87 #define VUMETER_QUIT BUTTON_MENU
88 #define VUMETER_HELP BUTTON_PLAY
89 #define VUMETER_MENU BUTTON_SELECT
90 #define VUMETER_MENU_EXIT BUTTON_SELECT
91 #define VUMETER_MENU_EXIT2 BUTTON_MENU
92 #define VUMETER_UP BUTTON_SCROLL_FWD
93 #define VUMETER_DOWN BUTTON_SCROLL_BACK
94 #define LABEL_HELP "PLAY"
95 #define LABEL_QUIT "MENU"
96 #define LABEL_MENU "SELECT"
97 #define LABEL_VOLUME "Wheel"
99 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
100 #define VUMETER_QUIT BUTTON_POWER
101 #define VUMETER_HELP BUTTON_A
102 #define VUMETER_MENU BUTTON_MENU
103 #define VUMETER_MENU_EXIT BUTTON_MENU
104 #define VUMETER_MENU_EXIT2 BUTTON_POWER
105 #define VUMETER_UP BUTTON_UP
106 #define VUMETER_DOWN BUTTON_DOWN
107 #define LABEL_HELP "A"
108 #define LABEL_QUIT "POWER"
109 #define LABEL_MENU "MENU"
110 #define LABEL_VOLUME "UP/DOWN"
112 #elif (CONFIG_KEYPAD == SANSA_E200_PAD)
113 #define VUMETER_QUIT BUTTON_POWER
114 #define VUMETER_HELP BUTTON_REC
115 #define VUMETER_MENU BUTTON_SELECT
116 #define VUMETER_MENU_EXIT BUTTON_SELECT
117 #define VUMETER_MENU_EXIT2 BUTTON_POWER
118 #define VUMETER_UP BUTTON_SCROLL_FWD
119 #define VUMETER_DOWN BUTTON_SCROLL_BACK
120 #define LABEL_HELP "REC"
121 #define LABEL_QUIT "POWER"
122 #define LABEL_MENU "SELECT"
123 #define LABEL_VOLUME "Wheel"
125 #elif (CONFIG_KEYPAD == SANSA_C200_PAD)
126 #define VUMETER_QUIT BUTTON_POWER
127 #define VUMETER_HELP BUTTON_REC
128 #define VUMETER_MENU BUTTON_SELECT
129 #define VUMETER_MENU_EXIT BUTTON_SELECT
130 #define VUMETER_MENU_EXIT2 BUTTON_POWER
131 #define VUMETER_UP BUTTON_VOL_UP
132 #define VUMETER_DOWN BUTTON_VOL_DOWN
133 #define LABEL_HELP "REC"
134 #define LABEL_QUIT "POWER"
135 #define LABEL_MENU "SELECT"
136 #define LABEL_VOLUME "VOL UP/DN"
138 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
139 #define VUMETER_QUIT BUTTON_POWER
140 #define VUMETER_HELP BUTTON_PLAY
141 #define VUMETER_MENU BUTTON_SELECT
142 #define VUMETER_MENU_EXIT BUTTON_SELECT
143 #define VUMETER_MENU_EXIT2 BUTTON_POWER
144 #define VUMETER_UP BUTTON_UP
145 #define VUMETER_DOWN BUTTON_DOWN
146 #define LABEL_HELP "PLAY"
147 #define LABEL_QUIT "POWER"
148 #define LABEL_MENU "SELECT"
149 #define LABEL_VOLUME "UP/DOWN"
151 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
152 #define VUMETER_QUIT BUTTON_POWER
153 #define VUMETER_HELP BUTTON_PLAY
154 #define VUMETER_MENU BUTTON_REW
155 #define VUMETER_MENU_EXIT BUTTON_REW
156 #define VUMETER_MENU_EXIT2 BUTTON_POWER
157 #define VUMETER_UP BUTTON_SCROLL_UP
158 #define VUMETER_DOWN BUTTON_SCROLL_DOWN
159 #define LABEL_HELP "PLAY"
160 #define LABEL_QUIT "POWER"
161 #define LABEL_MENU "REW"
162 #define LABEL_VOLUME "Scroller"
164 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
165 #define VUMETER_QUIT BUTTON_BACK
166 #define VUMETER_HELP BUTTON_NEXT
167 #define VUMETER_MENU BUTTON_MENU
168 #define VUMETER_MENU_EXIT BUTTON_MENU
169 #define VUMETER_MENU_EXIT2 BUTTON_PLAY
170 #define VUMETER_UP BUTTON_UP
171 #define VUMETER_DOWN BUTTON_DOWN
172 #define LABEL_HELP "NEXT"
173 #define LABEL_QUIT "BACK"
174 #define LABEL_MENU "MENU"
175 #define LABEL_VOLUME "UP/DOWN"
177 #elif (CONFIG_KEYPAD == MROBE100_PAD)
178 #define VUMETER_QUIT BUTTON_POWER
179 #define VUMETER_HELP BUTTON_DISPLAY
180 #define VUMETER_MENU BUTTON_MENU
181 #define VUMETER_MENU_EXIT BUTTON_MENU
182 #define VUMETER_MENU_EXIT2 BUTTON_POWER
183 #define VUMETER_UP BUTTON_UP
184 #define VUMETER_DOWN BUTTON_DOWN
185 #define LABEL_HELP "DISPLAY"
186 #define LABEL_QUIT "POWER"
187 #define LABEL_MENU "MENU"
188 #define LABEL_VOLUME "UP/DOWN"
190 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
191 #define VUMETER_QUIT BUTTON_RC_REC
192 #define VUMETER_HELP BUTTON_RC_MODE
193 #define VUMETER_MENU BUTTON_RC_MENU
194 #define VUMETER_MENU_EXIT BUTTON_RC_MENU
195 #define VUMETER_MENU_EXIT2 BUTTON_RC_REC
196 #define VUMETER_UP BUTTON_RC_VOL_UP
197 #define VUMETER_DOWN BUTTON_RC_VOL_DOWN
198 #define LABEL_HELP "MODE"
199 #define LABEL_QUIT "REC"
200 #define LABEL_MENU "MENU"
201 #define LABEL_VOLUME "VOL UP/DN"
203 #elif CONFIG_KEYPAD == COWOND2_PAD
204 #define VUMETER_QUIT BUTTON_POWER
205 #define VUMETER_MENU BUTTON_MENU
206 #define VUMETER_MENU_EXIT BUTTON_POWER
207 #define LABEL_QUIT "POWER"
208 #define LABEL_MENU "MENU"
210 #else
211 #error No keymap defined!
212 #endif
214 #ifdef HAVE_TOUCHPAD
215 #ifndef VUMETER_QUIT
216 #define VUMETER_QUIT BUTTON_TOPLEFT
217 #define LABEL_QUIT "TOPLEFT"
218 #endif
219 #ifndef VUMETER_HELP
220 #define VUMETER_HELP BUTTON_CENTER
221 #define LABEL_HELP "CENTRE"
222 #endif
223 #ifndef VUMETER_MENU
224 #define VUMETER_MENU BUTTON_TOPRIGHT
225 #define LABEL_MENU "TOPRIGHT"
226 #endif
227 #ifndef VUMETER_MENU_EXIT
228 #define VUMETER_MENU_EXIT BUTTON_TOPLEFT
229 #endif
230 #ifndef VUMETER_UP
231 #define VUMETER_UP BUTTON_TOPMIDDLE
232 #endif
233 #ifndef VUMETER_DOWN
234 #define VUMETER_DOWN BUTTON_BOTTOMMIDDLE
235 #endif
236 #ifndef LABEL_VOLUME
237 #define LABEL_VOLUME "UP/DOWN"
238 #endif
239 #endif
241 const struct plugin_api* rb;
243 #if defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
244 #define mas_codec_readreg(x) rand()%MAX_PEAK
245 #endif
247 /* Defines x positions on a logarithmic (dBfs) scale. */
248 unsigned char analog_db_scale[LCD_WIDTH/2];
250 /* Define's y positions, to make the needle arch, like a real needle would. */
251 unsigned char y_values[LCD_WIDTH/2];
253 const unsigned char digital_db_scale[] =
254 {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,
255 10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11};
257 const unsigned char needle_cover[] =
258 {0x18, 0x1c, 0x1c, 0x1e, 0x1e, 0x1f, 0x1f, 0x1f, 0x1e, 0x1e, 0x1c, 0x1c, 0x18};
260 const unsigned char sound_speaker[] = {0x18,0x24,0x42,0xFF};
261 const unsigned char sound_low_level[] = {0x24,0x18};
262 const unsigned char sound_med_level[] = {0x42,0x3C};
263 const unsigned char sound_high_level[] = {0x81,0x7E};
264 const unsigned char sound_max_level[] = {0x0E,0xDF,0x0E};
266 const int half_width = LCD_WIDTH / 2;
267 const int quarter_width = LCD_WIDTH / 4;
268 const int half_height = LCD_HEIGHT / 2;
270 /* approx ratio of the previous hard coded values */
271 const int analog_mini_1 = (LCD_WIDTH / 2)*0.1;
272 const int analog_mini_2 = (LCD_WIDTH / 2)*0.25;
273 const int analog_mini_3 = (LCD_WIDTH / 2)*0.4;
274 const int analog_mini_4 = (LCD_WIDTH / 2)*0.75;
276 const int digital_block_width = LCD_WIDTH / 11;
277 const int digital_block_gap = (int)(LCD_WIDTH / 11) / 10;
278 /* ammount to lead in on left so 11x blocks are centered - is often 0 */
279 const int digital_lead = (LCD_WIDTH - (((int)(LCD_WIDTH / 11))*11) ) / 2;
281 const int digital_block_height = (LCD_HEIGHT - 54) / 2 ;
283 #define ANALOG 0 /* The two meter types */
284 #define DIGITAL 1
286 int left_needle_top_y;
287 int left_needle_top_x;
288 int last_left_needle_top_x;
289 int right_needle_top_y;
290 int right_needle_top_x;
291 int last_right_needle_top_x = LCD_WIDTH / 2;
293 int num_left_leds;
294 int num_right_leds;
295 int last_num_left_leds;
296 int last_num_right_leds;
298 int i;
300 #define MAX_PEAK 0x8000
302 /* gap at the top for left/right etc */
303 #define NEEDLE_TOP 25
305 /* pow(M_E, 5) * 65536 */
306 #define E_POW_5 9726404
308 struct saved_settings {
309 int meter_type;
310 bool analog_use_db_scale;
311 bool digital_use_db_scale;
312 bool analog_minimeters;
313 bool digital_minimeters;
314 int analog_decay;
315 int digital_decay;
316 } vumeter_settings;
318 void reset_settings(void) {
319 vumeter_settings.meter_type=ANALOG;
320 vumeter_settings.analog_use_db_scale=true;
321 vumeter_settings.digital_use_db_scale=true;
322 vumeter_settings.analog_minimeters=true;
323 vumeter_settings.digital_minimeters=false;
324 vumeter_settings.analog_decay=3;
325 vumeter_settings.digital_decay=0;
328 void calc_scales(void)
330 unsigned int fx_log_factor = E_POW_5/half_width;
331 unsigned int y,z;
333 long j;
334 long k;
335 int nh = LCD_HEIGHT - NEEDLE_TOP;
336 long nh2 = nh*nh;
338 for (i=1; i <= half_width; i++)
340 /* analog scale */
341 y = (half_width/5)*flog(i*fx_log_factor);
343 /* better way of checking for negative values? */
344 z = y>>16;
345 if (z > LCD_WIDTH)
346 z = 0;
348 analog_db_scale[i-1] = z;
349 /* play nice */
350 rb->yield();
352 /* y values (analog needle co-ords) */
353 j = i - (int)(half_width/2);
354 k = nh2 - ( j * j );
356 /* fsqrt+1 seems to give a closer approximation */
357 y_values[i-1] = LCD_HEIGHT - (fsqrt(k, 16)>>8) - 1;
358 rb->yield();
362 void load_settings(void) {
363 int fp = rb->open(PLUGIN_DEMOS_DIR "/.vu_meter", O_RDONLY);
364 if(fp>=0) {
365 rb->read(fp, &vumeter_settings, sizeof(struct saved_settings));
366 rb->close(fp);
368 else {
369 reset_settings();
370 rb->splash(HZ, "Press " LABEL_HELP " for help");
374 void save_settings(void) {
375 int fp = rb->creat(PLUGIN_DEMOS_DIR "/.vu_meter");
376 if(fp >= 0) {
377 rb->write (fp, &vumeter_settings, sizeof(struct saved_settings));
378 rb->close(fp);
382 void change_volume(int delta) {
383 char curr_vol[5];
384 int minvol = rb->sound_min(SOUND_VOLUME);
385 int maxvol = rb->sound_max(SOUND_VOLUME);
386 int vol = rb->global_settings->volume + delta;
388 if (vol > maxvol) vol = maxvol;
389 else if (vol < minvol) vol = minvol;
390 if (vol != rb->global_settings->volume) {
391 rb->sound_set(SOUND_VOLUME, vol);
392 rb->global_settings->volume = vol;
393 rb->snprintf(curr_vol, sizeof(curr_vol), "%d", vol);
394 rb->lcd_putsxy(0,0, curr_vol);
395 rb->lcd_update();
396 rb->sleep(HZ/12);
400 static bool vu_meter_menu(void)
402 int selection;
403 bool menu_quit = false;
404 bool exit = false;
406 MENUITEM_STRINGLIST(menu,"VU Meter Menu",NULL,"Meter Type","Scale",
407 "Minimeters","Decay Speed","Quit");
409 static const struct opt_items meter_type_option[2] = {
410 { "Analog", -1 },
411 { "Digital", -1 },
414 static const struct opt_items decay_speed_option[7] = {
415 { "No Decay", -1 },
416 { "Very Fast", -1 },
417 { "Fast", -1 },
418 { "Medium", -1 },
419 { "Medium-Slow", -1 },
420 { "Slow", -1 },
421 { "Very Slow", -1 },
424 while (!menu_quit) {
425 switch(rb->do_menu(&menu, &selection, NULL, false))
427 case 0:
428 rb->set_option("Meter Type", &vumeter_settings.meter_type, INT,
429 meter_type_option, 2, NULL);
430 break;
432 case 1:
433 if(vumeter_settings.meter_type==ANALOG)
435 rb->set_bool_options("Scale", &vumeter_settings.analog_use_db_scale,
436 "dBfs", -1, "Linear", -1, NULL);
438 else
440 rb->set_bool_options("Scale", &vumeter_settings.digital_use_db_scale,
441 "dBfs", -1, "Linear", -1, NULL);
443 break;
445 case 2:
446 if(vumeter_settings.meter_type==ANALOG)
448 rb->set_bool("Enable Minimeters",
449 &vumeter_settings.analog_minimeters);
451 else
453 rb->set_bool("Enable Minimeters",
454 &vumeter_settings.digital_minimeters);
456 break;
458 case 3:
459 if(vumeter_settings.meter_type==ANALOG)
461 rb->set_option("Decay Speed", &vumeter_settings.analog_decay, INT,
462 decay_speed_option, 7, NULL);
464 else
466 rb->set_option("Decay Speed", &vumeter_settings.digital_decay, INT,
467 decay_speed_option, 7, NULL);
469 break;
471 case 4:
472 exit = true;
473 /* fall through to exit the menu */
474 default:
475 menu_quit = true;
476 break;
479 /* the menu uses the userfont, set it back to sysfont */
480 rb->lcd_setfont(FONT_SYSFIXED);
481 return exit;
484 void draw_analog_minimeters(void) {
485 rb->lcd_mono_bitmap(sound_speaker, quarter_width-28, 12, 4, 8);
486 rb->lcd_set_drawmode(DRMODE_FG);
487 if(analog_mini_1<left_needle_top_x)
488 rb->lcd_mono_bitmap(sound_low_level, quarter_width-23, 12, 2, 8);
489 if(analog_mini_2<left_needle_top_x)
490 rb->lcd_mono_bitmap(sound_med_level, quarter_width-21, 12, 2, 8);
491 if(analog_mini_3<left_needle_top_x)
492 rb->lcd_mono_bitmap(sound_high_level, quarter_width-19, 12, 2, 8);
493 if(analog_mini_4<left_needle_top_x)
494 rb->lcd_mono_bitmap(sound_max_level, quarter_width-16, 12, 3, 8);
496 rb->lcd_set_drawmode(DRMODE_SOLID);
497 rb->lcd_mono_bitmap(sound_speaker, quarter_width+half_width-30, 12, 4, 8);
498 rb->lcd_set_drawmode(DRMODE_FG);
499 if(analog_mini_1<(right_needle_top_x-half_width))
500 rb->lcd_mono_bitmap(sound_low_level, quarter_width+half_width-25, 12, 2, 8);
501 if(analog_mini_2<(right_needle_top_x-half_width))
502 rb->lcd_mono_bitmap(sound_med_level, quarter_width+half_width-23, 12, 2, 8);
503 if(analog_mini_3<(right_needle_top_x-half_width))
504 rb->lcd_mono_bitmap(sound_high_level, quarter_width+half_width-21, 12, 2, 8);
505 if(analog_mini_4<(right_needle_top_x-half_width))
506 rb->lcd_mono_bitmap(sound_max_level, quarter_width+half_width-18, 12, 3, 8);
507 rb->lcd_set_drawmode(DRMODE_SOLID);
510 void draw_digital_minimeters(void) {
511 rb->lcd_mono_bitmap(sound_speaker, 34, half_height-8, 4, 8);
512 rb->lcd_set_drawmode(DRMODE_FG);
513 if(1<num_left_leds)
514 rb->lcd_mono_bitmap(sound_low_level, 39, half_height-8, 2, 8);
515 if(2<num_left_leds)
516 rb->lcd_mono_bitmap(sound_med_level, 41, half_height-8, 2, 8);
517 if(5<num_left_leds)
518 rb->lcd_mono_bitmap(sound_high_level, 43, half_height-8, 2, 8);
519 if(8<num_left_leds)
520 rb->lcd_mono_bitmap(sound_max_level, 46, half_height-8, 3, 8);
522 rb->lcd_set_drawmode(DRMODE_SOLID);
523 rb->lcd_mono_bitmap(sound_speaker, 34, half_height+8, 4, 8);
524 rb->lcd_set_drawmode(DRMODE_FG);
525 if(1<(num_right_leds))
526 rb->lcd_mono_bitmap(sound_low_level, 39, half_height+8, 2, 8);
527 if(2<(num_right_leds))
528 rb->lcd_mono_bitmap(sound_med_level, 41, half_height+8, 2, 8);
529 if(5<(num_right_leds))
530 rb->lcd_mono_bitmap(sound_high_level, 43, half_height+8, 2, 8);
531 if(8<(num_right_leds))
532 rb->lcd_mono_bitmap(sound_max_level, 46, half_height+8, 3, 8);
533 rb->lcd_set_drawmode(DRMODE_SOLID);
536 void analog_meter(void) {
538 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
539 int left_peak = rb->mas_codec_readreg(0xC);
540 int right_peak = rb->mas_codec_readreg(0xD);
541 #elif (CONFIG_CODEC == SWCODEC)
542 int left_peak, right_peak;
543 rb->pcm_calculate_peaks(&left_peak, &right_peak);
544 #endif
546 if(vumeter_settings.analog_use_db_scale) {
547 left_needle_top_x = analog_db_scale[left_peak * half_width / MAX_PEAK];
548 right_needle_top_x = analog_db_scale[right_peak * half_width / MAX_PEAK] + half_width;
550 else {
551 left_needle_top_x = left_peak * half_width / MAX_PEAK;
552 right_needle_top_x = right_peak * half_width / MAX_PEAK + half_width;
555 /* Makes a decay on the needle */
556 left_needle_top_x = (left_needle_top_x+last_left_needle_top_x*vumeter_settings.analog_decay)
557 /(vumeter_settings.analog_decay+1);
558 right_needle_top_x = (right_needle_top_x+last_right_needle_top_x*vumeter_settings.analog_decay)
559 /(vumeter_settings.analog_decay+1);
561 last_left_needle_top_x = left_needle_top_x;
562 last_right_needle_top_x = right_needle_top_x;
564 left_needle_top_y = y_values[left_needle_top_x];
565 right_needle_top_y = y_values[right_needle_top_x-half_width];
567 /* Needles */
568 rb->lcd_drawline(quarter_width, LCD_HEIGHT-1, left_needle_top_x, left_needle_top_y);
569 rb->lcd_drawline((quarter_width+half_width), LCD_HEIGHT-1, right_needle_top_x, right_needle_top_y);
571 if(vumeter_settings.analog_minimeters)
572 draw_analog_minimeters();
574 /* Needle covers */
575 rb->lcd_set_drawmode(DRMODE_FG);
576 rb->lcd_mono_bitmap(needle_cover, quarter_width-6, LCD_HEIGHT-5, 13, 5);
577 rb->lcd_mono_bitmap(needle_cover, half_width+quarter_width-6, LCD_HEIGHT-5, 13, 5);
578 rb->lcd_set_drawmode(DRMODE_SOLID);
580 /* Show Left/Right */
581 rb->lcd_putsxy(quarter_width-12, 12, "Left");
582 rb->lcd_putsxy(half_width+quarter_width-12, 12, "Right");
584 /* Line above/below the Left/Right text */
585 rb->lcd_hline(0,LCD_WIDTH-1,9);
586 rb->lcd_hline(0,LCD_WIDTH-1,21);
588 for(i=0; i<half_width; i++) {
589 rb->lcd_drawpixel(i, (y_values[i])-2);
590 rb->lcd_drawpixel(i+half_width, (y_values[i])-2);
594 void digital_meter(void) {
595 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
596 int left_peak = rb->mas_codec_readreg(0xC);
597 int right_peak = rb->mas_codec_readreg(0xD);
598 #elif (CONFIG_CODEC == SWCODEC)
599 int left_peak, right_peak;
600 rb->pcm_calculate_peaks(&left_peak, &right_peak);
601 #endif
603 if(vumeter_settings.digital_use_db_scale) {
604 num_left_leds = digital_db_scale[left_peak * 44 / MAX_PEAK];
605 num_right_leds = digital_db_scale[right_peak * 44 / MAX_PEAK];
607 else {
608 num_left_leds = left_peak * 11 / MAX_PEAK;
609 num_right_leds = right_peak * 11 / MAX_PEAK;
612 num_left_leds = (num_left_leds+last_num_left_leds*vumeter_settings.digital_decay)
613 /(vumeter_settings.digital_decay+1);
614 num_right_leds = (num_right_leds+last_num_right_leds*vumeter_settings.digital_decay)
615 /(vumeter_settings.digital_decay+1);
617 last_num_left_leds = num_left_leds;
618 last_num_right_leds = num_right_leds;
620 rb->lcd_set_drawmode(DRMODE_FG);
621 /* LEDS */
622 for(i=0; i<num_left_leds; i++)
623 rb->lcd_fillrect((digital_lead + (i*digital_block_width)),
624 14, digital_block_width - digital_block_gap, digital_block_height);
626 for(i=0; i<num_right_leds; i++)
627 rb->lcd_fillrect((digital_lead + (i*digital_block_width)),
628 (half_height + 20), digital_block_width - digital_block_gap,
629 digital_block_height);
631 rb->lcd_set_drawmode(DRMODE_SOLID);
633 if(vumeter_settings.digital_minimeters)
634 draw_digital_minimeters();
636 /* Lines above/below where the LEDS are */
637 rb->lcd_hline(0,LCD_WIDTH-1,12);
638 rb->lcd_hline(0,LCD_WIDTH-1,half_height-12);
640 rb->lcd_hline(0,LCD_WIDTH-1,half_height+18);
641 rb->lcd_hline(0,LCD_WIDTH-1,LCD_HEIGHT-6);
643 /* Show Left/Right */
644 rb->lcd_putsxy(2, half_height-8, "Left");
645 rb->lcd_putsxy(2, half_height+8, "Right");
647 /* Line in the middle */
648 rb->lcd_hline(0,LCD_WIDTH-1,half_height+3);
651 enum plugin_status plugin_start(struct plugin_api* api, void* parameter) {
652 int button;
653 int lastbutton = BUTTON_NONE;
655 (void) parameter;
656 rb = api;
658 calc_scales();
660 load_settings();
661 rb->lcd_setfont(FONT_SYSFIXED);
663 while (1)
665 rb->lcd_clear_display();
667 rb->lcd_putsxy(half_width-23, 0, "VU Meter");
669 if(vumeter_settings.meter_type==ANALOG)
670 analog_meter();
671 else
672 digital_meter();
674 rb->lcd_update();
676 button = rb->button_get_w_tmo(1);
677 switch (button)
679 #ifdef VUMETER_RC_QUIT
680 case VUMETER_RC_QUIT:
681 #endif
682 case VUMETER_QUIT:
683 save_settings();
684 return PLUGIN_OK;
685 break;
687 case VUMETER_HELP:
688 #ifdef VUMETER_HELP_PRE
689 if (lastbutton != VUMETER_HELP_PRE)
690 break;
691 #endif
692 rb->lcd_clear_display();
693 rb->lcd_puts(0, 0, LABEL_QUIT ": Exit");
694 rb->lcd_puts(0, 1, LABEL_MENU ": Settings");
695 rb->lcd_puts(0, 2, LABEL_VOLUME ": Volume");
696 rb->lcd_update();
697 rb->sleep(HZ*3);
698 break;
700 case VUMETER_MENU:
702 #ifdef VUMETER_MENU2
703 case VUMETER_MENU2:
704 #endif
706 #ifdef VUMETER_MENU_PRE
707 if (lastbutton != VUMETER_MENU_PRE)
708 break;
709 #endif
710 if(vu_meter_menu())
711 return PLUGIN_OK;
712 break;
714 case VUMETER_UP:
715 case VUMETER_UP | BUTTON_REPEAT:
716 change_volume(1);
717 break;
719 case VUMETER_DOWN:
720 case VUMETER_DOWN | BUTTON_REPEAT:
721 change_volume(-1);
722 break;
724 default:
725 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
726 return PLUGIN_USB_CONNECTED;
727 break;
729 if (button != BUTTON_NONE)
730 lastbutton = button;
733 #endif /* #ifdef HAVE_LCD_BITMAP */