Binding to an object in the patcher…

Jun 3, 2013 at 12:06pm

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

#251551
Jun 19, 2013 at 4:41pm

Hi, anyone got any info on this, one way or t’other? thx

#253373
Aug 12, 2013 at 4:46pm

anyone? :)

#258725
Aug 12, 2013 at 10:32pm

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.

#258732
Aug 13, 2013 at 12:22pm

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….

#258803
Aug 13, 2013 at 8:44pm

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.

– Pasted Max Patch, click to expand. –
#258843
Aug 13, 2013 at 8:47pm

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.

#258844
Aug 13, 2013 at 8:48pm

Disclaimer: There may well be a better solution than this, but this is the best I can think up at the moment.

#258845
Aug 13, 2013 at 9:51pm

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:

– Pasted Max Patch, click to expand. –
#258848
Aug 14, 2013 at 2:03am

Hey, thanks Chris… will check this out tonight :)

#258857
Aug 20, 2013 at 12:39am

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.

#259388

You must be logged in to reply to this topic.