A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 796 lines 26 kB view raw
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. */ 4 5/* vdial.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */ 6 7/* name change to vradio by MSP (it's a radio button really) and changed to 8put out a "float" as in sliders, toggles, etc. */ 9 10#ifdef ROCKBOX 11#include "plugin.h" 12#include "../../pdbox.h" 13#include "m_pd.h" 14#include "g_canvas.h" 15#include "g_all_guis.h" 16#else /* ROCKBOX */ 17#include <stdlib.h> 18#include <string.h> 19#include <stdio.h> 20#include <ctype.h> 21#include "m_pd.h" 22#include "g_canvas.h" 23#include "t_tk.h" 24#include "g_all_guis.h" 25#include <math.h> 26#endif /* ROCKBOX */ 27 28/*------------------ global variables -------------------------*/ 29 30 31/*------------------ global functions -------------------------*/ 32 33 34 35 36/* ------------- vdl gui-vertical radio button ---------------------- */ 37 38t_widgetbehavior vradio_widgetbehavior; 39static t_class *vradio_class, *vradio_old_class; 40 41/* widget helper functions */ 42 43void vradio_draw_update(t_vradio *x, t_glist *glist) 44{ 45#ifdef ROCKBOX 46 (void) x; 47 (void) glist; 48#else /* ROCKBOX */ 49 if(glist_isvisible(glist)) 50 { 51 t_canvas *canvas=glist_getcanvas(glist); 52 53 sys_vgui(".x%x.c itemconfigure %xBUT%d -fill #%6.6x -outline #%6.6x\n", 54 canvas, x, x->x_on_old, 55 x->x_gui.x_bcol, x->x_gui.x_bcol); 56 sys_vgui(".x%x.c itemconfigure %xBUT%d -fill #%6.6x -outline #%6.6x\n", 57 canvas, x, x->x_on, 58 x->x_gui.x_fcol, x->x_gui.x_fcol); 59 } 60#endif /* ROCKBOX */ 61} 62 63void vradio_draw_new(t_vradio *x, t_glist *glist) 64{ 65#ifdef ROCKBOX 66 (void) x; 67 (void) glist; 68#else /* ROCKBOX */ 69 t_canvas *canvas=glist_getcanvas(glist); 70 int n=x->x_number, i, dy=x->x_gui.x_h, s4=dy/4; 71 int yy11b=text_ypix(&x->x_gui.x_obj, glist); 72 int yy11=yy11b, yy12=yy11+dy; 73 int yy21=yy11+s4, yy22=yy12-s4; 74 int xx11=text_xpix(&x->x_gui.x_obj, glist), xx12=xx11+dy; 75 int xx21=xx11+s4, xx22=xx12-s4; 76 77 for(i=0; i<n; i++) 78 { 79 sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -tags %xBASE%d\n", 80 canvas, xx11, yy11, xx12, yy12, 81 x->x_gui.x_bcol, x, i); 82 sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -outline #%6.6x -tags %xBUT%d\n", 83 canvas, xx21, yy21, xx22, yy22, 84 (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol, 85 (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol, x, i); 86 yy11 += dy; 87 yy12 += dy; 88 yy21 += dy; 89 yy22 += dy; 90 } 91 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \ 92 -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n", 93 canvas, xx11+x->x_gui.x_ldx, yy11b+x->x_gui.x_ldy, 94 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"", 95 x->x_gui.x_font, x->x_gui.x_fontsize, 96 x->x_gui.x_lcol, x); 97 if(!x->x_gui.x_fsf.x_snd_able) 98 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n", 99 canvas, xx11, yy11-1, xx11 + IOWIDTH, yy11, x, 0); 100 if(!x->x_gui.x_fsf.x_rcv_able) 101 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n", 102 canvas, xx11, yy11b, xx11 + IOWIDTH, yy11b+1, x, 0); 103#endif /* ROCKBOX */ 104} 105 106void vradio_draw_move(t_vradio *x, t_glist *glist) 107{ 108#ifdef ROCKBOX 109 (void) x; 110 (void) glist; 111#else /* ROCKBOX */ 112 t_canvas *canvas=glist_getcanvas(glist); 113 int n=x->x_number, i, dy=x->x_gui.x_h, s4=dy/4; 114 int yy11b=text_ypix(&x->x_gui.x_obj, glist); 115 int yy11=yy11b, yy12=yy11+dy; 116 int yy21=yy11+s4, yy22=yy12-s4; 117 int xx11=text_xpix(&x->x_gui.x_obj, glist), xx12=xx11+dy; 118 int xx21=xx11+s4, xx22=xx12-s4; 119 120 for(i=0; i<n; i++) 121 { 122 sys_vgui(".x%x.c coords %xBASE%d %d %d %d %d\n", 123 canvas, x, i, xx11, yy11, xx12, yy12); 124 sys_vgui(".x%x.c coords %xBUT%d %d %d %d %d\n", 125 canvas, x, i, xx21, yy21, xx22, yy22); 126 yy11 += dy; 127 yy12 += dy; 128 yy21 += dy; 129 yy22 += dy; 130 } 131 sys_vgui(".x%x.c coords %xLABEL %d %d\n", 132 canvas, x, xx11+x->x_gui.x_ldx, yy11b+x->x_gui.x_ldy); 133 if(!x->x_gui.x_fsf.x_snd_able) 134 sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n", 135 canvas, x, 0, xx11, yy11-1, xx11 + IOWIDTH, yy11); 136 if(!x->x_gui.x_fsf.x_rcv_able) 137 sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n", 138 canvas, x, 0, xx11, yy11b, xx11 + IOWIDTH, yy11b+1); 139#endif /* ROCKBOX */ 140} 141 142void vradio_draw_erase(t_vradio* x, t_glist* glist) 143{ 144#ifdef ROCKBOX 145 (void) x; 146 (void) glist; 147#else /* ROCKBOX */ 148 t_canvas *canvas=glist_getcanvas(glist); 149 int n=x->x_number, i; 150 151 for(i=0; i<n; i++) 152 { 153 sys_vgui(".x%x.c delete %xBASE%d\n", canvas, x, i); 154 sys_vgui(".x%x.c delete %xBUT%d\n", canvas, x, i); 155 } 156 sys_vgui(".x%x.c delete %xLABEL\n", canvas, x); 157 if(!x->x_gui.x_fsf.x_snd_able) 158 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0); 159 if(!x->x_gui.x_fsf.x_rcv_able) 160 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0); 161#endif /* ROCKBOX */ 162} 163 164void vradio_draw_config(t_vradio* x, t_glist* glist) 165{ 166#ifdef ROCKBOX 167 (void) x; 168 (void) glist; 169#else /* ROCKBOX */ 170 t_canvas *canvas=glist_getcanvas(glist); 171 int n=x->x_number, i; 172 173 sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n", 174 canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize, 175 x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol, 176 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:""); 177 for(i=0; i<n; i++) 178 { 179 sys_vgui(".x%x.c itemconfigure %xBASE%d -fill #%6.6x\n", canvas, x, i, 180 x->x_gui.x_bcol); 181 sys_vgui(".x%x.c itemconfigure %xBUT%d -fill #%6.6x -outline #%6.6x\n", canvas, x, i, 182 (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol, 183 (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol); 184 } 185#endif /* ROCKBOX */ 186} 187 188void vradio_draw_io(t_vradio* x, t_glist* glist, int old_snd_rcv_flags) 189{ 190#ifdef ROCKBOX 191 (void) x; 192 (void) glist; 193 (void) old_snd_rcv_flags; 194#else /* ROCKBOX */ 195 t_canvas *canvas=glist_getcanvas(glist); 196 int xpos=text_xpix(&x->x_gui.x_obj, glist); 197 int ypos=text_ypix(&x->x_gui.x_obj, glist); 198 199 if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able) 200 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n", 201 canvas, xpos, 202 ypos+(x->x_number*x->x_gui.x_h)-1, 203 xpos+ IOWIDTH, 204 ypos+(x->x_number*x->x_gui.x_h), x, 0); 205 if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able) 206 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0); 207 if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able) 208 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n", 209 canvas, xpos, ypos, 210 xpos+ IOWIDTH, ypos+1, 211 x, 0); 212 if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able) 213 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0); 214#endif /* ROCKBOX */ 215} 216 217void vradio_draw_select(t_vradio* x, t_glist* glist) 218{ 219#ifdef ROCKBOX 220 (void) x; 221 (void) glist; 222#else /* ROCKBOX */ 223 t_canvas *canvas=glist_getcanvas(glist); 224 int n=x->x_number, i; 225 226 if(x->x_gui.x_fsf.x_selected) 227 { 228 for(i=0; i<n; i++) 229 { 230 sys_vgui(".x%x.c itemconfigure %xBASE%d -outline #%6.6x\n", canvas, x, i, 231 IEM_GUI_COLOR_SELECTED); 232 } 233 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED); 234 } 235 else 236 { 237 for(i=0; i<n; i++) 238 { 239 sys_vgui(".x%x.c itemconfigure %xBASE%d -outline #%6.6x\n", canvas, x, i, 240 IEM_GUI_COLOR_NORMAL); 241 } 242 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, 243 x->x_gui.x_lcol); 244 } 245#endif /* ROCKBOX */ 246} 247 248void vradio_draw(t_vradio *x, t_glist *glist, int mode) 249{ 250 if(mode == IEM_GUI_DRAW_MODE_UPDATE) 251 vradio_draw_update(x, glist); 252 else if(mode == IEM_GUI_DRAW_MODE_MOVE) 253 vradio_draw_move(x, glist); 254 else if(mode == IEM_GUI_DRAW_MODE_NEW) 255 vradio_draw_new(x, glist); 256 else if(mode == IEM_GUI_DRAW_MODE_SELECT) 257 vradio_draw_select(x, glist); 258 else if(mode == IEM_GUI_DRAW_MODE_ERASE) 259 vradio_draw_erase(x, glist); 260 else if(mode == IEM_GUI_DRAW_MODE_CONFIG) 261 vradio_draw_config(x, glist); 262 else if(mode >= IEM_GUI_DRAW_MODE_IO) 263 vradio_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO); 264} 265 266/* ------------------------ vdl widgetbehaviour----------------------------- */ 267 268static void vradio_getrect(t_gobj *z, t_glist *glist, int *xp1, int *yp1, int *xp2, int *yp2) 269{ 270 t_vradio *x = (t_vradio *)z; 271 272 *xp1 = text_xpix(&x->x_gui.x_obj, glist); 273 *yp1 = text_ypix(&x->x_gui.x_obj, glist); 274 *xp2 = *xp1 + x->x_gui.x_w; 275 *yp2 = *yp1 + x->x_gui.x_h*x->x_number; 276} 277 278static void vradio_save(t_gobj *z, t_binbuf *b) 279{ 280 t_vradio *x = (t_vradio *)z; 281 int bflcol[3]; 282 t_symbol *srl[3]; 283 284 iemgui_save(&x->x_gui, srl, bflcol); 285 binbuf_addv(b, "ssiisiiiisssiiiiiiii", gensym("#X"),gensym("obj"), 286 (t_int)x->x_gui.x_obj.te_xpix, 287 (t_int)x->x_gui.x_obj.te_ypix, 288 (pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class ? 289 gensym("vdl") : gensym("vradio")), 290 x->x_gui.x_w, 291 x->x_change, iem_symargstoint(&x->x_gui.x_isa), x->x_number, 292 srl[0], srl[1], srl[2], 293 x->x_gui.x_ldx, x->x_gui.x_ldy, 294 iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize, 295 bflcol[0], bflcol[1], bflcol[2], x->x_on); 296 binbuf_addv(b, ";"); 297} 298 299static void vradio_properties(t_gobj *z, t_glist *owner) 300{ 301#ifdef ROCKBOX 302 (void) z; 303 (void) owner; 304#else /* ROCKBOX */ 305 t_vradio *x = (t_vradio *)z; 306 char buf[800]; 307 t_symbol *srl[3]; 308 int hchange=-1; 309 310 iemgui_properties(&x->x_gui, srl); 311 if(pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class) 312 hchange = x->x_change; 313 sprintf(buf, "pdtk_iemgui_dialog %%s vradio \ 314 ----------dimensions(pix):----------- %d %d size: 0 0 empty \ 315 empty 0.0 empty 0.0 empty %d \ 316 %d new-only new&old %d %d number: %d \ 317 %s %s \ 318 %s %d %d \ 319 %d %d \ 320 %d %d %d\n", 321 x->x_gui.x_w, IEM_GUI_MINSIZE, 322 0,/*no_schedule*/ 323 hchange, x->x_gui.x_isa.x_loadinit, -1, x->x_number, 324 srl[0]->s_name, srl[1]->s_name, 325 srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy, 326 x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize, 327 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol); 328 gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf); 329#endif /* ROCKBOX */ 330} 331 332static void vradio_dialog(t_vradio *x, t_symbol *s, int argc, t_atom *argv) 333{ 334 t_symbol *srl[3]; 335 int a = (int)atom_getintarg(0, argc, argv); 336 int chg = (int)atom_getintarg(4, argc, argv); 337 int num = (int)atom_getintarg(6, argc, argv); 338 int sr_flags; 339 340#ifdef ROCKBOX 341 (void) s; 342#endif 343 344 if(chg != 0) chg = 1; 345 x->x_change = chg; 346 sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv); 347 x->x_gui.x_w = iemgui_clip_size(a); 348 x->x_gui.x_h = x->x_gui.x_w; 349 if(x->x_number != num) 350 { 351 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE); 352 x->x_number = num; 353 if(x->x_on >= x->x_number) 354 { 355 x->x_on = x->x_number - 1; 356 x->x_on_old = x->x_on; 357 } 358 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW); 359 } 360 else 361 { 362 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG); 363 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags); 364 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE); 365 canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x); 366 } 367} 368 369static void vradio_set(t_vradio *x, t_floatarg f) 370{ 371 int i=(int)f; 372 int old; 373 374 if(i < 0) 375 i = 0; 376 if(i >= x->x_number) 377 i = x->x_number-1; 378 if(x->x_on != x->x_on_old) 379 { 380 old = x->x_on_old; 381 x->x_on_old = x->x_on; 382 x->x_on = i; 383 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); 384 x->x_on_old = old; 385 } 386 else 387 { 388 x->x_on = i; 389 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); 390 } 391} 392 393static void vradio_bang(t_vradio *x) 394{ 395 /* compatibility with earlier "vdial" behavior */ 396 if (pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class) 397 { 398 if((x->x_change)&&(x->x_on != x->x_on_old)) 399 { 400 SETFLOAT(x->x_at, (float)x->x_on_old); 401 SETFLOAT(x->x_at+1, 0.0); 402 outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at); 403 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) 404 pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at); 405 } 406 x->x_on_old = x->x_on; 407 SETFLOAT(x->x_at, (float)x->x_on); 408 SETFLOAT(x->x_at+1, 1.0); 409 outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at); 410 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) 411 pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at); 412 } 413 else 414 { 415 outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on); 416 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) 417 pd_float(x->x_gui.x_snd->s_thing, x->x_on); 418 } 419} 420 421static void vradio_fout(t_vradio *x, t_floatarg f) 422{ 423 int i=(int)f; 424 425 if(i < 0) 426 i = 0; 427 if(i >= x->x_number) 428 i = x->x_number-1; 429 430 if (pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class) 431 { 432 /* compatibility with earlier "vdial" behavior */ 433 if((x->x_change)&&(i != x->x_on_old)) 434 { 435 SETFLOAT(x->x_at, (float)x->x_on_old); 436 SETFLOAT(x->x_at+1, 0.0); 437 outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at); 438 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) 439 pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at); 440 } 441 if(x->x_on != x->x_on_old) 442 x->x_on_old = x->x_on; 443 x->x_on = i; 444 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); 445 x->x_on_old = x->x_on; 446 SETFLOAT(x->x_at, (float)x->x_on); 447 SETFLOAT(x->x_at+1, 1.0); 448 outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at); 449 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) 450 pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at); 451 } 452 else 453 { 454 x->x_on_old = x->x_on; 455 x->x_on = i; 456 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); 457 outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on); 458 if (x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) 459 pd_float(x->x_gui.x_snd->s_thing, x->x_on); 460 } 461} 462 463static void vradio_float(t_vradio *x, t_floatarg f) 464{ 465 int i=(int)f; 466 467 if(i < 0) 468 i = 0; 469 if(i >= x->x_number) 470 i = x->x_number-1; 471 472 if (pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class) 473 { 474 /* compatibility with earlier "vdial" behavior */ 475 if((x->x_change)&&(i != x->x_on_old)) 476 { 477 if(x->x_gui.x_fsf.x_put_in2out) 478 { 479 SETFLOAT(x->x_at, (float)x->x_on_old); 480 SETFLOAT(x->x_at+1, 0.0); 481 outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at); 482 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) 483 pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at); 484 } 485 } 486 if(x->x_on != x->x_on_old) 487 x->x_on_old = x->x_on; 488 x->x_on = i; 489 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); 490 x->x_on_old = x->x_on; 491 if(x->x_gui.x_fsf.x_put_in2out) 492 { 493 SETFLOAT(x->x_at, (float)x->x_on); 494 SETFLOAT(x->x_at+1, 1.0); 495 outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at); 496 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) 497 pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at); 498 } 499 } 500 else 501 { 502 x->x_on_old = x->x_on; 503 x->x_on = i; 504 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); 505 if (x->x_gui.x_fsf.x_put_in2out) 506 { 507 outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on); 508 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) 509 pd_float(x->x_gui.x_snd->s_thing, x->x_on); 510 } 511 } 512} 513 514static void vradio_click(t_vradio *x, t_floatarg xpos, t_floatarg ypos, 515 t_floatarg shift, t_floatarg ctrl, t_floatarg alt) 516{ 517 int yy = (int)ypos - text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist); 518 519#ifdef ROCKBOX 520 (void) xpos; 521 (void) shift; 522 (void) ctrl; 523 (void) alt; 524#endif 525 526 vradio_fout(x, (float)(yy / x->x_gui.x_h)); 527} 528 529static int vradio_newclick(t_gobj *z, struct _glist *glist, 530 int xpix, int ypix, int shift, int alt, int dbl, int doit) 531{ 532#ifdef ROCKBOX 533 (void) glist; 534 (void) dbl; 535#endif 536 if(doit) 537 vradio_click((t_vradio *)z, (t_floatarg)xpix, (t_floatarg)ypix, 538 (t_floatarg)shift, 0, (t_floatarg)alt); 539 return (1); 540} 541 542static void vradio_loadbang(t_vradio *x) 543{ 544 if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit) 545 vradio_bang(x); 546} 547 548static void vradio_number(t_vradio *x, t_floatarg num) 549{ 550 int n=(int)num; 551 552 if(n < 1) 553 n = 1; 554 if(n > IEM_RADIO_MAX) 555 n = IEM_RADIO_MAX; 556 if(n != x->x_number) 557 { 558 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE); 559 x->x_number = n; 560 if(x->x_on >= x->x_number) 561 x->x_on = x->x_number - 1; 562 x->x_on_old = x->x_on; 563 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW); 564 } 565} 566 567static void vradio_size(t_vradio *x, t_symbol *s, int ac, t_atom *av) 568{ 569#ifdef ROCKBOX 570 (void) s; 571#endif 572 x->x_gui.x_w = iemgui_clip_size((int)atom_getintarg(0, ac, av)); 573 x->x_gui.x_h = x->x_gui.x_w; 574 iemgui_size((void *)x, &x->x_gui); 575} 576 577static void vradio_delta(t_vradio *x, t_symbol *s, int ac, t_atom *av) 578{iemgui_delta((void *)x, &x->x_gui, s, ac, av);} 579 580static void vradio_pos(t_vradio *x, t_symbol *s, int ac, t_atom *av) 581{iemgui_pos((void *)x, &x->x_gui, s, ac, av);} 582 583static void vradio_color(t_vradio *x, t_symbol *s, int ac, t_atom *av) 584{iemgui_color((void *)x, &x->x_gui, s, ac, av);} 585 586static void vradio_send(t_vradio *x, t_symbol *s) 587{iemgui_send(x, &x->x_gui, s);} 588 589static void vradio_receive(t_vradio *x, t_symbol *s) 590{iemgui_receive(x, &x->x_gui, s);} 591 592static void vradio_label(t_vradio *x, t_symbol *s) 593{iemgui_label((void *)x, &x->x_gui, s);} 594 595static void vradio_label_pos(t_vradio *x, t_symbol *s, int ac, t_atom *av) 596{iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);} 597 598static void vradio_label_font(t_vradio *x, t_symbol *s, int ac, t_atom *av) 599{iemgui_label_font((void *)x, &x->x_gui, s, ac, av);} 600 601static void vradio_init(t_vradio *x, t_floatarg f) 602{ 603 x->x_gui.x_isa.x_loadinit = (f==0.0)?0:1; 604} 605 606static void vradio_double_change(t_vradio *x) 607{x->x_change = 1;} 608 609static void vradio_single_change(t_vradio *x) 610{x->x_change = 0;} 611 612static void *vradio_donew(t_symbol *s, int argc, t_atom *argv, int old) 613{ 614 t_vradio *x = (t_vradio *)pd_new(old? vradio_old_class : vradio_class); 615 int bflcol[]={-262144, -1, -1}; 616#ifdef ROCKBOX 617 int a=IEM_GUI_DEFAULTSIZE, on=0; 618#else 619 int a=IEM_GUI_DEFAULTSIZE, on=0, f=0; 620#endif 621 int ldx=0, ldy=-6, chg=1, num=8; 622 int fs=8; 623#ifndef ROCKBOX 624 int ftbreak=IEM_BNG_DEFAULTBREAKFLASHTIME, fthold=IEM_BNG_DEFAULTHOLDFLASHTIME; 625 char str[144]; 626#endif 627 628#ifdef ROCKBOX 629 (void) s; 630#endif 631 632 if((argc == 15)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)&&IS_A_FLOAT(argv,2) 633 &&IS_A_FLOAT(argv,3) 634 &&(IS_A_SYMBOL(argv,4)||IS_A_FLOAT(argv,4)) 635 &&(IS_A_SYMBOL(argv,5)||IS_A_FLOAT(argv,5)) 636 &&(IS_A_SYMBOL(argv,6)||IS_A_FLOAT(argv,6)) 637 &&IS_A_FLOAT(argv,7)&&IS_A_FLOAT(argv,8) 638 &&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10)&&IS_A_FLOAT(argv,11) 639 &&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13)&&IS_A_FLOAT(argv,14)) 640 { 641 a = (int)atom_getintarg(0, argc, argv); 642 chg = (int)atom_getintarg(1, argc, argv); 643 iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(2, argc, argv)); 644 num = (int)atom_getintarg(3, argc, argv); 645 iemgui_new_getnames(&x->x_gui, 4, argv); 646 ldx = (int)atom_getintarg(7, argc, argv); 647 ldy = (int)atom_getintarg(8, argc, argv); 648 iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(9, argc, argv)); 649 fs = (int)atom_getintarg(10, argc, argv); 650 bflcol[0] = (int)atom_getintarg(11, argc, argv); 651 bflcol[1] = (int)atom_getintarg(12, argc, argv); 652 bflcol[2] = (int)atom_getintarg(13, argc, argv); 653 on = (int)atom_getintarg(14, argc, argv); 654 } 655 else iemgui_new_getnames(&x->x_gui, 4, 0); 656 x->x_gui.x_draw = (t_iemfunptr)vradio_draw; 657 x->x_gui.x_fsf.x_snd_able = 1; 658 x->x_gui.x_fsf.x_rcv_able = 1; 659 x->x_gui.x_glist = (t_glist *)canvas_getcurrent(); 660 if (!strcmp(x->x_gui.x_snd->s_name, "empty")) 661 x->x_gui.x_fsf.x_snd_able = 0; 662 if (!strcmp(x->x_gui.x_rcv->s_name, "empty")) 663 x->x_gui.x_fsf.x_rcv_able = 0; 664 if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica"); 665 else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times"); 666 else { x->x_gui.x_fsf.x_font_style = 0; 667 strcpy(x->x_gui.x_font, "courier"); } 668 if(num < 1) 669 num = 1; 670 if(num > IEM_RADIO_MAX) 671 num = IEM_RADIO_MAX; 672 x->x_number = num; 673 if(on < 0) 674 on = 0; 675 if(on >= x->x_number) 676 on = x->x_number - 1; 677 if(x->x_gui.x_isa.x_loadinit) 678 x->x_on = on; 679 else 680 x->x_on = 0; 681 x->x_on_old = x->x_on; 682 x->x_change = (chg==0)?0:1; 683 if (x->x_gui.x_fsf.x_rcv_able) 684 pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv); 685 x->x_gui.x_ldx = ldx; 686 x->x_gui.x_ldy = ldy; 687 if(fs < 4) 688 fs = 4; 689 x->x_gui.x_fontsize = fs; 690 x->x_gui.x_w = iemgui_clip_size(a); 691 x->x_gui.x_h = x->x_gui.x_w; 692 iemgui_verify_snd_ne_rcv(&x->x_gui); 693 iemgui_all_colfromload(&x->x_gui, bflcol); 694 outlet_new(&x->x_gui.x_obj, &s_list); 695 return (x); 696} 697 698static void *vradio_new(t_symbol *s, int argc, t_atom *argv) 699{ 700 return (vradio_donew(s, argc, argv, 0)); 701} 702 703static void *vdial_new(t_symbol *s, int argc, t_atom *argv) 704{ 705 return (vradio_donew(s, argc, argv, 1)); 706} 707 708static void vradio_ff(t_vradio *x) 709{ 710 if(x->x_gui.x_fsf.x_rcv_able) 711 pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv); 712#ifndef ROCKBOX 713 gfxstub_deleteforkey(x); 714#endif 715} 716 717void g_vradio_setup(void) 718{ 719 vradio_class = class_new(gensym("vradio"), (t_newmethod)vradio_new, 720 (t_method)vradio_ff, sizeof(t_vradio), 0, A_GIMME, 0); 721 class_addbang(vradio_class, vradio_bang); 722 class_addfloat(vradio_class, vradio_float); 723 class_addmethod(vradio_class, (t_method)vradio_click, gensym("click"), 724 A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0); 725 class_addmethod(vradio_class, (t_method)vradio_dialog, gensym("dialog"), 726 A_GIMME, 0); 727 class_addmethod(vradio_class, (t_method)vradio_loadbang, 728 gensym("loadbang"), 0); 729 class_addmethod(vradio_class, (t_method)vradio_set, 730 gensym("set"), A_FLOAT, 0); 731 class_addmethod(vradio_class, (t_method)vradio_size, 732 gensym("size"), A_GIMME, 0); 733 class_addmethod(vradio_class, (t_method)vradio_delta, 734 gensym("delta"), A_GIMME, 0); 735 class_addmethod(vradio_class, (t_method)vradio_pos, 736 gensym("pos"), A_GIMME, 0); 737 class_addmethod(vradio_class, (t_method)vradio_color, 738 gensym("color"), A_GIMME, 0); 739 class_addmethod(vradio_class, (t_method)vradio_send, 740 gensym("send"), A_DEFSYM, 0); 741 class_addmethod(vradio_class, (t_method)vradio_receive, 742 gensym("receive"), A_DEFSYM, 0); 743 class_addmethod(vradio_class, (t_method)vradio_label, 744 gensym("label"), A_DEFSYM, 0); 745 class_addmethod(vradio_class, (t_method)vradio_label_pos, 746 gensym("label_pos"), A_GIMME, 0); 747 class_addmethod(vradio_class, (t_method)vradio_label_font, 748 gensym("label_font"), A_GIMME, 0); 749 class_addmethod(vradio_class, (t_method)vradio_init, 750 gensym("init"), A_FLOAT, 0); 751 class_addmethod(vradio_class, (t_method)vradio_number, 752 gensym("number"), A_FLOAT, 0); 753 class_addmethod(vradio_class, (t_method)vradio_single_change, 754 gensym("single_change"), 0); 755 class_addmethod(vradio_class, (t_method)vradio_double_change, 756 gensym("double_change"), 0); 757 vradio_widgetbehavior.w_getrectfn = vradio_getrect; 758 vradio_widgetbehavior.w_displacefn = iemgui_displace; 759 vradio_widgetbehavior.w_selectfn = iemgui_select; 760 vradio_widgetbehavior.w_activatefn = NULL; 761 vradio_widgetbehavior.w_deletefn = iemgui_delete; 762 vradio_widgetbehavior.w_visfn = iemgui_vis; 763 vradio_widgetbehavior.w_clickfn = vradio_newclick; 764 class_setwidget(vradio_class, &vradio_widgetbehavior); 765 class_sethelpsymbol(vradio_class, gensym("vradio")); 766 class_setsavefn(vradio_class, vradio_save); 767 class_setpropertiesfn(vradio_class, vradio_properties); 768 769 /* obsolete version (0.34-0.35) */ 770 vradio_old_class = class_new(gensym("vdl"), (t_newmethod)vdial_new, 771 (t_method)vradio_ff, sizeof(t_vradio), 0, A_GIMME, 0); 772 class_addbang(vradio_old_class, vradio_bang); 773 class_addfloat(vradio_old_class, vradio_float); 774 class_addmethod(vradio_old_class, (t_method)vradio_click, gensym("click"), 775 A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0); 776 class_addmethod(vradio_old_class, (t_method)vradio_dialog, gensym("dialog"), 777 A_GIMME, 0); 778 class_addmethod(vradio_old_class, (t_method)vradio_loadbang, gensym("loadbang"), 0); 779 class_addmethod(vradio_old_class, (t_method)vradio_set, gensym("set"), A_FLOAT, 0); 780 class_addmethod(vradio_old_class, (t_method)vradio_size, gensym("size"), A_GIMME, 0); 781 class_addmethod(vradio_old_class, (t_method)vradio_delta, gensym("delta"), A_GIMME, 0); 782 class_addmethod(vradio_old_class, (t_method)vradio_pos, gensym("pos"), A_GIMME, 0); 783 class_addmethod(vradio_old_class, (t_method)vradio_color, gensym("color"), A_GIMME, 0); 784 class_addmethod(vradio_old_class, (t_method)vradio_send, gensym("send"), A_DEFSYM, 0); 785 class_addmethod(vradio_old_class, (t_method)vradio_receive, gensym("receive"), A_DEFSYM, 0); 786 class_addmethod(vradio_old_class, (t_method)vradio_label, gensym("label"), A_DEFSYM, 0); 787 class_addmethod(vradio_old_class, (t_method)vradio_label_pos, gensym("label_pos"), A_GIMME, 0); 788 class_addmethod(vradio_old_class, (t_method)vradio_label_font, gensym("label_font"), A_GIMME, 0); 789 class_addmethod(vradio_old_class, (t_method)vradio_init, gensym("init"), A_FLOAT, 0); 790 class_addmethod(vradio_old_class, (t_method)vradio_number, gensym("number"), A_FLOAT, 0); 791 class_addmethod(vradio_old_class, (t_method)vradio_single_change, gensym("single_change"), 0); 792 class_addmethod(vradio_old_class, (t_method)vradio_double_change, gensym("double_change"), 0); 793 class_setwidget(vradio_old_class, &vradio_widgetbehavior); 794 class_sethelpsymbol(vradio_old_class, gensym("vradio")); 795} 796