use of com.xenoage.zong.musiclayout.stampings.Stamping in project Zong by Xenoage.
the class BarlinesStamper method stamp.
public List<Stamping> stamp(SystemSpacing system, List<StaffStamping> systemStaves, Score score) {
List<Stamping> ret = alist();
StaffStamping firstStaff = getFirst(systemStaves);
int stavesCount = systemStaves.size();
int systemIndex = system.getSystemIndexInFrame();
float xOffset = firstStaff.positionMm.x;
// common barline at the beginning, when system has at least one measure
if (system.columns.size() > 0) {
ret.add(new BarlineStamping(Barline.Companion.barlineRegular(), systemStaves, xOffset, BarlineGroup.Style.Common));
}
// barlines within the system and measure numbers
for (int iMeasure : range(system.columns)) {
float xLeft = xOffset;
// measure numbering
MeasureNumbering measureNumbering = score.getFormat().getMeasureNumbering();
int globalMeasureIndex = system.getStartMeasure() + iMeasure;
boolean showMeasureNumber = false;
if (measureNumbering == MeasureNumbering.System) {
// measure number at the beginning of each system (except the first one)
showMeasureNumber = (iMeasure == 0 && globalMeasureIndex > 0);
} else if (measureNumbering == MeasureNumbering.Measure) {
// measure number at each measure (except the first one)
showMeasureNumber = (globalMeasureIndex > 0);
}
if (showMeasureNumber) {
FormattedText text = Companion.fText("" + (globalMeasureIndex + 1), new FormattedTextStyle(8), Alignment.Left);
ret.add(new StaffTextStamping(text, sp(xLeft, firstStaff.linesCount * 2), firstStaff, null));
}
// for the first measure in the system: begin after leading spacing
if (iMeasure == 0)
xLeft += system.columns.get(iMeasure).getLeadingWidthMm();
xOffset += system.columns.get(iMeasure).getWidthMm();
float xRight = xOffset;
// regard the groups of the score
for (int iStaff : range(stavesCount)) {
ColumnHeader columnHeader = score.getColumnHeader(globalMeasureIndex);
BarlineGroup.Style barlineGroupStyle = BarlineGroup.Style.Single;
BarlineGroup group = score.getStavesList().getBarlineGroupByStaff(iStaff);
if (group != null)
barlineGroupStyle = group.getStyle();
List<StaffStamping> groupStaves = getBarlineGroupStaves(systemStaves, group);
// start barline
Barline startBarline = columnHeader.getStartBarline();
if (startBarline != null) {
// don't draw a regular barline at the left side of first measure of a system
if ((startBarline.getStyle() == BarlineStyle.Regular && systemIndex == 0) == false)
ret.add(new BarlineStamping(startBarline, groupStaves, xLeft, barlineGroupStyle));
}
// end barline. if none is set, use a regular one.
Barline endBarline = columnHeader.getEndBarline();
if (endBarline == null)
endBarline = Barline.Companion.barlineRegular();
ret.add(new BarlineStamping(endBarline, groupStaves, xRight, barlineGroupStyle));
// middle barlines
for (BeatE<Barline> middleBarline : columnHeader.getMiddleBarlines()) {
ret.add(new BarlineStamping(middleBarline.getElement(), groupStaves, xLeft + system.columns.get(iMeasure).getBarlineOffsetMm(middleBarline.getBeat()), barlineGroupStyle));
}
// go to next group
if (group != null)
iStaff = group.getStaves().getStop();
}
}
return ret;
}
use of com.xenoage.zong.musiclayout.stampings.Stamping in project Zong by Xenoage.
the class DirectionStamper method stamp.
/**
* Creates all direction stampings for the given measure.
*/
public List<Stamping> stamp(StamperContext context) {
List<Stamping> ret = alist();
val directionsWithBeats = context.getCurrentMeasure().getDirections().clone();
// over first staff, also add tempo directions for the whole column
if (context.staffIndex == 0) {
directionsWithBeats.addAll(context.getCurrentColumnHeader().getTempos());
}
for (BeatE<Direction> elementWithBeat : directionsWithBeats) {
Direction element = elementWithBeat.getElement();
Stamping stamping = null;
if (MusicElementType.Tempo.is(element))
stamping = directionStamper.createTempo((Tempo) element, context);
else if (MusicElementType.Dynamic.is(element))
stamping = directionStamper.createDynamics((Dynamic) element, context);
else if (MusicElementType.Pedal.is(element))
stamping = directionStamper.createPedal((Pedal) element, context);
else if (MusicElementType.Words.is(element))
stamping = directionStamper.createWords((Words) element, context);
if (stamping != null)
ret.add(stamping);
}
return ret;
}
use of com.xenoage.zong.musiclayout.stampings.Stamping in project Zong by Xenoage.
the class MeasureStamper method stampLeading.
/**
* Stamps the {@link MeasureElement}s of the leading spacing.
* @param leadingXMm the horizontal position on the staff in mm, where
* the leading spacing of the measure starts.
*/
public List<Stamping> stampLeading(MeasureSpacing measure, float leadingXMm, StamperContext context) {
LeadingSpacing leading = measure.leading;
if (leading == null)
return emptyList;
List<Stamping> ret = alist(leading.elements.size());
for (ElementSpacing element : leading.elements) {
MusicElement me = element.getElement();
if (me != null) {
float xMm = leadingXMm + element.xIs * measure.interlineSpace;
Notation notation = context.getNotation(me);
if (notation == null)
throw new RuntimeException("No notation for element " + me + " at " + MP.getMP(me));
ret.add(stamp(notation, xMm, context));
}
}
return ret;
}
use of com.xenoage.zong.musiclayout.stampings.Stamping in project Zong by Xenoage.
the class VoiceStamper method stampVoices.
public List<Stamping> stampVoices(MeasureSpacing measure, float voicesXMm, StaffStampings staffStampings, StamperContext context, // TODO:
FormattedTextStyle defaultLyricStyle, Map<Beam, BeamSpacing> beams, OpenSlursCache openCurvedLinesCache, OpenLyricsCache openLyricsCache, LastLyrics lastLyrics, OpenTupletsCache openTupletsCache) {
List<Stamping> ret = alist();
context.layouter.saveMp();
// iterate over the voices
for (int iVoice : range(measure.voices)) {
context.layouter.mp = context.layouter.mp.withVoice(iVoice);
VoiceSpacing voice = measure.voices.get(iVoice);
// don't stamp leading rests in non-first voices
boolean stampLeadingRests = (iVoice == 0);
// create voice stampings
ret.addAll(stampVoice(voice, voicesXMm, staffStampings, stampLeadingRests, context, defaultLyricStyle, beams, openCurvedLinesCache, openLyricsCache, lastLyrics, openTupletsCache));
}
context.layouter.restoreMp();
return ret;
}
use of com.xenoage.zong.musiclayout.stampings.Stamping in project Zong by Xenoage.
the class ScoreFrameLayoutTest method getLayoutElementAt.
@Test
public void getLayoutElementAt() {
/* 0 5 10 15 20 | 0
*
* *********** 2
* +----* [0] *
* | * *~~~~~~~ 4
* |[1] *********** |
* +--------+ [2] | 6
* | |
* ~~~~~~~~~~~~~~~~~~~~ 8
*/
Stamping[] stampings = new Stamping[3];
StampingMock s1 = new StampingMock(Level.Music, new Rectangle2f(6, 2, 10, 3));
stampings[0] = s1;
StampingMock s2 = new StampingMock(Level.Staff, new Rectangle2f(1, 3, 9, 3));
stampings[1] = s2;
StampingMock s3 = new StampingMock(Level.EmptySpace, new Rectangle2f(4, 4, 19, 4));
stampings[2] = s3;
ScoreFrameLayout layout = new ScoreFrameLayout(null, new ArrayList<>(), alist(stampings), new ArrayList<>());
// no hit (but empty space)
assertTrue(isNot(layout.getStampingAt(new Point2f(0, 0)), s1, s2, s3));
assertTrue(isNot(layout.getStampingAt(new Point2f(3, 7)), s1, s2, s3));
assertTrue(isNot(layout.getStampingAt(new Point2f(17, 3)), s1, s2, s3));
// single hit
assertEquals(s1, layout.getStampingAt(new Point2f(10, 2)));
assertEquals(s2, layout.getStampingAt(new Point2f(3, 5)));
assertEquals(s3, layout.getStampingAt(new Point2f(22, 8)));
// intersection hit
assertEquals(s1, layout.getStampingAt(new Point2f(15, 4)));
assertEquals(s2, layout.getStampingAt(new Point2f(5, 5)));
assertEquals(s1, layout.getStampingAt(new Point2f(8, 4)));
}
Aggregations