Csound Csound-dev Csound-tekno Search About

Re: [Csnd] fout

Date2021-10-10 19:15
FromEnrico Francioni <00000005323c8739-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd] fout
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

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2021-10-10 19:53
Fromjohn
SubjectRe: [Csnd] fout
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.

On Sun, 10 Oct 2021, Enrico Francioni wrote:

> 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
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
>

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2021-10-10 20:05
FromRory Walsh
SubjectRe: [Csnd] fout
Apologies if this has already been suggested, but you can also use the date opcode to generate a unique file name each time.  

On Sun, 10 Oct 2021 at 19:54, john <jpff@codemist.co.uk> wrote:
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.

On Sun, 10 Oct 2021, Enrico Francioni wrote:

> 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
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
>

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2021-10-10 20:09
FromTarmo Johannes
SubjectRe: [Csnd] fout
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.  

On Sun, 10 Oct 2021 at 19:54, john <jpff@codemist.co.uk> wrote:
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.

On Sun, 10 Oct 2021, Enrico Francioni wrote:

> 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
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
>

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2021-10-10 20:35
Fromjohn
SubjectRe: [Csnd] fout
In deed.  The example for dates opcode in the manual does just that and 
ows how using substr one can get usr-non-hostile names.


On Sun, 10 Oct 2021, Rory Walsh wrote:

> Apologies if this has already been suggested, but you can also use the date
> opcode to generate a unique file name each time.  
> 
> On Sun, 10 Oct 2021 at 19:54, john  wrote:
>       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.
>
>       On Sun, 10 Oct 2021, Enrico Francioni wrote:
>
>       > 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
>       >
>       > Csound mailing list
>       > Csound@listserv.heanet.ie
>       > https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>       > Send bugs reports to
>       >        https://github.com/csound/csound/issues
>       > Discussions of bugs and features can be posted here
>       >
>
>       Csound mailing list
>       Csound@listserv.heanet.ie
>       https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>       Send bugs reports to
>               https://github.com/csound/csound/issues
>       Discussions of bugs and features can be posted here
> 
> Csound mailing list Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
> https://github.com/csound/csound/issues Discussions of bugs and features can
> be posted here
>

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2021-10-10 20:40
From"Dr. Richard Boulanger"
SubjectRe: [Csnd] fout
excellent.  i know the manual.  and I know the opcodes, but not all of them by a mile.
- cool

- Dr.B


Dr. Richard Boulanger

Professor

Electronic Production and Design

Berklee College of Music

Professional Writing & Technology Division



On Sun, Oct 10, 2021 at 3:35 PM john <jpff@codemist.co.uk> wrote:
In deed.  The example for dates opcode in the manual does just that and
ows how using substr one can get usr-non-hostile names.


On Sun, 10 Oct 2021, Rory Walsh wrote:

> Apologies if this has already been suggested, but you can also use the date
> opcode to generate a unique file name each time.  
>
> On Sun, 10 Oct 2021 at 19:54, john <jpff@codemist.co.uk> wrote:
>       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.
>
>       On Sun, 10 Oct 2021, Enrico Francioni wrote:
>
>       > 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
>       >
>       > Csound mailing list
>       > Csound@listserv.heanet.ie
>       > https://us-west-2.protection.sophos.com?d=heanet.ie&u=aHR0cHM6Ly9saXN0c2Vydi5oZWFuZXQuaWUvY2dpLWJpbi93YT9BMD1DU09VTkQ=&i=NWYxNzBkMDNiNTVmZGEwZmIyNjczYmRm&t=WVZMRlI4dlFUVUZ6V2NTOUU5eE9lZnFIemtoc2hxYlBDMFFCWmtKZzhzRT0=&h=e966ac05151d41fda26e79c511f72006
>       > Send bugs reports to
>       >        https://us-west-2.protection.sophos.com?d=github.com&u=aHR0cHM6Ly9naXRodWIuY29tL2Nzb3VuZC9jc291bmQvaXNzdWVz&i=NWYxNzBkMDNiNTVmZGEwZmIyNjczYmRm&t=YlNrQ2lLclRLZUpGUE1iR0FyY2M1eW1NTUU5SUozWlJwMTNZU2NXT1BLOD0=&h=e966ac05151d41fda26e79c511f72006
>       > Discussions of bugs and features can be posted here
>       >
>
>       Csound mailing list
>       Csound@listserv.heanet.ie
>       https://us-west-2.protection.sophos.com?d=heanet.ie&u=aHR0cHM6Ly9saXN0c2Vydi5oZWFuZXQuaWUvY2dpLWJpbi93YT9BMD1DU09VTkQ=&i=NWYxNzBkMDNiNTVmZGEwZmIyNjczYmRm&t=WVZMRlI4dlFUVUZ6V2NTOUU5eE9lZnFIemtoc2hxYlBDMFFCWmtKZzhzRT0=&h=e966ac05151d41fda26e79c511f72006
>       Send bugs reports to
>               https://us-west-2.protection.sophos.com?d=github.com&u=aHR0cHM6Ly9naXRodWIuY29tL2Nzb3VuZC9jc291bmQvaXNzdWVz&i=NWYxNzBkMDNiNTVmZGEwZmIyNjczYmRm&t=YlNrQ2lLclRLZUpGUE1iR0FyY2M1eW1NTUU5SUozWlJwMTNZU2NXT1BLOD0=&h=e966ac05151d41fda26e79c511f72006
>       Discussions of bugs and features can be posted here
>
> Csound mailing list Csound@listserv.heanet.ie
> https://us-west-2.protection.sophos.com?d=heanet.ie&u=aHR0cHM6Ly9saXN0c2Vydi5oZWFuZXQuaWUvY2dpLWJpbi93YT9BMD1DU09VTkQ=&i=NWYxNzBkMDNiNTVmZGEwZmIyNjczYmRm&t=WVZMRlI4dlFUVUZ6V2NTOUU5eE9lZnFIemtoc2hxYlBDMFFCWmtKZzhzRT0=&h=e966ac05151d41fda26e79c511f72006 Send bugs reports to
> https://us-west-2.protection.sophos.com?d=github.com&u=aHR0cHM6Ly9naXRodWIuY29tL2Nzb3VuZC9jc291bmQvaXNzdWVz&i=NWYxNzBkMDNiNTVmZGEwZmIyNjczYmRm&t=YlNrQ2lLclRLZUpGUE1iR0FyY2M1eW1NTUU5SUozWlJwMTNZU2NXT1BLOD0=&h=e966ac05151d41fda26e79c511f72006 Discussions of bugs and features can
> be posted here
>

Csound mailing list
Csound@listserv.heanet.ie
https://us-west-2.protection.sophos.com?d=heanet.ie&u=aHR0cHM6Ly9saXN0c2Vydi5oZWFuZXQuaWUvY2dpLWJpbi93YT9BMD1DU09VTkQ=&i=NWYxNzBkMDNiNTVmZGEwZmIyNjczYmRm&t=WVZMRlI4dlFUVUZ6V2NTOUU5eE9lZnFIemtoc2hxYlBDMFFCWmtKZzhzRT0=&h=e966ac05151d41fda26e79c511f72006
Send bugs reports to
        https://us-west-2.protection.sophos.com?d=github.com&u=aHR0cHM6Ly9naXRodWIuY29tL2Nzb3VuZC9jc291bmQvaXNzdWVz&i=NWYxNzBkMDNiNTVmZGEwZmIyNjczYmRm&t=YlNrQ2lLclRLZUpGUE1iR0FyY2M1eW1NTUU5SUozWlJwMTNZU2NXT1BLOD0=&h=e966ac05151d41fda26e79c511f72006
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2021-10-10 20:49
Fromjoachim heintz
SubjectRe: [Csnd] fout
hi 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

instr Record
  S_filename sprintf "Out_REC_%02d.wav", giFilNum
  giFilNum += 1
  Scmd sprintf "printf %d > state.txt", giFilNum
  ires system_i 1, Scmd
  ;fprints("state.txt","%d",giFilNum)
  fout S_filename, 18, poscil:a(.2,random:i(400,800))
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.

	joachim


On 10/10/2021 20:15, Enrico Francioni wrote:
> 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
> 
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>          https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
> 

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2021-10-11 00:41
FromRichard Knight
SubjectRe: [Csnd] fout
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.
https://github.com/csound/csound/blob/develop/Opcodes/fout.c#L1298

On 2021-10-10 20:49, joachim heintz wrote:

> 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.
> 
> 	joachim
> 

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2021-10-11 16:23
Fromjoachim heintz
SubjectRe: [Csnd] fout
thanks for looking in the code.  for me, the result of this is 
definitely "1234", not "4":

indx = 1
istart = 0
while indx < 5 do
  schedule(1,istart,0,indx)
  istart += 1
  indx += 1
od
instr 1
  fprints "test.txt", "%d", p4
endin

	j



On 11/10/2021 01:41, Richard Knight wrote:
> 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.
> https://github.com/csound/csound/blob/develop/Opcodes/fout.c#L1298
> 
> On 2021-10-10 20:49, joachim heintz wrote:
> 
>> 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.
>>
>>     joachim
>>
> 
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>         https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2021-10-11 19:42
FromRichard Knight
SubjectRe: [Csnd] fout
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:


gStateFile = "state.txt"
giFilNum init 0

opcode WriteState, 0, 0
  ihandle fiopen gStateFile, 0
  fouti ihandle, 0, 0, giFilNum
  ficlose ihandle
endop

instr Init
  if filevalid(gStateFile) == 1 then
   fini gStateFile, 0, 0, giFilNum
   prints "File 'state.txt' read. Continuing with file counter %d.\n", 
giFilNum
  else
   puts "File 'state.txt' created, starting with 1.", 1
  giFilNum = 1
  WriteState

  endif
endin

instr Record
  S_filename sprintf "Out_REC_%02d.wav", giFilNum
  giFilNum += 1
  WriteState
  fout S_filename, 18, poscil:a(.2,random:i(400,800))
endin





On 2021-10-11 16:23, joachim heintz wrote:
> thanks for looking in the code.  for me, the result of this is
> definitely "1234", not "4":
> 
> indx = 1
> istart = 0
> while indx < 5 do
>  schedule(1,istart,0,indx)
>  istart += 1
>  indx += 1
> od
> instr 1
>  fprints "test.txt", "%d", p4
> endin
> 
> 	j
> 
> 

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here