Fix pdbox makefile to actually take part in dependency generation
[kugel-rb.git] / apps / plugins / pdbox / PDa / src / g_vumeter.c
blob328db2474263fd1e686cb04802540be069793349
1 /* Copyright (c) 1997-1999 Miller Puckette.
2 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
3 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
5 /* g_7_guis.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */
6 /* thanks to Miller Puckette, Guenther Geiger and Krzystof Czaja */
8 #ifdef ROCKBOX
9 #include "plugin.h"
10 #include "../../pdbox.h"
11 #include "m_pd.h"
12 #include "g_canvas.h"
13 #include "g_all_guis.h"
14 #else /* ROCKBOX */
15 #include <stdlib.h>
16 #include <string.h>
17 #include <stdio.h>
18 #include <ctype.h>
19 #include "m_pd.h"
20 #include "g_canvas.h"
21 #include "t_tk.h"
22 #include "g_all_guis.h"
23 #include <math.h>
25 #ifdef MSW
26 #include <io.h>
27 #else
28 #include <unistd.h>
29 #endif
30 #endif /* ROCKBOX */
32 /* ----- vu gui-peak- & rms- vu-meter-display ---------- */
34 t_widgetbehavior vu_widgetbehavior;
35 static t_class *vu_class;
37 /* widget helper functions */
39 static void vu_update_rms(t_vu *x, t_glist *glist)
41 #ifdef ROCKBOX
42 (void) x;
43 (void) glist;
44 #else /* ROCKBOX */
45 if(glist_isvisible(glist))
47 int w4=x->x_gui.x_w/4, off=text_ypix(&x->x_gui.x_obj, glist)-1;
48 int xpos=text_xpix(&x->x_gui.x_obj, glist), quad1=xpos+w4+1, quad3=xpos+x->x_gui.x_w-w4-1;
50 sys_vgui(".x%x.c coords %xRCOVER %d %d %d %d\n",
51 glist_getcanvas(glist), x, quad1, off, quad3,
52 off + (x->x_led_size+1)*(IEM_VU_STEPS-x->x_rms));
54 #endif /* ROCKBOX */
57 static void vu_update_peak(t_vu *x, t_glist *glist)
59 #ifdef ROCKBOX
60 (void) x;
61 (void) glist;
62 #else /* ROCKBOX */
63 t_canvas *canvas=glist_getcanvas(glist);
65 if(glist_isvisible(glist))
67 int xpos=text_xpix(&x->x_gui.x_obj, glist);
68 int ypos=text_ypix(&x->x_gui.x_obj, glist);
70 if(x->x_peak)
72 int i=iemgui_vu_col[x->x_peak];
73 int j=ypos + (x->x_led_size+1)*(IEM_VU_STEPS+1-x->x_peak)
74 - (x->x_led_size+1)/2;
76 sys_vgui(".x%x.c coords %xPLED %d %d %d %d\n", canvas, x,
77 xpos, j,
78 xpos+x->x_gui.x_w+1, j);
79 sys_vgui(".x%x.c itemconfigure %xPLED -fill #%6.6x\n", canvas, x,
80 iemgui_color_hex[i]);
82 else
84 int mid=xpos+x->x_gui.x_w/2;
86 sys_vgui(".x%x.c itemconfigure %xPLED -fill #%6.6x\n",
87 canvas, x, x->x_gui.x_bcol);
88 sys_vgui(".x%x.c coords %xPLED %d %d %d %d\n",
89 canvas, x, mid, ypos+20,
90 mid, ypos+20);
93 #endif /* ROCKBOX */
96 static void vu_draw_new(t_vu *x, t_glist *glist)
98 #ifdef ROCKBOX
99 (void) x;
100 (void) glist;
101 #else /* ROCKBOX */
102 t_canvas *canvas=glist_getcanvas(glist);
104 int xpos=text_xpix(&x->x_gui.x_obj, glist);
105 int ypos=text_ypix(&x->x_gui.x_obj, glist);
106 int w4=x->x_gui.x_w/4, mid=xpos+x->x_gui.x_w/2,
107 quad1=xpos+w4+1;
108 int quad3=xpos+x->x_gui.x_w-w4,
109 end=xpos+x->x_gui.x_w+4;
110 int k1=x->x_led_size+1, k2=IEM_VU_STEPS+1, k3=k1/2;
111 int led_col, yyy, i, k4=ypos-k3;
113 sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -tags %xBASE\n",
114 canvas, xpos-1, ypos-2,
115 xpos+x->x_gui.x_w+1,
116 ypos+x->x_gui.x_h+2, x->x_gui.x_bcol, x);
117 for(i=1; i<=IEM_VU_STEPS; i++)
119 led_col = iemgui_vu_col[i];
120 yyy = k4 + k1*(k2-i);
121 sys_vgui(".x%x.c create line %d %d %d %d -width %d -fill #%6.6x -tags %xRLED%d\n",
122 canvas, quad1, yyy, quad3, yyy, x->x_led_size, iemgui_color_hex[led_col], x, i);
123 if(((i+2)&3) && (x->x_scale))
124 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
125 -font {%s %d bold} -fill #%6.6x -tags %xSCALE%d\n",
126 canvas, end, yyy+k3, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize,
127 x->x_gui.x_lcol, x, i);
129 if(x->x_scale)
131 i=IEM_VU_STEPS+1;
132 yyy = k4 + k1*(k2-i);
133 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
134 -font {%s %d bold} -fill #%6.6x -tags %xSCALE%d\n",
135 canvas, end, yyy+k3, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize,
136 x->x_gui.x_lcol, x, i);
138 sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -outline #%6.6x -tags %xRCOVER\n",
139 canvas, quad1, ypos-1, quad3-1,
140 ypos-1 + k1*IEM_VU_STEPS, x->x_gui.x_bcol, x->x_gui.x_bcol, x);
141 sys_vgui(".x%x.c create line %d %d %d %d -width %d -fill #%6.6x -tags %xPLED\n",
142 canvas, mid, ypos+10,
143 mid, ypos+10, x->x_led_size, x->x_gui.x_bcol, x);
144 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
145 -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
146 canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy,
147 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
148 x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
149 if(!x->x_gui.x_fsf.x_snd_able)
151 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
152 canvas,
153 xpos-1, ypos + x->x_gui.x_h+1,
154 xpos + IOWIDTH-1, ypos + x->x_gui.x_h+2,
155 x, 0);
156 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
157 canvas,
158 xpos+x->x_gui.x_w+1-IOWIDTH, ypos + x->x_gui.x_h+1,
159 xpos+x->x_gui.x_w+1, ypos + x->x_gui.x_h+2,
160 x, 1);
162 if(!x->x_gui.x_fsf.x_rcv_able)
164 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
165 canvas,
166 xpos-1, ypos-2,
167 xpos + IOWIDTH-1, ypos-1,
168 x, 0);
169 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
170 canvas,
171 xpos+x->x_gui.x_w+1-IOWIDTH, ypos-2,
172 xpos+x->x_gui.x_w+1, ypos-1,
173 x, 1);
175 #endif /* ROCKBOX */
179 static void vu_draw_move(t_vu *x, t_glist *glist)
181 #ifdef ROCKBOX
182 (void) x;
183 (void) glist;
184 #else /* ROCKBOX */
185 t_canvas *canvas=glist_getcanvas(glist);
187 int xpos=text_xpix(&x->x_gui.x_obj, glist);
188 int ypos=text_ypix(&x->x_gui.x_obj, glist);
189 int w4=x->x_gui.x_w/4, quad1=xpos+w4+1;
190 int quad3=xpos+x->x_gui.x_w-w4,
191 end=xpos+x->x_gui.x_w+4;
192 int k1=x->x_led_size+1, k2=IEM_VU_STEPS+1, k3=k1/2;
193 int yyy, i, k4=ypos-k3;
195 sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
196 canvas, x, xpos-1, ypos-2,
197 xpos+x->x_gui.x_w+1,ypos+x->x_gui.x_h+2);
198 for(i=1; i<=IEM_VU_STEPS; i++)
200 yyy = k4 + k1*(k2-i);
201 sys_vgui(".x%x.c coords %xRLED%d %d %d %d %d\n",
202 canvas, x, i, quad1, yyy, quad3, yyy);
203 if(((i+2)&3) && (x->x_scale))
204 sys_vgui(".x%x.c coords %xSCALE%d %d %d\n",
205 canvas, x, i, end, yyy+k3);
207 if(x->x_scale)
209 i=IEM_VU_STEPS+1;
210 yyy = k4 + k1*(k2-i);
211 sys_vgui(".x%x.c coords %xSCALE%d %d %d\n",
212 canvas, x, i, end, yyy+k3);
214 vu_update_peak(x, glist);
215 vu_update_rms(x, glist);
216 sys_vgui(".x%x.c coords %xLABEL %d %d\n",
217 canvas, x, xpos+x->x_gui.x_ldx,
218 ypos+x->x_gui.x_ldy);
219 if(!x->x_gui.x_fsf.x_snd_able)
221 sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
222 canvas, x, 0,
223 xpos-1, ypos + x->x_gui.x_h+1,
224 xpos + IOWIDTH-1, ypos + x->x_gui.x_h+2);
225 sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
226 canvas, x, 1,
227 xpos+x->x_gui.x_w+1-IOWIDTH, ypos + x->x_gui.x_h+1,
228 xpos+x->x_gui.x_w+1, ypos + x->x_gui.x_h+2);
230 if(!x->x_gui.x_fsf.x_rcv_able)
232 sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
233 canvas, x, 0,
234 xpos-1, ypos-2,
235 xpos + IOWIDTH-1, ypos-1);
236 sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
237 canvas, x, 1,
238 xpos+x->x_gui.x_w+1-IOWIDTH, ypos-2,
239 xpos+x->x_gui.x_w+1, ypos-1);
241 #endif /* ROCKBOX */
244 static void vu_draw_erase(t_vu* x,t_glist* glist)
246 #ifdef ROCKBOX
247 (void) x;
248 (void) glist;
249 #else /* ROCKBOX */
250 int i;
251 t_canvas *canvas=glist_getcanvas(glist);
253 sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
254 for(i=1; i<=IEM_VU_STEPS; i++)
256 sys_vgui(".x%x.c delete %xRLED%d\n", canvas, x, i);
257 if(((i+2)&3) && (x->x_scale))
258 sys_vgui(".x%x.c delete %xSCALE%d\n", canvas, x, i);
260 if(x->x_scale)
262 i=IEM_VU_STEPS+1;
263 sys_vgui(".x%x.c delete %xSCALE%d\n", canvas, x, i);
265 sys_vgui(".x%x.c delete %xPLED\n", canvas, x);
266 sys_vgui(".x%x.c delete %xRCOVER\n", canvas, x);
267 sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
268 if(!x->x_gui.x_fsf.x_snd_able)
270 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
271 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 1);
273 if(!x->x_gui.x_fsf.x_rcv_able)
275 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
276 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 1);
278 #endif /* ROCKBOX */
281 static void vu_draw_config(t_vu* x, t_glist* glist)
283 #ifdef ROCKBOX
284 (void) x;
285 (void) glist;
286 #else /* ROCKBOX */
287 int i;
288 t_canvas *canvas=glist_getcanvas(glist);
290 sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n", canvas, x, x->x_gui.x_bcol);
291 for(i=1; i<=IEM_VU_STEPS; i++)
293 sys_vgui(".x%x.c itemconfigure %xRLED%d -width %d\n", canvas, x, i,
294 x->x_led_size);
295 if(((i+2)&3) && (x->x_scale))
296 sys_vgui(".x%x.c itemconfigure %xSCALE%d -text {%s} -font {%s %d bold} -fill #%6.6x\n",
297 canvas, x, i, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize,
298 x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol);
300 if(x->x_scale)
302 i=IEM_VU_STEPS+1;
303 sys_vgui(".x%x.c itemconfigure %xSCALE%d -text {%s} -font {%s %d bold} -fill #%6.6x\n",
304 canvas, x, i, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize,
305 x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol);
307 sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
308 canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
309 x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
310 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
312 sys_vgui(".x%x.c itemconfigure %xRCOVER -fill #%6.6x -outline #%6.6x\n", canvas,
313 x, x->x_gui.x_bcol, x->x_gui.x_bcol);
314 sys_vgui(".x%x.c itemconfigure %xPLED -width %d\n", canvas, x,
315 x->x_led_size);
316 #endif /* ROCKBOX */
319 static void vu_draw_io(t_vu* x, t_glist* glist, int old_snd_rcv_flags)
321 #ifdef ROCKBOX
322 (void) x;
323 (void) glist;
324 (void) old_snd_rcv_flags;
325 #else /* ROCKBOX */
326 int xpos=text_xpix(&x->x_gui.x_obj, glist);
327 int ypos=text_ypix(&x->x_gui.x_obj, glist);
328 t_canvas *canvas=glist_getcanvas(glist);
330 if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
332 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
333 canvas,
334 xpos-1, ypos + x->x_gui.x_h+1,
335 xpos + IOWIDTH-1, ypos + x->x_gui.x_h+2,
336 x, 0);
337 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
338 canvas,
339 xpos+x->x_gui.x_w+1-IOWIDTH, ypos + x->x_gui.x_h+1,
340 xpos+x->x_gui.x_w+1, ypos + x->x_gui.x_h+2,
341 x, 1);
343 if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
345 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
346 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 1);
348 if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
350 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
351 canvas,
352 xpos-1, ypos-2,
353 xpos + IOWIDTH-1, ypos-1,
354 x, 0);
355 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
356 canvas,
357 xpos+x->x_gui.x_w+1-IOWIDTH, ypos-2,
358 xpos+x->x_gui.x_w+1, ypos-1,
359 x, 1);
361 if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
363 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
364 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 1);
366 #endif /* ROCKBOX */
369 static void vu_draw_select(t_vu* x,t_glist* glist)
371 #ifdef ROCKBOX
372 (void) x;
373 (void) glist;
374 #else /* ROCKBOX */
375 int i;
376 t_canvas *canvas=glist_getcanvas(glist);
378 if(x->x_gui.x_fsf.x_selected)
380 sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
381 for(i=1; i<=IEM_VU_STEPS; i++)
383 if(((i+2)&3) && (x->x_scale))
384 sys_vgui(".x%x.c itemconfigure %xSCALE%d -fill #%6.6x\n",
385 canvas, x, i, IEM_GUI_COLOR_SELECTED);
387 if(x->x_scale)
389 i=IEM_VU_STEPS+1;
390 sys_vgui(".x%x.c itemconfigure %xSCALE%d -fill #%6.6x\n",
391 canvas, x, i, IEM_GUI_COLOR_SELECTED);
393 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
395 else
397 sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
398 for(i=1; i<=IEM_VU_STEPS; i++)
400 if(((i+2)&3) && (x->x_scale))
401 sys_vgui(".x%x.c itemconfigure %xSCALE%d -fill #%6.6x\n",
402 canvas, x, i, x->x_gui.x_lcol);
404 if(x->x_scale)
406 i=IEM_VU_STEPS+1;
407 sys_vgui(".x%x.c itemconfigure %xSCALE%d -fill #%6.6x\n",
408 canvas, x, i, x->x_gui.x_lcol);
410 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
412 #endif /* ROCKBOX */
415 void vu_draw(t_vu *x, t_glist *glist, int mode)
417 if(mode == IEM_GUI_DRAW_MODE_MOVE)
418 vu_draw_move(x, glist);
419 else if(mode == IEM_GUI_DRAW_MODE_NEW)
420 vu_draw_new(x, glist);
421 else if(mode == IEM_GUI_DRAW_MODE_SELECT)
422 vu_draw_select(x, glist);
423 else if(mode == IEM_GUI_DRAW_MODE_ERASE)
424 vu_draw_erase(x, glist);
425 else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
426 vu_draw_config(x, glist);
427 else if(mode >= IEM_GUI_DRAW_MODE_IO)
428 vu_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
431 /* ------------------------ vu widgetbehaviour----------------------------- */
434 static void vu_getrect(t_gobj *z, t_glist *glist,
435 int *xp1, int *yp1, int *xp2, int *yp2)
437 t_vu* x = (t_vu*)z;
439 *xp1 = text_xpix(&x->x_gui.x_obj, glist) - 1;
440 *yp1 = text_ypix(&x->x_gui.x_obj, glist) - 2;
441 *xp2 = *xp1 + x->x_gui.x_w + 2;
442 *yp2 = *yp1 + x->x_gui.x_h + 4;
445 static void vu_save(t_gobj *z, t_binbuf *b)
447 t_vu *x = (t_vu *)z;
448 int bflcol[3];
449 t_symbol *srl[3];
451 iemgui_save(&x->x_gui, srl, bflcol);
452 binbuf_addv(b, "ssiisiissiiiiiiii", gensym("#X"),gensym("obj"),
453 (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
454 gensym("vu"), x->x_gui.x_w, x->x_gui.x_h,
455 srl[1], srl[2],
456 x->x_gui.x_ldx, x->x_gui.x_ldy,
457 iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
458 bflcol[0], bflcol[2], x->x_scale,
459 iem_symargstoint(&x->x_gui.x_isa));
460 binbuf_addv(b, ";");
463 void vu_check_height(t_vu *x, int h)
465 int n;
467 n = h / IEM_VU_STEPS;
468 if(n < IEM_VU_MINSIZE)
469 n = IEM_VU_MINSIZE;
470 x->x_led_size = n-1;
471 x->x_gui.x_h = IEM_VU_STEPS * n;
474 static void vu_scale(t_vu *x, t_floatarg fscale)
476 #ifdef ROCKBOX
477 (void) x;
478 (void) fscale;
479 #else /* ROCKBOX */
480 int i, scale = (int)fscale;
482 if(scale != 0) scale = 1;
483 if(x->x_scale && !scale)
485 t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
487 x->x_scale = (int)scale;
488 if(glist_isvisible(x->x_gui.x_glist))
490 for(i=1; i<=IEM_VU_STEPS; i++)
492 if((i+2)&3)
493 sys_vgui(".x%x.c delete %xSCALE%d\n", canvas, x, i);
495 i=IEM_VU_STEPS+1;
496 sys_vgui(".x%x.c delete %xSCALE%d\n", canvas, x, i);
499 if(!x->x_scale && scale)
501 #ifdef ROCKBOX
502 int end=text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist)+x->x_gui.x_w+4;
503 #else /* ROCKBOX */
504 int w4=x->x_gui.x_w/4, end=text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist)+x->x_gui.x_w+4;
505 #endif /* ROCKBOX */
506 int k1=x->x_led_size+1, k2=IEM_VU_STEPS+1, k3=k1/2;
507 int yyy, k4=text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist)-k3;
508 t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
510 x->x_scale = (int)scale;
511 if(glist_isvisible(x->x_gui.x_glist))
513 for(i=1; i<=IEM_VU_STEPS; i++)
515 yyy = k4 + k1*(k2-i);
516 if((i+2)&3)
517 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
518 -font {%s %d bold} -fill #%6.6x -tags %xSCALE%d\n",
519 canvas, end, yyy+k3, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize,
520 x->x_gui.x_lcol, x, i);
522 i=IEM_VU_STEPS+1;
523 yyy = k4 + k1*(k2-i);
524 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
525 -font {%s %d bold} -fill #%6.6x -tags %xSCALE%d\n",
526 canvas, end, yyy+k3, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize,
527 x->x_gui.x_lcol, x, i);
530 #endif /* ROCKBOX */
533 static void vu_properties(t_gobj *z, t_glist *owner)
535 #ifdef ROCKBOX
536 (void) z;
537 (void) owner;
538 #else /* ROCKBOX */
539 t_vu *x = (t_vu *)z;
540 char buf[800];
541 t_symbol *srl[3];
543 iemgui_properties(&x->x_gui, srl);
544 sprintf(buf, "pdtk_iemgui_dialog %%s VU-METER \
545 --------dimensions(pix)(pix):-------- %d %d width: %d %d height: \
546 empty 0.0 empty 0.0 empty %d \
547 %d no_scale scale %d %d empty %d \
548 %s %s \
549 %s %d %d \
550 %d %d \
551 %d %d %d\n",
552 x->x_gui.x_w, IEM_GUI_MINSIZE, x->x_gui.x_h, IEM_VU_STEPS*IEM_VU_MINSIZE,
553 0,/*no_schedule*/
554 x->x_scale, -1, -1, -1,/*no linlog, no init, no multi*/
555 "nosndno", srl[1]->s_name,/*no send*/
556 srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
557 x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
558 0xffffff & x->x_gui.x_bcol, -1/*no front-color*/, 0xffffff & x->x_gui.x_lcol);
559 gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
560 #endif /* ROCKBOX */
563 static void vu_dialog(t_vu *x, t_symbol *s, int argc, t_atom *argv)
565 t_symbol *srl[3];
566 int w = (int)atom_getintarg(0, argc, argv);
567 int h = (int)atom_getintarg(1, argc, argv);
568 int scale = (int)atom_getintarg(4, argc, argv);
569 int sr_flags;
571 #ifdef ROCKBOX
572 (void) s;
573 #endif
575 srl[0] = gensym("empty");
576 sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
577 x->x_gui.x_fsf.x_snd_able = 0;
578 x->x_gui.x_isa.x_loadinit = 0;
579 x->x_gui.x_w = iemgui_clip_size(w);
580 vu_check_height(x, h);
581 if(scale != 0)
582 scale = 1;
583 vu_scale(x, (float)scale);
584 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
585 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
586 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
587 canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
590 static void vu_size(t_vu *x, t_symbol *s, int ac, t_atom *av)
592 #ifdef ROCKBOX
593 (void) s;
594 #endif
595 x->x_gui.x_w = iemgui_clip_size((int)atom_getintarg(0, ac, av));
596 if(ac > 1)
597 vu_check_height(x, (int)atom_getintarg(1, ac, av));
598 if(glist_isvisible(x->x_gui.x_glist))
600 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
601 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
602 canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
606 static void vu_delta(t_vu *x, t_symbol *s, int ac, t_atom *av)
607 {iemgui_delta((void *)x, &x->x_gui, s, ac, av);}
609 static void vu_pos(t_vu *x, t_symbol *s, int ac, t_atom *av)
610 {iemgui_pos((void *)x, &x->x_gui, s, ac, av);}
612 static void vu_color(t_vu *x, t_symbol *s, int ac, t_atom *av)
613 {iemgui_color((void *)x, &x->x_gui, s, ac, av);}
615 static void vu_receive(t_vu *x, t_symbol *s)
616 {iemgui_receive(x, &x->x_gui, s);}
618 static void vu_label(t_vu *x, t_symbol *s)
619 {iemgui_label((void *)x, &x->x_gui, s);}
621 static void vu_label_pos(t_vu *x, t_symbol *s, int ac, t_atom *av)
622 {iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);}
624 static void vu_label_font(t_vu *x, t_symbol *s, int ac, t_atom *av)
625 {iemgui_label_font((void *)x, &x->x_gui, s, ac, av);}
627 static void vu_float(t_vu *x, t_floatarg rms)
629 int i;
631 if(rms <= IEM_VU_MINDB)
632 x->x_rms = 0;
633 else if(rms >= IEM_VU_MAXDB)
634 x->x_rms = IEM_VU_STEPS;
635 else
637 int i = (int)(2.0*(rms + IEM_VU_OFFSET));
638 x->x_rms = iemgui_vu_db2i[i];
640 i = (int)(100.0*rms + 10000.5);
641 rms = 0.01*(float)(i - 10000);
642 x->x_fr = rms;
643 outlet_float(x->x_out_rms, rms);
644 vu_update_rms(x, x->x_gui.x_glist);
647 static void vu_ft1(t_vu *x, t_floatarg peak)
649 int i;
651 if(peak <= IEM_VU_MINDB)
652 x->x_peak = 0;
653 else if(peak >= IEM_VU_MAXDB)
654 x->x_peak = IEM_VU_STEPS;
655 else
657 int i = (int)(2.0*(peak + IEM_VU_OFFSET));
658 x->x_peak = iemgui_vu_db2i[i];
660 i = (int)(100.0*peak + 10000.5);
661 peak = 0.01*(float)(i - 10000);
662 x->x_fp = peak;
663 outlet_float(x->x_out_peak, peak);
664 vu_update_peak(x, x->x_gui.x_glist);
667 static void vu_bang(t_vu *x)
669 outlet_float(x->x_out_peak, x->x_fp);
670 outlet_float(x->x_out_rms, x->x_fr);
671 vu_update_rms(x, x->x_gui.x_glist);
672 vu_update_peak(x, x->x_gui.x_glist);
675 static void *vu_new(t_symbol *s, int argc, t_atom *argv)
677 t_vu *x = (t_vu *)pd_new(vu_class);
678 int bflcol[]={-66577, -1, -1};
679 int w=IEM_GUI_DEFAULTSIZE, h=IEM_VU_STEPS*IEM_VU_DEFAULTSIZE;
680 #ifdef ROCKBOX
681 int ldx=-1, ldy=-8, fs=8, scale=1;
682 (void) s;
683 #else /* ROCKBOX */
684 int ldx=-1, ldy=-8, f=0, fs=8, scale=1;
685 int ftbreak=IEM_BNG_DEFAULTBREAKFLASHTIME, fthold=IEM_BNG_DEFAULTHOLDFLASHTIME;
686 char str[144];
687 #endif /* ROCKBOX */
689 iem_inttosymargs(&x->x_gui.x_isa, 0);
690 iem_inttofstyle(&x->x_gui.x_fsf, 0);
692 if((argc >= 11)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)
693 &&(IS_A_SYMBOL(argv,2)||IS_A_FLOAT(argv,2))
694 &&(IS_A_SYMBOL(argv,3)||IS_A_FLOAT(argv,3))
695 &&IS_A_FLOAT(argv,4)&&IS_A_FLOAT(argv,5)
696 &&IS_A_FLOAT(argv,6)&&IS_A_FLOAT(argv,7)
697 &&IS_A_FLOAT(argv,8)&&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10))
699 w = (int)atom_getintarg(0, argc, argv);
700 h = (int)atom_getintarg(1, argc, argv);
701 iemgui_new_getnames(&x->x_gui, 1, argv);
702 ldx = (int)atom_getintarg(4, argc, argv);
703 ldy = (int)atom_getintarg(5, argc, argv);
704 iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(6, argc, argv));
705 fs = (int)atom_getintarg(7, argc, argv);
706 bflcol[0] = (int)atom_getintarg(8, argc, argv);
707 bflcol[2] = (int)atom_getintarg(9, argc, argv);
708 scale = (int)atom_getintarg(10, argc, argv);
710 else iemgui_new_getnames(&x->x_gui, 1, 0);
711 if((argc == 12)&&IS_A_FLOAT(argv,11))
712 iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(11, argc, argv));
713 x->x_gui.x_draw = (t_iemfunptr)vu_draw;
715 x->x_gui.x_fsf.x_snd_able = 0;
716 x->x_gui.x_fsf.x_rcv_able = 1;
717 x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
718 if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
719 x->x_gui.x_fsf.x_rcv_able = 0;
720 if (x->x_gui.x_fsf.x_font_style == 1)
721 strcpy(x->x_gui.x_font, "helvetica");
722 else if(x->x_gui.x_fsf.x_font_style == 2)
723 strcpy(x->x_gui.x_font, "times");
724 else { x->x_gui.x_fsf.x_font_style = 0;
725 strcpy(x->x_gui.x_font, "courier"); }
726 if(x->x_gui.x_fsf.x_rcv_able)
727 pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
728 x->x_gui.x_ldx = ldx;
729 x->x_gui.x_ldy = ldy;
731 if(fs < 4)
732 fs = 4;
733 x->x_gui.x_fontsize = fs;
734 x->x_gui.x_w = iemgui_clip_size(w);
735 vu_check_height(x, h);
736 iemgui_all_colfromload(&x->x_gui, bflcol);
737 if(scale != 0)
738 scale = 1;
739 x->x_scale = scale;
740 x->x_peak = 0;
741 x->x_rms = 0;
742 x->x_fp = -101.0;
743 x->x_fr = -101.0;
744 iemgui_verify_snd_ne_rcv(&x->x_gui);
745 inlet_new(&x->x_gui.x_obj, &x->x_gui.x_obj.ob_pd, &s_float, gensym("ft1"));
746 x->x_out_rms = outlet_new(&x->x_gui.x_obj, &s_float);
747 x->x_out_peak = outlet_new(&x->x_gui.x_obj, &s_float);
748 return (x);
751 static void vu_free(t_vu *x)
753 if(x->x_gui.x_fsf.x_rcv_able)
754 pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
755 #ifndef ROCKBOX
756 gfxstub_deleteforkey(x);
757 #endif
760 void g_vumeter_setup(void)
762 vu_class = class_new(gensym("vu"), (t_newmethod)vu_new, (t_method)vu_free,
763 sizeof(t_vu), 0, A_GIMME, 0);
764 class_addbang(vu_class,vu_bang);
765 class_addfloat(vu_class,vu_float);
766 class_addmethod(vu_class, (t_method)vu_ft1, gensym("ft1"), A_FLOAT, 0);
767 class_addmethod(vu_class, (t_method)vu_dialog, gensym("dialog"),
768 A_GIMME, 0);
769 class_addmethod(vu_class, (t_method)vu_size, gensym("size"), A_GIMME, 0);
770 class_addmethod(vu_class, (t_method)vu_scale, gensym("scale"), A_DEFFLOAT, 0);
771 class_addmethod(vu_class, (t_method)vu_delta, gensym("delta"), A_GIMME, 0);
772 class_addmethod(vu_class, (t_method)vu_pos, gensym("pos"), A_GIMME, 0);
773 class_addmethod(vu_class, (t_method)vu_color, gensym("color"), A_GIMME, 0);
774 class_addmethod(vu_class, (t_method)vu_receive, gensym("receive"), A_DEFSYM, 0);
775 class_addmethod(vu_class, (t_method)vu_label, gensym("label"), A_DEFSYM, 0);
776 class_addmethod(vu_class, (t_method)vu_label_pos, gensym("label_pos"), A_GIMME, 0);
777 class_addmethod(vu_class, (t_method)vu_label_font, gensym("label_font"), A_GIMME, 0);
778 vu_widgetbehavior.w_getrectfn = vu_getrect;
779 vu_widgetbehavior.w_displacefn = iemgui_displace;
780 vu_widgetbehavior.w_selectfn = iemgui_select;
781 vu_widgetbehavior.w_activatefn = NULL;
782 vu_widgetbehavior.w_deletefn = iemgui_delete;
783 vu_widgetbehavior.w_visfn = iemgui_vis;
784 vu_widgetbehavior.w_clickfn = NULL;
785 class_setwidget(vu_class,&vu_widgetbehavior);
786 class_sethelpsymbol(vu_class, gensym("vu"));
787 class_setsavefn(vu_class, vu_save);
788 class_setpropertiesfn(vu_class, vu_properties);