Skip to content

Commit

Permalink
Fix MusicXmlParser
Browse files Browse the repository at this point in the history
  • Loading branch information
ChainsManipulator committed Mar 5, 2024
1 parent 1d56585 commit 9a0ba96
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Libiada.Core/Music/MusicXml/MusicXmlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,21 +242,26 @@ private List<ValueNote> ParseNotes(XmlNode measureNode)
{
if (measureChild.Name == "note")
{
foreach (XmlNode chordChild in measureChild.Clone().ChildNodes)
var measureChildClone = measureChild.Clone();
foreach (XmlNode chordChild in measureChildClone.ChildNodes)
{
if (chordChild.Name == "chord")
{
// если найден "аккорд", то добавим текущую ноту к предыдущей уже мультиноте
notes[notes.Count - 1].AddPitch(ParsePitch(measureChild.Clone()));
if (notes[notes.Count - 1].Tie != ParseTie(measureChild.Clone()))
var chordPitch = ParsePitch(measureChildClone);
if(chordPitch != null) notes[notes.Count - 1].AddPitch(chordPitch);
if (notes[notes.Count - 1].Tie != ParseTie(measureChildClone))
{
notes[notes.Count - 1].Tie = Tie.None;
}

break;
}

var note = new ValueNote(ParsePitch(measureChild.Clone()), ParseDuration(measureChild.Clone()), ParseTriplet(measureChild.Clone()), ParseTie(measureChild.Clone()));
var pitch = ParsePitch(measureChildClone);
ValueNote note = pitch == null
? new ValueNote(ParseDuration(measureChildClone), ParseTriplet(measureChildClone), ParseTie(measureChildClone))
: new ValueNote(pitch, ParseDuration(measureChildClone), ParseTriplet(measureChildClone), ParseTie(measureChildClone));
note.Pitches.Sort();
notes.Add(note);
hasNotes = true;
Expand Down Expand Up @@ -287,7 +292,7 @@ private List<ValueNote> ParseNotes(XmlNode measureNode)
/// <exception cref="Exception">
/// Thrown if pitch doesn't have Octave or step.
/// </exception>
private Pitch ParsePitch(XmlNode noteNode)
private Pitch? ParsePitch(XmlNode noteNode)
{
string childName = string.Empty;
foreach (XmlNode noteChild in noteNode.ChildNodes)
Expand Down

0 comments on commit 9a0ba96

Please sign in to comment.