Forums > MaxMSP

[sharing is fun] drawing waveforms from buffer~: lcd, jit.lcd, and jit.gl.sketch

June 10, 2006 | 8:41 pm

This patch draws a waveform using 3 different methods. OK, maybe 2.5, since jit.lcd is pretty much the same as regular lcd.
Of course, this is sort of re-inventing the wheel, but this wheel has cool rims: it draws a waveform in openGL, too :) It includes adjustments for resolution, and for openGL, zoom and scroll.
I thought some might find this useful…

#P window setfont Geneva 9.;
#P window linecount 1;
#P comment 486 709 174 196617 pnyboer at slambassador dot com;
#P comment 485 690 174 196617 patch by peter nyboer;
#P comment 412 547 39 196617 (LCD);
#P comment 589 571 205 196617 name of pwindow is "waveform" of course!;
#P message 804 252 14 196617 0;
#P message 701 252 14 196617 1;
#P window linecount 2;
#P comment 167 122 133 196617 resolution. Default is every 44.1 samples;
#P window linecount 1;
#P comment 740 233 113 196617 Animate the waveform;
#P comment 861 254 33 196617 scroll;
#P comment 116 49 133 196617 1.) Read in a file to buffer~;
#P newex 670 441 52 196617 s drawGL;
#P newex 670 420 27 196617 t b l;
#P newex 670 399 52 196617 s drawGL;
#P newex 456 81 52 196617 s drawGL;
#P newex 625 40 52 196617 r drawGL;
#P newex 670 378 27 196617 t b l;
#P comment 388 596 174 196617 all pwindows are set to onscreen off;
#P comment 764 252 33 196617 zoom;
#P comment 577 357 169 196617 instead of a group of vertical lines;
#P comment 576 343 169 196617 use of bucket makes continuous line;
#P newex 167 81 78 196617 loadmess 44.1;
#P newex 455 347 33 196617 -3.3;
#P newex 494 347 42 196617 bucket;
#P newex 534 348 42 196617 bucket;
#P newex 142 155 32 196617 t b f;
#P flonum 167 102 81 9 1. 44100. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 600 377 29 196617 amp;
#P comment 607 307 33 196617 time;
#P comment 229 370 33 196617 time;
#P newex 105 158 30 196617 / 1.;
#P flonum 725 251 38 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 705 377 90 196617 pak scale 0. 1. 1.;
#P flonum 823 252 38 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 705 420 102 196617 pak position 0. 0. 0.;
#P message 447 419 186 196617 reset , glcolor 0.752941 0.65098 0. 1;
#P user jit.pwindow 499 467 402 102 0 0 0 0 1 0;
#X name waveform;
#P newex 494 305 113 196617 scale 0 1000 -3.3 3.3;
#P newex 625 62 44 196617 qlim 33;
#P newex 625 93 50 196617 t b erase;
#P newex 625 124 227 196617 jit.gl.render waveform @erase_color 0. 0. 0. 1.;
#P newex 469 391 173 196617 pack linesegment 0. 0. 0. 0.1 0. 0.;
#P newex 469 445 194 196617 jit.gl.sketch waveform @depth_enable 0;
#P newex 68 595 69 196617 jit.unpack;
#P newex 68 616 132 196617 jit.matrix 1 char 400 100;
#P newex 105 180 21 196617 t i;
#P button 6 96 18 0;
#P message 25 29 66 196617 import 0 -1;
#P button 400 34 18 0;
#P newex 400 55 66 196617 t b b 0. b b;
#P newex 431 130 44 196617 * 44.1;
#P newex 105 135 32 196617 * 1.;
#P newex 105 114 49 196617 / 1000.;
#P newex 25 94 108 196617 info~ drawme;
#P newex 68 573 114 196617 jit.lcd 4 char 400 100;
#P user jit.pwindow 9 635 402 102 0 0 0 0 1 0;
#P newex 431 108 30 196617 – 1;
#P message 324 449 90 196617 brgb 0 0 0 , clear;
#P newex 130 367 102 196617 scale 0 1000 0 400;
#P newex 130 415 206 196617 pack linesegment 10 50 10 100 192 166 0;
#P newex 232 393 95 196617 scale 1. -1. 0 100;
#P user lcd 10 468 400 100 1 1 0 0 0;
#P newex 400 80 53 196617 uzi 1000;
#P message 41 49 72 196617 read talk.aiff;
#P window setfont Geneva 12.;
#P newex 393 232 97 196620 peek~ drawme;
#B color 5;
#P window setfont Geneva 9.;
#P newex 25 73 113 196617 buffer~ drawme 1000;
#P comment 326 395 61 196617 amplitudes;
#P newex 751 332 30 196617 – 1.;
#P newex 775 310 32 196617 * 1.;
#P comment 419 36 115 196617 2.) draw the waveform;
#P fasten 12 0 8 0 329 466 15 466;
#P connect 10 0 8 0;
#P fasten 15 0 14 0 73 591 15 591;
#P connect 6 0 4 0;
#P connect 22 0 4 0;
#P fasten 20 4 16 0 461 74 30 74;
#P connect 23 0 16 0;
#P connect 4 1 16 0;
#P connect 7 1 15 0;
#P hidden fasten 12 0 15 0 329 572 73 572;
#P connect 10 0 15 0;
#P connect 15 0 26 0;
#P connect 26 1 25 0;
#P connect 16 6 17 0;
#P connect 16 0 18 0;
#P connect 18 0 39 0;
#P connect 44 0 39 0;
#P connect 39 0 24 0;
#P connect 44 1 39 1;
#P connect 17 0 18 1;
#P connect 13 0 11 0;
#P connect 7 0 10 0;
#P connect 43 0 44 0;
#P connect 11 0 10 1;
#P connect 24 0 11 2;
#P connect 48 0 43 0;
#P connect 11 0 10 3;
#P connect 5 0 9 0;
#P connect 9 0 10 4;
#P connect 20 1 12 0;
#P connect 19 0 5 0;
#P connect 21 0 20 0;
#P connect 20 0 7 0;
#P connect 7 2 13 0;
#P connect 13 0 19 0;
#P connect 24 0 7 1;
#P connect 20 1 34 0;
#P connect 20 3 47 0;
#P connect 7 1 55 0;
#P connect 43 0 19 1;
#P connect 7 0 28 0;
#P connect 57 1 27 0;
#P connect 53 1 27 0;
#P connect 28 0 27 0;
#P connect 34 0 27 0;
#P connect 13 0 32 0;
#P connect 32 0 46 0;
#P connect 47 0 46 0;
#P connect 46 0 28 1;
#P connect 45 0 28 2;
#P connect 24 0 32 2;
#P connect 5 0 45 0;
#P connect 20 2 45 0;
#P connect 32 0 28 4;
#P connect 5 0 28 5;
#P connect 54 0 31 0;
#P connect 31 0 30 0;
#P connect 30 1 29 0;
#P connect 30 0 29 0;
#P connect 37 0 53 0;
#P connect 53 0 56 0;
#P connect 35 0 57 0;
#P connect 57 0 58 0;
#P connect 63 0 38 0;
#P connect 38 0 37 1;
#P connect 36 0 35 1;
#P connect 38 0 2 0;
#P connect 1 0 2 1;
#P connect 38 0 1 0;
#P connect 64 0 36 0;
#P connect 2 0 36 0;
#P window clipboard copycount 69;


June 11, 2006 | 1:52 am

Hi, I hope this thread becomes perpetual. Id love to see some neat
tricks people come up with.

Here is a little patch that uses automatic 0 techniques to do some
letterboxing in openGL, and breakpoint functions to animate camera
paths around a model, and separate rendering destinations to give you
a 4 angle view of the scene like in maya/3D studio modeling
programs… I hope its helpful and fun to people,

max v2;
#N vpatcher 462 44 1127 637;
#P origin 0 6;
#P window setfont "Sans Serif" 9.;
#P comment 405 355 78 196617 read a model in;
#P button 402 370 88 0;
#P hidden newex 479 17 50 196617 qlim 300;
#P comment 32 4 38 196617 Power;
#P hidden newex 88 21 32 196617 sel 1;
#P hidden newex 435 15 29 196617 gate;
#P hidden message 549 322 20 196617 30;
#P hidden newex 550 296 48 196617 loadbang;
#P flonum 246 504 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 3;
#P comment 352 229 14 196617 xyz;
#P window linecount 1;
#N vpatcher 101 391 1115 944;
#P inlet 109 36 15 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 103 461 125 196617 forward preview_drawto;
#P newex 229 461 123 196617 forward preview_render;
#P message 229 443 198 196617 position 0. 0. -10. , rotatexyz 90.
180. 0.;
#P newex 49 497 123 196617 forward preview_render;
#P newex 85 479 134 196617 forward preview_pos_bang;
#P newex 49 423 66 196617 t b erase b b;
#P message 103 443 115 196617 drawto cam_position_z;
#P newex 117 362 125 196617 forward preview_drawto;
#P newex 243 362 123 196617 forward preview_render;
#P message 243 344 183 196617 position 0. 0. -10. , rotatexyz 0. 90. 0;
#P newex 63 398 123 196617 forward preview_render;
#P newex 99 380 134 196617 forward preview_pos_bang;
#P newex 63 324 66 196617 t b erase b b;
#P message 117 344 116 196617 drawto cam_position_y;
#P newex 131 255 125 196617 forward preview_drawto;
#P newex 257 255 123 196617 forward preview_render;
#P message 257 237 380 196617 ortho 0 , lens_angle 45 , camera 0.
0. 20. , position 0. 0. -10. , rotatexyz 0. 180. 0;
#P newex 145 138 125 196617 forward preview_drawto;
#P newex 271 138 123 196617 forward preview_render;
#P newex 77 291 123 196617 forward preview_render;
#P newex 91 176 123 196617 forward preview_render;
#P newex 558 305 91 196617 r preview_render;
#P message 270 120 386 196617 ortho 0 , lens_angle 45 , camera 0.
0. 20. , position 0. 0. -10 , rotatexyz 45. 145. 30;
#P newex 644 212 93 196617 r preview_drawto;
#P newex 113 273 134 196617 forward preview_pos_bang;
#P newex 127 158 134 196617 forward preview_pos_bang;
#P newex 719 234 102 196617 r preview_pos_bang;
#P newex 91 98 66 196617 t b erase b b;
#P newex 49 77 53 196617 t b b b b;
#P newex 77 217 66 196617 t b erase b b;
#P message 145 120 119 196617 drawto camera_position;
#P message 131 237 116 196617 drawto cam_position_x;
#P newex 719 258 101 196617 v preview_cam_pos;
#P newex 47 37 55 196617 r preview;
#P newex 48 57 50 196617 qlim 500;
#P window linecount 2;
#P newex 642 283 229 196617 jit.gl.gridshape camera_position @shape
sphere @scale 0.3 0.3 0.3 @color 1. 0. 0. @automatic 1;
#P newex 558 329 248 196617 jit.gl.render camera_position @axes 1
@erase_color 0.7 0.7 0.7 0.15 @antialias 1 @ortho 0;
#P connect 3 0 2 0;
#P connect 2 0 8 0;
#P connect 8 0 31 0;
#P connect 31 0 33 0;
#P connect 31 1 33 0;
#P connect 8 1 24 0;
#P connect 24 1 26 0;
#P connect 24 0 26 0;
#P connect 8 2 7 0;
#P connect 7 0 17 0;
#P connect 7 1 17 0;
#P connect 31 2 32 0;
#P connect 37 0 2 1;
#P connect 8 3 9 0;
#P connect 9 0 16 0;
#P connect 9 1 16 0;
#P connect 24 2 25 0;
#P connect 31 3 30 0;
#P connect 30 0 36 0;
#P connect 7 2 12 0;
#P connect 24 3 23 0;
#P connect 23 0 29 0;
#P connect 9 2 11 0;
#P connect 7 3 5 0;
#P connect 5 0 22 0;
#P connect 9 3 6 0;
#P connect 6 0 19 0;
#P fasten 31 3 34 0 108 441 234 441;
#P connect 34 0 35 0;
#P fasten 24 3 27 0 122 342 248 342;
#P connect 27 0 28 0;
#P fasten 7 3 20 0 136 235 262 235;
#P connect 20 0 21 0;
#P fasten 9 3 14 0 150 117 275 117;
#P connect 14 0 18 0;
#P connect 13 0 0 0;
#P connect 15 0 0 0;
#P connect 10 0 1 0;
#P connect 13 0 1 0;
#P connect 4 0 1 0;
#P connect 10 0 4 0;
#P pop;
#P newobj 246 522 69 196617 p preview_gl;
#P window linecount 2;
#P comment 353 345 14 196617 zx;
#P comment 22 345 14 196617 zy;
#P comment 22 228 14 196617 x y;
#P user jit.pwindow 194 343 159 115 1 0 0 0 1 0;
#X name cam_position_z;
#P objectname cam_position_x[2];
#P user jit.pwindow 34 343 159 115 1 0 0 0 1 0;
#X name cam_position_y;
#P objectname cam_position_x[1];
#P user jit.pwindow 34 227 159 115 1 0 0 0 1 0;
#X name cam_position_x;
#P objectname cam_position_x;
#P user jit.fpsgui 33 548 60 196617 0;
#P window linecount 1;
#P comment 93 2 160 196617 Animation Loop Time (in seconds);
#P number 255 1 35 9 0 300 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 22 212 126 196617 Cam Motion Preview;
#P hidden newex 136 185 101 196617 v preview_cam_pos;
#P newex 98 548 55 196617 s preview;
#P newex 33 502 51 196617 qmetro 2;
#N vpatcher 46 426 870 820;
#P origin 0 191;
#P inlet 408 -41 15 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 407 -23 30 196617 read;
#P window linecount 2;
#P newex 225 91 263 196617 jit.gl.model letter_box_finished
@automatic 0 @lighting_enable 1 @depth_enable 1 @smooth_shading 1;
#P outlet 51 359 15 0;
#P window linecount 1;
#P newex 63 290 136 196617 pak erase_color 0. 0. 0. 0.;
#P flonum 187 272 50 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 331 7 37 196617 v cam;
#P comment 135 345 150 196617 our render context and window;
#P newex 414 7 34 196617 v pos;
#P newex 375 7 33 196617 v rot;
#N vpatcher 116 497 650 753;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 105 131 376 196617 and send to the jit.gl.render instance
, now draw our two planes for letterboxing..;
#P window linecount 0;
#P newex 51 70 40 196617 t b b b;
#P window linecount 2;
#P newex 66 153 342 196617 jit.gl.gridshape letter_box_finished
@automatic 0 @shape plane @position 0. -1.7 0. @color 0. 0. 0. 1.
@scale 1.333 1. 1. @depth_enable 0;
#P newex 51 185 342 196617 jit.gl.gridshape letter_box_finished
@automatic 0 @shape plane @position 0. 1.7 0. @color 0. 0. 0. 1.
@scale 1.333 1. 1. @depth_enable 0;
#P window linecount 1;
#P message 81 99 380 196617 lookat 0. 0. 0. , position 0. 0. 0. ,
rotate 0. 0. 0. 1. , camera 0. 0. 2. , lookat 0. 0. 0.;
#P outlet 81 131 15 0;
#P inlet 51 49 15 0;
#P window linecount 0;
#P comment 137 82 143 196617 reset our camera to default…;
#P connect 1 0 6 0;
#P connect 6 0 4 0;
#P connect 6 1 5 0;
#P connect 6 2 3 0;
#P connect 3 0 2 0;
#P pop;
#P newobj 61 253 133 196617 p reset_cam_letter_boxing;
#P newex 75 -15 313 196617 t b b b b b;
#P newex 51 -62 58 196617 t b b erase;
#P newex 135 362 276 196617 jit.window letter_box_finished
@depthbuffer 1 @floating 1;
#P window linecount 2;
#P newex 51 311 222 196617 jit.gl.render letter_box_finished
@erase_color 0. 0. 0. 0.2 @depth_enable 1 @antialias 1;
#P inlet 51 -113 15 0;
#P outlet 75 7 15 0;
#P connect 1 0 4 0;
#P fasten 12 0 2 0 68 309 56 309;
#P fasten 10 0 2 0 336 28 56 28;
#P fasten 6 0 2 0 66 283 56 283;
#P fasten 8 0 2 0 419 28 56 28;
#P fasten 7 0 2 0 380 28 56 28;
#P connect 4 0 2 0;
#P fasten 4 2 2 0 104 -28 56 -28;
#P connect 2 0 13 0;
#P fasten 5 1 6 0 155 134 66 134;
#P connect 4 1 5 0;
#P connect 5 0 0 0;
#P connect 11 0 12 4;
#P connect 5 2 14 0;
#P connect 15 0 14 0;
#P fasten 5 4 10 0 380 4 336 4;
#P connect 5 4 7 0;
#P connect 16 0 15 0;
#P fasten 5 4 8 0 380 4 419 4;
#P pop;
#P newobj 33 528 54 196617 p gl_stuff;
#P user jit.pwindow 194 227 159 115 1 0 0 0 1 0;
#X name camera_position;
#P hidden newex 136 166 99 196617 pak position 0. 0. 0.;
#P comment 366 60 62 196617 y keyframe;
#P comment 573 60 61 196617 z keyframe;
#P user multiSlider 228 52 200 8 0. 1000. 1 2664 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P user function 228 59 428 159 1 1 0 1;
#X frgb 82 82 82;
#X brgb 204 204 204;
#X rgb2 85 85 85;
#X rgb3 255 255 255;
#X rgb4 0 0 0;
#X rgb5 0 0 0;
#X add 0. 0.4 0;
#X add 79.787231 8.933333 0;
#X add 202.127655 -3.866667 0;
#X add 271.276581 6.8 0;
#X add 367.021271 -5.2 0;
#X add 398.936157 10. 0;
#X add 563.829773 5.733334 0;
#X add 622.340393 -4.666667 0;
#X add 781.914856 -0.4 0;
#X add 1000. 0.4 0;
#X domain 1000.;
#X range -10. 10.;
#X done;
#P user multiSlider 432 52 200 8 0. 1000. 1 2664 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P user function 432 59 632 159 1 1 0 1;
#X frgb 82 82 82;
#X brgb 204 204 204;
#X rgb2 85 85 85;
#X rgb3 255 255 255;
#X rgb4 0 0 0;
#X rgb5 0 0 0;
#X add 0. -0.933333 0;
#X add 648.936157 -5.733333 0;
#X add 824.468079 4.666667 0;
#X add 1000. -0.933333 0;
#X domain 1000.;
#X range -10. 10.;
#X done;
#P user multiSlider 24 52 200 8 0. 1000. 1 2664 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P comment 162 60 62 196617 x keyframe;
#P user function 24 57 224 157 1 1 0 1;
#X frgb 82 82 82;
#X brgb 204 204 204;
#X rgb2 85 85 85;
#X rgb3 255 255 255;
#X rgb4 0 0 0;
#X rgb5 0 0 0;
#X add 5.319149 -1.2 0;
#X add 627.659546 5.733334 0;
#X add 803.191467 -4.666667 0;
#X add 872.340393 0.666667 0;
#X add 930.851013 -0.933333 0;
#X add 1000. -1.2 0;
#X domain 1000.;
#X range -10. 10.;
#X done;
#P hidden newex 28 167 97 196617 pak camera 0. 0. 0.;
#P hidden newex 28 186 37 196617 v cam;
#P newex 79 651 76 196617 prepend rotate;
#P hidden message 341 -2 62 196617 0 , 1000 $1;
#P hidden newex 341 23 50 196617 line 1 10;
#P newex 79 672 33 196617 v rot;
#P newex 33 630 103 196617 route position rotate;
#P message 33 586 34 196617 reset;
#P newex 33 606 380 196617 jit.gl.handle letter_box_finished
@inherit_transform 0 @auto_rotate 1 @visible 0;
#P toggle 75 2 15 0;
#P comment 26 31 152 196617 CAMERA KEYFRAME ANIMATOR;
#P hidden newex 278 20 44 196617 * 1000;
#P hidden connect 45 0 14 0;
#P hidden connect 7 0 12 0;
#P hidden connect 11 0 10 0;
#P hidden connect 2 0 24 0;
#P connect 24 0 23 0;
#P connect 23 0 30 0;
#P connect 4 0 3 0;
#P connect 3 0 5 0;
#P hidden fasten 12 0 11 1 29 162 62 162;
#P hidden connect 46 0 23 1;
#P connect 5 1 9 0;
#P connect 9 0 6 0;
#P hidden fasten 17 0 11 2 233 162 91 162;
#P hidden connect 2 0 43 0;
#P fasten 23 1 25 0 82 546 103 546;
#P hidden fasten 15 0 11 3 437 162 120 162;
#P hidden connect 21 0 26 0;
#P hidden fasten 12 0 21 1 29 162 170 162;
#P hidden fasten 17 0 21 2 233 162 199 162;
#P hidden fasten 15 0 21 3 437 162 228 162;
#P hidden connect 45 0 18 0;
#P hidden connect 7 0 17 0;
#P connect 39 0 37 0;
#P hidden connect 41 0 28 0;
#P hidden connect 43 0 28 0;
#P hidden connect 28 0 0 0;
#P hidden connect 0 0 8 0;
#P hidden connect 42 0 8 0;
#P hidden connect 8 0 7 0;
#P hidden connect 45 0 16 0;
#P hidden connect 7 0 15 0;
#P hidden connect 2 0 42 0;
#P hidden connect 7 1 42 1;
#P hidden connect 7 0 45 0;
#P hidden connect 40 0 41 0;
#P pop;

v a d e //

http://www.vade.info
abstrakt.vade.info


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