Search in sources :

Example 11 with Rest

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

the class ScoreTest method getGapBetweenTest.

@Test
public void getGapBetweenTest() {
    Score score = ScoreFactory.create1Staff4Measures();
    VoiceElement[] e = new VoiceElement[6];
    // 4/4 measure
    score.getColumnHeader(0).setTime(new TimeSignature(TimeType.Companion.getTime_4_4()));
    // first measure (filled only with 7/8)
    // voice 0: 1/4, 1/4, 1/4  (1/4 is missing)
    // voice 1: 3/4, 1/8       (1/8 is missing)
    score.getVoice(atVoice(0, 0, 0)).addElement(e[0] = new Rest(Companion.fr(1, 4)));
    score.getVoice(atVoice(0, 0, 0)).addElement(e[1] = new Rest(Companion.fr(1, 4)));
    score.getVoice(atVoice(0, 0, 0)).addElement(e[2] = new Rest(Companion.fr(1, 4)));
    new VoiceAdd(score.getMeasure(atMeasure(0, 0)), 1).execute();
    score.getVoice(atVoice(0, 0, 1)).addElement(new Rest(Companion.fr(3, 4)));
    score.getVoice(atVoice(0, 0, 1)).addElement(new Rest(Companion.fr(1, 8)));
    // second measure: 1/4, 3/4
    score.getVoice(atVoice(0, 1, 0)).addElement(e[3] = new Rest(Companion.fr(1, 4)));
    score.getVoice(atVoice(0, 1, 0)).addElement(e[4] = new Rest(Companion.fr(3, 4)));
    // third measure: 4/4
    score.getVoice(atVoice(0, 1, 0)).addElement(e[5] = new Rest(Companion.fr(4, 4)));
    // test gaps between adjacent elements
    assertEquals(Companion.get_0(), score.getGapBetween(e[0], e[1]));
    assertEquals(Companion.get_0(), score.getGapBetween(e[1], e[2]));
    // 1/8 from second voice
    assertEquals(Companion.fr(1, 8), score.getGapBetween(e[2], e[3]));
    assertEquals(Companion.get_0(), score.getGapBetween(e[3], e[4]));
    assertEquals(Companion.get_0(), score.getGapBetween(e[4], e[5]));
    // test some gaps between non-adjacent elements
    assertEquals(Companion.fr(1, 4), score.getGapBetween(e[0], e[2]));
    // includes 1/8 from second voice
    assertEquals(Companion.fr(3, 8), score.getGapBetween(e[1], e[3]));
    // includes 1/8 from second voice
    assertEquals(Companion.fr(3, 8), score.getGapBetween(e[2], e[4]));
    // includes 1/8 from second voice
    assertEquals(Companion.fr(5, 8).add(Companion.fr(4, 4)), score.getGapBetween(e[0], e[5]));
    // includes 1/8 from second voice
    assertEquals(Companion.fr(3, 8).add(Companion.fr(4, 4)), score.getGapBetween(e[1], e[5]));
    // test in reverse direction
    assertEquals(Companion.fr(-2, 4), score.getGapBetween(e[1], e[0]));
    assertEquals(Companion.fr(-2, 4), score.getGapBetween(e[2], e[1]));
    // includes 1/8 from second voice
    assertEquals(Companion.fr(-5, 8), score.getGapBetween(e[3], e[2]));
    // includes 1/8 from second voice
    assertEquals(Companion.fr(-23, 8), score.getGapBetween(e[5], e[0]));
    // includes 1/8 from second voice
    assertEquals(Companion.fr(-21, 8), score.getGapBetween(e[5], e[1]));
}
Also used : Rest(com.xenoage.zong.core.music.rest.Rest) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature) Test(org.junit.Test)

Example 12 with Rest

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

the class VoiceTest method getElementTest.

@Test
public void getElementTest() {
    // our test example: (g: grace note)
    // Beats:       0        1     2           3     4
    // Elements     |g1|-----a-----|g2|g3|--b--|--c--|g4|
    // Checked:     x  x           x  x  x     x     x  x
    Rest n = null, 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);
    VoiceElement[] elementsPool = { a, b, c, g1, g2, g3, g4 };
    Voice voice = new Voice(ilist(g1, a, g2, g3, b, c, g4));
    // expected solutions
    int sideCount = FirstOrLast.values().length;
    int borderCount = StartOrStop.values().length;
    int inCount = Interval.values().length;
    VoiceElement[][][][] expected = new VoiceElement[sideCount][borderCount][inCount][];
    // first/start
    expected[o(First)][o(Start)][o(Before)] = new VoiceElement[] { n, g1, g1, g1, g1, g1, g1, g1 };
    expected[o(First)][o(Start)][o(BeforeOrAt)] = new VoiceElement[] { g1, g1, g1, g1, g1, g1, g1, g1 };
    expected[o(First)][o(Start)][o(At)] = new VoiceElement[] { g1, a, g2, g3, b, c, g4, n };
    expected[o(First)][o(Start)][o(AtOrAfter)] = new VoiceElement[] { g1, a, g2, g3, b, c, g4, n };
    expected[o(First)][o(Start)][o(After)] = new VoiceElement[] { a, g2, g3, b, c, g4, n, n };
    // first/stop
    expected[o(First)][o(Stop)][o(Before)] = new VoiceElement[] { n, n, g1, g1, g1, g1, g1, g1 };
    expected[o(First)][o(Stop)][o(BeforeOrAt)] = new VoiceElement[] { n, g1, g1, g1, g1, g1, g1, g1 };
    expected[o(First)][o(Stop)][o(At)] = new VoiceElement[] { n, g1, a, g2, g3, b, c, g4 };
    expected[o(First)][o(Stop)][o(AtOrAfter)] = new VoiceElement[] { g1, g1, a, g2, g3, b, c, g4 };
    expected[o(First)][o(Stop)][o(After)] = new VoiceElement[] { g1, a, g2, g3, b, c, g4, n };
    // last/start
    expected[o(Last)][o(Start)][o(Before)] = new VoiceElement[] { n, g1, a, g2, g3, b, c, g4 };
    expected[o(Last)][o(Start)][o(BeforeOrAt)] = new VoiceElement[] { g1, a, g2, g3, b, c, g4, g4 };
    expected[o(Last)][o(Start)][o(At)] = new VoiceElement[] { g1, a, g2, g3, b, c, g4, n };
    expected[o(Last)][o(Start)][o(AtOrAfter)] = new VoiceElement[] { g4, g4, g4, g4, g4, g4, g4, n };
    expected[o(Last)][o(Start)][o(After)] = new VoiceElement[] { g4, g4, g4, g4, g4, g4, n, n };
    // last/stop
    expected[o(Last)][o(Stop)][o(Before)] = new VoiceElement[] { n, n, g1, a, g2, g3, b, c };
    expected[o(Last)][o(Stop)][o(BeforeOrAt)] = new VoiceElement[] { n, g1, a, g2, g3, b, c, g4 };
    expected[o(Last)][o(Stop)][o(At)] = new VoiceElement[] { n, g1, a, g2, g3, b, c, g4 };
    expected[o(Last)][o(Stop)][o(AtOrAfter)] = new VoiceElement[] { g4, g4, g4, g4, g4, g4, g4, g4 };
    expected[o(Last)][o(Stop)][o(After)] = new VoiceElement[] { g4, g4, g4, g4, g4, g4, g4, n };
    // test
    for (int iSide = 0; iSide < sideCount; iSide++) {
        for (int iBorder = 0; iBorder < borderCount; iBorder++) {
            for (int iIn = 0; iIn < inCount; iIn++) {
                assertGetElement(voice, elementsPool, FirstOrLast.values()[iSide], StartOrStop.values()[iBorder], Interval.values()[iIn], expected[iSide][iBorder][iIn]);
            }
        }
    }
}
Also used : Rest(com.xenoage.zong.core.music.rest.Rest) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Example 13 with Rest

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

the class VoiceTest method getElementAtTest.

@Test
public void getElementAtTest() {
    // our test example: (g: grace note)
    // Beats:       0        1     2           3     4
    // Elements     |g1|-----a-----|g2|g3|--b--|--c--|g4|
    // Checked:     x  x           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));
    // test
    assertEquals(a, voice.getElementAt(Companion.fr(0)));
    assertEquals(null, voice.getElementAt(Companion.fr(1)));
    assertEquals(b, voice.getElementAt(Companion.fr(2)));
    assertEquals(c, voice.getElementAt(Companion.fr(3)));
    assertEquals(g4, voice.getElementAt(Companion.fr(4)));
}
Also used : Rest(com.xenoage.zong.core.music.rest.Rest) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Example 14 with Rest

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

the class VoiceElementIteratorTest method createTestScore.

/**
 * Test score with 4 staves and 4 measures. In staves 1 and 3, the measures 1 and 3 have each
 * two voices with 4 quarter rests. The other measures have a single voice and
 * a full rest.
 */
public static Score createTestScore() {
    Score score = new Score();
    Cursor cursor = new Cursor(score, MP.mp0, true);
    for (int staff : range(4)) {
        for (int measure : range(4)) {
            if ((staff == 1 || staff == 3) && (measure == 1 || measure == 3)) {
                // 2 voices with each 4 quarter notes
                for (int voice : range(2)) {
                    cursor.setMp(atElement(staff, measure, voice, 0));
                    for (int i = 0; i < 4; i++) cursor.write(new Rest(Companion.fr(1, 4)));
                }
            } else {
                // full rest
                cursor.setMp(atElement(staff, measure, 0, 0));
                cursor.write(new Rest(Companion.fr(1)));
            }
        }
    }
    return score;
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) Cursor(com.xenoage.zong.io.selection.Cursor)

Example 15 with Rest

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

the class StrategyTest method getScore.

@Override
public Score getScore() {
    // collect test material
    List<Example> examples = getAllExamples();
    // text style
    FormattedTextStyle style = Companion.getDefaultStyle().withFont(new FontInfo("Arial", 6f, FontStyle.normal));
    // one chord in each measure
    Score score = ScoreFactory.create1Staff();
    Cursor cursor = new Cursor(score, mp0, true);
    cursor.write(new TimeSignature(TimeType.Companion.getTime_3_4()));
    for (int i : range(examples)) {
        Example example = examples.get(i);
        cursor.setMp(atElement(0, i, 0, 0));
        // write key
        int fifths = ((TraditionalKey) example.getContext().getKey()).getFifths();
        cursor.write((ColumnElement) new TraditionalKey(fifths));
        // write example name (each 2nd example one line down for better reading)
        String text = (i % 2 == 1 ? "\n" : "") + example.getName();
        cursor.write((MeasureElement) new Words(styleText(text, style)));
        // write chord with all accidentals from context (or a rest)
        Map<Pitch, Integer> accs = example.getContext().getAccidentals();
        if (accs.size() > 0) {
            Pitch[] pitches = new Pitch[accs.size()];
            int accIndex = 0;
            for (Pitch acc : accs.keySet()) {
                pitches[accIndex] = Companion.pi(acc.getStep(), accs.get(acc), acc.getOctave());
                accIndex++;
            }
            Chord accsChords = ChordFactory.chord(pitches, Companion.get_1$4());
            cursor.write(accsChords);
        } else {
            cursor.write(new Rest(Companion.get_1$4()));
        }
        // write a rest
        cursor.write(new Rest(Companion.get_1$4()));
        // write the tested chord
        Chord testedChord = ChordFactory.chord(example.getPitches().toArray(new Pitch[0]), Companion.get_1$4());
        cursor.write(testedChord);
    }
    return score;
}
Also used : FormattedTextStyle(com.xenoage.zong.core.text.FormattedTextStyle) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Cursor(com.xenoage.zong.io.selection.Cursor) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature) Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) Example(material.accidentals.Example) Words(com.xenoage.zong.core.music.direction.Words) Pitch(com.xenoage.zong.core.music.Pitch) FontInfo(com.xenoage.utils.font.FontInfo) Chord(com.xenoage.zong.core.music.chord.Chord)

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