use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class MusicXmlScoreFileInputTest method testSampleFiles.
/**
* It's too hard to check the contents of a MusicXML file
* automatically. We just try to load the score data and
* check if they could be loaded without problems.
*
* We check all official MusicXML 1.1 and 2.0 sample files.
*/
@Test
@SuppressWarnings("unused")
public void testSampleFiles() {
long startTime = System.currentTimeMillis();
for (String file : getSampleFiles()) {
try {
Score score = new MusicXmlScoreFileInput().read(jsePlatformUtils().openFile(file), file);
System.out.println("Loaded: " + file);
} catch (InconsistentScoreException ex) {
ex.printStackTrace();
fail("Score inconsistent after loading: " + file);
} catch (Exception ex) {
ex.printStackTrace();
fail("Failed to load file: " + file);
}
}
long totalTime = System.currentTimeMillis() - startTime;
// TEST
// System.out.println(getClass() + ": " + totalTime);
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class InstrumentsReaderTest method testInstrumentChanges.
/**
* Read the file "InstrumentChanges.xml".
* It must contain 3 instruments, namely a Clarinet in B, an Alto Sax in Eb
* and a Trombone in C. Check also the transpositons and see if the instrument
* changes happen at the right positions.
*/
@Test
public void testInstrumentChanges() {
Score score = MusicXmlScoreFileInputTest.loadXMLTestScore("InstrumentChanges.xml");
Part part = score.getStavesList().getParts().get(0);
assertEquals(3, part.getInstruments().size());
// clarinet
PitchedInstrument instr0 = (PitchedInstrument) part.getInstruments().get(0);
assertEquals("Clarinet in Bb", instr0.getName());
assertEquals(new Integer(-1), instr0.getTranspose().getDiatonic());
assertEquals(-2, instr0.getTranspose().getChromatic());
// altosax
PitchedInstrument instr1 = (PitchedInstrument) part.getInstruments().get(1);
assertEquals("Alto Saxophone", instr1.getName());
assertEquals(new Integer(-5), instr1.getTranspose().getDiatonic());
assertEquals(-9, instr1.getTranspose().getChromatic());
// trombone
PitchedInstrument instr2 = (PitchedInstrument) part.getInstruments().get(2);
assertEquals("Trombone", instr2.getName());
assertEquals(new Integer(0), instr2.getTranspose().getDiatonic());
assertEquals(0, instr2.getTranspose().getChromatic());
// instrument changes in measures 1, 2 and 3
Measure measure = score.getMeasure(atMeasure(0, 1));
assertEquals(instr1, getInstrumentChangeAtBeat0(measure).getInstrument());
measure = score.getMeasure(atMeasure(0, 2));
assertEquals(instr2, getInstrumentChangeAtBeat0(measure).getInstrument());
measure = score.getMeasure(atMeasure(0, 3));
assertEquals(instr0, getInstrumentChangeAtBeat0(measure).getInstrument());
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class ColumnElementRemoveTest method test.
@Test
public void test() {
Score score = ScoreFactory.create1Staff4Measures();
CommandPerformer cmd = score.getCommandPerformer();
ColumnHeader column2 = score.getColumnHeader(2);
// write middle barline
Barline b = Barline.Companion.barline(BarlineStyle.LightHeavy);
cmd.execute(new ColumnElementWrite(b, column2, Companion.fr(1, 4), null));
// remove it
cmd.execute(new ColumnElementRemove(column2, b));
assertEquals(0, column2.getMiddleBarlines().size());
// undo. should be here again
cmd.undo();
assertEquals(b, column2.getMiddleBarlines().get(Companion.fr(1, 4)));
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class VoiceElementWriteTest method testTimeAware.
/**
* Obey the time signature. Fail is written element is too long.
*/
@Test
public void testTimeAware() {
Score score = ScoreFactory.create1Staff4Measures();
score.getHeader().getColumnHeaders().get(1).setTime(new TimeSignature(TimeType.Companion.getTime_3_4()));
// create options
VoiceElementWrite.Options options = new VoiceElementWrite.Options();
options.checkTimeSignature = true;
// measure 0: senza misura: write 100 1/4 chords
Voice voice = score.getVoice(MP.atVoice(0, 0, 0));
for (int i : range(100)) new VoiceElementWrite(voice, atElement(0, 0, 0, i), new Rest(Companion.fr(1, 4)), options).execute();
// measure 2: must work for 3/4, then fail
for (int i : range(3)) new VoiceElementWrite(voice, atElement(0, 2, 0, i), new Rest(Companion.fr(1, 4)), options).execute();
try {
new VoiceElementWrite(voice, atElement(0, 2, 0, 3), new Rest(Companion.fr(1, 4)), options).execute();
fail();
} catch (MeasureFullException ex) {
}
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class VoiceElementWriteTest method createTestScoreEighths.
/**
* Creates a score with a single staff, a single measure,
* two voices with each 8 quarter notes which are beamed.
*/
private Score createTestScoreEighths() {
Score score = ScoreFactory.create1Staff();
new VoiceAdd(score.getMeasure(atMeasure(0, 0)), 1).execute();
for (int iVoice : range(2)) {
Voice voice = score.getVoice(atVoice(0, 0, iVoice));
List<Chord> beamChords = new ArrayList<>();
for (int i = 0; i < 8; i++) {
Chord chord = new Chord(new Note(Companion.pi(0, 0, 4)), Companion.fr(1, 8));
// add elements by hand, since the corresonding command is tested itself in this class
chord.setParent(voice);
voice.getElements().add(chord);
beamChords.add(chord);
}
// create beam
Companion.beamFromChords(beamChords);
}
// ensure that assert method works correctly. if not, fail now
assertTestScoreEighthsOriginalState(score);
return score;
}
Aggregations