Record audio to a folder relative to patch?
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.
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.
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.
best,
Zachary
Thanks for the replies and the example patch; that makes sense. I thought I was maybe missing an easier way...
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:
foo-Eb_25-12142009_11160.aif
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.
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.
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?
kp*,
Here you go.
best,
Zachary
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]?
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.
best,
Zachary