コード例 #1
0
        private static TimeProcessingInstruction CorrectObjectOnStartQuantizing(TObject obj, long time, TempoMap tempoMap, TSettings settings)
        {
            if (settings.FixOppositeEnd)
            {
                var endTime = obj.Time + obj.Length;

                if (time > endTime)
                {
                    var result = ProcessQuantizingBeyondFixedEnd(ref time,
                                                                 ref endTime,
                                                                 settings.QuantizingBeyondFixedEndPolicy,
                                                                 "Start time is going to be beyond the end one.");
                    if (result != null)
                    {
                        return(result);
                    }
                }

                LengthSetter.SetObjectLength(obj, endTime - time);
            }
            else
            {
                var length = obj.LengthAs(settings.LengthType, tempoMap);
                LengthSetter.SetObjectLength(obj, LengthConverter.ConvertFrom(length, time, tempoMap));
            }

            return(new TimeProcessingInstruction(time));
        }
コード例 #2
0
        private static TimeProcessingInstruction CorrectObjectOnEndQuantizing(TObject obj, long time, TempoMap tempoMap, TSettings settings)
        {
            if (settings.FixOppositeEnd)
            {
                var startTime = obj.Time;

                if (time < startTime)
                {
                    var result = ProcessQuantizingBeyondFixedEnd(ref time,
                                                                 ref startTime,
                                                                 settings.QuantizingBeyondFixedEndPolicy,
                                                                 "End time is going to be beyond the start one.");
                    if (result != null)
                    {
                        return(result);
                    }
                }

                LengthSetter.SetObjectLength(obj, time - startTime);
            }
            else
            {
                var length = obj.LengthAs(settings.LengthType, tempoMap);

                var newStartTime = settings.LengthType == TimeSpanType.Midi
                    ? time - obj.Length
                    : TimeConverter.ConvertFrom(((MidiTimeSpan)time).Subtract(length, TimeSpanMode.TimeLength), tempoMap);
                if (newStartTime < 0)
                {
                    switch (settings.QuantizingBeyondZeroPolicy)
                    {
                    case QuantizingBeyondZeroPolicy.Skip:
                        return(TimeProcessingInstruction.Skip);

                    case QuantizingBeyondZeroPolicy.Abort:
                        throw new InvalidOperationException("Object is going to be moved beyond zero.");

                    case QuantizingBeyondZeroPolicy.FixAtZero:
                        LengthSetter.SetObjectLength(obj, time);
                        break;
                    }
                }
                else
                {
                    LengthSetter.SetObjectLength(obj, LengthConverter.ConvertFrom(length, newStartTime, tempoMap));
                }
            }

            return(new TimeProcessingInstruction(time));
        }
コード例 #3
0
        /// <summary>
        /// Performs additional actions before the new time will be set to an object.
        /// </summary>
        /// <remarks>
        /// Inside this method the new time can be changed or randomizing of an object can be cancelled.
        /// </remarks>
        /// <param name="obj">Object to randomize.</param>
        /// <param name="time">The new time that is going to be set to the object. Can be changed
        /// inside this method.</param>
        /// <param name="settings">Settings according to which object should be randomized.</param>
        /// <returns>An object indicating whether the new time should be set to the object
        /// or not. Also returned object contains that new time.</returns>
        protected override TimeProcessingInstruction OnObjectRandomizing(TObject obj, long time, TSettings settings)
        {
            var target = settings.RandomizingTarget;

            switch (target)
            {
            case LengthedObjectTarget.Start:
                if (settings.FixOppositeEnd)
                {
                    LengthSetter.SetObjectLength(obj, obj.Time + obj.Length - time);
                }
                break;

            case LengthedObjectTarget.End:
                if (settings.FixOppositeEnd)
                {
                    LengthSetter.SetObjectLength(obj, time - obj.Time);
                }
                break;
            }

            return(new TimeProcessingInstruction(time));
        }