コード例 #1
0
ファイル: TimingPoint.cs プロジェクト: guusw/fx2
 public double GetDivisionDuration(TimeDivision division)
 {
     return(MeasureDuration * ((double)division.Numerator / division.Denominator));
 }
コード例 #2
0
ファイル: Beatmap.FromKSH.cs プロジェクト: guusw/fx2
        public void Process()
        {
            beatmap.Metadata = new BeatmapMetadata();

            // Process metadata
            foreach (var option in sourceBeatmap.Options)
            {
                if (option.Key == "artist")
                {
                    beatmap.Metadata.Artist = option.Value;
                }
                else if (option.Key == "title")
                {
                    beatmap.Metadata.Title = option.Value;
                }
                else if (option.Key == "effect")
                {
                    beatmap.Metadata.Creator = option.Value;
                }
                else if (option.Key == "illustrator")
                {
                    beatmap.Metadata.Illustrator = option.Value;
                }
                else if (option.Key == "jacket")
                {
                    beatmap.Metadata.JacketPath = option.Value;
                }
                else if (option.Key == "m")
                {
                    if (option.Value.Length == 0)
                    {
                        throw new BeatmapParserException("Invalid song path in beatmap options detected");
                    }

                    string[] paths = option.Value.Split(';');
                    if (paths.Length == 0)
                    {
                        beatmap.Metadata.AudioPath = option.Value;
                    }
                    else
                    {
                        beatmap.Metadata.AudioPath = paths[0];
                        if (paths.Length > 1)
                        {
                            beatmap.Metadata.EffectedAudioPath = paths[1];
                        }
                    }
                }
                else if (option.Key == "po")
                {
                    beatmap.Metadata.PreviewOffset = double.Parse(option.Value) / 1000.0;
                }
                else if (option.Key == "plength")
                {
                    beatmap.Metadata.PreviewDuration = double.Parse(option.Value) / 1000.0;
                }
            }

            var firstTimingPoint = new TimingPoint();

            beatmap.TimingPoints.Add(firstTimingPoint);
            firstTimingPoint.Beatmap = beatmap;
            currentTimingPoint       = beatmap.TimingPoints[0];

            // Must contain BPM and offset at least
            if (!sourceBeatmap.Options.ContainsKey("t") || !sourceBeatmap.Options.ContainsKey("o"))
            {
                throw new BeatmapParserException("Map does not contain valid timing information");
            }

            // Setup the initial timing point
            double startingBPM = 0.0;

            if (double.TryParse(sourceBeatmap.Options["t"], out startingBPM))
            {
                currentTimingPoint.BPM = startingBPM;
            }

            currentTimingPoint.Offset = double.Parse(sourceBeatmap.Options["o"]) / 1000.0;
            if (sourceBeatmap.Options.ContainsKey("beat"))
            {
                ParseBeatOption(sourceBeatmap.Options["beat"], currentTimingPoint);
            }
            else
            {
                currentTimingPoint.Numerator   = 4;
                currentTimingPoint.Denominator = 4;
            }

            // Process custom effect types
            ProcessEffectDefinitions();

            foreach (var sourceMeasure in sourceBeatmap.Measures)
            {
                this.sourceMeasure = sourceMeasure;

                // Process pending timing point
                if (pendingTimingPoint != null)
                {
                    // TODO: Add test for this
                    beatmap.TimingPoints.Add(pendingTimingPoint);
                    pendingTimingPoint.Beatmap = beatmap;
                    currentTimingPoint         = pendingTimingPoint;
                    pendingTimingPoint         = null;
                }

                // Process ticks
                currentMeasure = currentTimingPoint.AddMeasure();
                foreach (var tick in sourceMeasure.Ticks)
                {
                    currentPosition = new TimeDivision(tickIndex, sourceMeasure.Ticks.Length);

                    if (tick.Options != null)
                    {
                        ProcessTickOptions(tick);
                    }

                    // Process button states
                    for (int i = 0; i < 6; i++)
                    {
                        if (tick.Button[i] == '0')
                        {
                            // Terminate current button
                            if (buttonStates[i] != null)
                            {
                                EndButtonState(i);
                            }
                        }
                        else if (buttonStates[i] == null)
                        {
                            BeginButtonState(i, tick.Button[i]);
                        }
                        else
                        {
                            var state = buttonStates[i];

                            // For buttons not using the 1/32 grid
                            if (!state.Snap32)
                            {
                                EndButtonState(i);

                                // Create new button state
                                BeginButtonState(i, tick.Button[i]);
                            }
                            else
                            {
                                // Sort hold state
                                state.NumTicks++;
                            }
                        }
                    }

                    // Process laser states
                    for (int i = 0; i < 2; i++)
                    {
                        if (tick.Lasers[i] == BeatmapKsh.Tick.LaserNone)
                        {
                            // End laser
                            laserStates[i]   = null;
                            laserExtended[i] = false; // Reset extended range
                        }
                        else if (tick.Lasers[i] == BeatmapKsh.Tick.LaserLerp)
                        {
                            laserStates[i].NumTicks++;
                        }
                        else
                        {
                            UpdateLaserState(i, tick);
                        }
                    }

                    tickIndex++;
                }

                tickIndex = 0;
                measureIndex++;
                relativeMeasureIndex++;
            }
        }
コード例 #3
0
ファイル: TimeDivisionReference.cs プロジェクト: guusw/fx2
 public TimeDivisionReference(TimeDivision position, Measure measure)
 {
     this.Position = position;
     this.Measure  = measure;
 }