Search in sources :

Example 16 with MaybeNull

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

the class MxlDirectionType method read.

/**
 * Returns null, if content is unsupported.
 */
@MaybeNull
public static MxlDirectionType read(XmlReader reader) {
    MxlDirectionTypeContent content = null;
    if (reader.openNextChildElement()) {
        String n = reader.getElementName();
        switch(// switch for performance
        n.charAt(0)) {
            case 'c':
                if (n.equals(MxlCoda.elemName))
                    content = MxlCoda.read(reader);
                break;
            case 'd':
                if (n.equals(MxlDynamics.elemName))
                    content = MxlDynamics.read(reader);
                break;
            case 'i':
                if (n.equals("image"))
                    content = MxlImage.read(reader);
                break;
            case 'p':
                if (n.equals(MxlPedal.elemName))
                    content = MxlPedal.read(reader);
                break;
            case 'm':
                if (n.equals(MxlMetronome.elemName))
                    content = MxlMetronome.read(reader);
                break;
            case 's':
                if (n.equals(MxlSegno.elemName))
                    content = MxlSegno.read(reader);
                break;
            case 'w':
                if (n.equals(MxlWedge.elemName))
                    content = MxlWedge.read(reader);
                else if (n.equals(MxlWords.elemName))
                    content = MxlWords.read(reader);
                break;
        }
        reader.closeElement();
    }
    if (content != null)
        return new MxlDirectionType(content);
    else
        return null;
}
Also used : MxlDirectionTypeContent(com.xenoage.zong.musicxml.types.choice.MxlDirectionTypeContent) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 17 with MaybeNull

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

the class MxlLyric method read.

/**
 * Reads and returns the lyric content of the given element,
 * or returns null if unsupported.
 */
@MaybeNull
public static MxlLyric read(XmlReader reader) {
    String number = reader.getAttribute("number");
    MxlLyricContent content = null;
    if (reader.openNextChildElement()) {
        String n = reader.getElementName();
        if (n.equals("syllabic") || n.equals("text")) {
            content = MxlSyllabicText.read(reader);
        } else if (n.equals("extend")) {
            content = MxlExtend.read();
        }
        reader.closeElement();
    }
    if (content != null) {
        return new MxlLyric(content, number);
    } else {
        return null;
    }
}
Also used : MxlLyricContent(com.xenoage.zong.musicxml.types.choice.MxlLyricContent) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 18 with MaybeNull

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

the class MxlMetronome method read.

/**
 * Returns null, if the given element contains an unsupported metronome type.
 */
@MaybeNull
public static MxlMetronome read(XmlReader reader) {
    // attributes
    MxlPrintStyle printStyle = MxlPrintStyle.read(reader);
    // elements
    String sBeatUnit = null;
    int dotsCount = 0;
    Integer perMinute = null;
    while (reader.openNextChildElement()) {
        String n = reader.getElementName();
        switch(n) {
            case "beat-unit":
                sBeatUnit = reader.getText();
                break;
            case "beat-unit-dot":
                dotsCount++;
                break;
            case "per-minute":
                perMinute = parseIntegerNull(reader.getText());
                break;
        }
        reader.closeElement();
    }
    if (sBeatUnit != null && perMinute != null) {
        MxlNoteTypeValue beatUnit = MxlNoteTypeValue.read(sBeatUnit);
        return new MxlMetronome(beatUnit, dotsCount, perMinute, printStyle);
    } else {
        return null;
    }
}
Also used : MxlNoteTypeValue(com.xenoage.zong.musicxml.types.enums.MxlNoteTypeValue) MxlPrintStyle(com.xenoage.zong.musicxml.types.attributes.MxlPrintStyle) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 19 with MaybeNull

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

the class PartNameStamper method stamp.

@MaybeNull
public FrameTextStamping stamp(Part part, int firstStaffIndex, List<StaffStamping> systemStaves, Style style) {
    StaffStamping firstStaff = systemStaves.get(firstStaffIndex);
    StaffStamping lastStaff = systemStaves.get(firstStaffIndex + part.getStavesCount() - 1);
    String name = (style == Style.Full ? part.getName() : part.getAbbreviation());
    if (name == null || name.length() == 0)
        return null;
    // in the middle of the staves
    float top = firstStaff.positionMm.y;
    float bottom = lastStaff.positionMm.y + (lastStaff.linesCount - 1) * lastStaff.is;
    FormattedText text = // TODO
    Companion.fText(// TODO
    name, // TODO
    new FormattedTextStyle(firstStaff.is * 2.5f * 2.67f), Alignment.Right);
    if (text.getParagraphs().size() == 0)
        return null;
    // TODO correction of baseline. /3 looks good.
    float middle = (top + bottom) / 2 + text.getFirstParagraph().getMetrics().getAscent() / 3;
    return new FrameTextStamping(text, new Point2f(firstStaff.positionMm.x - firstStaff.is * 2.5f, middle), // TODO
    null);
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) FormattedTextStyle(com.xenoage.zong.core.text.FormattedTextStyle) FrameTextStamping(com.xenoage.zong.musiclayout.stampings.FrameTextStamping) FormattedText(com.xenoage.zong.core.text.FormattedText) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 20 with MaybeNull

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

the class VoltaGroups method getVoltaAt.

/**
 * Gets the {@link Volta} and its start measure over the given measure.
 */
@MaybeNull
public VoltaStartMeasure getVoltaAt(int measure) {
    val group = getVoltaGroupAt(measure);
    if (group == null)
        return null;
    VoltaStartMeasure volta = null;
    for (val v : group.voltasStartMeasures) {
        volta = v;
        if (measure < v.startMeasure + v.volta.getLength())
            break;
    }
    return volta;
}
Also used : lombok.val(lombok.val) VoltaStartMeasure(com.xenoage.zong.io.midi.out.repetitions.VoltaGroup.VoltaStartMeasure) 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