Copy data from one [mtr] track to another
I'm not sure how to handle copying the whole content of one track of a [mtr] object to another track of the same [mtr]. I'm basically looking for a 'duplicate track' functionality.
My current solution is to use several one-track [mtr] objects, which makes the data copy easy (see below). Any pointers on duplicating a track in a multi-track [mtr] very welcome! (Max preferred to JS). The mtr dictionary structure is a little intricate, and I have not yet managed to rebuild a full mtr dict after parsing it...
Thanks.
(patch I meant to attach)
That would be one of my attemps at unpacking and repacking a multi-track [mtr]. One problem seems to be that [dict.pack] does not interpret the list of dict references as a list but parses them instead.
I got something to work. One of the tricky things is that the names of the different track dictionaries have to be parsed. Here is a version avoiding regexpr parsing.
Actually, it's not working yet. Making progress, but there are still details to iron out. Current version copies the data, but I still need to update something inside the dict to make it work:
In case someone else is looking for that, here is a working version with js, after an example by J. Bernstein.
The "problem" here is that we are copying the data for the entire dict instead of just the track, but it looks like it's the best option at the moment.
JS:
// after an example by Jeremy Bernstein
inlets = 3;
var v = new Array();
v[0] = v[1] = 0;
if (jsarguments.length>1)
v[0] = jsarguments[1]-1; // arguments track number starting at 1
if (jsarguments.length>2)
v[1] = jsarguments[2]-1;
function msg_int(i) // i track number starting at 1
// inlet 1, source track
//inlet 2, destination track
{
v[inlet-1] = i-1;
}
function dictionary(name) {
var d = new Dict(name);
var o = JSON.parse(d.stringify());
if (o && o.tracks && o.tracks[v[0]]) {
o.tracks[v[1]] = JSON.parse(JSON.stringify(o.tracks[v[0]])); // clone it
}
d = new Dict(); // don't touch the incoming dict
d.parse(JSON.stringify(o));
outlet(0, "dictionary", d.name);
}
Is there a way to set a breakpoint and easily investigate what the contents or data structure of values are in js ? For the end-user in Max? I am wondering if Jeremy, who I think works at cycling, can investigate the locals/globals more directly if he can set breakpoints in max itself. Just curious, so to re-state the question:
Is there a way to set a breakpoint and easily investigate what the contents or data structure of values are in js ?