public void Load(XmlDocument doc) { XmlNodeList measures = doc.SelectNodes("score-partwise/part/measure"); XmlNode attributes = measures[0]["attributes"]; int divisions = int.Parse(attributes["divisions"].InnerText); //TODO: 調に対応 //XmlNode noteNumber = attributes.SelectSingleNode("noteNumber"); //TODO: 拍子に対応 //XmlNode time = attributes.SelectSingleNode("time"); foreach (XmlNode measure in measures) { if (measure.Name != "measure") { continue; } List <MeasurableElement> measureG = new List <MeasurableElement>(); List <MeasurableElement> measureF = new List <MeasurableElement>(); for (int noteIndex = 0; noteIndex < measure.ChildNodes.Count; noteIndex++) { XmlNode note = measure.ChildNodes[noteIndex]; XmlNode nextNote = (noteIndex + 1 < measure.ChildNodes.Count) ? measure.ChildNodes[noteIndex + 1] : null; if (note.Name != "note") { continue; } int duration = int.Parse(note["duration"].InnerText); bool isDotted = false; int pow = 0; for (int i = 0; ; i++) { int d = 4 * divisions / (1 << i); if (d * 3 == duration * 2) { isDotted = true; } if (d <= duration) { pow = i; break; } } MeasurableElement formedNote; if (note["rest"] == null) { XmlNode pitch = note["pitch"]; Note.PitchName pitchName = pitchNameDictionary[pitch["step"].InnerText]; int octave = int.Parse(pitch["octave"].InnerText); Note.Accidentals accidental = Note.Accidentals.None; if (note["accidental"] != null) { string accidentalStr = note["accidental"].InnerText; switch (accidentalStr) { case "sharp": accidental = Note.Accidentals.Sharp; break; case "natural": accidental = Note.Accidentals.Natural; break; case "flat": accidental = Note.Accidentals.Flat; break; } } bool isOverlaid = (nextNote != null && nextNote["chord"] != null); formedNote = new Note((Note.NoteType)pow, pitchName, octave, isDotted, accidental, isOverlaid); } else { formedNote = new Rest((Rest.RestType)pow); } int staff = int.Parse(note["staff"].InnerText); if (staff == 1) { measureG.Add(formedNote); } else if (staff == 2) { measureF.Add(formedNote); } else { throw new NotImplementedException(); } } measuresG.Add(measureG); measuresF.Add(measureF); } for (int i = 0; i < 4; i++) { staffNotationG[i].Measures = measuresG.GetRange(i * 4, 4); staffNotationF[i].Measures = measuresF.GetRange(i * 4, 4); } }