sfrecord: incorporating formatted date & time in filename

kryl's icon

I have created a patch that functions as a simple audio recorder.

The most challenging feature of this patch is that I want it to generate the filename automatically, using the current date and time, and formatting this data in the way that I prefer.

The filename should have the following format:

2018_05_04 (4꞉25꞉08) - My recording.wav

I've managed to successfully get the patch to create this filename. It works most of the time. But, every so often, the filename of the file that Max creates is:

2018_05_04 () - My recording.wav

In addition to the filename clearly missing the time string, the file itself is corrupted or empty. That is, the .wav file cannot be played in any media player and the file maintains a file size of 4 KB, indicating that no audio was ever recorded.

I've tried to determine what exactly is the root issue, and why it only occurs sometimes. The issue always seems to occur on the first iteration of the patch after Max is launched. Subsequent iterations typically have the correct filename.

Alas, I do not know what is going on. For example, is this a sprintf bug or an sfrecord bug?

Any insight is appreciated. Thanks in advance.


Max Patch
Copy patch and select New From Clipboard in Max.


(Note that the relevant code is found towards the bottom of the canvas.)

mizu's icon

bang the time first: the date bangs the open message to sfrecord. Trigger is your friend

Max Patch
Copy patch and select New From Clipboard in Max.

kryl's icon

@Mizu,

That solves the issue, thank you.

Do you happen to know the reason why the time calculation needs to be triggered first? That is, I don't understand why Max takes longer to calculate the time than to calculate the date.

On an entirely separate note, is it possible to tell Max to always have the Audio "on" by default? Every time that I open this patch in Max, I have to manually click the "on" button in the lower-right corner to turn the Audio on.

(I didn't find a "default" setting in the Audio Status or Preferences windows.)

mizu's icon

Hi KRYL
seems you need to understand the rules of Max to propagate the data between the objects. Without use of the trigger objekt, Max begins at bottom right to top left of the patch. An object with multiple inputs will give the result only when the left input receives a message (bang, int float message list etc ). I.e, MSP calculates every sample, and Jitter has sometime another clock's logic.
Go to trigger maxhelp, and it's reference
loadbang is your friend too ( making a new patch i prefer start the sound myself ;-) when i reopen it )

Max Patch
Copy patch and select New From Clipboard in Max.