Search in sources :

Example 1 with Promise

use of com.xenoage.utils.promise.Promise 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 2 with Promise

use of com.xenoage.utils.promise.Promise in project Zong by Xenoage.

the class AndroidPlatformUtils method openFileAsync.

@Override
public Promise<InputStream> openFileAsync(String filePath) {
    return new Promise<InputStream>((ret) -> {
        try {
            InputStream stream = openFile(filePath);
            ret.resolve(stream);
        } catch (IOException ex) {
            ret.reject(ex);
        }
    });
}
Also used : Promise(com.xenoage.utils.promise.Promise) InputStream(com.xenoage.utils.io.InputStream) JseInputStream(com.xenoage.utils.jse.io.JseInputStream) IOException(java.io.IOException)

Aggregations

Promise (com.xenoage.utils.promise.Promise)2 InputStream (com.xenoage.utils.io.InputStream)1 JseInputStream (com.xenoage.utils.jse.io.JseInputStream)1 Score (com.xenoage.zong.core.Score)1 ScoreDoc (com.xenoage.zong.documents.ScoreDoc)1 ScoreDocFactory (com.xenoage.zong.io.ScoreDocFactory)1 MxlScorePartwise (com.xenoage.zong.musicxml.types.MxlScorePartwise)1 IOException (java.io.IOException)1 List (java.util.List)1