Example #1
0
        public void TestRoundingErrorCompensation()
        {
            // The aim of this test is to make sure bar line generation compensates for floating-point errors.
            // The premise of the test is that we have a single timing point that should result in bar lines
            // that start at a time point that is a whole number every seventh beat.

            // The fact it's every seventh beat is important - it's a number indivisible by 2, which makes
            // it susceptible to rounding inaccuracies. In fact this was originally spotted in cases of maps
            // that met exactly this criteria.

            const int            beat_length_numerator   = 2000;
            const int            beat_length_denominator = 7;
            const TimeSignatures signature = TimeSignatures.SimpleQuadruple;

            var beatmap = new Beatmap
            {
                HitObjects = new List <HitObject>
                {
                    new HitObject {
                        StartTime = 0
                    },
                    new HitObject {
                        StartTime = 120_000
                    }
                },
Example #2
0
 IEnumerable <IDuratedItem <Measure> > IDurationField <Measure> .Intersecting(Duration duration) =>
 TimeSignatures
 .Intersecting_children(duration)
 .Select(
     simple_item =>
     new DuratedItem <Measure> {
     Duration = simple_item.Duration,
     Value    = new Measure()
 }
     );
Example #3
0
 internal TimingPoint(double offset, double beatLength, TimeSignatures timeSignature, SampleSet sampleSet,
                      bool customSamples, int volume)
 {
     this.offset        = offset;
     this.beatLength    = beatLength;
     this.timeSignature = timeSignature;
     this.sampleSet     = sampleSet;
     this.customSamples = customSamples;
     this.volume        = volume;
 }
Example #4
0
        public void Change(int absoluteTicks, TimeSignature timeSignature)
        {
            if (!TimeSignatures.ContainsKey(absoluteTicks))
            {
                TimeSignatures.Add(absoluteTicks, timeSignature);
            }

            if (Piece.TimeSignature == null)
            {
                Piece.TimeSignature = timeSignature;
            }
        }
Example #5
0
 internal ControlPoint(double offset, double beatLength, TimeSignatures timeSignature, SampleSet sampleSet,
                       CustomSampleSet customSamples, int volume, bool timingChange, EffectFlags effectFlags)
 {
     this.Offset        = offset;
     this.BeatLength    = beatLength;
     this.TimeSignature = timeSignature;
     this.SampleSet     = sampleSet == SampleSet.None ? SampleSet.Soft : sampleSet;
     this.CustomSamples = customSamples;
     this.Volume        = volume;
     this.TimingChange  = timingChange;
     this.EffectFlags   = effectFlags;
 }
        private Measure ParseMeasure(string input)
        {
            try
            {
                var ms = new Measure();

                if (input.Contains(":"))
                {
                    var options = input.Split(':');
                    foreach (var opt in options)
                    {
                        var info = opt.Trim();
                        if (info.StartsWith("Time-"))
                        {
                            ms.TimeSignature = TimeSignatures.GetTime(info.Substring(5));
                        }
                        else if (info.StartsWith("Key-"))
                        {
                            ms.KeySignature = KeySignatures.GetKey(info.Substring(4));
                        }
                        else if (info.StartsWith("Clef-"))
                        {
                            ms.Clef = Clefs.GetClef(info.Substring(5));
                        }
                    }

                    input = options.Last();
                }

                var units = input.Split(',');
                foreach (var unit in units)
                {
                    var p = unit.Trim().ToUpperInvariant();
                    if ((!p.EndsWith("QUARTER") && p.EndsWith("R")) ||
                        p.EndsWith("REST"))
                    {
                        ms.Pattern.Add(new Rest(p));
                    }
                    else
                    {
                        ms.Pattern.Add(new Note(p));
                    }
                }

                return(ms);
            }
            catch (Exception ex)
            {
                throw new UnrecognizedPatternException($"Unrecognized Measure: {input}", ex);
            }
        }
Example #7
0
        private void HandleTimeSignaturesAndMarkers()
        {
            bool timeSignatureChanged = false;
            bool markerHandled        = false;

            // Timesignature
            if (_currentIndexTimeSignatures < TimeSignatures.Count)
            {
                var nextTimeSignature = TimeSignatures.ElementAt(_currentIndexTimeSignatures);
                if (nextTimeSignature.Key <= _absoluteTicks)
                {
                    _midiChannelHandler.CurrentTimeSignature = nextTimeSignature.Value;
                    _currentIndexTimeSignatures++;
                    timeSignatureChanged = true;
                }
            }

            // Marker
            if (_currentIndexMarkers < Markers.Count)
            {
                var nextMarkers = Markers.ElementAt(_currentIndexMarkers);
                if (nextMarkers.Key <= _absoluteTicks)
                {
                    _currentIndexMarkers++;
                    var markers = nextMarkers.Value;

                    markers.ForEach(m =>
                    {
                        _markerHandler.HandleMarker(m, _midiChannelHandler.CurrentTimeSignature);
                    });
                    if (OpenBlocks == 0)
                    {
                        _midiChannelHandler.ConversionState = ConversionState.Normal;
                    }
                    else
                    {
                        _midiChannelHandler.ConversionState = ConversionState.Block;
                    }

                    markerHandled = true;
                }
            }

            // Fix
            if (timeSignatureChanged && !markerHandled && _currentIndexTimeSignatures > 1)
            {
                _markerHandler.HandleMarker(Marker.MusicBlockStart, _midiChannelHandler.CurrentTimeSignature);
                _midiChannelHandler.ConversionState = ConversionState.Block;
            }
        }
Example #8
0
        public void GenerateAttributes(TimeSignatures timeSignatures)
        {
            string firsMeasureId = _currentPart.Measure.FirstOrDefault().Number;

            foreach (var measure in _currentPart.Measure)
            {
                var currentTimeSig = timeSignatures.GetTimeSignature(measure.Number);
                int numerator      = currentTimeSig.GetNumerator();
                int denominator    = currentTimeSig.GetDenominator();
                int divisions      = GetDivisionsMeasureId(measure.Number);
                //int maxDuration = (int)((4 / (double)denominator) * (divisions * numerator));
                int fractionCursor = 0;

                for (int i = 0; i < measure.Items.Length; i++)
                {
                    string typeName = measure.Items[i].GetType().Name;

                    switch (typeName)
                    {
                    case nameof(AttributesMusicXML):
                        if (firsMeasureId == measure.Number && fractionCursor == 0)
                        {
                            AttributesChanged(measure.Items[i] as AttributesMusicXML, fractionCursor, measure.Number, true);
                        }
                        else
                        {
                            AttributesChanged(measure.Items[i] as AttributesMusicXML, fractionCursor, measure.Number);
                        }
                        break;

                    case nameof(BackupMusicXML):
                        BackupMusicXML b = (BackupMusicXML)measure.Items[i];
                        fractionCursor -= (int)b.Duration;
                        break;

                    case nameof(ForwardMusicXML):
                        ForwardMusicXML f = (ForwardMusicXML)measure.Items[i];
                        fractionCursor += (int)f.Duration;
                        break;

                    case nameof(NoteMusicXML):
                        NoteMusicXML n = (NoteMusicXML)measure.Items[i];
                        fractionCursor += n.IsChord() || n.IsGrace() ? 0 : n.GetDuration();
                        break;
                    }
                }
            }
            GenerateClefPerStaffDictionary();
        }
Example #9
0
            private void playBeatFor(int beatIndex, TimeSignatures signature)
            {
                if (beatIndex == 0)
                {
                    finishSample?.Play();
                }

                switch (signature)
                {
                case TimeSignatures.SimpleTriple:
                    switch (beatIndex % 6)
                    {
                    case 0:
                        kickSample?.Play();
                        break;

                    case 3:
                        clapSample?.Play();
                        break;

                    default:
                        hatSample?.Play();
                        break;
                    }

                    break;

                case TimeSignatures.SimpleQuadruple:
                    switch (beatIndex % 4)
                    {
                    case 0:
                        kickSample?.Play();
                        break;

                    case 2:
                        clapSample?.Play();
                        break;

                    default:
                        hatSample?.Play();
                        break;
                    }

                    break;
                }
            }
        internal void ChangeTimeSignature(TimeSignatures ts)
        {
            if (AudioEngine.ControlPoints.Count == 0)
            {
                return;
            }

            GameBase.EditorControl.TimeSignatureChanged(ts);

            ControlPoint activeTimingPoint = AudioEngine.ActiveTimingPoint;

            if (activeTimingPoint == null)
            {
                return;
            }

            changeManager.BeginAction(ChangeType.Timing, ActionType.ChangeSignature, activeTimingPoint);

            AudioEngine.TimeSignature = ts;

            editor.Timing.FixInheritSignatures();
            changeManager.FinishAction();
        }
Example #11
0
        private void handleTimingPoints(Beatmap beatmap, string val)
        {
            string[] split = val.Split(',');

            double time       = double.Parse(split[0].Trim(), NumberFormatInfo.InvariantInfo);
            double beatLength = double.Parse(split[1].Trim(), NumberFormatInfo.InvariantInfo);

            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]);
            }

            //SampleBank sampleBank = SampleBank.Default;
            //if (split.Length >= 5)
            //    sampleBank = (SampleBank)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)
            {
                int effectFlags = int.Parse(split[7]);
                kiaiMode = (effectFlags & 1) > 0;
                omitFirstBarSignature = (effectFlags & 8) > 0;
            }

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

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

            beatmap.TimingInfo.ControlPoints.Add(new ControlPoint
            {
                Time             = time,
                BeatLength       = beatLength,
                SpeedMultiplier  = beatLength < 0 ? -beatLength / 100.0 : 1,
                TimingChange     = timingChange,
                TimeSignature    = timeSignature,
                SampleBank       = stringSampleSet,
                SampleVolume     = sampleVolume,
                KiaiMode         = kiaiMode,
                OmitFirstBarLine = omitFirstBarSignature
            });
        }
Example #12
0
 public IEnumerable <IDuratedItem <TimeSignature> > TimeSignaturesInTime(Duration duration) =>
 TimeSignatures.Intersecting(duration);
Example #13
0
        private void handleTimingPoints(Sheetmusic sheetmusic, string line)
        {
            // 音 時間 長度 加速 三分/四分 音量 時間改變
            string[] split = line.Split(',');

            int   column          = int.Parse(split[0].Trim());
            float time            = float.Parse(split[1].Trim());
            float noteLength      = float.Parse(split[2].Trim());
            float speedMultiplier = noteLength < 0 ? 100f / -noteLength : 1;

            TimeSignatures timeSignature = TimeSignatures.SimpleQuadruple;

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

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

            //SampleBank sampleBank = SampleBank.Default;
            //if (split.Length >= 5)
            //    sampleBank = (SampleBank)int.Parse(split[4]);

            int sampleVolume = defaultSampleVolume;

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

            bool timingChange = true;

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

            //bool kiaiMode = false;
            //bool omitFirstBarSignature = false;
            //if (split.Length >= 8) {
            //    int effectFlags = int.Parse(split[7]);
            //    kiaiMode = (effectFlags & 1) > 0;
            //    omitFirstBarSignature = (effectFlags & 8) > 0;
            //}

            //string stringSampleSet = sampleSet.ToString().ToLower();
            //if (stringSampleSet == @"none")
            //    stringSampleSet = @"normal";

            //DifficultyControlPoint difficultyPoint = beatmap.ControlPointInfo.DifficultyPointAt(time);
            //SoundControlPoint soundPoint = beatmap.ControlPointInfo.SoundPointAt(time);
            //EffectControlPoint effectPoint = beatmap.ControlPointInfo.EffectPointAt(time);

            if (timingChange)
            {
                sheetmusic.ControlPointInfo.TimingControlPoints.Add(new TimingControlPoint {
                    Column        = column,
                    Time          = time,
                    NoteLength    = noteLength,
                    TimeSignature = timeSignature
                });
            }

            //if (speedMultiplier != difficultyPoint.SpeedMultiplier) {
            //    beatmap.ControlPointInfo.DifficultyPoints.RemoveAll(x => x.Time == time);
            //    beatmap.ControlPointInfo.DifficultyPoints.Add(new DifficultyControlPoint {
            //        Time = time,
            //        SpeedMultiplier = speedMultiplier
            //    });
            //}

            //if (stringSampleSet != soundPoint.SampleBank || sampleVolume != soundPoint.SampleVolume) {
            //    beatmap.ControlPointInfo.SoundPoints.Add(new SoundControlPoint {
            //        Time = time,
            //        SampleBank = stringSampleSet,
            //        SampleVolume = sampleVolume
            //    });
            //}

            //if (kiaiMode != effectPoint.KiaiMode || omitFirstBarSignature != effectPoint.OmitFirstBarLine) {
            //    beatmap.ControlPointInfo.EffectPoints.Add(new EffectControlPoint {
            //        Time = time,
            //        KiaiMode = kiaiMode,
            //        OmitFirstBarLine = omitFirstBarSignature
            //    });
            //}
        }
Example #14
0
        private void handleTimingPoints(Beatmap beatmap, string line)
        {
            string[] split = line.Split(',');

            double time            = 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]);
            }

            //SampleBank sampleBank = SampleBank.Default;
            //if (split.Length >= 5)
            //    sampleBank = (SampleBank)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)
            {
                int effectFlags = int.Parse(split[7]);
                kiaiMode = (effectFlags & 1) > 0;
                omitFirstBarSignature = (effectFlags & 8) > 0;
            }

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

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

            DifficultyControlPoint difficultyPoint = beatmap.ControlPointInfo.DifficultyPointAt(time);
            SoundControlPoint      soundPoint      = beatmap.ControlPointInfo.SoundPointAt(time);
            EffectControlPoint     effectPoint     = beatmap.ControlPointInfo.EffectPointAt(time);

            if (timingChange)
            {
                beatmap.ControlPointInfo.TimingPoints.Add(new TimingControlPoint
                {
                    Time          = time,
                    BeatLength    = beatLength,
                    TimeSignature = timeSignature
                });
            }

            if (speedMultiplier != difficultyPoint.SpeedMultiplier)
            {
                beatmap.ControlPointInfo.DifficultyPoints.RemoveAll(x => x.Time == time);
                beatmap.ControlPointInfo.DifficultyPoints.Add(new DifficultyControlPoint
                {
                    Time            = time,
                    SpeedMultiplier = speedMultiplier
                });
            }

            if (stringSampleSet != soundPoint.SampleBank || sampleVolume != soundPoint.SampleVolume)
            {
                beatmap.ControlPointInfo.SoundPoints.Add(new SoundControlPoint
                {
                    Time         = time,
                    SampleBank   = stringSampleSet,
                    SampleVolume = sampleVolume
                });
            }

            if (kiaiMode != effectPoint.KiaiMode || omitFirstBarSignature != effectPoint.OmitFirstBarLine)
            {
                beatmap.ControlPointInfo.EffectPoints.Add(new EffectControlPoint
                {
                    Time             = time,
                    KiaiMode         = kiaiMode,
                    OmitFirstBarLine = omitFirstBarSignature
                });
            }
        }
Example #15
0
        public RhythmTrack(
            StorageObjectID storageobjectID,
            EditorFile file
            ) :
            base(
                storageobjectID,
                file,
                null     //TOOD
                )
        {
            obj = this.Object();

            binder_timesignatures =
                TimeSignatures.Bind(
                    obj.GetOrMake("time-signatures").ID,
                    file
                    );

            binder_timesignatures.Deserializer = timesig_obj => {
                using (var stream = timesig_obj.OpenRead()) {
                    using (var br = new BinaryReader(stream)) {
                        var simples = new Simple[br.ReadInt32()];

                        for (int i = 0; i < simples.Length; i++)
                        {
                            var upper = br.ReadInt32();
                            var lower = br.ReadInt32();

                            simples[i] = new Simple(upper, lower);
                        }

                        return(new TimeSignature(simples));
                    }
                }
            };

            binder_timesignatures.Serializer = (timesig_obj, timesig) => {
                using (var stream = timesig_obj.OpenWrite()) {
                    using (var bw = new BinaryWriter(stream)) {
                        bw.Write(timesig.Simples.Count);

                        for (int i = 0; i < timesig.Simples.Count; i++)
                        {
                            var simple = timesig.Simples[i];

                            bw.Write(simple.Upper);
                            bw.Write(simple.Lower);
                        }
                    }
                }
            };

            binder_metersignatures =
                MeterSignatures.Bind(
                    obj.GetOrMake("meter-signatures").ID,
                    file
                    );

            binder_metersignatures.Deserializer = metersig_obj => {
                using (var stream = metersig_obj.OpenRead()) {
                    using (var br = new BinaryReader(stream)) {
                        var cells = new Cell[br.ReadInt32()];

                        for (int i = 0; i < cells.Length; i++)
                        {
                            var length = Time.FromTicks(br.ReadInt32());
                            var stress = br.ReadSingle();

                            cells[i] = new Cell {
                                Length = length,
                                Stress = stress
                            };
                        }

                        var totallength =
                            cells.Aggregate(
                                Time.Zero,
                                (acc, cell) => acc + cell.Length
                                );

                        return(new MeterSignature(totallength, cells));
                    }
                }
            };

            binder_metersignatures.Serializer = (metersig_obj, metersig) => {
                using (var stream = metersig_obj.OpenWrite()) {
                    using (var bw = new BinaryWriter(stream)) {
                        bw.Write(metersig.Cells.Count);

                        for (int i = 0; i < metersig.Cells.Count; i++)
                        {
                            var cell = metersig.Cells[i];

                            bw.Write(cell.Length.Ticks);
                            bw.Write(cell.Stress);
                        }
                    }
                }
            };
        }
Example #16
0
 IEnumerable <IDuratedItem <Simple> > IDurationField <Simple> .Intersecting(Time point) =>
 TimeSignatures.Intersecting_children(point);
Example #17
0
 IEnumerable <IDuratedItem <Simple> > IDurationField <Simple> .Intersecting(Duration duration) =>
 TimeSignatures.Intersecting_children(duration);
Example #18
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)
            {
            }
        }
Example #19
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);
            }
        }
        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)
            {
                LegacyEffectFlags effectFlags = (LegacyEffectFlags)Parsing.ParseInt(split[7]);
                kiaiMode = effectFlags.HasFlag(LegacyEffectFlags.Kiai);
                omitFirstBarSignature = effectFlags.HasFlag(LegacyEffectFlags.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);
            }

#pragma warning disable 618
            addControlPoint(time, new LegacyDifficultyControlPoint(beatLength)
#pragma warning restore 618
            {
                SpeedMultiplier = speedMultiplier,
            }, timingChange);

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

            addControlPoint(time, new LegacySampleControlPoint
            {
                SampleBank       = stringSampleSet,
                SampleVolume     = sampleVolume,
                CustomSampleBank = customSampleBank,
            }, timingChange);
        }
Example #21
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();
            }
        }
Example #22
0
 internal void TimeSignatureChanged(TimeSignatures ts)
 {
     signature34.Checked = ts == TimeSignatures.SimpleTriple;
     signature44.Checked = ts == TimeSignatures.SimpleQuadruple;
 }
        public IEnumerable <GuitarMessage> GetByDifficulty(GuitarDifficulty diff)
        {
            var ret = new List <GuitarMessage>();

            foreach (var messageType in GetAllMessageTypes())
            {
                switch (messageType)
                {
                case GuitarMessageType.GuitarHandPosition:
                    ret.AddRange(HandPositions.Where(x => diff.HasFlag(x.Difficulty)));
                    break;

                case GuitarMessageType.GuitarChordName:
                    ret.AddRange(ChordNames.Where(x => diff.HasFlag(x.Difficulty)));
                    break;

                case GuitarMessageType.GuitarTextEvent:
                    ret.AddRange(TextEvents.Where(x => diff.HasFlag(x.Difficulty)));
                    break;

                case GuitarMessageType.GuitarTrainer:
                    ret.AddRange(Trainers.Where(x => diff.HasFlag(x.Difficulty)));
                    break;

                case GuitarMessageType.GuitarChordStrum:
                    ret.AddRange(ChordStrums.Where(x => diff.HasFlag(x.Difficulty)));
                    break;

                case GuitarMessageType.GuitarChord:
                    ret.AddRange(Chords.Where(x => diff.HasFlag(x.Difficulty)));
                    break;

                case GuitarMessageType.GuitarNote:
                    ret.AddRange(Notes.Where(x => diff.HasFlag(x.Difficulty)));
                    break;

                case GuitarMessageType.GuitarPowerup:
                    ret.AddRange(Powerups.Where(x => diff.HasFlag(x.Difficulty)));
                    break;

                case GuitarMessageType.GuitarSolo:
                    ret.AddRange(Solos.Where(x => diff.HasFlag(x.Difficulty)));
                    break;

                case GuitarMessageType.GuitarTempo:
                    ret.AddRange(Tempos.Where(x => diff.HasFlag(x.Difficulty)));
                    break;

                case GuitarMessageType.GuitarTimeSignature:
                    ret.AddRange(TimeSignatures.Where(x => diff.HasFlag(x.Difficulty)));
                    break;

                case GuitarMessageType.GuitarArpeggio:
                    ret.AddRange(Arpeggios.Where(x => diff.HasFlag(x.Difficulty)));
                    break;

                case GuitarMessageType.GuitarBigRockEnding:
                    ret.AddRange(BigRockEndings.Where(x => diff.HasFlag(x.Difficulty)));
                    break;

                case GuitarMessageType.GuitarBigRockEndingSubMessage:

                    break;

                case GuitarMessageType.GuitarSingleStringTremelo:
                    ret.AddRange(SingleStringTremelos.Where(x => diff.HasFlag(x.Difficulty)));
                    break;

                case GuitarMessageType.GuitarMultiStringTremelo:
                    ret.AddRange(MultiStringTremelos.Where(x => diff.HasFlag(x.Difficulty)));
                    break;

                case GuitarMessageType.GuitarSlide:
                    ret.AddRange(Slides.Where(x => diff.HasFlag(x.Difficulty)));
                    break;

                case GuitarMessageType.GuitarHammeron:
                    ret.AddRange(Hammerons.Where(x => diff.HasFlag(x.Difficulty)));
                    break;

                default:
                    ("unknown message: " + messageType).OutputDebug();
                    break;
                }
            }

            return(ret);
        }