Search in sources :

Example 1 with MxlStartStop

use of com.xenoage.zong.musicxml.types.enums.MxlStartStop in project Zong by Xenoage.

the class MxlPartGroup method read.

@NonNull
public static MxlPartGroup read(XmlReader reader) {
    // attributes
    MxlStartStop type = MxlStartStop.read(reader.getAttributeNotNull("type"));
    String number = notNull(reader.getAttribute("number"), defaultNumber);
    // elements
    String groupName = null;
    String groupAbbreviation = null;
    MxlGroupSymbol groupSymbol = null;
    MxlGroupBarline groupBarline = null;
    while (reader.openNextChildElement()) {
        String n = reader.getElementName();
        switch(n) {
            case "group-name":
                groupName = reader.getTextNotNull();
                break;
            case "group-abbreviation":
                groupAbbreviation = reader.getTextNotNull();
                break;
            case "group-symbol":
                groupSymbol = MxlGroupSymbol.read(reader);
                break;
            case "group-barline":
                groupBarline = MxlGroupBarline.read(reader);
                break;
        }
        reader.closeElement();
    }
    return new MxlPartGroup(groupName, groupAbbreviation, groupSymbol, groupBarline, type, number);
}
Also used : MxlStartStop(com.xenoage.zong.musicxml.types.enums.MxlStartStop) NonNull(com.xenoage.utils.annotations.NonNull)

Example 2 with MxlStartStop

use of com.xenoage.zong.musicxml.types.enums.MxlStartStop in project Zong by Xenoage.

the class StavesListReader method readPartGroup.

/**
 * Reads a part-group element.
 * If a group was closed, it is returned. If a group was opened or it can not be read,
 * null is returned. While MusicXML groups can be combined barline and bracket groups,
 * these are separated values in Zong!. This is why they are returned as a tuple
 * (with null if not set).
 */
private PartsGroups readPartGroup(int currentPartIndex, MxlPartGroup mxlPartGroup, Map<String, PartsBarlineGroup> openBarlineGroups, Map<String, PartsBracketGroup> openBracketGroups) {
    String number = mxlPartGroup.getNumber();
    MxlStartStop type = mxlPartGroup.getType();
    PartsBarlineGroup openBarlineGroup = openBarlineGroups.get(number);
    PartsBracketGroup openBracketGroup = openBracketGroups.get(number);
    if (type == MxlStartStop.Start) {
        // group begins here
        if (openBarlineGroup != null || openBracketGroup != null) {
            errorHandling.reportError("part-group \"" + number + "\" was already opened");
        }
        // read group-barline and group-symbol (bracket)
        BarlineGroup.Style barlineStyle = readBarlineGroupStyle(mxlPartGroup.getGroupBarline());
        if (barlineStyle != BarlineGroup.Style.Single) {
            openBarlineGroups.put(number, openBarlineGroup = new PartsBarlineGroup());
            openBarlineGroup.startPartIndex = currentPartIndex;
            openBarlineGroup.style = barlineStyle;
        }
        BracketGroup.Style bracketStyle = readBracketGroupStyle(mxlPartGroup.getGroupSymbol());
        if (bracketStyle != BracketGroup.Style.None) {
            openBracketGroups.put(number, openBracketGroup = new PartsBracketGroup());
            openBracketGroup.startPartIndex = currentPartIndex;
            openBracketGroup.style = bracketStyle;
        }
        return null;
    } else if (type == MxlStartStop.Stop) {
        // group ends here
        if (openBarlineGroup == null && openBracketGroup == null) {
            errorHandling.reportError("score-group \"" + number + "\" was closed before it was opened");
        }
        // close open barline group and/or bracket group
        PartsBarlineGroup closedBarlineGroup = null;
        if (openBarlineGroup != null) {
            closedBarlineGroup = openBarlineGroup;
            openBarlineGroups.remove(number);
            closedBarlineGroup.stopPartIndex = currentPartIndex - 1;
        }
        PartsBracketGroup closedBracketGroup = null;
        if (openBracketGroup != null) {
            closedBracketGroup = openBracketGroup;
            openBracketGroups.remove(number);
            closedBracketGroup.stopPartIndex = currentPartIndex - 1;
        }
        PartsGroups ret = new PartsGroups();
        ret.barlineGroup = closedBarlineGroup;
        ret.bracketsGroup = closedBracketGroup;
        return ret;
    }
    return null;
}
Also used : BracketGroup(com.xenoage.zong.core.music.group.BracketGroup) MxlStartStop(com.xenoage.zong.musicxml.types.enums.MxlStartStop) BarlineGroup(com.xenoage.zong.core.music.group.BarlineGroup)

Aggregations

MxlStartStop (com.xenoage.zong.musicxml.types.enums.MxlStartStop)2 NonNull (com.xenoage.utils.annotations.NonNull)1 BarlineGroup (com.xenoage.zong.core.music.group.BarlineGroup)1 BracketGroup (com.xenoage.zong.core.music.group.BracketGroup)1