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

Mar 9, 2011 at 7:51pm

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

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?

#55423
Mar 9, 2011 at 8:00pm

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.

Jan

#199464
Mar 9, 2011 at 8:03pm

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.

#199465
Mar 9, 2011 at 8:17pm

Is this what you want?

– Pasted Max Patch, click to expand. –
#199466
Mar 9, 2011 at 8:18pm

Are you looking for something like this?

– Pasted Max Patch, click to expand. –
#199467
Mar 9, 2011 at 9:34pm

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.

#199468
Mar 9, 2011 at 10:14pm

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

#199469
Mar 9, 2011 at 10:58pm

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

– Pasted Max Patch, click to expand. –
#199470
Mar 10, 2011 at 12:07pm

@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!!

#199471
Mar 10, 2011 at 12:22pm

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

#199472
Mar 10, 2011 at 2:58pm

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.

#199473

You must be logged in to reply to this topic.