public void Parse() { var expectedGuidelines = new GuidelineCollection(new[] { new Guideline(1.5, GuidelineColor.Green), new Guideline(3.2, GuidelineColor.Yellow), new Guideline(4.7, GuidelineColor.Orange), new Guideline(6.0, GuidelineColor.Green), new Guideline(7.25, GuidelineColor.Green), new Guideline(8.112, GuidelineColor.Yellow), }); var resultingGuidelines = GuidelineCollection.Parse(guidelineString); Assert.AreEqual(expectedGuidelines, resultingGuidelines); resultingGuidelines = GuidelineCollection.Parse($"{guidelineString}~"); Assert.AreEqual(expectedGuidelines, resultingGuidelines); resultingGuidelines = GuidelineCollection.Parse($"~"); Assert.AreEqual(Array.Empty <Guideline>(), resultingGuidelines); resultingGuidelines = GuidelineCollection.Parse($""); Assert.AreEqual(Array.Empty <Guideline>(), resultingGuidelines); }
public void Parse() { var matchedGuidelines = new Guideline[] { new Guideline(1.5, GuidelineColor.Green), new Guideline(3.2, GuidelineColor.Yellow), new Guideline(4.7, GuidelineColor.Orange), new Guideline(6.0, GuidelineColor.Green), new Guideline(7.25, GuidelineColor.Green), new Guideline(8.112, GuidelineColor.Yellow), }; var collection = GuidelineCollection.Parse("1.5~1~3.2~0.9~4.7~0.8~6~1~7.25~1~8.112~0.9"); for (int i = 0; i < matchedGuidelines.Length; i++) { Assert.IsTrue(collection[i] == matchedGuidelines[i]); } }
public void Stringification() { var guidelines = new GuidelineCollection(); Assert.AreEqual("", guidelines.ToString()); guidelines.Add(new Guideline(1.5, GuidelineColor.Green)); Assert.AreEqual("1.5~1", guidelines.ToString()); guidelines.AddRange(new Guideline[] { new Guideline(3.2, GuidelineColor.Yellow), new Guideline(4.7, GuidelineColor.Orange), new Guideline(6.0, GuidelineColor.Green), new Guideline(7.25, GuidelineColor.Green), new Guideline(8.112, GuidelineColor.Yellow), }); Assert.AreEqual("1.5~1~3.2~0.9~4.7~0.8~6~1~7.25~1~8.112~0.9", guidelines.ToString()); }
/// <summary>Generates guidelines based on the current <seealso cref="GuidelineEditorPreset"/> and adds them to the level.</summary> /// <param name="appendGuidelines">If <see langword="true"/>, the generated guidelines will be appended to the level and the previous ones will be preserved, otherwise the new ones will replace the old ones.</param> public void GenerateGuidelines(bool appendGuidelines = true) { var guidelines = new GuidelineCollection(); double audioLength = GetMP3Duration(Level.CustomSongLocation); var tracks = Preset.Tracks.CompactTracks(Preset.TimingPoints); var startingTimingPoint = Preset.TimingPoints.TimingPointAtTime(Preset.StartingPosition); int startingTimingPointIndex = Preset.TimingPoints.IndexOf(startingTimingPoint); foreach (var t in tracks) { var currentPosition = MeasuredTimePosition.Start; var currentTimingPoint = startingTimingPoint; int currentTimingPointIndex = startingTimingPointIndex; foreach (var e in t) { currentPosition = e.TimePosition; // Determine when to end guideline creation if (Preset.IsEndingPositionEndOfSong) { if (currentTimingPoint.ConvertTime(currentPosition).TotalSeconds > audioLength) { break; } else if (currentPosition > Preset.EndingPosition) { break; } } // During the event, the timing point may only change under the same time signature // Therefore, precalculation of the ending position is acceptable var eventEnd = e.GetEnd(currentTimingPoint.TimeSignature); foreach (var m in e.EventPatternInfo.Pattern.Measures) { bool shouldBreak = false; foreach (var n in m.Notes) { currentPosition.BeatWithFraction = n.Position.BeatWithFraction; if (shouldBreak = currentPosition > eventEnd) { break; } // Determine the current timing point to use while (Preset.TimingPoints[currentTimingPointIndex + 1].GetRelativeTimePosition() < currentPosition) { currentTimingPointIndex++; } currentTimingPoint = Preset.TimingPoints[currentTimingPointIndex]; guidelines.Add(new Guideline(currentTimingPoint.ConvertTime(currentPosition).TotalSeconds, n.Color)); } if (shouldBreak) { break; } currentPosition.AdvanceToStartOfNextMeasure(); } } } Level.AddGuidelines(guidelines, appendGuidelines); }