Search in sources :

Example 1 with Placement

use of com.xenoage.zong.core.music.format.Placement in project Zong by Xenoage.

the class DirectionStamper method computePosition.

/**
 * Computes the position for the given {@link Direction}
 * within the given {@link StaffStamping}.
 */
private SP computePosition(Direction direction, StaffStamping staffStamping, float defaultLP, float defaultLPAbove, float defaultLPBelow) {
    Positioning customPos = direction.getPositioning();
    MP mp = direction.getMP();
    if (mp == null)
        // TODO. Happens. But just with offical MusicXML sample Telemann.xml
        return SP.sp(0, 0);
    float x, lp;
    // default positioning
    x = notNull(staffStamping.system.getXMmAt(mp.getTime()), 0f) + staffStamping.positionMm.x;
    lp = defaultLP;
    // custom positioning
    if (customPos instanceof Placement) {
        Placement placement = (Placement) customPos;
        if (placement == Placement.Above)
            lp = defaultLPAbove;
        else
            lp = defaultLPBelow;
    } else if (customPos instanceof Position) {
        // coordinates
        Position pos = (Position) customPos;
        if (pos.x != null)
            x = pos.x;
        x += Position.getRelativeX(pos);
        // vertical position
        if (pos.y != null)
            lp = pos.y;
        lp += Position.getRelativeY(pos);
    }
    return sp(x, lp);
}
Also used : Positioning(com.xenoage.zong.core.music.format.Positioning) MP(com.xenoage.zong.core.position.MP) Placement(com.xenoage.zong.core.music.format.Placement) Position(com.xenoage.zong.core.music.format.Position)

Aggregations

Placement (com.xenoage.zong.core.music.format.Placement)1 Position (com.xenoage.zong.core.music.format.Position)1 Positioning (com.xenoage.zong.core.music.format.Positioning)1 MP (com.xenoage.zong.core.position.MP)1