Search in sources :

Example 16 with Rest

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

the class Test03b method test.

@Test
public void test() {
    Measure measure = getScore().getMeasure(mp0);
    // two voices
    assertEquals(2, measure.getVoices().size());
    // check first voice
    Voice voice = measure.getVoice(0);
    assertEquals(2, voice.getElements().size());
    assertEquals(Companion.pi(0, 0, 4), ((Chord) voice.getElement(0)).getNotes().get(0).getPitch());
    assertEquals(Companion.fr(1, 4), voice.getElement(0).getDuration());
    assertEquals(Companion.pi(0, 0, 4), ((Chord) voice.getElement(1)).getNotes().get(0).getPitch());
    assertEquals(Companion.fr(1, 4), voice.getElement(1).getDuration());
    // check second voice
    // in Zong!, there is no "empty" space in voices. Instead, an invisible rest is used
    voice = measure.getVoice(1);
    assertTrue(voice.getElement(0) instanceof Rest);
    assertTrue(((Rest) voice.getElement(0)).isHidden());
    assertEquals(Companion.fr(1, 4), voice.getElement(0).getDuration());
    assertEquals(Companion.pi(5, 0, 3), ((Chord) voice.getElement(1)).getNotes().get(0).getPitch());
    assertEquals(Companion.fr(1, 4), voice.getElement(1).getDuration());
    assertEquals(Companion.pi(5, 0, 3), ((Chord) voice.getElement(2)).getNotes().get(0).getPitch());
    assertEquals(Companion.fr(1, 4), voice.getElement(2).getDuration());
}
Also used : Rest(com.xenoage.zong.core.music.rest.Rest) Measure(com.xenoage.zong.core.music.Measure) Voice(com.xenoage.zong.core.music.Voice) Test(org.junit.Test)

Example 17 with Rest

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

the class Base46e method getExpectedStaff.

static Staff getExpectedStaff() {
    Score score = ScoreFactory.create1Staff();
    Cursor cursor = new Cursor(score, mp0, true);
    cursor.write(new TimeSignature(TimeType.Companion.getTimeCommon()));
    // measure 0, voice 0
    cursor.write(chord(Companion.pi('C', 0, 5), Companion.fr(1, 4)));
    // measure 1, voice 0
    cursor.setMp(atElement(0, 1, 0, 0));
    cursor.write(chord(Companion.pi('C', 0, 5), Companion.fr(1, 4)));
    cursor.write(chord(Companion.pi('A', 0, 4), Companion.fr(1, 4)));
    cursor.write(chord(Companion.pi('F', 0, 4), Companion.fr(1, 4)));
    cursor.write(chord(Companion.pi('C', 0, 5), Companion.fr(1, 4)));
    // measure 1, voice 1
    cursor.setMp(atElement(0, 1, 1, 0));
    cursor.write(new Rest(Companion.fr(1, 4)));
    cursor.write(chord(Companion.pi('C', 0, 4), Companion.fr(1, 4)));
    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 18 with Rest

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

the class ScoreReader method readToScore.

public void readToScore(Score score, ErrorHandling errorHandling) {
    Context context = new Context(score, new ReaderSettings(errorHandling));
    // create the measures of the parts
    It<MxlPart> mxlParts = it(doc.getParts());
    for (MxlPart mxlPart : mxlParts) {
        // create measures
        execute(new MeasureAddUpTo(score, mxlPart.getMeasures().size()));
        // initialize each measure with a C clef
        Part part = score.getStavesList().getParts().get(mxlParts.getIndex());
        StavesRange stavesRange = score.getStavesList().getPartStaffIndices(part);
        for (int staff : stavesRange.getRange()) {
            execute(new MeasureElementWrite(new Clef(ClefType.Companion.getClefTreble()), score.getMeasure(MP.atMeasure(staff, 0)), Companion.get_0()));
        }
    }
    // write a 4/4 measure and C key signature in the first measure
    execute(new ColumnElementWrite(new TimeSignature(TimeType.Companion.getTime_4_4()), score.getColumnHeader(0), Companion.get_0(), null));
    execute(new ColumnElementWrite(new TraditionalKey(0), score.getColumnHeader(0), Companion.get_0(), null));
    // read the parts
    mxlParts = it(doc.getParts());
    for (MxlPart mxlPart : mxlParts) {
        // clear part-dependent context values
        context.beginNewPart(mxlParts.getIndex());
        // read the measures
        It<MxlMeasure> mxlMeasures = it(mxlPart.getMeasures());
        for (MxlMeasure mxlMeasure : mxlMeasures) {
            try {
                MeasureReader.readToContext(mxlMeasure, mxlMeasures.getIndex(), context);
            } catch (MusicReaderException ex) {
                throw new RuntimeException("Error at " + ex.getContext().toString(), ex);
            } catch (Exception ex) {
                throw new RuntimeException("Error (roughly) around " + context.toString(), ex);
            }
        }
    }
    // remove unclosed elements
    context.removeUnclosedWedges();
    // go through the whole score, and fill empty measures (that means, measures where
    // voice 0 has no single VoiceElement) with rests
    Fraction measureDuration = Companion.fr(1, 4);
    for (int iStaff = 0; iStaff < score.getStavesCount(); iStaff++) {
        Staff staff = score.getStaff(atStaff(iStaff));
        for (int iMeasure : range(staff.getMeasures())) {
            Measure measure = staff.getMeasure(iMeasure);
            TimeSignature newTime = score.getHeader().getColumnHeader(iMeasure).getTime();
            if (newTime != null) {
                // time signature has changed
                measureDuration = newTime.getType().getMeasureBeats();
            }
            if (measureDuration == null) {
                // senza misura
                // use whole rest
                measureDuration = Companion.fr(4, 4);
            }
            Voice voice0 = measure.getVoice(0);
            if (voice0.isEmpty()) {
                // TODO: "whole rests" or split. currently, also 3/4 rests are possible
                MP mp = atElement(iStaff, iMeasure, 0, 0);
                new VoiceElementWrite(score.getVoice(mp), mp, new Rest(measureDuration), null).execute();
            }
        }
    }
}
Also used : VoiceElementWrite(com.xenoage.zong.commands.core.music.VoiceElementWrite) MP.atStaff(com.xenoage.zong.core.position.MP.atStaff) Staff(com.xenoage.zong.core.music.Staff) ColumnElementWrite(com.xenoage.zong.commands.core.music.ColumnElementWrite) MxlPart(com.xenoage.zong.musicxml.types.partwise.MxlPart) Clef(com.xenoage.zong.core.music.clef.Clef) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) MxlMeasure(com.xenoage.zong.musicxml.types.partwise.MxlMeasure) MeasureAddUpTo(com.xenoage.zong.commands.core.music.MeasureAddUpTo) StavesRange(com.xenoage.zong.core.music.group.StavesRange) Rest(com.xenoage.zong.core.music.rest.Rest) MxlMeasure(com.xenoage.zong.musicxml.types.partwise.MxlMeasure) Measure(com.xenoage.zong.core.music.Measure) MP(com.xenoage.zong.core.position.MP) MusicReaderException(com.xenoage.zong.io.musicxml.in.util.MusicReaderException) Fraction(com.xenoage.utils.math.Fraction) MusicReaderException(com.xenoage.zong.io.musicxml.in.util.MusicReaderException) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature) MxlPart(com.xenoage.zong.musicxml.types.partwise.MxlPart) Part(com.xenoage.zong.core.music.Part) MeasureElementWrite(com.xenoage.zong.commands.core.music.MeasureElementWrite) Voice(com.xenoage.zong.core.music.Voice)

Example 19 with Rest

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

the class MeasureElementsSpacerTest method testNeedAdditionalSpace.

/**
 * If there is not enough space left for the measure elements,
 * the voice spacings have to be moved to create enough space.
 * 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 4)
 * voice 1:   o      2
 * voice 2:    1          o
 * </pre>
 * Between VE1 and VE2, there are 6 spaces.
 * Assuming a padding width of 1 and a clef width of 6,
 * the clef can be moved two spaces to the left, but this is not
 * enough. All elements at or after beat 3 have to be moved 2 spaces
 * to the right.
 */
@Test
public void testNeedAdditionalSpace() {
    Rest[] ve = ve();
    List<VoiceSpacing> vs = alist(new VoiceSpacing(null, 1, alist(spacing(ve[0], Companion.fr(1, 2), 4), spacing(ve[1], Companion.fr(4), 11))), new VoiceSpacing(null, 1, alist(spacing(ve[2], Companion.fr(1), 5), spacing(ve[3], Companion.fr(13, 2), 16))));
    Clef innerClef = new Clef(ClefType.Companion.getClefTreble());
    BeatEList<Clef> innerClefs = Companion.beatEList();
    innerClefs.add(Companion.beatE(innerClef, Companion.fr(4)));
    List<ElementSpacing> mes = testee.compute(innerClefs, Companion.beatEList(), null, false, vs, 0, notations(ve, innerClef), ls);
    // voice spacings
    assertEquals(2, vs.size());
    assertEqualsSpacings(ilist(spacing(ve[0], Companion.fr(1, 2), 4), spacing(ve[1], Companion.fr(4), 13)), vs.get(0).elements);
    assertEqualsSpacings(ilist(spacing(ve[2], Companion.fr(1), 5), spacing(ve[3], Companion.fr(13, 2), 18)), vs.get(1).elements);
    // clef must be at offset 13 - padding - clefwidth/2
    ElementSpacing[] se = mes.toArray(new ElementSpacing[0]);
    assertEquals(1, se.length);
    assertEquals(Companion.fr(4), se[0].beat);
    assertEquals(13 - paddingWidth - clefWidth / 2, se[0].xIs, Delta.DELTA_FLOAT);
}
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 20 with Rest

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

the class SingleVoiceSpacerTest method setUp.

@Before
public void setUp() throws IOException {
    r1 = new Rest(Companion.fr(1, 4));
    r2 = new Rest(Companion.fr(1, 8));
    r3 = new Rest(Companion.fr(1, 8));
    r4 = new Rest(Companion.fr(1, 2));
    g1 = VoiceTest.grace(1);
    g2 = VoiceTest.grace(1);
    layoutSettings = LayoutSettingsTest.loadTestSettings();
}
Also used : Rest(com.xenoage.zong.core.music.rest.Rest) Before(org.junit.Before)

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