Search in sources :

Example 6 with MaybeNull

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

the class MxlLyricFont method read.

@MaybeNull
public static MxlLyricFont read(XmlReader reader) {
    String number = reader.getAttribute("number");
    String name = reader.getAttribute("name");
    MxlFont font = MxlFont.read(reader);
    if (number != null || name != null || font != null)
        return new MxlLyricFont(number, name, font);
    else
        return null;
}
Also used : MxlFont(com.xenoage.zong.musicxml.types.attributes.MxlFont) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 7 with MaybeNull

use of com.xenoage.utils.annotations.MaybeNull 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 8 with MaybeNull

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

the class DynamicsFinder method getStaffDynamicStartAt.

/**
 * Returns the {@link DynamicsType} starting at the given time within the given staff (not a voice),
 * or null, if nothing starts here.
 */
@MaybeNull
private DynamicsType getStaffDynamicStartAt(int staff, Time time, DynamicValue currentDynamicValue) {
    val measure = score.getMeasure(atMeasure(staff, time.getMeasure()));
    // when there is a Wedge (possible with a Dynamic as the start volume), create
    // a gradient dynamic, when there is only a Dynamic, create a fixed dynamic
    val foundDynamic = (Dynamic) measure.getDirections().get(time.getBeat(), MusicElementType.Dynamic);
    val foundWedge = (Wedge) measure.getDirections().get(time.getBeat(), MusicElementType.Wedge);
    if (foundWedge != null) {
        // gradient
        val startDynamicValue = (foundDynamic != null ? foundDynamic.getValue() : currentDynamicValue);
        val endDynamicValue = startDynamicValue.getWedgeEndValue(foundWedge.getType());
        // can be replaced later, when end dynamic is found
        return new GradientDynamics(startDynamicValue, endDynamicValue);
    } else if (foundDynamic != null) {
        // fixed value
        return new FixedDynamics(foundDynamic.getValue());
    }
    return null;
}
Also used : lombok.val(lombok.val) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) FixedDynamics(com.xenoage.zong.io.midi.out.dynamics.type.FixedDynamics) Wedge(com.xenoage.zong.core.music.direction.Wedge) GradientDynamics(com.xenoage.zong.io.midi.out.dynamics.type.GradientDynamics) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 9 with MaybeNull

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

the class DynamicsPeriods method get.

/**
 * Gets the {@link DynamicsPeriod} for the given position.
 * The highest priority has a dynamic in the current voice. If there is none,
 * the last dynamic of the part is searched. When there are multiple candidates
 * on different staves, the current staff wins.
 * @param mp          the position where to find the dynamic
 * @param repetition  the index of the {@link Repetition}
 * @param partStaves  the staves indices in the part
 */
@MaybeNull
public DynamicsPeriod get(MP mp, int repetition, Range partStaves) {
    val time = mp.getTime();
    // first, find voice dynamics
    val voicePeriods = getVoicePeriods(mp.getStaff(), mp.getVoice(), repetition);
    val voicePeriod = getPeriod(voicePeriods, time);
    if (voicePeriod != null)
        return voicePeriod;
    // then, for all staves in the part, look for last period(s) - when there
    // is more than one at the same time, prefer the one at the own staff
    Time maxStartTime = time;
    DynamicsPeriod bestMatch = null;
    for (int iStaff : partStaves) {
        val staffPeriods = getStaffPeriods(mp.getStaff(), repetition);
        val staffPeriod = getPeriod(staffPeriods, time);
        int compare = staffPeriod.startTime.compareTo(maxStartTime);
        if (staffPeriod != null && compare > 0 || (compare >= 0 && iStaff == mp.getStaff())) {
            // new best match
            maxStartTime = staffPeriod.startTime;
            bestMatch = null;
        }
    }
    return bestMatch;
}
Also used : lombok.val(lombok.val) Time(com.xenoage.zong.core.position.Time) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 10 with MaybeNull

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

the class VoltaGroups method getStateAt.

/**
 * Gets information about the volta group over the given measure.
 */
@MaybeNull
public VoltaGroupState getStateAt(int measure) {
    val group = getVoltaGroupAt(measure);
    val volta = getVoltaAt(measure);
    if (volta == null)
        return null;
    return new VoltaGroupState(group, volta.volta, volta.startMeasure, volta.startMeasure + volta.volta.getLength() - 1);
}
Also used : lombok.val(lombok.val) 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