use of com.xenoage.zong.core.music.barline.BarlineRepeat in project Zong by Xenoage.
the class BarlinesBeatOffsetter method compute.
public Result compute(List<BeatOffset> baseOffsets, ColumnHeader columnHeader, float maxInterlineSpace) {
ArrayList<BeatOffset> retNotes = alist(baseOffsets);
ArrayList<BeatOffset> retBarlines = alist();
// start barline
retBarlines.add(new BeatOffset(Fraction.Companion.get_0(), 0));
Barline startBarline = columnHeader.getStartBarline();
if (startBarline != null && startBarline.getRepeat() == BarlineRepeat.Forward) {
// forward repeat: move all beats REPEAT_SPACE IS backward
float move = repeatSpace * maxInterlineSpace;
for (int i = 0; i < retNotes.size(); i++) {
BeatOffset oldOffset = retNotes.get(i);
retNotes.set(i, new BeatOffset(oldOffset.getBeat(), oldOffset.getOffsetMm() + move));
}
}
// mid-measure barlines
for (BeatE<Barline> midBarline : columnHeader.getMiddleBarlines()) {
// get beat of barline, find it in the note offsets and move the following ones
Fraction beat = midBarline.getBeat();
int i = 0;
float move = 0;
for (; i < retNotes.size(); i++) {
if (retNotes.get(i).getBeat().compareTo(beat) >= 0) {
BarlineRepeat repeat = midBarline.getElement().getRepeat();
if (repeat == BarlineRepeat.Backward) {
// backward repeat: additional space before barline
move += repeatSpace * maxInterlineSpace;
BeatOffset oldOffset = retNotes.get(i);
retBarlines.add(new BeatOffset(oldOffset.getBeat(), oldOffset.getOffsetMm() + move));
} else if (repeat == BarlineRepeat.Forward) {
// forward repeat: additional space after barline
BeatOffset oldOffset = retNotes.get(i);
retBarlines.add(new BeatOffset(oldOffset.getBeat(), oldOffset.getOffsetMm() + move));
move += repeatSpace * maxInterlineSpace;
} else if (repeat == BarlineRepeat.Both) {
// forward and backward repeat: additional space before and after barline
move += repeatSpace * maxInterlineSpace;
BeatOffset oldOffset = retNotes.get(i);
retBarlines.add(new BeatOffset(oldOffset.getBeat(), oldOffset.getOffsetMm() + move));
move += repeatSpace * maxInterlineSpace;
} else {
retBarlines.add(retNotes.get(i));
}
move += midBarlineSpace * maxInterlineSpace;
break;
}
}
for (; i < retNotes.size(); i++) {
// move following notes
BeatOffset oldOffset = retNotes.get(i);
retNotes.set(i, new BeatOffset(oldOffset.getBeat(), oldOffset.getOffsetMm() + move));
}
}
// end barline
BeatOffset lastOffset = retNotes.get(retNotes.size() - 1);
Barline endBarline = columnHeader.getEndBarline();
if (endBarline != null && endBarline.getRepeat() == BarlineRepeat.Backward) {
// backward repeat: additional space before end barline
float move = repeatSpace * maxInterlineSpace;
retBarlines.add(new BeatOffset(lastOffset.getBeat(), lastOffset.getOffsetMm() + move));
} else {
retBarlines.add(lastOffset);
}
// return result
retBarlines.trimToSize();
return new Result(retNotes, retBarlines);
}
use of com.xenoage.zong.core.music.barline.BarlineRepeat in project Zong by Xenoage.
the class BarlineRenderer method draw.
/**
* Draws the given {@link BarlineStamping} on the given {@link Canvas},
* using the given {@link RendererArgs}.
*/
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
BarlineStamping barlineSt = (BarlineStamping) stamping;
List<StaffStamping> staves = barlineSt.staves;
float xPosition = barlineSt.xMm;
float xCorrection = 0;
// lines
BarlineGroup.Style group = barlineSt.groupStyle;
BarlineStyle style = barlineSt.barline.getStyle();
if (group == null || group == BarlineGroup.Style.Single || group == BarlineGroup.Style.Common) {
// draw single barlines
for (StaffStamping staff : staves) {
xCorrection = paintBarline(canvas, args, staff, (staff.linesCount - 1) * 2, staff, 0, xPosition, style);
}
}
if (group == BarlineGroup.Style.Mensurstrich || group == BarlineGroup.Style.Common) {
// draw barlines between staves
for (int i = 0; i < staves.size() - 1; i++) {
xCorrection = paintBarline(canvas, args, staves.get(i), 0, staves.get(i + 1), (staves.get(i + 1).linesCount - 1) * 2, xPosition, style);
}
}
// repeat dots
// TODO: xCorrection is the value of the last staff, but this may differ
// draw repeat dots directly after drawing the corresponding staff!
BarlineRepeat repeat = barlineSt.barline.getRepeat();
if (repeat == BarlineRepeat.Forward || repeat == BarlineRepeat.Both) {
paintRepeatDots(staves, xPosition + xCorrection, 1, canvas, args);
}
if (repeat == BarlineRepeat.Backward || repeat == BarlineRepeat.Both) {
paintRepeatDots(staves, xPosition + xCorrection, -1, canvas, args);
}
}
Aggregations