Search in sources :

Example 1 with MP

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);
}
Also used : MP(com.xenoage.zong.core.position.MP) Test(org.junit.Test)

Example 2 with MP

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();
}
Also used : MP(com.xenoage.zong.core.position.MP) MeasureElementWrite(com.xenoage.zong.commands.core.music.MeasureElementWrite) SlurWaypoint(com.xenoage.zong.core.music.slur.SlurWaypoint)

Example 3 with MP

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)));
        }
    }
}
Also used : MP(com.xenoage.zong.core.position.MP) StaffCursorStamping(com.xenoage.zong.musiclayout.stampings.StaffCursorStamping) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout)

Example 4 with MP

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);
    }
}
Also used : MP(com.xenoage.zong.core.position.MP) Pitch(com.xenoage.zong.core.music.Pitch) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Example 5 with MP

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);
    }
}
Also used : MP(com.xenoage.zong.core.position.MP) Pitch(com.xenoage.zong.core.music.Pitch) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Aggregations

MP (com.xenoage.zong.core.position.MP)46 Test (org.junit.Test)30 Score (com.xenoage.zong.core.Score)19 Chord (com.xenoage.zong.core.music.chord.Chord)16 Voice (com.xenoage.zong.core.music.Voice)14 Rest (com.xenoage.zong.core.music.rest.Rest)11 ChordTest (musicxmltestsuite.tests.utils.ChordTest)6 Pitch (com.xenoage.zong.core.music.Pitch)4 Measure (com.xenoage.zong.core.music.Measure)3 Direction (com.xenoage.zong.core.music.direction.Direction)3 MP.atVoice (com.xenoage.zong.core.position.MP.atVoice)3 VoiceTest.assertEqualsVoice (musicxmltestsuite.tests.utils.VoiceTest.assertEqualsVoice)3 MeasureElementWrite (com.xenoage.zong.commands.core.music.MeasureElementWrite)2 VoiceElementWrite (com.xenoage.zong.commands.core.music.VoiceElementWrite)2 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)2 Staff (com.xenoage.zong.core.music.Staff)2 Beam (com.xenoage.zong.core.music.beam.Beam)2 Tempo (com.xenoage.zong.core.music.direction.Tempo)2 Position (com.xenoage.zong.core.music.format.Position)2 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)2