Search in sources :

Example 36 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class DemoScoreLayoutTry method main.

public static void main(String... args) throws Exception {
    SymbolPool symbolPool = sync(new SymbolPoolReader("default"));
    LayoutSettings layoutSettings = LayoutSettingsReader.read(jsePlatformUtils().openFile("data/test/layout/LayoutSettingsTest.xml"));
    try {
        Score score = ScoreRevolutionary.createScore();
        Size2f areaSize = new Size2f(150, 10000);
        Context context = new Context(score, symbolPool, layoutSettings);
        Target target = Target.completeLayoutTarget(new ScoreLayoutArea(areaSize));
        ScoreLayout layout = new ScoreLayouter(context, target).createLayoutWithExceptions();
        System.out.println(layout.toString());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : SymbolPoolReader(com.xenoage.zong.io.symbols.SymbolPoolReader) Score(com.xenoage.zong.core.Score) LayoutSettings(com.xenoage.zong.musiclayout.settings.LayoutSettings) Size2f(com.xenoage.utils.math.geom.Size2f) SymbolPool(com.xenoage.zong.symbols.SymbolPool) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout)

Example 37 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class ScoreLayouterTest method testSampleFiles.

/**
 * Try to layout all official MusicXML 1.1 and 2.0 sample files.
 * We can not test for the correct layout of course, but at least
 * we want to have no exceptions.
 */
@Test
public void testSampleFiles() throws Exception {
    SymbolPool symbolPool = sync(new SymbolPoolReader("default"));
    LayoutSettings layoutSettings = LayoutSettingsReader.read(jsePlatformUtils().openFile("data/test/layout/LayoutSettingsTest.xml"));
    for (String file : MusicXmlScoreFileInputTest.getSampleFiles()) {
        try {
            // System.out.println(file);
            Score score = new MusicXmlScoreFileInput().read(jsePlatformUtils().openFile(file), file);
            Size2f areaSize = new Size2f(150, 10000);
            Context context = new Context(score, symbolPool, layoutSettings);
            Target target = Target.completeLayoutTarget(new ScoreLayoutArea(areaSize));
            ScoreLayouter layouter = new ScoreLayouter(context, target);
            layouter.createLayoutWithExceptions();
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Failed to layout file: " + file);
        }
    }
}
Also used : SymbolPoolReader(com.xenoage.zong.io.symbols.SymbolPoolReader) Score(com.xenoage.zong.core.Score) LayoutSettings(com.xenoage.zong.musiclayout.settings.LayoutSettings) Size2f(com.xenoage.utils.math.geom.Size2f) SymbolPool(com.xenoage.zong.symbols.SymbolPool) MusicXmlScoreFileInput(com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInput) MusicXmlScoreFileInputTest(com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest) Test(org.junit.Test)

Example 38 with Score

use of com.xenoage.zong.core.Score 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 39 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class ColumnElementIteratorTest method createTestScore.

/**
 * Test score with 4 measures. The measures 1 and 3 have each
 * a time signature, a middle barline at 1/4 and an end barline.
 */
public static Score createTestScore() {
    Score score = new Score();
    Cursor cursor = new Cursor(score, MP.mp0, true);
    for (int measure : new int[] { 1, 3 }) {
        cursor.setMp(mp(unknown, measure, 0, Companion.get_0(), 0));
        cursor.write(new TimeSignature(Companion.getTime_4_4()));
        cursor.setMp(mp(unknown, measure, unknown, Companion.fr(1, 4), 0));
        cursor.write(Companion.barlineRegular());
        ColumnHeader column = score.getColumnHeader(measure);
        column.setEndBarline(Companion.barline(LightLight));
    }
    return score;
}
Also used : Score(com.xenoage.zong.core.Score) ColumnHeader(com.xenoage.zong.core.header.ColumnHeader) Cursor(com.xenoage.zong.io.selection.Cursor) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature)

Example 40 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class Test24e method test.

@Test
public void test() {
    Score score = getScore();
    for (int i : range(2)) checkGraceChords(score.getStaff(i), expectedStavesChords[i], true);
    // check start beats
    Fraction[][] startBeats = expectedStavesBeats;
    assertEquals(startBeats[0][0], MP.getMP(score.getVoice(mp0).getElement(0)).getBeat());
    assertEquals(startBeats[0][1], MP.getMP(score.getVoice(mp0).getElement(1)).getBeat());
    // half rest
    assertEquals(Companion.fr(2, 4), score.getVoice(mp0.withStaff(1)).getElement(0).getDuration());
    assertEquals(startBeats[1][0], MP.getMP(score.getVoice(mp0.withStaff(1)).getElement(1)).getBeat());
    assertEquals(startBeats[1][1], MP.getMP(score.getVoice(mp0.withStaff(1)).getElement(2)).getBeat());
}
Also used : Score(com.xenoage.zong.core.Score) Test(org.junit.Test)

Aggregations

Score (com.xenoage.zong.core.Score)99 Test (org.junit.Test)62 Rest (com.xenoage.zong.core.music.rest.Rest)22 MP (com.xenoage.zong.core.position.MP)19 Voice (com.xenoage.zong.core.music.Voice)15 Cursor (com.xenoage.zong.io.selection.Cursor)15 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)14 Chord (com.xenoage.zong.core.music.chord.Chord)11 StavesList (com.xenoage.zong.core.music.StavesList)9 MusicXmlScoreFileInputTest (com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest)9 Part (com.xenoage.zong.core.music.Part)8 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)7 lombok.val (lombok.val)7 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)6 Direction (com.xenoage.zong.core.music.direction.Direction)5 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)5 Size2f (com.xenoage.utils.math.geom.Size2f)4 PartAdd (com.xenoage.zong.commands.core.music.PartAdd)4 ScoreFormat (com.xenoage.zong.core.format.ScoreFormat)4 ScoreHeader (com.xenoage.zong.core.header.ScoreHeader)4