summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/x_qlist.c
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2009-05-24 21:28:16 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2009-05-24 21:28:16 +0000
commit526b5580dabbfed7cfe5439dc3a90ec727f563c2 (patch)
tree22b1af92348785daad16714ee5e2b633017e0e48 /apps/plugins/pdbox/PDa/src/x_qlist.c
parent4f2dfcc01b260d946044ef2b6af5fe36cb772c8d (diff)
downloadrockbox-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/x_qlist.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/x_qlist.c345
1 files changed, 0 insertions, 345 deletions
diff --git a/apps/plugins/pdbox/PDa/src/x_qlist.c b/apps/plugins/pdbox/PDa/src/x_qlist.c
index e2c0605087..7dbec5e7b4 100644
--- a/apps/plugins/pdbox/PDa/src/x_qlist.c
+++ b/apps/plugins/pdbox/PDa/src/x_qlist.c
@@ -343,348 +343,3 @@ void x_qlist_setup(void )
343 class_addbang(textfile_class, textfile_bang); 343 class_addbang(textfile_class, textfile_bang);
344} 344}
345 345
346/* Copyright (c) 1997-1999 Miller Puckette and others.
347* For information on usage and redistribution, and for a DISCLAIMER OF ALL
348* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
349
350#include "m_pd.h"
351#include <string.h>
352#ifdef UNIX
353#include <unistd.h>
354#endif
355#ifdef MSW
356#include <io.h>
357#endif
358
359typedef struct _qlist
360{
361 t_object x_ob;
362 t_outlet *x_bangout;
363 void *x_binbuf;
364 int x_onset; /* playback position */
365 t_clock *x_clock;
366 float x_tempo;
367 double x_whenclockset;
368 float x_clockdelay;
369 t_symbol *x_dir;
370 t_canvas *x_canvas;
371 int x_reentered;
372} t_qlist;
373
374static void qlist_tick(t_qlist *x);
375
376static t_class *qlist_class;
377
378static void *qlist_new( void)
379{
380 t_symbol *name, *filename = 0;
381 t_qlist *x = (t_qlist *)pd_new(qlist_class);
382 x->x_binbuf = binbuf_new();
383 x->x_clock = clock_new(x, (t_method)qlist_tick);
384 outlet_new(&x->x_ob, &s_list);
385 x->x_bangout = outlet_new(&x->x_ob, &s_bang);
386 x->x_onset = 0x7fffffff;
387 x->x_tempo = 1;
388 x->x_whenclockset = 0;
389 x->x_clockdelay = 0;
390 x->x_canvas = canvas_getcurrent();
391 x->x_reentered = 0;
392 return (x);
393}
394
395static void qlist_rewind(t_qlist *x)
396{
397 x->x_onset = 0;
398 if (x->x_clock) clock_unset(x->x_clock);
399 x->x_whenclockset = 0;
400 x->x_reentered = 1;
401}
402
403static void qlist_donext(t_qlist *x, int drop, int automatic)
404{
405 t_pd *target = 0;
406 while (1)
407 {
408 int argc = binbuf_getnatom(x->x_binbuf),
409 count, onset = x->x_onset, onset2, wasreentered;
410 t_atom *argv = binbuf_getvec(x->x_binbuf);
411 t_atom *ap = argv + onset, *ap2;
412 if (onset >= argc) goto end;
413 while (ap->a_type == A_SEMI || ap->a_type == A_COMMA)
414 {
415 if (ap->a_type == A_SEMI) target = 0;
416 onset++, ap++;
417 if (onset >= argc) goto end;
418 }
419
420 if (!target && ap->a_type == A_FLOAT)
421 {
422 ap2 = ap + 1;
423 onset2 = onset + 1;
424 while (onset2 < argc && ap2->a_type == A_FLOAT)
425 onset2++, ap2++;
426 x->x_onset = onset2;
427 if (automatic)
428 {
429 clock_delay(x->x_clock,
430 x->x_clockdelay = ap->a_w.w_float * x->x_tempo);
431 x->x_whenclockset = clock_getsystime();
432 }
433 else outlet_list(x->x_ob.ob_outlet, 0, onset2-onset, ap);
434 return;
435 }
436 ap2 = ap + 1;
437 onset2 = onset + 1;
438 while (onset2 < argc &&
439 (ap2->a_type == A_FLOAT || ap2->a_type == A_SYMBOL))
440 onset2++, ap2++;
441 x->x_onset = onset2;
442 count = onset2 - onset;
443 if (!target)
444 {
445 if (ap->a_type != A_SYMBOL) continue;
446 else if (!(target = ap->a_w.w_symbol->s_thing))
447 {
448 error("qlist: %s: no such object", ap->a_w.w_symbol->s_name);
449 continue;
450 }
451 ap++;
452 onset++;
453 count--;
454 if (!count)
455 {
456 x->x_onset = onset2;
457 continue;
458 }
459 }
460 wasreentered = x->x_reentered;
461 x->x_reentered = 0;
462 if (!drop)
463 {
464 if (ap->a_type == A_FLOAT)
465 typedmess(target, &s_list, count, ap);
466 else if (ap->a_type == A_SYMBOL)
467 typedmess(target, ap->a_w.w_symbol, count-1, ap+1);
468 }
469 if (x->x_reentered)
470 return;
471 x->x_reentered = wasreentered;
472 } /* while (1); never falls through */
473
474end:
475 x->x_onset = 0x7fffffff;
476 outlet_bang(x->x_bangout);
477 x->x_whenclockset = 0;
478}
479
480static void qlist_next(t_qlist *x, t_floatarg drop)
481{
482 qlist_donext(x, drop != 0, 0);
483}
484
485static void qlist_bang(t_qlist *x)
486{
487 qlist_rewind(x);
488 qlist_donext(x, 0, 1);
489}
490
491static void qlist_tick(t_qlist *x)
492{
493 x->x_whenclockset = 0;
494 qlist_donext(x, 0, 1);
495}
496
497static void qlist_add(t_qlist *x, t_symbol *s, int ac, t_atom *av)
498{
499 t_atom a;
500 SETSEMI(&a);
501 binbuf_add(x->x_binbuf, ac, av);
502 binbuf_add(x->x_binbuf, 1, &a);
503}
504
505static void qlist_add2(t_qlist *x, t_symbol *s, int ac, t_atom *av)
506{
507 binbuf_add(x->x_binbuf, ac, av);
508}
509
510static void qlist_clear(t_qlist *x)
511{
512 qlist_rewind(x);
513 binbuf_clear(x->x_binbuf);
514}
515
516static void qlist_set(t_qlist *x, t_symbol *s, int ac, t_atom *av)
517{
518 qlist_clear(x);
519 qlist_add(x, s, ac, av);
520}
521
522static void qlist_read(t_qlist *x, t_symbol *filename, t_symbol *format)
523{
524 int cr = 0;
525 if (!strcmp(format->s_name, "cr"))
526 cr = 1;
527 else if (*format->s_name)
528 error("qlist_read: unknown flag: %s", format->s_name);
529
530 if (binbuf_read_via_path(x->x_binbuf, filename->s_name,
531 canvas_getdir(x->x_canvas)->s_name, cr))
532 error("%s: read failed", filename->s_name);
533 x->x_onset = 0x7fffffff;
534 x->x_reentered = 1;
535}
536
537static void qlist_write(t_qlist *x, t_symbol *filename, t_symbol *format)
538{
539 int cr = 0;
540 char buf[MAXPDSTRING];
541 canvas_makefilename(x->x_canvas, filename->s_name,
542 buf, MAXPDSTRING);
543 if (!strcmp(format->s_name, "cr"))
544 cr = 1;
545 else if (*format->s_name)
546 error("qlist_read: unknown flag: %s", format->s_name);
547 if (binbuf_write(x->x_binbuf, buf, "", cr))
548 error("%s: write failed", filename->s_name);
549}
550
551static void qlist_print(t_qlist *x)
552{
553 post("--------- textfile or qlist contents: -----------");
554 binbuf_print(x->x_binbuf);
555}
556
557static void qlist_tempo(t_qlist *x, t_float f)
558{
559 float newtempo;
560 if (f < 1e-20) f = 1e-20;
561 else if (f > 1e20) f = 1e20;
562 newtempo = 1./f;
563 if (x->x_whenclockset != 0)
564 {
565 float elapsed = clock_gettimesince(x->x_whenclockset);
566 float left = x->x_clockdelay - elapsed;
567 if (left < 0) left = 0;
568 left *= newtempo / x->x_tempo;
569 clock_delay(x->x_clock, left);
570 }
571 x->x_tempo = newtempo;
572}
573
574static void qlist_free(t_qlist *x)
575{
576 binbuf_free(x->x_binbuf);
577 if (x->x_clock) clock_free(x->x_clock);
578}
579
580/* -------------------- textfile ------------------------------- */
581
582static t_class *textfile_class;
583typedef t_qlist t_textfile;
584
585static void *textfile_new( void)
586{
587 t_symbol *name, *filename = 0;
588 t_textfile *x = (t_textfile *)pd_new(textfile_class);
589 x->x_binbuf = binbuf_new();
590 outlet_new(&x->x_ob, &s_list);
591 x->x_bangout = outlet_new(&x->x_ob, &s_bang);
592 x->x_onset = 0x7fffffff;
593 x->x_reentered = 0;
594 x->x_tempo = 1;
595 x->x_whenclockset = 0;
596 x->x_clockdelay = 0;
597 x->x_clock = NULL;
598 x->x_canvas = canvas_getcurrent();
599 return (x);
600}
601
602static void textfile_bang(t_textfile *x)
603{
604 int argc = binbuf_getnatom(x->x_binbuf),
605 count, onset = x->x_onset, onset2;
606 t_atom *argv = binbuf_getvec(x->x_binbuf);
607 t_atom *ap = argv + onset, *ap2;
608 while (onset < argc &&
609 (ap->a_type == A_SEMI || ap->a_type == A_COMMA))
610 onset++, ap++;
611 onset2 = onset;
612 ap2 = ap;
613 while (onset2 < argc &&
614 (ap2->a_type != A_SEMI && ap2->a_type != A_COMMA))
615 onset2++, ap2++;
616 if (onset2 > onset)
617 {
618 x->x_onset = onset2;
619 if (ap->a_type == A_SYMBOL)
620 outlet_anything(x->x_ob.ob_outlet, ap->a_w.w_symbol,
621 onset2-onset-1, ap+1);
622 else outlet_list(x->x_ob.ob_outlet, 0, onset2-onset, ap);
623 }
624 else
625 {
626 x->x_onset = 0x7fffffff;
627 outlet_bang(x->x_bangout);
628 }
629}
630
631static void textfile_rewind(t_qlist *x)
632{
633 x->x_onset = 0;
634}
635
636static void textfile_free(t_textfile *x)
637{
638 binbuf_free(x->x_binbuf);
639}
640
641/* ---------------- global setup function -------------------- */
642
643void x_qlist_setup(void )
644{
645 qlist_class = class_new(gensym("qlist"), (t_newmethod)qlist_new,
646 (t_method)qlist_free, sizeof(t_qlist), 0, 0);
647 class_addmethod(qlist_class, (t_method)qlist_rewind, gensym("rewind"), 0);
648 class_addmethod(qlist_class, (t_method)qlist_next,
649 gensym("next"), A_DEFFLOAT, 0);
650 class_addmethod(qlist_class, (t_method)qlist_set, gensym("set"),
651 A_GIMME, 0);
652 class_addmethod(qlist_class, (t_method)qlist_clear, gensym("clear"), 0);
653 class_addmethod(qlist_class, (t_method)qlist_add, gensym("add"),
654 A_GIMME, 0);
655 class_addmethod(qlist_class, (t_method)qlist_add2, gensym("add2"),
656 A_GIMME, 0);
657 class_addmethod(qlist_class, (t_method)qlist_add, gensym("append"),
658 A_GIMME, 0);
659 class_addmethod(qlist_class, (t_method)qlist_read, gensym("read"),
660 A_SYMBOL, A_DEFSYM, 0);
661 class_addmethod(qlist_class, (t_method)qlist_write, gensym("write"),
662 A_SYMBOL, A_DEFSYM, 0);
663 class_addmethod(qlist_class, (t_method)qlist_print, gensym("print"),
664 A_DEFSYM, 0);
665 class_addmethod(qlist_class, (t_method)qlist_tempo,
666 gensym("tempo"), A_FLOAT, 0);
667 class_addbang(qlist_class, qlist_bang);
668
669 textfile_class = class_new(gensym("textfile"), (t_newmethod)textfile_new,
670 (t_method)textfile_free, sizeof(t_textfile), 0, 0);
671 class_addmethod(textfile_class, (t_method)textfile_rewind, gensym("rewind"),
672 0);
673 class_addmethod(textfile_class, (t_method)qlist_set, gensym("set"),
674 A_GIMME, 0);
675 class_addmethod(textfile_class, (t_method)qlist_clear, gensym("clear"), 0);
676 class_addmethod(textfile_class, (t_method)qlist_add, gensym("add"),
677 A_GIMME, 0);
678 class_addmethod(textfile_class, (t_method)qlist_add2, gensym("add2"),
679 A_GIMME, 0);
680 class_addmethod(textfile_class, (t_method)qlist_add, gensym("append"),
681 A_GIMME, 0);
682 class_addmethod(textfile_class, (t_method)qlist_read, gensym("read"),
683 A_SYMBOL, A_DEFSYM, 0);
684 class_addmethod(textfile_class, (t_method)qlist_write, gensym("write"),
685 A_SYMBOL, A_DEFSYM, 0);
686 class_addmethod(textfile_class, (t_method)qlist_print, gensym("print"),
687 A_DEFSYM, 0);
688 class_addbang(textfile_class, textfile_bang);
689}
690