Now I wonder if it was also possible to make sure that, after generating some audio files with fout, after closing the frontend (in my case CsoundQt), in a subsequent work session the audio files - always generated with fout - can be saved starting from the numbering immediately following the last file previously generated.
This will avoid overwriting the new files generated in new work sessions, on the previous audio files created.
Enrico
There are a number of ways of achieving this depending on how automated you desire it to be.
If you know when your program has finished you can write a file defining a csound macro which records the number and you can define with either a #include or a CLI csound call defining a macro.
More automate methods include writing a C program (or whatever you refer) to scan the directory and extract the highest version number.
And - as you mentioned CsoundQt - if you use the Record button in CsoundQt, an unique index will be added to the file name automatically.
Tarmo
P, 10. oktoober 2021 22:05 Rory Walsh <rorywalsh@ear.ie> kirjutas:
Apologies if this has already been suggested, but you can also use the date opcode to generate a unique file name each time.
There are a number of ways of achieving this depending on how automated
you desire it to be.
If you know when your program has finished you can write a file defining
a csound macro which records the number and you can define with either a #include or a CLI csound call defining a macro.
More automate methods include writing a C program (or whatever you refer)
to scan the directory and extract the highest version number.
Hi Joachim!
What a pleasure to hear from you…!
Your patch works, thanks!
Now I wonder if it was also possible to make sure that, after generating some audio files with fout, after closing the frontend (in my case CsoundQt), in a subsequent work session the audio files - always generated with fout - can be saved starting from the numbering immediately following the last file previously generated.
This will avoid overwriting the new files generated in new work sessions, on the previous audio files created.
Enrico
i think this is one of the possible solutions which john mentioned. it looks for a file "state.txt" in the working directory. if not found, it will be created. if found, it will continue where it was left.
instr Init
if filevalid("state.txt") == 1 then
State, iline readfi "state.txt"
giFilNum = strtod(State)
prints "File 'state.txt' read. Continuing with file counter %d.\n", giFilNum
else
puts "File 'state.txt' created, starting with 1.", 1
fprints("state.txt","1")
giFilNum = 1
endif
endin
and score e.g.
i "Init" 0 0
i "Record" 0 1
i . 1 1
rather than using the system_i opcode i would prefer to use fprints. but this always appends the string to the file content, and i could not figure out how just to replace the content. i don't know whether there is a hidden option in fprints, or any other opcode to do it.
Hmm, fprints overwrites the existing file for me and a quick look at the source suggests the file is always opened in "w" so I think the intended behaviour is to overwrite.
I see many avenues open to accomplishing the same thing: very well!
Each solution adapts to specific needs.
I had neglected the Tarmo solution; on the other hand, the other proposals are valid reasons for in-depth analysis and study.
Actually, I was wrong, and I can't recreate what I originally said now...
I had a further look and it seems that fprints and fprintks keep the file open, so a subsequent call will use the existing open file and hence append. It seems that writing strings will always append to the file, but fiopen/ficlose could be used to overwrite a state file with a number and then retrieve it with fini. I had a play around with your example to try it: