Search in sources :

Example 1 with MxlNoteTypeValue

use of com.xenoage.zong.musicxml.types.enums.MxlNoteTypeValue in project Zong by Xenoage.

the class MxlNote method read.

@NonNull
public static MxlNote read(XmlReader reader) {
    MxlNoteContent content = null;
    MxlInstrument instrument = null;
    MxlEditorialVoice editorialVoice = new MxlEditorialVoice();
    MxlNoteTypeValue noteType = null;
    int dots = 0;
    MxlStem stem = null;
    Integer staff = null;
    List<MxlBeam> beams = null;
    List<MxlNotations> notations = null;
    List<MxlLyric> lyrics = null;
    while (reader.openNextChildElement()) {
        String n = reader.getElementName();
        // but, be tolerant for errors, and also accept late grace or cue elements
        if (n.equals(MxlGraceNote.elemName)) {
            MxlGraceNote graceNote = MxlGraceNote.read(reader);
            if (// grace element too late, but accept it
            content instanceof MxlNormalNote)
                graceNote.setFullNote(((MxlNormalNote) content).getFullNote());
            content = graceNote;
        } else if (n.equals(MxlCueNote.elemName)) {
            MxlCueNote cueNote = MxlCueNote.read();
            if (// cue element too late, but accept it
            content instanceof MxlNormalNote)
                cueNote.setFullNote(((MxlNormalNote) content).getFullNote());
            content = cueNote;
        } else if (content == null) {
            content = MxlNormalNote.read();
        }
        // read content of child elements
        switch(n) {
            case MxlStem.elemName:
                stem = MxlStem.read(reader);
                break;
            case "staff":
                staff = reader.getTextIntNotNull();
                break;
            case MxlBeam.elemName:
                if (beams == null)
                    beams = new ArrayList<>();
                beams.add(MxlBeam.read(reader));
                break;
            case MxlInstrument.elemName:
                instrument = MxlInstrument.read(reader);
                break;
            case MxlNotations.elemName:
                if (notations == null)
                    notations = new ArrayList<>();
                notations.add(MxlNotations.read(reader));
                break;
            case MxlLyric.elemName:
                if (lyrics == null)
                    lyrics = new ArrayList<>();
                lyrics.add(MxlLyric.read(reader));
                break;
            case "type":
                noteType = MxlNoteTypeValue.read(reader.getText());
                break;
            case "dot":
                dots++;
                break;
            default:
                boolean read = content.readElement(reader);
                if (!read)
                    editorialVoice.readElement(reader);
                break;
        }
        reader.closeElement();
    }
    content.check(reader);
    if (false == editorialVoice.isUsed())
        editorialVoice = null;
    return new MxlNote(content, instrument, editorialVoice, noteType, dots, stem, staff, beams, notations, lyrics);
}
Also used : ArrayList(java.util.ArrayList) MxlEditorialVoice(com.xenoage.zong.musicxml.types.groups.MxlEditorialVoice) MxlNoteTypeValue(com.xenoage.zong.musicxml.types.enums.MxlNoteTypeValue) NonNull(com.xenoage.utils.annotations.NonNull)

Example 2 with MxlNoteTypeValue

use of com.xenoage.zong.musicxml.types.enums.MxlNoteTypeValue in project Zong by Xenoage.

the class MxlMetronome method read.

/**
 * Returns null, if the given element contains an unsupported metronome type.
 */
@MaybeNull
public static MxlMetronome read(XmlReader reader) {
    // attributes
    MxlPrintStyle printStyle = MxlPrintStyle.read(reader);
    // elements
    String sBeatUnit = null;
    int dotsCount = 0;
    Integer perMinute = null;
    while (reader.openNextChildElement()) {
        String n = reader.getElementName();
        switch(n) {
            case "beat-unit":
                sBeatUnit = reader.getText();
                break;
            case "beat-unit-dot":
                dotsCount++;
                break;
            case "per-minute":
                perMinute = parseIntegerNull(reader.getText());
                break;
        }
        reader.closeElement();
    }
    if (sBeatUnit != null && perMinute != null) {
        MxlNoteTypeValue beatUnit = MxlNoteTypeValue.read(sBeatUnit);
        return new MxlMetronome(beatUnit, dotsCount, perMinute, printStyle);
    } else {
        return null;
    }
}
Also used : MxlNoteTypeValue(com.xenoage.zong.musicxml.types.enums.MxlNoteTypeValue) MxlPrintStyle(com.xenoage.zong.musicxml.types.attributes.MxlPrintStyle) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Aggregations

MxlNoteTypeValue (com.xenoage.zong.musicxml.types.enums.MxlNoteTypeValue)2 MaybeNull (com.xenoage.utils.annotations.MaybeNull)1 NonNull (com.xenoage.utils.annotations.NonNull)1 MxlPrintStyle (com.xenoage.zong.musicxml.types.attributes.MxlPrintStyle)1 MxlEditorialVoice (com.xenoage.zong.musicxml.types.groups.MxlEditorialVoice)1 ArrayList (java.util.ArrayList)1