Sending messages to bpatcher

woodslanding's icon

What is the correct syntax for sending a message to a bpatcher itself? (not its internal patch) I'd like to set it's presentation_rect programatically.

My best interpretation of the docs has not worked, and other messages on this forum indicate the helpfile is not correct anyway.

Also, does anyone know if it is possible to do this through js? FI, could you do something like the fader bank in the tutorial, using bpatchers instead of faders?

And is it true there is no way to set the arguments of the object in a bpatcher programmatically? Can js do this?

I'm using Max 5

Thanks in advance for any tips!
-eric

Chris Muir's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Here's an example I did for a similar question;

seejayjames's icon

you can set the arguments with

script sendbox my_bp args $1 $2

but it looks like it needs to be reloaded for them to be set. So you'd need to reload it via scripting after setting the arguments.

I only use args for a few things on instantiation, then if I need to change things it's inlets or send/receive. Easy enough to use [prepend 1] to send a message to the bpatcher with argument 1, then [route #1] in the bpatch to get the right messages, etc.

woodslanding's icon

Chris:

Since I want to address identical bpatchers independently, your patch above is not helpful in this case.... unless I can figure out how to change the bpatcher scripting name via your method--is this possible? No syntax I have tried has worked....

James:

When you talk about using [prepend 1] does this allow you to address the bpatcher itself or just the object within? Can you explain this syntax more explicitly?

To be clear: I have a mixer channel strip gui. I want to create a bunch of these programatically, identical except for the presentation rectangle of their enclosing bpatchers.

So, I need to set the presentation_rect of numerous identical bpatchers without manually editing their scripting names. Is this possible??? I'm starting to wonder.

Thanks as always!
-e

seejayjames's icon

the [prepend 1] is to address objects within the bpatcher, not the bp itself.

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

I extended the example patch a bit, see if it helps?

woodslanding's icon

Reading more on thispatcher, it looks like I may be able to name items as I create them.... assuming this is the scripting name.

I don't know if I can create a pbatcher and set its internal patch this way though.... ??

Chris Muir's icon
Max Patch
Copy patch and select New From Clipboard in Max.

If you duplicate bpatchers the scripting name gets incremented. Name your first bpatcher something along the lines of "my_name[1]" When you duplicate this bpatcher the new one will be "my_name[2]"

woodslanding's icon

Seriously??? That's awesome!

I'll see if I can get there from here.... Thanks, Chris!

cheers,
-eric

woodslanding's icon

Okay, this looks good, but I cannot seem to address these bpatchers programatically. I'd like to be able to change the integer in this message without output, and have the checkbox send output....

If I try:

script sendbox my_bp[$2] border $1

that doesn't work at all...

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

so I tried putting the message together with combine and pack, and this doesn't work:

In fact, every way I have tried to put this message together, (using sprintf, combine or pack) I get both the print and sendpatch objects saying

doesn't understand "message"

How can PRINT not understand a message???? That just seems absurd....

Maybe this will make sense in the morning. Heck, right now I can't even get the forum to parse my backtick marks.

Chris Muir's icon
Max Patch
Copy patch and select New From Clipboard in Max.
Roman Thilenius's icon

if you have to reload it anyway, you could as well script a new copy with the desired size.

woodslanding's icon

Roman:

Yep, that's how it needs to work.

Chris:

Thanks! I confess I would never have thought to pack those integers before feeding sprintf with them.... but this is still all very new to me!

cheers,
-eric

Chris Muir's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Actually, the pack was a remnant of another approach I was considering. Completely redundant in the patch as it is.

seejayjames's icon

@woods: you were missing "script" in your message, without it, the commands to [thisptacher] won't work.

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

Also, "sendbox" is a reserved message, which lets you change attributes of object boxes. This is why the [print] object didn't behave as expected:

woodslanding's icon

Oh, thank you for clarifying that.... I thought it was the pack, and not the missing command!

I am now doing this with JS, though, but I will keep that info in mind; I'm sure I'll need it again.

-e

darrcass's icon

Pretty new to M4L, so getting things to send the messages I want is a major challenge/hair pull, but I did figure out how to show/hide multiple interfaces (in bpatchers) with js.

In the parent patch (.amxd) I have a tab object whose items are the Scripting Names of each bpatcher I want to control. Selecting a tab calls my js function, which shows the appropriate tab and moves/resizes the others outside the work area in Live.

function iFace(s){
    var iFace = this.patcher.getnamed('iFace'),
     tabs = iFace.getattr('tabs');
    for(var i = 0, t; t = tabs[i++];){
        var args = ["script","sendbox",t,"presentation_rect"],
         add = t == s ? [0,0,116,170] : [0,171,16,16],
                msg = args.concat(add);
        this.patcher.message(msg);
    }
}