Beispiel #1
0
    private static (int controlMin, int controlMax, int targetRange) GetControlValuesFromPitch(RatchetOptions options, Clip controlSequence)
    {
        int controlMin;
        int controlMax;
        int min = controlSequence.Notes.Select(x => x.Pitch).Min();
        int max = controlSequence.Notes.Select(x => x.Pitch).Max();

        if (options.AutoScale)
        {
            controlMin = min;
            controlMax = max;
        }
        else
        {
            controlMin = min - min % 12;
            controlMax = max + 12 - max % 12;
        }

        var targetRange = Math.Max(controlMax - controlMin, 1);

        return(controlMin, controlMax, targetRange);
    }
Beispiel #2
0
    public static ProcessResult <Clip[]> Apply(RatchetOptions options, params Clip[] clips)
    {
        options.Strength = Math.Clamp(options.Strength, 0, 1);
        if (options.By != null)
        {
            clips = clips.Prepend(options.By).ToArray();
        }
        ClipUtilities.NormalizeClipLengths(clips);
        if (clips.Length < 2)
        {
            clips = new[] { clips[0], clips[0] };
        }
        Clip controlSequence = new Clip(clips[0]);

        Clip[] targetSequences = clips.Skip(1).Select(x => new Clip(x)).ToArray();
        Clip[] resultSequences = new Clip[targetSequences.Length];

        if (options.RatchetValues.Length > 0)
        {
            for (var i = 0; i < options.RatchetValues.Length; i++)
            {
                if (options.RatchetValues[i] < 1)
                {
                    options.RatchetValues[i] = 1;                               // todo: should be handled by optionparser and min max values in optioninfo
                }
            }
            for (var i = 0; i < targetSequences.Length; i++)
            {
                var targetSequence = targetSequences[i];
                resultSequences[i] = DoManualRatchet(options.RatchetValues, targetSequence, options.Strength, options.VelocityToStrength, options.Shape,
                                                     options.Mode);
            }
        }
        else
        {
            var(controlMin, controlMax, targetRange) = options.Mode == RatchetMode.Pitch
                ? GetControlValuesFromPitch(options, controlSequence)
                : GetControlValuesFromVelocity(options, controlSequence);

            float controlRange = Math.Max(controlMax - controlMin, 1);

            // set pitch for each note in control sequence
            if (options.Mode == RatchetMode.Pitch)
            {
                foreach (var note in controlSequence.Notes)
                {
                    note.Pitch = (int)Math.Round((note.Pitch - controlMin) / controlRange * targetRange) + 1;
                }
            }
            else
            {
                foreach (var note in controlSequence.Notes)
                {
                    note.Velocity = (int)Math.Round((Math.Clamp(note.Velocity, controlMin, controlMax) - controlMin) / controlRange * targetRange) + 1;
                }
            }
            for (var i = 0; i < targetSequences.Length; i++)
            {
                var targetSequence = targetSequences[i];
                resultSequences[i] = DoRatchet(controlSequence, targetSequence, (float)options.Strength, options.VelocityToStrength, options.Shape,
                                               options.Mode);
            }
        }


        return(new ProcessResult <Clip[]>(resultSequences));
    }
Beispiel #3
0
    private static (float controlMin, float controlMax, float targetRange) GetControlValuesFromVelocity(RatchetOptions options, Clip controlSequence)
    {
        float controlMin;
        float controlMax;
        float targetRange;

        if (options.AutoScale)
        {
            controlMin  = controlSequence.Notes.Select(x => x.Velocity).Min();
            controlMax  = controlSequence.Notes.Select(x => x.Velocity).Max();
            targetRange = Math.Max(controlMax - controlMin, 10) / 10;
        }
        else
        {
            controlMin  = 20;
            controlMax  = 120;
            targetRange = 16;
        }

        return(controlMin, controlMax, targetRange);
    }