Пример #1
0
        /// <summary>Parses a <seealso cref="GuidelineEditorPreset"/> from raw data wtih a specified name.</summary>
        /// <param name="name">The name of the preset.</param>
        /// <param name="rawData">The raw data of the preset that will be parsed.</param>
        public static GuidelineEditorPreset Parse(string name, string rawData)
        {
            var patternPool  = new List <GuidelineEditorPresetPattern>();
            var tracks       = new GuidelineEditorPresetTrackList();
            var timingPoints = new TimingPointList();

            var lines = rawData.GetLines().ToList();

            lines.RemoveAll(s => s.StartsWith("//"));
            int    currentLineIndex = 0;
            string currentLine;

            // Pattern pool
            for (; (currentLine = lines[currentLineIndex]).Length > 0; currentLineIndex++)
            {
                patternPool.Add(GuidelineEditorPresetPattern.Parse(currentLine));
                currentLineIndex++;
            }

            // Intermediate parameters
            currentLineIndex++;
            var split  = lines[currentLineIndex].Split('|');
            var offset = ToDouble(split[0]);
            var start  = MeasuredTimePosition.Parse(split[1]);
            var end    = MeasuredTimePosition.Parse(split[2]);

            currentLineIndex++;

            // Timing points
            for (; (currentLine = lines[currentLineIndex]).Length > 0; currentLineIndex++)
            {
                timingPoints.Add(TimingPoint.Parse(currentLine));
                currentLineIndex++;
            }

            // Tracks
            for (currentLineIndex++; currentLineIndex < lines.Count; currentLineIndex++)
            {
                // TODO: Consider caring about the track indices
                var events = new List <GuidelineEditorPresetEvent>();
                for (currentLineIndex++; currentLineIndex < lines.Count && (currentLine = lines[currentLineIndex]).Length > 0; currentLineIndex++)
                {
                    events.Add(GuidelineEditorPresetEvent.Parse(currentLine, patternPool));
                }
                tracks.Add(new GuidelineEditorPresetTrack(events));
            }

            return(new GuidelineEditorPreset(name, offset, start, end, tracks, timingPoints));
        }
Пример #2
0
        /// <summary>Gets all the events of this track list and generates a track list that contains the smallest number of tracks where the events are not overlapping in any track.</summary>
        /// <param name="timingPoints">The timing points based on which to compact the tracks.</param>
        public GuidelineEditorPresetTrackList CompactTracks(TimingPointList timingPoints)
        {
            var result        = new GuidelineEditorPresetTrackList();
            var unifiedTracks = UnifyTracks();

            foreach (var e in unifiedTracks)
            {
                bool found = false;
                for (int i = 0; i < result.Count && !found; i++)
                {
                    if (found = MeasuredTimePosition.CompareByAbsolutePosition(result.tracks[i].GetEnd(timingPoints), e.TimePosition) < 0)
                    {
                        result.tracks[i].Add(e);
                    }
                }
                if (!found)
                {
                    result.Add(new GuidelineEditorPresetTrack(e));
                }
            }
            return(result);
        }