Search in sources :

Example 1 with ScoreFormatReader

use of com.xenoage.zong.io.musicxml.in.readers.ScoreFormatReader in project Zong by Xenoage.

the class MusicXmlScoreFileInput method read.

/**
 * Builds a {@link Score} entity from a {@link MxlScorePartwise} document.
 * @param doc            the provided score-partwise document
 * @param errorHandling  how to deal with errors
 */
public Score read(MxlScorePartwise mxlScore, Level errorHandling) throws InvalidFormatException {
    try {
        // create new score
        Score score = new Score();
        // read information about the score
        ScoreInfo scoreInfo = new ScoreInfoReader(mxlScore.getScoreHeader()).read();
        score.setInfo(scoreInfo);
        // read score format
        MxlScoreHeader mxlScoreHeader = mxlScore.getScoreHeader();
        MxlDefaults mxlDefaults = mxlScoreHeader.getDefaults();
        ScoreFormat scoreFormat = new ScoreFormatReader(mxlDefaults).read();
        score.setFormat(scoreFormat);
        // read layout format
        MxlLayout mxlLayout = (mxlDefaults != null ? mxlDefaults.getLayout() : null);
        LayoutFormat layoutFormat = new LayoutFormatReader(mxlLayout, scoreFormat.getInterlineSpace() / 10).read();
        // TIDY
        score.setMetaData("layoutformat", layoutFormat);
        // create the list of staves
        ErrorHandling mxlErrorHandling = new ErrorHandling(errorHandling);
        StavesListReader stavesListReader = new StavesListReader(mxlScore, mxlErrorHandling);
        StavesList stavesList = stavesListReader.read();
        stavesList.setScore(score);
        score.setStavesList(stavesList);
        // read the musical contents
        new ScoreReader(mxlScore).readToScore(score, mxlErrorHandling);
        // remember the XML document for further application-dependend processing
        // TIDY
        score.setMetaData("mxldoc", mxlScore);
        // when errors were collected, log them and save them as metadata
        if (mxlErrorHandling.getErrorMessages().size() > 0) {
            INSTANCE.log(Companion.warning("The file could be loaded, but the following error(s) were reported: " + mxlErrorHandling.getErrorMessages()));
            score.setMetaData("mxlerrors", mxlErrorHandling.getErrorMessages());
        }
        return score;
    } catch (RuntimeException ex) {
        // catch runtime exceptions and rethrow them in the expected type
        throw new InvalidFormatException(ex);
    }
}
Also used : ErrorHandling(com.xenoage.zong.io.musicxml.in.util.ErrorHandling) LayoutFormatReader(com.xenoage.zong.io.musicxml.in.readers.LayoutFormatReader) MxlDefaults(com.xenoage.zong.musicxml.types.MxlDefaults) MxlLayout(com.xenoage.zong.musicxml.types.groups.MxlLayout) LayoutFormat(com.xenoage.zong.core.format.LayoutFormat) ScoreReader(com.xenoage.zong.io.musicxml.in.readers.ScoreReader) InvalidFormatException(com.xenoage.utils.exceptions.InvalidFormatException) ScoreFormat(com.xenoage.zong.core.format.ScoreFormat) Score(com.xenoage.zong.core.Score) ScoreInfo(com.xenoage.zong.core.info.ScoreInfo) StavesList(com.xenoage.zong.core.music.StavesList) ScoreFormatReader(com.xenoage.zong.io.musicxml.in.readers.ScoreFormatReader) ScoreInfoReader(com.xenoage.zong.io.musicxml.in.readers.ScoreInfoReader) MxlScoreHeader(com.xenoage.zong.musicxml.types.groups.MxlScoreHeader) StavesListReader(com.xenoage.zong.io.musicxml.in.readers.StavesListReader)

Aggregations

InvalidFormatException (com.xenoage.utils.exceptions.InvalidFormatException)1 Score (com.xenoage.zong.core.Score)1 LayoutFormat (com.xenoage.zong.core.format.LayoutFormat)1 ScoreFormat (com.xenoage.zong.core.format.ScoreFormat)1 ScoreInfo (com.xenoage.zong.core.info.ScoreInfo)1 StavesList (com.xenoage.zong.core.music.StavesList)1 LayoutFormatReader (com.xenoage.zong.io.musicxml.in.readers.LayoutFormatReader)1 ScoreFormatReader (com.xenoage.zong.io.musicxml.in.readers.ScoreFormatReader)1 ScoreInfoReader (com.xenoage.zong.io.musicxml.in.readers.ScoreInfoReader)1 ScoreReader (com.xenoage.zong.io.musicxml.in.readers.ScoreReader)1 StavesListReader (com.xenoage.zong.io.musicxml.in.readers.StavesListReader)1 ErrorHandling (com.xenoage.zong.io.musicxml.in.util.ErrorHandling)1 MxlDefaults (com.xenoage.zong.musicxml.types.MxlDefaults)1 MxlLayout (com.xenoage.zong.musicxml.types.groups.MxlLayout)1 MxlScoreHeader (com.xenoage.zong.musicxml.types.groups.MxlScoreHeader)1