Set divisor of a / object from js
Lee
6月 11 2024 | 4:44 午後
Hi, is there a way to do this from js? Think I need to send a message directly to inlet 2 but can't remember/figure out if this is possible from js?
Thx
Ben Bracken
6月 11 2024 | 8:27 午後
There are a handful of different ways to do this with js:
send the object
in1 [val]
(for an integer object) orft1 [val]
(for a float object) message (easiest)recreate the object with the desired divisor value (slightly less easy)
invisibly create a message box with the desired divisor value, connect it to the right inlet of the div object and bang it out, then delete the temp object (most annoying, but old school)
Ben Bracken
6月 11 2024 | 10:48 午後
function setdiv(v) {
var obj = this.patcher.getnamed("div");
obj.message("ft1", v); // or obj.message("in1", v);
}
function setdiv2(v) {
var obj = this.patcher.getnamed("div");
// uses some mystery 'newex' sauce
this.patcher.message("script", "replace", "div", "newex", 0, 0, 0, 12.5, "/", v);
}
function setdiv3(v) {
this.patcher.newdefault(300, 400, "message", "@text", v, "@hidden", 1, "@varname", "tmpmsg");
this.patcher.message("script", "connect", "tmpmsg", 0, "div", 1);
var tmpobj = this.patcher.getnamed("tmpmsg");
tmpobj.message("bang");
this.patcher.remove(tmpobj);
}
Lee
6月 12 2024 | 5:59 午前
thx ben - very helpful. It was the first form I'd used in the past, just couldn't remember the format.
Cheers