Forums > MaxMSP

list slicing (javascript?)

May 29, 2009 | 1:08 pm

So im trying to get max talking to liveOSC in ableton live.
Basically i get an undetermined number of lists (same as the number of tracks in ableton) of an undertermined of number (number of scenes) and i want to split it into groups of 3 and output them.
Example:
print: 0 0 0 2 16. 1 0 0. 2 0 0. 3 0 0. 4 0 0. 5 0 0. 6 0 0. 7 0 0. 8 0 0. 9 0 0. 10 0 0. 11 0 0. 12 0 0. 13 0 0. 14 0 0. 15 0 0. 16 0 0. 17 0 0. 18 0 0. 19 0 0.
print: 1 0 0 1 0. 1 0 0. 2 0 0. 3 0 0. 4 0 0. 5 0 0. 6 0 0. 7 0 0. 8 0 0. 9 0 0. 10 0 0. 11 0 0. 12 0 0. 13 0 0. 14 0 0. 15 0 0. 16 0 0. 17 0 0. 18 0 0. 19 0 0.
At the start of each list is the column/track number. Then is a number telling me if the track i armed for recording or not. I don’t need this number so we can just ignore that.
After that it goes i i f i i f i i f etc The first i is the row/scene number. The second i is the state of the clip: 0=empty, 1=has clip, 2=playing, 3=triggered. We can ignore the float.

I want to put these lists in and get out lots of lists in this format:
column row state

I think javascript would be the best solution but i haven’t done any before…

Ideally i just send all the big lists in but i could use a route object and have lots of inlets in the js object and link each one up so:
[route 0 1 2 3 4 5 6 7 8 9 10 11 12 13]
linked to 14 inlets of a js object.
But then this limits the number of columns i can have

Help would be much apreciated, i probably haven’t explained it very well so if you have questions, just ask.
Thanks a lot.

update:

outlets = 2;
var a;
var a1;
function list()
  {
    a = arrayfromargs(messagename,arguments);
    p = a.slice(0, 1);
    a = a.slice(2);

  }
function bang()
{
    a1 = a.slice(0, 3);
    a = a.slice(3);
    outlet(0,a);
    a1 = a1.slice(0, 2);
    a1 = p.concat(a1);
    outlet(1,a1);
}

This sort of works but only for one column. if there is more than one column then the last one works.


May 29, 2009 | 2:50 pm

Have you looked at the ‘zl’ list processor object? Also, Peter Elsea’s LObjects (http://arts.ucsc.edu/ems/music/research/Lobjects.readme.html) may help, they are the list processing toolkit.

If you want to continue with Javascript you may be better off posting the the Javascript forum.


May 29, 2009 | 3:08 pm
dovemouse wrote on Fri, 29 May 2009 08:08
This sort of works but only for one column. if there is more than one column then the last one works.

that sounds like it’s actually doing them all, but so fast you only see the last one. are you sure it’s not working? try using another outlet to track the index of the list. outside the js use a pack to hold the values, then print them.

the advantage of the javascript is the flexible-length array, but you could work around that probably. zl could work for you too. Do you get the entire track list at once, or one at a time? You can dice each up horizontally, or in vertical chunks of the three values you want, depending on how you’re getting them and what you want to do with them.

If you’re getting one list at a time, you could just use a massive [route] that’s bigger than you’ll realistically need, then lots of inlets/outlets simply wouldn’t be used, no biggie.

Better yet, you can use a single [route #1] in a bpatcher and have as many instances as you think you’ll need for tracks. If you have additional things you want to do to each cluster of data, the bpatcher would be the way to go–just program it once and keep tabs on the list/track index (will be the #1 argument). The index of each three-element cluster (your "row" in Live) can be added with a [counter] as you spit out the list clusters with [zl group 3] and slice off each unneeded float.


January 4, 2012 | 5:51 pm

The short answer to the first poster is:

Use "zl iter 3"

You have a list like this:
"100 200 123 100 222 222 199 199 100"

zl iter 3 – splits and collects into groups of 3
"100 200 123"
"100 222 222"
"199 199 100"

Attachments:
  1. iterzlgroup.maxpat

January 5, 2012 | 3:29 am

no matter if you use [zl] or javascript only one inlet will also be enough for 14 or more lists coming from that [route].


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