maxX = 0;
xpos.put(new Double(0), 0);
int maxLeft = 0;
long lastLineBreak = 0;
for (int x = 0; x < allLayoutObjects.size(); x++) {
SimpleNode nd = allLayoutObjects.get(x);
//a new lineBreak is generated
if (nd.id == ParserTreeConstants.JJTBAR && lastX - lastLineBreak > MAX_LINE_LEN) {
lastLineBreak = lastX;
score.registerBreak(nd);
nd.setLayoutObject(LayoutObject.NULL_LAYOUT());
nd.getlayoutObject().priority = 99;
generateNodesForBreak(nd.getBeattime(),false);
Collections.sort(allLayoutObjects);
x--;
continue;
}
if (nd.getBeattime() != lastBeattime || nd.getlayoutObject().priority != lastPriority) {
maxLeft = nd.getlayoutObject().distanceLeft;//distanceLeft=maxLeft beacause ordering
Integer intp = xpos.get(nd.getBeattime());
if (intp == null) {
if (nd.id == ParserTreeConstants.JJTBAR) {
((ASTBar) nd).unvisible = true;
} else {
new Exception("invalid beattime " + nd.toString());
}
} else {
lastX = xpos.get(nd.getBeattime()) + maxLeft;
}
lastBeattime = nd.getBeattime();
lastPriority = nd.getlayoutObject().priority;
}
//manuell linebreak -> count virtuell linebreaks from begin
if (nd.id == ParserTreeConstants.JJTFUNCTION && nd.jjtGetFirstToken().kind == ParserConstants.break_) {
lastLineBreak = lastX;
}
//register beattime for next group
double newBeatTime = round(nd.getBeattime() + nd.duration);
Integer oldPos = xpos.get(newBeatTime);
int nextPos = lastX + nd.getlayoutObject().distanceRight;
if (oldPos == null || nextPos > oldPos) {
xpos.put(newBeatTime, nextPos);
}
nd.getlayoutObject().x = lastX;
//move all higher registred positions if needed
Iterator<Entry<Double, Integer>> itv = xpos.tailMap(newBeatTime, false).entrySet().iterator();
int toMove = 0;
while (itv.hasNext()) {
Entry<Double, Integer> n = itv.next();
int test = n.getValue() - nd.getlayoutObject().x;
if (test <= toMove) {
toMove = -test;
}
if (toMove > 0) {
n.setValue(n.getValue() + toMove + 5);//5 -> should not stand on the same position like node