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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations