Forums > MaxMSP

Record audio to a folder relative to patch?

Dec 11 2009 | 5:16 pm

Let’s say I’ve got a patch called ‘foo.maxpat’ saved in a folder called ‘bar’, then I make a subfolder called ‘audio’. How can I get an sfrecord~ object in foo.maxpat to record into the ‘audio’ folder, so that I end up with ‘bar/audio/myfile.aif’? In such a way that I can move the whole ‘bar’ folder anywhere and it still works? Max 5, OSX.

Dec 11 2009 | 6:04 pm

Maybe look to the "path" message to [thispatcher], and some sprintf to create the complete filepath (adding on audio/myfile.aif….also you can put numbers into the filename with %ld inside sprintf). Watch for spaces in the path, it needs to be a single symbol. It takes a bit of trial and error but can be done.

[opendialog fold] and the [dropfolder] can also work, but the other method can be done automatically.

Dec 11 2009 | 7:49 pm

The path message to [thispatcher] does sound like the right approach here, but you should also know about Jasch’s [getpaths] object. Here’s an example patch using both.


— Pasted Max Patch, click to expand. —
Dec 13 2009 | 2:06 pm

Thanks for the replies and the example patch; that makes sense. I thought I was maybe missing an easier way…

Dec 14 2009 | 3:48 am

I think that [sprintf symout %s/audio/%s] should be [sprintf symout %saudio/%s] since there is already a slash at the end of the path.

So, this is brilliant and useful. What i can’t quite figure out is how to do a variation this that would be exceedingly helpful.

In the case where i am munging a soundfile (off the disk or loaded into a buffer) I like to know the sound file that was used and usually include that in the name.

So if the source is a file called foo-Eb_25.aif then I would get a file in the audio directory called:


or some such. The reason is that my names are occasionally meaningful and contain information about what kind of musical gesture it is and pitch info.

I guess you can bang info~ and then used the last outlet of that and somehow concat that into the name after stripping the extension, but i can’t quite get that to work.

Dec 14 2009 | 8:32 am

One other idea, not sure if it can work, but if you tell sfrecord~ (or any object which can do a "write file" kind of command) simply to save with a filename, it goes into the main Max 5 application folder, at least on my XP machine here. If there was a way to tell Max to change this default location to be something different—like the output of [thispatcher] "path"—then perhaps all subsequent file-writing could go to that folder? It would eliminate all the sprintf-ing. :)

I was testing some save features awhile back and my examples were saving somewhere, but I couldn’t figure out where they were going…thought it would be the patch’s folder, but I suppose the Max 5 App folder makes sense too. Anyway, no big deal.

Dec 14 2009 | 8:46 am

You’re right about that extra slash in the path, I spotted that slip too.

As to where files are saved by default; into the application folder does seem a bit daft. I’m trying to remember how this works on Pd; I might have thought a better default location might have been into the same folder as the patch? Isn’t that the way it is in Pd?

Dec 14 2009 | 9:26 am


Here you go.


— Pasted Max Patch, click to expand. —

Dec 14 2009 | 10:11 am

Thanks for that. I was sniffing in the right corners, but i never would have thunk to use regexp. Fantastic.

Any special reason to use Jasch’s [getpaths]?

Dec 14 2009 | 11:57 am

The [getpaths] object is useful when you want to find various paths on the user’s system. You can do things with that object that can not be done with [thispatcher], such as save to the home directory of whatever machine you’re using. But it’s Mac only.


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

Forums > MaxMSP