Search in sources :

Example 1 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class VoicesBeatOffsetterTest method computeTestGrace.

/**
 * Compute offsets of the common beats, when also grace notes are used.
 */
@Test
public void computeTestGrace() {
    Score score = createTestScore3VoicesGrace();
    BeatOffset[] beatOffsets = testee.compute(createVoiceSpacings(score), Companion.fr(4, 4), minimalBeatsOffsetIs).toArray(new BeatOffset[0]);
    float is = score.getFormat().getInterlineSpace();
    // 2: half note, 4: quarter note, 8: eighth note, 3: quarter triplet
    // ^: dominating voice
    // voice 1: | 4     ...4       4     4     |
    // ^^^^^^^^^              ^^^^^
    // voice 2: | 8  8     8  8  ..2           |
    // ^^^^^^^^
    // voice 3: | 3   3      3    .8  8  4     |
    // ^^^^^^
    // used:      *  **    * **    *  *  *     *
    // checked:   *        *       *     *     *
    assertEquals(10, beatOffsets.length);
    assertEquals(Companion.fr(0, 4), beatOffsets[0].getBeat());
    assertEquals((0) * is, beatOffsets[0].getOffsetMm(), df);
    assertEquals(Companion.fr(1, 4), beatOffsets[3].getBeat());
    float offset1 = width_1_4 + 3 * width_grace;
    assertEquals(offset1 * is, beatOffsets[3].getOffsetMm(), df);
    assertEquals(Companion.fr(2, 4), beatOffsets[6].getBeat());
    float offset2 = offset1 + 2 * width_1_8 + 2 * width_grace;
    assertEquals(offset2 * is, beatOffsets[6].getOffsetMm(), df);
    assertEquals(Companion.fr(3, 4), beatOffsets[8].getBeat());
    float offset3 = offset2 + 2 * width_1_8;
    assertEquals(offset3 * is, beatOffsets[8].getOffsetMm(), df);
    assertEquals(Companion.fr(4, 4), beatOffsets[9].getBeat());
    float offset4 = offset3 + width_1_4;
    assertEquals(offset4 * is, beatOffsets[9].getOffsetMm(), df);
}
Also used : Score(com.xenoage.zong.core.Score) MusicXmlScoreFileInputTest(com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest) Test(org.junit.Test)

Example 2 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class VoicesBeatOffsetterTest method computeBeatOffsets_File3.

/**
 * Test file "BeatOffsetsStrategyTest-3.xml".
 */
@Test
public void computeBeatOffsets_File3() {
    Score score = MusicXmlScoreFileInputTest.loadXMLTestScore("VoicesBeatOffsetterTest-3.xml");
    LinkedList<VoiceSpacing> voiceSpacings = createVoiceSpacings(score);
    BeatOffset[] beatOffsets = testee.compute(voiceSpacings, Companion.fr(5, 4), minimalBeatsOffsetIs).toArray(new BeatOffset[0]);
    // file must have 8 beat offsets with increasing mm offsets
    // special difficulty: last eighth note must be further to the right as preceding quarter
    // in other voice, even the distance between the whole note and the last eighth would be big enough
    assertEquals(8, beatOffsets.length);
    assertEquals(Companion.fr(0, 4), beatOffsets[0].getBeat());
    assertEquals(Companion.fr(1, 8), beatOffsets[1].getBeat());
    assertEquals(Companion.fr(1, 4), beatOffsets[2].getBeat());
    assertEquals(Companion.fr(2, 4), beatOffsets[3].getBeat());
    assertEquals(Companion.fr(3, 4), beatOffsets[4].getBeat());
    assertEquals(Companion.fr(4, 4), beatOffsets[5].getBeat());
    assertEquals(Companion.fr(9, 8), beatOffsets[6].getBeat());
    assertEquals(Companion.fr(5, 4), beatOffsets[7].getBeat());
    for (int i = 0; i < beatOffsets.length - 1; i++) {
        assertTrue("beat " + (i + 1) + " wrong", beatOffsets[i].getOffsetMm() < beatOffsets[i + 1].getOffsetMm());
    }
    // distance between beat 1/4 and 2/4 must be width_1_4
    float is = score.getFormat().getInterlineSpace();
    assertEquals(width_1_4 * is, beatOffsets[3].getOffsetMm() - beatOffsets[2].getOffsetMm(), df);
}
Also used : Score(com.xenoage.zong.core.Score) MusicXmlScoreFileInputTest(com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest) Test(org.junit.Test)

Example 3 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class VoicesBeatOffsetterTest method computeTest1.

/**
 * Compute offsets of the common beats.
 */
@Test
public void computeTest1() {
    Score score = createTestScore3Voices();
    BeatOffset[] beatOffsets = testee.compute(createVoiceSpacings(score), Companion.fr(4, 4), minimalBeatsOffsetIs).toArray(new BeatOffset[0]);
    float is = score.getFormat().getInterlineSpace();
    // 2: half note, 4: quarter note, 8: eighth note, 3: quarter triplet
    // ^: dominating voice
    // voice 1:   | 4     4     4     4     |
    // ^^^^^
    // voice 2:   | 8  8  8  8  2           |
    // ^^^^^^^^^^^^
    // voice 3:   | 3   3   3   8  8  4     |
    // ^^^^^^
    // used:        *  ** * **  *  *  *     *
    // checked:     *     *     *     *     *
    assertEquals(10, beatOffsets.length);
    assertEquals(Companion.fr(0, 4), beatOffsets[0].getBeat());
    assertEquals((0) * is, beatOffsets[0].getOffsetMm(), df);
    assertEquals(Companion.fr(1, 4), beatOffsets[3].getBeat());
    assertEquals((2 * width_1_8) * is, beatOffsets[3].getOffsetMm(), df);
    assertEquals(Companion.fr(2, 4), beatOffsets[6].getBeat());
    assertEquals((4 * width_1_8) * is, beatOffsets[6].getOffsetMm(), df);
    assertEquals(Companion.fr(3, 4), beatOffsets[8].getBeat());
    assertEquals((6 * width_1_8) * is, beatOffsets[8].getOffsetMm(), df);
    assertEquals(Companion.fr(4, 4), beatOffsets[9].getBeat());
    assertEquals((6 * width_1_8 + width_1_4) * is, beatOffsets[9].getOffsetMm(), df);
}
Also used : Score(com.xenoage.zong.core.Score) MusicXmlScoreFileInputTest(com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest) Test(org.junit.Test)

Example 4 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class VoicesBeatOffsetterTest method createTestScore3VoicesGrace.

private Score createTestScore3VoicesGrace() {
    Score score = new Score();
    score.getFormat().setInterlineSpace(10);
    Cursor cursor = new Cursor(score, mp0, true);
    cursor.write(new TimeSignature(Companion.getTime_4_4()));
    // 2: half note, 4: quarter note, 8: eighth note, 3: quarter triplet, .: grace note
    // voice 1: | 4     ...4       4     4     |   (staff 1)
    // voice 2: | 8  8     8  8  ..2           |   (staff 1)
    // voice 3: | 3   3      3    .8  8  4     |   (staff 2)
    // voice 1 (staff 1)
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
    cursor.write(graceChord(Companion.pi(0, 0, 0)));
    cursor.write(graceChord(Companion.pi(0, 0, 0)));
    cursor.write(graceChord(Companion.pi(0, 0, 0)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
    // voice 2 (staff 1)
    cursor.setMp(atElement(0, 0, 1, 0));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    cursor.write(graceChord(Companion.pi(0, 0, 0)));
    cursor.write(graceChord(Companion.pi(0, 0, 0)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 2)));
    // voice 3 (staff 2)
    cursor.setMp(atElement(1, 0, 0, 0));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 6)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 6)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 6)));
    cursor.write(graceChord(Companion.pi(0, 0, 0)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
    return score;
}
Also used : Score(com.xenoage.zong.core.Score) Cursor(com.xenoage.zong.io.selection.Cursor) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature)

Example 5 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class VoicesBeatOffsetterTest method computeBeatOffsets_File2.

/**
 * Test file "BeatOffsetsStrategyTest-2.xml".
 */
@Test
public void computeBeatOffsets_File2() {
    Score score = MusicXmlScoreFileInputTest.loadXMLTestScore("VoicesBeatOffsetterTest-2.xml");
    LinkedList<VoiceSpacing> voiceSpacings = createVoiceSpacings(score);
    BeatOffset[] beatOffsets = testee.compute(voiceSpacings, Companion.fr(3, 4), minimalBeatsOffsetIs).toArray(new BeatOffset[0]);
    // file must have 6 beat offsets with increasing mm offsets
    assertEquals(6, beatOffsets.length);
    assertEquals(Companion.fr(0, 4), beatOffsets[0].getBeat());
    assertEquals(Companion.fr(1, 8), beatOffsets[1].getBeat());
    assertEquals(Companion.fr(1, 4), beatOffsets[2].getBeat());
    assertEquals(Companion.fr(2, 4), beatOffsets[3].getBeat());
    assertEquals(Companion.fr(5, 8), beatOffsets[4].getBeat());
    assertEquals(Companion.fr(3, 4), beatOffsets[5].getBeat());
    for (int i = 0; i < beatOffsets.length - 1; i++) {
        assertTrue(beatOffsets[i].getOffsetMm() < beatOffsets[i + 1].getOffsetMm());
    }
    // distance between beat 1/4 and 2/4 must be width_1_4
    float is = score.getFormat().getInterlineSpace();
    assertEquals(width_1_4 * is, beatOffsets[3].getOffsetMm() - beatOffsets[2].getOffsetMm(), df);
}
Also used : Score(com.xenoage.zong.core.Score) MusicXmlScoreFileInputTest(com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest) Test(org.junit.Test)

Aggregations

Score (com.xenoage.zong.core.Score)99 Test (org.junit.Test)62 Rest (com.xenoage.zong.core.music.rest.Rest)22 MP (com.xenoage.zong.core.position.MP)19 Voice (com.xenoage.zong.core.music.Voice)15 Cursor (com.xenoage.zong.io.selection.Cursor)15 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)14 Chord (com.xenoage.zong.core.music.chord.Chord)11 StavesList (com.xenoage.zong.core.music.StavesList)9 MusicXmlScoreFileInputTest (com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest)9 Part (com.xenoage.zong.core.music.Part)8 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)7 lombok.val (lombok.val)7 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)6 Direction (com.xenoage.zong.core.music.direction.Direction)5 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)5 Size2f (com.xenoage.utils.math.geom.Size2f)4 PartAdd (com.xenoage.zong.commands.core.music.PartAdd)4 ScoreFormat (com.xenoage.zong.core.format.ScoreFormat)4 ScoreHeader (com.xenoage.zong.core.header.ScoreHeader)4