Csound Csound-dev Csound-tekno Search About

[Csnd] Odd string problem

Date2021-12-15 10:14
FromOeyvind Brandtsegg
Subject[Csnd] Odd string problem
Hi,
I am trying to parse comma separated numbers in a string (as to send them one by one to another process). Something odd is happening so that my instrument works correctly the first time it starts, but then when it is started again the first item of the string is not converted to a number.

It might look like some k-rate string opcodes somehow retain their state from previous initializations (??)

The csd below shows the problem. Running instr 1 should print the numbers in the string one by one. This happens correctly the first time the instrument runs, but it only prints 2 and 3 the second time the instrument runs.

As a test I have recreated the same procedure with i-time string opcodes in instr 2. This works every time. Sadly, I do need to make it work at k-rate...

All best
Øyvind


<CsoundSynthesizer>
<CsOptions>
-n
</CsOptions>

<CsInstruments>

instr 1
  Snumbers = "1,2,3"
  Snumbers strcat Snumbers, ","
  kcomma strindexk Snumbers, ","
  while kcomma > -1 do
    Sval strsubk Snumbers, 0, kcomma
    kval strtodk Sval
    printk2 kval, 10
    Snumbers strsubk Snumbers, kcomma+1, -1
    kcomma strindexk Snumbers, ","
  od
endin

instr 2
  Snumbers = "1,2,3"
  Snumbers strcat Snumbers, ","
  icomma strindex Snumbers, ","
  while icomma > -1 do
    Sval strsub Snumbers, 0, icomma
    ival strtod Sval
    print ival
    Snumbers strsub Snumbers, icomma+1, -1
    icomma strindex Snumbers, ","
  od
endin

</CsInstruments>
<CsScore>
i1 0 .1
i1 1 .1

;i2 2 .1
;i2 3 .1

</CsScore>
</CsoundSynthesizer>

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-12-15 13:46
FromOeyvind Brandtsegg
SubjectRe: [Csnd] Odd string problem
Browsing through the list of opcodes (csound -z), I found string2array that seems very useful in this context. 
I can't find a manual page for it. Can I expect it to still be included in future versions of Csound?

ons. 15. des. 2021 kl. 11:14 skrev Oeyvind Brandtsegg <obrandts@gmail.com>:
Hi,
I am trying to parse comma separated numbers in a string (as to send them one by one to another process). Something odd is happening so that my instrument works correctly the first time it starts, but then when it is started again the first item of the string is not converted to a number.

It might look like some k-rate string opcodes somehow retain their state from previous initializations (??)

The csd below shows the problem. Running instr 1 should print the numbers in the string one by one. This happens correctly the first time the instrument runs, but it only prints 2 and 3 the second time the instrument runs.

As a test I have recreated the same procedure with i-time string opcodes in instr 2. This works every time. Sadly, I do need to make it work at k-rate...

All best
Øyvind


<CsoundSynthesizer>
<CsOptions>
-n
</CsOptions>

<CsInstruments>

instr 1
  Snumbers = "1,2,3"
  Snumbers strcat Snumbers, ","
  kcomma strindexk Snumbers, ","
  while kcomma > -1 do
    Sval strsubk Snumbers, 0, kcomma
    kval strtodk Sval
    printk2 kval, 10
    Snumbers strsubk Snumbers, kcomma+1, -1
    kcomma strindexk Snumbers, ","
  od
endin

instr 2
  Snumbers = "1,2,3"
  Snumbers strcat Snumbers, ","
  icomma strindex Snumbers, ","
  while icomma > -1 do
    Sval strsub Snumbers, 0, icomma
    ival strtod Sval
    print ival
    Snumbers strsub Snumbers, icomma+1, -1
    icomma strindex Snumbers, ","
  od
endin

</CsInstruments>
<CsScore>
i1 0 .1
i1 1 .1

;i2 2 .1
;i2 3 .1

</CsScore>
</CsoundSynthesizer>

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-12-15 14:31
FromOeyvind Brandtsegg
SubjectRe: [Csnd] Odd string problem
Found it in "what's new 6.16", wonderful!

ons. 15. des. 2021 kl. 14:46 skrev Oeyvind Brandtsegg <obrandts@gmail.com>:
Browsing through the list of opcodes (csound -z), I found string2array that seems very useful in this context. 
I can't find a manual page for it. Can I expect it to still be included in future versions of Csound?

ons. 15. des. 2021 kl. 11:14 skrev Oeyvind Brandtsegg <obrandts@gmail.com>:
Hi,
I am trying to parse comma separated numbers in a string (as to send them one by one to another process). Something odd is happening so that my instrument works correctly the first time it starts, but then when it is started again the first item of the string is not converted to a number.

It might look like some k-rate string opcodes somehow retain their state from previous initializations (??)

The csd below shows the problem. Running instr 1 should print the numbers in the string one by one. This happens correctly the first time the instrument runs, but it only prints 2 and 3 the second time the instrument runs.

As a test I have recreated the same procedure with i-time string opcodes in instr 2. This works every time. Sadly, I do need to make it work at k-rate...

All best
Øyvind


<CsoundSynthesizer>
<CsOptions>
-n
</CsOptions>

<CsInstruments>

instr 1
  Snumbers = "1,2,3"
  Snumbers strcat Snumbers, ","
  kcomma strindexk Snumbers, ","
  while kcomma > -1 do
    Sval strsubk Snumbers, 0, kcomma
    kval strtodk Sval
    printk2 kval, 10
    Snumbers strsubk Snumbers, kcomma+1, -1
    kcomma strindexk Snumbers, ","
  od
endin

instr 2
  Snumbers = "1,2,3"
  Snumbers strcat Snumbers, ","
  icomma strindex Snumbers, ","
  while icomma > -1 do
    Sval strsub Snumbers, 0, icomma
    ival strtod Sval
    print ival
    Snumbers strsub Snumbers, icomma+1, -1
    icomma strindex Snumbers, ","
  od
endin

</CsInstruments>
<CsScore>
i1 0 .1
i1 1 .1

;i2 2 .1
;i2 3 .1

</CsScore>
</CsoundSynthesizer>

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-12-15 15:31
Fromjoachim heintz
SubjectRe: [Csnd] Odd string problem
hi oeyvind -

i think this is expected behaviour.  i wrote about it in
https://flossmanual.csound.com/csound-language/initialization-and-performance-pass#k-values-and-initialization-in-multiple-triggered-instruments

or is this a different case?

cheers -
	joachim


On 15/12/2021 11:14, Oeyvind Brandtsegg wrote:
> Hi,
> I am trying to parse comma separated numbers in a string (as to send 
> them one by one to another process). Something odd is happening so that 
> my instrument works correctly the first time it starts, but then when it 
> is started again the first item of the string is not converted to a number.
> 
> It might look like some k-rate string opcodes somehow retain their state 
> from previous initializations (??)
> 
> The csd below shows the problem. Running instr 1 should print the 
> numbers in the string one by one. This happens correctly the first time 
> the instrument runs, but it only prints 2 and 3 the second time the 
> instrument runs.
> 
> As a test I have recreated the same procedure with i-time string opcodes 
> in instr 2. This works every time. Sadly, I do need to make it work at 
> k-rate...
> 
> All best
> Øyvind
> 
> 
> 
> 
> -n
> 
> 
> 
> 
> instr 1
>    Snumbers = "1,2,3"
>    Snumbers strcat Snumbers, ","
>    kcomma strindexk Snumbers, ","
>    while kcomma > -1 do
>      Sval strsubk Snumbers, 0, kcomma
>      kval strtodk Sval
>      printk2 kval, 10
>      Snumbers strsubk Snumbers, kcomma+1, -1
>      kcomma strindexk Snumbers, ","
>    od
> endin
> 
> instr 2
>    Snumbers = "1,2,3"
>    Snumbers strcat Snumbers, ","
>    icomma strindex Snumbers, ","
>    while icomma > -1 do
>      Sval strsub Snumbers, 0, icomma
>      ival strtod Sval
>      print ival
>      Snumbers strsub Snumbers, icomma+1, -1
>      icomma strindex Snumbers, ","
>    od
> endin
> 
> 
> 
> i1 0 .1
> i1 1 .1
> 
> ;i2 2 .1
> ;i2 3 .1
> 
> 
> 
> 
> 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-12-15 17:09
FromOeyvind Brandtsegg
SubjectRe: [Csnd] Odd string problem
Hi Joachim
I think it is a different case. The issue is that the instrument produce different output the second time it is initialized. I would not expect such behavior in any case where all variables are local to the instrument instance.

All best
Øyvind

ons. 15. des. 2021, 4:31 p.m. skrev joachim heintz <jh@joachimheintz.de>:
hi oeyvind -

i think this is expected behaviour.  i wrote about it in
https://flossmanual.csound.com/csound-language/initialization-and-performance-pass#k-values-and-initialization-in-multiple-triggered-instruments

or is this a different case?

cheers -
        joachim


On 15/12/2021 11:14, Oeyvind Brandtsegg wrote:
> Hi,
> I am trying to parse comma separated numbers in a string (as to send
> them one by one to another process). Something odd is happening so that
> my instrument works correctly the first time it starts, but then when it
> is started again the first item of the string is not converted to a number.
>
> It might look like some k-rate string opcodes somehow retain their state
> from previous initializations (??)
>
> The csd below shows the problem. Running instr 1 should print the
> numbers in the string one by one. This happens correctly the first time
> the instrument runs, but it only prints 2 and 3 the second time the
> instrument runs.
>
> As a test I have recreated the same procedure with i-time string opcodes
> in instr 2. This works every time. Sadly, I do need to make it work at
> k-rate...
>
> All best
> Øyvind
>
>
> <CsoundSynthesizer>
> <CsOptions>
> -n
> </CsOptions>
>
> <CsInstruments>
>
> instr 1
>    Snumbers = "1,2,3"
>    Snumbers strcat Snumbers, ","
>    kcomma strindexk Snumbers, ","
>    while kcomma > -1 do
>      Sval strsubk Snumbers, 0, kcomma
>      kval strtodk Sval
>      printk2 kval, 10
>      Snumbers strsubk Snumbers, kcomma+1, -1
>      kcomma strindexk Snumbers, ","
>    od
> endin
>
> instr 2
>    Snumbers = "1,2,3"
>    Snumbers strcat Snumbers, ","
>    icomma strindex Snumbers, ","
>    while icomma > -1 do
>      Sval strsub Snumbers, 0, icomma
>      ival strtod Sval
>      print ival
>      Snumbers strsub Snumbers, icomma+1, -1
>      icomma strindex Snumbers, ","
>    od
> endin
>
> </CsInstruments>
> <CsScore>
> i1 0 .1
> i1 1 .1
>
> ;i2 2 .1
> ;i2 3 .1
>
> </CsScore>
> </CsoundSynthesizer>
>
> Csound mailing list Csound@listserv.heanet.ie
> <mailto:Csound@listserv.heanet.ie>
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> <https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND> Send bugs reports to
> https://github.com/csound/csound/issues
> <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-12-15 17:38
FromOeyvind Brandtsegg
SubjectRe: [Csnd] Odd string problem
Oh I see now what you meant. The link sent me to the top of the page first, so I checked again scrolling down to the section about multiple passes. But is still don't see how it applies to the code I sent. Could you be so kind to explain it in terms of my example code? 

ons. 15. des. 2021, 6:09 p.m. skrev Oeyvind Brandtsegg <obrandts@gmail.com>:
Hi Joachim
I think it is a different case. The issue is that the instrument produce different output the second time it is initialized. I would not expect such behavior in any case where all variables are local to the instrument instance.

All best
Øyvind

ons. 15. des. 2021, 4:31 p.m. skrev joachim heintz <jh@joachimheintz.de>:
hi oeyvind -

i think this is expected behaviour.  i wrote about it in
https://flossmanual.csound.com/csound-language/initialization-and-performance-pass#k-values-and-initialization-in-multiple-triggered-instruments

or is this a different case?

cheers -
        joachim


On 15/12/2021 11:14, Oeyvind Brandtsegg wrote:
> Hi,
> I am trying to parse comma separated numbers in a string (as to send
> them one by one to another process). Something odd is happening so that
> my instrument works correctly the first time it starts, but then when it
> is started again the first item of the string is not converted to a number.
>
> It might look like some k-rate string opcodes somehow retain their state
> from previous initializations (??)
>
> The csd below shows the problem. Running instr 1 should print the
> numbers in the string one by one. This happens correctly the first time
> the instrument runs, but it only prints 2 and 3 the second time the
> instrument runs.
>
> As a test I have recreated the same procedure with i-time string opcodes
> in instr 2. This works every time. Sadly, I do need to make it work at
> k-rate...
>
> All best
> Øyvind
>
>
> <CsoundSynthesizer>
> <CsOptions>
> -n
> </CsOptions>
>
> <CsInstruments>
>
> instr 1
>    Snumbers = "1,2,3"
>    Snumbers strcat Snumbers, ","
>    kcomma strindexk Snumbers, ","
>    while kcomma > -1 do
>      Sval strsubk Snumbers, 0, kcomma
>      kval strtodk Sval
>      printk2 kval, 10
>      Snumbers strsubk Snumbers, kcomma+1, -1
>      kcomma strindexk Snumbers, ","
>    od
> endin
>
> instr 2
>    Snumbers = "1,2,3"
>    Snumbers strcat Snumbers, ","
>    icomma strindex Snumbers, ","
>    while icomma > -1 do
>      Sval strsub Snumbers, 0, icomma
>      ival strtod Sval
>      print ival
>      Snumbers strsub Snumbers, icomma+1, -1
>      icomma strindex Snumbers, ","
>    od
> endin
>
> </CsInstruments>
> <CsScore>
> i1 0 .1
> i1 1 .1
>
> ;i2 2 .1
> ;i2 3 .1
>
> </CsScore>
> </CsoundSynthesizer>
>
> Csound mailing list Csound@listserv.heanet.ie
> <mailto:Csound@listserv.heanet.ie>
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> <https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND> Send bugs reports to
> https://github.com/csound/csound/issues
> <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-12-15 21:17
Fromjoachim heintz
SubjectRe: [Csnd] Odd string problem
hi oeyvind -

you are right; this is not the same as the case which i thought it was. 
  (i had no time to look closer this afternoon and just reacted to your 
desription.)

now i had a closer look and i think the problem is that in your code you 
mix i- and k-rate.  when you go consequently to k-rate, it works for me:

instr 1
   Snumbers strcpyk "1,2,3"
   Snumbers strcatk Snumbers, ","
   kcomma strindexk Snumbers, ","
   while kcomma > -1 do
     Sval strsubk Snumbers, 0, kcomma
     kval strtodk Sval
     printk2 kval, 10
     Snumbers strsubk Snumbers, kcomma+1, -1
     kcomma strindexk Snumbers, ","
   od
   turnoff
endin

ciao -
	joachim



On 15/12/2021 18:38, Oeyvind Brandtsegg wrote:
> Oh I see now what you meant. The link sent me to the top of the page 
> first, so I checked again scrolling down to the section about multiple 
> passes. But is still don't see how it applies to the code I sent. Could 
> you be so kind to explain it in terms of my example code?
> 
> ons. 15. des. 2021, 6:09 p.m. skrev Oeyvind Brandtsegg 
> >:
> 
>     Hi Joachim
>     I think it is a different case. The issue is that the instrument
>     produce different output the second time it is initialized. I would
>     not expect such behavior in any case where all variables are local
>     to the instrument instance.
> 
>     All best
>     Øyvind
> 
>     ons. 15. des. 2021, 4:31 p.m. skrev joachim heintz
>     >:
> 
>         hi oeyvind -
> 
>         i think this is expected behaviour.  i wrote about it in
>         https://flossmanual.csound.com/csound-language/initialization-and-performance-pass#k-values-and-initialization-in-multiple-triggered-instruments
>         
> 
>         or is this a different case?
> 
>         cheers -
>                  joachim
> 
> 
>         On 15/12/2021 11:14, Oeyvind Brandtsegg wrote:
>          > Hi,
>          > I am trying to parse comma separated numbers in a string (as
>         to send
>          > them one by one to another process). Something odd is
>         happening so that
>          > my instrument works correctly the first time it starts, but
>         then when it
>          > is started again the first item of the string is not
>         converted to a number.
>          >
>          > It might look like some k-rate string opcodes somehow retain
>         their state
>          > from previous initializations (??)
>          >
>          > The csd below shows the problem. Running instr 1 should print
>         the
>          > numbers in the string one by one. This happens correctly the
>         first time
>          > the instrument runs, but it only prints 2 and 3 the second
>         time the
>          > instrument runs.
>          >
>          > As a test I have recreated the same procedure with i-time
>         string opcodes
>          > in instr 2. This works every time. Sadly, I do need to make
>         it work at
>          > k-rate...
>          >
>          > All best
>          > Øyvind
>          >
>          >
>          > 
>          > 
>          > -n
>          > 
>          >
>          > 
>          >
>          > instr 1
>          >    Snumbers = "1,2,3"
>          >    Snumbers strcat Snumbers, ","
>          >    kcomma strindexk Snumbers, ","
>          >    while kcomma > -1 do
>          >      Sval strsubk Snumbers, 0, kcomma
>          >      kval strtodk Sval
>          >      printk2 kval, 10
>          >      Snumbers strsubk Snumbers, kcomma+1, -1
>          >      kcomma strindexk Snumbers, ","
>          >    od
>          > endin
>          >
>          > instr 2
>          >    Snumbers = "1,2,3"
>          >    Snumbers strcat Snumbers, ","
>          >    icomma strindex Snumbers, ","
>          >    while icomma > -1 do
>          >      Sval strsub Snumbers, 0, icomma
>          >      ival strtod Sval
>          >      print ival
>          >      Snumbers strsub Snumbers, icomma+1, -1
>          >      icomma strindex Snumbers, ","
>          >    od
>          > endin
>          >
>          > 
>          > 
>          > i1 0 .1
>          > i1 1 .1
>          >
>          > ;i2 2 .1
>          > ;i2 3 .1
>          >
>          > 
>          > 
>          >
>          > 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-12-15 22:41
FromPete Goodeve
SubjectRe: [Csnd] Odd string problem
AttachmentsNone  

Date2021-12-16 14:05
FromOeyvind Brandtsegg
SubjectRe: [Csnd] Odd string problem
Oh, good catch. Thanks for looking into the details of my code. And thanks for the workaround. 
op, if I need to insert an i-rate string into this, I could make that work with
'''
  Sinput = "1,2,3"
  Snumbers strcpyk Sinput
  ... and so on, rest of the instr like you wrote it
'''

It looks like this is an oddity that could trip up many users (don't you think?). Especially since the relation between i- and k-rate for string variables seems to work differently than one would experience with regular numeric i- and k-variables. I have posted an issue at github about it, and hope the community agrees that it would be more clear if this oddity did not occur.

Thanks and best
Øyvind

ons. 15. des. 2021 kl. 22:17 skrev joachim heintz <jh@joachimheintz.de>:
hi oeyvind -

you are right; this is not the same as the case which i thought it was.
  (i had no time to look closer this afternoon and just reacted to your
desription.)

now i had a closer look and i think the problem is that in your code you
mix i- and k-rate.  when you go consequently to k-rate, it works for me:

instr 1
   Snumbers strcpyk "1,2,3"
   Snumbers strcatk Snumbers, ","
   kcomma strindexk Snumbers, ","
   while kcomma > -1 do
     Sval strsubk Snumbers, 0, kcomma
     kval strtodk Sval
     printk2 kval, 10
     Snumbers strsubk Snumbers, kcomma+1, -1
     kcomma strindexk Snumbers, ","
   od
   turnoff
endin

ciao -
        joachim



On 15/12/2021 18:38, Oeyvind Brandtsegg wrote:
> Oh I see now what you meant. The link sent me to the top of the page
> first, so I checked again scrolling down to the section about multiple
> passes. But is still don't see how it applies to the code I sent. Could
> you be so kind to explain it in terms of my example code?
>
> ons. 15. des. 2021, 6:09 p.m. skrev Oeyvind Brandtsegg
> <obrandts@gmail.com <mailto:obrandts@gmail.com>>:
>
>     Hi Joachim
>     I think it is a different case. The issue is that the instrument
>     produce different output the second time it is initialized. I would
>     not expect such behavior in any case where all variables are local
>     to the instrument instance.
>
>     All best
>     Øyvind
>
>     ons. 15. des. 2021, 4:31 p.m. skrev joachim heintz
>     <jh@joachimheintz.de <mailto:jh@joachimheintz.de>>:
>
>         hi oeyvind -
>
>         i think this is expected behaviour.  i wrote about it in
>         https://flossmanual.csound.com/csound-language/initialization-and-performance-pass#k-values-and-initialization-in-multiple-triggered-instruments
>         <https://flossmanual.csound.com/csound-language/initialization-and-performance-pass#k-values-and-initialization-in-multiple-triggered-instruments>
>
>         or is this a different case?
>
>         cheers -
>                  joachim
>
>
>         On 15/12/2021 11:14, Oeyvind Brandtsegg wrote:
>          > Hi,
>          > I am trying to parse comma separated numbers in a string (as
>         to send
>          > them one by one to another process). Something odd is
>         happening so that
>          > my instrument works correctly the first time it starts, but
>         then when it
>          > is started again the first item of the string is not
>         converted to a number.
>          >
>          > It might look like some k-rate string opcodes somehow retain
>         their state
>          > from previous initializations (??)
>          >
>          > The csd below shows the problem. Running instr 1 should print
>         the
>          > numbers in the string one by one. This happens correctly the
>         first time
>          > the instrument runs, but it only prints 2 and 3 the second
>         time the
>          > instrument runs.
>          >
>          > As a test I have recreated the same procedure with i-time
>         string opcodes
>          > in instr 2. This works every time. Sadly, I do need to make
>         it work at
>          > k-rate...
>          >
>          > All best
>          > Øyvind
>          >
>          >
>          > <CsoundSynthesizer>
>          > <CsOptions>
>          > -n
>          > </CsOptions>
>          >
>          > <CsInstruments>
>          >
>          > instr 1
>          >    Snumbers = "1,2,3"
>          >    Snumbers strcat Snumbers, ","
>          >    kcomma strindexk Snumbers, ","
>          >    while kcomma > -1 do
>          >      Sval strsubk Snumbers, 0, kcomma
>          >      kval strtodk Sval
>          >      printk2 kval, 10
>          >      Snumbers strsubk Snumbers, kcomma+1, -1
>          >      kcomma strindexk Snumbers, ","
>          >    od
>          > endin
>          >
>          > instr 2
>          >    Snumbers = "1,2,3"
>          >    Snumbers strcat Snumbers, ","
>          >    icomma strindex Snumbers, ","
>          >    while icomma > -1 do
>          >      Sval strsub Snumbers, 0, icomma
>          >      ival strtod Sval
>          >      print ival
>          >      Snumbers strsub Snumbers, icomma+1, -1
>          >      icomma strindex Snumbers, ","
>          >    od
>          > endin
>          >
>          > </CsInstruments>
>          > <CsScore>
>          > i1 0 .1
>          > i1 1 .1
>          >
>          > ;i2 2 .1
>          > ;i2 3 .1
>          >
>          > </CsScore>
>          > </CsoundSynthesizer>
>          >
>          > Csound mailing list Csound@listserv.heanet.ie
>         <mailto:Csound@listserv.heanet.ie>
>          > <mailto:Csound@listserv.heanet.ie
>         <mailto:Csound@listserv.heanet.ie>>
>          > https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>         <https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND>
>          > <https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>         <https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND>> Send bugs
>         reports to
>          > https://github.com/csound/csound/issues
>         <https://github.com/csound/csound/issues>
>          > <https://github.com/csound/csound/issues
>         <https://github.com/csound/csound/issues>> Discussions of bugs and
>          > features can be posted here
>
>         Csound mailing list
>         Csound@listserv.heanet.ie <mailto:Csound@listserv.heanet.ie>
>         https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>         <https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND>
>         Send bugs reports to
>         https://github.com/csound/csound/issues
>         <https://github.com/csound/csound/issues>
>         Discussions of bugs and features can be posted here
>
> Csound mailing list Csound@listserv.heanet.ie
> <mailto:Csound@listserv.heanet.ie>
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> <https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND> Send bugs reports to
> https://github.com/csound/csound/issues
> <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-12-16 21:45
Fromjoachim heintz
SubjectRe: [Csnd] Odd string problem
yes i think, too =)

On 16/12/2021 15:05, Oeyvind Brandtsegg wrote:
> Oh, good catch. Thanks for looking into the details of my code. And 
> thanks for the workaround.
> op, if I need to insert an i-rate string into this, I could make that 
> work with
> '''
>    Sinput = "1,2,3"
>    Snumbers strcpyk Sinput
>    ... and so on, rest of the instr like you wrote it
> '''
> 
> It looks like this is an oddity that could trip up many users (don't you 
> think?). Especially since the relation between i- and k-rate for string 
> variables seems to work differently than one would experience with 
> regular numeric i- and k-variables. I have posted an issue at github 
> about it, and hope the community agrees that it would be more clear if 
> this oddity did not occur.
> 
> Thanks and best
> Øyvind
> 
> ons. 15. des. 2021 kl. 22:17 skrev joachim heintz  >:
> 
>     hi oeyvind -
> 
>     you are right; this is not the same as the case which i thought it was.
>        (i had no time to look closer this afternoon and just reacted to
>     your
>     desription.)
> 
>     now i had a closer look and i think the problem is that in your code
>     you
>     mix i- and k-rate.  when you go consequently to k-rate, it works for me:
> 
>     instr 1
>         Snumbers strcpyk "1,2,3"
>         Snumbers strcatk Snumbers, ","
>         kcomma strindexk Snumbers, ","
>         while kcomma > -1 do
>           Sval strsubk Snumbers, 0, kcomma
>           kval strtodk Sval
>           printk2 kval, 10
>           Snumbers strsubk Snumbers, kcomma+1, -1
>           kcomma strindexk Snumbers, ","
>         od
>         turnoff
>     endin
> 
>     ciao -
>              joachim
> 
> 
> 
>     On 15/12/2021 18:38, Oeyvind Brandtsegg wrote:
>      > Oh I see now what you meant. The link sent me to the top of the page
>      > first, so I checked again scrolling down to the section about
>     multiple
>      > passes. But is still don't see how it applies to the code I sent.
>     Could
>      > you be so kind to explain it in terms of my example code?
>      >
>      > ons. 15. des. 2021, 6:09 p.m. skrev Oeyvind Brandtsegg
>      > 
>     >>:
>      >
>      >     Hi Joachim
>      >     I think it is a different case. The issue is that the instrument
>      >     produce different output the second time it is initialized. I
>     would
>      >     not expect such behavior in any case where all variables are
>     local
>      >     to the instrument instance.
>      >
>      >     All best
>      >     Øyvind
>      >
>      >     ons. 15. des. 2021, 4:31 p.m. skrev joachim heintz
>      >     
>     >>:
>      >
>      >         hi oeyvind -
>      >
>      >         i think this is expected behaviour.  i wrote about it in
>      >
>     https://flossmanual.csound.com/csound-language/initialization-and-performance-pass#k-values-and-initialization-in-multiple-triggered-instruments
>     
>      >       
>       >
>      >
>      >         or is this a different case?
>      >
>      >         cheers -
>      >                  joachim
>      >
>      >
>      >         On 15/12/2021 11:14, Oeyvind Brandtsegg wrote:
>      >          > Hi,
>      >          > I am trying to parse comma separated numbers in a
>     string (as
>      >         to send
>      >          > them one by one to another process). Something odd is
>      >         happening so that
>      >          > my instrument works correctly the first time it
>     starts, but
>      >         then when it
>      >          > is started again the first item of the string is not
>      >         converted to a number.
>      >          >
>      >          > It might look like some k-rate string opcodes somehow
>     retain
>      >         their state
>      >          > from previous initializations (??)
>      >          >
>      >          > The csd below shows the problem. Running instr 1
>     should print
>      >         the
>      >          > numbers in the string one by one. This happens
>     correctly the
>      >         first time
>      >          > the instrument runs, but it only prints 2 and 3 the second
>      >         time the
>      >          > instrument runs.
>      >          >
>      >          > As a test I have recreated the same procedure with i-time
>      >         string opcodes
>      >          > in instr 2. This works every time. Sadly, I do need to
>     make
>      >         it work at
>      >          > k-rate...
>      >          >
>      >          > All best
>      >          > Øyvind
>      >          >
>      >          >
>      >          > 
>      >          > 
>      >          > -n
>      >          > 
>      >          >
>      >          > 
>      >          >
>      >          > instr 1
>      >          >    Snumbers = "1,2,3"
>      >          >    Snumbers strcat Snumbers, ","
>      >          >    kcomma strindexk Snumbers, ","
>      >          >    while kcomma > -1 do
>      >          >      Sval strsubk Snumbers, 0, kcomma
>      >          >      kval strtodk Sval
>      >          >      printk2 kval, 10
>      >          >      Snumbers strsubk Snumbers, kcomma+1, -1
>      >          >      kcomma strindexk Snumbers, ","
>      >          >    od
>      >          > endin
>      >          >
>      >          > instr 2
>      >          >    Snumbers = "1,2,3"
>      >          >    Snumbers strcat Snumbers, ","
>      >          >    icomma strindex Snumbers, ","
>      >          >    while icomma > -1 do
>      >          >      Sval strsub Snumbers, 0, icomma
>      >          >      ival strtod Sval
>      >          >      print ival
>      >          >      Snumbers strsub Snumbers, icomma+1, -1
>      >          >      icomma strindex Snumbers, ","
>      >          >    od
>      >          > endin
>      >          >
>      >          > 
>      >          > 
>      >          > i1 0 .1
>      >          > i1 1 .1
>      >          >
>      >          > ;i2 2 .1
>      >          > ;i2 3 .1
>      >          >
>      >          > 
>      >          > 
>      >          >
>      >          > 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
> 
> 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