Csound Csound-dev Csound-tekno Search About

apparent problems with if-then-elseif structure

Date2016-01-14 16:50
FromKarin Daum
Subjectapparent problems with if-then-elseif structure
I'm still investigating the performance of the different multichannel panning methods. For this purpose I'm just writing a program which allows me also to visualise the behaviour of the different methods. This is my first program in Csound. Now I realise that something goes wrong with the if-then-else(if) structure in Csound. Below you find a simple test program which shows the effect:

 
 	
 
 		
sr = 44100 		
ksmps = 128 	
nchnls = 2 		
0dbfs = 1 			
gkMethod	init 0

instr 1 			
	printf "Method: %d \n",1,gkMethod
if gkMethod== 0 then
	iInst1 = 12
	iInst2 = 0
elseif gkMethod == 1 then
	giorder = 1
	iInst1 = 10
	iInst2 = 11
else
	iInst1 = 20
	iInst2 = 21
endif
	print iInst1, iInst2
endin
 		
 			
i 1 0 1
e
 

I would expect that the code between then-else or else-endif is executed only if the corresponding condition is true which means in this example I would expect as result iInst1=12 and iInst2=0 however the result with both, CsoundQt and Csound is:

new alloc for instr 1:
instr 1:  iInst1 = 20.000  iInst2 = 21.000
Method: 0 

Or did I miss something?

cheers,

Karin

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

Date2016-01-14 17:02
FromRory Walsh
SubjectRe: apparent problems with if-then-elseif structure

On 14 January 2016 at 16:50, Karin Daum <karin.daum@desy.de> wrote:
I'm still investigating the performance of the different multichannel panning methods. For this purpose I'm just writing a program which allows me also to visualise the behaviour of the different methods. This is my first program in Csound. Now I realise that something goes wrong with the if-then-else(if) structure in Csound. Below you find a simple test program which shows the effect:

<CsoundSynthesizer>
<CsOptions>
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1
gkMethod        init 0

instr 1
        printf "Method: %d \n",1,gkMethod
if gkMethod== 0 then
        iInst1 = 12
        iInst2 = 0
elseif gkMethod == 1 then
        giorder = 1
        iInst1 = 10
        iInst2 = 11
else
        iInst1 = 20
        iInst2 = 21
endif
        print iInst1, iInst2
endin
</CsInstruments>
<CsScore>
i 1 0 1
e
</CsScore>

I would expect that the code between then-else or else-endif is executed only if the corresponding condition is true which means in this example I would expect as result iInst1=12 and iInst2=0 however the result with both, CsoundQt and Csound is:

new alloc for instr 1:
instr 1:  iInst1 = 20.000  iInst2 = 21.000
Method: 0

Or did I miss something?

cheers,

Karin

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

Date2016-01-14 17:02
FromSteven Yi
SubjectRe: apparent problems with if-then-elseif structure
if-then's can be tricky in csound due to rates. The issue here I see
is that you are doing a k-rate comparison but also have I-time code.
I would suggest doing something like:

imethod = i(gkMethod)

if imethod == 1 then
elseif ...
else...
endif

Typically it's best to always match up the rate of the conditions to
each other and to the code within the branches.

On Thu, Jan 14, 2016 at 11:50 AM, Karin Daum  wrote:
> I'm still investigating the performance of the different multichannel panning methods. For this purpose I'm just writing a program which allows me also to visualise the behaviour of the different methods. This is my first program in Csound. Now I realise that something goes wrong with the if-then-else(if) structure in Csound. Below you find a simple test program which shows the effect:
>
> 
> 
> 
> 
> sr = 44100
> ksmps = 128
> nchnls = 2
> 0dbfs = 1
> gkMethod        init 0
>
> instr 1
>         printf "Method: %d \n",1,gkMethod
> if gkMethod== 0 then
>         iInst1 = 12
>         iInst2 = 0
> elseif gkMethod == 1 then
>         giorder = 1
>         iInst1 = 10
>         iInst2 = 11
> else
>         iInst1 = 20
>         iInst2 = 21
> endif
>         print iInst1, iInst2
> endin
> 
> 
> i 1 0 1
> e
> 
>
> I would expect that the code between then-else or else-endif is executed only if the corresponding condition is true which means in this example I would expect as result iInst1=12 and iInst2=0 however the result with both, CsoundQt and Csound is:
>
> new alloc for instr 1:
> instr 1:  iInst1 = 20.000  iInst2 = 21.000
> Method: 0
>
> Or did I miss something?
>
> cheers,
>
> Karin
>
> 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

Date2016-01-14 17:03
FromRory Walsh
SubjectRe: apparent problems with if-then-elseif structure
You can skip my post and just read Istvan's answer. 

On 14 January 2016 at 17:02, Rory Walsh <rorywalsh@ear.ie> wrote:

On 14 January 2016 at 16:50, Karin Daum <karin.daum@desy.de> wrote:
I'm still investigating the performance of the different multichannel panning methods. For this purpose I'm just writing a program which allows me also to visualise the behaviour of the different methods. This is my first program in Csound. Now I realise that something goes wrong with the if-then-else(if) structure in Csound. Below you find a simple test program which shows the effect:

<CsoundSynthesizer>
<CsOptions>
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1
gkMethod        init 0

instr 1
        printf "Method: %d \n",1,gkMethod
if gkMethod== 0 then
        iInst1 = 12
        iInst2 = 0
elseif gkMethod == 1 then
        giorder = 1
        iInst1 = 10
        iInst2 = 11
else
        iInst1 = 20
        iInst2 = 21
endif
        print iInst1, iInst2
endin
</CsInstruments>
<CsScore>
i 1 0 1
e
</CsScore>

I would expect that the code between then-else or else-endif is executed only if the corresponding condition is true which means in this example I would expect as result iInst1=12 and iInst2=0 however the result with both, CsoundQt and Csound is:

new alloc for instr 1:
instr 1:  iInst1 = 20.000  iInst2 = 21.000
Method: 0

Or did I miss something?

cheers,

Karin

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

Date2016-01-14 17:32
FromKarin Daum
SubjectRe: apparent problems with if-then-elseif structure
thanks, it’s really tricky when starting with Csound with these different rate
On 14 Jan 2016, at 18:03, Rory Walsh <rorywalsh@EAR.IE> wrote:

You can skip my post and just read Istvan's answer. 

On 14 January 2016 at 17:02, Rory Walsh <rorywalsh@ear.ie> wrote:

On 14 January 2016 at 16:50, Karin Daum <karin.daum@desy.de> wrote:
I'm still investigating the performance of the different multichannel panning methods. For this purpose I'm just writing a program which allows me also to visualise the behaviour of the different methods. This is my first program in Csound. Now I realise that something goes wrong with the if-then-else(if) structure in Csound. Below you find a simple test program which shows the effect:

<CsoundSynthesizer>
<CsOptions>
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1
gkMethod        init 0

instr 1
        printf "Method: %d \n",1,gkMethod
if gkMethod== 0 then
        iInst1 = 12
        iInst2 = 0
elseif gkMethod == 1 then
        giorder = 1
        iInst1 = 10
        iInst2 = 11
else
        iInst1 = 20
        iInst2 = 21
endif
        print iInst1, iInst2
endin
</CsInstruments>
<CsScore>
i 1 0 1
e
</CsScore>

I would expect that the code between then-else or else-endif is executed only if the corresponding condition is true which means in this example I would expect as result iInst1=12 and iInst2=0 however the result with both, CsoundQt and Csound is:

new alloc for instr 1:
instr 1:  iInst1 = 20.000  iInst2 = 21.000
Method: 0

Or did I miss something?

cheers,

Karin

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


Date2016-01-14 18:06
FromRory Walsh
SubjectRe: apparent problems with if-then-elseif structure
Agreed! I'm still getting caught out with these things many years later ;)

On 14 January 2016 at 17:32, Karin Daum <karin.daum@desy.de> wrote:
thanks, it’s really tricky when starting with Csound with these different rate

On 14 Jan 2016, at 18:03, Rory Walsh <rorywalsh@EAR.IE> wrote:

You can skip my post and just read Istvan's answer. 

On 14 January 2016 at 17:02, Rory Walsh <rorywalsh@ear.ie> wrote:

On 14 January 2016 at 16:50, Karin Daum <karin.daum@desy.de> wrote:
I'm still investigating the performance of the different multichannel panning methods. For this purpose I'm just writing a program which allows me also to visualise the behaviour of the different methods. This is my first program in Csound. Now I realise that something goes wrong with the if-then-else(if) structure in Csound. Below you find a simple test program which shows the effect:

<CsoundSynthesizer>
<CsOptions>
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1
gkMethod        init 0

instr 1
        printf "Method: %d \n",1,gkMethod
if gkMethod== 0 then
        iInst1 = 12
        iInst2 = 0
elseif gkMethod == 1 then
        giorder = 1
        iInst1 = 10
        iInst2 = 11
else
        iInst1 = 20
        iInst2 = 21
endif
        print iInst1, iInst2
endin
</CsInstruments>
<CsScore>
i 1 0 1
e
</CsScore>

I would expect that the code between then-else or else-endif is executed only if the corresponding condition is true which means in this example I would expect as result iInst1=12 and iInst2=0 however the result with both, CsoundQt and Csound is:

new alloc for instr 1:
instr 1:  iInst1 = 20.000  iInst2 = 21.000
Method: 0

Or did I miss something?

cheers,

Karin

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