use of com.xenoage.zong.core.music.key.TraditionalKey in project Zong by Xenoage.
the class VoicesBeatOffsetterTest method createTestScore1Voice.
private Score createTestScore1Voice() {
Score score = new Score();
score.getFormat().setInterlineSpace(1);
Cursor cursor = new Cursor(score, mp0, true);
cursor.write(new Clef(ClefType.Companion.getClefTreble()));
cursor.write((MeasureElement) new TraditionalKey(-3));
cursor.write(new TimeSignature(TimeType.Companion.timeType(6, 4)));
// beats: 0, 2, 3, 4, 8.
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 2)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 2)));
return score;
}
use of com.xenoage.zong.core.music.key.TraditionalKey in project Zong by Xenoage.
the class Base13a method getExpectedKeys.
default TraditionalKey[] getExpectedKeys() {
TraditionalKey[] expectedKeys = new TraditionalKey[15 * 2];
for (int fifths = -7; fifths <= 7; fifths++) {
expectedKeys[(fifths + 7) * 2 + 0] = new TraditionalKey(fifths, Mode.Major);
expectedKeys[(fifths + 7) * 2 + 1] = new TraditionalKey(fifths, Mode.Minor);
}
return expectedKeys;
}
use of com.xenoage.zong.core.music.key.TraditionalKey in project Zong by Xenoage.
the class AttributesReader method readKey.
private Key readKey(MxlKey mxlKey) {
if (mxlKey == null)
return null;
// read fifths. currently, only -7 to 7 is supported (clamp, if needed)
int mxlFifths = INSTANCE.clamp(mxlKey.fifths, -7, 7);
// write to column header (TODO: attribute "number" for single staves)
Mode mode = getEnumValue(mxlKey.mode, Mode.values());
Key key = new TraditionalKey(mxlFifths, mode);
return key;
}
use of com.xenoage.zong.core.music.key.TraditionalKey in project Zong by Xenoage.
the class MeasureElementsSpacer method compute.
List<ElementSpacing> compute(BeatEList<Clef> clefs, @MaybeEmpty BeatEList<Key> keys, @MaybeNull TimeSignature time, boolean existsLeadingSpacing, List<VoiceSpacing> voiceSpacings, int staff, Notations notations, LayoutSettings layoutSettings) {
Key key0 = null;
if (keys.size() > 0 && keys.getFirst().getBeat().equals(Companion.get_0()))
key0 = keys.getFirst().getElement();
if (key0 == null && time == null && (clefs == null || clefs.size() == 0)) {
// nothing to do
return empty;
}
ArrayList<ElementSpacing> ret = alist();
float startOffset = layoutSettings.offsetMeasureStart;
// key and time
// ************
boolean isKey = !existsLeadingSpacing && key0 instanceof TraditionalKey;
boolean isTime = time != null;
if (isKey || isTime) {
float currentOffset = startOffset;
// ***
if (isKey) {
Notation keyNotation = notations.get(key0, staff);
ret.add(new SimpleSpacing(keyNotation, Companion.get_0(), startOffset));
currentOffset += keyNotation.getWidth().getUsedWidth();
}
// ****
if (time != null) {
Notation timeNotation = notations.get(time, staff);
ret.add(new SimpleSpacing(timeNotation, Companion.get_0(), currentOffset + timeNotation.getWidth().symbolWidth / 2));
currentOffset += timeNotation.getWidth().getUsedWidth();
}
// move voice elements, if not enough space before first voice element
ElementSpacing leftSE = getFirstElementSpacing(voiceSpacings);
if (leftSE != null) {
float leftSEx = getLeftX(leftSE);
// existing space
float ES = leftSEx;
// additional needed space
float AS = currentOffset - ES;
if (AS > 0) {
shift(voiceSpacings, AS);
startOffset += AS;
}
}
}
// voice 2: 1 o
if (clefs != null) {
for (BeatE<Clef> ME : clefs) {
Fraction MEb = ME.getBeat();
Notation MEnotation = notations.get(ME.getElement());
float MEwidth = MEnotation.getWidth().getWidth();
// if there is a leading spacing, ignore elements at beat 0
if (existsLeadingSpacing && !MEb.isGreater0())
continue;
// find VE1 and VE2 for the current element
ElementSpacing[] ses = getNearestSpacingElements(MEb, voiceSpacings);
ElementSpacing VE1 = ses[0], VE2 = ses[1];
// if VE1 is unknown, use startOffset. if VE2 is unknown, ignore this element
float VE1x = (VE1 != null ? getRightX(VE1) : startOffset);
if (VE2 == null)
continue;
float VE2x = getLeftX(VE2);
// existing space
float ES = VE2x - VE1x - 2 * layoutSettings.spacings.widthDistanceMin;
if (ES < MEwidth) {
// additional space needed
float AS = MEwidth - ES;
// move all elements at or after ME.beat
VE2x += AS;
shiftAfterBeat(voiceSpacings, AS, MEb);
}
// add measure element
float MEx = VE2x - layoutSettings.spacings.widthDistanceMin - MEwidth / 2;
ret.add(new SimpleSpacing(MEnotation, ME.getBeat(), MEx));
}
}
ret.trimToSize();
return ret;
}
use of com.xenoage.zong.core.music.key.TraditionalKey in project Zong by Xenoage.
the class MidiSequenceWriter method writeKey.
/**
* Writes a MIDI key signature. Only {@link TraditionalKey} is supported.
* @param track the index of the track where to write the event
* @param tick the time of the event
* @param key The {@link Key} to write
*/
public void writeKey(int track, long tick, Key key) {
if (key.getMusicElementType() == MusicElementType.TraditionalKey) {
val tradKey = (TraditionalKey) key;
byte fifths = (byte) tradKey.getFifths();
// minor, or (everything else) major
byte mode = (byte) (tradKey.getMode() == TraditionalKey.Mode.Minor ? 1 : 0);
byte[] data = { fifths, mode };
writeMetaMessage(track, tick, typeKey, data);
}
}
Aggregations