use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.
the class SystemSpacingTest method getMpAtTest.
@Test
public void getMpAtTest() {
MP mp;
ColumnSpacing column;
float xMm;
int lastMeasure = system.getEndMeasure();
// coordinate before first measure must return unknown measure
mp = system.getMpAt(system.getMeasureStartMm(0) - 0.1f, unknown);
assertEquals(unknown, mp.measure);
// coordinate before first beat in measure 0 must return first beat
column = system.getColumn(0);
xMm = system.getMeasureStartMm(0) + getFirst(column.getBeatOffsets()).offsetMm * 0.1f;
mp = system.getMpAt(xMm, unknown);
assertEquals(0, mp.measure);
assertEquals(getFirst(column.getBeatOffsets()).beat, mp.beat);
// coordinate after last measure must return unknown measure
mp = system.getMpAt(system.getMeasureEndMm(lastMeasure) + 0.1f, unknown);
assertEquals(mp.measure, unknown);
// coordinate after last beat in last measure must return last beat
column = system.getColumn(system.getEndMeasure());
xMm = system.getMeasureStartMm(lastMeasure) + getLast(column.getBeatOffsets()).offsetMm + 0.1f;
mp = system.getMpAt(xMm, unknown);
assertEquals(lastMeasure, mp.measure);
assertEquals(getLast(column.getBeatOffsets()).beat, mp.beat);
// coordinate at i-th x-position must return i-th beat
for (int iMeasure : range(lastMeasure + 1)) {
List<BeatOffset> bm = system.getColumn(iMeasure).getBeatOffsets();
for (int iBeat : range(bm)) {
xMm = system.getMeasureStartMm(iMeasure) + bm.get(iBeat).offsetMm;
mp = system.getMpAt(xMm, unknown);
assertEquals(iMeasure, mp.measure);
assertEquals(bm.get(iBeat).beat, mp.beat);
}
}
// coordinate between beat 0 and 3 (but nearer to beat 0) in measure 2 must return beat 0
column = system.getColumn(2);
BeatOffset m2bo0 = column.getBeatOffset(Companion.fr(0, 4));
BeatOffset m2bo3 = column.getBeatOffset(Companion.fr(3, 4));
xMm = system.getMeasureStartMm(2) + m2bo0.offsetMm + (m2bo3.offsetMm - m2bo0.offsetMm) * 0.4f;
mp = system.getMpAt(xMm, unknown);
assertEquals(2, mp.measure);
assertEquals(m2bo0.beat, mp.beat);
// coordinate between beat 0 and 3 (but nearer to beat 3) in measure 2 must return beat 3
xMm = system.getMeasureStartMm(2) + m2bo0.offsetMm + (m2bo3.offsetMm - m2bo0.offsetMm) * 0.6f;
mp = system.getMpAt(xMm, unknown);
assertEquals(2, mp.measure);
assertEquals(m2bo3.beat, mp.beat);
}
use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.
the class Context method writeMeasureElement.
/**
* Writes the given {@link MeasureElement} at the given staff (index relative to first
* staff in current part), current measure and current beat.
*/
public void writeMeasureElement(MeasureElement element, int staffIndexInPart) {
int staffIndex = getPartStaffIndices().getStart() + staffIndexInPart;
MP mp = this.mp.withStaff(staffIndex);
new MeasureElementWrite(element, score.getMeasure(mp), mp.getBeat()).execute();
}
use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.
the class ScoreSelectionLayouter method setCursor.
/**
* Sets a {@link StaffCursorStamping} for the given {@link Cursor}.
*/
private void setCursor(Cursor cursor) {
// remove old stampings
removeSelectionStampings();
// find frame
MP mp = cursor.getMP();
int measure = mp.measure;
ScoreFrameLayout frame = scoreLayout.getScoreFrameLayout(measure);
if (frame != null) {
StaffStamping staff = frame.getStaffStamping(mp.staff, measure);
if (staff != null) {
frame.setSelectionStampings(ilist(new StaffCursorStamping(frame.getPositionX(mp.getTime()), -0.5f, staff)));
}
}
}
use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.
the class Test72b method testNotatedPitches.
@Test
public void testNotatedPitches() {
for (int iStaff : range(expectedNotatedPitches.length)) {
MP mp = MP.atElement(iStaff, 0, 0, 0);
Chord chord = getChordAt(score, mp);
Pitch pitch = chord.getNotes().get(0).getPitch();
assertEquals("" + mp, expectedNotatedPitches[iStaff], pitch);
}
}
use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.
the class Test72c method testNotatedPitches.
@Test
public void testNotatedPitches() {
for (int iMeasure : range(expectedTransposes.length)) {
MP mp = MP.atElement(0, iMeasure, 0, 0);
Chord chord = getChordAt(score, mp);
Pitch pitch = chord.getNotes().get(0).getPitch();
assertEquals("" + mp, expectedNotatedPitch, pitch);
}
}
Aggregations