create buffers on click?

elloPropello's icon

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..

cheers,
Ello

Jason Charney's icon

You'll want to start with something like this.

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

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

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.

elloPropello's icon

wow, thank you very much!

elloPropello's icon

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?

Nikolas K's icon

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!

----------begin_max5_patcher----------
2049.3ocyas0ihaCE9YleCUstY29FcTbRbtz1G1p9TkppZetc0HSvv3tgDTh
Y1Y2Ua6e85aARfDHvdHCZjfI1N3i+NW84X+o6l3Lq3YVkC5GP+EZxjOc2jI5
lTMLw97DmUzmSynU5g4jydewr+wYpoKA6Ygt4p0k7bwBT0GVUrQflsYwBV4C
eWU8.y2rhmmwD5eDrswEE4hJ9GY517t2017ZpH8Qd9xGJYoBCs4QHxtQgtgp
uvApAi7bu2E81cSfbh6ZFxoqzyfyOWxoY0DDettM4Z46wddMWOoEYEklo089
DxzVehaLkl4S7g0LyncbPuU0ymu6N0GSGHhlVrZEKWb.jJJ4KWxJQhBzejQ+
.PHYXbhB6BhwZjj3dBjz8rPRbRcqKJWNS+9aIlCv1PRbrWvzN+OMNeAf4rMB
QQ9Qwpt.kP+Ffhm6.ktZsxib5SrXFMe4kIZrhUUQWxNPz3+5bA5c9BCX78js
qaesjANFHsJLwAVEkKi25icMKtu.dq+Uf21igTosSzLfz0IgF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0IomwyVMgLzcINNziu6P2k33POCwXl+3od4OD08wbCYCAdtTsKS5
N26NroHk8t6Z6cu0N7Nq028USNOe9t+20.M0C
-----------end_max5_patcher-----------

Nikolas K's icon

Its based based on Jason's example above
:)

Nikolas

elloPropello's icon

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

Christopher Dobrian's icon

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.