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”);
fnerp = this.patcher.getnamed(“fnerp”);
glunch = this.patcher.getnamed(“glunch”);

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

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.

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?

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.


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).


You must be logged in to reply to this topic.