Csound Csound-dev Csound-tekno Search About

[Csnd] strange things with strings

Date2020-11-23 12:30
FromRichard
Subject[Csnd] strange things with strings
I have this piece of code:

if (kgm==1) then
     ;printks "in if...%s",1, Spath
     Sbank strsubk Spath, 7, 9
     Spres strsubk Spath, 18, 23
     printks "bank:%s, preset:%s",1, Sbank, Spres
     klen strlenk Sbank
     printk2 klen
     if (klen>0) then
         kbank strtodk Sbank  ;<= here the output says: empty string
         kpres strtodk Spres
         printks "bank:%f, preset:%f",1, kbank, kpres
     endif

endif


See the commented line, csound output gives an error about Sbank being 
an empty string

But this is what I try to avoid by the if (klen>0) construction! It 
looks like the code is already executed??

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

Date2020-11-23 13:51
Fromandy fillebrown
SubjectRe: [Csnd] strange things with strings
Try skipping over it at i-time or initializing it to a non-empty string at i-time.


On Mon, Nov 23, 2020 at 7:30 AM Richard <zappfinger@gmail.com> wrote:
I have this piece of code:

if (kgm==1) then
     ;printks "in if...%s",1, Spath
     Sbank strsubk Spath, 7, 9
     Spres strsubk Spath, 18, 23
     printks "bank:%s, preset:%s",1, Sbank, Spres
     klen strlenk Sbank
     printk2 klen
     if (klen>0) then
         kbank strtodk Sbank  ;<= here the output says: empty string
         kpres strtodk Spres
         printks "bank:%f, preset:%f",1, kbank, kpres
     endif

endif


See the commented line, csound output gives an error about Sbank being
an empty string

But this is what I try to avoid by the if (klen>0) construction! It
looks like the code is already executed??

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

Date2020-11-23 21:45
FromRichard
SubjectRe: [Csnd] strange things with strings

I would not know how to skip at i-time, but initializing the string does not work: I get the same error message.

Here's the code:

instr 11
Spath chnget "GM"
printks "now.....%s",1,Spath    ;when this line is commented out, the change shows the previous value!
kgm changed Spath
printk2 kgm
if (kgm==1) then
    Sbank = "0"        ;<= initialized here
    ;printks "in if...%s",1, Spath
    Sbank strsubk Spath, 7, 9
    Spres strsubk Spath, 18, 23
    printks "bank:%s, preset:%s",1, Sbank, Spres
    klen strlenk Sbank
    printk2 klen    ;<= nothing is printed here
    if (klen>0) then
        kbank strtodk Sbank     ;<= error about empty string here
        kpres strtodk Spres
        printks "bank:%f, preset:%f",1, kbank, kpres
    endif
   
endif
endin

On 23/11/2020 14:51, andy fillebrown wrote:
Try skipping over it at i-time or initializing it to a non-empty string at i-time.


On Mon, Nov 23, 2020 at 7:30 AM Richard <zappfinger@gmail.com> wrote:
I have this piece of code:

if (kgm==1) then
     ;printks "in if...%s",1, Spath
     Sbank strsubk Spath, 7, 9
     Spres strsubk Spath, 18, 23
     printks "bank:%s, preset:%s",1, Sbank, Spres
     klen strlenk Sbank
     printk2 klen
     if (klen>0) then
         kbank strtodk Sbank  ;<= here the output says: empty string
         kpres strtodk Spres
         printks "bank:%f, preset:%f",1, kbank, kpres
     endif

endif


See the commented line, csound output gives an error about Sbank being
an empty string

But this is what I try to avoid by the if (klen>0) construction! It
looks like the code is already executed??

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

Date2020-11-23 21:50
Fromjohn
SubjectRe: [Csnd] strange things with strings
= is not i-time initialisatio; init is for that.

Not sure if that is yur problem though. A complete csd would e so much 
easier to see what if happening by reading the actual compiled code.


On Mon, 23 Nov 2020, Richard wrote:

> 
> I would not know how to skip at i-time, but initializing the string does not
> work: I get the same error message.
> 
> Here's the code:
> 
> instr 11
> Spath chnget "GM"
> printks "now.....%s",1,Spath    ;when this line is commented out, the change
> shows the previous value!
> kgm changed Spath
> printk2 kgm
> if (kgm==1) then
>     Sbank = "0"        ;<= initialized here
>     ;printks "in if...%s",1, Spath
>     Sbank strsubk Spath, 7, 9
>     Spres strsubk Spath, 18, 23
>     printks "bank:%s, preset:%s",1, Sbank, Spres
>     klen strlenk Sbank
>     printk2 klen    ;<= nothing is printed here
>     if (klen>0) then
>         kbank strtodk Sbank     ;<= error about empty string here
>         kpres strtodk Spres
>         printks "bank:%f, preset:%f",1, kbank, kpres
>     endif
>    
> endif
> endin
> 
> On 23/11/2020 14:51, andy fillebrown wrote:
>       Try skipping over it at i-time or initializing it to a non-empty
>       string at i-time.
> 
> 
> On Mon, Nov 23, 2020 at 7:30 AM Richard  wrote:
>       I have this piece of code:
>
>       if (kgm==1) then
>            ;printks "in if...%s",1, Spath
>            Sbank strsubk Spath, 7, 9
>            Spres strsubk Spath, 18, 23
>            printks "bank:%s, preset:%s",1, Sbank, Spres
>            klen strlenk Sbank
>            printk2 klen
>            if (klen>0) then
>                kbank strtodk Sbank  ;<= here the output says:
>       empty string
>                kpres strtodk Spres
>                printks "bank:%f, preset:%f",1, kbank, kpres
>            endif
>
>       endif
> 
>
>       See the commented line, csound output gives an error about
>       Sbank being
>       an empty string
>
>       But this is what I try to avoid by the if (klen>0)
>       construction! It
>       looks like the code is already executed??
>
>       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

Date2020-11-23 22:04
FromRichard
SubjectRe: [Csnd] strange things with strings
I also tried init.

But you are right, a csd is needed.

Here it is:




On 23/11/2020 22:50, john wrote:
> = is not i-time initialisatio; init is for that.
>
> Not sure if that is yur problem though. A complete csd would e so much 
> easier to see what if happening by reading the actual compiled code.
>
>
> On Mon, 23 Nov 2020, Richard wrote:
>
>>
>> I would not know how to skip at i-time, but initializing the string 
>> does not
>> work: I get the same error message.
>>
>> Here's the code:
>>
>> instr 11
>> Spath chnget "GM"
>> printks "now.....%s",1,Spath    ;when this line is commented out, the 
>> change
>> shows the previous value!
>> kgm changed Spath
>> printk2 kgm
>> if (kgm==1) then
>>     Sbank = "0"        ;<= initialized here
>>     ;printks "in if...%s",1, Spath
>>     Sbank strsubk Spath, 7, 9
>>     Spres strsubk Spath, 18, 23
>>     printks "bank:%s, preset:%s",1, Sbank, Spres
>>     klen strlenk Sbank
>>     printk2 klen    ;<= nothing is printed here
>>     if (klen>0) then
>>         kbank strtodk Sbank     ;<= error about empty string here
>>         kpres strtodk Spres
>>         printks "bank:%f, preset:%f",1, kbank, kpres
>>     endif
>>
>> endif
>> endin
>>
>> On 23/11/2020 14:51, andy fillebrown wrote:
>>       Try skipping over it at i-time or initializing it to a non-empty
>>       string at i-time.
>>
>>
>> On Mon, Nov 23, 2020 at 7:30 AM Richard  wrote:
>>       I have this piece of code:
>>
>>       if (kgm==1) then
>>            ;printks "in if...%s",1, Spath
>>            Sbank strsubk Spath, 7, 9
>>            Spres strsubk Spath, 18, 23
>>            printks "bank:%s, preset:%s",1, Sbank, Spres
>>            klen strlenk Sbank
>>            printk2 klen
>>            if (klen>0) then
>>                kbank strtodk Sbank  ;<= here the output says:
>>       empty string
>>                kpres strtodk Spres
>>                printks "bank:%f, preset:%f",1, kbank, kpres
>>            endif
>>
>>       endif
>>
>>
>>       See the commented line, csound output gives an error about
>>       Sbank being
>>       an empty string
>>
>>       But this is what I try to avoid by the if (klen>0)
>>       construction! It
>>       looks like the code is already executed??
>>
>>       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

Date2020-11-23 22:06
FromRichard
SubjectRe: [Csnd] strange things with strings
AttachmentsGM_test.txt  chnget.csd  
Sorry, sent too soon.

Here is the csd and the text file


On 23/11/2020 22:50, john wrote:
> = is not i-time initialisatio; init is for that.
>
> Not sure if that is yur problem though. A complete csd would e so much 
> easier to see what if happening by reading the actual compiled code.
>
>
> On Mon, 23 Nov 2020, Richard wrote:
>
>>
>> I would not know how to skip at i-time, but initializing the string 
>> does not
>> work: I get the same error message.
>>
>> Here's the code:
>>
>> instr 11
>> Spath chnget "GM"
>> printks "now.....%s",1,Spath    ;when this line is commented out, the 
>> change
>> shows the previous value!
>> kgm changed Spath
>> printk2 kgm
>> if (kgm==1) then
>>     Sbank = "0"        ;<= initialized here
>>     ;printks "in if...%s",1, Spath
>>     Sbank strsubk Spath, 7, 9
>>     Spres strsubk Spath, 18, 23
>>     printks "bank:%s, preset:%s",1, Sbank, Spres
>>     klen strlenk Sbank
>>     printk2 klen    ;<= nothing is printed here
>>     if (klen>0) then
>>         kbank strtodk Sbank     ;<= error about empty string here
>>         kpres strtodk Spres
>>         printks "bank:%f, preset:%f",1, kbank, kpres
>>     endif
>>
>> endif
>> endin
>>
>> On 23/11/2020 14:51, andy fillebrown wrote:
>>       Try skipping over it at i-time or initializing it to a non-empty
>>       string at i-time.
>>
>>
>> On Mon, Nov 23, 2020 at 7:30 AM Richard  wrote:
>>       I have this piece of code:
>>
>>       if (kgm==1) then
>>            ;printks "in if...%s",1, Spath
>>            Sbank strsubk Spath, 7, 9
>>            Spres strsubk Spath, 18, 23
>>            printks "bank:%s, preset:%s",1, Sbank, Spres
>>            klen strlenk Sbank
>>            printk2 klen
>>            if (klen>0) then
>>                kbank strtodk Sbank  ;<= here the output says:
>>       empty string
>>                kpres strtodk Spres
>>                printks "bank:%f, preset:%f",1, kbank, kpres
>>            endif
>>
>>       endif
>>
>>
>>       See the commented line, csound output gives an error about
>>       Sbank being
>>       an empty string
>>
>>       But this is what I try to avoid by the if (klen>0)
>>       construction! It
>>       looks like the code is already executed??
>>
>>       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

Date2020-11-24 21:43
Fromjohn
SubjectRe: [Csnd] strange things with strings
I fiddled with your program a bit as I do not have cabbage or the sf file 
you use but the problem is in instr 11 were you use strtodk which runs at 
both i-time and k-rate.  But Sbank is not given a value at init time only 
on each k-cycle.

Thisis because strsubk is also run at i- and k-time so as the range given 
is ourside the blank string of Spath,  Sbank is set to an empty string.

Many string operations run at both times which often causes problems

==John ff

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