Beispiel #1
0
        /// <summary>
        /// Resizes <see cref="MidiFile"/> to the specified length.
        /// </summary>
        /// <param name="midiFile"><see cref="MidiFile"/> to resize.</param>
        /// <param name="length">New length of the <paramref name="midiFile"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="midiFile"/> is null. -or-
        /// <paramref name="length"/> is null.</exception>
        public static void Resize(this MidiFile midiFile, ITimeSpan length)
        {
            ThrowIfArgument.IsNull(nameof(midiFile), midiFile);
            ThrowIfArgument.IsNull(nameof(length), length);

            if (midiFile.IsEmpty())
            {
                return;
            }

            var tempoMap = midiFile.GetTempoMap();
            var duration = midiFile.GetDuration <MidiTimeSpan>();

            var oldLength = TimeConverter.ConvertTo(duration, length.GetType(), tempoMap);
            var ratio     = TimeSpanUtilities.Divide(length, oldLength);

            ResizeByRatio(midiFile, ratio);
        }
        /// <summary>
        /// Resizes <see cref="MidiFile"/> to the specified length.
        /// </summary>
        /// <param name="midiFile"><see cref="MidiFile"/> to resize.</param>
        /// <param name="length">New length of the <paramref name="midiFile"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="midiFile"/> is null. -or-
        /// <paramref name="length"/> is null.</exception>
        public static void Resize(this MidiFile midiFile, ITimeSpan length)
        {
            ThrowIfArgument.IsNull(nameof(midiFile), midiFile);
            ThrowIfArgument.IsNull(nameof(length), length);

            var lastTime = midiFile.GetTimedEvents().LastOrDefault()?.Time ?? 0;

            if (lastTime == 0)
            {
                return;
            }

            var tempoMap = midiFile.GetTempoMap();

            var oldLength = TimeConverter.ConvertTo((MidiTimeSpan)lastTime, length.GetType(), tempoMap);
            var ratio     = TimeSpanUtilities.Divide(length, oldLength);

            ResizeByRatio(midiFile, ratio);
        }
Beispiel #3
0
        public static void Resize(this MidiFile midiFile, ITimeSpan length)
        {
            ThrowIfArgument.IsNull(nameof(midiFile), midiFile);
            ThrowIfArgument.IsNull(nameof(length), length);

            // TODO: create method to get absolute time (or last time...)
            var lastTime = midiFile.GetTimedEvents().LastOrDefault()?.Time;

            if (lastTime.GetValueOrDefault() == 0)
            {
                return;
            }

            var tempoMap = midiFile.GetTempoMap();

            var oldLength = TimeConverter.ConvertTo((MidiTimeSpan)lastTime.Value, length.GetType(), tempoMap);
            var ratio     = TimeSpanUtilities.Divide(length, oldLength);

            ResizeByRatio(midiFile, ratio);
        }
Beispiel #4
0
        /// <summary>
        /// Subtracts a time span from the current one.
        /// </summary>
        /// <remarks>
        /// If <paramref name="timeSpan"/> and the current time span have the same type,
        /// the result time span will be of this type too; otherwise - of the <see cref="MathTimeSpan"/>.
        /// </remarks>
        /// <param name="timeSpan">Time span to subtract from the current one.</param>
        /// <param name="mode">Mode of the operation that defines meaning of time spans the
        /// operation will be performed on.</param>
        /// <returns>Time span that is a difference between the <paramref name="timeSpan"/> and the
        /// current time span.</returns>
        public ITimeSpan Subtract(ITimeSpan timeSpan, TimeSpanMode mode)
        {
            ThrowIfArgument.IsNull(nameof(timeSpan), timeSpan);

            return(TimeSpanUtilities.Subtract(this, timeSpan, mode));
        }