Search in sources :

Example 1 with Slur

use of com.xenoage.zong.core.music.slur.Slur in project Zong by Xenoage.

the class Context method createSlur.

/**
 * Creates and writes a slur or tie from the given {@link OpenSlur} object.
 */
public void createSlur(OpenSlur openSlur) {
    if (checkSlur(openSlur)) {
        Slur slur = new Slur(openSlur.type, alist(openSlur.start.wp, openSlur.stop.wp), openSlur.start.side);
        writeSlur(slur);
    }
}
Also used : Slur(com.xenoage.zong.core.music.slur.Slur)

Example 2 with Slur

use of com.xenoage.zong.core.music.slur.Slur in project Zong by Xenoage.

the class Test33b method test.

@Test
public void test() {
    Score score = getScore();
    Chord chord1 = (Chord) score.getVoice(atVoice(0, 0, 0)).getElement(0);
    Chord chord2 = (Chord) score.getVoice(atVoice(0, 1, 0)).getElement(0);
    assertEquals(1, chord1.getSlurs().size());
    Slur tie = chord1.getSlurs().get(0);
    assertEquals(SlurType.Tie, tie.getType());
    List<SlurWaypoint> waypoints = tie.getWaypoints();
    assertEquals(2, waypoints.size());
    assertEquals(chord1, waypoints.get(0).getChord());
    assertEquals(chord2, waypoints.get(1).getChord());
}
Also used : Slur(com.xenoage.zong.core.music.slur.Slur) Score(com.xenoage.zong.core.Score) Chord(com.xenoage.zong.core.music.chord.Chord) SlurWaypoint(com.xenoage.zong.core.music.slur.SlurWaypoint) Test(org.junit.Test)

Example 3 with Slur

use of com.xenoage.zong.core.music.slur.Slur in project Zong by Xenoage.

the class ChordStamper method stampAll.

/**
 * Returns all the stampings for the given {@link Chord}, including beams,
 * tuplets, slurs and other attachments.
 *
 * The given {@link OpenSlursCache},
 * {@link OpenLyricsCache}, {@link LastLyrics} and {@link OpenTupletsCache} may be modified.
 */
public List<Stamping> stampAll(ChordNotation chord, float xMm, BeamSpacing beam, StaffStampings staffStampings, StamperContext context, FormattedTextStyle defaultLyricStyle, OpenSlursCache openSlursCache, OpenLyricsCache openLyricsCache, LastLyrics lastLyrics, OpenTupletsCache openTupletsCache) {
    List<Stamping> ret = alist();
    Chord element = chord.getElement();
    int staffIndex = context.staffIndex;
    int systemIndex = context.systemIndex;
    // noteheads, leger lines, dots, accidentals, stem, flags, articulations
    ChordStampings chordSt = stampCore(chord, xMm, context);
    chordSt.addAllTo(ret);
    // beam
    if (beam != null) {
        // stamp the whole beam (when we find the beginning of the beam)
        // TIDY: create/store beam stampings elsewhere?
        Beam beamElement = beam.notation.element;
        int chordIndex = beamElement.getWaypointIndex(element);
        if (chordIndex == 0) {
            ret.addAll(beamStamper.stamp(beam, context.getCurrentStaffStamping()));
        }
    }
    // ties and slurs
    for (Slur slur : element.getSlurs()) {
        SlurWaypoint wp = slur.getWaypoint(element);
        WaypointPosition pos = slur.getWaypointPosition(element);
        // TODO: choose top/bottom
        int noteIndex = notNull(wp.getNoteIndex(), 0);
        NoteheadStamping notehead = chordSt.noteheads[noteIndex];
        // define the placement: above or below (TODO: better strategy)
        VSide side = slurStamper.getSide(slur);
        // compute position
        val staff = staffStampings.get(systemIndex, notehead.parentStaff.staffIndex);
        val slurCache = openSlursCache.getOrCreate(slur);
        float distanceIs = slurStamper.getAdditionalDistanceIs(chord, slur.getSide());
        SP defaultSp = sp(notehead.position.xMm, notehead.position.lp + side.getDir() * distanceIs * 2);
        if (pos == WaypointPosition.Start)
            slurCache.setStart(defaultSp, staff, systemIndex);
        else
            slurCache.setStop(defaultSp, staff, systemIndex);
    }
    // lyric
    List<Lyric> lyrics = element.getLyrics();
    if (lyrics.size() > 0) {
        float baseLine = -10;
        for (Lyric lyric : lyrics) {
            if (lyric != null) {
                SyllableType lyricType = lyric.getSyllableType();
                StaffTextStamping lastLyric = lastLyrics.get(staffIndex, lyric.getVerse());
                if (lyricType == SyllableType.Extend) {
                    // extend
                    if (// TODO: frame breaks...
                    lastLyric != null) {
                        // remember it
                        openLyricsCache.setUnderscore((Lyric) lastLyric.getElement(), lastLyric, chordSt.noteheads[0], /* TODO*/
                        staffIndex);
                    }
                } else {
                    // normal lyric
                    // create text stamping
                    StaffTextStamping sts = lyricStamper.createSyllableStamping(lyric, defaultLyricStyle, context.getCurrentStaffStamping(), chordSt.noteheads[0].position.xMm, baseLine);
                    ret.add(sts);
                    // when middle or end syllable, add a hypen between the preceding syllable and this syllable
                    if (// TODO: frame breaks...
                    lastLyric != null) {
                        if (lyricType == SyllableType.Middle || lyricType == SyllableType.End) {
                            StaffTextStamping hyphenStamping = lyricStamper.createHyphenStamping(lastLyric, sts, defaultLyricStyle);
                            ret.add(hyphenStamping);
                        }
                    }
                    // remember this lyric as the currently last one in the current staff and verse
                    lastLyrics.set(staffIndex, lyric.getVerse(), sts);
                }
            }
            baseLine += -5;
        }
    }
    // directions
    ret.addAll(directionStamper.stampForChord(chordSt, context.layouter.symbols));
    // tuplet
    Tuplet tuplet = element.getTuplet();
    if (tuplet != null) {
        openTupletsCache.addChord(element, tuplet, chordSt);
    }
    return ret;
}
Also used : lombok.val(lombok.val) WaypointPosition(com.xenoage.zong.core.music.WaypointPosition) SlurWaypoint(com.xenoage.zong.core.music.slur.SlurWaypoint) SlurWaypoint(com.xenoage.zong.core.music.slur.SlurWaypoint) VSide(com.xenoage.utils.math.VSide) Beam(com.xenoage.zong.core.music.beam.Beam) Tuplet(com.xenoage.zong.core.music.tuplet.Tuplet) Slur(com.xenoage.zong.core.music.slur.Slur) Lyric(com.xenoage.zong.core.music.lyric.Lyric) SyllableType(com.xenoage.zong.core.music.lyric.SyllableType) Chord(com.xenoage.zong.core.music.chord.Chord) ChordStampings(com.xenoage.zong.musiclayout.layouter.scoreframelayout.util.ChordStampings) SP(com.xenoage.zong.core.music.format.SP)

Example 4 with Slur

use of com.xenoage.zong.core.music.slur.Slur in project Zong by Xenoage.

the class SlurStamper method createForSingleSystem.

/**
 * Creates a {@link SlurStamping} for a curved line that
 * uses only a single system. The slur may span over multiple staves.
 */
SlurStamping createForSingleSystem(SlurCache slurCache) {
    Slur slur = slurCache.getSlur();
    SlurWaypoint wp1 = slur.getStart();
    SlurWaypoint wp2 = slur.getStop();
    // end points of the bezier curve
    VSide side = slurCache.getSide();
    SP p1 = computeEndPoint(slur, slurCache.getDefaultStartSp(), wp1.getBezierPoint());
    SP p2 = computeEndPoint(slur, slurCache.getDefaultStopSp(), wp2.getBezierPoint());
    // control points of the bezier curve
    BezierPoint b1 = wp1.getBezierPoint();
    BezierPoint b2 = wp2.getBezierPoint();
    SP c1 = (// custom formatting
    b1 != null && b1.getControl() != null ? // custom formatting
    b1.getControl() : // default formatting
    computeLeftControlPoint(slur, p1, p2, slurCache.getStartStaff()));
    SP c2 = (// custom formatting
    b2 != null && b2.getControl() != null ? // custom formatting
    b2.getControl() : // default formatting
    computeRightControlPoint(slur, p1, p2, slurCache.getStopStaff()));
    return new SlurStamping(slur, p1, p2, c1, c2, slurCache.getStartStaff(), slurCache.getStopStaff());
}
Also used : BezierPoint(com.xenoage.zong.core.music.format.BezierPoint) Slur(com.xenoage.zong.core.music.slur.Slur) ContinuedSlur(com.xenoage.zong.musiclayout.continued.ContinuedSlur) SlurStamping(com.xenoage.zong.musiclayout.stampings.SlurStamping) SP(com.xenoage.zong.core.music.format.SP) SlurWaypoint(com.xenoage.zong.core.music.slur.SlurWaypoint) VSide(com.xenoage.utils.math.VSide)

Example 5 with Slur

use of com.xenoage.zong.core.music.slur.Slur in project Zong by Xenoage.

the class Test24f method test.

@Test
public void test() {
    checkGraceChords(getFirstStaff(), expectedChords);
    // slur between chord 1 and 2
    Slur slur = expectedChords[1].getSlurs().get(0);
    assertEquals(expectedChords[1], slur.getStart().getChord());
    assertEquals(expectedChords[2], slur.getStop().getChord());
}
Also used : Slur(com.xenoage.zong.core.music.slur.Slur) Test(org.junit.Test)

Aggregations

Slur (com.xenoage.zong.core.music.slur.Slur)6 SlurWaypoint (com.xenoage.zong.core.music.slur.SlurWaypoint)4 VSide (com.xenoage.utils.math.VSide)2 Chord (com.xenoage.zong.core.music.chord.Chord)2 SP (com.xenoage.zong.core.music.format.SP)2 Test (org.junit.Test)2 Score (com.xenoage.zong.core.Score)1 WaypointPosition (com.xenoage.zong.core.music.WaypointPosition)1 Beam (com.xenoage.zong.core.music.beam.Beam)1 BezierPoint (com.xenoage.zong.core.music.format.BezierPoint)1 Lyric (com.xenoage.zong.core.music.lyric.Lyric)1 SyllableType (com.xenoage.zong.core.music.lyric.SyllableType)1 Tuplet (com.xenoage.zong.core.music.tuplet.Tuplet)1 ContinuedSlur (com.xenoage.zong.musiclayout.continued.ContinuedSlur)1 ChordStampings (com.xenoage.zong.musiclayout.layouter.scoreframelayout.util.ChordStampings)1 SlurStamping (com.xenoage.zong.musiclayout.stampings.SlurStamping)1 lombok.val (lombok.val)1