[Csnd] Detecting string change

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[Csnd] Detecting string change

zappfinger
I am using the following code:

instr 11
Sgm chnget "GM"
kgm changed Sgm
printk2 kgm
if (kgm==1) then
     prints "%s", Sgm
endif
endin

When the string changes the output shows that kgm becomes 1, but
immediately becomes 0 again.
Printing of the string in the if block is not executed.

Why?

Csound mailing list
[hidden email]
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
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] Detecting string change

Dave Seidel
I think because you're using prints, which is I-rate, but it's a k-rate if statement. Try using prints. 

On Sun, Nov 22, 2020, 8:59 AM Richard <[hidden email]> wrote:
I am using the following code:

instr 11
Sgm chnget "GM"
kgm changed Sgm
printk2 kgm
if (kgm==1) then
     prints "%s", Sgm
endif
endin

When the string changes the output shows that kgm becomes 1, but
immediately becomes 0 again.
Printing of the string in the if block is not executed.

Why?

Csound mailing list
[hidden email]
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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] Detecting string change

zappfinger

Yes of course. I am using printks now and that works.
Well in this case it actually lags one behind. The string that is printed is actually the previous selection.
Have to find out why...

BTW, it would be nice if printks could also accept -1 for the itime, indicating that it only prints one time...

On 22/11/2020 15:16, Dave Seidel wrote:
I think because you're using prints, which is I-rate, but it's a k-rate if statement. Try using prints. 

On Sun, Nov 22, 2020, 8:59 AM Richard <[hidden email]> wrote:
I am using the following code:

instr 11
Sgm chnget "GM"
kgm changed Sgm
printk2 kgm
if (kgm==1) then
     prints "%s", Sgm
endif
endin

When the string changes the output shows that kgm becomes 1, but
immediately becomes 0 again.
Printing of the string in the if block is not executed.

Why?

Csound mailing list
[hidden email]
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 [hidden email] 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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] Detecting string change

zappfinger
In reply to this post by Dave Seidel

It only works correctly if I put a delay after the chnget other wise the previous value is printed. It looks like the change after the chnget comes too soon.
Following code works:

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
    printks "in if...%s",1, Spath
endif
endin

On 22/11/2020 15:16, Dave Seidel wrote:
I think because you're using prints, which is I-rate, but it's a k-rate if statement. Try using prints. 

On Sun, Nov 22, 2020, 8:59 AM Richard <[hidden email]> wrote:
I am using the following code:

instr 11
Sgm chnget "GM"
kgm changed Sgm
printk2 kgm
if (kgm==1) then
     prints "%s", Sgm
endif
endin

When the string changes the output shows that kgm becomes 1, but
immediately becomes 0 again.
Printing of the string in the if block is not executed.

Why?

Csound mailing list
[hidden email]
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 [hidden email] 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 [hidden email] 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