Dynamically created patchcords made with JS won't pass signals

Oct 22, 2012 at 9:09am

Dynamically created patchcords made with JS won't pass signals

I’m using JS to dynamically create patchcord routings between objects. Curiously, new connections will only pass MSP signals if I stop and restart the audio engine. Scripting connections by sending max messages to this thispatcher does not have this problem.

here’s an example:

– Pasted Max Patch, click to expand. –

and here’s the js:

function connect(){
glurp = this.patcher.getnamed(“glurp”);
churble = this.patcher.getnamed(“churble”);
this.patcher.connect(glurp,0,churble,0);
fnerp = this.patcher.getnamed(“fnerp”);
glunch = this.patcher.getnamed(“glunch”);
this.patcher.connect(fnerp,0,glunch,0);
}

function disconnect(){
glurp = this.patcher.getnamed(“glurp”);
churble = this.patcher.getnamed(“churble”);
this.patcher.disconnect(glurp,0,churble,0);
fnerp = this.patcher.getnamed(“fnerp”);
glunch = this.patcher.getnamed(“glunch”);
this.patcher.disconnect(fnerp,0,glunch,0);
}

#64863
Oct 22, 2012 at 6:03pm

The audio chain is “compiled” when audio is turned on. I’m not sure if there’s a way to trigger the chain to recompile from javascript. As a work-around, you could make some trivial connection with thispatcher. I expect that would trigger all connections to be reevaluated.

#233893
Oct 22, 2012 at 10:46pm

Thanks for the tip, I got that working very well.

Broadly, shouldn’t using JS to create connections cause the audio chain to “compile” already? I guess what I’m asking is, is this an actual bug or a known limitation of JS in max?

#233894
Oct 23, 2012 at 10:46pm

Hi wizardcommander,

Thanks for pointing this out. This looks like a bug to me, as a new msp connection should recompile the chain. We will take a closer look.

-Ben

#233895
Oct 24, 2012 at 12:34am

I was experimenting with using JSUI to create a “dynamic patching interface” and have had some luck. Attached is a small piece (not the JSUI part) of what I was experimenting with, using JS to create dynamic patching between “hunter” and “target” elements. Not sure if this will be of any use to you. But using forward~ you can create dynamic connections to matching receive~ objects (what my example does under the hood).

#233896

You must be logged in to reply to this topic.