Search in sources :

Example 1 with Spacings

use of com.xenoage.zong.musiclayout.settings.Spacings in project Zong by Xenoage.

the class LayoutSettingsReader method read.

// private static final String file = "data/musiclayout/default.xml";
/**
 * Reads the {@link LayoutSettings} from the given input stream.
 */
public static LayoutSettings read(InputStream inputStream) throws IOException {
    ChordWidths chordWidths = null, graceChordWidths;
    Spacings spacings = null;
    float scalingClefInner = 0, scalingGrace = 0;
    float offsetMeasureStart = 0;
    float offsetBeatsMinimal = 0;
    try {
        XmlReader r = platformUtils().createXmlReader(inputStream);
        r.openNextChildElement();
        while (r.openNextChildElement()) {
            String n = r.getElementName();
            switch(n) {
                case "chordwidths":
                    // load the chord layout settings
                    chordWidths = readChordWidths(r);
                    break;
                case "spacings":
                    // load the space settings
                    spacings = readSpacings(r);
                    break;
                case "scaling":
                    // load scalings
                    while (r.openNextChildElement()) {
                        String n2 = r.getElementName();
                        if (n2.equals("clef"))
                            scalingClefInner = parseFloat(r.getAttributeNotNull("inner"));
                        else if (n2.equals("grace"))
                            scalingGrace = parseFloat(r.getAttributeNotNull("scaling"));
                        r.closeElement();
                    }
                    break;
                case "offset":
                    // load offsets
                    while (r.openNextChildElement()) {
                        String n2 = r.getElementName();
                        if (n2.equals("measure"))
                            offsetMeasureStart = parseFloat(r.getAttributeNotNull("start"));
                        else if (n2.equals("beats"))
                            offsetBeatsMinimal = parseFloat(r.getAttributeNotNull("minimal"));
                        r.closeElement();
                    }
                    break;
            }
            r.closeElement();
        }
        r.close();
    } catch (Exception ex) {
        INSTANCE.log(Companion.error("Could not read the input stream", ex));
        throw new IOException(ex);
    /*
			//default values
			durationWidths.put(fr(1, 32), 1 + 1/2f);
			durationWidths.put(fr(1, 16), 1 + 3/4f);
			durationWidths.put(fr(1, 8), 2 + 1/2f);
			durationWidths.put(fr(1, 2), 4 + 3/4f);
			widthClef = 4;
			widthSharp = 1.2f;
			widthFlat = 1f;
			widthMeasureEmpty = 8f;
			scalingClefInner = 0.75f;
			offsetMeasureStart = 1;
			offsetBeatsMinimal = 1.5f;
			*/
    }
    // compute grace chord widths
    graceChordWidths = chordWidths.scale(scalingGrace);
    return new LayoutSettings(chordWidths, graceChordWidths, spacings, scalingClefInner, scalingGrace, offsetMeasureStart, offsetBeatsMinimal);
}
Also used : LayoutSettings(com.xenoage.zong.musiclayout.settings.LayoutSettings) Spacings(com.xenoage.zong.musiclayout.settings.Spacings) SpacingsReader.readSpacings(com.xenoage.zong.io.musiclayout.SpacingsReader.readSpacings) ChordWidthsReader.readChordWidths(com.xenoage.zong.io.musiclayout.ChordWidthsReader.readChordWidths) ChordWidths(com.xenoage.zong.musiclayout.settings.ChordWidths) XmlReader(com.xenoage.utils.xml.XmlReader) IOException(java.io.IOException) IOException(java.io.IOException)

Example 2 with Spacings

use of com.xenoage.zong.musiclayout.settings.Spacings in project Zong by Xenoage.

the class SpacingsReader method readSpacings.

/**
 * Reads a {@link Spacings} from the given {@link XmlReader} at the "spacings" element.
 */
public static Spacings readSpacings(XmlReader r) throws IOException {
    ChordSpacings normalChordSpacings = null, graceChordSpacings = null;
    float widthSharp = 0, widthFlat = 0, widthClef = 0, widthMeasureEmpty = 0, widthDistanceMin = 0;
    while (r.openNextChildElement()) {
        String n = r.getElementName();
        switch(n) {
            case "chords":
                // chord spacings
                while (r.openNextChildElement()) {
                    String n2 = r.getElementName();
                    if (n2.equals("normal"))
                        normalChordSpacings = readChordSpacings(r);
                    else if (n2.equals("grace"))
                        graceChordSpacings = readChordSpacings(r);
                    r.closeElement();
                }
                break;
            case "clef":
                // clef
                widthClef = parseFloat(r.getAttributeNotNull("width"));
                break;
            case "key":
                // keys
                while (r.openNextChildElement()) {
                    String n2 = r.getElementName();
                    if (n2.equals("sharp"))
                        widthSharp = parseFloat(r.getAttributeNotNull("width"));
                    else if (n2.equals("flat"))
                        widthFlat = parseFloat(r.getAttributeNotNull("width"));
                    r.closeElement();
                }
                break;
            case "measure":
                // measure
                widthMeasureEmpty = parseFloat(r.getAttributeNotNull("empty"));
                break;
            case "distance":
                // distance
                widthDistanceMin = parseFloat(r.getAttributeNotNull("minimal"));
                break;
        }
        r.closeElement();
    }
    return new Spacings(normalChordSpacings, graceChordSpacings, widthSharp, widthFlat, widthClef, widthMeasureEmpty, widthDistanceMin);
}
Also used : Spacings(com.xenoage.zong.musiclayout.settings.Spacings) ChordSpacings(com.xenoage.zong.musiclayout.settings.ChordSpacings) ChordSpacingsReader.readChordSpacings(com.xenoage.zong.io.musiclayout.ChordSpacingsReader.readChordSpacings) ChordSpacings(com.xenoage.zong.musiclayout.settings.ChordSpacings) ChordSpacingsReader.readChordSpacings(com.xenoage.zong.io.musiclayout.ChordSpacingsReader.readChordSpacings)

Example 3 with Spacings

use of com.xenoage.zong.musiclayout.settings.Spacings in project Zong by Xenoage.

the class ElementStamper method createKeyStamping.

/**
 * Creates a stamping for the given key signature.
 */
public KeySignatureStamping createKeyStamping(TraditionalKeyNotation key, float xMm, StamperContext context) {
    val staff = context.getCurrentStaffStamping();
    boolean useSharps = key.element.getFifths() > 0;
    Symbol symbol = context.getSymbol(useSharps ? CommonSymbol.AccidentalSharp : CommonSymbol.AccidentalFlat);
    Spacings spacings = context.getSettings().spacings;
    float distance = (useSharps ? spacings.widthSharp : spacings.widthFlat);
    return new KeySignatureStamping(key, xMm, staff, symbol, distance);
}
Also used : lombok.val(lombok.val) CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol) Symbol(com.xenoage.zong.symbols.Symbol) Spacings(com.xenoage.zong.musiclayout.settings.Spacings) KeySignatureStamping(com.xenoage.zong.musiclayout.stampings.KeySignatureStamping)

Aggregations

Spacings (com.xenoage.zong.musiclayout.settings.Spacings)3 XmlReader (com.xenoage.utils.xml.XmlReader)1 ChordSpacingsReader.readChordSpacings (com.xenoage.zong.io.musiclayout.ChordSpacingsReader.readChordSpacings)1 ChordWidthsReader.readChordWidths (com.xenoage.zong.io.musiclayout.ChordWidthsReader.readChordWidths)1 SpacingsReader.readSpacings (com.xenoage.zong.io.musiclayout.SpacingsReader.readSpacings)1 ChordSpacings (com.xenoage.zong.musiclayout.settings.ChordSpacings)1 ChordWidths (com.xenoage.zong.musiclayout.settings.ChordWidths)1 LayoutSettings (com.xenoage.zong.musiclayout.settings.LayoutSettings)1 KeySignatureStamping (com.xenoage.zong.musiclayout.stampings.KeySignatureStamping)1 Symbol (com.xenoage.zong.symbols.Symbol)1 CommonSymbol (com.xenoage.zong.symbols.common.CommonSymbol)1 IOException (java.io.IOException)1 lombok.val (lombok.val)1