use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.
the class Test72a method testNotatedPitches.
@Test
public void testNotatedPitches() {
for (int iStaff : range(3)) {
for (int iMeasure : range(2)) {
for (int iElement : range(4)) {
MP mp = MP.atElement(iStaff, iMeasure, 0, iElement);
Chord chord = getChordAt(score, mp);
Pitch pitch = chord.getNotes().get(0).getPitch();
assertEquals("" + mp, expectedNotatedPitches[iStaff][iMeasure * 4 + iElement], pitch);
}
}
}
}
use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.
the class OpenUnnumberedTieds method stopTied.
/**
* Ends an existing tie and returns the {@link OpenSlur}.
* When the tie does not exist, null is returned.
*/
public OpenSlur stopTied(SlurWaypoint wp, VSide side, Context context) {
Chord chord = wp.getChord();
Pitch pitch = chord.getNotes().get(wp.getNoteIndex()).getPitch();
// get tied for this pitch
OpenSlur openTied = openTieds.remove(pitch);
if (openTied == null) {
context.reportError("Can not stop non-existing tied");
return null;
}
// does start chord exist? could have been overwritten by backup element
MP startMp = openTied.start.wp.getChord().getMP();
if (startMp == null) {
context.reportError("Tied can not be closed; start chord does not exist");
return null;
}
// then close the earlier open tied instead, if there is one
if (startMp.equals(context.getMp())) {
// remember last tied
openTieds.put(pitch, openTied);
// use earlier tied instead
openTied = openEarlierTieds.remove(pitch);
if (openTied == null) {
context.reportError("Tied can not be stopped on starting position, " + "and there is no earlier tied");
return null;
}
}
openTied.stop = new OpenSlur.Waypoint(wp, side);
return openTied;
}
use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.
the class DirectionStamper method computePosition.
/**
* Computes the position for the given {@link Direction}
* within the given {@link StaffStamping}.
*/
private SP computePosition(Direction direction, StaffStamping staffStamping, float defaultLP, float defaultLPAbove, float defaultLPBelow) {
Positioning customPos = direction.getPositioning();
MP mp = direction.getMP();
if (mp == null)
// TODO. Happens. But just with offical MusicXML sample Telemann.xml
return SP.sp(0, 0);
float x, lp;
// default positioning
x = notNull(staffStamping.system.getXMmAt(mp.getTime()), 0f) + staffStamping.positionMm.x;
lp = defaultLP;
// custom positioning
if (customPos instanceof Placement) {
Placement placement = (Placement) customPos;
if (placement == Placement.Above)
lp = defaultLPAbove;
else
lp = defaultLPBelow;
} else if (customPos instanceof Position) {
// coordinates
Position pos = (Position) customPos;
if (pos.x != null)
x = pos.x;
x += Position.getRelativeX(pos);
// vertical position
if (pos.y != null)
lp = pos.y;
lp += Position.getRelativeY(pos);
}
return sp(x, lp);
}
use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.
the class VoiceElementWriteTest method testOverwrite2.
/**
* Write<pre>
* xxxxxxxx
* into aabbccddeeffgghh
* => aaxxxxxxxxffgghh</pre>
*/
@Test
public void testOverwrite2() {
Score score = createTestScoreEighths();
// in voice 1, write a half rest at 1/8
MP mp = atElement(0, 0, 1, 1);
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/2, 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(1, 2), 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 testWriteAfterEnd.
/**
* Write at a beat after the end of the elements.<pre>
* xxxx
* into aabbccddeeffgghh
* => aabbccddeeffgghhrrxxxx</pre> (r is a rest)
*/
@Test
public void testWriteAfterEnd() {
Score score = createTestScoreEighths();
// in voice 1, write a 1/4 rest at 9/8 (1/8 after the end)
MP mp = atBeat(0, 0, 0, Companion.fr(9, 8));
Voice voice = score.getVoice(mp);
Rest x = new Rest(Companion.fr(1, 4));
VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, x, null);
cmd.execute();
// check elements
assertEquals(10, voice.getElements().size());
for (int i : range(8)) assertEquals(Companion.fr(1, 8), getDur(voice, i));
assertTrue(voice.getElement(8) instanceof Rest);
assertEquals(Companion.fr(1, 8), getDur(voice, 8));
assertEquals(x, voice.getElement(9));
assertEquals(Companion.fr(1, 4), getDur(voice, 9));
// test undo
cmd.undo();
assertTestScoreEighthsOriginalState(score);
}
Aggregations