Forums > Javascript

Binding to an object in the patcher…


Lee
June 3, 2013 | 12:06 pm

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



Lee
June 19, 2013 | 4:41 pm

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



Lee
August 12, 2013 | 4:46 pm

anyone? :)


August 12, 2013 | 10:32 pm

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.



Lee
August 13, 2013 | 12:22 pm

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


August 13, 2013 | 8:44 pm

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

August 13, 2013 | 8:47 pm

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.


August 13, 2013 | 8:48 pm

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


August 13, 2013 | 9:51 pm

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


Lee
August 14, 2013 | 2:03 am

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


August 20, 2013 | 12:39 am

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.


Viewing 11 posts - 1 through 11 (of 11 total)