Search in sources :

Example 1 with LinePoint

use of blue.components.lines.LinePoint in project blue by kunstmusik.

the class BSBLineObject method setPresetValue.

@Override
public void setPresetValue(String val) {
    String[] parts = val.split("@_@");
    int version = 1;
    int startIndex = 0;
    if (parts[0].startsWith("version=")) {
        version = Integer.parseInt(parts[0].substring(8));
        startIndex = 1;
    }
    for (int i = startIndex; i < parts.length; i++) {
        String lineStr = parts[i];
        // System.out.println(lineStr);
        String[] vals = lineStr.split(":");
        String name = vals[0];
        Line line = getLineByName(name);
        if (line != null) {
            line.clear();
            double min = line.getMin();
            double max = line.getMax();
            double range = max - min;
            for (int j = 1; j < vals.length; j += 2) {
                LinePoint p = new LinePoint();
                double x = (Double.parseDouble(vals[j]));
                double y = (Double.parseDouble(vals[j + 1]));
                if (version == 1) {
                    y = (y * range) + min;
                }
                p.setLocation(x, y);
                line.addLinePoint(p);
            }
        }
    }
    if (propListeners != null) {
        propListeners.firePropertyChange("presetValue", null, "preset");
    }
}
Also used : Line(blue.components.lines.Line) LinePoint(blue.components.lines.LinePoint) LinePoint(blue.components.lines.LinePoint)

Example 2 with LinePoint

use of blue.components.lines.LinePoint in project blue by kunstmusik.

the class BSBLineObject method getPresetValue.

@Override
public String getPresetValue() {
    StringBuilder buffer = new StringBuilder();
    buffer.append("version=2");
    for (Iterator iter = lines.iterator(); iter.hasNext(); ) {
        buffer.append("@_@");
        Line line = (Line) iter.next();
        StringBuilder temp = new StringBuilder();
        temp.append(line.getVarName());
        for (int i = 0; i < line.size(); i++) {
            LinePoint pt = line.getLinePoint(i);
            temp.append(":").append(pt.getX());
            temp.append(":").append(pt.getY());
        }
        buffer.append(temp.toString());
    }
    // System.out.println(buffer.toString());
    return buffer.toString();
}
Also used : Line(blue.components.lines.Line) LinePoint(blue.components.lines.LinePoint) Iterator(java.util.Iterator) LinePoint(blue.components.lines.LinePoint)

Example 3 with LinePoint

use of blue.components.lines.LinePoint in project blue by kunstmusik.

the class AbstractLineObject method createTable.

protected String createTable(Line line) {
    // double range = line.getMax() - line.getMin();
    // double min = line.getMin();
    StringBuilder buffer = new StringBuilder();
    int genSize = getGenSize();
    buffer.append(" 0 ");
    buffer.append(genSize);
    buffer.append(" -7 ");
    double lastTime = 0.0f;
    boolean firstPoint = true;
    for (int i = 0; i < line.size(); i++) {
        LinePoint point = line.getLinePoint(i);
        double newTime = point.getX() * genSize;
        double dur = Math.max(newTime - lastTime, 0);
        double yVal = point.getY();
        if (firstPoint) {
            firstPoint = false;
        } else {
            buffer.append(" ");
            buffer.append(NumberUtilities.formatDouble(dur));
        }
        buffer.append(" ");
        buffer.append(NumberUtilities.formatDouble(yVal));
        lastTime = newTime;
    }
    return buffer.toString();
}
Also used : LinePoint(blue.components.lines.LinePoint) LinePoint(blue.components.lines.LinePoint)

Example 4 with LinePoint

use of blue.components.lines.LinePoint in project blue by kunstmusik.

the class Parameter method setValue.

public void setValue(double value) {
    if (isAutomationEnabled()) {
        double time = ParameterTimeManagerFactory.getInstance().getTime();
        if (time < 0) {
            return;
        }
        updatingLine = true;
        LinePoint found = null;
        for (int i = 0; i < line.size(); i++) {
            LinePoint point = line.getLinePoint(i);
            if (point.getX() == time) {
                found = point;
                break;
            }
        }
        if (found != null) {
            found.setLocation(found.getX(), value);
        } else {
            LinePoint lp = new LinePoint();
            lp.setLocation(time, value);
            line.insertLinePoint(lp);
        }
        updatingLine = false;
    } else {
        this.value = value;
        if (line.size() == 1) {
            updatingLine = true;
            LinePoint lp = line.getLinePoint(0);
            lp.setLocation(lp.getX(), value);
            updatingLine = false;
        }
    }
}
Also used : LinePoint(blue.components.lines.LinePoint) LinePoint(blue.components.lines.LinePoint)

Example 5 with LinePoint

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