use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.
the class WedgeStamper method stamp.
/**
* Creates a {@link WedgeStamping} for the given {@link Wedge} on the given staff.
* The start and end measure of the wedge may be outside the staff, then the
* wedge is clipped to the staff.
*/
public WedgeStamping stamp(Wedge wedge, StaffStamping staffStamping) {
SystemSpacing system = staffStamping.system;
Range systemMeasures = system.getMeasures();
// musical positions of wedge
MP p1 = MP.getMP(wedge);
MP p2 = MP.getMP(wedge.getWedgeEnd());
// clip start to staff
float x1Mm;
if (p1.measure < systemMeasures.getStart()) {
// begins before staff
x1Mm = system.getMeasureStartAfterLeadingMm(systemMeasures.getStart());
} else {
// begins within staff
x1Mm = system.getXMmAt(p1.getTime());
}
// clip end to staff
float x2Mm;
if (p2.measure > systemMeasures.getStop()) {
// ends after staff
x2Mm = system.getMeasureEndMm(systemMeasures.getStop());
} else {
// ends within staff
x2Mm = system.getXMmAt(p2.getTime());
}
// spread
float d1Is = 0;
float d2Is = 0;
float defaultSpreadIS = 1.5f;
if (wedge.getType() == WedgeType.Crescendo) {
d2Is = (wedge.getSpread() != null ? wedge.getSpread() : defaultSpreadIS);
} else if (wedge.getType() == WedgeType.Diminuendo) {
d1Is = (wedge.getSpread() != null ? wedge.getSpread() : defaultSpreadIS);
}
// custom horizontal position
Position customPos = asPosition(wedge.getPositioning());
float length = x2Mm - x1Mm;
if (customPos != null && customPos.x != null)
x1Mm = customPos.x;
x1Mm += Position.getRelativeX(customPos);
x2Mm = x1Mm + length;
// vertical position
float lp;
if (customPos != null && customPos.y != null)
lp = customPos.y;
else
lp = -6;
lp += Position.getRelativeY(customPos);
return new WedgeStamping(lp, x1Mm, x2Mm, d1Is, d2Is, staffStamping);
}
use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.
the class VoiceElementWriteTest method testGraceInsert2.
/**
* Writes elements in a voice that contains grace notes.
* <pre>
* xxxx___xxxx
* into ..aaaa...bbbb.cccc..
* => ..xxxx___xxxx.cccc..</pre>
*/
@Test
public void testGraceInsert2() {
Score score = createTestScoreGraces();
// in voice 0, write a 1/2 rest at position 2
MP mp = atElement(0, 0, 0, 2);
Voice voice = score.getVoice(mp);
Rest r = new Rest(Companion.fr(1, 2));
VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, r, null);
cmd.execute();
// check notes
assertEquals(7, voice.getElements().size());
// here 1st grace note has step 0, 2nd 1, ...
assertEquals(0, getStep(voice, 0));
assertEquals(1, getStep(voice, 1));
assertEquals(r, voice.getElement(2));
assertEquals(5, getStep(voice, 3));
assertEquals(Companion.fr(1, 4), getDur(voice, 4));
assertEquals(6, getStep(voice, 5));
assertEquals(0, getStep(voice, 6));
// test undo
cmd.undo();
assertTestScoreGracesOriginalState(score);
}
use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.
the class VoiceElementWriteTest method testWriteAtBeat.
/**
* Write at a beat.<pre>
* xxxxxxx
* into aabbccddeeffgghh
* => aaxxxxxxx_ffgghh</pre>
*/
@Test
public void testWriteAtBeat() {
Score score = createTestScoreEighths();
// in voice 1, write a 7/16 rest at 1/8
MP mp = atBeat(0, 0, 0, Companion.fr(1, 8));
Voice voice = score.getVoice(mp);
Rest r = new Rest(Companion.fr(7, 16));
VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, r, null);
cmd.execute();
// now, there must be the durations 1/18, 7/16, 1/8, 1/8, 1/8 in voice 1
assertEquals(5, voice.getElements().size());
assertEquals(Companion.fr(1, 8), getDur(voice, 0));
assertEquals(Companion.fr(7, 16), getDur(voice, 1));
assertEquals(Companion.fr(1, 8), getDur(voice, 2));
assertEquals(Companion.fr(1, 8), getDur(voice, 3));
assertEquals(Companion.fr(1, 8), getDur(voice, 4));
// test undo
cmd.undo();
assertTestScoreEighthsOriginalState(score);
}
use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.
the class VoiceElementWriteTest method testOverwrite4.
/**
* Write<pre>
* xxxxxxxx
* into aabbccddeeffgghh
* => aabbccddxxxxxxxx</pre>
*/
@Test
public void testOverwrite4() {
Score score = createTestScoreEighths();
// in voice 1, write a half rest at 4/8
MP mp = atElement(0, 0, 1, 4);
Voice voice = score.getVoice(mp);
VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, new Rest(Companion.fr(1, 2)), null);
cmd.execute();
// now, there must be the durations 1/8, 1/8, 1/8, 1/8, 1/2 in voice 1
assertEquals(5, voice.getElements().size());
assertEquals(Companion.fr(1, 8), getDur(voice, 0));
assertEquals(Companion.fr(1, 8), getDur(voice, 1));
assertEquals(Companion.fr(1, 8), getDur(voice, 2));
assertEquals(Companion.fr(1, 8), getDur(voice, 3));
assertEquals(Companion.fr(1, 2), getDur(voice, 4));
// test undo
cmd.undo();
assertTestScoreEighthsOriginalState(score);
}
use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.
the class VoiceElementWriteTest method testGraceInsert1.
/**
* Writes elements in a voice that contains grace notes.
* <pre>
* xxxx
* into ..aaaa...bbbb.cccc..</pre>
* => ..aaaa...bbbb.cccc..</pre>
*/
@Test
public void testGraceInsert1() {
Score score = createTestScoreGraces();
// in voice 0, write a 1/4 rest at position 2
MP mp = atElement(0, 0, 0, 2);
Voice voice = score.getVoice(mp);
Rest r = new Rest(Companion.fr(1, 4));
VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, r, null);
cmd.execute();
// check notes
assertEquals(11, voice.getElements().size());
// here 1st grace note has step 0, 2nd 1, ...
assertEquals(0, getStep(voice, 0));
assertEquals(1, getStep(voice, 1));
assertEquals(r, voice.getElement(2));
assertEquals(2, getStep(voice, 3));
assertEquals(3, getStep(voice, 4));
assertEquals(4, getStep(voice, 5));
assertEquals(Companion.fr(1, 4), getDur(voice, 6));
assertEquals(5, getStep(voice, 7));
assertEquals(Companion.fr(1, 4), getDur(voice, 8));
assertEquals(6, getStep(voice, 9));
assertEquals(0, getStep(voice, 10));
// test undo
cmd.undo();
assertTestScoreGracesOriginalState(score);
}
Aggregations