Forums > MaxMSP

coll: [1] else/other [2] output csv

November 21, 2008 | 1:43 am

Hello all,

I have 2 questions concerning coll.

[1] I have a set of 24 messages in coll. they output when a certain sequence of numbers triggers it. However, there are more possible sequences than there are messages, so my question is, what’s the easiest way to say, ‘when not one of the 24 sequence, print: Other’ without having to type in each possible sequence [which i couldn't do anyways since coll has a limit on how many seq it can take store].

[2] how/can i use coll to output a csv file? or is there another object that would work better for that?

thanks in advance.

max v2;
#N vpatcher 752 70 1238 487;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 33 36 115 196617 1 0 1 0 0 0 0 1 0 0 0 0;
#P newex 130 330 32 196617 print;
#N coll ;
#T flags 1 0;
#T 145 AM;
#T 137 Am;
#T 290 A#M;
#T 274 A#m;
#T 580 BM;
#T 548 Bm;
#T 1160 CM;
#T 1096 Cm;
#T 2320 C#M;
#T 2192 C#m;
#T 545 DM;
#T 289 Dm;
#T 1090 D#M;
#T 578 D#m;
#T 2180 EM;
#T 1156 Em;
#T 265 FM;
#T 2312 Fm;
#T 530 F#M;
#T 529 F#m;
#T 1060 GM;
#T 1058 Gm;
#T 2120 G#M;
#T 2116 G#m;
#P newobj 130 301 53 196617 coll;
#P message 54 57 115 196617 1 0 0 1 0 0 0 1 0 0 0 0;
#P message 86 77 115 196617 0 0 0 1 0 0 0 1 0 0 1 0;
#P message 109 96 115 196617 1 0 0 0 0 1 0 0 1 0 0 0;
#P newex 131 254 45 196617 bits2int;
#P number 130 276 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 127 231 157 196617 pack 0 0 0 0 0 0 0 0 0 0 0 0;
#P number 4 196 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 413 198 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 376 198 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 338 198 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 301 198 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 265 197 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 228 197 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 190 197 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 153 197 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 116 196 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 79 196 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 41 196 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 120 138 166 196617 unpack 1 2 3 4 5 6 7 8 9 10 11 12;
#P message 120 116 151 196617 0. 0. 0. 1. 0. 0. 1. 0. 0. 0. 0. 1.;
#P comment 229 97 100 196617 d-minor;
#P comment 203 78 100 196617 C-Major;
#P comment 171 57 100 196617 A-minor;
#P comment 273 115 100 196617 G#-Major;
#P comment 156 36 100 196617 -other-;
#P connect 6 0 18 0;
#P connect 6 1 7 0;
#P connect 6 2 8 0;
#P connect 6 3 9 0;
#P connect 27 0 6 0;
#P connect 5 0 6 0;
#P connect 24 0 6 0;
#P connect 22 0 6 0;
#P connect 23 0 6 0;
#P connect 18 0 19 0;
#P connect 21 0 20 0;
#P connect 20 0 25 0;
#P connect 25 0 26 0;
#P connect 19 0 21 0;
#P connect 7 0 19 1;
#P connect 6 4 10 0;
#P connect 8 0 19 2;
#P connect 9 0 19 3;
#P connect 10 0 19 4;
#P connect 6 5 11 0;
#P connect 11 0 19 5;
#P connect 12 0 19 6;
#P connect 13 0 19 7;
#P connect 6 6 12 0;
#P connect 14 0 19 8;
#P connect 15 0 19 9;
#P connect 16 0 19 10;
#P connect 6 7 13 0;
#P connect 17 0 19 11;
#P connect 6 8 14 0;
#P connect 6 9 15 0;
#P connect 6 10 16 0;
#P connect 6 11 17 0;
#P pop;


November 21, 2008 | 3:41 am

You could use [gate] like this. I hope it does what you need.

lh

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 186 375 33 196617 gate;
#P newex 251 397 32 196617 print;
#P newex 232 352 29 196617 t 0 l;
#N coll ;
#T flags 1 0;
#T 145 AM;
#T 137 Am;
#T 290 A#M;
#T 274 A#m;
#T 580 BM;
#T 548 Bm;
#T 1160 CM;
#T 1096 Cm;
#T 2320 C#M;
#T 2192 C#m;
#T 545 DM;
#T 289 Dm;
#T 1090 D#M;
#T 578 D#m;
#T 2180 EM;
#T 1156 Em;
#T 265 FM;
#T 2312 Fm;
#T 530 F#M;
#T 529 F#m;
#T 1060 GM;
#T 1058 Gm;
#T 2120 G#M;
#T 2116 G#m;
#P newobj 232 331 53 196617 coll;
#P newex 186 310 56 196617 t 1 other i;
#P message 92 54 115 196617 1 0 1 0 0 0 0 1 0 0 0 0;
#P message 113 75 115 196617 1 0 0 1 0 0 0 1 0 0 0 0;
#P message 145 95 115 196617 0 0 0 1 0 0 0 1 0 0 1 0;
#P message 168 114 115 196617 1 0 0 0 0 1 0 0 1 0 0 0;
#P newex 186 270 45 196617 bits2int;
#P number 186 291 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 179 134 151 196617 0. 0. 0. 1. 0. 0. 1. 0. 0. 0. 0. 1.;
#P comment 288 115 100 196617 d-minor;
#P comment 262 96 100 196617 C-Major;
#P comment 230 75 100 196617 A-minor;
#P comment 332 133 100 196617 G#-Major;
#P comment 215 54 100 196617 -other-;
#P newex 186 249 157 196617 pack 0 0 0 0 0 0 0 0 0 0 0 0;
#P number 63 214 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 472 216 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 435 216 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 397 216 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 360 216 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 324 215 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 287 215 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 249 215 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 212 215 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 175 214 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 138 214 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 100 214 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 179 156 166 196617 unpack 1 2 3 4 5 6 7 8 9 10 11 12;
#P connect 25 0 0 0;
#P connect 19 0 0 0;
#P connect 24 0 0 0;
#P connect 22 0 0 0;
#P connect 23 0 0 0;
#P connect 13 0 21 0;
#P connect 0 0 12 0;
#P connect 0 1 1 0;
#P connect 0 2 2 0;
#P connect 0 3 3 0;
#P connect 12 0 13 0;
#P connect 1 0 13 1;
#P connect 0 4 4 0;
#P connect 2 0 13 2;
#P connect 3 0 13 3;
#P connect 4 0 13 4;
#P connect 0 5 5 0;
#P connect 5 0 13 5;
#P connect 6 0 13 6;
#P connect 7 0 13 7;
#P connect 0 6 6 0;
#P connect 8 0 13 8;
#P connect 9 0 13 9;
#P connect 10 0 13 10;
#P connect 0 7 7 0;
#P connect 11 0 13 11;
#P connect 0 8 8 0;
#P connect 0 9 9 0;
#P connect 0 10 10 0;
#P connect 0 11 11 0;
#P connect 20 0 26 0;
#P connect 26 1 30 1;
#P connect 26 0 30 0;
#P fasten 28 0 30 0 237 372 191 372;
#P fasten 30 0 29 0 191 394 256 394;
#P connect 28 1 29 0;
#P connect 27 0 28 0;
#P connect 26 2 27 0;
#P connect 21 0 20 0;
#P window clipboard copycount 31;


November 21, 2008 | 4:21 am

And this should create your comma separated values file. The left [button] parses the info in [coll]. The other one saves it with whatever name is in the [textedit] object to a folder chosen in the dialog that will open.

lh

#P window setfont "Sans Serif" 9.;
#P window linecount 2;
#P newex 320 146 89 196617 sprintf write "%s%s.csv";
#P window linecount 1;
#P newex 400 126 56 196617 route text;
#P user textedit 400 106 501 123 32904 3 9 lalala;
#P newex 320 86 90 196617 t b b;
#P button 320 68 15 0;
#P newex 320 106 76 196617 opendialog fold;
#P newex 102 180 32 196617 print;
#P newex 56 180 40 196617 text;
#P newex 56 158 100 196617 sprintf %ld %s\\\,;
#P newex 137 116 62 196617 prepend set;
#P newex 56 138 45 196617 prepend;
#P newex 56 116 69 196617 route symbol;
#N coll chordnames;
#T flags 1 0;
#T 145 AM;
#T 137 Am;
#T 290 A#M;
#T 274 A#m;
#T 580 BM;
#T 548 Bm;
#T 1160 CM;
#T 1096 Cm;
#T 2320 C#M;
#T 2192 C#m;
#T 545 DM;
#T 289 Dm;
#T 1090 D#M;
#T 578 D#m;
#T 2180 EM;
#T 1156 Em;
#T 265 FM;
#T 2312 Fm;
#T 530 F#M;
#T 529 F#m;
#T 1060 GM;
#T 1058 Gm;
#T 2120 G#M;
#T 2116 G#m;
#P newobj 56 96 257 196617 coll chordnames;
#P newex 56 76 40 196617 t dump;
#P button 56 58 15 0;
#P connect 9 0 14 0;
#P connect 13 0 14 1;
#P fasten 14 0 7 0 325 177 61 177;
#P connect 6 0 7 0;
#P fasten 6 0 8 0 61 177 107 177;
#P connect 12 0 13 0;
#P connect 11 1 12 0;
#P connect 11 0 9 0;
#P connect 10 0 11 0;
#P connect 4 0 6 0;
#P fasten 5 0 4 0 142 135 61 135;
#P connect 2 1 5 0;
#P fasten 3 1 4 0 120 135 61 135;
#P connect 3 0 4 0;
#P connect 2 0 3 0;
#P connect 1 0 2 0;
#P connect 0 0 1 0;
#P window clipboard copycount 15;


November 25, 2008 | 1:31 am

Hey lh,

thanks for all the help.
i still have a question though, 2 actually!
[1] is there a way to set the filename so it’s not always triggered to ask. that way it’ll automatically save.
[2] the values are saved horizontally. to use them in excel against another set of preset values, is there a way to save them vertically?

again,
thanks!

…here’s the patch i’ve ‘tweaked’
max v2;
#N vpatcher 401 51 987 442;
#P window setfont "Sans Serif" 9.;
#P newex 137 218 40 196617 text;
#P objectname test1;
#P newex 56 186 103 196617 sprintf %ld %s \\\,;
#P newex 138 123 62 196617 prepend set;
#P newex 56 165 45 196617 prepend;
#P newex 56 123 69 196617 route symbol;
#N coll chordnames;
#T flags 1 0;
#T 145 AM;
#T 137 Am;
#T 290 A#M;
#T 274 A#m;
#T 580 BM;
#T 548 Bm;
#T 1160 CM;
#T 1096 Cm;
#T 2320 C#M;
#T 2192 C#m;
#T 545 DM;
#T 289 Dm;
#T 1090 D#M;
#T 578 D#m;
#T 2180 EM;
#T 1156 Em;
#T 265 FM;
#T 2312 Fm;
#T 530 F#M;
#T 529 F#m;
#T 1060 GM;
#T 1058 Gm;
#T 2120 G#M;
#T 2116 G#m;
#P newobj 56 100 257 196617 coll chordnames;
#P newex 56 78 40 196617 t dump;
#P button 56 34 15 0;
#P window linecount 5;
#P comment 51 265 90 196617 \\=comma %ld = intergers %s = symbols %f = floats %c = ASCII char;
#P window linecount 1;
#P newex 331 141 129 196617 sprintf write "%s%s.csv";
#P newex 331 95 90 196617 t b b;
#P newex 331 119 56 196617 opendialog;
#P connect 4 0 5 0;
#P connect 5 0 6 0;
#P connect 6 0 7 0;
#P connect 9 0 8 0;
#P connect 7 0 8 0;
#P connect 8 0 10 0;
#P connect 2 0 11 0;
#P connect 10 0 11 0;
#P connect 6 1 9 0;
#P connect 4 0 1 0;
#P connect 1 0 0 0;
#P connect 0 0 2 0;
#P pop;


November 25, 2008 | 5:58 pm

You can send the "write" message to the [text] object to save it with a specified name and at a specified location, for example:

write "Macintosh HD:/Users/username/Desktop/myfilename.csv"

If you want to prompt for the file and/or destination each time you can use [sprintf] and the [textedit] or [opendialog fold] objects, as I illustrated in the earlier patch I sent you.

To create new columns you need to insert a comma, which due to its special duties in max has to be escaped. Using [sprintf] and [text] sending "something","somethingelse" would be done [sprintf %s\,%s]. To create a new row you need to send the integer "13" to the [itoa] object to [text] which will create insert the ASCII new line character.

lh


Viewing 5 posts - 1 through 5 (of 5 total)