Search in sources :

Example 21 with MaybeNull

use of com.xenoage.utils.annotations.MaybeNull in project Zong by Xenoage.

the class DynamicsFinder method getWedgeEndAt.

/**
 * Checks, if there is a {@link WedgeEnd} at the given time within the given staff (not a voice).
 * If yes, the given open wedge is closed and returned.
 */
@MaybeNull
private GradientDynamics getWedgeEndAt(int staff, Time time, GradientDynamics openWedge) {
    val measure = score.getMeasure(atMeasure(staff, time.getMeasure()));
    val foundDynamic = (Dynamic) measure.getDirections().get(time.getBeat(), MusicElementType.Dynamic);
    val foundWedgeEnd = (WedgeEnd) measure.getDirections().get(time.getBeat(), MusicElementType.WedgeEnd);
    if (foundWedgeEnd != null) {
        val endDynamicValue = (foundDynamic != null ? foundDynamic.getValue() : openWedge.end);
        return new GradientDynamics(openWedge.start, endDynamicValue);
    }
    return null;
}
Also used : lombok.val(lombok.val) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) WedgeEnd(com.xenoage.zong.core.music.direction.WedgeEnd) GradientDynamics(com.xenoage.zong.io.midi.out.dynamics.type.GradientDynamics) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 22 with MaybeNull

use of com.xenoage.utils.annotations.MaybeNull in project Zong by Xenoage.

the class MxlTime method read.

/**
 * Returns null, if the time signature is unsupported.
 */
@MaybeNull
public static MxlTime read(XmlReader reader) {
    MxlTimeSymbol symbol = MxlTimeSymbol.read(reader);
    MxlTimeContent content = null;
    if (reader.openNextChildElement()) {
        String n = reader.getElementName();
        switch(n) {
            case "beats":
                content = MxlNormalTime.read(reader);
                break;
            case "senza-misura":
                content = MxlSenzaMisura.read();
                reader.closeElement();
                break;
            default:
                reader.closeElement();
                break;
        }
    }
    if (content != null)
        return new MxlTime(content, symbol);
    else
        return null;
}
Also used : MxlTimeContent(com.xenoage.zong.musicxml.types.choice.MxlTimeContent) MxlTimeSymbol(com.xenoage.zong.musicxml.types.enums.MxlTimeSymbol) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 23 with MaybeNull

use of com.xenoage.utils.annotations.MaybeNull in project Zong by Xenoage.

the class DirectionReader method readPedal.

@MaybeNull
private Pedal readPedal() {
    MxlPedal mxlPedal = (MxlPedal) currentMxlDirType;
    Pedal.Type type = null;
    switch(mxlPedal.getType()) {
        case Start:
            type = Type.Start;
            break;
        case Stop:
            type = Type.Stop;
            break;
        default:
            return null;
    }
    Pedal pedal = new Pedal(type);
    pedal.setPositioning(readPositioning());
    return pedal;
}
Also used : Type(com.xenoage.zong.core.music.direction.Pedal.Type) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 24 with MaybeNull

use of com.xenoage.utils.annotations.MaybeNull in project Zong by Xenoage.

the class FontInfoReader method read.

/**
 * Reads the font from the given element, if it is a {@link MxlPrintStyleContent} element
 * and contains font information. The returned font is based on the given default font.
 */
@MaybeNull
public static FontInfo read(Object printStyleElement, FontInfo defaultFont) {
    if (false == printStyleElement instanceof MxlPrintStyleContent)
        return null;
    MxlPrintStyle mxlPrintStyle = ((MxlPrintStyleContent) printStyleElement).getPrintStyle();
    MxlFont mxlFont = mxlPrintStyle.getFont();
    return new FontInfoReader(mxlFont, defaultFont).read();
}
Also used : MxlPrintStyleContent(com.xenoage.zong.musicxml.types.util.MxlPrintStyleContent) MxlFont(com.xenoage.zong.musicxml.types.attributes.MxlFont) MxlPrintStyle(com.xenoage.zong.musicxml.types.attributes.MxlPrintStyle) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 25 with MaybeNull

use of com.xenoage.utils.annotations.MaybeNull in project Zong by Xenoage.

the class OtherReader method readBezierPoint.

@MaybeNull
public static BezierPoint readBezierPoint(MxlPosition mxlPosition, MxlBezier mxlBezier, float tenthsMm, int staffLinesCount, float noteLP, Fraction chordDuration) {
    Float px = mxlPosition.getDefaultX();
    Float py = mxlPosition.getDefaultY();
    Float cx = (mxlBezier != null ? mxlBezier.getBezierX() : null);
    Float cy = (mxlBezier != null ? mxlBezier.getBezierY() : null);
    SP point = null;
    SP control = null;
    float halfNoteWidth = getNoteheadWidth(chordDuration) / 2;
    if (px != null && py != null) {
        float fpx = notNull(px, 0).floatValue();
        float fpy = notNull(py, 0).floatValue();
        // default-x is relative to left side of note. thus, substract the half width
        // of a note (TODO: note type. e.g., whole note is wider)
        point = sp((fpx / 10 - halfNoteWidth) * tenthsMm, (staffLinesCount - 1) * 2 + fpy / 10 * 2 - noteLP);
    }
    if (cx != null && cy != null) {
        float fcx = notNull(cx, 0).floatValue();
        float fcy = notNull(cy, 0).floatValue();
        control = sp((fcx / 10 - halfNoteWidth) * tenthsMm, fcy / 10 * 2);
    }
    if (point != null || control != null)
        return new BezierPoint(point, control);
    else
        return null;
}
Also used : BezierPoint(com.xenoage.zong.core.music.format.BezierPoint) SP(com.xenoage.zong.core.music.format.SP) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Aggregations

MaybeNull (com.xenoage.utils.annotations.MaybeNull)25 lombok.val (lombok.val)5 MxlPrintStyle (com.xenoage.zong.musicxml.types.attributes.MxlPrintStyle)4 MxlFont (com.xenoage.zong.musicxml.types.attributes.MxlFont)3 MxlPlacement (com.xenoage.zong.musicxml.types.enums.MxlPlacement)3 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)2 GradientDynamics (com.xenoage.zong.io.midi.out.dynamics.type.GradientDynamics)2 MxlLayout (com.xenoage.zong.musicxml.types.groups.MxlLayout)2 FontInfo (com.xenoage.utils.font.FontInfo)1 FontStyle (com.xenoage.utils.font.FontStyle)1 BufferedInputStream (com.xenoage.utils.io.BufferedInputStream)1 Point2f (com.xenoage.utils.math.geom.Point2f)1 XmlException (com.xenoage.utils.xml.XmlException)1 XmlReader (com.xenoage.utils.xml.XmlReader)1 DynamicValue (com.xenoage.zong.core.music.direction.DynamicValue)1 Type (com.xenoage.zong.core.music.direction.Pedal.Type)1 Wedge (com.xenoage.zong.core.music.direction.Wedge)1 WedgeEnd (com.xenoage.zong.core.music.direction.WedgeEnd)1 BezierPoint (com.xenoage.zong.core.music.format.BezierPoint)1 SP (com.xenoage.zong.core.music.format.SP)1