use of blue.components.lines.LinePoint in project blue by kunstmusik.
the class ParameterLinePanel method drawLine.
private final void drawLine(Graphics g, Parameter p, boolean drawPoints) {
Line line = p.getLine();
Rectangle clipBounds = g.getClipBounds();
if (line.size() == 0) {
return;
}
if (line.size() == 1) {
LinePoint lp = line.getLinePoint(0);
double min = line.getMin();
double max = line.getMax();
int x = doubleToScreenX(lp.getX());
int y = doubleToScreenY(lp.getY(), min, max);
g.drawLine(0, y, getWidth(), y);
if (drawPoints) {
paintPoint(g, x, y);
}
return;
}
if (p.getResolution().doubleValue() <= 0) {
int[] xValues = new int[line.size()];
int[] yValues = new int[line.size()];
double min = line.getMin();
double max = line.getMax();
for (int i = 0; i < line.size(); i++) {
LinePoint point = line.getLinePoint(i);
xValues[i] = doubleToScreenX(point.getX());
yValues[i] = doubleToScreenY(point.getY(), min, max);
}
g.drawPolyline(xValues, yValues, xValues.length);
final int lastX = xValues[xValues.length - 1];
if (lastX < this.getWidth()) {
int lastY = yValues[yValues.length - 1];
g.drawLine(lastX, lastY, getWidth(), lastY);
}
if (drawPoints) {
for (int i = 0; i < xValues.length; i++) {
paintPoint(g, xValues[i], yValues[i]);
}
}
} else {
LinePoint previous = null;
int x, y;
double min = p.getMin();
double max = p.getMax();
BigDecimal resolution = p.getResolution();
for (int i = 0; i < line.size(); i++) {
LinePoint point = line.getLinePoint(i);
x = doubleToScreenX(point.getX());
y = doubleToScreenY(point.getY(), min, max);
if (drawPoints) {
paintPoint(g, x, y);
}
if (previous != null) {
double startVal = previous.getY();
int startX = doubleToScreenX(previous.getX());
int startY = doubleToScreenY(startVal, min, max);
int endX = doubleToScreenX(point.getX());
int endY = doubleToScreenY(point.getY(), min, max);
if (startVal == point.getY()) {
g.drawLine(startX, startY, endX, startY);
previous = point;
continue;
}
if (previous.getX() == point.getX()) {
if (startY != endY) {
g.drawLine(startX, startY, startX, endY);
}
previous = point;
continue;
}
int lastY = startY;
int lastX = startX;
for (int j = startX; j <= endX; j++) {
double timeVal = screenToDoubleX(j);
double val = line.getValue(timeVal);
int newY = doubleToScreenY(val, min, max);
if (endY > startY) {
if (newY < startY) {
newY = startY;
}
} else if (newY > startY) {
newY = startY;
}
if (newY != lastY) {
g.drawLine(lastX, lastY, j, lastY);
g.drawLine(j, lastY, j, newY);
lastX = j;
lastY = newY;
}
}
if (lastX != endX) {
g.drawLine(lastX, lastY, endX, lastY);
g.drawLine(endX, lastY, endX, endY);
}
}
previous = point;
}
if (previous.getX() < this.getWidth()) {
int lastX = doubleToScreenX(previous.getX());
int lastY = doubleToScreenY(previous.getY(), min, max);
g.drawLine(lastX, lastY, getWidth(), lastY);
}
}
}
use of blue.components.lines.LinePoint in project blue by kunstmusik.
the class ParameterLinePanel method processLineForSelectionScale.
private void processLineForSelectionScale(Line line) {
if (selectionStartTime < 0) {
return;
}
ArrayList<LinePoint> points = new ArrayList<>();
for (Iterator<LinePoint> iter = line.iterator(); iter.hasNext(); ) {
LinePoint lp = iter.next();
if (line.isFirstLinePoint(lp)) {
continue;
}
double pointTime = lp.getX();
if (pointTime >= selectionStartTime && pointTime <= selectionEndTime) {
points.add(lp);
iter.remove();
} else if (pointTime >= newSelectionStartTime && pointTime <= newSelectionEndTime) {
iter.remove();
}
}
double oldStart = selectionStartTime;
double newStart = newSelectionStartTime;
double oldRange = selectionEndTime - selectionStartTime;
double newRange = newSelectionEndTime - newSelectionStartTime;
for (Iterator<LinePoint> iterator = points.iterator(); iterator.hasNext(); ) {
LinePoint lp = iterator.next();
double newX = (lp.getX() - oldStart);
newX = (newX / oldRange) * newRange;
newX += newStart;
lp.setLocation(newX, lp.getY());
line.addLinePoint(lp);
}
line.sort();
}
use of blue.components.lines.LinePoint in project blue by kunstmusik.
the class LineCanvas method setBoundaryXValues.
public void setBoundaryXValues() {
if (selectedPoint == null) {
return;
}
if (selectedPoint == currentLine.getLinePoint(0)) {
leftBoundaryX = 5;
rightBoundaryX = 5;
return;
} else if (selectedPoint == currentLine.getLinePoint(currentLine.size() - 1)) {
leftBoundaryX = this.getWidth() - 5;
rightBoundaryX = this.getWidth() - 5;
return;
}
for (int i = 0; i < currentLine.size(); i++) {
if (currentLine.getLinePoint(i) == selectedPoint) {
LinePoint p1 = currentLine.getLinePoint(i - 1);
LinePoint p2 = currentLine.getLinePoint(i + 1);
leftBoundaryX = doubleToScreenX(p1.getX());
rightBoundaryX = doubleToScreenX(p2.getX());
return;
}
}
}
use of blue.components.lines.LinePoint in project blue by kunstmusik.
the class LineCanvas method drawLine.
private final void drawLine(Graphics g, Line line, boolean drawPoints) {
double min = line.getMin();
double max = line.getMax();
int[] xValues = new int[line.size()];
int[] yValues = new int[line.size()];
for (int i = 0; i < line.size(); i++) {
LinePoint point = line.getLinePoint(i);
xValues[i] = doubleToScreenX(point.getX());
yValues[i] = doubleToScreenY(point.getY(), min, max);
}
g.drawPolyline(xValues, yValues, xValues.length);
if (drawPoints) {
for (int i = 0; i < xValues.length; i++) {
paintPoint(g, xValues[i], yValues[i]);
}
}
}
use of blue.components.lines.LinePoint in project blue by kunstmusik.
the class CSDRender method getTempoMapper.
protected TempoMapper getTempoMapper(Tempo tempo) {
StrBuilder buffer = new StrBuilder();
Line line = tempo.getLine();
for (int i = 0; i < line.size(); i++) {
LinePoint lp = line.getLinePoint(i);
buffer.append(" ").append(lp.getX());
buffer.append(" ").append(lp.getY());
}
return TempoMapper.createTempoMapper(buffer.toString());
}
Aggregations