Binding to an object in the patcher...
Hi, is there anyway I can bind to a control in patcher so that I can see when the value has changed instead of having to take the output from the control and send it into the js?
thx Lee
Hi, anyone got any info on this, one way or t'other? thx
anyone? :)
Is your objective to have nothing attached to the inlet of your js object, or do you just want to bind to something that's not directly connected to your js object but you could tolerate having a pattr object attached to it? If the latter, then it's feasible. If the former, I'm not so sure.
latter is fine... i tried with a pattr but couldn't figure it out...
basically there's about 15 controls in a "cell" - rather than taking the output of each, doing a prepend with an id and sending it into the inlet, I'd like to shortcut and just get the JS to be notified when any of the 15 controls changes....
Well then, I think you could do something along these lines (times 15).
Here's some js code you should save in a file called objectinfo.js.
inlets = 1;
outlets = 1;
autowatch = 1;
var mypatcher = this.patcher;
var mynumberbox = mypatcher.getnamed("mynumberbox");
var mynumber;
function showit()
{
if (mynumberbox.valid)
{
mynumberbox.message("int", mynumber);
}
}
function setit(x)
{
mynumber = x;
}
function setvalueof(x)
{
mynumber = x;
post("something changed\n");
}
And here's a patch to test it.
So, as you suggested, you could tag each of your UI object values with an ID tag before sending it into the pattr setit, and then store all the values inside your js object.
Disclaimer: There may well be a better solution than this, but this is the best I can think up at the moment.
And isn't this just as good, and more 'normal'?
Save this code as 'holdvalues.js':
inlets = 1;
outlets = 1;
autowatch = 1;
var thevalues = new Array();
function setvalue(x,y)
{
thevalues[x]=y;
post("something changed\n");
}
function getvalue(x)
{
outlet(0, thevalues[x]);
}
And then test it with this patch:
Hey, thanks Chris... will check this out tonight :)
Every GUI object (e.g. flonum, umenu etc.) understands getvalueof() and setvalueof(). Since this is not documented, it might be subject of change in later max versions.