public void GenerateSectionData(IAttributes attribute, dynamic song) { if (song.Sections == null) return; for (int i = 0; i < song.Sections.Length; i++) { var section = song.Sections[i]; var sect = new Section { Name = section.Name, Number = section.Number, StartTime = section.StartTime, EndTime = (i >= song.Sections.Length - 1) ? song.SongLength : song.Sections[i + 1].StartTime, UIName = null }; string[] sep = sect.Name.Split(new string[1] { " " }, StringSplitOptions.RemoveEmptyEntries); // process "<section><number>" used by official XML var numAlpha = new Regex("(?<Alpha>[a-zA-Z]*)(?<Numeric>[0-9]*)"); var match = numAlpha.Match(sep[0]); if (match.Groups["Numeric"].Value != "") sep = new string[] { match.Groups["Alpha"].Value, match.Groups["Numeric"].Value }; if (sep.Length == 1) { string uiName; if (SectionUINames.TryGetValue(sep[0], out uiName)) sect.UIName = uiName; else throw new InvalidDataException(String.Format("Unknown section name: {0}", sep[0])); } else { string uiName; if (SectionUINames.TryGetValue(sep[0], out uiName)) { try { if (Convert.ToInt32(sep[1]) != 0 || Convert.ToInt32(sep[1]) != 1) uiName += String.Format("|{0}", sep[1]); } catch { } sect.UIName = uiName; } else throw new InvalidDataException(String.Format("Unknown section name: {0}", sep[0])); } var phraseIterStart = -1; var phraseIterEnd = 0; var isSolo = section.Name == "solo"; if (song.PhraseIterations != null) { for (int o = 0; o < song.PhraseIterations.Length; o++) { var phraseIter = song.PhraseIterations[o]; if (phraseIterStart == -1 && phraseIter.Time >= sect.StartTime) phraseIterStart = o; if (phraseIter.Time >= sect.EndTime) break; phraseIterEnd = o; if (song.Phrases[phraseIter.PhraseId].Solo > 0) isSolo = true; } } sect.StartPhraseIterationIndex = phraseIterStart; sect.EndPhraseIterationIndex = phraseIterEnd; sect.IsSolo = isSolo; attribute.Sections.Add(sect); } }
private void GenerateSectionData(Attributes attribute, Song song) { if (song.Sections == null) { return; } for (int i = 0; i < song.Sections.Length; i++) { var section = song.Sections[i]; var sect = new Section { Name = section.Name, Number = section.Number, StartTime = section.StartTime, EndTime = (i >= song.Sections.Length - 1) ? song.SongLength : song.Sections[i + 1].StartTime, UIName = String.Format("$[6007] {0} [1]", section.Name) }; var sep = sect.Name.Split(new string[1] { " " }, StringSplitOptions.RemoveEmptyEntries); if (sep.Length == 1) { string uiName; if (SectionUINames.TryGetValue(sep[0], out uiName)) sect.UIName = uiName; } else { string uiName; if (SectionUINames.TryGetValue(sep[0], out uiName)) { try { if (Convert.ToInt32(sep[1]) != 0 || Convert.ToInt32(sep[1]) != 1) uiName += String.Format("|{0}", sep[1]); } catch { } sect.UIName = uiName; } } var phraseIterStart = -1; var phraseIterEnd = 0; var isSolo = false; if (song.PhraseIterations != null) { for (int o = 0; o < song.PhraseIterations.Length; o++) { var phraseIter = song.PhraseIterations[o]; if (phraseIterStart == -1 && phraseIter.Time >= sect.StartTime) phraseIterStart = o; if (phraseIter.Time >= sect.EndTime) break; phraseIterEnd = o; if (song.Phrases[phraseIter.PhraseId].Solo > 0) isSolo = true; } } sect.StartPhraseIterationIndex = phraseIterStart; sect.EndPhraseIterationIndex = phraseIterEnd; sect.IsSolo = isSolo; attribute.Sections.Add(sect); } }