Search in sources :

Example 1 with MaybeNull

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

the class FileTypeReader method getFileType.

@MaybeNull
public static FileType getFileType(InputStream inputStream) throws IOException {
    // create buffered stream for reuse
    BufferedInputStream bis = new BufferedInputStream(inputStream);
    bis.mark();
    // read first two characters. if "PK", we have a compressed MusicXML file.
    int[] bytes = new int[] { bis.read(), bis.read() };
    if (// P, K
    bytes[0] == 80 && bytes[1] == 75) {
        return FileType.Compressed;
    }
    bis.reset();
    bis.unmark();
    // otherwise, try to parse as XML up to the root element (using StAX)
    try {
        XmlReader reader = platformUtils().createXmlReader(bis);
        if (reader.openNextChildElement()) {
            String n = reader.getElementName();
            switch(n) {
                case "score-partwise":
                    return FileType.XMLScorePartwise;
                case "score-timewise":
                    return FileType.XMLScoreTimewise;
                case "opus":
                    return FileType.XMLOpus;
            }
            reader.closeElement();
        }
    } catch (XmlException ex) {
        // unknown (no XML)
        return null;
    }
    // unknown
    return null;
}
Also used : BufferedInputStream(com.xenoage.utils.io.BufferedInputStream) XmlException(com.xenoage.utils.xml.XmlException) XmlReader(com.xenoage.utils.xml.XmlReader) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 2 with MaybeNull

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

the class FontInfoReader method read.

@MaybeNull
public FontInfo read() {
    IList<String> families = readFamilies();
    Float size = readSize();
    FontStyle style = readStyle();
    return new FontInfo(families, size, style);
}
Also used : FontStyle(com.xenoage.utils.font.FontStyle) MxlFontStyle(com.xenoage.zong.musicxml.types.enums.MxlFontStyle) FontInfo(com.xenoage.utils.font.FontInfo) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 3 with MaybeNull

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

the class MxlFermata method read.

/**
 * Reads the given element and returns it, or returns null if
 * the element is not supported.
 */
@MaybeNull
public static MxlFermata read(XmlReader reader) {
    MxlUprightInverted type = MxlUprightInverted.read(reader, "type");
    MxlPrintStyle printStyle = MxlPrintStyle.read(reader);
    return new MxlFermata(type, printStyle);
}
Also used : MxlUprightInverted(com.xenoage.zong.musicxml.types.enums.MxlUprightInverted) MxlPrintStyle(com.xenoage.zong.musicxml.types.attributes.MxlPrintStyle) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 4 with MaybeNull

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

the class MxlDefaults method read.

@MaybeNull
public static MxlDefaults read(XmlReader reader) {
    MxlScaling scaling = null;
    MxlLayout layout = new MxlLayout();
    MxlFont wordFont = null;
    MxlLyricFont lyricFont = null;
    while (reader.openNextChildElement()) {
        String n = reader.getElementName();
        if (n.equals(MxlScaling.elemName))
            scaling = MxlScaling.read(reader);
        else if (n.equals("word-font"))
            wordFont = MxlFont.read(reader);
        else if (// read only first
        n.equals(MxlLyricFont.elemName) && lyricFont == null)
            lyricFont = MxlLyricFont.read(reader);
        else
            layout.readElement(reader);
        reader.closeElement();
    }
    if (false == layout.isUsed())
        layout = null;
    if (scaling != null || layout != null || wordFont != null || lyricFont != null)
        return new MxlDefaults(scaling, layout, wordFont, lyricFont);
    else
        return null;
}
Also used : MxlLayout(com.xenoage.zong.musicxml.types.groups.MxlLayout) MxlFont(com.xenoage.zong.musicxml.types.attributes.MxlFont) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 5 with MaybeNull

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

the class MxlKey method read.

/**
 * Returns null, if the key is unsupported.
 */
@MaybeNull
public static MxlKey read(XmlReader reader) {
    Integer fifths = null;
    MxlMode mode = null;
    while (reader.openNextChildElement()) {
        String eName = reader.getElementName();
        if (eName.equals("fifths")) {
            fifths = Parser.parseIntegerNull(reader.getText());
        } else if (eName.equals(MxlMode.elemName)) {
            mode = MxlMode.read(reader);
        }
        reader.closeElement();
    }
    if (fifths != null)
        return new MxlKey(fifths, mode);
    else
        return null;
}
Also used : MxlMode(com.xenoage.zong.musicxml.types.enums.MxlMode) 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