コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Lines"></param>
        /// <param name="bms"></param>
        /// <returns></returns>
        static private Bms ParseChannel(this Bms bms)
        {
            Regex channelRegex = new Regex("#(?<bar>[0-9]{3})(?<channel>[0-9A-Za-z]{2}):(?<value>[0-9a-zA-Z]*)");

            foreach (var line in bms.ErrorLines)
            {
                Match channel = channelRegex.Match(line.Value);
                if (channel.Success)
                {
                    if (channel.Success)
                    {
                        try
                        {
                            var bar      = int.Parse(channel.Groups["bar"].Value);
                            var ch       = channel.Groups["channel"].Value;
                            var value    = channel.Groups["value"].Value;
                            var bmobject = BmObject.Read(bar, ch, value);

                            foreach (var b in bmobject)
                            {
                                bms.ChannelObjects.Add(SetMilliSecond(b, bms.RhythmObjects));
                            }
                        }
                        catch
                        {
                            throw;
                        }
                        bms.ErrorLines.Remove(line.Key);
                        continue;
                    }
                }
            }

            return(bms);
        }
コード例 #2
0
        /// <summary>
        /// bmObjectに対してミリ秒を計算します。
        /// </summary>
        /// <param name="bmObject"></param>
        /// <param name="RhythmObjects"></param>
        /// <returns></returns>
        static private BmObject SetMilliSecond(BmObject bmObject, List <BmObject> RhythmObjects)
        {
            List <BarlineObject> BarlineObjects = RhythmObjects.OfType <BarlineObject>().ToList();

            for (int i = 0; i < RhythmObjects.Count; i++)
            {
                BpmObject nowObject    = (BpmObject)RhythmObjects.First();
                BpmObject recentObject = nowObject;

                //Bpmから計算
                if (bmObject.Position.CompareTo(RhythmObjects[i].Position) > 0)
                {
                    var sub = bmObject.Position - recentObject.Position;

                    foreach (var barline in BarlineObjects)
                    {
                        if (recentObject.Position.Bar <= barline.Position.Bar && bmObject.Position.Bar > barline.Position.Bar)
                        {
                            sub.Pulse -= (1 - barline.LengthRatio);
                        }
                    }

                    bmObject.MilliSecond += sub.MilliSecond(nowObject.BpmValue);
                    break;
                }


                //Bpm変更
                if (RhythmObjects[i].GetType() == typeof(BpmObject))
                {
                    nowObject = (BpmObject)RhythmObjects[i];
                    var sub = nowObject.Position - recentObject.Position;

                    foreach (var barline in BarlineObjects)
                    {
                        if (recentObject.Position.Bar <= barline.Position.Bar && nowObject.Position.Bar > barline.Position.Bar)
                        {
                            sub.Pulse -= (1 - barline.LengthRatio);
                        }
                    }

                    bmObject.MilliSecond += sub.MilliSecond(nowObject.BpmValue);
                    recentObject          = nowObject;
                    continue;
                }

                //停止
                if (RhythmObjects[i].GetType() == typeof(StopObject))
                {
                    StopObject stopObject = (StopObject)RhythmObjects[i];
                    var        duration   = new Position(0, stopObject.stopDuration);
                    bmObject.MilliSecond += duration.MilliSecond(nowObject.BpmValue);
                    continue;
                }
            }

            Console.WriteLine($"{bmObject.Position.Bar}:{bmObject.MilliSecond}");
            return(bmObject);
        }
コード例 #3
0
        /// <summary>
        /// リズムや小節に関するチャンネル情報を読み込みます
        /// ToDO:同時の場合の順
        /// </summary>
        /// <param name="Lines"></param>
        /// <param name="bms"></param>
        /// <returns></returns>
        static private Bms ParseRhythmChannel(this Bms bms)
        {
            Regex rhythmRegex = new Regex(@"#(?<bar>[\d]{3})(?<channel>02|03|08|09):(?<value>[0-9a-zA-Z\.]*)");

            bms.RhythmObjects.Add(BpmObject.InitBpmObject(bms.Header.InitBpm));

            foreach (var line in bms.ErrorLines)
            {
                Match rhythm = rhythmRegex.Match(line.Value);
                if (rhythm.Success)
                {
                    try
                    {
                        var    bar      = int.Parse(rhythm.Groups["bar"].Value);
                        var    channel  = rhythm.Groups["channel"].Value;
                        string value    = rhythm.Groups["value"].Value;
                        var    bmobject = BmObject.Read(bar, channel, value);
                        bms.RhythmObjects.AddRange(bmobject);
                    }
                    catch
                    {
                        throw new Exception($"{line.Key}:{line.Value}");
                        throw;
                    }
                    bms.ErrorLines.Remove(line.Key);
                    continue;
                }
            }

            bms.RhythmObjects = bms.RhythmObjects

                                /*.Select(r =>
                                 * {
                                 * if (r.Channel != "08") return r;
                                 * var ch8 = (BpmObject)r;
                                 * ch8.BpmValue = bms.BpmDefinisitons[ch8.Value];
                                 * return ch8;
                                 * })*/
                                .OrderBy(r => r.Position).ToList();

            return(bms);
        }