Exemplo n.º 1
0
        public void Parse()
        {
            bool success = MeasuredDuration.TryParse("1:1.500", out var duration);

            Assert.IsTrue(success, "Unparsable because ???");
            Assert.AreEqual(new MeasuredDuration(1, 1, 0.5f), duration, "Something wrong with parsing");
        }
Exemplo n.º 2
0
        public void Comparison()
        {
            var durations = new MeasuredDuration[]
            {
                new MeasuredDuration(0, 0, 0.5f),
                new MeasuredDuration(0, 1, 0.5f),
                new MeasuredDuration(1, 0, 0),
                new MeasuredDuration(1, 420, 0.1337f),
                new MeasuredDuration(2, 1, 0),
            };

            for (int i = 0; i < durations.Length; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    Assert.IsTrue(durations[i] > durations[j]);
                }

                Assert.IsTrue(durations[i] == durations[i]);

                for (int j = i + 1; j < durations.Length; j++)
                {
                    Assert.IsTrue(durations[i] < durations[j]);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>Converts a absolute time position into an relative time position.</summary>
        /// <param name="absoluteTimePosition">The absolute time position to convert to an relative one.</param>
        public MeasuredTimePosition ConvertTime(TimeSpan absoluteTimePosition)
        {
            var absolute = GetAbsoluteTimePosition();
            var relative = GetRelativeTimePosition();
            var duration = new MeasuredDuration(absoluteTimePosition - absolute, BPM, TimeSignature);

            return(relative.Add(duration, TimeSignature));
        }
Exemplo n.º 4
0
        /// <summary>Parses a <seealso cref="GuidelineEditorPresetEvent"/> from raw data.</summary>
        /// <param name="s">The raw data of the event that will be parsed.</param>
        /// <param name="patternPool">The pattern pool from which to retrieve the pattern object that is referred.</param>
        public static GuidelineEditorPresetEvent Parse(string s, List <GuidelineEditorPresetPattern> patternPool)
        {
            var split     = s.Split(", ");
            var position  = MeasuredTimePosition.Parse(split[0]);
            var duration  = MeasuredDuration.Parse(split[1]);
            var eventInfo = GuidelineEditorPresetEventPatternInfo.Parse($"{split[2]}, {split[3]}", patternPool);

            return(new GuidelineEditorPresetEvent(position, eventInfo, duration));
        }
Exemplo n.º 5
0
        /// <summary>Extends the selected events' duration by an amount.</summary>
        /// <param name="amount">The amount to extend the selected events' duration by.</param>
        public void ExtendSelectedEventsDuration(MeasuredDuration amount)
        {
            // Extend the events by the amount
            foreach (var e in selectedEvents)
            {
                var eventTimeSignature = Preset.TimingPoints.TimingPointAtTime(e.TimePosition).TimeSignature;

                var initialEnd              = e.GetEnd(eventTimeSignature);
                var initialTimingPoint      = Preset.TimingPoints.TimingPointAtTime(initialEnd);
                int initialTimingPointIndex = Preset.TimingPoints.IndexOf(initialTimingPoint);

                // Find the timing point that the new event end will be at
                var newTimingPoint      = Preset.TimingPoints.TimingPointAtTime(initialEnd.Add(amount, eventTimeSignature));
                int newTimingPointIndex = Preset.TimingPoints.IndexOf(newTimingPoint);

                // Ensure that the event can be extended further, since it can only pass through multiple relative timing points with the same time signature
                int finalValidTimingPoint = initialTimingPointIndex;
                for (int i = initialTimingPointIndex + 1; i <= newTimingPointIndex; i++)
                {
                    var point = Preset.TimingPoints[i];

                    if (point is AbsoluteTimingPoint)
                    {
                        break;
                    }
                    if (point.TimeSignature != eventTimeSignature)
                    {
                        break;
                    }

                    finalValidTimingPoint = i;
                }

                if (finalValidTimingPoint == newTimingPointIndex)
                {
                    e.Duration.IncreaseValue(amount, eventTimeSignature);
                }
                else
                {
                    e.Duration = e.TimePosition.DistanceFrom(Preset.TimingPoints[finalValidTimingPoint + 1].GetRelativeTimePosition(), eventTimeSignature);
                }
            }
        }
Exemplo n.º 6
0
 /// <summary>Initializes a new instance of the <seealso cref="GuidelineEditorPresetEvent"/> class from a given time position, event pattern info and duration.</summary>
 /// <param name="timePosition">The starting time position of the pattern.</param>
 /// <param name="eventPatternInfo">The <seealso cref="GuidelineEditorPresetEventPatternInfo"/> to use in the event.</param>
 /// <param name="duration">The duration of the event.</param>
 public GuidelineEditorPresetEvent(MeasuredTimePosition timePosition, GuidelineEditorPresetEventPatternInfo eventPatternInfo, MeasuredDuration duration)
 {
     TimePosition     = timePosition;
     Duration         = duration;
     EventPatternInfo = eventPatternInfo;
 }
Exemplo n.º 7
0
 /// <summary>Initializes a new instance of the <seealso cref="GuidelineEditorPresetEvent"/> class from a given time position, pattern and duration.</summary>
 /// <param name="timePosition">The starting time position of the pattern.</param>
 /// <param name="pattern">The pattern that this event will use.</param>
 /// <param name="duration">The duration of the event.</param>
 public GuidelineEditorPresetEvent(MeasuredTimePosition timePosition, GuidelineEditorPresetPattern pattern, MeasuredDuration duration)
     : this(timePosition, new GuidelineEditorPresetEventPatternInfo(pattern), duration)
 {
 }