Search in sources :

Example 21 with Score

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);
}
Also used : Score(com.xenoage.zong.core.Score) InconsistentScoreException(com.xenoage.zong.core.util.InconsistentScoreException) InconsistentScoreException(com.xenoage.zong.core.util.InconsistentScoreException) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

Example 22 with Score

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());
}
Also used : Score(com.xenoage.zong.core.Score) Part(com.xenoage.zong.core.music.Part) PitchedInstrument(com.xenoage.zong.core.instrument.PitchedInstrument) MP.atMeasure(com.xenoage.zong.core.position.MP.atMeasure) Measure(com.xenoage.zong.core.music.Measure) MusicXmlScoreFileInputTest(com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest) Test(org.junit.Test)

Example 23 with Score

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)));
}
Also used : Score(com.xenoage.zong.core.Score) ColumnHeader(com.xenoage.zong.core.header.ColumnHeader) Barline(com.xenoage.zong.core.music.barline.Barline) CommandPerformer(com.xenoage.utils.document.command.CommandPerformer) Test(org.junit.Test)

Example 24 with Score

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) {
    }
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) MeasureFullException(com.xenoage.zong.utils.exceptions.MeasureFullException) Voice(com.xenoage.zong.core.music.Voice) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature) Test(org.junit.Test)

Example 25 with Score

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;
}
Also used : Score(com.xenoage.zong.core.Score) Note(com.xenoage.zong.core.music.chord.Note) ArrayList(java.util.ArrayList) Voice(com.xenoage.zong.core.music.Voice) Chord(com.xenoage.zong.core.music.chord.Chord)

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