Forums > MaxMSP

Write [buffer~] to disk & display save file name

Mar 09 2011 | 7:51 pm

I am trying to figure out how to save the contents of a [buffer~] object to disk in a user chosen audio format, and then display & use the filename of the saved file.

If I use [savedialog] -> (write $1) -> [buffer~], I can get the file name from [savedialog], but it does not ensure that the file name entered and the audio file type will match. For example, I can tell [savedialog] that my file is to be named bongo.wav, but (write) -> [buffer~] will save an aiff file by default. And since I want to give the user the option of audio file format, I do not want to have to use one or the other of (writeaiff) or (writewave).

Alternatively, I could simply use (write) -> [buffer~], and the user will be asked to choose a file format (e.g., aiff, wave, NeXT/Sun), but then I do not see a way to grab the file name for display/use within my patch.

Any suggestions?

Mar 09 2011 | 8:00 pm

buffer takes the "writeaiff", "writewave", "writeau" and writeraw" messages.

From the reference page of buffer:
writewave filename [symbol]
Saves the contents of the buffer~ into a WAV file. A standard Save As dialog is opened for naming the file unless the word writewave is followed by a symbol, in which case the file is saved in the current default folder, using the symbol as the filename.


Mar 09 2011 | 8:03 pm

Thanks Jan. I understand how writeaiff, etc. work. But how do I get the filename for display? The write message does not have an outlet for the chosen filename the way [savedialog] does.

Mar 09 2011 | 8:17 pm

Is this what you want?

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

Mar 09 2011 | 8:18 pm

Are you looking for something like this?

— Pasted Max Patch, click to expand. —
Mar 09 2011 | 9:34 pm

Thank you both for your suggestions.

@saulpimpson – Your example allows selection of writing either a wave or an aiff file, but I do not see a way to get the save file name for display.

@Jan – Your example has the user enter the save file name in a text edit object, then send it to the [buffer~] using (writeaiff $1). Unfortunately, if the user does not enter a save file name with the right extension (".aiff" in your example), then a file gets saved in a format that does not match its extension, and this file will not load properly later on.

What I am after is the behavior of a (write) message sent to a [buffer~] object, because it allows the user to select from a drop-down list of audio file types and then to specify a file name, but then to have the specified file name available within my patch, in much the same way an [opendialog] or [savedialog] makes the selected filename available via an object outlet.

Mar 09 2011 | 10:14 pm

could you combine the two examples to get what you’re looking for?

Mar 09 2011 | 10:58 pm

now i think I understand!!!!
What about this

— Pasted Max Patch, click to expand. —
Mar 10 2011 | 12:07 pm

@Jan – This should do the trick, thanks. On my Windows 7 machine, the savedialog does not seem to work correctly, in that it still displays all files rather than limiting to AIFF and WAVE. What you suggest will be good enough though – only file names with aiff or wave extensions will be saved and in the correct format. Thanks again. I really appreciate you taking the time to help me figure this out!!

Mar 10 2011 | 12:22 pm

@bongo : happy that I could help… (sharing is fun ;) )

Mar 10 2011 | 2:58 pm

any idea why i can’t seem to set the file types for [savedialog] or [opendialog] for that matter? sending a writeaiff or writewave message without a file name to [buffer~] will open a save dialog with the file type (.aiff or .wav) selected.

i am on windows 7.

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

Forums > MaxMSP