Search in sources :

Example 1 with BeamSpacing

use of com.xenoage.zong.musiclayout.spacing.BeamSpacing in project Zong by Xenoage.

the class SingleStaffBeamSpacer method compute.

BeamSpacing compute(BeamNotation beam, SystemSpacing systemSpacing, int staffLinesCount) {
    int size = beam.element.size();
    // compute slant
    val chords = beamSpacer.getBeamChordSpacings(beam, systemSpacing);
    val stems = BeamedStems.fromBeam(chords);
    val slant = singleStaffBeamSlanter.compute(stems, staffLinesCount);
    // compute the ends of the first and last stem
    val placement = singleStaffBeamPlacer.compute(slant, stems, 1, Companion.staffLines(staffLinesCount));
    // adjust the stem lengths by interpolating the other values
    for (int i : range(size)) {
        float lp = INSTANCE.interpolateLinear(placement.leftEndLp, placement.rightEndLp, stems.leftXIs, stems.rightXIs, stems.get(i).xIs);
        val stem = beam.chords.get(i).stem;
        if (// it could be possible that there is no stem
        stem != null)
            stem.endSlp = stem.endSlp.withLp(lp);
    }
    return new BeamSpacing(beam, placement.leftEndLp, placement.rightEndLp, chords);
}
Also used : lombok.val(lombok.val) BeamSpacing(com.xenoage.zong.musiclayout.spacing.BeamSpacing)

Example 2 with BeamSpacing

use of com.xenoage.zong.musiclayout.spacing.BeamSpacing in project Zong by Xenoage.

the class ScoreLayouter method createLayoutWithExceptions.

/**
 * Computes the whole layout and returns it.
 * If something fails, an exception is thrown.
 */
public ScoreLayout createLayoutWithExceptions() {
    // notations of elements
    Notations notations = notator.computeAll(context);
    // compute optimal measure column spacings
    List<ColumnSpacing> columns = columnsSpacer.compute(notations, context);
    // break columns into systems and frames
    FramesSpacing frames = framesSpacer.compute(columns, target, context, notations);
    // system stretching (horizontal)
    fillSystemsHorizontally(frames, target);
    // frame filling (vertical)
    fillFramesVertically(frames, target, context.score);
    // compute beam spacings. these are computed only now, after the horizontal
    // and vertical spacing of the score is fixed, since the beam slants depend on the
    // exact spacings
    Map<Beam, BeamSpacing> beams = beamsSpacer.compute(context.score, notations, frames);
    // create score frame layouts from the collected information
    List<ScoreFrameLayout> scoreFrameLayouts = createScoreFrameLayouts(frames, notations, context, beams);
    // create score layout
    return new ScoreLayout(context.score, scoreFrameLayouts, context.symbols, context.settings);
}
Also used : Beam(com.xenoage.zong.core.music.beam.Beam) FramesSpacing(com.xenoage.zong.musiclayout.spacing.FramesSpacing) BeamSpacing(com.xenoage.zong.musiclayout.spacing.BeamSpacing) ColumnSpacing(com.xenoage.zong.musiclayout.spacing.ColumnSpacing) Notations(com.xenoage.zong.musiclayout.notation.Notations) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout)

Example 3 with BeamSpacing

use of com.xenoage.zong.musiclayout.spacing.BeamSpacing in project Zong by Xenoage.

the class VoiceStamper method stampVoice.

public List<Stamping> stampVoice(VoiceSpacing voice, float voiceXMm, StaffStampings staffStampings, boolean stampLeadingRests, StamperContext context, // TODO:
FormattedTextStyle defaultLyricStyle, Map<Beam, BeamSpacing> beams, OpenSlursCache openCurvedLinesCache, OpenLyricsCache openLyricsCache, LastLyrics lastLyrics, OpenTupletsCache openTupletsCache) {
    List<Stamping> ret = alist();
    // create the voice elements
    boolean onlyRestsSoFar = true;
    for (ElementSpacing spacingElement : voice.elements) {
        MusicElement element = spacingElement.getElement();
        if (element != null) /* TODO && (stampRests || !(element instanceof Rest)) */
        {
            Notation notation = context.getNotation(element);
            float xMm = voiceXMm + spacingElement.xIs * voice.interlineSpace;
            if (element instanceof Chord) {
                // chord
                onlyRestsSoFar = false;
                Chord chord = (Chord) element;
                BeamSpacing beam = beams.get(chord.getBeam());
                ret.addAll(chordStamper.stampAll((ChordNotation) spacingElement.getNotation(), xMm, beam, staffStampings, context, defaultLyricStyle, openCurvedLinesCache, openLyricsCache, lastLyrics, openTupletsCache));
            } else if (spacingElement instanceof RestSpacing) {
                // rest
                if (false == onlyRestsSoFar || stampLeadingRests) {
                    // not a leading rest, or a leading rest which should be stamped
                    ret.add(elementStamper.createRestStamping((RestSpacing) spacingElement, xMm, context));
                }
            } else {
                throw new IllegalArgumentException("Notation not supported: " + notation);
            }
        }
    }
    return ret;
}
Also used : ElementSpacing(com.xenoage.zong.musiclayout.spacing.ElementSpacing) Stamping(com.xenoage.zong.musiclayout.stampings.Stamping) BeamSpacing(com.xenoage.zong.musiclayout.spacing.BeamSpacing) ChordNotation(com.xenoage.zong.musiclayout.notation.ChordNotation) MusicElement(com.xenoage.zong.core.music.MusicElement) RestSpacing(com.xenoage.zong.musiclayout.spacing.RestSpacing) Notation(com.xenoage.zong.musiclayout.notation.Notation) ChordNotation(com.xenoage.zong.musiclayout.notation.ChordNotation) Chord(com.xenoage.zong.core.music.chord.Chord)

Example 4 with BeamSpacing

use of com.xenoage.zong.musiclayout.spacing.BeamSpacing 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 5 with BeamSpacing

use of com.xenoage.zong.musiclayout.spacing.BeamSpacing in project Zong by Xenoage.

the class TwoStavesBeamSpacer method compute.

BeamSpacing compute(BeamNotation beam, SystemSpacing system) {
    // compute slant
    val slant = twoStavesBeamSlanter.compute(beam);
    // compute the ends of the first and last stem
    val chords = beamSpacer.getBeamChordSpacings(beam, system);
    val stems = BeamedStems.fromBeam(chords);
    val placement = twoStavesBeamPlacer.compute(slant, stems, beam, system);
    // adjust the stem lengths by interpolating
    // the end LPs of the stems have then to be relative to the beam's staff (the staff of the first chord)
    int beamStaffIndex = beam.mp.getStaff();
    float leftEndYMm = system.getYMm(placement.leftSlp);
    float rightEndYMm = system.getYMm(placement.rightSlp);
    // may be on different staff, so this is not always equal to placement.rightSlp.lp
    float beamRightEndLp = 0;
    for (int iChord : range(stems)) {
        float yMm = INSTANCE.interpolateLinear(leftEndYMm, rightEndYMm, stems.leftXIs, stems.rightXIs, stems.get(iChord).xIs);
        float lp = system.getLp(beamStaffIndex, yMm);
        if (iChord == stems.getCount() - 1)
            beamRightEndLp = lp;
        // so that it touches each beam line
        if (stems.get(iChord).dir != stems.primaryStemDir) {
            int linesCountAtChord = INSTANCE.getFlagsCount(beam.chords.get(iChord).element.getDuration());
            lp += stems.get(iChord).dir.getSign() * 2 * ((linesCountAtChord - 1) * beam.lineHeightIs + linesCountAtChord * beam.gapIs);
        }
        StemNotation stem = beam.chords.get(iChord).stem;
        if (// it could be possible that there is no stem
        stem != null)
            // before, maybe the end LP was relative to another staff
            stem.endSlp = slp(beamStaffIndex, lp);
    }
    return new BeamSpacing(beam, placement.leftSlp.lp, beamRightEndLp, chords);
}
Also used : lombok.val(lombok.val) BeamSpacing(com.xenoage.zong.musiclayout.spacing.BeamSpacing) StemNotation(com.xenoage.zong.musiclayout.notation.chord.StemNotation)

Aggregations

BeamSpacing (com.xenoage.zong.musiclayout.spacing.BeamSpacing)5 lombok.val (lombok.val)3 Beam (com.xenoage.zong.core.music.beam.Beam)2 MusicElement (com.xenoage.zong.core.music.MusicElement)1 Chord (com.xenoage.zong.core.music.chord.Chord)1 MP (com.xenoage.zong.core.position.MP)1 BeamIterator (com.xenoage.zong.core.util.BeamIterator)1 ScoreFrameLayout (com.xenoage.zong.musiclayout.ScoreFrameLayout)1 ScoreLayout (com.xenoage.zong.musiclayout.ScoreLayout)1 BeamNotation (com.xenoage.zong.musiclayout.notation.BeamNotation)1 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)1 Notation (com.xenoage.zong.musiclayout.notation.Notation)1 Notations (com.xenoage.zong.musiclayout.notation.Notations)1 StemNotation (com.xenoage.zong.musiclayout.notation.chord.StemNotation)1 ColumnSpacing (com.xenoage.zong.musiclayout.spacing.ColumnSpacing)1 ElementSpacing (com.xenoage.zong.musiclayout.spacing.ElementSpacing)1 FramesSpacing (com.xenoage.zong.musiclayout.spacing.FramesSpacing)1 RestSpacing (com.xenoage.zong.musiclayout.spacing.RestSpacing)1 Stamping (com.xenoage.zong.musiclayout.stampings.Stamping)1