public static SkipTakeFilter Create(IHostEnvironment env, TakeOptions options, IDataView input) { Contracts.CheckValue(env, nameof(env)); env.CheckValue(options, nameof(options)); env.CheckUserArg(options.Count >= 0, nameof(options.Count), "should be non-negative"); return(new SkipTakeFilter(Options.DefaultSkip, options.Count, env, input)); }
/// <summary> /// Initializes a new instance of <see cref="SkipTakeFilter"/>. /// </summary> /// <param name="env">Host Environment.</param> /// <param name="options">Options for the take operation.</param> /// <param name="input">Input <see cref="IDataView"/>.</param> public SkipTakeFilter(IHostEnvironment env, TakeOptions options, IDataView input) : this(Options.DefaultSkip, options.Count, env, input) { }
public static ProcessResult <Clip[]> Apply(TakeOptions options, params Clip[] clips) { var resultClips = new Clip[clips.Length]; // Normalize take values (typical input range: 1 - N, while 0 - N is used internally) for (var ix = 0; ix < options.TakeCounts.Length; ix++) { options.TakeCounts[ix]--; } var(lowVelocity, highVelocity) = (options.LowVelocity, options.HighVelocity); if (lowVelocity > highVelocity) { (lowVelocity, highVelocity) = (highVelocity, lowVelocity); } var(lowPitch, highPitch) = (options.LowPitch, options.HighPitch); if (lowPitch > highPitch) { (lowPitch, highPitch) = (highPitch, lowPitch); } var i = 0; foreach (var clip in clips) { var filteredNotes = clip.Notes.Where(x => x.Velocity >= lowVelocity && x.Velocity <= highVelocity && x.Pitch >= lowPitch && x.Pitch <= highPitch).ToList(); var resultClip = new Clip(clips[i].Length, clips[i].IsLooping); decimal currentPos = 0; var noteIx = 0; var currentTake = options.TakeCounts[0]; var takeIx = 0; // We want to keep the length of the newly created clip approximately equal to the original, therefore we keep // going until we have filled at least the same length as the original clip while (currentPos < resultClip.Length) { if (currentTake == 0) { if (noteIx >= clip.Count) { noteIx %= clip.Count; } var note = filteredNotes[noteIx] with { Start = currentPos }; currentPos += clip.DurationUntilNextNote(noteIx); resultClip.Add(note); currentTake = options.TakeCounts[++takeIx % options.TakeCounts.Length]; } else { if (options.Thin) { currentPos += clip.DurationUntilNextNote(noteIx); } currentTake--; } noteIx++; } resultClips[i] = resultClip; i++; } return(new ProcessResult <Clip[]>(resultClips)); }