use of com.xenoage.zong.core.music.clef.Clef 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.clef.Clef in project Zong by Xenoage.
the class MeasureElementsSpacerTest method testEnoughExistingSpace.
/**
* If there is enough space left for the measure elements,
* the voice spacings do not have to be changed.
* To understand the following sketch, have a look at the comments
* in {@link MeasureElementsSpacer}.
* <pre>
* enough space:
* beat: 0 2 4 6 8
* offset: 3 5 7 9 13 17 21
* . . . . . . . . . .
* clef: *[clef]* (on beat 6)
* voice 1: o 2
* voice 2: 1 o
* </pre>
*/
@Test
public void testEnoughExistingSpace() {
Rest[] ve = ve();
List<VoiceSpacing> originalVs = alist(new VoiceSpacing(null, 1, alist(spacing(ve[0], Companion.fr(1, 2), 4), spacing(ve[1], Companion.fr(6), 15))), new VoiceSpacing(null, 1, alist(spacing(ve[2], Companion.fr(1), 5), spacing(ve[3], Companion.fr(17, 2), 20))));
List<VoiceSpacing> vs = alist(originalVs);
Clef innerClef = new Clef(ClefType.Companion.getClefTreble());
BeatEList<Clef> innerClefs = Companion.beatEList();
innerClefs.add(Companion.beatE(innerClef, Companion.fr(6)));
List<ElementSpacing> res = testee.compute(innerClefs, Companion.beatEList(), null, false, vs, 0, notations(ve, innerClef), ls);
// clef must be at offset 15 - padding - clefwidth/2
ElementSpacing[] mes = res.toArray(new ElementSpacing[0]);
assertEquals(1, mes.length);
assertEquals(Companion.fr(6), mes[0].beat);
assertEquals(15 - paddingWidth - clefWidth / 2, mes[0].xIs, Delta.DELTA_FLOAT);
// voice spacings must be unchanged
assertEquals(originalVs, vs);
}
use of com.xenoage.zong.core.music.clef.Clef in project Zong by Xenoage.
the class LeadingSpacingMock method createGClefSpacing.
/**
* Creates an easy MeasureLeadingSpacing (with a g-clef)
* that has the given width in IS.
*/
public static LeadingSpacing createGClefSpacing(float widthIs) {
ClefNotation notation = new ClefNotation(new Clef(ClefType.Companion.getClefTreble()), new ElementWidth(widthIs), 0, 1);
ElementSpacing spacing = new SimpleSpacing(notation, Companion.fr(0), 0);
return new LeadingSpacing(alist(spacing), widthIs);
}
use of com.xenoage.zong.core.music.clef.Clef in project Zong by Xenoage.
the class Base43e method getExpectedClefs.
static List<Tuple2<MP, Clef>> getExpectedClefs() {
List<Tuple2<MP, Clef>> clefs = alist();
clefs.add(t(atBeat(0, 0, unknown, Companion.get_0()), new Clef(ClefType.Companion.getClefTreble())));
clefs.add(t(atBeat(0, 2, unknown, Companion.get_0()), new Clef(new ClefType(ClefSymbol.C, 2))));
clefs.add(t(atBeat(1, 0, unknown, Companion.get_0()), new Clef(ClefType.Companion.getClefBass())));
clefs.add(t(atBeat(1, 1, unknown, Companion.get_0()), new Clef(ClefType.Companion.getClefTreble())));
return clefs;
}
use of com.xenoage.zong.core.music.clef.Clef 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;
}
Aggregations