ddf / Minim

A Java audio library, designed to be used with Processing.

Home Page:http://code.compartmental.net/tools/minim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deleting recorder files on exit

markcosmic opened this issue · comments

Greetings all,
Question: Is there a way to have minin release the use of the recorder created without creating a a new recorder under the same name?
Explain: So I’ve written a recording sketch using minim examples. My sketch checks for existing files in the data folder starting with the prefix “MaxRecordings” (after my son) with an added incremental index (1,2,3 and so on). This is done in a while() loop until the file does not exist. Then increments the suffix by 1. (Example: “MaxRecordings9”) because it found 8 previous files. This works no issue.
Here’s the issue: I use recorder.createRecorder(“MaxRecordings” + index). This works as it should. If I don’t want to keep the recorded file or just don’t actually record and exit the sketch. The file still exist. I’ve written the code to delete the unused or unwanted file to delete it onexit(), (easy to do). But the delete() method returns “false” and the file remains. Even if I save the recording first it still remains. All the code I wrote works even the delete() method which returns “false”. No errors. I believe that that minin doesn’t release the use of the “recorder” created until another is created using the same name (“recorder”). Thus, not allowing the delete() method to delete the file. Is there a way to have minin release the use of the recorder created without creating a new recorder under the same name?

No takers? Oh well thanks anyway

Hi, apologies for not responding sooner, I am not really actively maintaining Minim right now, so I don't often check in here. With questions like these you might get a faster response from the community by posting in the Processing forum.

That said, I looked into the code and I believe what's going on is that the version of createRecorder that you are using results in a "streaming" recording being created that records directly to a file that is opened when the recorder is created. The only way to close that file stream is to call save() on the recorder (and you'll also want to call close() on the recording returned from save(). So you'd need to do that before deleting the file. This code is not well written (my fault) and lots of people have had issues with it over the years.

Another option would be to use the version of createRecorder that takes a boolean buffered argument. If buffered is true, then you'll get back a recorder that records into an in-memory array and doesn't actually write to disk until you call save(). So, in that case, if you discard the recorder without ever saving, you won't wind up with open file handles or extra files on disk that you want to delete. But this buffered version may not be appropriate if you are making longer recordings. In particular, the longer that you record, the slower it gets, which is why the streaming version is the default.

Many years ago I had aspirations to do that, but never got around to it.