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");
}
}
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();
}
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();
}
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;
}
}
}
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;
}
Aggregations