Csound Csound-dev Csound-tekno Search About

[Csnd] if ( p4 < 12 ) then go nuts

Date2005-09-25 21:13
Fromdigger vermont
Subject[Csnd] if ( p4 < 12 ) then go nuts
Attachmentscond-else.csd  cond-elseif.csd  
Hello all,
	I'm getting bogged down trying to get some conditional statements to
work.

the statement:

if ( p4 < 12 ) then
   print p4
else
   print p2
endif

goes to the else statement regardless of the result of ( p4 < 12 ).
Whereas using an elseif statement seems to work properly:

if ( p4 < 12 ) then
   print p4
elseif ( p4 >= 12 ) then
   print p2
endif

This seems to be the case for other tests I've tried ( =, >=, etc ) Is
there something I'm missing? or is this a bug?

I've attached two examples.

I using a freshly compiled cs5 from cvs.


Thanks for any help

digger

Date2005-09-25 22:50
From"Matt J. Ingalls"
SubjectRe: [Csnd] if ( p4 < 12 ) then go nuts

with if statements [ both if/then and if/goto ]
the rate of the variables in the conditional determines if it functions 
as an if-kgoto/if-then or an if-igoto/if-ithen

it turns out pfields are interpreted as k-rate variables!
and when you have a k-rate 'if', the if statement is essentially ignored 
at the irate in order to initialize anything for potential program breaks.

you might try to replace the 'then's with 'ithen's
or assign an ivar = p4 then do an 'if(ivar < p12) then'

-m

On Sun, 25 Sep 2005, digger vermont wrote:

> Hello all,
> 	I'm getting bogged down trying to get some conditional statements to
> work.
>
> the statement:
>
> if ( p4 < 12 ) then
>   print p4
> else
>   print p2
> endif
>
Ë> goes to the else statement regardless of the result of ( p4 < 12 ).
> Whereas using an elseif statement seems to work properly:
>
> if ( p4 < 12 ) then
>   print p4
> elseif ( p4 >= 12 ) then
Ë>   print p2
> endif
>
> This seems to be the case for other tests I've tried ( =, >=, etc ) Is
> there something I'm missing? or is this a bug?
>
> I've attached two examples.
>
> I using a freshly compiled cs5 from cvs.
>
>
> Thanks for any help
>
> digger
>
™
Ë
™
™

Date2005-09-26 04:41
Fromdigger vermont
SubjectRe: [Csnd] if ( p4 < 12 ) then go nuts
On Sun, 2005-09-25 at 14:50 -0700, Matt J. Ingalls wrote:
> 
> with if statements [ both if/then and if/goto ]
> the rate of the variables in the conditional determines if it functions 
> as an if-kgoto/if-then or an if-igoto/if-ithen
> 
> it turns out pfields are interpreted as k-rate variables!
> and when you have a k-rate 'if', the if statement is essentially ignored 
> at the irate in order to initialize anything for potential program breaks.
> 
> you might try to replace the 'then's with 'ithen's
> or assign an ivar = p4 then do an 'if(ivar < p12) then'
> 

Thanks for the help, Matt.  I tried using ivar's and it didn't make a
difference.

It looks like ithen works though.  I hadn't come across ithen in either
the online manual or "The "Csound Book"  Once again the mailing list
comes through.

Thanks again

digger  





> -m
> 
> On Sun, 25 Sep 2005, digger vermont wrote:
> 
> > Hello all,
> > 	I'm getting bogged down trying to get some conditional statements to
> > work.
> >
> > the statement:
> >
> > if ( p4 < 12 ) then
> >   print p4
> > else
> >   print p2
> > endif
> >
> Ë> goes to the else statement regardless of the result of ( p4 < 12 ).
> > Whereas using an elseif statement seems to work properly:
> >
> > if ( p4 < 12 ) then
> >   print p4
> > elseif ( p4 >= 12 ) then
> Ë>   print p2
> > endif
> >
> > This seems to be the case for other tests I've tried ( =, >=, etc ) Is
> > there something I'm missing? or is this a bug?
> >
> > I've attached two examples.
> >
> > I using a freshly compiled cs5 from cvs.
> >
> >
> > Thanks for any help
> >
> > digger
> >
> ™
> Ë
> ™
> ™

-- 
Send bugs reports to this list.
To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Date2005-09-26 16:39
FromAnthony Kozar
SubjectRe: [Csnd] if ( p4 < 12 ) then go nuts
Wouldn't this be a bug then?  pfields are treated as i-rate variables
everywhere else in the code.

Anthony Kozar
anthonykozar AT sbcglobal DOT net
http://akozar.spymac.net/


Matt J. Ingalls wrote on 9/25/05 5:50 PM:

> it turns out pfields are interpreted as k-rate variables!
> and when you have a k-rate 'if', the if statement is essentially ignored
> at the irate in order to initialize anything for potential program breaks.

-- 
Send bugs reports to this list.
To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

Date2005-09-27 05:33
FromMichael Rempel
SubjectRe: [Csnd] if ( p4 < 12 ) then go nuts
the Then part of the if code has been buggy in past. Then has a state
dependancy on the previous section of code. I think it should be explicitly
rate linked. For this reason I always use goto / igoto code, even though it
is less structured, it is guaranteed.

For beginners, there are two basic patterns I use. Here I am using irate
stuff, but this is applicable for any rate. It is best to make the rate
explicit since the various rates can get confusing if you dont say what you
mean at least in comments.

EITHER


if () igoto thisok
	
thisok:

OR

if () igoto thisAct
	
igoto thisok: thisAct: thisok: NOTE: the tests in each case are not the same. The first one does the default if the test is true, the second one does the alternate if the test is true. Most code is written so the 'normal' case goes first, and more rare cases go later. This tends to make things faster, but it is also good convention. It makes things easier to find. On another topic, if you want to make an effective list selector, the quickest way is not to do if x==1 then if x==2 then ... if x==n then it should be much faster when your if statements cut the size of the list in half each time. My example is for an N of 8, and all possibilities are integer numbers. If you follow each possibility though you will see that for each action we have 3 and only 3 if statements that get executed. It makes for a bit of compiler work, but it will execute fast once it is loaded. My msrOsc udo uses this pattern to decide what oscilator to generate. if x > 4 igoto test5 if x > 2 igoto test3 if x > 1 igoto test2 ;test1 igoto testdone test2: igoto testdone test3: if x > 3 igoto test4 igoto testdone test4: igoto testdone test5: if x > 6 igoto test7 if x > 5 igoto test6 igoto testdone test6: igoto testdone test7: if x > 7 igoto test8 igoto testdone test8: testdone: -- Send bugs reports to this list. To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk