[javascript-dev] Re: Saving files by js
Dominique DAVID
domi at cantatio.com
Sat Jun 2 03:52:06 MDT 2007
- Previous message: [javascript-dev] Saving files by js
- Next message: [javascript-dev] Re: progress indicator...
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hello
Thanks for answering. Here is the patch (somewhat long because it includes computation of the check redundancy code for png) and after the patch the js function.
Basically, when you click on the message, you are asking for the png image where data must be merged, and a second opendialog asks for the data file to embed.
------------------------------------
max v2;
#N vpatcher 41 53 485 345;
#P origin 0 -14;
#P window setfont "Sans Serif" 9.;
#P hidden newex 331 26 92 131137545 bgcolor 200 200 230;
#N vpatcher 316 110 758 770;
#P window setfont "Sans Serif" 9.;
#P newex 138 557 72 131137545 v eli_full_name;
#P outlet 124 607 15 0;
#P newex 138 582 137 131137545 print successfully_created_file;
#P newex 229 109 59 131137545 print reading;
#P newex 193 145 43 131137545 deferlow;
#P newex 193 82 46 131137545 t b l l;
#P newex 126 171 62 131137545 prepend read;
#P newex 193 50 52 131137545 opendialog;
#P newex 124 397 53 131137545 b 4;
#P newex 313 517 82 131137545 prepend add_data;
#P newex 239 193 46 131137545 s init_crc;
#P newex 216 215 56 131137545 s init_count;
#P newex 193 170 56 131137545 t dump 1 -1;
#P newex 258 428 44 131137545 r init_crc;
#P newex 166 484 21 131137545 iter;
#N vpatcher 210 72 1090 880;
#P window setfont "Sans Serif" 9.;
#P message 548 239 72 131137545 101 \, 108 \, 73 \, 120;
#P newex 548 203 91 131137545 t b i;
#P inlet 548 178 15 0;
#P inlet 401 177 15 0;
#P outlet 202 639 15 0;
#P newex 202 606 323 131137545 0 0 0 0;
#P inlet 202 179 15 0;
#P window setfont "Sans Serif" 18.;
#P window linecount 1;
#P comment 12 33 397 131137554 Calculateur de CRC pour image au format PNG.;
#P window setfont "Sans Serif" 9.;
#P comment 12 59 385 131137545 Mise en oeuvre l'algorithme de la spécification PNG spec v1.0 indiqué en pages 74 & 75.;
#P comment 12 76 319 131137545 CRC must be computed on both identifier code (4 bytes) and data bytes.;
#P window linecount 0;
#N vpatcher 15 55 620 532;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 205 54 45 131137545 loadbang;
#P window linecount 2;
#P newex 205 309 96 131137545 expr $i1 & 2147483647;
#P window linecount 1;
#P newex 205 284 27 131137545 >> 1;
#P window linecount 2;
#P newex 382 310 96 131137545 expr $i1 & 2147483647;
#P window linecount 1;
#N coll crc_table;
#P newobj 129 311 63 131137545 coll crc_table;
#P newex 129 286 52 131137545 0 0;
#P newex 129 235 52 131137545 b;
#P newex 309 162 39 131137545 t i i;
#P newex 338 188 39 131137545 v index;
#P newex 129 261 39 131137545 v index;
#P newex 171 261 22 131137545 v c;
#P newex 205 373 22 131137545 v c;
#P newex 205 348 100 131137545 expr $i1 ^ -306674912;
#P newex 205 260 22 131137545 v c;
#P newex 382 349 22 131137545 v c;
#P newex 205 235 187 131137545 if (($i1 & 1) == 1) then bang else out2 bang;
#P newex 382 260 22 131137545 v c;
#P newex 205 179 22 131137545 v c;
#P button 205 85 15 0;
#P newex 309 188 22 131137545 v c;
#P newex 382 285 27 131137545 >> 1;
#P newex 226 207 27 131137545 % 2;
#P newex 309 138 27 131137545 - 1;
#P newex 205 139 40 131137545 uzi 8;
#P newex 205 111 114 131137545 uzi 256;
#P comment 156 34 193 131137545 precompute loo-up table for all byte values;
#P window linecount 2;
#P comment 113 393 372 131137545 On faut suivre l'opératuer de rightshift par & 2147483647 pour contre le 1 introduit par le complément 2 sur 32 bits. On veut introduire 0 à gauche de l'opérande et non 1.;
#P fasten 3 1 20 0 225 169 134 169;
#P connect 20 0 17 0;
#P connect 17 0 21 0;
#P connect 21 0 22 0;
#P connect 20 1 16 0;
#P connect 16 0 21 1;
#P connect 26 0 8 0;
#P connect 8 0 2 0;
#P connect 2 0 3 0;
#P connect 3 0 9 0;
#P connect 9 0 11 0;
#P connect 5 0 11 0;
#P connect 11 0 13 0;
#P connect 13 0 24 0;
#P connect 24 0 25 0;
#P connect 25 0 14 0;
#P connect 14 0 15 0;
#P connect 2 2 4 0;
#P connect 4 0 19 0;
#P connect 19 0 7 0;
#P connect 19 1 18 0;
#P connect 11 1 10 0;
#P connect 10 0 6 0;
#P connect 6 0 23 0;
#P connect 23 0 12 0;
#P pop;
#P newobj 13 97 108 131137545 p precompute_crc_table;
#P window linecount 1;
#P newex 629 239 30 131137545 v crc;
#P newex 202 575 103 131137545 expr ($i1 >> 24) & 255;
#P newex 306 575 103 131137545 expr ($i1 >> 16) & 255;
#P newex 410 575 95 131137545 expr ($i1 >> 8) &0xff;
#P newex 202 541 324 131137545 t i i i i;
#P newex 514 575 71 131137545 expr $i1 & 255;
#N vpatcher 25 70 599 694;
#P window setfont "Sans Serif" 9.;
#P window linecount 3;
#P comment 87 43 388 131137545 On faut suivre l'opératuer de rightshift par & 2147483647 pour contre le 1 introduit par le complément 2 sur 32 bits. On veut introduire 0 à gauche de l'opérande et non 1. Ici \, on fait le tout 8 fois pour obtenir le shiftright de 8 souhaité. On doit pouvoir faire plus compact.;
#P outlet 203 526 15 0;
#P inlet 203 100 15 0;
#P window linecount 1;
#P newex 203 499 109 131137545 expr $i1 & 2147483647;
#P newex 203 474 27 131137545 >> 1;
#P newex 203 449 109 131137545 expr $i1 & 2147483647;
#P newex 203 424 27 131137545 >> 1;
#P newex 203 399 109 131137545 expr $i1 & 2147483647;
#P newex 203 374 27 131137545 >> 1;
#P newex 203 349 109 131137545 expr $i1 & 2147483647;
#P newex 203 324 27 131137545 >> 1;
#P newex 203 299 109 131137545 expr $i1 & 2147483647;
#P newex 203 274 27 131137545 >> 1;
#P newex 203 249 109 131137545 expr $i1 & 2147483647;
#P newex 203 224 27 131137545 >> 1;
#P newex 203 199 109 131137545 expr $i1 & 2147483647;
#P newex 203 174 27 131137545 >> 1;
#P newex 203 149 109 131137545 expr $i1 & 2147483647;
#P newex 203 124 27 131137545 >> 1;
#P connect 16 0 0 0;
#P connect 0 0 1 0;
#P connect 1 0 2 0;
#P connect 2 0 3 0;
#P connect 3 0 4 0;
#P connect 4 0 5 0;
#P connect 5 0 6 0;
#P connect 6 0 7 0;
#P connect 7 0 8 0;
#P connect 8 0 9 0;
#P connect 9 0 10 0;
#P connect 10 0 11 0;
#P connect 11 0 12 0;
#P connect 12 0 13 0;
#P connect 13 0 14 0;
#P connect 14 0 15 0;
#P connect 15 0 17 0;
#P pop;
#P newobj 453 465 68 131137545 p shift_right_8;
#P newex 202 513 92 131137545 expr $i1 ^ -1;
#P newex 401 516 30 131137545 v crc;
#P newex 202 486 30 131137545 v crc;
#P newex 401 492 62 131137545 expr $i1 ^ $i2;
#P newex 453 434 30 131137545 v crc;
#P newex 401 407 62 131137545 t i b;
#N coll crc_table;
#P newobj 401 377 63 131137545 coll crc_table;
#P newex 401 322 30 131137545 v crc;
#P newex 401 293 101 131137545 t b i;
#P newex 401 350 101 131137545 expr (($i2 ^ $i1)& 0xff);
#P window linecount 0;
#P comment 662 242 132 131137545 preload to OxFFFFFFFF = -1;
#P comment 565 179 100 131137545 init;
#P comment 418 177 100 131137545 compute;
#P comment 221 179 100 131137545 output when finished;
#P comment 414 260 129 131137545 elIx prefix contributes to crc;
#P connect 26 0 12 0;
#P connect 12 0 14 0;
#P connect 14 0 17 0;
#P connect 17 0 20 0;
#P connect 20 0 27 0;
#P connect 27 0 28 0;
#P connect 17 1 19 0;
#P connect 19 0 27 1;
#P connect 29 0 6 0;
#P fasten 32 0 6 0 553 274 406 274;
#P connect 6 0 7 0;
#P connect 7 0 5 0;
#P connect 5 0 8 0;
#P connect 8 0 9 0;
#P connect 9 0 11 0;
#P connect 11 0 13 0;
#P connect 17 2 18 0;
#P connect 18 0 27 2;
#P connect 9 1 10 0;
#P connect 10 0 15 0;
#P connect 15 0 11 1;
#P connect 6 1 5 1;
#P connect 17 3 16 0;
#P connect 16 0 27 3;
#P connect 30 0 31 0;
#P connect 31 0 32 0;
#P connect 31 1 21 0;
#P pop;
#P newobj 166 455 102 131137545 p elIx_CRC_calculator;
#P message 152 521 31 131137545 finish;
#P newex 193 319 29 131137545 t 13 l;
#P newex 212 348 21 131137545 iter;
#P newex 212 388 27 131137545 t i i;
#P newex 193 293 40 131137545 atoi;
#N coll ;
#P newobj 193 244 53 131137545 coll;
#P inlet 193 30 15 0;
#P outlet 313 566 15 0;
#P fasten 2 3 15 0 240 279 129 279;
#P connect 15 0 22 0;
#P fasten 18 1 17 0 216 136 131 136;
#P connect 15 1 23 0;
#P connect 23 0 21 0;
#P connect 15 2 7 0;
#P connect 15 3 8 0;
#P connect 8 0 9 0;
#P connect 1 0 16 0;
#P connect 16 0 18 0;
#P connect 18 0 19 0;
#P connect 19 0 11 0;
#P fasten 17 0 2 0 131 217 198 217;
#P connect 11 0 2 0;
#P connect 2 0 3 0;
#P connect 3 0 6 0;
#P connect 6 1 5 0;
#P connect 5 0 4 0;
#P fasten 6 0 4 0 198 374 217 374;
#P connect 4 0 8 1;
#P connect 11 1 12 0;
#P connect 18 2 20 0;
#P connect 11 2 13 0;
#P connect 10 0 8 2;
#P fasten 9 0 14 0 171 510 318 510;
#P fasten 4 1 14 0 234 419 318 419;
#P fasten 7 0 0 0 157 550 318 550;
#P connect 14 0 0 0;
#P pop;
#P newobj 80 149 127 131137545 p read_and_dump_midi_data;
#N vpatcher 266 90 706 671;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 187 368 72 131137545 v eli_full_name;
#P window linecount 0;
#P newex 170 341 27 131137545 t l l;
#P newex 170 153 109 131137545 t l l;
#N vpatcher 568 218 1020 696;
#P window setfont "Sans Serif" 9.;
#P window linecount 0;
#P message 81 344 44 131137545 PNG file;
#P newex 81 371 61 131137545 print opening;
#P newex 50 316 41 131137545 b;
#P outlet 50 344 15 0;
#P window linecount 1;
#P newex 99 151 40 131137545 atoi;
#P newex 50 263 56 131137545 v check_eli;
#P message 192 318 86 131137545 Already an ELI file;
#P newex 192 345 78 131137545 print WARNING!;
#P newex 50 290 152 131137545 if $i1==0 then bang else out2 bang;
#P newex 99 230 56 131137545 v check_eli;
#P newex 99 204 19 131137545 t 1;
#P newex 80 102 56 131137545 v check_eli;
#P newex 99 178 101 131137545 match 46 101 108 105;
#P newex 65 125 44 131137545 zl ecils 4;
#P newex 50 50 78 131137545 v png_full_name;
#P newex 50 77 40 131137545 t b l 0;
#P inlet 50 30 15 0;
#P connect 0 0 2 0;
#P connect 2 0 1 0;
#P connect 1 0 11 0;
#P connect 11 0 8 0;
#P connect 8 0 14 0;
#P connect 14 0 13 0;
#P connect 1 1 3 0;
#P connect 1 2 5 0;
#P connect 14 1 16 0;
#P connect 16 0 15 0;
#P connect 3 1 12 0;
#P connect 12 0 4 0;
#P connect 4 0 6 0;
#P connect 6 0 7 0;
#P connect 8 1 10 0;
#P connect 10 0 9 0;
#P pop;
#P newobj 170 84 73 131137545 p check_eli_file;
#P window linecount 1;
#P newex 170 121 78 131137545 v png_full_name;
#P window linecount 0;
#N vpatcher 433 81 779 704;
#P window setfont "Sans Serif" 9.;
#P window linecount 0;
#P newex 38 424 62 131137545 v check_png;
#P message 180 479 96 131137545 Not a valid PNG file;
#P newex 180 506 78 131137545 print WARNING!;
#P newex 38 451 152 131137545 if $i1==1 then bang else out2 bang;
#P newex 53 223 27 131137545 - 1;
#P window linecount 1;
#P newex 92 389 62 131137545 v check_png;
#P newex 92 362 19 131137545 t 1;
#P newex 215 75 62 131137545 v check_png;
#P newex 92 337 143 131137545 match 137 80 78 71 13 10 26 10;
#P newex 92 303 48 131137545 zl group 8;
#P newex 23 197 40 131137545 uzi 8;
#P newex 109 135 78 131137545 v png_full_name;
#P newex 92 109 27 131137545 t l l;
#P newex 92 266 40 131137545 filein;
#P newex 92 162 62 131137545 prepend read;
#P newex 92 50 133 131137545 t b 0;
#P newex 92 77 52 131137545 opendialog;
#P inlet 92 30 15 0;
#P outlet 38 509 15 0;
#P fasten 5 2 8 0 127 292 143 292 143 190 28 190;
#P connect 8 1 18 0;
#P connect 18 0 15 0;
#P connect 15 0 0 0;
#P connect 8 2 14 0;
#P connect 1 0 3 0;
#P connect 3 0 2 0;
#P connect 2 0 6 0;
#P connect 6 0 4 0;
#P fasten 14 0 5 0 58 254 97 254;
#P connect 4 0 5 0;
#P connect 5 0 9 0;
#P connect 9 0 10 0;
#P connect 10 0 12 0;
#P connect 12 0 13 0;
#P connect 6 1 7 0;
#P connect 15 1 17 0;
#P connect 17 0 16 0;
#P connect 3 1 11 0;
#P pop;
#P newobj 170 51 79 131137545 p check_png_file;
#P outlet 170 522 15 0;
#P window linecount 1;
#P newex 170 490 43 131137545 deferlow;
#P newex 170 461 82 131137545 t b l;
#P newex 170 434 83 131137545 prepend mergefile;
#P newex 170 409 41 131137545 prepend;
#P newex 269 315 57 131137545 prepend set;
#P newex 170 313 40 131137545 itoa;
#P newex 170 287 31 131137545 zl join;
#P message 191 263 72 131137545 46 101 108 105;
#P newex 170 237 31 131137545 t l b;
#P newex 170 211 44 131137545 zl ecils 4;
#P newex 170 182 40 131137545 atoi;
#P inlet 170 31 15 0;
#P outlet 242 523 15 0;
#P window linecount 0;
#P comment 42 266 131 131137545 change name.png to name.eli;
#P connect 2 0 15 0;
#P connect 15 0 17 0;
#P connect 17 0 16 0;
#P connect 16 0 18 0;
#P connect 18 0 3 0;
#P connect 3 0 4 0;
#P connect 4 0 5 0;
#P connect 5 0 7 0;
#P connect 7 0 8 0;
#P connect 8 0 19 0;
#P fasten 9 0 10 0 274 401 175 401;
#P connect 19 0 10 0;
#P connect 10 0 11 0;
#P connect 11 0 12 0;
#P connect 12 0 13 0;
#P connect 13 0 14 0;
#P connect 19 1 20 0;
#P connect 5 1 6 0;
#P connect 6 0 7 1;
#P connect 12 1 1 0;
#P connect 18 1 9 0;
#P pop;
#P newobj 80 111 95 131137545 p process_filenames;
#P window setfont "Sans Serif" 12.;
#P message 80 76 203 131137548 1. open png file 2. midi_data textfile;
#B color 6;
#P window setfont "Sans Serif" 9.;
#P newex 210 186 110 131137545 js dd_png2eli_encoder.js;
#P window setfont "Sans Serif" 20.;
#P comment 5 3 197 131137556 PNG to ELI Encoder;
#B color 13;
#P window setfont "Sans Serif" 9.;
#P comment 5 28 175 131137545 Direct writing of eli file in png directory;
#P connect 3 0 4 0;
#P connect 4 0 5 0;
#P fasten 4 1 2 0 170 137 215 137;
#P fasten 5 1 2 0 202 177 215 177;
#P pop;
-------------------------
this is part of the javascript, which is called each time the dump is outputing a byte from the coll (not too complex...):
function add_data(x)
{
var a;
a=x;
dstfile.writebytes(a);
number_of_added = number_of_added + 1; // including crc count = 4
}
-------------------------
The pb occurs as well when trying to save only the coll content (not within a png image).
- Previous message: [javascript-dev] Saving files by js
- Next message: [javascript-dev] Re: progress indicator...
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
