public static void Subtract_TimeTime(ITimeSpan timeSpan1, ITimeSpan timeSpan2, TempoMap tempoMap) { var mathTimeSpan = CheckMathTimeSpan(timeSpan1, timeSpan2, MathOperation.Subtract, TimeSpanMode.TimeTime); AreEqual(timeSpan1, TimeConverter.ConvertTo(timeSpan2.Add(mathTimeSpan, TimeSpanMode.TimeLength), timeSpan1.GetType(), tempoMap), $"{timeSpan2} + ({timeSpan1} - {timeSpan2}) != {timeSpan1}."); }
private static MathTimeSpan CheckMathTimeSpan(ITimeSpan timeSpan1, ITimeSpan timeSpan2, MathOperation operation, TimeSpanMode mode) { var mathTimeSpan = (operation == MathOperation.Add ? timeSpan1.Add(timeSpan2, mode) : timeSpan1.Subtract(timeSpan2, mode)) as MathTimeSpan; Assert.IsTrue(mathTimeSpan != null && mathTimeSpan.TimeSpan1.Equals(timeSpan1) && mathTimeSpan.TimeSpan2.Equals(timeSpan2) && mathTimeSpan.Operation == operation && mathTimeSpan.Mode == mode, "Result is not a math time span."); return(mathTimeSpan); }
private static void ResizeNotesByRatio(IEnumerable <Note> notes, double ratio, TimeSpanType distanceCalculationType, TempoMap tempoMap, ITimeSpan startTime) { foreach (var note in notes) { var noteLength = note.LengthAs(distanceCalculationType, tempoMap); var noteTime = note.TimeAs(distanceCalculationType, tempoMap); var scaledShiftFromStart = noteTime.Subtract(startTime, TimeSpanMode.TimeTime).Multiply(ratio); note.Time = TimeConverter.ConvertFrom(startTime.Add(scaledShiftFromStart, TimeSpanMode.TimeLength), tempoMap); var scaledLength = noteLength.Multiply(ratio); note.Length = LengthConverter.ConvertFrom(scaledLength, note.Time, tempoMap); } }
private static long CalculateBoundaryTime(long time, ITimeSpan size, MathOperation operation, TempoMap tempoMap) { ITimeSpan boundaryTime = (MidiTimeSpan)time; switch (operation) { case MathOperation.Add: boundaryTime = boundaryTime.Add(size, TimeSpanMode.TimeLength); break; case MathOperation.Subtract: var convertedSize = TimeConverter.ConvertFrom(size, tempoMap); boundaryTime = convertedSize > time ? (MidiTimeSpan)0 : boundaryTime.Subtract(size, TimeSpanMode.TimeLength); break; } return(TimeConverter.ConvertFrom(boundaryTime, tempoMap)); }
/// <summary> /// Takes part of the specified length of a MIDI file (starting at the specified time within the file) /// and returns it as an instance of <see cref="MidiFile"/>. /// </summary> /// <param name="midiFile"><see cref="MidiFile"/> to take part of.</param> /// <param name="partStart">The start time of part to take.</param> /// <param name="partLength">The length of part to take.</param> /// <param name="settings">Settings according to which <paramref name="midiFile"/> /// should be splitted.</param> /// <returns><see cref="MidiFile"/> which is part of the <paramref name="midiFile"/>.</returns> /// <exception cref="ArgumentNullException"> /// <para>One of the following errors occured:</para> /// <list type="bullet"> /// <item> /// <description><paramref name="midiFile"/> is <c>null</c>.</description> /// </item> /// <item> /// <description><paramref name="partStart"/> is <c>null</c>.</description> /// </item> /// <item> /// <description><paramref name="partLength"/> is <c>null</c>.</description> /// </item> /// </list> /// </exception> public static MidiFile TakePart(this MidiFile midiFile, ITimeSpan partStart, ITimeSpan partLength, SliceMidiFileSettings settings = null) { ThrowIfArgument.IsNull(nameof(midiFile), midiFile); ThrowIfArgument.IsNull(nameof(partStart), partStart); ThrowIfArgument.IsNull(nameof(partLength), partLength); var grid = new ArbitraryGrid(partStart, partStart.Add(partLength, TimeSpanMode.TimeLength)); settings = settings ?? new SliceMidiFileSettings(); midiFile = PrepareMidiFileForSlicing(midiFile, grid, settings); var tempoMap = midiFile.GetTempoMap(); var times = grid.GetTimes(tempoMap).ToArray(); using (var slicer = MidiFileSlicer.CreateFromFile(midiFile)) { slicer.GetNextSlice(times[0], settings); return(slicer.GetNextSlice(times[1], settings)); } }
public static void Add_TimeTime(ITimeSpan timeSpan1, ITimeSpan timeSpan2) { Assert.ThrowsException <ArgumentException>(() => timeSpan1.Add(timeSpan2, TimeSpanMode.TimeTime)); }