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