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);
}
});
});
}
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);
}
});
}
Aggregations