Search in sources :

Example 1 with Rest

use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.

the class MeasureElementsSpacerTest method testEnoughExistingSpace.

/**
 * If there is enough space left for the measure elements,
 * the voice spacings do not have to be changed.
 * To understand the following sketch, have a look at the comments
 * in {@link MeasureElementsSpacer}.
 * <pre>
 * enough space:
 * beat:     0   2   4   6   8
 * offset:   3 5 7 9  13  17  21
 *           . . . . . . . . . .
 * clef:         *[clef]*          (on beat 6)
 * voice 1:   o          2
 * voice 2:    1              o
 * </pre>
 */
@Test
public void testEnoughExistingSpace() {
    Rest[] ve = ve();
    List<VoiceSpacing> originalVs = alist(new VoiceSpacing(null, 1, alist(spacing(ve[0], Companion.fr(1, 2), 4), spacing(ve[1], Companion.fr(6), 15))), new VoiceSpacing(null, 1, alist(spacing(ve[2], Companion.fr(1), 5), spacing(ve[3], Companion.fr(17, 2), 20))));
    List<VoiceSpacing> vs = alist(originalVs);
    Clef innerClef = new Clef(ClefType.Companion.getClefTreble());
    BeatEList<Clef> innerClefs = Companion.beatEList();
    innerClefs.add(Companion.beatE(innerClef, Companion.fr(6)));
    List<ElementSpacing> res = testee.compute(innerClefs, Companion.beatEList(), null, false, vs, 0, notations(ve, innerClef), ls);
    // clef must be at offset 15 - padding - clefwidth/2
    ElementSpacing[] mes = res.toArray(new ElementSpacing[0]);
    assertEquals(1, mes.length);
    assertEquals(Companion.fr(6), mes[0].beat);
    assertEquals(15 - paddingWidth - clefWidth / 2, mes[0].xIs, Delta.DELTA_FLOAT);
    // voice spacings must be unchanged
    assertEquals(originalVs, vs);
}
Also used : ElementSpacing(com.xenoage.zong.musiclayout.spacing.ElementSpacing) Rest(com.xenoage.zong.core.music.rest.Rest) Clef(com.xenoage.zong.core.music.clef.Clef) VoiceSpacing(com.xenoage.zong.musiclayout.spacing.VoiceSpacing) Test(org.junit.Test)

Example 2 with Rest

use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.

the class Base42a method getExpectedStaff.

/**
 * Gets the expected musical data, but without the dynamics, fermatas, articulations and slurs.
 */
static Staff getExpectedStaff() {
    Score score = ScoreFactory.create1Staff();
    Cursor cursor = new Cursor(score, mp0, true);
    cursor.write(new TimeSignature(TimeType.Companion.getTime_4_4()));
    // measure 0, voice 0
    cursor.write(addLyric(chord(Companion.pi('E', 0, 5), Companion.fr(1, 2)), "This"));
    cursor.write(addLyric(chord(Companion.pi('D', 0, 5), Companion.fr(1, 4)), "is"));
    cursor.write(addLyric(chord(Companion.pi('B', 0, 4), Companion.fr(1, 4)), "the"));
    // measure 1, voice 0
    cursor.write(new Rest(Companion.fr(1, 4)));
    cursor.write(addLyric(chord(Companion.pi('D', 0, 5), Companion.fr(1, 4)), "lyrics"));
    cursor.write(addLyric(chord(Companion.pi('B', 0, 3), Companion.fr(3, 8)), "of"));
    cursor.write(addLyric(chord(Companion.pi('C', 0, 5), Companion.fr(1, 8)), "Voice1"));
    // measure 0, voice 1
    cursor.setMp(atElement(0, 0, 1, 0));
    cursor.write(addLyric(chord(Companion.pi('C', 0, 5), Companion.fr(1, 2)), "This"));
    cursor.write(addLyric(chord(Companion.pi('B', 0, 4), Companion.fr(1, 4)), "is"));
    cursor.write(addLyric(chord(Companion.pi('G', 0, 4), Companion.fr(1, 4)), "the"));
    // measure 1, voice 1
    cursor.write(new Rest(Companion.fr(1, 4)));
    cursor.write(addLyric(chord(Companion.pi('B', 0, 4), Companion.fr(1, 4)), "lyrics"));
    cursor.write(addLyric(chord(Companion.pi('G', 0, 3), Companion.fr(3, 8)), "of"));
    cursor.write(addLyric(chord(Companion.pi('A', 0, 4), Companion.fr(1, 8)), "Voice2"));
    return score.getStaff(0);
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) Cursor(com.xenoage.zong.io.selection.Cursor) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature)

Example 3 with Rest

use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.

the class Base42b method getExpectedStaves.

/**
 * Gets the expected musical data, but without the dynamics, articulations and slurs
 * and also without the clef changes.
 */
static Staff[] getExpectedStaves() {
    Score score = ScoreFactory.create1Staff();
    Cursor cursor = new Cursor(score, mp0, true);
    cursor.write(new TimeSignature(TimeType.Companion.getTime_6_8()));
    // staff 1, measure 0
    cursor.write(chord(Companion.pi('F', 0, 4), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('D', 0, 4), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('B', 0, 3), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('G', 0, 3), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('F', 0, 3), Companion.fr(1, 4)));
    // staff 1, measure 1
    cursor.write(chord(Companion.pi('E', 0, 5), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('C', 0, 5), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('G', 0, 4), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('G', 0, 4), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('F', 0, 4), Companion.fr(1, 4)));
    // staff 1, measure 0
    cursor.setMp(atElement(1, 0, 0, 0));
    cursor.write(new Rest(Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('G', 0, 2), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('G', 0, 2), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('G', 0, 2), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('A', 0, 2), Companion.fr(1, 16)));
    cursor.write(chord(Companion.pi('G', 0, 2), Companion.fr(1, 16)));
    cursor.write(chord(Companion.pi('F', 1, 2), Companion.fr(1, 16)));
    cursor.write(chord(Companion.pi('G', 0, 2), Companion.fr(1, 16)));
    // staff 1, measure 1
    cursor.write(chord(new Pitch[] { Companion.pi('C', 0, 3), Companion.pi('E', 0, 3), Companion.pi('G', 0, 3), Companion.pi('C', 0, 4) }, Companion.fr(1, 4)));
    cursor.write(new Rest(Companion.fr(1, 8)));
    cursor.write(new Rest(Companion.fr(1, 4)));
    cursor.write(chord(Companion.pi('G', 0, 3), Companion.fr(1, 8)));
    return new Staff[] { score.getStaff(0), score.getStaff(1) };
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) Staff(com.xenoage.zong.core.music.Staff) Pitch(com.xenoage.zong.core.music.Pitch) Cursor(com.xenoage.zong.io.selection.Cursor) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature)

Example 4 with Rest

use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.

the class Utils method checkGraceChords.

public static void checkGraceChords(Staff staff, Chord[] expectedChords, boolean skipRests) {
    int iChord = 0;
    for (int iM = 0; iM < staff.getMeasures().size(); iM++) {
        Voice voice = staff.getMeasure(iM).getVoice(0);
        for (VoiceElement e : voice.getElements()) {
            if (e instanceof Rest && skipRests)
                continue;
            // check duration, type and notes
            Chord chord = (Chord) e;
            Chord expectedChord = expectedChords[iChord];
            assertEquals("chord " + iChord, expectedChord.getDuration(), chord.getDuration());
            assertEquals("chord " + iChord, expectedChord.getGrace(), chord.getGrace());
            assertEquals("chord " + iChord, expectedChord.getNotes(), chord.getNotes());
            iChord++;
        }
    }
    assertEquals("not all chords found", expectedChords.length, iChord);
}
Also used : Rest(com.xenoage.zong.core.music.rest.Rest) VoiceElement(com.xenoage.zong.core.music.VoiceElement) Voice(com.xenoage.zong.core.music.Voice) Chord(com.xenoage.zong.core.music.chord.Chord) SlurWaypoint(com.xenoage.zong.core.music.slur.SlurWaypoint)

Example 5 with Rest

use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.

the class VoiceElementWriteTest method testTimeAware.

/**
 * Obey the time signature. Fail is written element is too long.
 */
@Test
public void testTimeAware() {
    Score score = ScoreFactory.create1Staff4Measures();
    score.getHeader().getColumnHeaders().get(1).setTime(new TimeSignature(TimeType.Companion.getTime_3_4()));
    // create options
    VoiceElementWrite.Options options = new VoiceElementWrite.Options();
    options.checkTimeSignature = true;
    // measure 0: senza misura: write 100 1/4 chords
    Voice voice = score.getVoice(MP.atVoice(0, 0, 0));
    for (int i : range(100)) new VoiceElementWrite(voice, atElement(0, 0, 0, i), new Rest(Companion.fr(1, 4)), options).execute();
    // measure 2: must work for 3/4, then fail
    for (int i : range(3)) new VoiceElementWrite(voice, atElement(0, 2, 0, i), new Rest(Companion.fr(1, 4)), options).execute();
    try {
        new VoiceElementWrite(voice, atElement(0, 2, 0, 3), new Rest(Companion.fr(1, 4)), options).execute();
        fail();
    } catch (MeasureFullException ex) {
    }
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) MeasureFullException(com.xenoage.zong.utils.exceptions.MeasureFullException) Voice(com.xenoage.zong.core.music.Voice) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature) Test(org.junit.Test)

Aggregations

Rest (com.xenoage.zong.core.music.rest.Rest)35 Score (com.xenoage.zong.core.Score)22 Test (org.junit.Test)22 Voice (com.xenoage.zong.core.music.Voice)16 MP (com.xenoage.zong.core.position.MP)11 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)9 Cursor (com.xenoage.zong.io.selection.Cursor)8 Chord (com.xenoage.zong.core.music.chord.Chord)6 Clef (com.xenoage.zong.core.music.clef.Clef)4 Pitch (com.xenoage.zong.core.music.Pitch)3 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)3 Fraction (com.xenoage.utils.math.Fraction)2 ColumnElementWrite (com.xenoage.zong.commands.core.music.ColumnElementWrite)2 MeasureElementWrite (com.xenoage.zong.commands.core.music.MeasureElementWrite)2 Measure (com.xenoage.zong.core.music.Measure)2 Part (com.xenoage.zong.core.music.Part)2 Staff (com.xenoage.zong.core.music.Staff)2 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)2 Words (com.xenoage.zong.core.music.direction.Words)2 ElementSpacing (com.xenoage.zong.musiclayout.spacing.ElementSpacing)2