Buffer and function in genexpr

Maurizio Giri's icon

Hi all,
is it possible to change a Buffer reference in a genexpr function? If yes, how?

In the attached patch I created three gen~ patches: the first one is a simple patch which plays the content of an external buffer, and it works.
In the second patch I used a codebox with the same algorithm, and it still works.
In the third patch I enclosed the algorithm into a function, then called the function, and it doesn't work: that is because the buffer declaration is inside the function and cannot (apparently) be redirect from the 'outside'. I tried to pass the buffer name as a parameter but without success.

Is there a way to make it work? Thanks!

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

Ernest's icon

Hi Maurizio

What version of Max?

Maurizio Giri's icon

Hi Ernest,
it is the latest Max 7.3.5

Ernest's icon

That means I can't help, sorry.

Ernest's icon

Oh. ran into bandwidth limits again. Hope you can figure it out )

Cptnfantasy's icon

You have it right, you just need to uncomment the Buffer declaration. It has been my experience that buffers need to be declared in the top level, so that there is something to pass the message on to the function. Otherwise the top level [gen~] has no idea what to do with the message when it is received from max. Sort of like Params:

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

Maurizio Giri's icon

Hi, cptnfantasy, thank you for the reply, but apparently uncommenting the Buffer declaration didn't fix the issue (no sound).
I don't know if I'm missing something: is there something other I should do other than uncommenting the Buffer declaration? Your patch is a completely different example so I don't understand how to use it.

Thanks

.quasar's icon

Not sure if that's what you wanted but I think I managed to make it work

gen_readbuffer.maxpat
text/plain 21.30 KB

Maurizio Giri's icon

.QUASAR Awesome, thanks!

to_the_sun's icon

To summarize this very helpful thread:
The buffer to be passed to the function must be declared outside of the codebox with an actual [buffer] operator and NOT anywhere inside the codebox.

Ernest's icon

Hi I did upgrade eventually and I did not have this problem, and could declare buffers inside codebox. There's a number of ways to do it, including passing the buffer name in as an argument from the main routine. However, you can't use the name of the buffer for another variable because all variables in codebox have global scope in various ways. They are not meant to, but they do. You should use unique names for everything or it may not work.