Forums > MaxMSP

create buffers on click?

Feb 01 2014 | 4:45 am

hi, i am wondering if there is a way to create buffers on a keypress for example. so if i press key x, a buffer called buffer-x is created. additionally i want to send a replace message to that buffer and afterwards the buffer should play when key x is pressed.

generally my main question is how i can dynamically create and name that buffer~

hope someone has an idea to share..


Feb 01 2014 | 7:13 am

You’ll want to start with something like this.

Take a look at [thispatcher] help file, specifically "Making new objects."

You’ll want to take the key pressed and put it into a [bag] or something and compare it against the key being pressed to see if a buffer already exists with that name. With some clever logic, it will trigger the buffer to play rather than create a new one.

-- Pasted Max Patch, click to expand. --


Feb 01 2014 | 7:43 am

wow, thank you very much!

Feb 01 2014 | 11:11 am

hm, now i am facing the problem how to send the message to such an object. i’d need to send the replace-message to the buffer when it is created or when the according key is passed.

and btw, how can i prepend something without the space between the original value and the prepend part?

Feb 02 2014 | 2:50 am

when creating a buffer, you can give it a scripting name, so you can send it the replace message via scripting!! All in one message!!

To remove the space between two messages "prepend orignalMessage", you could use [sprintf %s%s].

Check to code, it’s not the most elegant… but it will get you started!

-- Pasted Max Patch, click to expand. --


Feb 02 2014 | 2:51 am

Its based based on Jason’s example above


Feb 02 2014 | 9:43 am

thank you very much. that got me to the point..

Feb 05 2014 | 8:41 am

A couple things I’d recommend.
1) If all you want to do is automatically assign a key to play back an already-recorded soundfile, you might want to use sfplay~ rather than buffer~ to access the soundfile.
2) If you want to do more complex things with the sound than just play it, then perhaps buffer~ is indeed what you want, but…
Rather than trying to dynamically create new objects and create names for them based on the letter of the key that has been pressed, and then trying to access them via that name later, you might want to consider creating a single buffer~ with enough memory to hold the amount of sound you intend to record, and then recording into different parts of that buffer, keeping track (in a coll) of the start and end times of each recording, and using the ASCII code of the key in question to look up those start and end times.

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

Forums > MaxMSP