Search in sources :

Example 6 with LinePoint

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);
        }
    }
}
Also used : Line(blue.components.lines.Line) LinePoint(blue.components.lines.LinePoint) Rectangle(java.awt.Rectangle) Point(java.awt.Point) LinePoint(blue.components.lines.LinePoint) BigDecimal(java.math.BigDecimal)

Example 7 with LinePoint

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();
}
Also used : LinePoint(blue.components.lines.LinePoint) ArrayList(java.util.ArrayList)

Example 8 with LinePoint

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;
        }
    }
}
Also used : LinePoint(blue.components.lines.LinePoint) Point(java.awt.Point) LinePoint(blue.components.lines.LinePoint)

Example 9 with LinePoint

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]);
        }
    }
}
Also used : LinePoint(blue.components.lines.LinePoint) Point(java.awt.Point) LinePoint(blue.components.lines.LinePoint)

Example 10 with LinePoint

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());
}
Also used : SoundObjectParameterLine(blue.components.lines.SoundObjectParameterLine) Line(blue.components.lines.Line) LinePoint(blue.components.lines.LinePoint) StrBuilder(org.apache.commons.lang3.text.StrBuilder) LinePoint(blue.components.lines.LinePoint)

Aggregations

LinePoint (blue.components.lines.LinePoint)43 Line (blue.components.lines.Line)18 Point (java.awt.Point)13 Paint (javafx.scene.paint.Paint)6 SoundObjectParameterLine (blue.components.lines.SoundObjectParameterLine)3 Rectangle (java.awt.Rectangle)3 MenuItem (javafx.scene.control.MenuItem)3 Parameter (blue.automation.Parameter)2 DragDirection (blue.components.DragDirection)2 LineList (blue.components.lines.LineList)2 BlueFX (blue.jfx.BlueFX)2 Sound (blue.soundObject.Sound)2 NumberUtilities (blue.utility.NumberUtilities)2 BigDecimal (java.math.BigDecimal)2 Optional (java.util.Optional)2 BooleanProperty (javafx.beans.property.BooleanProperty)2 ObjectProperty (javafx.beans.property.ObjectProperty)2 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)2 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)2 ListChangeListener (javafx.collections.ListChangeListener)2