Can subpatchers be passed arguments as opposed to using multiple inputs?

Andy Maskell's icon

In my former Fortran and Pascal days, I could define a function or procedure that had arguments defined in the declaration statement.

Is there any way to do something similar in Max?

Obviously, the simple way is to feed parameter values into a subpatcher via [input] objects, but I would like to be able to simply add values as arguments to a subpatcher object, like most Max objects do, if there is way to do it.

So, for example, I regularly use a [t 1 500] object fed into two inputs of a small [gatedelay] subpatch to control a [gate]. The first parameter in the trigger gives the normal state of the [gate] and the second gives the period the gate will change state for in ms. So, the idea is that a [gate] that is normaly open would close for 500ms and then reopen.

I'm wondering whether I could define the [gatedelay] object to accept arguments instead of discrete inputs, so that I could use objects like this:

[gatedelay 1 500]

Andy Maskell's icon

Is [patcherargs] what I'm looking for perhaps? I guess that if there multiple arguments, I'd just have to [unjoin] the output of [patchargs] to use the actual values?

Will this also work for subpatchers defined in a maxpat file in a project as well as in an embeded [patcher] object?

Roman Thilenius's icon

you only need [patcherargs] (or [110.loadargs]) when you use the argument multiple times in your abstraction - or for the rare cases where a compiled object will not accept #1 type of arguments in its own objectbox.

otherwise [loadbang]-[t #3]- or [zmap 0. 1. #5 #6] reliably fetches what you wrote outside, and in the order you would expect.

[p] can not do it, only abstraction files (and files loaded into bpatcher), for poly~ and pfft~ see help.

you can forward #1 arguments across multiple levels where required.

patch - abstraction - abstraction with arguments actually used

Andy Maskell's icon

Well, I did it like this and it worked fine. [gatedelay] and [gatedelay2] are saved in my library as maxpat files:

These routines set the gate to the value of the first inlet/argument for a period set by the second inlet/argument and then reverse it.