use of blue.components.lines.Line in project blue by kunstmusik.
the class ParameterLinePanel method insertGraphPoint.
/**
* Use by the MouseListener to add points
*
* @param x
* @param y
* @return
*/
protected LinePoint insertGraphPoint(int x, int y) {
LinePoint point = new LinePoint();
double min = currentParameter.getMin();
double max = currentParameter.getMax();
point.setLocation(screenToDoubleX(x), screenToDoubleY(y, min, max, currentParameter.getResolution()));
int index = 1;
Line currentLine = currentParameter.getLine();
LinePoint last = currentLine.getLinePoint(currentLine.size() - 1);
if (point.getX() > last.getX()) {
currentLine.addLinePoint(point);
return point;
}
for (int i = 0; i < currentLine.size(); i++) {
LinePoint p1 = currentLine.getLinePoint(i);
LinePoint p2 = currentLine.getLinePoint(i + 1);
if (point.getX() >= p1.getX() && point.getX() <= p2.getX()) {
index = i + 1;
break;
}
}
currentLine.addLinePoint(index, point);
return point;
}
use of blue.components.lines.Line 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.Line in project blue by kunstmusik.
the class ParameterLinePanel method getSelectionScalingSortedLine.
// private boolean isPointInSelectionRegion(double pointTime, double timeMod) {
// double min, max;
// double[] points;
//
// for (int i = 0; i < selectionList.size(); i++) {
// points = selectionList.get(i);
// min = points[0] + timeMod;
// max = points[1] + timeMod;
//
// if (pointTime >= min && pointTime <= max) {
// return true;
// }
// }
// return false;
// }
/**
* Pre-Selection Selection Post-Selection
*
* TODO - fix for scaling
*
* @param line
*/
// private void processLineForSelectionDrag(Line line) {
//
// ArrayList<LinePoint> points = new ArrayList<>();
// double[] selPoints = selectionList.get(0);
//
// double selectionStartTime = selPoints[0];
// double selectionEndTime = selPoints[1];
//
// double preSelectionEnd = selectionStartTime;
// double postSelectionBeginning = selectionEndTime;
//
// if(transTime < 0) {
// preSelectionEnd = selectionStartTime + transTime;
// } else {
// postSelectionBeginning = selectionEndTime + transTime;
// }
//
// double preSelectY = line.getValue(preSelectionEnd);
// double postSelectY = line.getValue(postSelectionBeginning);
//
// points.add(new LinePoint(selectionStartTime, line.getValue(selectionStartTime)));
// points.add(new LinePoint(selectionEndTime, line.getValue(selectionEndTime)));
//
// for (Iterator<LinePoint> iter = line.iterator(); iter.hasNext();) {
//
// LinePoint lp = iter.next();
//
// if (line.isFirstLinePoint(lp)) {
// continue;
// }
//
// double pointTime = lp.getX();
//
// if (isPointInSelectionRegion(pointTime, 0)) {
// points.add(lp);
// iter.remove();
// } else if (isPointInSelectionRegion(pointTime, transTime)) {
// iter.remove();
// }
// }
//
// line.addLinePoint(new LinePoint(preSelectionEnd, preSelectY));
// line.addLinePoint(new LinePoint(postSelectionBeginning, postSelectY));
//
// for (LinePoint lp : points) {
// lp.setLocation(lp.getX() + transTime, lp.getY());
// line.addLinePoint(lp);
// }
//
// line.sort();
// }
/**
* Returns a line that has the points sorted and those masked removed when
* handling SelectionScaling; not sure this will be good for long term as it
* doesn't seem performant but using for initial work and can reevaluate
* later.
*
* @param line
* @return
*/
private Line getSelectionScalingSortedLine(Line line) {
Line retVal = new Line(line);
processLineForSelectionScale(retVal);
return retVal;
}
use of blue.components.lines.Line in project blue by kunstmusik.
the class LineCanvas method paintComponent.
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setStroke(STROKE2);
RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHints(hints);
// g.setColor(bgColor);
g2d.setColor(Color.black);
g2d.fillRect(0, 0, this.getWidth(), this.getHeight());
g2d.setColor(Color.lightGray);
g2d.drawRect(5, 5, this.getWidth() - 10, this.getHeight() - 10);
Color currentColor = null;
if (lineList == null) {
return;
}
for (Line line : lineList) {
if (line == currentLine) {
currentColor = line.getColor();
} else {
g2d.setColor(line.getColor().darker());
drawLine(g2d, line, false);
}
}
if (currentColor != null) {
g2d.setColor(currentColor);
drawLine(g2d, currentLine, true);
}
if (selectedPoint != null) {
double min = currentLine.getMin();
double max = currentLine.getMax();
int x = doubleToScreenX(selectedPoint.getX());
int y = doubleToScreenY(selectedPoint.getY(), min, max);
g2d.setColor(Color.red);
paintPoint(g2d, x, y);
if (currentLine != null) {
drawPointInformation(g2d, x, y);
}
}
}
use of blue.components.lines.Line 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