Can patcher connections be queried using js?


    Nov 07 2013 | 7:22 am
    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.

    • Nov 07 2013 | 8: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
    • Nov 07 2013 | 12:05 pm
      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.