Ejemplo n.º 1
0
        private void handleTimingPoint(string line)
        {
            string[] split = line.Split(',');

            double time            = getOffsetTime(Parsing.ParseDouble(split[0].Trim()));
            double beatLength      = Parsing.ParseDouble(split[1].Trim());
            double speedMultiplier = beatLength < 0 ? 100.0 / -beatLength : 1;

            TimeSignatures timeSignature = TimeSignatures.SimpleQuadruple;

            if (split.Length >= 3)
            {
                timeSignature = split[2][0] == '0' ? TimeSignatures.SimpleQuadruple : (TimeSignatures)Parsing.ParseInt(split[2]);
            }

            LegacySampleBank sampleSet = defaultSampleBank;

            if (split.Length >= 4)
            {
                sampleSet = (LegacySampleBank)Parsing.ParseInt(split[3]);
            }

            int customSampleBank = 0;

            if (split.Length >= 5)
            {
                customSampleBank = Parsing.ParseInt(split[4]);
            }

            int sampleVolume = defaultSampleVolume;

            if (split.Length >= 6)
            {
                sampleVolume = Parsing.ParseInt(split[5]);
            }

            bool timingChange = true;

            if (split.Length >= 7)
            {
                timingChange = split[6][0] == '1';
            }

            bool kiaiMode = false;
            bool omitFirstBarSignature = false;

            if (split.Length >= 8)
            {
                EffectFlags effectFlags = (EffectFlags)Parsing.ParseInt(split[7]);
                kiaiMode = effectFlags.HasFlag(EffectFlags.Kiai);
                omitFirstBarSignature = effectFlags.HasFlag(EffectFlags.OmitFirstBarLine);
            }

            string stringSampleSet = sampleSet.ToString().ToLowerInvariant();

            if (stringSampleSet == @"none")
            {
                stringSampleSet = @"normal";
            }

            if (timingChange)
            {
                var controlPoint = CreateTimingControlPoint();

                controlPoint.BeatLength    = beatLength;
                controlPoint.TimeSignature = timeSignature;

                addControlPoint(time, controlPoint, true);
            }

            addControlPoint(time, new LegacyDifficultyControlPoint
            {
                SpeedMultiplier = speedMultiplier,
            }, timingChange);

            addControlPoint(time, new EffectControlPoint
            {
                KiaiMode         = kiaiMode,
                OmitFirstBarLine = omitFirstBarSignature,
            }, timingChange);

            addControlPoint(time, new LegacySampleControlPoint
            {
                SampleBank       = stringSampleSet,
                SampleVolume     = sampleVolume,
                CustomSampleBank = customSampleBank,
            }, timingChange);

            // To handle the scenario where a non-timing line shares the same time value as a subsequent timing line but
            // appears earlier in the file, we buffer non-timing control points and rewrite them *after* control points from the timing line
            // with the same time value (allowing them to overwrite as necessary).
            //
            // The expected outcome is that we prefer the non-timing line's adjustments over the timing line's adjustments when time is equal.
            if (timingChange)
            {
                flushPendingPoints();
            }
        }
Ejemplo n.º 2
0
        private void handleTimingPoint(string line)
        {
            try
            {
                string[] split = line.Split(',');

                double time            = getOffsetTime(double.Parse(split[0].Trim(), NumberFormatInfo.InvariantInfo));
                double beatLength      = double.Parse(split[1].Trim(), NumberFormatInfo.InvariantInfo);
                double speedMultiplier = beatLength < 0 ? 100.0 / -beatLength : 1;

                TimeSignatures timeSignature = TimeSignatures.SimpleQuadruple;
                if (split.Length >= 3)
                {
                    timeSignature = split[2][0] == '0' ? TimeSignatures.SimpleQuadruple : (TimeSignatures)int.Parse(split[2]);
                }

                LegacySampleBank sampleSet = defaultSampleBank;
                if (split.Length >= 4)
                {
                    sampleSet = (LegacySampleBank)int.Parse(split[3]);
                }

                int customSampleBank = 0;
                if (split.Length >= 5)
                {
                    customSampleBank = int.Parse(split[4]);
                }

                int sampleVolume = defaultSampleVolume;
                if (split.Length >= 6)
                {
                    sampleVolume = int.Parse(split[5]);
                }

                bool timingChange = true;
                if (split.Length >= 7)
                {
                    timingChange = split[6][0] == '1';
                }

                bool kiaiMode = false;
                bool omitFirstBarSignature = false;
                if (split.Length >= 8)
                {
                    EffectFlags effectFlags = (EffectFlags)int.Parse(split[7]);
                    kiaiMode = effectFlags.HasFlag(EffectFlags.Kiai);
                    omitFirstBarSignature = effectFlags.HasFlag(EffectFlags.OmitFirstBarLine);
                }

                string stringSampleSet = sampleSet.ToString().ToLowerInvariant();
                if (stringSampleSet == @"none")
                {
                    stringSampleSet = @"normal";
                }

                if (timingChange)
                {
                    var controlPoint = CreateTimingControlPoint();
                    controlPoint.Time          = time;
                    controlPoint.BeatLength    = beatLength;
                    controlPoint.TimeSignature = timeSignature;

                    handleTimingControlPoint(controlPoint);
                }

                handleDifficultyControlPoint(new DifficultyControlPoint
                {
                    Time            = time,
                    SpeedMultiplier = speedMultiplier
                });

                handleEffectControlPoint(new EffectControlPoint
                {
                    Time             = time,
                    KiaiMode         = kiaiMode,
                    OmitFirstBarLine = omitFirstBarSignature
                });

                handleSampleControlPoint(new LegacySampleControlPoint
                {
                    Time             = time,
                    SampleBank       = stringSampleSet,
                    SampleVolume     = sampleVolume,
                    CustomSampleBank = customSampleBank
                });
            }
            catch (FormatException e)
            {
            }
        }
Ejemplo n.º 3
0
        private void handleTimingPoint(string line)
        {
            try
            {
                string[] split = line.Split(',');

                double time            = getOffsetTime(Parsing.ParseDouble(split[0].Trim()));
                double beatLength      = Parsing.ParseDouble(split[1].Trim());
                double speedMultiplier = beatLength < 0 ? 100.0 / -beatLength : 1;

                TimeSignatures timeSignature = TimeSignatures.SimpleQuadruple;
                if (split.Length >= 3)
                {
                    timeSignature = split[2][0] == '0' ? TimeSignatures.SimpleQuadruple : (TimeSignatures)Parsing.ParseInt(split[2]);
                }

                LegacySampleBank sampleSet = defaultSampleBank;
                if (split.Length >= 4)
                {
                    sampleSet = (LegacySampleBank)Parsing.ParseInt(split[3]);
                }

                int customSampleBank = 0;
                if (split.Length >= 5)
                {
                    customSampleBank = Parsing.ParseInt(split[4]);
                }

                int sampleVolume = defaultSampleVolume;
                if (split.Length >= 6)
                {
                    sampleVolume = Parsing.ParseInt(split[5]);
                }

                bool timingChange = true;
                if (split.Length >= 7)
                {
                    timingChange = split[6][0] == '1';
                }

                bool kiaiMode = false;
                bool omitFirstBarSignature = false;

                if (split.Length >= 8)
                {
                    EffectFlags effectFlags = (EffectFlags)Parsing.ParseInt(split[7]);
                    kiaiMode = effectFlags.HasFlag(EffectFlags.Kiai);
                    omitFirstBarSignature = effectFlags.HasFlag(EffectFlags.OmitFirstBarLine);
                }

                string stringSampleSet = sampleSet.ToString().ToLowerInvariant();
                if (stringSampleSet == @"none")
                {
                    stringSampleSet = @"normal";
                }

                if (timingChange)
                {
                    var controlPoint = CreateTimingControlPoint();
                    controlPoint.Time          = time;
                    controlPoint.BeatLength    = beatLength;
                    controlPoint.TimeSignature = timeSignature;

                    handleTimingControlPoint(controlPoint);
                }

                handleDifficultyControlPoint(new DifficultyControlPoint
                {
                    Time            = time,
                    SpeedMultiplier = speedMultiplier,
                    AutoGenerated   = timingChange
                });

                handleEffectControlPoint(new EffectControlPoint
                {
                    Time             = time,
                    KiaiMode         = kiaiMode,
                    OmitFirstBarLine = omitFirstBarSignature,
                    AutoGenerated    = timingChange
                });

                handleSampleControlPoint(new LegacySampleControlPoint
                {
                    Time             = time,
                    SampleBank       = stringSampleSet,
                    SampleVolume     = sampleVolume,
                    CustomSampleBank = customSampleBank,
                    AutoGenerated    = timingChange
                });
            }
            catch (FormatException)
            {
                Logger.Log("A timing point could not be parsed correctly and will be ignored", LoggingTarget.Runtime, LogLevel.Important);
            }
            catch (OverflowException)
            {
                Logger.Log("A timing point could not be parsed correctly and will be ignored", LoggingTarget.Runtime, LogLevel.Important);
            }
        }