Пример #1
0
    public override bool SetValueFromString(string str)
    {
        string ty  = string.Empty;
        string val = string.Empty;

        if (str.Contains("|") == true)
        {
            string [] rest = str.Split(new char [] { '|' }, System.StringSplitOptions.RemoveEmptyEntries);
            ty  = rest[0].Trim();
            val = rest[1].Trim();
        }
        else
        {
            ty  = "hz";
            val = str.Trim();
        }

        float.TryParse(val, out this.value);

        switch (ty)
        {
        case "foct":
            this.freqTy = TimeLenType.FrequencyOctave;
            break;

        case "frmm":
            this.freqTy = TimeLenType.FrequencyMul;
            this.mul    = true;
            break;

        case "frmd":
            this.freqTy = TimeLenType.FrequencyMul;
            this.mul    = false;
            break;

        case "boct":
            this.freqTy = TimeLenType.BeatOctave;
            break;

        case "bmm":
            this.freqTy = TimeLenType.BeatMul;
            this.mul    = true;
            break;

        case "bmd":
            this.freqTy = TimeLenType.BeatMul;
            this.mul    = false;
            break;

        case "sec":
            this.freqTy = TimeLenType.Seconds;
            break;

        default:
            this.freqTy = TimeLenType.Hertz;
            break;
        }
        return(true);
    }
Пример #2
0
    public static Value CalcValFromFrequency(float hz, float noteFr, float bps, TimeLenType ty)
    {
        const float minSafeHz = 0.1f; // Arbitrary
        float       clampedHz = Mathf.Max(hz, minSafeHz);

        switch (ty)
        {
        case TimeLenType.FrequencyOctave:
            // From wolfram alpha,
            // y = n*2^x solve for x
            // where n is noteFr, and y = fr
            return(new Value(Mathf.Log(clampedHz / noteFr) / Mathf.Log(2.0f)));

        case TimeLenType.FrequencyMul:
            if (clampedHz > noteFr)
            {
                return(new Value(noteFr / clampedHz, true));
            }
            else
            {
                return(new Value(clampedHz / noteFr, false));
            }

        case TimeLenType.BeatOctave:
            return(new Value(Mathf.Log(clampedHz / bps) / Mathf.Log(2.0f)));

        case TimeLenType.BeatMul:
            if (clampedHz > bps)
            {
                return(new Value(bps / clampedHz, true));
            }
            else
            {
                return(new Value(clampedHz / bps, false));
            }

        case TimeLenType.Seconds:
            return(new Value(1.0f / clampedHz));

        case TimeLenType.Hertz:
            return(new Value(hz));
        }

        return(new Value(1.0f));
    }
Пример #3
0
 public ParamTimeLen(string name, float value, TimeLenType frty, string widget)
     : base(name, Type.TimeLen, widget)
 {
     this.value  = value;
     this.freqTy = frty;
 }