protected bool HandleLfoFunc(FunctionArgs args, List <double> evaluatedArgs)
        {
            if (evaluatedArgs.Count != 6)
            {
                return(false);
            }

            double       input  = evaluatedArgs[0];
            double       attack = evaluatedArgs[1];
            WaveformShap shape  = (WaveformShap)evaluatedArgs[2];
            double       phase  = evaluatedArgs[3];
            double       cycles = evaluatedArgs[4];
            double       amount = evaluatedArgs[5];

            if (attack < 0 || attack > 1)
            {
                return(false);
            }

            if (Enum.IsDefined(typeof(WaveformShap), shape) == false)
            {
                return(false);
            }

            //input
            double output = input;

            //cycles
            output *= cycles;

            //phase
            output += phase % 360 / 360.0;

            //shape
            HandleWaveformFunc(output, shape, out output);

            output -= 0.5;

            //attack
            double attackAtInput;

            if (attack == 0)
            {
                attackAtInput = 1;
            }
            else
            {
                attackAtInput = Math.Min(1, input / attack);
            }
            output *= attackAtInput;

            //amount
            output *= amount;

            output += 0.5;

            args.Result = output;
            return(true);
        }
        protected bool HandleWaveformFunc(double input, WaveformShap shape, out double output)
        {
            //simply using "input % 1" does not work for negative values.
            double inAsRamp = (1 + (input % 1)) % 1;

            switch (shape)
            {
            case WaveformShap.Sin:
                output = Math.Sin(2 * Math.PI * input) / 2 + 0.5;
                break;

            case WaveformShap.Triangle:
                //Offset the base ramp wave so that the triangle wave starts at 0.5 instead
                //of 0.
                double inAsOffsetRamp = (1 + ((input + 0.25) % 1)) % 1;
                output = 1 - Math.Abs(inAsOffsetRamp - 0.5) * 2;
                break;

            case WaveformShap.Square:
                output = System.Convert.ToDouble(inAsRamp < 0.5);
                break;

            case WaveformShap.Ramp:
                output = inAsRamp;
                break;

            case WaveformShap.Saw:
                output = 1 - inAsRamp;
                break;

            default:
                output = double.NaN;
                return(false);
            }

            return(true);
        }
        protected bool HandleWaveformFunc(double input, WaveformShap shape, out double output)
        {
            //simply using "input % 1" does not work for negative values.
            double inAsRamp = (1 + (input % 1)) % 1;

            switch (shape)
            {
                case WaveformShap.Sin:
                    output = Math.Sin(2 * Math.PI * input) / 2 + 0.5;
                    break;
                case WaveformShap.Triangle:
                    //Offset the base ramp wave so that the triangle wave starts at 0.5 instead
                    //of 0.
                    double inAsOffsetRamp = (1 + ((input+0.25) % 1)) % 1;
                    output = 1 - Math.Abs(inAsOffsetRamp - 0.5) * 2;
                    break;
                case WaveformShap.Square:
                    output = System.Convert.ToDouble(inAsRamp < 0.5);
                    break;
                case WaveformShap.Ramp:
                    output = inAsRamp;
                    break;
                case WaveformShap.Saw:
                    output = 1 - inAsRamp;
                    break;
                default:
                    output = double.NaN;
                    return false;
            }

            return true;
        }