Search in sources :

Example 16 with Score

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

the class Test90a method testOpenFile.

@Test
public void testOpenFile() {
    String filepath = Base.dirPath + getFileName();
    try {
        List<Score> scores = sync(new MusicXmlFileReader(io().openFile(filepath), filepath, l -> CollectionUtils.alist("20a-Compressed-MusicXML.xml")));
        assertEquals(1, scores.size());
        assertEquals("Compressed MusicXML file", scores.get(0).getInfo().getMovementTitle());
    } catch (Exception ex) {
        ex.printStackTrace();
        fail(ex.getMessage());
    }
}
Also used : MusicXmlFileReader(com.xenoage.zong.io.musicxml.in.MusicXmlFileReader) List(java.util.List) Base90a(musicxmltestsuite.tests.base.Base90a) Base(musicxmltestsuite.tests.base.Base) Assert.fail(org.junit.Assert.fail) Test(org.junit.Test) CollectionUtils(com.xenoage.utils.collections.CollectionUtils) JsePlatformUtils.io(com.xenoage.utils.jse.JsePlatformUtils.io) Sync.sync(com.xenoage.utils.jse.async.Sync.sync) Assert.assertEquals(org.junit.Assert.assertEquals) Score(com.xenoage.zong.core.Score) Score(com.xenoage.zong.core.Score) MusicXmlFileReader(com.xenoage.zong.io.musicxml.in.MusicXmlFileReader) Test(org.junit.Test)

Example 17 with Score

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

the class StemReader method convertDefaultYToLP.

/**
 * Converts the given default-y position in global tenths (that is always
 * relative to the topmost staff line) to a line position, using the
 * musical context from the given staff.
 */
private float convertDefaultYToLP(Context context, float defaultY, int staff) {
    Score score = context.getScore();
    float defaultYInMm = defaultY * score.getFormat().getInterlineSpace() / 10;
    float interlineSpace = score.getInterlineSpace(context.getPartStaffIndices().getStart() + staff);
    int linesCount = context.getStaffLinesCount(staff);
    return 2 * (linesCount - 1) + 2 * defaultYInMm / interlineSpace;
}
Also used : Score(com.xenoage.zong.core.Score)

Example 18 with Score

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

the class MusicXmlScoreDocFileReader method read.

public Promise<ScoreDoc> read() {
    return new Promise<>(ret -> {
        MusicXmlFileReader reader = new MusicXmlFileReader(stream, filePath, new AllFilter<>());
        reader.produce(new AsyncResult<List<Score>>() {

            @Override
            public void onSuccess(List<Score> scores) {
                if (scores.size() == 0) {
                    // no score was opened
                    ret.resolve(null);
                } else {
                    // open first selected score
                    Score score = scores.get(0);
                    ScoreDoc scoreDoc;
                    try {
                        scoreDoc = new ScoreDocFactory().read(score);
                        // add credit elements - TIDY
                        Object o = score.getMetaData().get("mxldoc");
                        if (o != null && o instanceof MxlScorePartwise) {
                            MxlScorePartwise doc = (MxlScorePartwise) o;
                            CreditsReader.read(doc, scoreDoc.getLayout(), score.getFormat());
                        }
                        ret.resolve(scoreDoc);
                    } catch (Exception ex) {
                        ret.reject(ex);
                    }
                }
            }

            @Override
            public void onFailure(Exception ex) {
                ret.reject(ex);
            }
        });
    });
}
Also used : ScoreDoc(com.xenoage.zong.documents.ScoreDoc) ScoreDocFactory(com.xenoage.zong.io.ScoreDocFactory) Promise(com.xenoage.utils.promise.Promise) Score(com.xenoage.zong.core.Score) List(java.util.List) MxlScorePartwise(com.xenoage.zong.musicxml.types.MxlScorePartwise)

Example 19 with Score

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

the class VoltaGroupFinderTest method findAllVoltaGroupsTest.

@Test
public void findAllVoltaGroupsTest() {
    Score score = createScore();
    val found = new VoltaGroupFinder(score).findAllVoltaGroups();
    assertEquals(voltaGroups.length, found.voltaGroups.size());
    for (val expectedGroups : voltaGroups) {
        val voltaGroup = found.getVoltaGroupAt(expectedGroups[0]);
        assertNotNull(voltaGroup);
        assertEquals(getLast(expectedGroups) - getFirst(expectedGroups), voltaGroup.getMeasuresCount());
        assertEquals(expectedGroups.length - 1, voltaGroup.voltasStartMeasures.size());
        for (// -2: last measure is just for marking the ending
        int iVolta : // -2: last measure is just for marking the ending
        range(0, expectedGroups.length - 2)) assertEquals(expectedGroups[iVolta], voltaGroup.voltasStartMeasures.get(iVolta).startMeasure);
    }
}
Also used : lombok.val(lombok.val) Score(com.xenoage.zong.core.Score) Test(org.junit.Test)

Example 20 with Score

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

the class TimeMapperTest method getScore.

/**
 * Creates the following score (each space is a quarter note)
 *
 * measures:
 * repetitions: voltas/signs:            1───┐2───┐   d.c. senza rep
 *              barlines:     |    |:   |   :|    |1   ||
 * part 0: staff 0: voice 0:  |1   |1   |2 2 |1   |1   ||
 *                  voice 1:  |    |442 |42 4|1 d |1   ||   //d = direction
 *         staff 1: voice 0:  |2 44|1   |    |1   |1   ||
 * part 1: staff 2: voice 0:  |1   |1   |2 2 |    |2 2 ||
 *
 * play ranges:               0---------------
 *                                 1----     2---------
 *                            3---------     4---------
 */
private Score getScore() {
    val score = new Score();
    new PartAdd(score, new Part("p0", null, 2, null), 0, null).execute();
    new PartAdd(score, new Part("p1", null, 1, null), 1, null).execute();
    new MeasureAdd(score, 5).execute();
    // time, barlines, voltas and signs
    score.getColumnHeader(0).setTime(new TimeSignature(TimeType.Companion.getTime_4_4()));
    score.getColumnHeader(1).setStartBarline(Companion.barlineForwardRepeat(Regular));
    score.getColumnHeader(2).setVolta(new Volta(1, range(1, 1), "1", true));
    score.getColumnHeader(2).setEndBarline(Companion.barlineBackwardRepeat(Regular, 1));
    score.getColumnHeader(3).setVolta(new Volta(1, range(2, 2), "2", true));
    score.getColumnHeader(4).setNavigationOrigin(new DaCapo(false));
    // staff 0, voice 0
    val cursor = new Cursor(score, mp0, true);
    cursor.write(e(1));
    cursor.write(e(1));
    cursor.write(e(2));
    cursor.write(e(2));
    cursor.write(e(1));
    cursor.write(e(1));
    // staff 0, voice 1
    cursor.setMp(atElement(0, 1, 1, 0));
    cursor.write(e(4));
    cursor.write(e(4));
    cursor.write(e(2));
    cursor.write(e(4));
    cursor.write(e(2));
    cursor.write(e(4));
    cursor.write(e(1));
    cursor.write(e(1));
    new MeasureElementWrite(new Dynamic(DynamicValue.f), score.getMeasure(atMeasure(0, 3)), Companion.get_1$2()).execute();
    // staff 1, voice 0
    cursor.setMp(atElement(1, 0, 0, 0));
    cursor.write(e(2));
    cursor.write(e(4));
    cursor.write(e(4));
    cursor.write(e(1));
    cursor.setMp(atElement(1, 2, 0, 0));
    cursor.write(e(1));
    cursor.write(e(1));
    // staff 2, voice 0
    cursor.setMp(atElement(2, 0, 0, 0));
    cursor.write(e(1));
    cursor.write(e(1));
    cursor.write(e(2));
    cursor.write(e(2));
    cursor.setMp(atElement(2, 4, 0, 0));
    cursor.write(e(2));
    cursor.write(e(2));
    return score;
}
Also used : lombok.val(lombok.val) Score(com.xenoage.zong.core.Score) MeasureAdd(com.xenoage.zong.commands.core.music.MeasureAdd) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) Part(com.xenoage.zong.core.music.Part) PartAdd(com.xenoage.zong.commands.core.music.PartAdd) DaCapo(com.xenoage.zong.core.music.direction.DaCapo) Cursor(com.xenoage.zong.io.selection.Cursor) MeasureElementWrite(com.xenoage.zong.commands.core.music.MeasureElementWrite) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature) Volta(com.xenoage.zong.core.music.volta.Volta)

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