[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] BooleanUGens (was Re: conditional statement in SynthDef)



On 5 Sep 2005, at 21:22, James Harkins wrote:

On Sep 5, 2005, at 1:04 PM, Joshua Parmenter wrote:

I first tried to add ==, but a recompile of the library threw all sorts of errors. It seemed to me that, at least on a first look , adding == as a UGen would break code. I really didn't spend much time trying different approaches. It seemed like it would be very simple to code in C, so IsEqual made sense to me.

Here is the problem. There may be an alternate way to handle it, but it could be risky.

Maybe a.asFloat === 0.0 etc.? But that would create and throw out a bunch of objects for UGens. Maybe have testA = a.asFloat; testB = b.asFloat;

Dunno, maybe it's not worth it. Since BinaryOpUGen already supports == and != I think it could just be documented how to write the BinaryOpUGen yourself. Or implement IsEqual in terms of BinaryOpUGen. I don't think we need to lard it up with more plugins for things already included in the plugin lib.

hjh

<x-tad-smaller> if (selector == </x-tad-smaller><x-tad-smaller>'*'</x-tad-smaller><x-tad-smaller>, {
if (a == 0.0, { ^0.0 });
if (b == 0.0, { ^0.0 });
if (a == 1.0, { ^b });
if (a == -1.0, { ^b.neg });
if (b == 1.0, { ^a });
if (b == -1.0, { ^a.neg });
},{
if (selector == </x-tad-smaller><x-tad-smaller>'+'</x-tad-smaller><x-tad-smaller>, {
if (a == 0.0, { ^b });
if (b == 0.0, { ^a });
},{
if (selector == </x-tad-smaller><x-tad-smaller>'-'</x-tad-smaller><x-tad-smaller>, {
if (a == 0.0, { ^b.neg });
if (b == 0.0, { ^a });
},{
if (selector == </x-tad-smaller><x-tad-smaller>'/'</x-tad-smaller><x-tad-smaller>, {
if (b == 1.0, { ^a });
if (b == -1.0, { ^a.neg });
if (b.rate == </x-tad-smaller><x-tad-smaller>'scalar'</x-tad-smaller><x-tad-smaller>, { ^a * b.reciprocal });
})})})});
</x-tad-smaller>

If I understand these correctly, these tests will always prove false if a or b (as applicable) are UGens, and for UGens == and === are the same. So I think that they could be safely changed to === without the need to create extra objects, call asFloat, etc. On my machine === between Floats seems to bench slightly faster on average than == anyway.

nes pas?

S.