// ブロック終了まで進める private void SkipUntilBlockEnd(MmlFileReader m) { while (true) { m.SkipSkipable(); var ct = m.FetchType(); if (ct == MmlCharactorType.GeneralChanacter || ct == MmlCharactorType.Separator) { VerboseWriteLine($"{m.GetPosition()} {ct}"); m.SkipType(); continue; } if (ct == MmlCharactorType.Eof) { Error.Add(ErrorData.Type.BlockEndNotFound); return; } if (ct == MmlCharactorType.BlockEnd) { m.SkipType(); m.StepNextLine(); return; } Error.Add(ErrorData.Type.UnknownCharacterUsed); return; } }
// 音色を読み出す private int[] ReadToneParameter(MmlFileReader m) { List <int> Parameter = new List <int>(); bool SkipSeparator = false; while (true) { m.SkipSkipable(); var ct = m.FetchType(); // EOF if (ct == MmlCharactorType.Eof) { Error.Add(ErrorData.Type.BlockEndNotFound); return(null); } // Separator if (ct == MmlCharactorType.Separator) { VerboseWriteLine($"{m.GetPosition()} {ct}"); if (!SkipSeparator) { SkipSeparator = false; Parameter.Add(0); } m.SkipType(); continue; } if (m.IsLineEnd(ct) || m.IsComment(ct)) { m.SkipType(); continue; } if (ct == MmlCharactorType.GeneralChanacter) { SkipSeparator = true; VerboseWriteLine($"{m.GetPosition()} {ct}"); Parameter.Add(ReadParameter(m)); continue; } if (ct == MmlCharactorType.BlockEnd) { m.SkipType(); m.StepNextLine(); return(Parameter.ToArray()); } Error.Add(ErrorData.Type.UnknownCharacterUsed); return(null); } }
/// <summary> /// トラックコマンド読み出し /// </summary> private void ReadTrackText(string Name, MmlFileReader m) { var ct = SkipSpaceAndFetch(m); var TrackData = Song.GetTrack(Name); if (TrackData == null) { return; } bool Track = false; bool Block = false; // トラック if (ct == MmlCharactorType.GeneralChanacter) { Track = true; } if (ct == MmlCharactorType.BlockStart) { Block = true; Track = true; } if (Track) { if (Block) { m.SkipType(); } ReadCommandUntilNextTrack(TrackData, m, Block); return; } Error.Add(ErrorData.Type.UnknownCharacterUsed); }
// トラック private void ReadTrack(MmlFileReader m) { List <string> TrackName = new List <string>(); while (true) { var Name = m.ReadName(); TrackName.Add(Name); m.SkipIfSpace(); var ct = m.FetchType(); if (ct == MmlCharactorType.Separator) { m.SkipType(); continue; } break; } var TrackPos = m.GetPosition(); for (var i = 0; i < TrackName.Count; i++) { if (i > 0) { m.SetPosition(TrackPos); } var Name = TrackName[i]; VerboseWriteLine($"--- Track: {Name} ---"); ReadTrackText(Name, m); } }
private void ParseMmlFile(string filename) { Song = new SongData(); Song.Error = Error; var m = new MmlFileReader(); Error.SetFileReader(m); if (!m.Load(filename)) { Error.Add(ErrorData.Type.FileNotFound); return; } while (!m.IsEof() && !Error.HasError) { // 行頭 var ct = m.FetchType(); // コメントブロック終了時の行は読み飛ばす if (ct == MmlCharactorType.CommentEnd) { m.SkipType(); m.StepNextLine(); } if (m.IsComment(ct)) { m.SkipType(); continue; } if (ct == MmlCharactorType.NextLine || ct == MmlCharactorType.Eof) { m.SkipType(); continue; } if (ct != MmlCharactorType.GeneralChanacter) { Error.Add(ErrorData.Type.LineHeaderIsWrong); continue; } ReadItem(m); } }
// ブロック開始まで進める private bool SkipUntilBlockStart(MmlFileReader m) { m.SkipSkipable(); var ct = m.FetchType(); if (ct != MmlCharactorType.BlockStart) { Error.Add(ErrorData.Type.BlockStartNotFound); return(false); } m.SkipType(); return(true); }
/// <summary> /// トラック処理 /// </summary> private void ReadCommandUntilNextTrack(TrackData Track, MmlFileReader m, bool Block = false) { while (!Error.HasError) { var ct = m.FetchType(); // EOF if (ct == MmlCharactorType.Eof) { if (Block) { Error.Add(ErrorData.Type.BlockEndNotFound); } return; } // 改行 if (ct == MmlCharactorType.NextLine) { m.SkipType(); if (Block) { continue; } return; } // 改行 if (m.IsSpace(ct) || m.IsComment(ct)) { m.SkipType(); continue; } // ブロック終了 if (ct == MmlCharactorType.BlockEnd) { if (!Block) { Error.Add(ErrorData.Type.UnknownCharacterUsed); return; } m.SkipType(); m.StepNextLine(); return; } // トラックコマンド if (ct == MmlCharactorType.GeneralChanacter) { Command.Make(Song, Track, m); var lc = Track.GetLastCommand(); if (lc != null) { VerboseWriteLine(lc.ToString()); } } else { Error.Add(ErrorData.Type.UnknownCharacterUsed); return; } } }