Search in sources :

Example 51 with Chord

use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.

the class VoiceElementWriteTest method testGraceAdd.

/**
 * Writes grace notes in a voice.
 * <pre>
 *           ..
 * into  aabb__ccddeeffgghh
 *  =>   aabb..ccddeeffgghh</pre>
 */
@Test
public void testGraceAdd() {
    Score score = createTestScoreEighths();
    CommandPerformer cp = score.getCommandPerformer();
    // in voice 1, write two grace notes
    Voice voice = score.getVoice(atVoice(0, 0, 1));
    Chord g1 = grace(1), g2 = grace(2);
    cp.execute(new VoiceElementWrite(voice, atElement(0, 0, 1, 2), g1, null));
    cp.execute(new VoiceElementWrite(voice, atElement(0, 0, 1, 3), g2, null));
    // now we must find the other elements unchanged but the grace notes inserted
    assertEquals(10, voice.getElements().size());
    assertEquals(Companion.fr(1, 8), getDur(voice, 0));
    assertEquals(Companion.fr(1, 8), getDur(voice, 1));
    assertEquals(Companion.fr(0), getDur(voice, 2));
    assertEquals(Companion.fr(0), getDur(voice, 3));
    assertEquals(Companion.fr(1, 8), getDur(voice, 4));
    assertEquals(Companion.fr(1, 8), getDur(voice, 5));
    assertEquals(Companion.fr(1, 8), getDur(voice, 6));
    assertEquals(Companion.fr(1, 8), getDur(voice, 7));
    assertEquals(Companion.fr(1, 8), getDur(voice, 8));
    assertEquals(Companion.fr(1, 8), getDur(voice, 9));
    // right elements?
    assertEquals(g1, voice.getElement(2));
    assertEquals(g2, voice.getElement(3));
    // test undo
    cp.undoMultipleSteps(2);
    assertTestScoreEighthsOriginalState(score);
}
Also used : Score(com.xenoage.zong.core.Score) Voice(com.xenoage.zong.core.music.Voice) Chord(com.xenoage.zong.core.music.chord.Chord) CommandPerformer(com.xenoage.utils.document.command.CommandPerformer) Test(org.junit.Test)

Example 52 with Chord

use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.

the class VoiceTest method grace.

public static Chord grace(int step) {
    Chord chord = new Chord(new Note(Companion.pi(step, 0)), Companion.fr(0, 4));
    chord.setGrace(new Grace(true, Companion.fr(1, 16)));
    return chord;
}
Also used : Grace(com.xenoage.zong.core.music.chord.Grace) Note(com.xenoage.zong.core.music.chord.Note) Chord(com.xenoage.zong.core.music.chord.Chord)

Example 53 with Chord

use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.

the class VoiceTest method getElementIndexTest.

@Test
public void getElementIndexTest() {
    // our test example: (g: grace note)
    // Beats:       0        1     2           3     4    5
    // Elements     |g1|-----a-----|g2|g3|--b--|--c--|g4|
    // Indices      0  1           2  3  4     5     6  7
    // Checked:     x        x     x           x     x    x
    Rest a = new Rest(Companion.fr(2)), b = new Rest(Companion.fr(1)), c = new Rest(Companion.fr(1));
    Chord g1 = grace(1), g2 = grace(2), g3 = grace(3), g4 = grace(4);
    Voice voice = new Voice(ilist(g1, a, g2, g3, b, c, g4));
    assertEquals(1, voice.getElementIndex(Companion.fr(0)));
    assertEquals(1, voice.getElementIndex(Companion.fr(1)));
    assertEquals(4, voice.getElementIndex(Companion.fr(2)));
    assertEquals(5, voice.getElementIndex(Companion.fr(3)));
    assertEquals(7, voice.getElementIndex(Companion.fr(4)));
    assertEquals(7, voice.getElementIndex(Companion.fr(5)));
}
Also used : Rest(com.xenoage.zong.core.music.rest.Rest) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Example 54 with Chord

use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.

the class ChordReader method readFirstNote.

private void readFirstNote() {
    mxlFirstNote = mxlNotes.get(0);
    MxlNoteContentType mxlFirstNoteType = mxlFirstNote.getContent().getNoteContentType();
    // type of chord/rest
    // (unpitched is still unsupported)
    MxlFullNote mxlFirstFullNote = mxlFirstNote.getContent().getFullNote();
    MxlNormalNote mxlFirstNormalNote = null;
    MxlCueNote mxlFirstCueNote = null;
    MxlGraceNote mxlFirstGraceNote = null;
    boolean isCue = false;
    boolean isGrace = false;
    if (mxlFirstNoteType == MxlNoteContentType.Normal) {
        mxlFirstNormalNote = (MxlNormalNote) mxlNotes.get(0).getContent();
    } else if (mxlFirstNoteType == MxlNoteContentType.Cue) {
        mxlFirstCueNote = (MxlCueNote) mxlNotes.get(0).getContent();
        isCue = true;
    } else if (mxlFirstNoteType == MxlNoteContentType.Grace) {
        mxlFirstGraceNote = (MxlGraceNote) mxlNotes.get(0).getContent();
        isGrace = true;
        // may also be true later, see (TODO) "Zong-Library/Discussions/MusicXML/Note - cue vs grace.txt"
        isCue = false;
    }
    MxlFullNoteContentType mxlFNCType = mxlFirstFullNote.getContent().getFullNoteContentType();
    // duration. here, the first duration is the duration of the whole chord.
    Fraction duration = Companion.get_0();
    if (mxlFirstNormalNote != null) {
        duration = readDuration(mxlFirstNormalNote.getDuration(), context.getDivisions());
    } else if (mxlFirstCueNote != null) {
        duration = readDuration(mxlFirstCueNote.getDuration(), context.getDivisions());
    }
    // when duration of normal note is 0, ignore the chord
    if (false == isGrace && false == duration.isGreater0()) {
        context.reportError("duration of chord is 0");
        return;
    }
    // create new chord or rest
    if (mxlFNCType == MxlFullNoteContentType.Pitch || mxlFNCType == MxlFullNoteContentType.Unpitched) {
        // create a chord
        Pitch pitch;
        if (mxlFNCType == MxlFullNoteContentType.Pitch)
            pitch = ((MxlPitch) mxlFirstFullNote.getContent()).getPitch();
        else
            // TODO (ZONG-96): better support for unpitched notes
            pitch = Pitch.Companion.pi(0, 4);
        Grace grace = null;
        if (mxlFirstGraceNote != null) {
            // read grace duration from note-type ("eighth", "16th", ...)
            Fraction graceDuration = Companion.fr(1, 8);
            if (mxlFirstNote.getNoteType() != null)
                graceDuration = mxlFirstNote.getNoteType().getDuration();
            boolean slash = mxlFirstGraceNote.getSlash() == MxlYesNo.Yes;
            grace = new Grace(slash, graceDuration);
            chord = new Chord(alist(new Note(pitch)), grace);
        } else {
            chord = new Chord(alist(new Note(pitch)), duration);
        }
        chord.setCue(isCue);
        chordOrRest = chord;
    } else if (mxlFNCType == MxlFullNoteContentType.Rest) {
        // create a rest
        Rest rest = new Rest(duration);
        rest.setCue(isCue);
        chordOrRest = rest;
    }
}
Also used : MxlFullNote(com.xenoage.zong.musicxml.types.groups.MxlFullNote) MxlCueNote(com.xenoage.zong.musicxml.types.choice.MxlCueNote) Grace(com.xenoage.zong.core.music.chord.Grace) Fraction(com.xenoage.utils.math.Fraction) MxlFullNoteContentType(com.xenoage.zong.musicxml.types.choice.MxlFullNoteContent.MxlFullNoteContentType) Rest(com.xenoage.zong.core.music.rest.Rest) MxlPitch(com.xenoage.zong.musicxml.types.MxlPitch) MxlGraceNote(com.xenoage.zong.musicxml.types.choice.MxlGraceNote) 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) MxlNormalNote(com.xenoage.zong.musicxml.types.choice.MxlNormalNote) MxlNoteContentType(com.xenoage.zong.musicxml.types.choice.MxlNoteContent.MxlNoteContentType) Chord(com.xenoage.zong.core.music.chord.Chord)

Example 55 with Chord

use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.

the class Test21a method test.

@Test
public void test() {
    Chord chord = (Chord) getFirstVoice().getElement(0);
    assertEquals(2, chord.getNotes().size());
    assertEquals(expectedChord.getNotes(), chord.getNotes());
    assertEquals(expectedChord.getDuration(), chord.getDuration());
}
Also used : Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Aggregations

Chord (com.xenoage.zong.core.music.chord.Chord)63 Test (org.junit.Test)34 MP (com.xenoage.zong.core.position.MP)16 Pitch (com.xenoage.zong.core.music.Pitch)12 Score (com.xenoage.zong.core.Score)11 Voice (com.xenoage.zong.core.music.Voice)10 NotesNotation (com.xenoage.zong.musiclayout.notation.chord.NotesNotation)10 VoiceElement (com.xenoage.zong.core.music.VoiceElement)8 Note (com.xenoage.zong.core.music.chord.Note)6 Rest (com.xenoage.zong.core.music.rest.Rest)6 ChordTest (musicxmltestsuite.tests.utils.ChordTest)6 Fraction (com.xenoage.utils.math.Fraction)5 Staff (com.xenoage.zong.core.music.Staff)4 Beam (com.xenoage.zong.core.music.beam.Beam)4 Grace (com.xenoage.zong.core.music.chord.Grace)4 StemDirection (com.xenoage.zong.core.music.chord.StemDirection)4 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)4 SlurWaypoint (com.xenoage.zong.core.music.slur.SlurWaypoint)4 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)4 NoteDisplacement (com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement)4