Search in sources :

Example 1 with Example

use of material.accidentals.Example 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 Example

use of material.accidentals.Example in project Zong by Xenoage.

the class StrategyTest method testStrategies.

@Test
public void testStrategies() {
    // collect test material
    List<Example> examples = getAllExamples();
    // run tests
    List<ExampleResult> failedExamples = alist();
    for (Example example : examples) {
        ExampleResult result = testExample(example);
        if (result.getResult() == Result.Failed)
            failedExamples.add(result);
    }
    // list failed examples
    if (failedExamples.size() > 0) {
        for (ExampleResult example : failedExamples) System.out.println(example.getExample().getName() + " failed: " + example.getComment());
        fail(failedExamples.size() + " of " + examples.size() + " examples failed. " + "See console for details.");
    }
}
Also used : Example(material.accidentals.Example) ExampleResult(material.ExampleResult) VisualTest(com.xenoage.zong.test.VisualTest) Test(org.junit.Test)

Aggregations

Example (material.accidentals.Example)2 FontInfo (com.xenoage.utils.font.FontInfo)1 Score (com.xenoage.zong.core.Score)1 Pitch (com.xenoage.zong.core.music.Pitch)1 Chord (com.xenoage.zong.core.music.chord.Chord)1 Words (com.xenoage.zong.core.music.direction.Words)1 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)1 Rest (com.xenoage.zong.core.music.rest.Rest)1 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)1 FormattedTextStyle (com.xenoage.zong.core.text.FormattedTextStyle)1 Cursor (com.xenoage.zong.io.selection.Cursor)1 VisualTest (com.xenoage.zong.test.VisualTest)1 ExampleResult (material.ExampleResult)1 Test (org.junit.Test)1