Пример #1
0
        // Use like this:
        // Zebra2Preset.LFOSync lfoSync = Zebra2Preset.LFOSync.SYNC_0_1s;
        // double lfoValue = 0.0;
        // Zebra2Preset.MillisecondsToLFOSyncAndValue(msValue, out lfoSync, out lfoValue);
        public static void MillisecondsToLFOSyncAndValue(float timeInMs, out LFOSync lfoSync, out int lfoValue)
        {
            if (float.IsNaN(timeInMs) || float.IsInfinity(timeInMs)) {
                Console.Out.WriteLine("MillisecondsToLFOSyncAndValue failed. Zebra2 does not support non number LFO values! (Value: {0} ms.)", timeInMs);
                //IOUtils.LogMessageToFile(outputStatusLog, String.Format("Warning! MillisecondsToLFOSyncAndValue failed. Zebra2 does not support non number LFO values! (Value: {0} ms.)", timeInMs));
                Sylenth1Preset.DoError(String.Format("Warning! MillisecondsToLFOSyncAndValue failed. Zebra2 does not support non number LFO values! (Value: {0} ms.)", timeInMs));
                lfoValue = 0;
                lfoSync = Zebra2Preset.LFOSync.SYNC_0_1s;
                return;
            }
            if (timeInMs < 12.5) {
                Console.Out.WriteLine("MillisecondsToLFOSyncAndValue failed. Zebra2 does not support LFO values lower than 12.5 ms! (Value: {0} ms.)", timeInMs);
                //IOUtils.LogMessageToFile(outputStatusLog, String.Format("Warning! MillisecondsToLFOSyncAndValue failed. Zebra2 does not support LFO values lower than 12.5 ms! (Value: {0} ms.)", timeInMs));
                Sylenth1Preset.DoError(String.Format("Warning! MillisecondsToLFOSyncAndValue failed. Zebra2 does not support LFO values lower than 12.5 ms! (Value: {0} ms.)", timeInMs));
                lfoValue = 200;
                lfoSync = Zebra2Preset.LFOSync.SYNC_0_1s;
                return;
            }

            // calculate all three alternatives and choose the one that is closest.

            // first use SYNC_0_1s:
            lfoSync = Zebra2Preset.LFOSync.SYNC_0_1s;
            double value0_1s = (double) 50 / Math.Pow( (double) timeInMs/1000/0.8f, (double) 1/3);
            value0_1s = MathUtils.RoundToNearestInteger((int)value0_1s, 2); // the Lfo value (Rate) has steps of two
            // get the value
            double value0_1s_ms = PresetConverter.Zebra2Preset.LFOSyncAndValueToMilliseconds(lfoSync, (int) value0_1s);
            if (value0_1s > 200) {
                value0_1s_ms = 0;
            }

            // then use SYNC_1s:
            lfoSync = Zebra2Preset.LFOSync.SYNC_1s;
            double value1s = (double) 50 / Math.Pow( (double) timeInMs/1000/8f, (double) 1/3);
            value1s = MathUtils.RoundToNearestInteger((int)value1s, 2); // the Lfo value (Rate) has steps of two
            // get the value
            double value1s_ms = PresetConverter.Zebra2Preset.LFOSyncAndValueToMilliseconds(lfoSync, (int) value1s);
            if (value1s > 200) {
                value1s_ms = 0;
            }

            // then use SYNC_10s:
            lfoSync = Zebra2Preset.LFOSync.SYNC_10s;
            double value10s = (double) 50 / Math.Pow( (double) timeInMs/1000/80f, (double) 1/3);
            value10s = MathUtils.RoundToNearestInteger((int)value10s, 2); // the Lfo value (Rate) has steps of two
            // get the value
            double value10s_ms = PresetConverter.Zebra2Preset.LFOSyncAndValueToMilliseconds(lfoSync, (int) value10s);
            if (value10s > 200) {
                value10s_ms = 0;
            }

            // determine which is closest
            List<float> list = new List<float> { (float) value0_1s_ms, (float) value1s_ms, (float) value10s_ms };
            float closest = MathUtils.FindClosest(list, timeInMs);
            if (closest == (float) value0_1s_ms) {
                lfoValue = (int) value0_1s;
                lfoSync = Zebra2Preset.LFOSync.SYNC_0_1s;
            } else if (closest == (float) value1s_ms) {
                lfoValue = (int) value1s;
                lfoSync = Zebra2Preset.LFOSync.SYNC_1s;
            } else {
                lfoValue = (int) value10s;
                lfoSync = Zebra2Preset.LFOSync.SYNC_10s;
            }
        }
Пример #2
0
        public static double LFOSyncAndValueToMilliseconds(LFOSync lfoSync, int lfoValue, int bpm=120)
        {
            double ms = 0;
            switch (lfoSync) {
                case LFOSync.SYNC_0_1s:
                    // =0,8*((50/U3)^3)
                    ms = 1000 * 0.8 * ( Math.Pow(50 / (double) lfoValue, 3) );
                    return ms;
                case LFOSync.SYNC_1s:
                    // =8*((50/U36)^3)
                    ms = 1000 * 8 * ( Math.Pow(50 / (double) lfoValue, 3) );
                    return ms;
                case LFOSync.SYNC_10s:
                    // =80*((50/U69)^3)
                    ms = 1000 * 80 * ( Math.Pow(50 / (double) lfoValue, 3) );
                    return ms;
                case LFOSync.SYNC_1_64:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_1_64, bpm);
                    break;
                case LFOSync.SYNC_1_32:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_1_32, bpm);
                    break;
                case LFOSync.SYNC_1_16:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_1_16, bpm);
                    break;
                case LFOSync.SYNC_1_8:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_1_8, bpm);
                    break;
                case LFOSync.SYNC_1_4:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_1_4, bpm);
                    break;
                case LFOSync.SYNC_1_2:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_1_2, bpm);
                    break;
                case LFOSync.SYNC_1_1:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_1_1, bpm);
                    break;
                case LFOSync.SYNC_1_32_dot:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_1_32D, bpm);
                    break;
                case LFOSync.SYNC_1_16_dot:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_1_16D, bpm);
                    break;
                case LFOSync.SYNC_1_8_dot:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_1_8D, bpm);
                    break;
                case LFOSync.SYNC_1_4_dot:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_1_4D, bpm);
                    break;
                case LFOSync.SYNC_1_2_dot:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_1_2D, bpm);
                    break;
                case LFOSync.SYNC_1_16_trip:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_1_16T, bpm);
                    break;
                case LFOSync.SYNC_1_8_trip:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_1_8T, bpm);
                    break;
                case LFOSync.SYNC_1_4_trip:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_1_4T, bpm);
                    break;
                case LFOSync.SYNC_1_2_trip:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_1_2T, bpm);
                    break;
                case LFOSync.SYNC_1_1_trip:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_1_1T, bpm);
                    break;
                case LFOSync.SYNC_2_1:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_2_1, bpm);
                    break;
                case LFOSync.SYNC_3_1:
                    //ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_3_1, bpm);
                    break;
                case LFOSync.SYNC_4_1:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_4_1, bpm);
                    break;
                case LFOSync.SYNC_5_1:
                    //ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_5_1, bpm);
                    break;
                case LFOSync.SYNC_6_1:
                    //ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_6_1, bpm);
                    break;
                case LFOSync.SYNC_7_1:
                    //ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_7_1, bpm);
                    break;
                case LFOSync.SYNC_8_1:
                    ms = AudioUtils.LFOOrDelayToMilliseconds(AudioUtils.LFOTIMING.LFO_8_1, bpm);
                    break;
            }

            // find multiplication factor
            if (lfoValue != 100) {
                double mult = ( Math.Pow(50 / (double) lfoValue, 3) );
                ms = ms * mult * 8;
            }
            return ms;
        }