Forums > Javascript

Can patcher connections be queried using js?

November 6, 2013 | 11:22 pm

Hi,

I know how to iterate over all the objects in a patcher using javascript, but is it possible to tell what is connected to what (and which inlets/outlets are involved, etc.) ?

Thanks,

Aengus.


November 7, 2013 | 12:00 am

Currently, the only way to do it is to either keep track of all the connections made along the way, or parse the json of a saved .maxpat.

-Ben


November 7, 2013 | 4:05 am

I thought that might be the case. Thanks.

For reference, this code seems to work (written with reference to Andrew Pask’s post in this thread) :

function findconnections()
{
post("Finding connections!\n");
lines="";
var patcher_file = new File(this.patcher.filepath);
while (patcher_file.position != patcher_file.eof)
{
lines += patcher_file.readline();
}
patcher_file.close();
var parsed_patcher = JSON.parse(lines);
post("Num patch cords: " + parsed_patcher["patcher"]["lines"].length + "\n");
for ( i = 0; i < parsed_patcher["patcher"]["lines"].length ; i++ )
{
destin = parsed_patcher["patcher"]["lines"][i]["patchline"]["destination"][0];
dinlet = parsed_patcher["patcher"]["lines"][i]["patchline"]["destination"][1];
source = parsed_patcher["patcher"]["lines"][i]["patchline"]["source"][0];
soutlet = parsed_patcher["patcher"]["lines"][i]["patchline"]["source"][1];
post("Connection from " + source + " (out:" + soutlet + ") to " + destin + " (in:" + dinlet + ")\n");
}
post("Finished!\n");

}

Cheers,

Aengus.


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