SynthMaker

Questions on Code...

Archive · 2005 8 old posts

From the original SynthMaker forum (2004–2014), with its members’ names and dates.

Acolmiztli ·

When you write something like out = (x > xMustBeBiggerThan) & in; What are you basically saying in prose terms?

Is there any guide on the syntax and general usage of the code module yet?

infuzion ·

Yes, but I don't quite get the code thing yet, esp compairisons.

rl ·

The '&' operator is a logical AND

The comparison operator creates a mask:

so x < y is either 0 or 11111111111111111111111111111111 (bit-wise)

0 & x gives always 0 11111111111111111111111111111111 & x gives always x

if x > xMustBeBiggerThan we have out = 111....111 & in, so out = in if x <= xMustBeBiggerThan we have out = 0 & in, so out = 0

so basically the statement means:

if (x > xMustBeBiggerThan) out = in else out =0;

Acolmiztli ·

right.. so if a condition within the parenthesis is true, it performs the AND... if its false, what does it do? Does it just stop there and not perform the AND, or is the AND performed always?

unkargherth ·

If the condition it's false , you could consider there's "hidden" &0.

a=(a<=0.5)&1; /* This reads

if (a>=0.5) then a=1; else a=0; */

Obviously &0 means set something to ZERO, if you want something diferent try like this

a=(n<=0.5)&(2*a)+(n>0.5)&(0.95*a); /* This reads

if (n>=0.5) then a=2*a; else a=0.95*a; */

Be carefult at this point. The two conditions are complementary and exclusive: if first is true, second is false and reverse

Rellik ·

Acolmiztli wrote: right.. so if a condition within the parenthesis is true, it performs the AND... if its false, what does it do? Does it just stop there and not perform the AND, or is the AND performed always?

Nope, it doesn't stop. The code just keeps going - it always performs the AND. But the AND will have a different result depending on the result of "x > xMustBeGreaterThan". That is why there are two results for "out" - "out" is equal to "in" when "x > xMustBeGreaterThan" is true (the big 11111111111111 thing means it's true), since true AND "in" is "in" - and if "x > xMustBeGreaterThan" is false (0), then "out" is equal to "in" AND false, which is 0.

Shifrin ·

Just for reference you can chain together these (<comparison>)&... expressions, i.e. :-

x = (x < 0.5)&(x > 0.0)&(0.123*x);

Would be :-

if(x < 0.5 && X > 0.0) { x = 0.123*x; } else { x = 0; }

Shif.

Acolmiztli ·

can anyone say HEADACHE!!!

hehe. Thanks guys.

Wrote something here? To have a post removed or your name hidden, write to [email protected].

Before your first post

A few rules keep this a friendly place. You agree to them once.

Shown next to what you post, here and in the app. It doesn’t have to be your real name: 3–24 lower-case letters, digits or _ (capitals become lower case, spaces become _).

    Then your post goes up straight away.

    Delete this reply?

    Open it in SynthMaker?

    It goes on the track you’re editing there, in place of that track’s sound, and into My sounds. Your other tracks stay as they are.

    Want to keep that track’s sound? Start a new song in SynthMaker first (Song › New song), then open this.

    Report this reply?

    Only the developer reads reports. The person isn’t told who reported them.

    What’s wrong with it?

    Block this person?

    You won’t see their posts and replies here any more. They aren’t told, and you can unblock them at any time.

    People you’ve blocked

    Their posts and replies are hidden from you. Unblock someone to see them again.

    The community rules

    A few rules keep this a friendly place. Everyone agrees to them once, before their first post.