buffer~ arguments from input

Jan 3, 2011 at 5:59am

buffer~ arguments from input

Hi I have some buffer objects that looks like this:
[buffer~ 01sound 01sound.aif]
[buffer~ 02sound 02sound.aif]
[buffer~ 03sound 03sound.aif]
I would like to modularize it a bit so that I can input an integer (01, 02, 03)
into buffer~ and have buffer~ interpret the integer like sprintf does. Is there a way to write something like this?
[buffer~ %ldsound %ldsound.aif]
and have buffer interpret it correctly? Is there maybe some other way to achieve what I am trying to do?

Thanks
Pete

#54212
Jan 3, 2011 at 8:34am

First, it would be impossible to give 03 as an argument. Then, of course it is possible to make an abstraction with a buffer~ object, that gets named and which loads a sound file based on an argument. It could be done using sprintf.
[sprintf set %02dsound] and [sprintf replace %02dsound.aif] should do it.

_
johan

#195130
Jan 3, 2011 at 6:17pm

Hi thanks for you reply. So how does [sprintf replace %02dsound.aif] get connected to [buffer~].
03 sounds like a sensible argument to me. Can you explain why it is impossible?

Thanks
Pete

#195131
Jan 3, 2011 at 7:06pm

Numbers in Max can’t have leading zeros. The reason that the sprintf solution works is that it is no longer a number at the output of sprintf.

#195132
Jan 3, 2011 at 8:07pm

Thanks that makes sense. I still am not sure how to pass srguments into a buffer object, though. How does [sprintf replace %02dsound.aif] get connected to [buffer~]?

Thanks
Pete

#195133
Jan 6, 2011 at 2:01am

OK so I compressed a patch demonstrating what I am trying to do, if any one would care to have a look any advice would be greatly appreciated.

– Pasted Max Patch, click to expand. –

Thanks
Pete

#195134
Jan 6, 2011 at 2:39am

one way:

– Pasted Max Patch, click to expand. –
#195135
Jan 6, 2011 at 2:45am

“How does [sprintf replace %02dsound.aif] get connected to [buffer~]?”

with a connection?

#195136
Jan 6, 2011 at 10:17am

combine also have a zero padding option.

– Pasted Max Patch, click to expand. –
#195137
Jan 7, 2011 at 5:24am

Thanks to everyone for their suggestions. That works perfectly.

Cheers
Pete

#195138

You must be logged in to reply to this topic.