if-then-else expression in [expr] and [codebox]?
I know there are other solutions, but is there an if-then-else or equivalent in Gen’s [expr] and [codebox]?
I seem to remember a statement that there was, but now can’t find any documentation.
Best wishes, Charles
have a look here, the same applies to expr inside gen: http://cycling74.com/forums/topic.php?id=38012
about codebox, i haven’t tried yet but i understood it takes C code so i guess if/then/else statements should work: http://cycling74.com/2011/12/12/week-47-waveshaping-with-gen/
no, codebox doesn’t take if, then, else, for, etc. but apparently it will one day.
in gen and codebox i assign first and use [switch]:
x = w ? y : z;
or [selector] or [gate] (same as max land).
tanx for pointing that out!
Thanks for pointing all this out.
I was sitting with a similar problem the last days, missing if-else, it looks like there is an example of how to get around it,using ? operator within codebox,, needing extra lines of code, intermittent variables
its about pd filters realized in gen
a bit down the page, porting c code to gen, >>stkr< < writes himself : (looks ridiculous - getting around GenExpr limitations)
Well, [gen~] is a synchronous language. Just because it has a C-like syntax…
Someone could prove me wrong, but I think it has to do with preserving state across time spent in the rendering loop. Currently with [gen~] everything is forgotten when the audio interrupt is exited. There are exceptions at the object level, like [sah].
But if conditionals have got your nose twisted, try anything that changes the flow of time, like a "for" or "while" loop!
greetings and just IF more people follow this if-else ? discussion THEN this tiny simple example is working, its doing C*sin(x) where C is variable parameter and x is fed back in the loop and trig is a running sample counter input, so that there will only be a new output every so many samples.
x = in1;
c = in2;
trig = in3;
xout = (trig == 1) ? c * (sin (x)) : x;
out1 = xout;
here on my babysocks in the code landscapes i hope that in this way there is some some cpu saving in the sense that the csinx calculation is only done IF trig==1.. for more complex algorithms this would matter i bet.