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();
}
}
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);
}
}
}
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;
}
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;
}
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());
}
Aggregations