Search in sources :

Example 11 with MP

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);
            }
        }
    }
}
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 12 with MP

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

Example 13 with MP

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);
}
Also used : Positioning(com.xenoage.zong.core.music.format.Positioning) MP(com.xenoage.zong.core.position.MP) Placement(com.xenoage.zong.core.music.format.Placement) Position(com.xenoage.zong.core.music.format.Position)

Example 14 with MP

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

Example 15 with MP

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);
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) MP(com.xenoage.zong.core.position.MP) Voice(com.xenoage.zong.core.music.Voice) 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