Forums > Javascript

Dynamically created patchcords made with JS won't pass signals


Oct 22 2012 | 9:09 am

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

Oct 22 2012 | 6:03 pm

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 | 10:46 pm

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 | 10:46 pm

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

Oct 24 2012 | 12:34 am

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

Aug 20 2016 | 2:04 pm

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

Aug 21 2016 | 11:53 am

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.

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

Forums > Javascript