Search in sources :

Example 1 with MxlNote

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

the class MeasureReader method readToContext.

/**
 * Reads the given measure element.
 */
public static void readToContext(MxlMeasure mxlMeasure, int measureIndex, Context context) {
    // begin a new measure
    context.beginNewMeasure(measureIndex);
    // list all elements
    List<MxlMusicDataContent> content = mxlMeasure.getMusicData().getContent();
    for (int i = 0; i < content.size(); i++) {
        // i may be modified within this loop
        MxlMusicDataContent mxlMDC = content.get(i);
        switch(mxlMDC.getMusicDataContentType()) {
            case Note:
                {
                    MxlNote mxlNote = ((MxlNote) mxlMDC);
                    // when it is a chord, ignore it, because we did already read it
                    if (mxlNote.getContent().getFullNote().isChord()) {
                        continue;
                    }
                    // instrument change?
                    MxlInstrument mxlInstrument = mxlNote.getInstrument();
                    if (mxlInstrument != null) {
                        String instrumentID = mxlInstrument.getId();
                        if (context.getInstrumentID() == null || !context.getInstrumentID().equals(instrumentID)) {
                            // instrument change detected!
                            context.writeInstrumentChange(instrumentID);
                        }
                    }
                    // collect all following notes which have a chord-element
                    // inbetween there may be direction elements, so we collect the
                    // notes until the first non-chord or non-direction element and after
                    // that go on at the current position + 1
                    List<MxlNote> mxlNotes = alist(mxlNote);
                    for (int i2 = i + 1; i2 < content.size(); i2++) {
                        MxlMusicDataContent mxlMDC2 = content.get(i2);
                        boolean goOn = false;
                        if (mxlMDC2.getMusicDataContentType() == MxlMusicDataContentType.Note) {
                            MxlNote mxlNote2 = (MxlNote) mxlMDC2;
                            if (mxlNote2.getContent().getFullNote().isChord()) {
                                mxlNotes.add(mxlNote2);
                                goOn = true;
                            }
                        } else if (mxlMDC2.getMusicDataContentType() == MxlMusicDataContentType.Direction) {
                            goOn = true;
                        }
                        if (!goOn)
                            break;
                    }
                    new ChordReader(mxlNotes).readToContext(context);
                    break;
                }
            case Attributes:
                new AttributesReader((MxlAttributes) mxlMDC).readToContext(context);
                break;
            case Backup:
                readBackupToContext((MxlBackup) mxlMDC, context);
                break;
            case Forward:
                readForwardToContext((MxlForward) mxlMDC, context);
                break;
            case Print:
                new PrintReader((MxlPrint) mxlMDC).readToContext(context);
                break;
            case Direction:
                new DirectionReader((MxlDirection) mxlMDC).readToContext(context);
                break;
            case Barline:
                new BarlineReader((MxlBarline) mxlMDC).readToContext(context);
                break;
        }
    }
}
Also used : MxlInstrument(com.xenoage.zong.musicxml.types.MxlInstrument) MxlPrint(com.xenoage.zong.musicxml.types.MxlPrint) MxlBarline(com.xenoage.zong.musicxml.types.MxlBarline) MxlPrint(com.xenoage.zong.musicxml.types.MxlPrint) MxlDirection(com.xenoage.zong.musicxml.types.MxlDirection) MxlNote(com.xenoage.zong.musicxml.types.MxlNote) MxlMusicDataContent(com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent) MxlAttributes(com.xenoage.zong.musicxml.types.MxlAttributes) List(java.util.List)

Example 2 with MxlNote

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

the class ChordReader method addChordNote.

/**
 * Reads the given note element, which is part of
 * a chord (but not the first note element of the chord), and adds it to the given chord.
 * Also the notations of this note are read.
 */
private static void addChordNote(Context context, MxlNote mxlNote, Chord chord, int staffIndexInPart) {
    // only pitch is interesting for us, since we do not allow
    // different durations for notes within a chord or other strange stuff
    MxlFullNoteContent mxlFNC = mxlNote.getContent().getFullNote().getContent();
    if (mxlFNC.getFullNoteContentType() == MxlFullNoteContentType.Pitch) {
        Pitch pitch = ((MxlPitch) mxlFNC).getPitch();
        Note note = new Note(pitch);
        chord.addNote(note);
        // notations
        if (mxlNote.getNotations() != null) {
            new NotationsReader(mxlNote.getNotations()).readToNote(chord, chord.getNotes().indexOf(note), staffIndexInPart, context);
        }
    }
}
Also used : MxlPitch(com.xenoage.zong.musicxml.types.MxlPitch) MxlNormalNote(com.xenoage.zong.musicxml.types.choice.MxlNormalNote) Note(com.xenoage.zong.core.music.chord.Note) MxlFullNote(com.xenoage.zong.musicxml.types.groups.MxlFullNote) MxlNote(com.xenoage.zong.musicxml.types.MxlNote) MxlCueNote(com.xenoage.zong.musicxml.types.choice.MxlCueNote) MxlGraceNote(com.xenoage.zong.musicxml.types.choice.MxlGraceNote) Pitch(com.xenoage.zong.core.music.Pitch) MxlPitch(com.xenoage.zong.musicxml.types.MxlPitch) MxlFullNoteContent(com.xenoage.zong.musicxml.types.choice.MxlFullNoteContent)

Example 3 with MxlNote

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

the class LyricReader method readLyrics.

private List<Lyric> readLyrics() {
    // not supported yet: in MusicXML also rests can have lyrics. see measure 36 in Echigo-Jishi
    List<Lyric> ret = alist();
    for (MxlNote mxlNote : mxlNotes) {
        for (MxlLyric mxlLyric : it(mxlNote.getLyrics())) {
            int verse = readVerse(mxlLyric);
            MxlLyricContentType mxlLCType = mxlLyric.getContent().getLyricContentType();
            if (mxlLCType == MxlLyricContentType.SyllabicText) {
                MxlSyllabicText mxlSyllabicText = (MxlSyllabicText) mxlLyric.getContent();
                SyllableType syllableType = readSyllableType(mxlLyric);
                // the next element must be the text element
                ret.add(new Lyric(Companion.ut(mxlSyllabicText.getText().getValue()), syllableType, verse));
            } else if (mxlLCType == MxlLyricContentType.Extend) {
                // extend - TODO: extension to next chord!
                ret.add(Lyric.Companion.lyricExtend(verse));
            }
        }
    }
    return ret;
}
Also used : MxlLyric(com.xenoage.zong.musicxml.types.MxlLyric) MxlLyric(com.xenoage.zong.musicxml.types.MxlLyric) Lyric(com.xenoage.zong.core.music.lyric.Lyric) SyllableType(com.xenoage.zong.core.music.lyric.SyllableType) MxlSyllabicText(com.xenoage.zong.musicxml.types.MxlSyllabicText) MxlNote(com.xenoage.zong.musicxml.types.MxlNote) MxlLyricContentType(com.xenoage.zong.musicxml.types.choice.MxlLyricContent.MxlLyricContentType)

Example 4 with MxlNote

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

the class Test01c method test.

@Test
public void test() {
    MxlMeasure measure = getFirstMeasure();
    for (MxlMusicDataContent data : measure.getMusicData().getContent()) {
        if (data.getMusicDataContentType() == MxlMusicDataContentType.Note) {
            // check pitch
            MxlNote note = (MxlNote) data;
            MxlFullNote fullNote = note.getContent().getFullNote();
            MxlPitch pitch = (MxlPitch) (fullNote.getContent());
            assertEquals(Companion.pi('G', 0, 4), pitch.getPitch());
            // check lyric
            assertEquals(1, note.getLyrics().size());
            assertEquals("A", ((MxlSyllabicText) note.getLyrics().get(0).getContent()).getText().getValue());
            return;
        }
    }
    fail("note not found");
}
Also used : MxlMusicDataContent(com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent) MxlFullNote(com.xenoage.zong.musicxml.types.groups.MxlFullNote) MxlPitch(com.xenoage.zong.musicxml.types.MxlPitch) MxlSyllabicText(com.xenoage.zong.musicxml.types.MxlSyllabicText) MxlMeasure(com.xenoage.zong.musicxml.types.partwise.MxlMeasure) MxlNote(com.xenoage.zong.musicxml.types.MxlNote) Test(org.junit.Test)

Aggregations

MxlNote (com.xenoage.zong.musicxml.types.MxlNote)4 MxlPitch (com.xenoage.zong.musicxml.types.MxlPitch)2 MxlSyllabicText (com.xenoage.zong.musicxml.types.MxlSyllabicText)2 MxlMusicDataContent (com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent)2 MxlFullNote (com.xenoage.zong.musicxml.types.groups.MxlFullNote)2 Pitch (com.xenoage.zong.core.music.Pitch)1 Note (com.xenoage.zong.core.music.chord.Note)1 Lyric (com.xenoage.zong.core.music.lyric.Lyric)1 SyllableType (com.xenoage.zong.core.music.lyric.SyllableType)1 MxlAttributes (com.xenoage.zong.musicxml.types.MxlAttributes)1 MxlBarline (com.xenoage.zong.musicxml.types.MxlBarline)1 MxlDirection (com.xenoage.zong.musicxml.types.MxlDirection)1 MxlInstrument (com.xenoage.zong.musicxml.types.MxlInstrument)1 MxlLyric (com.xenoage.zong.musicxml.types.MxlLyric)1 MxlPrint (com.xenoage.zong.musicxml.types.MxlPrint)1 MxlCueNote (com.xenoage.zong.musicxml.types.choice.MxlCueNote)1 MxlFullNoteContent (com.xenoage.zong.musicxml.types.choice.MxlFullNoteContent)1 MxlGraceNote (com.xenoage.zong.musicxml.types.choice.MxlGraceNote)1 MxlLyricContentType (com.xenoage.zong.musicxml.types.choice.MxlLyricContent.MxlLyricContentType)1 MxlNormalNote (com.xenoage.zong.musicxml.types.choice.MxlNormalNote)1