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