Set divisor of a / object from js

Lee's icon

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's icon

There are a handful of different ways to do this with js:

  • send the object in1 [val] (for an integer object) or ft1 [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's icon
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's icon

thx ben - very helpful. It was the first form I'd used in the past, just couldn't remember the format.

Cheers