Search in sources :

Example 1 with MxlScorePartwise

use of com.xenoage.zong.musicxml.types.MxlScorePartwise in project Zong by Xenoage.

the class MusicXmlScoreFileInput method read.

/**
 * Creates a {@link Score} instance from the document
 * behind the given {@link InputStream}.
 * @param inputStream  the input stream with the MusicXML document
 * @param filePath     file path if known, null otherwise
 */
@Override
public Score read(InputStream stream, @MaybeNull String filePath) throws InvalidFormatException, IOException {
    // parse MusicXML file
    MxlScorePartwise score;
    try {
        XmlReader xmlReader = platformUtils().createXmlReader(stream);
        MusicXMLDocument doc = MusicXMLDocument.read(xmlReader);
        score = doc.getScore();
    } catch (XmlDataException ex) {
        // no valid MusicXML
        throw new InvalidFormatException(ex);
    } catch (Exception ex) {
        throw new IOException(ex);
    }
    return read(score, Level.LogErrors);
}
Also used : MxlScorePartwise(com.xenoage.zong.musicxml.types.MxlScorePartwise) XmlReader(com.xenoage.utils.xml.XmlReader) MusicXMLDocument(com.xenoage.zong.musicxml.MusicXMLDocument) XmlDataException(com.xenoage.utils.xml.XmlDataException) IOException(java.io.IOException) InvalidFormatException(com.xenoage.utils.exceptions.InvalidFormatException) IOException(java.io.IOException) XmlDataException(com.xenoage.utils.xml.XmlDataException) InvalidFormatException(com.xenoage.utils.exceptions.InvalidFormatException)

Example 2 with MxlScorePartwise

use of com.xenoage.zong.musicxml.types.MxlScorePartwise 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 3 with MxlScorePartwise

use of com.xenoage.zong.musicxml.types.MxlScorePartwise in project Zong by Xenoage.

the class Test51b method test.

@Test
public void test() {
    MxlScorePartwise score = getScore();
    assertEquals(expectedMovementTitle, score.getScoreHeader().getMovementTitle());
    assertEquals(expectedComposer, score.getScoreHeader().getIdentification().getCreators().get(0).getValue());
    MxlScorePart part = (MxlScorePart) score.getScoreHeader().getPartList().getContent().get(0);
    assertEquals(expectedPartName, part.getPartName());
}
Also used : MxlScorePart(com.xenoage.zong.musicxml.types.MxlScorePart) MxlScorePartwise(com.xenoage.zong.musicxml.types.MxlScorePartwise) Test(org.junit.Test)

Aggregations

MxlScorePartwise (com.xenoage.zong.musicxml.types.MxlScorePartwise)3 InvalidFormatException (com.xenoage.utils.exceptions.InvalidFormatException)1 Promise (com.xenoage.utils.promise.Promise)1 XmlDataException (com.xenoage.utils.xml.XmlDataException)1 XmlReader (com.xenoage.utils.xml.XmlReader)1 Score (com.xenoage.zong.core.Score)1 ScoreDoc (com.xenoage.zong.documents.ScoreDoc)1 ScoreDocFactory (com.xenoage.zong.io.ScoreDocFactory)1 MusicXMLDocument (com.xenoage.zong.musicxml.MusicXMLDocument)1 MxlScorePart (com.xenoage.zong.musicxml.types.MxlScorePart)1 IOException (java.io.IOException)1 List (java.util.List)1 Test (org.junit.Test)1