Forums > Javascript

sharing will be fun: optimisation help needed for a graphic step sequencer

April 24, 2009 | 9:49 am

Dear all

I have this lovely basic step sequencer, which freaks my computer out (even in overdrive mode)… I think it is the itterative redraw of the squares, or maybe the iterative implementation of the pattr handling, but before redoing it differently, I’d like some help from some (most) of you who are much more experienced coders…

I’ve attached both the js code and pasted a test file below

thanks or your input

pa

===

max v2;
#N vpatcher -3 47 957 747;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 22 394 20 196617 t b;
#P newex 28 441 41 196617 *~ 0.1;
#P newex 30 419 37 196617 click~;
#N vpatcher 10 59 610 459;
#P window setfont "Sans Serif" 9.;
#P newex 105 76 27 196617 != 2;
#P newex 76 113 60 196617 loadmess 1;
#P newex 137 112 29 196617 gate;
#P newex 144 85 32 196617 sel 0;
#P newex 195 126 29 196617 gate;
#P newex 50 162 99 196617 pak midinote 220 0.;
#P newex 195 108 31 196617 == 1;
#P newex 136 50 106 196617 t i i 0;
#P inlet 136 30 15 0;
#P outlet 50 184 15 0;
#P connect 4 0 0 0;
#P connect 2 0 9 0;
#P connect 1 0 2 0;
#P connect 8 0 7 0;
#P connect 9 0 7 0;
#P connect 7 0 4 2;
#P connect 5 0 4 2;
#P connect 2 1 6 0;
#P connect 6 1 7 1;
#P connect 2 0 3 0;
#P connect 3 0 5 0;
#P connect 2 2 5 1;
#P pop;
#P newobj 656 467 36 196617 p 220;
#N vpatcher 10 59 610 459;
#P window setfont "Sans Serif" 9.;
#P newex 105 76 27 196617 != 2;
#P newex 76 113 60 196617 loadmess 1;
#P newex 137 112 29 196617 gate;
#P newex 144 85 32 196617 sel 0;
#P newex 195 126 29 196617 gate;
#P newex 50 162 96 196617 pak midinote 330 0;
#P newex 195 108 31 196617 == 1;
#P newex 136 50 106 196617 t i i 0;
#P inlet 136 30 15 0;
#P outlet 50 184 15 0;
#P connect 4 0 0 0;
#P connect 2 0 9 0;
#P connect 1 0 2 0;
#P connect 7 0 4 2;
#P connect 5 0 4 2;
#P connect 9 0 7 0;
#P connect 8 0 7 0;
#P connect 2 1 6 0;
#P connect 6 1 7 1;
#P connect 2 0 3 0;
#P connect 3 0 5 0;
#P connect 2 2 5 1;
#P pop;
#P newobj 593 466 36 196617 p 330;
#N vpatcher 10 59 610 459;
#P window setfont "Sans Serif" 9.;
#P newex 105 76 27 196617 != 2;
#P newex 76 113 60 196617 loadmess 1;
#P newex 137 112 29 196617 gate;
#P newex 144 85 32 196617 sel 0;
#P newex 195 126 29 196617 gate;
#P newex 50 162 99 196617 pak midinote 550 0.;
#P newex 195 108 31 196617 == 1;
#P newex 136 50 106 196617 t i i 0;
#P inlet 136 30 15 0;
#P outlet 50 184 15 0;
#P connect 4 0 0 0;
#P connect 2 0 9 0;
#P connect 1 0 2 0;
#P connect 8 0 7 0;
#P connect 9 0 7 0;
#P connect 7 0 4 2;
#P connect 5 0 4 2;
#P connect 2 1 6 0;
#P connect 6 1 7 1;
#P connect 2 0 3 0;
#P connect 3 0 5 0;
#P connect 2 2 5 1;
#P pop;
#P newobj 531 466 36 196617 p 550;
#N vpatcher 10 59 610 459;
#P window setfont "Sans Serif" 9.;
#P newex 105 76 27 196617 != 2;
#P newex 76 113 60 196617 loadmess 1;
#P newex 137 112 29 196617 gate;
#P newex 144 85 32 196617 sel 0;
#P newex 195 126 29 196617 gate;
#P newex 50 162 99 196617 pak midinote 770 0.;
#P newex 195 108 31 196617 == 1;
#P newex 136 50 106 196617 t i i 0;
#P inlet 136 30 15 0;
#P outlet 50 184 15 0;
#P connect 4 0 0 0;
#P connect 2 0 9 0;
#P connect 1 0 2 0;
#P connect 9 0 7 0;
#P connect 8 0 7 0;
#P connect 7 0 4 2;
#P connect 5 0 4 2;
#P connect 2 1 6 0;
#P connect 6 1 7 1;
#P connect 2 0 3 0;
#P connect 3 0 5 0;
#P connect 2 2 5 1;
#P pop;
#P newobj 470 466 36 196617 p 770;
#N vpatcher 10 59 610 459;
#P window setfont "Sans Serif" 9.;
#P newex 105 76 27 196617 != 2;
#P newex 76 113 60 196617 loadmess 1;
#P newex 137 112 29 196617 gate;
#P newex 144 85 32 196617 sel 0;
#P newex 195 126 29 196617 gate;
#P newex 50 162 108 196617 pak midinote 1210. 0.;
#P newex 195 108 31 196617 == 1;
#P newex 136 50 106 196617 t i i 0;
#P inlet 136 30 15 0;
#P outlet 50 184 15 0;
#P connect 4 0 0 0;
#P connect 2 0 9 0;
#P connect 1 0 2 0;
#P connect 8 0 7 0;
#P connect 9 0 7 0;
#P connect 2 1 6 0;
#P connect 7 0 4 2;
#P connect 5 0 4 2;
#P connect 6 1 7 1;
#P connect 2 0 3 0;
#P connect 3 0 5 0;
#P connect 2 2 5 1;
#P pop;
#P newobj 406 465 42 196617 p 1210;
#P user ezdac~ 483 613 527 646 0;
#P newex 478 579 107 196617 poly~ simplesynth 10;
#B color 6;
#P newex 407 417 259 196617 unpack i i i i i;
#P toggle 92 374 15 0;
#P newex 92 392 58 196617 metro 200;
#P newex 171 385 78 196617 prepend setmin;
#P newex 208 413 27 196617 – 1;
#N counter;
#X flags 0 0;
#P newobj 152 437 66 196617 counter;
#P user rslider 82 326 804 18 33 1 0 0 0;
#P message 631 26 14 196617 2;
#P message 568 26 14 196617 1;
#P flonum 613 63 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 547 66 43 196617 store 2;
#P message 484 66 43 196617 store 1;
#P newex 573 107 67 196617 pattrstorage;
#X client_rect 20 631 1231 886;
#X storage_rect 237 610 1186 873;
#P objectname u497000006;
#P newex 243 112 65 196617 pattr theseq;
#X prestore 160 0 2 2 2 1 0 1 0 0 0 0 0 0 0 0 2 2 2 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 2 1 0 0 0 0 0 0;
#X prestore 160 41 0 0 0 0 1 0 0 0 0 0 2 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2 1 0 0 0 2 1 0 1 0 0 0 0 0 0 0;
#X prestore 160 82 1 0 0 1 0 0 0 0 0 0 2 2 2 1 2 2 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0;
#X prestore 160 123 0 0 0 0 0 2 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 2 2 2 1;
#P objectname theseq;
#P user jsui 82 171 808 154 1 0 0 SeqUI.js;
#P objectname jsui;
#P message 221 92 33 196617 clear;
#P number 145 97 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 662 75 75 196617 storagewindow;
#P connect 3 0 27 0;
#P connect 25 0 26 0;
#P connect 27 0 25 0;
#P connect 12 0 3 0;
#P connect 1 0 3 0;
#P connect 2 0 3 0;
#P connect 4 1 3 0;
#P connect 16 0 15 0;
#P connect 15 0 12 0;
#P connect 14 0 12 0;
#P connect 11 0 14 0;
#P connect 11 1 13 0;
#P connect 13 0 12 4;
#P connect 17 0 20 0;
#P connect 3 0 17 0;
#P connect 17 1 21 0;
#P connect 24 0 18 0;
#P connect 23 0 18 0;
#P connect 22 0 18 0;
#P connect 21 0 18 0;
#P connect 20 0 18 0;
#P connect 26 0 19 0;
#P connect 18 0 19 0;
#P connect 18 0 19 1;
#P connect 17 2 22 0;
#P connect 8 0 5 0;
#P connect 6 0 5 0;
#P connect 7 0 5 0;
#P connect 0 0 5 0;
#P connect 17 3 23 0;
#P connect 10 0 8 0;
#P connect 9 0 8 0;
#P connect 17 4 24 0;
#P pop;


April 27, 2009 | 5:36 pm

a shameful bump, with some more info…

I have removed the all the pattr stuff (notifyclient() and all) and it does not change the efficiency.

I have change the number of squares (from 5 tracks of 32 clicks to 2 tracks of 16) and it does help a little, but it is still hiccupping when clicked…

Any help from a good javascripter is welcome.

pa


April 28, 2009 | 6:54 pm

Cher Nicolas

Thanks for this, there is still some problem with your suggestions:

1) using JS offline to fill a coll will not allow proper pattr interpolation (which is important for the use I do)

2)matrixctrl is not allowing staccato (consecutive cells to be on without being continuous)

3)drawing just the selected shapes (with a sort of dirty flag) could be an option, but I will have to look into partial erasing. I could keep the cursor that way as well, redrawing only 10 cells… or maybe dismiss it as you suggest.

Anyway, thanks for taking the time to reply, and I’ll try the option 3 and keep people posted (and asking for more help Wink

pa


April 28, 2009 | 7:01 pm

I also tried to open badaboum.tutorial and I have a blank, locked patcher, with MaxOS10.4.11, Max5.0.7 with Jitter. No error message,just nothing!

What am I supposed to see?

pa


April 29, 2009 | 7:45 am

ok, got it to work, this is nice work!

I’ve open the js and doing it in jitter is a good idea (joined with the independent editing) maybe I could handle the pattr in another object…

I’ll continue my explorations

pa


April 29, 2009 | 9:10 am

ok, here goes v.0.2

- now only the clicked cells are updated graphically
- I’ve pushed my querying method to the scheduler thread

Any other input is more than welcome

pa

ps use the same test patch above


April 29, 2009 | 9:12 am

April 30, 2009 | 1:22 pm

It would be possible to just use [matrixctrl]. You just need to set it so that each square has 3 values, on, off and joined, then create your own custom picture to show these states. You can then use the "clickvalue" message to decide which to use (for example normal click to add, shift+click to delete). You might need to analyse which is the last location on each row to be selected and whether it has been added or removed and then change the click state to make it look tidier. You can then read through using the "getcolumn" message. Perhaps using a semi-transparent [slider] placed over the top to be your cursor.

I’ll see if I can piece an example together for you when I get back from work.

lh


May 1, 2009 | 7:51 am

thanks for this

The only problem I can see with this is when you click in the middle of a long bar to chop it, you will not be able to update the previous square to and ending one…

but I’ll give it a go

pa


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