Search in sources :

Example 1 with Direction

use of com.xenoage.zong.core.music.direction.Direction in project Zong by Xenoage.

the class WedgeStamper method stampSystem.

/**
 * Creates all wedge stampings in the given system.
 * @param openWedges  input and output parameter: voltas, which are still open from the
 *                    last system. After the method returns, it contains the voltas which
 *                    are still open after this system
 */
public List<WedgeStamping> stampSystem(SystemSpacing system, Score score, StaffStampings staffStampings, OpenWedges openWedges) {
    List<WedgeStamping> ret = alist();
    // find new wedges beginning in this staff
    for (int iStaff : range(score.getStavesCount())) {
        Staff staff = score.getStaff(iStaff);
        for (int iMeasure : system.getMeasures()) {
            Measure measure = staff.getMeasure(iMeasure);
            for (BeatE<Direction> dir : measure.getDirections()) {
                if (dir.getElement() instanceof Wedge) {
                    Wedge wedge = (Wedge) dir.getElement();
                    // if the position of the end element is known
                    if (wedge.getWedgeEnd().getMP() != null)
                        openWedges.wedges.add(new ContinuedWedge((Wedge) dir.getElement()));
                }
            }
        }
    }
    // draw wedges in the cache, and remove them if closed in this system
    for (Iterator<ContinuedWedge> itW = openWedges.wedges.iterator(); itW.hasNext(); ) {
        ContinuedWedge wedge = itW.next();
        ret.add(stamp(wedge.element, staffStampings.get(system.getSystemIndexInFrame(), wedge.element.getMP().staff)));
        if (MP.getMP(wedge.element.getWedgeEnd()).measure <= system.getEndMeasure()) {
            // wedge is closed
            itW.remove();
        }
    }
    return ret;
}
Also used : ContinuedWedge(com.xenoage.zong.musiclayout.continued.ContinuedWedge) Staff(com.xenoage.zong.core.music.Staff) Measure(com.xenoage.zong.core.music.Measure) WedgeStamping(com.xenoage.zong.musiclayout.stampings.WedgeStamping) Direction(com.xenoage.zong.core.music.direction.Direction) Wedge(com.xenoage.zong.core.music.direction.Wedge) ContinuedWedge(com.xenoage.zong.musiclayout.continued.ContinuedWedge)

Example 2 with Direction

use of com.xenoage.zong.core.music.direction.Direction in project Zong by Xenoage.

the class Test31a method test.

@ToDo("add support for multiple direction-types within a single MusicXML direction")
@Test
public void test() {
    Score score = getScore();
    // test directions
    for (Tuple2<MP, ?> item : expectedDirections) {
        MP mp = item.get1();
        List<?> directions = null;
        // in the column header instead, and not in the measure
        if (item.get2() instanceof Tempo)
            directions = score.getColumnHeader(mp.measure).getTempos().getAll(mp.beat);
        else if (item.get2() instanceof NavigationSign)
            directions = score.getColumnHeader(mp.measure).getOtherDirections().getAll(mp.beat);
        else
            directions = score.getMeasure(mp).getDirections().getAll(mp.beat);
        // check correct classes
        if (item.get2() instanceof Direction) {
            // single direction at this beat expected
            assertEquals("" + mp, 1, directions.size());
            assertEquals("" + mp, item.get2().getClass(), directions.get(0).getClass());
        } else if (item.get2() instanceof List<?>) {
        // List<?> l = (List<?>) item.get2();
        // multiple directions at this beat expected
        // TODO: add support for multiple direction-types within a single MusicXML direction
        // assertEquals(""+mp, l.size(), directions.size());
        // for (int i : range(l))
        // assertEquals(""+mp+"["+i+"]", l.get(i).getClass(), directions.get(i).getClass());
        }
    }
    // segno and coda
    assertEquals(MusicElementType.Segno, score.getColumnHeader(1).getNavigationTarget().getMusicElementType());
    assertEquals(MusicElementType.Coda, score.getColumnHeader(1).getNavigationOrigin().getMusicElementType());
}
Also used : Score(com.xenoage.zong.core.Score) MP(com.xenoage.zong.core.position.MP) Tempo(com.xenoage.zong.core.music.direction.Tempo) NavigationSign(com.xenoage.zong.core.music.direction.NavigationSign) Direction(com.xenoage.zong.core.music.direction.Direction) ToDo(musicxmltestsuite.tests.utils.ToDo) Test(org.junit.Test)

Example 3 with Direction

use of com.xenoage.zong.core.music.direction.Direction in project Zong by Xenoage.

the class Test32a method test.

@Test
public void test() {
    Score score = getScore();
    for (Tuple2<MP, ?> item : expectedAnnotations) {
        MP mp = item.get1();
        List<?> annotations = null;
        Chord chord = (Chord) score.getVoice(mp).getElementAt(mp.beat);
        assertNotNull("" + mp, chord);
        // in this test, the chords contain either directions or annotations
        if (false == chord.getDirections().isEmpty())
            annotations = chord.getDirections();
        else
            annotations = chord.getAnnotations();
        // check correct classes
        if (item.get2() instanceof Direction) {
            // single direction at this beat expected
            assertEquals("" + mp, 1, annotations.size());
            assertEquals("" + mp, item.get2().getClass(), annotations.get(0).getClass());
        } else if (item.get2() instanceof List<?>) {
            // list of annotations
            // we ignore the order here (MusicXML does not contain a order)
            assertEquals("" + mp, set((List<?>) item.get2()), set(annotations));
        } else {
            // single annotation
            assertEquals("" + mp, 1, annotations.size());
            assertEquals("" + mp, item.get2(), annotations.get(0));
        }
    }
}
Also used : Score(com.xenoage.zong.core.Score) MP(com.xenoage.zong.core.position.MP) Chord(com.xenoage.zong.core.music.chord.Chord) Direction(com.xenoage.zong.core.music.direction.Direction) Test(org.junit.Test)

Example 4 with Direction

use of com.xenoage.zong.core.music.direction.Direction in project Zong by Xenoage.

the class Test32b method testStyle.

@Test
public void testStyle() {
    Score score = getScore();
    for (int i = 0; i < expectedTexts.size(); ) {
        MP mp = expectedTexts.get(i).get1();
        List<Direction> directions = score.getMeasure(mp).getDirections().getAll(mp.beat);
        assertTrue("" + mp, directions.size() > 0);
        for (val direction : directions) {
            assertTrue("" + mp, direction instanceof Words);
            check((Words) direction, expectedTexts.get(i).get2(), mp);
            i++;
        }
    }
}
Also used : lombok.val(lombok.val) Score(com.xenoage.zong.core.Score) MP(com.xenoage.zong.core.position.MP) Words(com.xenoage.zong.core.music.direction.Words) Direction(com.xenoage.zong.core.music.direction.Direction) Test(org.junit.Test)

Example 5 with Direction

use of com.xenoage.zong.core.music.direction.Direction in project Zong by Xenoage.

the class Test21d method test.

@Test
public void test() {
    MxlPart part = getFirstPart();
    List<Tuple2<MP, ? extends Direction>> expectedDirections = getExpectedDirections();
    // check only directions in this test
    int iDirection = 0;
    for (int iMeasure = 0; iMeasure <= 1; iMeasure++) {
        MxlMeasure measure = part.getMeasures().get(iMeasure);
        for (MxlMusicDataContent data : measure.getMusicData().getContent()) {
            if (data.getMusicDataContentType() == MxlMusicDataContentType.Direction) {
                // check type
                MxlDirection dir = (MxlDirection) data;
                MxlDirectionTypeContent content = dir.getDirectionTypes().get(0).getContent();
                if (iDirection == 0) {
                    // Words "Largo"
                    assertEquals(0, iMeasure);
                    assertEquals(MxlDirectionTypeContentType.Words, content.getDirectionTypeContentType());
                    assertEquals("Largo", ((MxlWords) content).getFormattedText().getValue());
                } else if (iDirection == 1) {
                    // Dynamic "fp"
                    assertEquals(0, iMeasure);
                    assertEquals(MxlDirectionTypeContentType.Dynamics, content.getDirectionTypeContentType());
                    assertEquals(DynamicValue.fp, ((MxlDynamics) content).getElement());
                } else if (iDirection == 2) {
                    // Dynamic "p"
                    assertEquals(1, iMeasure);
                    assertEquals(MxlDirectionTypeContentType.Dynamics, content.getDirectionTypeContentType());
                    assertEquals(DynamicValue.p, ((MxlDynamics) content).getElement());
                }
                iDirection++;
            }
        }
    }
    assertEquals("not all directions found", expectedDirections.size(), iDirection);
}
Also used : MxlMusicDataContent(com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent) MxlDynamics(com.xenoage.zong.musicxml.types.MxlDynamics) Tuple2(com.xenoage.utils.kernel.Tuple2) MxlDirectionTypeContent(com.xenoage.zong.musicxml.types.choice.MxlDirectionTypeContent) MxlWords(com.xenoage.zong.musicxml.types.MxlWords) MxlPart(com.xenoage.zong.musicxml.types.partwise.MxlPart) MxlDirection(com.xenoage.zong.musicxml.types.MxlDirection) Direction(com.xenoage.zong.core.music.direction.Direction) MxlMeasure(com.xenoage.zong.musicxml.types.partwise.MxlMeasure) MxlDirection(com.xenoage.zong.musicxml.types.MxlDirection) Test(org.junit.Test)

Aggregations

Direction (com.xenoage.zong.core.music.direction.Direction)8 Test (org.junit.Test)6 Score (com.xenoage.zong.core.Score)5 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)3 MP (com.xenoage.zong.core.position.MP)3 Tuple2 (com.xenoage.utils.kernel.Tuple2)2 Chord (com.xenoage.zong.core.music.chord.Chord)2 Words (com.xenoage.zong.core.music.direction.Words)2 InstrumentChange (com.xenoage.zong.core.music.InstrumentChange)1 Measure (com.xenoage.zong.core.music.Measure)1 MeasureElement (com.xenoage.zong.core.music.MeasureElement)1 Staff (com.xenoage.zong.core.music.Staff)1 VoiceElement (com.xenoage.zong.core.music.VoiceElement)1 Clef (com.xenoage.zong.core.music.clef.Clef)1 Coda (com.xenoage.zong.core.music.direction.Coda)1 NavigationSign (com.xenoage.zong.core.music.direction.NavigationSign)1 Segno (com.xenoage.zong.core.music.direction.Segno)1 Tempo (com.xenoage.zong.core.music.direction.Tempo)1 Wedge (com.xenoage.zong.core.music.direction.Wedge)1 Key (com.xenoage.zong.core.music.key.Key)1