Csound Csound-dev Csound-tekno Search About

Re: if then problem

Date2006-05-05 11:58
FromIstvan Varga
SubjectRe: if then problem
AttachmentsNone  

Date2006-05-05 12:35
FromRory Walsh
Subjectif then problem
Can anyone spot the problem here. The 'if then' statement for ktest and 
ktest2 always returns true? No doubt it's something really stupid that I 
just can't see?


instr 2

Sname  strget  1
ichnls filenchnls Sname
ksearch chnget "skip"
ktrig changed ksearch
reset:
iskip = i(ksearch);
if(ktrig==0) then
goto contin
else
reinit reset
endif
contin:
         ktest = 1;
         ktest2 = 2;
         if ktest>ktest2 then
         print giflen
         event_i "e", 0, 0, 0.1
         endif
         if ichnls==2 then
         a1, a2 soundin Sname, iskip
         outs a1, a2
         elseif ichnls==1 then
         a1 soundin Sname, iskip
         outs a1, a1
         endif
         rireturn
endin

Date2006-05-05 13:25
FromRory Walsh
SubjectRe: if then problem
Thanks Istvan, that makes perfect sense.
Rory.

Istvan Varga wrote:
> On Friday 05 May 2006 13:35, Rory Walsh wrote:
> 
>> Can anyone spot the problem here. The 'if then' statement for ktest and 
>> ktest2 always returns true? No doubt it's something really stupid that I 
>> just can't see?
> 
> If you compare k-rate values, then the code for both the 'if' and 'else'
> branch always gets executed at i-time, because the result of the comparison
> is undefined at i-time. So, the flow of control just "falls through" any
> if/then/else with a k-rate condition at init time, to avoid the possibility
> of unexpected "not initialised" errors. If you want if/then/else to have
> any effect at i-time, compare i-rate values instead.