Outputting individual terms from a coll

Sep 1, 2008 at 6:28pm

Outputting individual terms from a coll

Hello all,

To try and put across my problem as succinctly as possible, say I have a coll with the following contents:

1, 1 2 3 4;
2, a 1 b c 2;

If I send 1 to the coll it will output ’1 2 3 4′ as a list.

Can I make it send 1, 2, 3, 4 as seperate terms?

Obviously [iter] would do this.

However, if I wish to send 2 to the coll and have ‘a 1′, ‘b c 2′ output (i.e. two lists of differing lengths) [iter] is no longer appropriate.

If I was using a [message box] to store my data I could have the message box contain [a 1, b c 2] and the ‘comma’ would seperate my list into the required terms.

However, this is not a valid coll entry:

2, a 1 , b c 2;

Any ideas for how I could achieve this?

The example should illustrate why I want to do this.

Regards

#P window setfont “Sans Serif” 12.;
#P window linecount 1;
#P comment 16 28 116 196620 1] Choose method;
#P comment 201 29 122 196620 2] Trigger events;
#P window setfont “Sans Serif” 9.;
#P hidden newex 16 28 48 196617 loadbang;
#P message 121 156 85 196617 send number , 30;
#P message 106 176 85 196617 send number , 20;
#P message 91 201 152 196617 send messagebox , set dothistoo;
#P newex 76 267 70 196617 pattrforward;
#P message 76 221 156 196617 send messagebox , set dothisnow;
#P newex 76 134 70 196617 route 1 2 3 4;
#P comment 418 289 61 196617 messagebox;
#P message 243 49 14 196617 4;
#P number 485 302 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname number;
#P message 418 302 50 196617 do that;
#P objectname messagebox;
#P newex 388 231 70 196617 pattrforward;
#N coll $0directions 1;
#T flags 1 0;
#T 1 send messagebox;
#T 2 send messagebox;
#T 3 send number;
#T 4 send number;
#P newobj 475 179 96 196617 coll $0directions 1;
#P newex 388 146 27 196617 t i i;
#P newex 76 66 21 196617 t 2;
#P newex 76 99 135 196617 gate 2;
#P newex 16 65 21 196617 t 1;
#P message 76 48 52 196617 using coll;
#P message 16 48 60 196617 using route;
#P message 229 49 14 196617 3;
#P message 215 49 14 196617 2;
#P message 201 49 14 196617 1;
#N coll $0events 1;
#T flags 1 0;
#T 1 set do this;
#T 2 set do that;
#T 3 5;
#T 4 10;
#P newobj 388 179 81 196617 coll $0events 1;
#P comment 485 289 42 196617 number;
#P window linecount 3;
#P comment 74 295 212 196617 How can a message that is a sequence of items (as in the above message boxes) be sent from a single address in a coll?;
#P user panel 412 285 118 41;
#X brgb 0 177 232;
#X frgb 0 0 0;
#X border 1;
#X rounded 0;
#X shadow 0;
#X done;
#P hidden connect 25 0 7 0;
#P connect 7 0 9 0;
#P connect 8 0 11 0;
#P connect 11 0 10 0;
#P connect 9 0 10 0;
#P connect 10 0 19 0;
#P connect 19 0 20 0;
#P connect 23 0 21 0;
#P connect 24 0 21 0;
#P connect 22 0 21 0;
#P connect 20 0 21 0;
#P connect 19 1 22 0;
#P connect 19 2 23 0;
#P connect 19 3 24 0;
#P connect 17 0 10 1;
#P connect 6 0 10 1;
#P connect 5 0 10 1;
#P connect 4 0 10 1;
#P fasten 10 1 12 0 206 131 393 131;
#P connect 12 0 3 0;
#P connect 13 0 14 0;
#P connect 3 0 14 0;
#P connect 12 1 13 0;
#P window clipboard copycount 28;

#39513
Sep 1, 2008 at 6:37pm

Apologies, but this patch perhaps better demonstrates ‘why’ I’d want to do this (ignore the last patch):

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P message 136 156 253 196617 send number , 40 , send messagebox , set two at a time;
#P message 257 49 14 196617 5;
#P window setfont “Sans Serif” 12.;
#P comment 16 28 116 196620 1] Choose method;
#P comment 201 29 122 196620 2] Trigger events;
#P window setfont “Sans Serif” 9.;
#P hidden newex 16 28 48 196617 loadbang;
#P message 121 174 85 196617 send number , 30;
#P message 106 194 85 196617 send number , 20;
#P message 91 219 152 196617 send messagebox , set dothistoo;
#P newex 76 269 70 196617 pattrforward;
#P message 76 239 156 196617 send messagebox , set dothisnow;
#P newex 76 134 89 196617 route 1 2 3 4 5;
#P comment 418 289 61 196617 messagebox;
#P message 243 49 14 196617 4;
#P number 508 302 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname number;
#P message 418 302 69 196617 two at a time;
#P objectname messagebox;
#P newex 394 240 70 196617 pattrforward;
#N coll $0directions 1;
#T flags 1 0;
#T 1 send messagebox;
#T 2 send messagebox;
#T 3 send number;
#T 4 send number;
#P newobj 481 188 96 196617 coll $0directions 1;
#P newex 394 155 27 196617 t i i;
#P newex 76 66 21 196617 t 2;
#P newex 76 99 135 196617 gate 2;
#P newex 16 65 21 196617 t 1;
#P message 76 48 52 196617 using coll;
#P message 16 48 60 196617 using route;
#P message 229 49 14 196617 3;
#P message 215 49 14 196617 2;
#P message 201 49 14 196617 1;
#N coll $0events 1;
#T flags 1 0;
#T 1 set do this;
#T 2 set do that;
#T 3 5;
#T 4 10;
#P newobj 394 188 81 196617 coll $0events 1;
#P comment 508 289 42 196617 number;
#P window linecount 3;
#P comment 74 295 212 196617 How can a message that is a sequence of items (as in the above message boxes) be sent from a single address in a coll?;
#P user panel 412 285 146 41;
#X brgb 0 177 232;
#X frgb 0 0 0;
#X border 1;
#X rounded 0;
#X shadow 0;
#X done;
#P window linecount 2;
#P comment 276 88 198 196617 nb. Event 5 can not easily be performed by accessing a single address in the coll(s);
#P hidden connect 26 0 8 0;
#P connect 8 0 10 0;
#P connect 9 0 12 0;
#P connect 12 0 11 0;
#P connect 10 0 11 0;
#P connect 11 0 20 0;
#P connect 20 0 21 0;
#P connect 21 0 22 0;
#P connect 23 0 22 0;
#P connect 25 0 22 0;
#P connect 24 0 22 0;
#P connect 30 0 22 0;
#P connect 20 1 23 0;
#P connect 20 2 24 0;
#P connect 20 3 25 0;
#P connect 20 4 30 0;
#P connect 29 0 11 1;
#P connect 18 0 11 1;
#P connect 7 0 11 1;
#P connect 6 0 11 1;
#P connect 5 0 11 1;
#P fasten 11 1 13 0 206 131 399 131;
#P connect 13 0 4 0;
#P connect 14 0 15 0;
#P connect 4 0 15 0;
#P connect 13 1 14 0;
#P window clipboard copycount 31;

#139230
Sep 1, 2008 at 7:44pm

On Sep 1, 2008, at 11:37 AM, Willy C wrote:

> Apologies, but this patch perhaps better demonstrates ‘why’ I’d want
> to do this (ignore the last patch):

I would put some sort of separator in the data itself, then route
based on that data.

-C

Chris Muir
cbm@well.com

http://www.xfade.com

#139231
Sep 1, 2008 at 8:04pm

#139232
Sep 1, 2008 at 9:32pm

On Sep 1, 2008, at 12:44 PM, Chris Muir wrote:

> I would put some sort of separator in the data itself, then route
> based on that data.

Like this:

– Pasted Max Patch, click to expand. –

Chris Muir
cbm@well.com

http://www.xfade.com

#139233
Sep 1, 2008 at 9:32pm

i would argue that you’re operating with key:value or address:content
pairs.
the value can be a float, int, symbol or list. the list should be
encoded as a symbol by putting qutoes around it in order to be certain
it goes through as one atom.

hth

/*j

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P message 220 41 14 196617 8;
#P newex 98 121 69 196617 route symbol;
#P message 201 41 14 196617 7;
#P comment 60 187 34 196617 value;
#P message 180 41 14 196617 6;
#P number 449 328 35 9 0 0 0 3 0 0 0 232 232 232 222 222 222 0 0 0;
#P objectname number;
#P window linecount 0;
#P message 317 329 122 196617;
#P objectname messagebox;
#P window linecount 1;
#P message 162 41 14 196617 5;
#P message 146 41 14 196617 4;
#P message 130 41 14 196617 3;
#P message 114 41 14 196617 2;
#P message 97 41 14 196617 1;
#P newex 98 326 70 196617 pattrforward;
#P newex 148 279 64 196617 fromsymbol;
#P newex 98 242 108 196617 route int float symbol;
#P newex 241 267 68 196617 prepend send;
#P newex 98 187 44 196617 zl nth 2;
#P newex 241 187 44 196617 zl nth 1;
#P newex 98 153 47 196617 zl iter 2;
#N coll $0events 1;
#T flags 1 0;
#T 1 messagebox “set do this”;
#T 2 messagebox “set do that”;
#T 3 number 5;
#T 4 number 10;
#T 5 number 40 messagebox “set two at a time”;
#T 6 number 50 messagebox “set three is enough?” mess “set more and
more”;
#T 7 messagebox “set AAA” mess set number “frgb 0 0 0″ number “brgb
232 232 232″;
#T 8 messagebox set number “frgb 255 127 0″ number “brgb 0 31 63″;
#P newobj 98 91 81 196617 coll $0events 1;
#P window linecount 0;
#P message 318 357 121 196617;
#P objectname mess;
#P window linecount 1;
#P comment 299 187 24 196617 key;
#P user panel 292 307 223 85;
#X brgb 0 129 214;
#X frgb 0 0 0;
#X border 1;
#X rounded 0;
#X shadow 0;
#X done;
#P connect 4 0 6 0;
#P connect 4 0 5 0;
#P connect 22 0 3 0;
#P connect 5 0 7 0;
#P connect 8 3 9 0;
#P connect 8 2 9 0;
#P connect 21 1 4 0;
#P connect 21 0 4 0;
#P connect 3 0 21 0;
#P connect 6 0 8 0;
#P connect 8 0 10 0;
#P connect 8 1 10 0;
#P connect 20 0 3 0;
#P connect 18 0 3 0;
#P connect 15 0 3 0;
#P connect 14 0 3 0;
#P connect 13 0 3 0;
#P connect 12 0 3 0;
#P connect 11 0 3 0;
#P fasten 7 0 10 0 246 289;
#P connect 9 0 10 0;
#P window clipboard copycount 23;

#139234
Sep 2, 2008 at 8:20am

On 1-sep-2008, at 23:32, jasch wrote:

> i would argue that you’re operating with key:value or
> address:content pairs.
> the value can be a float, int, symbol or list. the list should be
> encoded as a symbol by putting qutoes around it in order to be
> certain it goes through as one atom.
>
> hth

continuing along this line:
coll is able to handle key:value pairs.
you need key:list-of-value pairs, so it seems

you can achieve this with a two stage key
one coll stores key:list-of-intermediate-key pairs
the second coll stores intermediate-key:value pairs

your example
1, 1 2 3 4;
2, a 1 b c 2;

would look like
[first coll]
1, 1000
2, 2000 2001

[second coll]
1000, 1 2 3 4
2000, a 1
2001, b c 2

(I do not have time to do a sample patch right now)

this is more housekeeping, but less quoting unquoting.
it all depends on what kind of things and how many sublists you need
to put in your coll values.

HtH
-jennek

#139235
Sep 2, 2008 at 10:39pm

Many thanks all.

Funny how looking at a problem in one way for too long can blind you to looking for alternative ways of solving it. I was hell bent in including ‘commas’ in my coll data…

In my case the best solution seems to be pairing my terms via enclosing the relevant bits with “a b c” then using [zl iter 2].

I think it was the pointer to using [fromsymbol] which i’d been unable to see for myself.

I’d be interested in seeing Chris Muir’s solution. Presumably it would enable the use of arbritarily lengthed groups of terms. Anyone fancy doing a Max 4 version?

Cheers

#139236
Sep 2, 2008 at 11:13pm

3am moment…

Solved this using ‘commas’ to seperate my terms within coll data as per my initial problem. Uses good old backslash(), the [fromsymbol] object and a message box.

Not sure of the implications performance wise of using the messagebox like this to split the list but it works.

Probably not actually as useful as the key:value solutions suggested above mind…

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 270 204 64 196617 fromsymbol;
#P newex 248 287 32 196617 print;
#P newex 248 167 69 196617 route symbol;
#P message 248 264 50 196617 a b , c;
#P newex 270 228 62 196617 prepend set;
#P newex 248 229 20 196617 t b;
#P message 248 120 14 196617 1;
#N coll test 1;
#T flags 1 0;
#T 1 ” a b , c”;
#P newobj 248 143 56 196617 coll test 1;
#P connect 1 0 0 0;
#P connect 0 0 5 0;
#P connect 5 0 2 0;
#P connect 2 0 4 0;
#P connect 3 0 4 0;
#P connect 4 0 6 0;
#P connect 5 0 7 0;
#P connect 7 0 3 0;
#P window clipboard copycount 8;

#139237
Sep 3, 2008 at 12:24am

On Sep 2, 2008, at 3:39 PM, Willy C wrote:

> I’d be interested in seeing Chris Muir’s solution. Presumably it
> would enable the use of arbritarily lengthed groups of terms. Anyone
> fancy doing a Max 4 version?

I decided to check out the .maxpat to .pat converter, which is
discussed in this thread – http://www.cycling74.com/forums/index.php?t=msg&goto=146725

#P window setfont Verdana 12.;
#P window linecount 2;
#P comment 179 117 258 472055820 end is only required when there is
symbol data at the end of a coll entry.;
#P window linecount 1;
#P comment 179 94 258 472055820 keywords “addr , ” “data , ” and
“end”;
#P button 179 179 20 0;
#P newex 113 256 62 472055820 route int;
#P newex 156 286 59 472055820 zl group;
#P newex 27 232 93 472055820 prepend send;
#P newex 27 205 105 472055820 gate 2;
#P message 70 177 33 472055820 2;
#P message 27 177 33 472055820 1;
#P newex 27 118 31 472055820 iter;
#P message 161 34 32 472055820 5;
#P message 128 34 32 472055820 4;
#P message 95 34 32 472055820 3;
#P message 62 34 32 472055820 2;
#P message 27 34 33 472055820 1;
#P newex 27 142 148 472055820 route addr data end;
#P window setfont Verdana 9.;
#P newex 27 315 70 472055817 pattrforward;
#P window setfont Verdana 12.;
#N coll combined 1;
#T flags 1 0;
#T 1 addr messagebox data set dothisnow end;
#T 2 addr messagebox data set dothistoo end;
#T 3 addr number data 20;
#T 4 addr number data 30;
#T 5 addr number data 40 addr messagebox data set two at a time end;
#P newobj 27 95 105 472055820 coll combined 1;
#P window setfont Verdana 9.;
#P comment 261 243 79 472055817 messagebox;
#P window setfont Verdana 12.;
#P number 354 256 39 12 0 0 0 7203 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname number;
#P message 257 256 89 472055820 two at a time;
#P objectname messagebox;
#P window setfont Verdana 9.;
#P comment 351 243 43 472055817 number;
#P user panel 255 239 146 41;
#X brgb 0 177 232;
#X frgb 0 0 0;
#X border 1;
#X rounded 0;
#X shadow 0;
#X done;
#P connect 8 0 5 0;
#P connect 9 0 5 0;
#P connect 10 0 5 0;
#P connect 11 0 5 0;
#P connect 12 0 5 0;
#P connect 5 0 13 0;
#P connect 14 0 16 0;
#P connect 15 0 16 0;
#P connect 16 0 17 0;
#P connect 17 0 6 0;
#P connect 16 1 19 0;
#P connect 19 0 6 0;
#P connect 7 1 15 0;
#P connect 7 0 14 0;
#P fasten 7 0 20 0 37 169 189 169;
#P connect 13 0 7 0;
#P fasten 20 0 18 0 189 228 189 281 166 281;
#P connect 18 0 6 0;
#P connect 19 1 18 0;
#P fasten 7 2 20 0 123 169 189 169;
#P fasten 7 3 16 1 166 199 123 199;
#P window clipboard copycount 23;

Chris Muir
cbm@well.com

http://www.xfade.com

#139238

You must be logged in to reply to this topic.