aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--help/listUnfold-help.pd54
-rw-r--r--help/param-help.pd12
-rw-r--r--src/Makefile4
-rw-r--r--src/listUnfold.c126
-rw-r--r--test/Makefile4
5 files changed, 144 insertions, 56 deletions
diff --git a/help/listUnfold-help.pd b/help/listUnfold-help.pd
index f837bc5..ba2085c 100644
--- a/help/listUnfold-help.pd
+++ b/help/listUnfold-help.pd
@@ -1,20 +1,40 @@
-#N canvas 154 102 524 446 10;
-#X obj 196 327 listUnfold;
-#X obj 165 388 print value;
-#X obj 277 385 print index;
-#X msg 199 277 anything works too;
-#X msg 154 208 5 3 2 8 4;
-#X msg 185 237 symbol test;
-#X obj 62 22 cnv 15 400 100 empty empty empty 20 12 0 14 -249661 -66577
+#N canvas 82 115 833 496 10;
+#X msg 103 285 anything works too;
+#X msg 91 258 symbol test;
+#X obj 62 27 cnv 15 400 100 empty empty empty 20 12 0 14 -249661 -66577
0;
#X text 67 77 author: mrtoftrash@gmail.com;
-#X text 67 88 version: 2009-06-07 (initial release);
-#X text 67 66 tags: list flow tof;
-#X text 68 22 description: output the individual elements of a list
-one after the other while simultaneously doing so with their indices.
+#X obj 100 362 tof/listUnfold;
+#X obj 464 358 tof/listUnfold wait;
+#X obj 493 309 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
+-1 -1;
+#X text 67 66 tags: lists;
+#X obj 100 388 print ATOM;
+#X obj 181 389 print INDEX;
+#X obj 464 384 print ATOM;
+#X obj 575 381 print INDEX;
+#X msg 60 229 list a b c d e f g;
+#X msg 464 282 list m n o p q r s t u v;
+#X text 468 263 step 1: add list;
+#X text 513 307 step 2: bang to output each element;
+#X obj 122 313 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
+-1 -1;
+#X text 147 312 bang to interrupt output;
+#X text 67 145 listUnfold has two modes:;
+#X text 68 27 description: output the individual elements of a list
+and their indices \, either immediately or on bangs.;
+#X text 67 88 version: 2009-10-06 (added the second mode);
+#X text 56 199 default mode: output everything once it is received.
;
-#X connect 0 0 1 0;
-#X connect 0 1 2 0;
-#X connect 3 0 0 0;
-#X connect 4 0 0 0;
-#X connect 5 0 0 0;
+#X text 428 196 "wait" or "manually" mode: output one element for every
+bang .;
+#X connect 0 0 4 0;
+#X connect 1 0 4 0;
+#X connect 4 0 8 0;
+#X connect 4 1 9 0;
+#X connect 5 0 10 0;
+#X connect 5 1 11 0;
+#X connect 6 0 5 0;
+#X connect 12 0 4 0;
+#X connect 13 0 5 0;
+#X connect 16 0 4 0;
diff --git a/help/param-help.pd b/help/param-help.pd
index ea41f91..bdf0714 100644
--- a/help/param-help.pd
+++ b/help/param-help.pd
@@ -1,4 +1,4 @@
-#N canvas 6 80 1018 688 10;
+#N canvas 1024 24 1018 688 10;
#X floatatom 477 321 5 0 0 0 - - -;
#X obj -23 2 cnv 15 400 100 empty empty empty 20 12 0 14 -249661 -66577
0;
@@ -45,17 +45,17 @@ name \, will be used to build the path. See an example to the right.
;
#X obj 472 448 dac~;
#X obj 690 364 hsl 100 15 0 1 0 0 \$0/FM_MOD/volume \$0/FM_MOD/volume_
-/FM_MOD/volume 105 7 0 10 -262144 -1 -1 4131 1;
+/FM_MOD/volume 105 7 0 10 -262144 -1 -1 2884 1;
#X obj 690 384 hsl 100 15 200 2000 0 0 \$0/FM_MOD/carrier \$0/FM_MOD/carrier_
/FM_MOD/carrier 105 7 0 10 -262144 -1 -1 2200 1;
#X obj 688 423 nbx 5 14 -1e+37 1e+37 0 0 \$0/FM_MOD/modulation/index
\$0/FM_MOD/modulation/index_ /FM_MOD/modulation/index 57 7 0 10 -262144
--1 -1 85 256;
+-1 -1 10 256;
#X obj 688 404 nbx 5 14 -1e+37 1e+37 0 0 \$0/FM_MOD/modulation/freq
\$0/FM_MOD/modulation/freq_ /FM_MOD/modulation/freq 57 7 0 10 -262144
-1 -1 3 256;
#X obj 517 367 hsl 128 15 0 1 0 0 empty empty empty -2 -8 0 10 -262144
--1 -1 5300 1;
+-1 -1 3700 1;
#X text 650 542 Outputs all children params of the root patch.;
#X text 121 539 Saves and restores all chilren params of the root patch
to/from a file with optionnal presets.;
@@ -81,8 +81,8 @@ for the "/gui" keyword.;
#X text 531 246 A param automatically ouputs its value when it is created.
You can disable this behavior with the "/nlb" (no loadbang) keyword.
;
-#X msg 477 343 modulation/index \$1;
-#X msg 514 389 volume \$1;
+#X msg 477 343 /modulation/index \$1;
+#X msg 514 389 /volume \$1;
#X connect 0 0 54 0;
#X connect 21 0 43 0;
#X connect 22 0 39 0;
diff --git a/src/Makefile b/src/Makefile
index b064d5d..e1d67f9 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,7 +1,9 @@
+default:
+
PARAM: param paramDump paramRoute paramFile
current:
- echo make pd_linux
+ echo make class
clean:
rm -f *.pd_linux *.o
diff --git a/src/listUnfold.c b/src/listUnfold.c
index 579f645..60f5ec4 100644
--- a/src/listUnfold.c
+++ b/src/listUnfold.c
@@ -1,61 +1,114 @@
#include "m_pd.h"
+#include <string.h>
#define IS_A_SYMBOL(atom,index) ((atom+index)->a_type == A_SYMBOL)
#define IS_A_FLOAT(atom,index) ((atom+index)->a_type == A_FLOAT)
+/* Mode 0: unfold all the list till its end or when banged.
+ * Mode 1: unfold each element of the list at each bang.
+ * Mode 0 is by default. Mode 1 is activated when listUnfold is
+ * created with "wait" or "manually" as only argument.
+ */
static t_class *listUnfold_class;
typedef struct _listUnfold {
- t_object x_obj;
-
- //t_float start;
- //t_float step;
- t_int iterating;
- t_outlet* outlet1;
- t_outlet* outlet2;
+ t_object x_obj;
+ t_int iterating;
+ t_outlet* outlet1;
+ t_outlet* outlet2;
+ t_int mode;
+ int memSize;
+ int ac;
+ t_atom* av;
} t_listUnfold;
+
+
+
void listUnfold_bang(t_listUnfold *x)
{
//x->i_count = x->i_down;
- x->iterating = 0;
+ if ( x->mode == 0) {
+ x->iterating = 0;
+ } else {
+ if ( x->iterating < x->ac ) {
+ outlet_float(x->outlet2,x->iterating);
+ if ( IS_A_FLOAT(x->av,x->iterating) ) {
+ outlet_float(x->outlet1,atom_getfloat(x->av + x->iterating));
+ } else {
+ outlet_symbol(x->outlet1,atom_getsymbol(x->av + x->iterating));
+ }
+ x->iterating++;
+ }
+ }
}
void listUnfold_anything(t_listUnfold *x, t_symbol* s, int ac, t_atom* av)
{
- int i = 0;
- int count = 0;
- x->iterating = 1;
-
- if ( s != &s_list && s != &s_float && s != &s_symbol ) {
- outlet_float(x->outlet2,0);
- outlet_symbol(x->outlet1,s);
- count++;
- }
- for ( ; i < ac; i++ ) {
- if ( !(x->iterating) ) break;
- outlet_float(x->outlet2,count);
- count++;
- if ( IS_A_FLOAT(av,i) ) {
- outlet_float(x->outlet1,atom_getfloat(av+i));
- } else {
- outlet_symbol(x->outlet1,atom_getsymbol(av+i));
+
+
+ if ( x->mode == 0) {
+
+ // Output all
+
+ int i =0;
+ int offset =0;
+ x->iterating = 1;
+
+ if ( s != &s_list && s != &s_float && s != &s_symbol ) {
+ outlet_float(x->outlet2,0);
+ outlet_symbol(x->outlet1,s);
+ offset=1;
+ }
+
+ for ( ; i < ac && x->iterating; i++ ) {
+ outlet_float(x->outlet2,i+offset);
+ if ( IS_A_FLOAT(av,0) ) {
+ outlet_float(x->outlet1,atom_getfloat(av));
+ } else {
+ outlet_symbol(x->outlet1,atom_getsymbol(av));
+ }
+ av++;
}
+ } else {
+
+ x->iterating = 0;
+
+ // Copy and wait for bangs to output
+
+
+ int do_selector = ( s != &s_list && s != &s_float && s != &s_symbol );
+ x->ac = ac + do_selector; //One more for the selector
+
+ // Resize memory if required and add 3 atoms just in case
+ if(x->ac > x->memSize) {
+ x->av = resizebytes(x->av, x->memSize * sizeof(*(x->av)),
+ (3 + x->ac) * sizeof(*(x->av)));
+ x->memSize = 3 + x->ac;
+ }
+ t_atom* dst = x->av;
+
+ // Copy selector
+ if ( do_selector ) {
+ SETSYMBOL(dst, s);
+ dst++;
+ }
+ // Copy atoms
+ while(ac--) *dst++ = *av++;
- }
+ }
}
static void listUnfold_free(t_listUnfold *x)
{
-
-
+ freebytes(x->av, x->memSize * sizeof(*(x->av)));
}
void *listUnfold_new(t_symbol *s, int argc, t_atom *argv)
@@ -64,9 +117,20 @@ void *listUnfold_new(t_symbol *s, int argc, t_atom *argv)
x->iterating = 0;
-
- //floatinlet_new(&x->x_obj, &x->start);
- //floatinlet_new(&x->x_obj, &x->step);
+ x->mode = 0;
+
+ if (argc && IS_A_SYMBOL(argv,0) ) {
+ t_symbol* type = atom_getsymbol(argv);
+ if (strcmp(type->s_name,"wait")==0 || strcmp(type->s_name,"manually")==0) {
+ x->mode = 1;
+ }
+ }
+
+ // Initialize memory
+ x->memSize = 10;
+ x->ac = 0;
+ x->av = getbytes(x->memSize * sizeof(*(x->av)));
+
x->outlet1 = outlet_new(&x->x_obj, &s_list);
x->outlet2 = outlet_new(&x->x_obj, &s_float);
diff --git a/test/Makefile b/test/Makefile
index b064d5d..e1d67f9 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,7 +1,9 @@
+default:
+
PARAM: param paramDump paramRoute paramFile
current:
- echo make pd_linux
+ echo make class
clean:
rm -f *.pd_linux *.o