Binding to an object in the patcher...

Lee's icon

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

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

Lee's icon

anyone? :)

Christopher Dobrian's icon

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

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

Christopher Dobrian's icon

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");
}

Max Patch
Copy patch and select New From Clipboard in Max.

And here's a patch to test it.

Christopher Dobrian's icon

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.

Christopher Dobrian's icon

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

Christopher Dobrian's icon

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]);
}

Max Patch
Copy patch and select New From Clipboard in Max.

And then test it with this patch:

Lee's icon

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

timtation's icon

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.