public static SkipTakeFilter Create(IHostEnvironment env, SkipOptions 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.Count, Options.DefaultTake, env, input)); }
public static ProcessResult <Clip[]> Apply(SkipOptions options, params Clip[] clips) { var resultClips = new Clip[clips.Length]; // Normalize skip values (typical input range: 1 - N, while 0 - N is used internally) for (var ix = 0; ix < options.SkipCounts.Length; ix++) { options.SkipCounts[ix]--; } if (options.SkipCounts.All(x => x == 0)) { return(new ProcessResult <Clip[]>("The given input to skip would produce an empty clip. Aborting...")); } var i = 0; foreach (var clip in clips) { var resultClip = new Clip(clips[i].Length, clips[i].IsLooping); decimal currentPos = 0; var noteIx = 0; var currentSkip = options.SkipCounts[0]; var skipIx = 0; // We don't want skipping notes to result in shorter clips, therefore we keep going until we have filled at least // the same length as the original clip while (currentPos < resultClip.Length) { if (currentSkip > 0) { if (noteIx >= clip.Count) { noteIx %= clip.Count; } var note = clip.Notes[noteIx] with { Start = currentPos }; currentPos += clip.DurationUntilNextNote(noteIx); resultClip.Add(note); currentSkip--; } else { currentSkip = options.SkipCounts[++skipIx % options.SkipCounts.Length]; } noteIx++; } resultClips[i] = resultClip; i++; } return(new ProcessResult <Clip[]>(resultClips)); }
/// <summary> /// Initializes a new instance of <see cref="SkipTakeFilter"/>. /// </summary> /// <param name="env">Host Environment.</param> /// <param name="options">Options for the skip operation.</param> /// <param name="input">Input <see cref="IDataView"/>.</param> public SkipTakeFilter(IHostEnvironment env, SkipOptions options, IDataView input) : this(options.Count, Options.DefaultTake, env, input) { }