Search in sources :

Example 1 with Words

use of com.xenoage.zong.core.music.direction.Words 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)

Example 2 with Words

use of com.xenoage.zong.core.music.direction.Words in project Zong by Xenoage.

the class Test32b method testStyle.

@Test
public void testStyle() {
    Score score = getScore();
    for (int i = 0; i < expectedTexts.size(); ) {
        MP mp = expectedTexts.get(i).get1();
        List<Direction> directions = score.getMeasure(mp).getDirections().getAll(mp.beat);
        assertTrue("" + mp, directions.size() > 0);
        for (val direction : directions) {
            assertTrue("" + mp, direction instanceof Words);
            check((Words) direction, expectedTexts.get(i).get2(), mp);
            i++;
        }
    }
}
Also used : lombok.val(lombok.val) Score(com.xenoage.zong.core.Score) MP(com.xenoage.zong.core.position.MP) Words(com.xenoage.zong.core.music.direction.Words) Direction(com.xenoage.zong.core.music.direction.Direction) Test(org.junit.Test)

Example 3 with Words

use of com.xenoage.zong.core.music.direction.Words in project Zong by Xenoage.

the class Test21d method testMeasure0.

@Test
public void testMeasure0() {
    // F4, whole, with accent and fermata
    Chord chord = (Chord) score.getVoice(mp0).getElementAt(Companion.get_0());
    assertEquals(1, chord.getNotes().size());
    assertEquals(Companion.pi('F', 0, 4), chord.getNotes().get(0).getPitch());
    assertEquals(Companion.get_1(), chord.getDuration());
    assertEquals(2, chord.getAnnotations().size());
    assertEquals(articulation(ArticulationType.Accent, Placement.Below), chord.getAnnotations().get(0));
    assertEquals(fermata(Placement.Above), chord.getAnnotations().get(1));
    // words "Largo"
    List<MeasureElement> directions = score.getMeasure(mp0).getMeasureElements().getAll(Companion.get_0());
    // clef, words, dynamics
    assertEquals(3, directions.size());
    Words words = (Words) directions.get(1);
    assertEquals("Largo", words.getText().toString());
    assertEquals(Placement.Above, words.getPositioning());
    // dynamics "fp"
    Dynamic dynamics = (Dynamic) directions.get(2);
    assertEquals(DynamicValue.fp, dynamics.getValue());
    assertEquals(Placement.Below, dynamics.getPositioning());
}
Also used : MeasureElement(com.xenoage.zong.core.music.MeasureElement) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) Words(com.xenoage.zong.core.music.direction.Words) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Example 4 with Words

use of com.xenoage.zong.core.music.direction.Words in project Zong by Xenoage.

the class Base21d method getExpectedDirections.

default List<Tuple2<MP, ? extends Direction>> getExpectedDirections() {
    List<Tuple2<MP, ? extends Direction>> expectedDirections = alist();
    Words largo = new Words(new UnformattedText("Largo"));
    largo.setPositioning(Placement.Above);
    expectedDirections.add(t(mp0, largo));
    Dynamic fp = new Dynamic(DynamicValue.fp);
    fp.setPositioning(Placement.Below);
    expectedDirections.add(t(mp0, fp));
    Dynamic p = new Dynamic(DynamicValue.p);
    fp.setPositioning(Placement.Below);
    expectedDirections.add(t(mp0.withMeasure(1), p));
    return expectedDirections;
}
Also used : Dynamic(com.xenoage.zong.core.music.direction.Dynamic) Tuple2(com.xenoage.utils.kernel.Tuple2) Words(com.xenoage.zong.core.music.direction.Words) UnformattedText(com.xenoage.zong.core.text.UnformattedText) Direction(com.xenoage.zong.core.music.direction.Direction)

Example 5 with Words

use of com.xenoage.zong.core.music.direction.Words in project Zong by Xenoage.

the class MeasureElementIteratorTest method createTestScore.

/**
 * Test score with 4 staves and 4 measures. In staves 1 and 3, the measures 1 and 3 have each
 * three words with text "staff x, measure y, element z" on beats 1/4 and 2/4
 */
public static Score createTestScore() {
    Score score = new Score();
    Cursor cursor = new Cursor(score, MP.mp0, true);
    for (int staff : new int[] { 1, 3 }) {
        for (int measure : new int[] { 1, 3 }) {
            cursor.setMp(atElement(staff, measure, 0, 0));
            for (int element : range(2)) {
                cursor.write(new Rest(Companion.fr(1, 4)));
                cursor.write((MeasureElement) new Words(new UnformattedText("staff " + staff + ", measure " + measure + ", element " + element)));
            }
        }
    }
    return score;
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) Words(com.xenoage.zong.core.music.direction.Words) UnformattedText(com.xenoage.zong.core.text.UnformattedText) Cursor(com.xenoage.zong.io.selection.Cursor)

Aggregations

Words (com.xenoage.zong.core.music.direction.Words)5 Score (com.xenoage.zong.core.Score)3 Chord (com.xenoage.zong.core.music.chord.Chord)2 Direction (com.xenoage.zong.core.music.direction.Direction)2 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)2 Rest (com.xenoage.zong.core.music.rest.Rest)2 UnformattedText (com.xenoage.zong.core.text.UnformattedText)2 Cursor (com.xenoage.zong.io.selection.Cursor)2 Test (org.junit.Test)2 FontInfo (com.xenoage.utils.font.FontInfo)1 Tuple2 (com.xenoage.utils.kernel.Tuple2)1 MeasureElement (com.xenoage.zong.core.music.MeasureElement)1 Pitch (com.xenoage.zong.core.music.Pitch)1 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)1 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)1 MP (com.xenoage.zong.core.position.MP)1 FormattedTextStyle (com.xenoage.zong.core.text.FormattedTextStyle)1 lombok.val (lombok.val)1 Example (material.accidentals.Example)1