use of com.xenoage.zong.core.music.clef.Clef in project Zong by Xenoage.
the class AttributesReader method readToContext.
/**
* Reads the given attributes element.
*/
public void readToContext(Context context) {
// divisions
Integer divisions = mxlAttributes.getDivisions();
if (divisions != null)
context.setDivisions(divisions);
// key signature
Key key = readKey(mxlAttributes.getKey());
if (key != null)
context.writeColumnElement(key);
// time signature
TimeSignature time = readTime(mxlAttributes.getTime());
if (// TODO: attribute "number" for single staves
time != null)
context.writeColumnElement(time);
// clefs
if (mxlAttributes.getClefs() != null) {
for (MxlClef mxlClef : mxlAttributes.getClefs()) {
ClefReader clefReader = new ClefReader(mxlClef);
Clef clef = clefReader.read();
int staff = clefReader.readStaff();
if (clef != null)
context.writeMeasureElement(clef, staff);
}
}
// transposition changes - TODO: clean solution for instrument changes
PitchedInstrument instrument = readTransposedInstrument(mxlAttributes.getTranspose());
if (instrument != null) {
// write to all staves of this part
for (int staff = 0; staff < context.getPartStaffIndices().getCount(); staff++) context.writeMeasureElement(new InstrumentChange(instrument), staff);
}
}
use of com.xenoage.zong.core.music.clef.Clef in project Zong by Xenoage.
the class ScoreRevolutionary method createScore.
public static Score createScore() {
Score score = new Score();
Instrument instr = Instrument.defaultInstrument;
float is = score.getFormat().getInterlineSpace();
StaffLayout staffLayout = new StaffLayout(is * 9);
score.getFormat().setStaffLayoutOther(staffLayout);
ArticulationType[] accent = { ArticulationType.Accent };
ArticulationType[] staccato = { ArticulationType.Staccato };
Fraction f2 = fr(1, 2);
Fraction f4 = fr(1, 4);
Fraction f8 = fr(1, 8);
Fraction f16 = fr(1, 16);
Chord attachC, firstSlurC, lastSlurC;
BezierPoint firstSlurB, lastSlurB;
Part pianoPart = new Part("Piano", null, 2, alist(instr));
new PartAdd(score, pianoPart, 0, null).execute();
// set barlines and brackets
new BarlineGroupAdd(score.getStavesList(), new BarlineGroup(new StavesRange(0, 1), BarlineGroup.Style.Common)).execute();
new BracketGroupAdd(score.getStavesList(), new BracketGroup(new StavesRange(0, 1), BracketGroup.Style.Bracket)).execute();
// use cursor for more convenient input
Cursor cursor = new Cursor(score, MP.mp0, true);
// C minor, C (4/4) time
cursor.write((ColumnElement) new TraditionalKey(-3, Mode.Minor));
cursor.write(new TimeSignature(TimeType.timeCommon));
// first staff: g-clef and some notes
cursor.write(new Clef(ClefType.clefTreble));
// measure 1
// , , FontInfo.defaultValue, );
Tempo tempo = new Tempo(f4, 160);
tempo.setText(ut("Allegro con fuoco."));
tempo.setPositioning(new Position(null, 22f, -5f, -5f));
cursor.write((ColumnElement) tempo);
cursor.write(attachC = chord(f2, accent, pi(B, 4), pi(D, 5), pi(F, 5), pi(G, 5), pi(B, 5)));
attachC.setDirections(addOrNew(attachC.getDirections(), new Dynamic(DynamicValue.f)));
cursor.write(new Rest(f2));
// measure 2
cursor.write(new Rest(f2));
cursor.write(new Rest(f4));
Wedge cresc = new Wedge(WedgeType.Crescendo);
cresc.setPositioning(new Position(null, null, -1f, -2f));
cursor.write((MeasureElement) cresc);
cursor.openBeam();
cursor.write(firstSlurC = chord(fr(3, 16), accent, pi(A, -1, 4), pi(E, -1, 5), pi(F, 5), pi(A, -1, 5)));
cursor.write(lastSlurC = chord(f16, pi(G, 4), pi(G, 5)));
cursor.closeBeam();
cursor.write((MeasureElement) cresc.getWedgeEnd());
firstSlurB = new BezierPoint(sp(is * 0.8f, is * 7.6f), sp(is, is * 0.8f));
lastSlurB = new BezierPoint(sp(0, is * 6f), sp(-is, is));
new SlurAdd(new Slur(SlurType.Slur, clwp(firstSlurC, firstSlurB), clwp(lastSlurC, lastSlurB), null)).execute();
// measure 3
cursor.write(attachC = chord(f2, pi(D, 5), pi(F, 5), pi(G, 5), pi(D, 6)));
new DirectionAdd(new Dynamic(DynamicValue.f), attachC).execute();
cursor.write(new Rest(f2));
// measure 4
cursor.write(new Rest(f2));
cursor.write(new Rest(f4));
cresc = new Wedge(WedgeType.Crescendo);
cresc.setPositioning(new Position(null, null, -1f, -2f));
cursor.write((MeasureElement) cresc);
cursor.openBeam();
cursor.write(firstSlurC = chord(fr(3, 16), accent, pi(A, -1, 4), pi(E, -1, 5), pi(F, 0, 5), pi(A, -1, 5)));
cursor.write(lastSlurC = chord(f16, pi(G, 0, 4), pi(G, 0, 5)));
cursor.closeBeam();
cursor.write((MeasureElement) cresc.getWedgeEnd());
firstSlurB = new BezierPoint(sp(is * 0.8f, is * 7.6f), sp(is, is * 0.8f));
lastSlurB = new BezierPoint(sp(0, is * 6f), sp(-is, is));
new SlurAdd(new Slur(SlurType.Slur, clwp(firstSlurC, firstSlurB), clwp(lastSlurC, lastSlurB), null)).execute();
// measure 5
cursor.write(attachC = chord(f4, staccato, pi(F, 5), pi(G, 5), pi(D, 6), pi(F, 6)));
new DirectionAdd(new Dynamic(DynamicValue.f), attachC).execute();
cursor.write(new Rest(f4));
cursor.write(new Rest(f2));
// second staff: f-clef some notes
cursor = new Cursor(cursor.getScore(), mp(1, 0, 0, _0, 0), true);
cursor.write(new Clef(ClefType.clefBass));
// measure 1
cursor.openBeam();
cursor.write(new Rest(f8));
cursor.write(firstSlurC = chord(f16, pi(A, -1, 4)));
cursor.write(chord(f16, pi(G, 0, 4)));
cursor.closeBeam();
cursor.openBeam();
cursor.write(chord(f16, accent, pi(F, 0, 4)));
cursor.write(chord(f16, pi(D, 0, 4)));
cursor.write(chord(f16, pi(E, -1, 4)));
cursor.write(chord(f16, pi(D, 0, 4)));
cursor.closeBeam();
cursor.openBeam();
cursor.write(chord(f16, accent, pi(B, 0, 3)));
cursor.write(chord(f16, pi(G, 0, 3)));
cursor.write(chord(f16, pi(A, -1, 3)));
cursor.write(chord(f16, pi(G, 0, 3)));
cursor.closeBeam();
cursor.openBeam();
cursor.write(chord(f16, accent, pi(F, 0, 3)));
cursor.write(chord(f16, pi(D, 0, 3)));
cursor.write(chord(f16, pi(E, -1, 3)));
cursor.write(chord(f16, pi(D, 0, 3)));
cursor.closeBeam();
// measure 2
cursor.openBeam();
cursor.write(chord(f16, accent, pi(B, 0, 2)));
cursor.write(chord(f16, pi(G, 0, 2)));
cursor.write(chord(f16, pi(A, -1, 2)));
cursor.write(chord(f16, pi(G, 0, 2)));
cursor.closeBeam();
cursor.openBeam();
cursor.write(chord(f16, accent, pi(F, 0, 2)));
cursor.write(chord(f16, pi(D, 0, 2)));
cursor.write(chord(f16, pi(E, -1, 2)));
cursor.write(chord(f16, pi(D, 0, 2)));
cursor.closeBeam();
cursor.openBeam();
cursor.write(chord(f16, accent, pi(C, 0, 2)));
cursor.write(chord(f16, pi(G, 0, 1)));
cursor.write(chord(f16, pi(C, 0, 2)));
cursor.write(chord(f16, pi(G, 0, 1)));
cursor.closeBeam();
cursor.openBeam();
cursor.write(chord(f16, accent, pi(C, 0, 2)));
cursor.write(chord(f16, pi(G, 0, 1)));
cursor.write(chord(f16, pi(C, 0, 2)));
cursor.write(lastSlurC = chord(f16, pi(G, 0, 1)));
cursor.closeBeam();
firstSlurB = new BezierPoint(sp(0, is * 1.5f), sp(15, 5));
lastSlurB = new BezierPoint(sp(0, is * 7.5f), sp(-is * 5, is * 2));
new SlurAdd(new Slur(SlurType.Slur, clwp(firstSlurC, firstSlurB), clwp(lastSlurC, lastSlurB), null)).execute();
// measure 3
cursor.write(chord(f8, staccato, pi(B, 0, 1)));
cursor.openBeam();
cursor.write(firstSlurC = chord(f16, pi(A, -1, 4)));
cursor.write(chord(f16, pi(G, 0, 4)));
cursor.closeBeam();
cursor.openBeam();
cursor.write(chord(f16, accent, pi(F, 0, 4)));
cursor.write(chord(f16, pi(D, 0, 4)));
cursor.write(chord(f16, pi(E, -1, 4)));
cursor.write(chord(f16, pi(D, 0, 4)));
cursor.closeBeam();
cursor.openBeam();
cursor.write(chord(f16, accent, pi(B, 0, 3)));
cursor.write(chord(f16, pi(G, 0, 3)));
cursor.write(chord(f16, pi(A, -1, 3)));
cursor.write(chord(f16, pi(G, 0, 3)));
cursor.closeBeam();
cursor.openBeam();
cursor.write(chord(f16, accent, pi(F, 0, 3)));
cursor.write(chord(f16, pi(D, 0, 3)));
cursor.write(chord(f16, pi(E, -1, 3)));
cursor.write(lastSlurC = chord(f16, pi(D, 0, 3)));
cursor.closeBeam();
firstSlurB = new BezierPoint(sp(0, is * 1.5f), sp(15, 3));
lastSlurB = new BezierPoint(sp(0, is * 5f), sp(-is * 5.5f, is * 2));
new SlurAdd(new Slur(SlurType.Slur, clwp(firstSlurC, firstSlurB), clwp(lastSlurC, lastSlurB), null)).execute();
// measure 4
cursor.openBeam();
cursor.write(firstSlurC = chord(f16, accent, pi(B, 0, 2)));
cursor.write(chord(f16, pi(G, 0, 2)));
cursor.write(chord(f16, pi(A, -1, 2)));
cursor.write(chord(f16, pi(G, 0, 2)));
cursor.closeBeam();
cursor.openBeam();
cursor.write(chord(f16, accent, pi(F, 0, 2)));
cursor.write(chord(f16, pi(D, 0, 2)));
cursor.write(chord(f16, pi(E, -1, 2)));
cursor.write(chord(f16, pi(D, 0, 2)));
cursor.closeBeam();
cursor.openBeam();
cursor.write(chord(f16, accent, pi(C, 0, 2)));
cursor.write(chord(f16, pi(G, 0, 1)));
cursor.write(chord(f16, pi(C, 0, 2)));
cursor.write(chord(f16, pi(G, 0, 1)));
cursor.closeBeam();
cursor.openBeam();
cursor.write(chord(f16, accent, pi(C, 0, 2)));
cursor.write(chord(f16, pi(G, 0, 1)));
cursor.write(chord(f16, pi(C, 0, 2)));
cursor.write(lastSlurC = chord(f16, pi(G, 0, 1)));
cursor.closeBeam();
firstSlurB = new BezierPoint(sp(-is, is * 8.5f), sp(15, 4));
lastSlurB = new BezierPoint(sp(0, is * 7.5f), sp(-is * 5, is * 2));
new SlurAdd(new Slur(SlurType.Slur, clwp(firstSlurC, firstSlurB), clwp(lastSlurC, lastSlurB), null)).execute();
// measure 5
cursor.write(chord(f4, staccato, pi(B, 0, 1)));
cursor.write(new Rest(f4));
cursor.write(new Rest(f2));
// end line
Barline barlineEnd = Barline.barline(BarlineStyle.LightHeavy);
new ColumnElementWrite(barlineEnd, score.getColumnHeader(4), null, MeasureSide.Right).execute();
return score;
}
use of com.xenoage.zong.core.music.clef.Clef in project Zong by Xenoage.
the class MeasureElementsSpacerTest method testNeedAdditionalSpace.
/**
* If there is not enough space left for the measure elements,
* the voice spacings have to be moved to create enough space.
* 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 4)
* voice 1: o 2
* voice 2: 1 o
* </pre>
* Between VE1 and VE2, there are 6 spaces.
* Assuming a padding width of 1 and a clef width of 6,
* the clef can be moved two spaces to the left, but this is not
* enough. All elements at or after beat 3 have to be moved 2 spaces
* to the right.
*/
@Test
public void testNeedAdditionalSpace() {
Rest[] ve = ve();
List<VoiceSpacing> vs = alist(new VoiceSpacing(null, 1, alist(spacing(ve[0], fr(1, 2), 4), spacing(ve[1], fr(4), 11))), new VoiceSpacing(null, 1, alist(spacing(ve[2], fr(1), 5), spacing(ve[3], fr(13, 2), 16))));
Clef innerClef = new Clef(ClefType.clefTreble);
BeatEList<Clef> innerClefs = beatEList();
innerClefs.add(beatE(innerClef, fr(4)));
List<ElementSpacing> mes = testee.compute(innerClefs, beatEList(), null, false, vs, 0, notations(ve, innerClef), ls);
// voice spacings
assertEquals(2, vs.size());
assertEqualsSpacings(ilist(spacing(ve[0], fr(1, 2), 4), spacing(ve[1], fr(4), 13)), vs.get(0).elements);
assertEqualsSpacings(ilist(spacing(ve[2], fr(1), 5), spacing(ve[3], fr(13, 2), 18)), vs.get(1).elements);
// clef must be at offset 13 - padding - clefwidth/2
ElementSpacing[] se = mes.toArray(new ElementSpacing[0]);
assertEquals(1, se.length);
assertEquals(fr(4), se[0].beat);
assertEquals(13 - paddingWidth - clefWidth / 2, se[0].xIs, Delta.DELTA_FLOAT);
}
use of com.xenoage.zong.core.music.clef.Clef in project Zong by Xenoage.
the class CursorTest method write_MeasureElement_Test.
@Test
public void write_MeasureElement_Test() {
Score score = ScoreFactory.create1Staff();
Cursor cursor = new Cursor(score, mpe0, true);
cursor.write(new Rest(fr(1, 4)));
cursor.write(new Rest(fr(1, 4)));
cursor.write(new Rest(fr(1, 4)));
// write clef at 1/4
Clef clef1 = new Clef(ClefType.clefBass);
cursor.setMp(atElement(0, 0, 0, 1));
cursor.write(clef1);
BeatEList<Clef> clefs = score.getMeasure(atMeasure(0, 0)).getClefs();
assertEquals(1, clefs.size());
assertEquals(beatE(clef1, fr(1, 4)), clefs.getFirst());
// write clef at 2/4
Clef clef2 = new Clef(ClefType.clefTreble);
cursor.setMp(atElement(0, 0, 0, 2));
cursor.write(clef2);
clefs = score.getMeasure(atMeasure(0, 0)).getClefs();
assertEquals(2, clefs.size());
assertEquals(beatE(clef1, fr(1, 4)), clefs.getFirst());
assertEquals(beatE(clef2, fr(2, 4)), clefs.getElements().get(1));
// overwrite clef at 1/4
Clef clef3 = new Clef(ClefType.clefTreble);
cursor.setMp(atElement(0, 0, 0, 1));
cursor.write(clef3);
clefs = score.getMeasure(atMeasure(0, 0)).getClefs();
assertEquals(2, clefs.size());
assertEquals(beatE(clef3, fr(1, 4)), clefs.getFirst());
assertEquals(beatE(clef2, fr(2, 4)), clefs.getElements().get(1));
// write key at 1/4
Key key = new TraditionalKey(5, Mode.Major);
cursor.setMp(atElement(0, 0, 0, 1));
cursor.write((MeasureElement) key);
// clefs must still be there
assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
// write direction at 1/4
Direction direction1 = new Dynamic(DynamicValue.ff);
cursor.setMp(atElement(0, 0, 0, 1));
cursor.write((MeasureElement) direction1);
// clefs must still be there
assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
// key must still be there
assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
assertEquals(1, score.getMeasure(atMeasure(0, 0)).getDirections().size());
// write another direction at 1/4, which does not replace the first one
Direction direction2 = new Coda();
cursor.setMp(atElement(0, 0, 0, 1));
cursor.write((MeasureElement) direction2);
// clefs must still be there
assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
// key must still be there
assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
// now two directions
assertEquals(2, score.getMeasure(atMeasure(0, 0)).getDirections().size());
// write instrument change at 1/4
InstrumentChange instrChange = new InstrumentChange(Instrument.defaultInstrument);
cursor.setMp(atElement(0, 0, 0, 1));
cursor.write(instrChange);
// clefs must still be there
assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
// key must still be there
assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
// directions must still be there
assertEquals(2, score.getMeasure(atMeasure(0, 0)).getDirections().size());
assertEquals(1, score.getMeasure(atMeasure(0, 0)).getInstrumentChanges().size());
// check all added elements
BeatEList<MeasureElement> all = score.getMeasure(atMeasure(0, 0)).getMeasureElements();
assertEquals(6, all.size());
assertEquals(clef3, all.getElements().get(0).element);
assertEquals(key, all.getElements().get(1).element);
assertEquals(direction1, all.getElements().get(2).element);
assertEquals(direction2, all.getElements().get(3).element);
assertEquals(instrChange, all.getElements().get(4).element);
assertEquals(clef2, all.getElements().get(5).element);
}
use of com.xenoage.zong.core.music.clef.Clef in project Zong by Xenoage.
the class Score method getClef.
/**
* Gets the last {@link Clef} that is defined before (or at,
* dependent on the given {@link Interval}) the given
* {@link MP}, also over measure boundaries. If there is
* none, a default g clef is returned. The beat in the {@link MP} is required.
*/
public ClefType getClef(MP mp, Interval interval) {
if (!interval.isPrecedingOrAt())
throw new IllegalArgumentException("Illegal interval for this method");
if (mp.beat == MP.unknownBeat)
throw new IllegalArgumentException("beat is required");
// begin with the given measure. if there is one, return it.
Measure measure = getMeasure(mp);
BeatE<Clef> ret = null;
if (measure.getClefs() != null) {
ret = measure.getClefs().getLastBefore(interval, mp.beat);
if (ret != null)
return ret.element.getType();
}
if (interval != At) {
// search in the preceding measures
for (int iMeasure : rangeReverse(mp.measure - 1, 0)) {
measure = getMeasure(atMeasure(mp.staff, iMeasure));
if (measure.getClefs() != null) {
ret = measure.getClefs().getLast();
if (ret != null)
return ret.element.getType();
}
}
}
// no clef found. return default clef.
return ClefType.clefTreble;
}
Aggregations