Forums > Javascript

Dynamically created patchcords made with JS won't pass signals

October 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");
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");

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

October 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?

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


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

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