Dynamically created patchcords made with JS won't pass signals

wizardcommander's icon

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.

Max Patch
Copy patch and select New From Clipboard in Max.

here's an example:

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);
}

mzed's icon

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.

wizardcommander's icon

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?

Ben Bracken's icon

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

rjungemann's icon

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

4580.StandoffDynamicPatching.zip
zip
Yeray's icon

Hi, did you ever got a solution?, it seems the problem still exists, and makes js useless with connect and signals.

Roman Thilenius's icon

if you really want to use javascript, old style scripting or prepend/route for patching signal connections, you can easily force a recompile as well by sending "0, 1" to (any) dac~ object.