Search in sources :

Example 1 with MxlEditorialVoice

use of com.xenoage.zong.musicxml.types.groups.MxlEditorialVoice in project Zong by Xenoage.

the class MxlForward method read.

@NonNull
public static MxlForward read(XmlReader reader) {
    Integer duration = null;
    MxlEditorialVoice editorialVoice = new MxlEditorialVoice();
    while (reader.openNextChildElement()) {
        String n = reader.getElementName();
        if (n.equals("duration"))
            duration = Parser.parseInt(reader.getText());
        else
            editorialVoice.readElement(reader);
        reader.closeElement();
    }
    if (duration == null)
        throw reader.dataException("duration unknown");
    if (false == editorialVoice.isUsed())
        editorialVoice = null;
    return new MxlForward(duration, editorialVoice);
}
Also used : MxlEditorialVoice(com.xenoage.zong.musicxml.types.groups.MxlEditorialVoice) NonNull(com.xenoage.utils.annotations.NonNull)

Example 2 with MxlEditorialVoice

use of com.xenoage.zong.musicxml.types.groups.MxlEditorialVoice 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 3 with MxlEditorialVoice

use of com.xenoage.zong.musicxml.types.groups.MxlEditorialVoice in project Zong by Xenoage.

the class ChordReader method readToContext.

/**
 * Reads the given chord, consisting of the given list of note elements,
 * including beams, notations and lyrics.
 * All but the first given note must have a chord-element inside.
 */
public void readToContext(Context context) {
    this.context = context;
    readFirstNote();
    // find staff
    // (not supported yet: multi-staff chords)
    staff = notNull(mxlFirstNote.getStaff(), 1) - 1;
    // find voice
    // TODO: might not exist! we have to use a helper algorithm to determine the right voice
    // then, see MusicReader class documentation.
    int staffVoice = 0;
    mxlVoice = null;
    MxlEditorialVoice editorialVoice = mxlFirstNote.getEditorialVoice();
    if (editorialVoice != null) {
        mxlVoice = editorialVoice.getVoice();
        if (mxlVoice != null) {
            try {
                staffVoice = context.getVoice(staff, mxlVoice);
            } catch (MusicReaderException ex) {
                context.reportError(ex.getMessage());
                return;
            }
        }
    }
    // write chord or rest
    boolean isWritten = false;
    if (chordOrRest != null)
        isWritten = context.writeVoiceElement(chordOrRest, staff, staffVoice);
    // more details for chord
    if (isWritten && chord != null) {
        // check if chord could be written. if not, return
        if (getMP(chord) == null)
            return;
        readFirstNoteNotations();
        readOtherChordNotes();
        readStem();
        readBeams();
        new LyricReader(mxlNotes).readToChord(chord);
    }
    if (chordOrRest != null)
        context.moveCursorForward(chordOrRest.getDuration());
}
Also used : MusicReaderException(com.xenoage.zong.io.musicxml.in.util.MusicReaderException) MxlEditorialVoice(com.xenoage.zong.musicxml.types.groups.MxlEditorialVoice)

Aggregations

MxlEditorialVoice (com.xenoage.zong.musicxml.types.groups.MxlEditorialVoice)3 NonNull (com.xenoage.utils.annotations.NonNull)2 MusicReaderException (com.xenoage.zong.io.musicxml.in.util.MusicReaderException)1 MxlNoteTypeValue (com.xenoage.zong.musicxml.types.enums.MxlNoteTypeValue)1 ArrayList (java.util.ArrayList)1