Search in sources :

Example 1 with MxlPosition

use of com.xenoage.zong.musicxml.types.attributes.MxlPosition in project Zong by Xenoage.

the class MxlStem method read.

@NonNull
public static MxlStem read(XmlReader reader) {
    MxlPosition yPosition = MxlPosition.read(reader);
    MxlColor color = MxlColor.read(reader);
    MxlStemValue stem = MxlStemValue.read(reader);
    return new MxlStem(stem, yPosition, color);
}
Also used : MxlStemValue(com.xenoage.zong.musicxml.types.enums.MxlStemValue) MxlColor(com.xenoage.zong.musicxml.types.attributes.MxlColor) MxlPosition(com.xenoage.zong.musicxml.types.attributes.MxlPosition) NonNull(com.xenoage.utils.annotations.NonNull)

Example 2 with MxlPosition

use of com.xenoage.zong.musicxml.types.attributes.MxlPosition in project Zong by Xenoage.

the class StemReader method read.

/**
 * Reads and returns the stem of the given chord.
 * If not available, {@link Stem#defaultStem} is returned.
 * @param context   the global context
 * @param chord     the chord, whose notes are already collected
 * @param staff     the staff index of the current chord
 */
public Stem read(Context context, Chord chord, int staff) {
    if (mxlStem == null)
        return Companion.getDefaultStem();
    // direction
    StemDirection direction = readStemDirection();
    // length
    Float length = null;
    MxlPosition yPos = mxlStem.getPosition();
    if (yPos.getDefaultY() != null) {
        // convert position in tenths relative to topmost staff line into
        // a length in interline spaces measured from the outermost chord note on stem side
        float stemEndLinePosition = convertDefaultYToLP(context, yPos.getDefaultY(), staff);
        VSide side = (direction == StemDirection.Up ? VSide.Top : VSide.Bottom);
        length = Math.abs(stemEndLinePosition - getOuterNoteLp(context, chord, side, staff)) / 2;
    }
    // create stem
    return new Stem(direction, length);
}
Also used : MxlPosition(com.xenoage.zong.musicxml.types.attributes.MxlPosition) StemDirection(com.xenoage.zong.core.music.chord.StemDirection) VSide(com.xenoage.utils.math.VSide) Stem.defaultStem(com.xenoage.zong.core.music.chord.Stem.defaultStem) MxlStem(com.xenoage.zong.musicxml.types.MxlStem) Stem(com.xenoage.zong.core.music.chord.Stem)

Example 3 with MxlPosition

use of com.xenoage.zong.musicxml.types.attributes.MxlPosition in project Zong by Xenoage.

the class MxlSlurOrTied method read.

@MaybeNull
public static MxlSlurOrTied read(XmlReader reader) {
    // element type
    MxlElementType elementType = null;
    String eName = reader.getElementName();
    if (elemNameSlur.equals(eName))
        elementType = MxlElementType.Slur;
    else if (elemNameTied.equals(eName))
        elementType = MxlElementType.Tied;
    else
        throw reader.dataException("slur or tied expected");
    // type
    MxlStartStopContinue type = MxlStartStopContinue.read(reader.getAttribute("type"));
    if (type == MxlStartStopContinue.Continue && elementType == MxlElementType.Tied)
        throw reader.dataException("tied can not be continued");
    // other members
    Integer number = reader.getAttributeInt("number");
    if (elementType == MxlElementType.Slur)
        number = notNull(number, defaultNumberForSlur);
    MxlPosition position = MxlPosition.read(reader);
    MxlPlacement placement = MxlPlacement.read(reader);
    MxlBezier bezier = MxlBezier.read(reader);
    return new MxlSlurOrTied(elementType, type, number, position, placement, bezier);
}
Also used : MxlPosition(com.xenoage.zong.musicxml.types.attributes.MxlPosition) MxlPlacement(com.xenoage.zong.musicxml.types.enums.MxlPlacement) MxlStartStopContinue(com.xenoage.zong.musicxml.types.enums.MxlStartStopContinue) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 4 with MxlPosition

use of com.xenoage.zong.musicxml.types.attributes.MxlPosition in project Zong by Xenoage.

the class CreditsReader method addTextFrame.

/**
 * Adds the given credit element as a {@link TextFrame} to the given {@link Layout}.
 */
private static void addTextFrame(MxlCredit credit, Layout layout, ScoreFormat scoreFormat) {
    if (credit.getContent().getCreditContentType() == MxlCreditContentType.CreditWords) {
        MxlCreditWords mxlCreditWords = (MxlCreditWords) credit.getContent();
        // create formatted text
        FormattedText text = createFormattedText(mxlCreditWords, scoreFormat.getLyricFont());
        // compute position (read only the position of the first credit-words element)
        Page firstPage = layout.getPages().get(0);
        float tenths = scoreFormat.getInterlineSpace() / 10;
        MxlFormattedText mxlFirstCreditWords = mxlCreditWords.getItems().get(0);
        MxlPosition mxlPosition = mxlFirstCreditWords.getPrintStyle().getPosition();
        Point2f offsetFromBottomInTenths = mxlPosition.getDefault().or(new Point2f(10f, 10f));
        Point2f position = new Point2f(offsetFromBottomInTenths.x * tenths, firstPage.getFormat().getSize().height - offsetFromBottomInTenths.y * tenths);
        // compute size
        // this is the width of the widest paragraph and the height of the sum of all paragraphs
        // at least 1 mm
        float maxParagraphWidth = 1;
        // at least 1 mm
        float sumParagraphsHeight = 1;
        for (FormattedTextParagraph paragraph : text.getParagraphs()) {
            maxParagraphWidth = Math.max(maxParagraphWidth, paragraph.getMetrics().getWidth());
            sumParagraphsHeight += paragraph.getHeightMm();
        }
        Size2f size = new Size2f(maxParagraphWidth, sumParagraphsHeight);
        // horizontal alignment:
        // try with halign first, and if not set, use justify
        Alignment alignment = readAlignment(mxlFirstCreditWords.getHAlign());
        if (alignment == null) {
            alignment = readAlignment(mxlFirstCreditWords.getJustify());
        }
        if (alignment == null || alignment == Alignment.Left) {
            position = position.add(size.width / 2, 0);
        } else if (alignment == Alignment.Center) {
        // already centered
        } else if (alignment == Alignment.Right) {
            position = position.add(-size.width / 2, 0);
        }
        // vertical alignment
        MxlVAlign mxlVAlign = mxlFirstCreditWords.getVAlign();
        if (mxlVAlign == MxlVAlign.Top || mxlVAlign == MxlVAlign.Unknown) {
            position = position.add(0, size.height / 2);
        } else if (mxlVAlign == MxlVAlign.Middle) {
        // already centered
        } else if (mxlVAlign == MxlVAlign.Bottom || mxlVAlign == MxlVAlign.Baseline) {
            position = position.add(0, -size.height / 2);
        }
        // create and add TextFrame
        TextFrame textFrame = new TextFrame();
        textFrame.setPosition(position);
        textFrame.setSize(size);
        textFrame.setText(text);
        layout.getPages().get(0).addFrame(textFrame);
    }
}
Also used : Alignment(com.xenoage.zong.core.text.Alignment) OtherReader.readAlignment(com.xenoage.zong.io.musicxml.in.readers.OtherReader.readAlignment) Point2f(com.xenoage.utils.math.geom.Point2f) MxlFormattedText(com.xenoage.zong.musicxml.types.MxlFormattedText) Size2f(com.xenoage.utils.math.geom.Size2f) MxlPosition(com.xenoage.zong.musicxml.types.attributes.MxlPosition) FormattedTextParagraph(com.xenoage.zong.core.text.FormattedTextParagraph) TextFrame(com.xenoage.zong.layout.frames.TextFrame) MxlCreditWords(com.xenoage.zong.musicxml.types.MxlCreditWords) Page(com.xenoage.zong.layout.Page) MxlVAlign(com.xenoage.zong.musicxml.types.enums.MxlVAlign) FormattedText(com.xenoage.zong.core.text.FormattedText) MxlFormattedText(com.xenoage.zong.musicxml.types.MxlFormattedText)

Example 5 with MxlPosition

use of com.xenoage.zong.musicxml.types.attributes.MxlPosition in project Zong by Xenoage.

the class MxlGroupSymbol method read.

@NonNull
public static MxlGroupSymbol read(XmlReader reader) {
    MxlPosition position = MxlPosition.read(reader);
    MxlColor color = MxlColor.read(reader);
    MxlGroupSymbolValue value = MxlGroupSymbolValue.read(reader);
    return new MxlGroupSymbol(value, position, color);
}
Also used : MxlColor(com.xenoage.zong.musicxml.types.attributes.MxlColor) MxlPosition(com.xenoage.zong.musicxml.types.attributes.MxlPosition) MxlGroupSymbolValue(com.xenoage.zong.musicxml.types.enums.MxlGroupSymbolValue) NonNull(com.xenoage.utils.annotations.NonNull)

Aggregations

MxlPosition (com.xenoage.zong.musicxml.types.attributes.MxlPosition)5 NonNull (com.xenoage.utils.annotations.NonNull)2 MxlColor (com.xenoage.zong.musicxml.types.attributes.MxlColor)2 MaybeNull (com.xenoage.utils.annotations.MaybeNull)1 VSide (com.xenoage.utils.math.VSide)1 Point2f (com.xenoage.utils.math.geom.Point2f)1 Size2f (com.xenoage.utils.math.geom.Size2f)1 Stem (com.xenoage.zong.core.music.chord.Stem)1 Stem.defaultStem (com.xenoage.zong.core.music.chord.Stem.defaultStem)1 StemDirection (com.xenoage.zong.core.music.chord.StemDirection)1 Alignment (com.xenoage.zong.core.text.Alignment)1 FormattedText (com.xenoage.zong.core.text.FormattedText)1 FormattedTextParagraph (com.xenoage.zong.core.text.FormattedTextParagraph)1 OtherReader.readAlignment (com.xenoage.zong.io.musicxml.in.readers.OtherReader.readAlignment)1 Page (com.xenoage.zong.layout.Page)1 TextFrame (com.xenoage.zong.layout.frames.TextFrame)1 MxlCreditWords (com.xenoage.zong.musicxml.types.MxlCreditWords)1 MxlFormattedText (com.xenoage.zong.musicxml.types.MxlFormattedText)1 MxlStem (com.xenoage.zong.musicxml.types.MxlStem)1 MxlGroupSymbolValue (com.xenoage.zong.musicxml.types.enums.MxlGroupSymbolValue)1