Forums > MaxMSP

Sending messages to bpatcher

November 23, 2011 | 7:32 pm

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


November 23, 2011 | 7:45 pm

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

– Pasted Max Patch, click to expand. –

November 23, 2011 | 9:00 pm

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.


November 25, 2011 | 5:36 pm

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


November 25, 2011 | 6:25 pm

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

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

– Pasted Max Patch, click to expand. –

November 25, 2011 | 6:42 pm

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


November 25, 2011 | 6:54 pm

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]"

– Pasted Max Patch, click to expand. –

November 26, 2011 | 4:22 am

Seriously??? That’s awesome!

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

cheers,
-eric


November 26, 2011 | 5:57 am

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…

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

– Pasted Max Patch, click to expand. –

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.


November 26, 2011 | 7:05 am
– Pasted Max Patch, click to expand. –

November 26, 2011 | 1:19 pm

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


November 26, 2011 | 6:23 pm

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


November 27, 2011 | 6:03 am

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

– Pasted Max Patch, click to expand. –

November 27, 2011 | 9:35 pm

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

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:

– Pasted Max Patch, click to expand. –

November 28, 2011 | 2:45 am

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


September 26, 2013 | 1:12 pm

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


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