Buffer and MIDI

seekyou's icon

Hi everyone,
I need to build a patch with the following specs:

I have a few wav mono files I need to playback (1 time with note on midi message - no loop). each file is different for each note of my midi controller (a usb keyboard with 4 octaves of range).
Files are short (almost 1 1.5 seconds each). I need to play max 6 files at the same time.

Is it possible to preload in ram the wav files (almost 48 files more or less) when the patch loads. Do I have to use a loadbang for that?
Now using the buffer command is it possible to generate (through a list or message) the specific buffer command for the specific file relevant to the midi pitch note on message?

Let's say midi note on pitch = 48
I want to play a file with the buffer command and the file is named sample48.wav

Is it buffer a suitable object for this. Should I look to other objects as well?

Marco

seejayjames's icon

buffer~ can do all that (and lots more)...look to the "loadram" message for your first question, and the [sprintf] object for the second question:

sprintf read sample%u.wav

send in "48" from your midi note on pitch, and the %u in [sprintf] will be replaced by it. Send the output of [sprintf] to your [buffer~] and voila!

You'll need a separate buffer~ for every file unless you combine the files beforehand. No problem, each buffer~ is named differently. you can set which buffer~ the groove~ object plays with the "set" message. (Note that buffer~ names are NOT the same as the filename it's playing.)

If you want a separate groove~ for each buffer~ (I would do it that way), you can make an abstraction for each "bundle", and maybe use [bpatcher]. Very easy to duplicate when everything's bundled together. Or you can make a subpatch for each instead, which is easier and more flexible in some ways, but not in others...

[Edit]: If you have a separate buffer~ for each possible file, you won't need the [sprintf] command for reading new files in. But if you haven't met [sprintf] yet, it's a great one to be aware of...it can handle string replacement differently than messages can, like being able to insert values right into a string (message $1 $2 etc. will turn them into lists with spaces). Essential for filepath and filename processing.

seekyou's icon

Thank you so much mate!

marco