sprintf-like function in gen~

Ian Sampson's icon

Is there anything similar to sprintf or combine in GenExpr? All I want to do is combine a symbol and an integer into a single string (e.g. i = buffer.x where x is a number from an input or param). I reread the GenExpr docs but didn’t find anything on this. Thanks – Ian

Nikolas K's icon

Similar to Ian's question, I would like to know if there is any way to see a [polybuffer~] inside a gen~ patch.
Not a specific buffer of the polybuffer, but to handle all buffers from a polybuffer.
Not from a param, all from inside gen~.
e.g. Have a "for" loop, that sums the first sample from every buffer from a polybuffer...

@Ian, as I understand, you want to dynamically change the buffer used inside the gen? You could make the message outside the patch and then feed it to gen.
I do not think there is yet a way, to change the buffer from inside gen.

Ian Sampson's icon

Yup, you read my mind: trying to get gen~ to play nicely with polybuffer~ (when the number of buffers isn’t set in advance). It is possible to change the buffer of a poke, for example, if you use a variable instead of a buffer name, but then there’s the problem of changing the variable to refer to appropriate buffer in polybuffer~ (via something like sprintf, which doesn’t exist in gen~ I guess) as well as the problem of declaring the various buffers (which I don’t think would be possible with a for loop because declarations need to go at the top of the codebox – before any expressions). Your solution sounds like good compromise: to feed gen~ a message from outside. Just I’ve got everything synced up so nicely at signal rates inside gen~ (no Max messages anywhere except the initial MIDI button press) and I’m being a bit stubborn.

My current workaround is to use data instead of buffer (since I don’t need the audio to be accessible outside of gen~) and use multiple channels the same way I’d use multiple buffers with polybuffer~. So far it’s working pretty smoothly – with the added bonus that gen~ doesn’t have to convert any 32-bit floats. But if anyone does think of a way to combine symbols in gen~ I’ll be glad to hear of it.

Graham Wakefield's icon

No, there's no sprintf-like object in gen~ and unlikely to change soon, as there is no string/message processing in gen~ either. Using [data] is the right way forward for dealing with multiple (> 4) channels of signal data.

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

The only way to work with polybuffer~ from gen~ right now is by sending messages to remap a gen buffer to a polybuffer~ index:

dsmd's icon

Hi Ian,

What I understand of about your workaround is that you have 1 Data with multiple channels. And that you link different buffers to the channels in that Data object.
How do you achieve that?
I can't find anything about that in the docs. Only copying a buffer to a Data. But not multiple buffers to multiple channels in 1 Data.
Or do I misunderstand your workaround?

I guess it's possible with a for loop which copies al the buffer info to the right channels in the Data object. But I was kinda hoping that there is a simpler solution for that.

Thanks