diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-24 21:28:16 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-24 21:28:16 +0000 |
commit | 526b5580dabbfed7cfe5439dc3a90ec727f563c2 (patch) | |
tree | 22b1af92348785daad16714ee5e2b633017e0e48 /apps/plugins/pdbox/PDa/src/m_pd.c | |
parent | 4f2dfcc01b260d946044ef2b6af5fe36cb772c8d (diff) | |
download | rockbox-526b5580dabbfed7cfe5439dc3a90ec727f563c2.tar.gz rockbox-526b5580dabbfed7cfe5439dc3a90ec727f563c2.zip |
Cut the files in half and it might work better (note to self: check your tree is really clean before patching)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21070 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/m_pd.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/src/m_pd.c | 306 |
1 files changed, 0 insertions, 306 deletions
diff --git a/apps/plugins/pdbox/PDa/src/m_pd.c b/apps/plugins/pdbox/PDa/src/m_pd.c index 321574b5a2..e686c2cb52 100644 --- a/apps/plugins/pdbox/PDa/src/m_pd.c +++ b/apps/plugins/pdbox/PDa/src/m_pd.c | |||
@@ -304,309 +304,3 @@ void pd_init(void) | |||
304 | glob_init(); | 304 | glob_init(); |
305 | } | 305 | } |
306 | 306 | ||
307 | /* Copyright (c) 1997-1999 Miller Puckette. | ||
308 | * For information on usage and redistribution, and for a DISCLAIMER OF ALL | ||
309 | * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ | ||
310 | |||
311 | #include <stdlib.h> | ||
312 | #include "m_pd.h" | ||
313 | #include "m_imp.h" | ||
314 | |||
315 | /* FIXME no out-of-memory testing yet! */ | ||
316 | |||
317 | t_pd *pd_new(t_class *c) | ||
318 | { | ||
319 | t_pd *x; | ||
320 | if (!c) | ||
321 | bug ("pd_new: apparently called before setup routine"); | ||
322 | x = (t_pd *)t_getbytes(c->c_size); | ||
323 | *x = c; | ||
324 | if (c->c_patchable) | ||
325 | { | ||
326 | ((t_object *)x)->ob_inlet = 0; | ||
327 | ((t_object *)x)->ob_outlet = 0; | ||
328 | } | ||
329 | return (x); | ||
330 | } | ||
331 | |||
332 | void pd_free(t_pd *x) | ||
333 | { | ||
334 | t_class *c = *x; | ||
335 | if (c->c_freemethod) (*(t_gotfn)(c->c_freemethod))(x); | ||
336 | if (c->c_patchable) | ||
337 | { | ||
338 | while (((t_object *)x)->ob_outlet) | ||
339 | outlet_free(((t_object *)x)->ob_outlet); | ||
340 | while (((t_object *)x)->ob_inlet) | ||
341 | inlet_free(((t_object *)x)->ob_inlet); | ||
342 | if (((t_object *)x)->ob_binbuf) | ||
343 | binbuf_free(((t_object *)x)->ob_binbuf); | ||
344 | } | ||
345 | if (c->c_size) t_freebytes(x, c->c_size); | ||
346 | } | ||
347 | |||
348 | void gobj_save(t_gobj *x, t_binbuf *b) | ||
349 | { | ||
350 | t_class *c = x->g_pd; | ||
351 | if (c->c_savefn) | ||
352 | (c->c_savefn)(x, b); | ||
353 | } | ||
354 | |||
355 | /* deal with several objects bound to the same symbol. If more than one, we | ||
356 | actually bind a collection object to the symbol, which forwards messages sent | ||
357 | to the symbol. */ | ||
358 | |||
359 | static t_class *bindlist_class; | ||
360 | |||
361 | typedef struct _bindelem | ||
362 | { | ||
363 | t_pd *e_who; | ||
364 | struct _bindelem *e_next; | ||
365 | } t_bindelem; | ||
366 | |||
367 | typedef struct _bindlist | ||
368 | { | ||
369 | t_pd b_pd; | ||
370 | t_bindelem *b_list; | ||
371 | } t_bindlist; | ||
372 | |||
373 | static void bindlist_bang(t_bindlist *x) | ||
374 | { | ||
375 | t_bindelem *e; | ||
376 | for (e = x->b_list; e; e = e->e_next) | ||
377 | pd_bang(e->e_who); | ||
378 | } | ||
379 | |||
380 | static void bindlist_float(t_bindlist *x, t_float f) | ||
381 | { | ||
382 | t_bindelem *e; | ||
383 | for (e = x->b_list; e; e = e->e_next) { | ||
384 | pd_float(e->e_who, f); | ||
385 | } | ||
386 | } | ||
387 | |||
388 | static void bindlist_symbol(t_bindlist *x, t_symbol *s) | ||
389 | { | ||
390 | t_bindelem *e; | ||
391 | for (e = x->b_list; e; e = e->e_next) | ||
392 | pd_symbol(e->e_who, s); | ||
393 | } | ||
394 | |||
395 | static void bindlist_pointer(t_bindlist *x, t_gpointer *gp) | ||
396 | { | ||
397 | t_bindelem *e; | ||
398 | for (e = x->b_list; e; e = e->e_next) | ||
399 | pd_pointer(e->e_who, gp); | ||
400 | } | ||
401 | |||
402 | static void bindlist_list(t_bindlist *x, t_symbol *s, | ||
403 | int argc, t_atom *argv) | ||
404 | { | ||
405 | t_bindelem *e; | ||
406 | for (e = x->b_list; e; e = e->e_next) | ||
407 | pd_list(e->e_who, s, argc, argv); | ||
408 | } | ||
409 | |||
410 | static void bindlist_anything(t_bindlist *x, t_symbol *s, | ||
411 | int argc, t_atom *argv) | ||
412 | { | ||
413 | t_bindelem *e; | ||
414 | for (e = x->b_list; e; e = e->e_next) | ||
415 | pd_typedmess(e->e_who, s, argc, argv); | ||
416 | } | ||
417 | |||
418 | void m_pd_setup(void) | ||
419 | { | ||
420 | bindlist_class = class_new(gensym("bindlist"), 0, 0, | ||
421 | sizeof(t_bindlist), CLASS_PD, 0); | ||
422 | class_addbang(bindlist_class, bindlist_bang); | ||
423 | class_addfloat(bindlist_class, (t_method)bindlist_float); | ||
424 | class_addsymbol(bindlist_class, bindlist_symbol); | ||
425 | class_addpointer(bindlist_class, bindlist_pointer); | ||
426 | class_addlist(bindlist_class, bindlist_list); | ||
427 | class_addanything(bindlist_class, bindlist_anything); | ||
428 | } | ||
429 | |||
430 | void pd_bind(t_pd *x, t_symbol *s) | ||
431 | { | ||
432 | pd_checkgui(x,s); | ||
433 | if (s->s_thing) | ||
434 | { | ||
435 | if (*s->s_thing == bindlist_class) | ||
436 | { | ||
437 | t_bindlist *b = (t_bindlist *)s->s_thing; | ||
438 | t_bindelem *e = (t_bindelem *)getbytes(sizeof(t_bindelem)); | ||
439 | e->e_next = b->b_list; | ||
440 | e->e_who = x; | ||
441 | b->b_list = e; | ||
442 | } | ||
443 | else | ||
444 | { | ||
445 | t_bindlist *b = (t_bindlist *)pd_new(bindlist_class); | ||
446 | t_bindelem *e1 = (t_bindelem *)getbytes(sizeof(t_bindelem)); | ||
447 | t_bindelem *e2 = (t_bindelem *)getbytes(sizeof(t_bindelem)); | ||
448 | b->b_list = e1; | ||
449 | e1->e_who = x; | ||
450 | e1->e_next = e2; | ||
451 | e2->e_who = s->s_thing; | ||
452 | e2->e_next = 0; | ||
453 | s->s_thing = &b->b_pd; | ||
454 | } | ||
455 | } | ||
456 | else s->s_thing = x; | ||
457 | } | ||
458 | |||
459 | void pd_unbind(t_pd *x, t_symbol *s) | ||
460 | { | ||
461 | if (s->s_thing == x) s->s_thing = 0; | ||
462 | else if (s->s_thing && *s->s_thing == bindlist_class) | ||
463 | { | ||
464 | /* bindlists always have at least two elements... if the number | ||
465 | goes down to one, get rid of the bindlist and bind the symbol | ||
466 | straight to the remaining element. */ | ||
467 | |||
468 | t_bindlist *b = (t_bindlist *)s->s_thing; | ||
469 | t_bindelem *e, *e2; | ||
470 | if ((e = b->b_list)->e_who == x) | ||
471 | { | ||
472 | b->b_list = e->e_next; | ||
473 | freebytes(e, sizeof(t_bindelem)); | ||
474 | } | ||
475 | else for (e = b->b_list; e2 = e->e_next; e = e2) | ||
476 | if (e2->e_who == x) | ||
477 | { | ||
478 | e->e_next = e2->e_next; | ||
479 | freebytes(e2, sizeof(t_bindelem)); | ||
480 | break; | ||
481 | } | ||
482 | if (!b->b_list->e_next) | ||
483 | { | ||
484 | s->s_thing = b->b_list->e_who; | ||
485 | freebytes(b->b_list, sizeof(t_bindelem)); | ||
486 | pd_free(&b->b_pd); | ||
487 | } | ||
488 | } | ||
489 | else pd_error(x, "%s: couldn't unbind", s->s_name); | ||
490 | } | ||
491 | |||
492 | void zz(void) {} | ||
493 | |||
494 | t_pd *pd_findbyclass(t_symbol *s, t_class *c) | ||
495 | { | ||
496 | t_pd *x = 0; | ||
497 | |||
498 | if (!s->s_thing) return (0); | ||
499 | if (*s->s_thing == c) return (s->s_thing); | ||
500 | if (*s->s_thing == bindlist_class) | ||
501 | { | ||
502 | t_bindlist *b = (t_bindlist *)s->s_thing; | ||
503 | t_bindelem *e, *e2; | ||
504 | int warned = 0; | ||
505 | for (e = b->b_list; e; e = e->e_next) | ||
506 | if (*e->e_who == c) | ||
507 | { | ||
508 | if (x && !warned) | ||
509 | { | ||
510 | zz(); | ||
511 | post("warning: %s: multiply defined", s->s_name); | ||
512 | warned = 1; | ||
513 | } | ||
514 | x = e->e_who; | ||
515 | } | ||
516 | } | ||
517 | return x; | ||
518 | } | ||
519 | |||
520 | /* stack for maintaining bindings for the #X symbol during nestable loads. | ||
521 | */ | ||
522 | |||
523 | typedef struct _gstack | ||
524 | { | ||
525 | t_pd *g_what; | ||
526 | t_symbol *g_loadingabstraction; | ||
527 | struct _gstack *g_next; | ||
528 | } t_gstack; | ||
529 | |||
530 | static t_gstack *gstack_head = 0; | ||
531 | static t_pd *lastpopped; | ||
532 | static t_symbol *pd_loadingabstraction; | ||
533 | |||
534 | int pd_setloadingabstraction(t_symbol *sym) | ||
535 | { | ||
536 | t_gstack *foo = gstack_head; | ||
537 | for (foo = gstack_head; foo; foo = foo->g_next) | ||
538 | if (foo->g_loadingabstraction == sym) | ||
539 | return (1); | ||
540 | pd_loadingabstraction = sym; | ||
541 | return (0); | ||
542 | } | ||
543 | |||
544 | void pd_pushsym(t_pd *x) | ||
545 | { | ||
546 | t_gstack *y = (t_gstack *)t_getbytes(sizeof(*y)); | ||
547 | y->g_what = s__X.s_thing; | ||
548 | y->g_next = gstack_head; | ||
549 | y->g_loadingabstraction = pd_loadingabstraction; | ||
550 | pd_loadingabstraction = 0; | ||
551 | gstack_head = y; | ||
552 | s__X.s_thing = x; | ||
553 | } | ||
554 | |||
555 | void pd_popsym(t_pd *x) | ||
556 | { | ||
557 | if (!gstack_head || s__X.s_thing != x) bug("gstack_pop"); | ||
558 | else | ||
559 | { | ||
560 | t_gstack *headwas = gstack_head; | ||
561 | s__X.s_thing = headwas->g_what; | ||
562 | gstack_head = headwas->g_next; | ||
563 | t_freebytes(headwas, sizeof(*headwas)); | ||
564 | lastpopped = x; | ||
565 | } | ||
566 | } | ||
567 | |||
568 | void pd_doloadbang(void) | ||
569 | { | ||
570 | if (lastpopped) | ||
571 | pd_vmess(lastpopped, gensym("loadbang"), ""); | ||
572 | lastpopped = 0; | ||
573 | } | ||
574 | |||
575 | void pd_bang(t_pd *x) | ||
576 | { | ||
577 | (*(*x)->c_bangmethod)(x); | ||
578 | } | ||
579 | |||
580 | void pd_float(t_pd *x, t_float f) | ||
581 | { | ||
582 | (*(*x)->c_floatmethod)(x, f); | ||
583 | } | ||
584 | |||
585 | void pd_pointer(t_pd *x, t_gpointer *gp) | ||
586 | { | ||
587 | (*(*x)->c_pointermethod)(x, gp); | ||
588 | } | ||
589 | |||
590 | void pd_symbol(t_pd *x, t_symbol *s) | ||
591 | { | ||
592 | (*(*x)->c_symbolmethod)(x, s); | ||
593 | } | ||
594 | |||
595 | void pd_list(t_pd *x, t_symbol *s, int argc, t_atom *argv) | ||
596 | { | ||
597 | (*(*x)->c_listmethod)(x, &s_list, argc, argv); | ||
598 | } | ||
599 | |||
600 | void mess_init(void); | ||
601 | void obj_init(void); | ||
602 | void conf_init(void); | ||
603 | void glob_init(void); | ||
604 | |||
605 | void pd_init(void) | ||
606 | { | ||
607 | mess_init(); | ||
608 | obj_init(); | ||
609 | conf_init(); | ||
610 | glob_init(); | ||
611 | } | ||
612 | |||