Search in sources :

Example 6 with Beam

use of com.xenoage.zong.core.music.beam.Beam in project Zong by Xenoage.

the class BeamsSpacer method compute.

public Map<Beam, BeamSpacing> compute(Score score, Notations notations, FramesSpacing frames) {
    Map<Beam, BeamSpacing> ret = map();
    BeamIterator itB = new BeamIterator(score);
    for (Beam beam : itB) {
        MP mp = itB.getMp();
        int staffLinesCount = score.getStaff(mp).getLinesCount();
        val frame = frames.getFrame(mp.measure);
        val system = frame.getSystem(mp.measure);
        val beamNotation = (BeamNotation) notations.get(beam);
        ret.put(beam, beamSpacer.compute(beamNotation, system, score));
    }
    return ret;
}
Also used : Beam(com.xenoage.zong.core.music.beam.Beam) lombok.val(lombok.val) BeamSpacing(com.xenoage.zong.musiclayout.spacing.BeamSpacing) MP(com.xenoage.zong.core.position.MP) BeamIterator(com.xenoage.zong.core.util.BeamIterator) BeamNotation(com.xenoage.zong.musiclayout.notation.BeamNotation)

Example 7 with Beam

use of com.xenoage.zong.core.music.beam.Beam in project Zong by Xenoage.

the class Notator method computeAll.

/**
 * Computes the {@link Notation}s of all elements and returns them.
 */
public Notations computeAll(Context context) {
    context.saveMp();
    Score score = context.score;
    Notations notations = new Notations();
    // iterate over all column elements, measure elements and voice elements
    ColumnElementIterator itC = new ColumnElementIterator(score);
    for (ColumnElement e : itC) {
        // column elements: one notation for each staff
        for (int iStaff : range(context.score.getStavesCount())) {
            context.mp = itC.getMp().withStaff(iStaff);
            notations.add(compute(e, context, notations), iStaff);
        }
    }
    MeasureElementIterator itM = new MeasureElementIterator(score);
    for (MeasureElement e : itM) {
        context.mp = itM.getMp();
        notations.add(compute(e, context, notations));
    }
    VoiceElementIterator itV = new VoiceElementIterator(score);
    for (VoiceElement e : itV) {
        context.mp = itV.getMp();
        notations.add(compute(e, context, notations));
    }
    BeamIterator itB = new BeamIterator(score);
    for (Beam e : itB) {
        context.mp = itB.getMp();
        notations.add(compute(e, context, notations));
    }
    context.restoreMp();
    return notations;
}
Also used : Beam(com.xenoage.zong.core.music.beam.Beam) Score(com.xenoage.zong.core.Score) VoiceElementIterator(com.xenoage.zong.core.util.VoiceElementIterator) Notations(com.xenoage.zong.musiclayout.notation.Notations) BeamIterator(com.xenoage.zong.core.util.BeamIterator) ColumnElementIterator(com.xenoage.zong.core.util.ColumnElementIterator) MeasureElementIterator(com.xenoage.zong.core.util.MeasureElementIterator)

Example 8 with Beam

use of com.xenoage.zong.core.music.beam.Beam 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 9 with Beam

use of com.xenoage.zong.core.music.beam.Beam in project Zong by Xenoage.

the class BeamIteratorTest method test.

@Test
public void test() {
    BeamIterator it = new BeamIterator(createTestScore());
    // first beam
    assertTrue(it.hasNext());
    Beam beam = it.next();
    assertEquals(atBeat(0, 0, 1, Companion.get_0()), beam.getMP());
    // second beam (two staves)
    assertTrue(it.hasNext());
    beam = it.next();
    assertEquals(atBeat(0, 2, 0, Companion.get_0()), beam.getMP());
    assertEquals(atBeat(0, 2, 0, Companion.get_0()), beam.getChord(0).getMP());
    assertEquals(atBeat(1, 2, 0, Companion.get_1$8()), beam.getChord(1).getMP());
    // third chord
    assertTrue(it.hasNext());
    beam = it.next();
    assertEquals(atBeat(1, 3, 0, Companion.get_0()), beam.getMP());
    // finished
    assertFalse(it.hasNext());
}
Also used : Beam(com.xenoage.zong.core.music.beam.Beam) Test(org.junit.Test)

Aggregations

Beam (com.xenoage.zong.core.music.beam.Beam)9 Chord (com.xenoage.zong.core.music.chord.Chord)4 lombok.val (lombok.val)3 Test (org.junit.Test)3 Score (com.xenoage.zong.core.Score)2 StemDirection (com.xenoage.zong.core.music.chord.StemDirection)2 SlurWaypoint (com.xenoage.zong.core.music.slur.SlurWaypoint)2 MP (com.xenoage.zong.core.position.MP)2 BeamIterator (com.xenoage.zong.core.util.BeamIterator)2 ChordStampings (com.xenoage.zong.musiclayout.layouter.scoreframelayout.util.ChordStampings)2 Notations (com.xenoage.zong.musiclayout.notation.Notations)2 BeamSpacing (com.xenoage.zong.musiclayout.spacing.BeamSpacing)2 VSide (com.xenoage.utils.math.VSide)1 Staff (com.xenoage.zong.core.music.Staff)1 Voice (com.xenoage.zong.core.music.Voice)1 VoiceElement (com.xenoage.zong.core.music.VoiceElement)1 WaypointPosition (com.xenoage.zong.core.music.WaypointPosition)1 SP (com.xenoage.zong.core.music.format.SP)1 Lyric (com.xenoage.zong.core.music.lyric.Lyric)1 SyllableType (com.xenoage.zong.core.music.lyric.SyllableType)1