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);
}
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);
}
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);
}
Aggregations