int[] startPointXArray = new int[childrenNoteOrChords.size()];
int[] startPointYArray = new int[childrenNoteOrChords.size()];
int[] stemLengthArray = new int[childrenNoteOrChords.size()];
ArrayList<Point> descendantPointList = new ArrayList<Point>();
for (int i = 0; i < childrenNoteOrChords.size(); i++) {
INoteOrChordForm noteOrChord = ((INoteOrChordForm) childrenNoteOrChords
.get(i));
if (!figurePassingObject.getNoteHeadLocationMap().containsKey(
noteOrChord.getId())) {
LogService.warning(MusicMessages.FigureRenderLibrary_2
+ noteOrChord.getId());
return;
}
Point startPoint = figurePassingObject.getNoteHeadLocationMap()
.get(noteOrChord.getId());
descendantPointList.add(startPoint);
startPointXArray[i] = startPoint.x;
startPointYArray[i] = startPoint.y;
stemLengthArray[i] = noteOrChord.getStemLength();
}
Arrays.sort(startPointXArray); // startpos of beam-X-axis is first
Arrays.sort(startPointYArray);
Arrays.sort(stemLengthArray); // determine min and max stemlengths
int extremeYValue; // the end of the stems: the y position component of
// the beam
Point beamStart; // the start pos of the basic 8th-beam
Point beamEnd; // the end pos of the basic 8th-beam
int default_minimal_space_const = stemLengthArray[childrenNoteOrChords
.size() - 1]; // biggest stemlength
int compensationX; // X-shifting compensation for stem touching the
// notehead
int compensationY; // Y-shifting compensation for stem touching the
// notehead
if (beamGroupForm.isStemDirUp()) {
extremeYValue = startPointYArray[0] - default_minimal_space_const;
compensationX = 9;
compensationY = 12;
} else {
extremeYValue = startPointYArray[childrenNoteOrChords.size() - 1]
+ default_minimal_space_const;
compensationX = 2;
compensationY = 13;
}
// draw thick 8th-beam
graphics.setLineWidth(3);
beamStart = new Point(startPointXArray[0] + compensationX,
extremeYValue + compensationY);
beamEnd = new Point(startPointXArray[childrenNoteOrChords.size() - 1]
+ compensationX, extremeYValue + compensationY);
graphics.drawLine(beamStart, beamEnd);
// draw partner beams and boxy at first one
for (int i = 0; i < childrenNoteOrChords.size() - 1
&& i < descendantPointList.size() - 1; i++) {
INoteOrChordForm oneNoteOrChord = ((INoteOrChordForm) childrenNoteOrChords
.get(i));
INoteOrChordForm otherNoteOrChord = ((INoteOrChordForm) childrenNoteOrChords
.get(i + 1));
Point startPoint = descendantPointList.get(i);
Point endPoint = descendantPointList.get(i + 1);
int shift = 5 * (beamGroupForm.isStemDirUp() ? 1 : -1);
// 1024 = whole note. calculate the connecting number by log(2).
// duration1024 recognizes durationincrements by dots etc, not
// applicable here
int durOne = oneNoteOrChord.getDuration1024();
int durOther = otherNoteOrChord.getDuration1024();
int minCommonLog = Math.max(HelperMethods.calculateLogOf2(durOne),
HelperMethods.calculateLogOf2(durOther));
// int minCommonLog = HelperMethods.calculateLogOf2(minCommon);
// if(minCommonLog < 0 ) minCommonLog = 7; //fallback: single beam
for (int k = 6; k >= minCommonLog; k--) {
graphics.drawLine(new Point(startPoint.x + compensationX,
extremeYValue + compensationY + (7 - k) * shift),
new Point(endPoint.x + compensationX, extremeYValue
+ compensationY + (7 - k) * shift));
}
for (int k = 6; k >= HelperMethods.calculateLogOf2(durOne); k--) {
graphics.drawLine(
new Point(startPoint.x + compensationX, extremeYValue
+ compensationY + (7 - k) * shift),
new Point(startPoint.x + compensationX + 5,
extremeYValue + compensationY + (7 - k) * shift));
}
}
// boxy flags on last noteOrChord in beam
INoteOrChordForm lastNoteOrChord = ((INoteOrChordForm) childrenNoteOrChords
.get(childrenNoteOrChords.size() - 1));
Point startPoint = descendantPointList
.get(childrenNoteOrChords.size() - 1);
int shift = 5 * (beamGroupForm.isStemDirUp() ? 1 : -1);
int durLast = 1024 / Integer.parseInt(lastNoteOrChord.getDuration());
for (int k = 6; k >= HelperMethods.calculateLogOf2(durLast); k--) {
graphics.drawLine(new Point(startPoint.x + compensationX,
extremeYValue + compensationY + (7 - k) * shift),
new Point(startPoint.x + compensationX - 5, extremeYValue
+ compensationY + (7 - k) * shift));