Search in sources :

Example 1 with MxlLayout

use of com.xenoage.zong.musicxml.types.groups.MxlLayout 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)

Example 2 with MxlLayout

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

the class MxlDefaults method read.

@MaybeNull
public static MxlDefaults read(XmlReader reader) {
    MxlScaling scaling = null;
    MxlLayout layout = new MxlLayout();
    MxlFont wordFont = null;
    MxlLyricFont lyricFont = null;
    while (reader.openNextChildElement()) {
        String n = reader.getElementName();
        if (n.equals(MxlScaling.elemName))
            scaling = MxlScaling.read(reader);
        else if (n.equals("word-font"))
            wordFont = MxlFont.read(reader);
        else if (// read only first
        n.equals(MxlLyricFont.elemName) && lyricFont == null)
            lyricFont = MxlLyricFont.read(reader);
        else
            layout.readElement(reader);
        reader.closeElement();
    }
    if (false == layout.isUsed())
        layout = null;
    if (scaling != null || layout != null || wordFont != null || lyricFont != null)
        return new MxlDefaults(scaling, layout, wordFont, lyricFont);
    else
        return null;
}
Also used : MxlLayout(com.xenoage.zong.musicxml.types.groups.MxlLayout) MxlFont(com.xenoage.zong.musicxml.types.attributes.MxlFont) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 3 with MxlLayout

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

the class PrintReader method readSystemLayout.

private SystemLayout readSystemLayout(boolean isPageStarted, float tenthMm) {
    MxlLayout mxlLayout = mxlPrint.getLayout();
    if (mxlLayout != null) {
        MxlSystemLayout mxlSystemLayout = mxlLayout.getSystemLayout();
        if (mxlSystemLayout != null) {
            SystemLayoutReader systemLayoutReader = new SystemLayoutReader(mxlSystemLayout, tenthMm);
            SystemLayout systemLayout = systemLayoutReader.read();
            Float topSystemDistance = systemLayoutReader.getTopSystemDistance();
            // for first systems on a page, use top-system-distance
            if (isPageStarted && topSystemDistance != null)
                systemLayout.setDistance(topSystemDistance);
            return systemLayout;
        }
    }
    return null;
}
Also used : MxlSystemLayout(com.xenoage.zong.musicxml.types.MxlSystemLayout) SystemLayout(com.xenoage.zong.core.format.SystemLayout) MxlSystemLayout(com.xenoage.zong.musicxml.types.MxlSystemLayout) MxlLayout(com.xenoage.zong.musicxml.types.groups.MxlLayout)

Example 4 with MxlLayout

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

the class PrintReader method readToContext.

public void readToContext(Context context) {
    ScoreHeader header = context.getScore().getHeader();
    int measure = context.getMp().measure;
    // system and page break
    Break break_ = readBreak();
    if (break_ != null) {
        // MusicXML print is in the first broken measure, but we
        // store the break in the last measure before the break (thus -1)
        int breakMeasure = measure - 1;
        if (// ignore, when in the first measure
        breakMeasure >= 0)
            context.writeColumnElement(break_, breakMeasure);
    }
    // the first measure of a score is also ok.
    if (measure == 0 || break_ != null) {
        // first page or new page?
        boolean isPageBreak = break_ != null && break_.getPageBreak() == PageBreak.NewPage;
        boolean isPageStarted = (measure == 0 || isPageBreak);
        if (isPageBreak) {
            // increment page index
            context.incPageIndex();
        }
        // first system or new system?
        boolean isSystemBreak = isPageBreak || (break_ != null && break_.getSystemBreak() == SystemBreak.NewSystem);
        if (isSystemBreak) {
            // increment system index
            context.incSystemIndex();
        }
        // read system layout, if there
        SystemLayout systemLayout = readSystemLayout(isPageStarted, context.getTenthMm());
        if (systemLayout != null)
            header.setSystemLayout(context.getSystemIndex(), systemLayout);
        // staff layouts
        MxlLayout mxlLayout = mxlPrint.getLayout();
        if (mxlLayout != null) {
            for (MxlStaffLayout mxlStaffLayout : it(mxlLayout.getStaffLayouts())) {
                int staffIndex = mxlStaffLayout.getNumberNotNull() - 1;
                // get system layout. if it does not exist yet, create it
                systemLayout = header.getSystemLayout(context.getSystemIndex());
                if (systemLayout == null) {
                    systemLayout = new SystemLayout();
                    header.setSystemLayout(context.getSystemIndex(), systemLayout);
                }
                StaffLayout staffLayout = new StaffLayoutReader(mxlStaffLayout, context.getTenthMm()).read();
                systemLayout.setStaffLayout(context.getPartStaffIndices().getStart() + staffIndex, staffLayout);
            }
        }
    }
}
Also used : ScoreHeader(com.xenoage.zong.core.header.ScoreHeader) MxlStaffLayout(com.xenoage.zong.musicxml.types.MxlStaffLayout) StaffLayout(com.xenoage.zong.core.format.StaffLayout) SystemLayout(com.xenoage.zong.core.format.SystemLayout) MxlSystemLayout(com.xenoage.zong.musicxml.types.MxlSystemLayout) SystemBreak(com.xenoage.zong.core.music.layout.SystemBreak) PageBreak(com.xenoage.zong.core.music.layout.PageBreak) Break(com.xenoage.zong.core.format.Break) MxlLayout(com.xenoage.zong.musicxml.types.groups.MxlLayout) MxlStaffLayout(com.xenoage.zong.musicxml.types.MxlStaffLayout) MxlPrint(com.xenoage.zong.musicxml.types.MxlPrint)

Example 5 with MxlLayout

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

the class MxlPrint method read.

@MaybeNull
public static MxlPrint read(XmlReader reader) {
    MxlLayout layout = new MxlLayout();
    MxlPrintAttributes printAttributes = MxlPrintAttributes.read(reader);
    while (reader.openNextChildElement()) {
        layout.readElement(reader);
        reader.closeElement();
    }
    if (false == layout.isUsed())
        layout = null;
    if (layout != null || printAttributes != noPrintAttributes)
        return new MxlPrint(layout, printAttributes);
    else
        return null;
}
Also used : MxlPrintAttributes(com.xenoage.zong.musicxml.types.attributes.MxlPrintAttributes) MxlLayout(com.xenoage.zong.musicxml.types.groups.MxlLayout) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Aggregations

MxlLayout (com.xenoage.zong.musicxml.types.groups.MxlLayout)5 MaybeNull (com.xenoage.utils.annotations.MaybeNull)2 SystemLayout (com.xenoage.zong.core.format.SystemLayout)2 MxlSystemLayout (com.xenoage.zong.musicxml.types.MxlSystemLayout)2 InvalidFormatException (com.xenoage.utils.exceptions.InvalidFormatException)1 Score (com.xenoage.zong.core.Score)1 Break (com.xenoage.zong.core.format.Break)1 LayoutFormat (com.xenoage.zong.core.format.LayoutFormat)1 ScoreFormat (com.xenoage.zong.core.format.ScoreFormat)1 StaffLayout (com.xenoage.zong.core.format.StaffLayout)1 ScoreHeader (com.xenoage.zong.core.header.ScoreHeader)1 ScoreInfo (com.xenoage.zong.core.info.ScoreInfo)1 StavesList (com.xenoage.zong.core.music.StavesList)1 PageBreak (com.xenoage.zong.core.music.layout.PageBreak)1 SystemBreak (com.xenoage.zong.core.music.layout.SystemBreak)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