use of blue.components.lines.LinePoint in project blue by kunstmusik.
the class CSDRender method getTempoScore.
protected String getTempoScore(Tempo tempo, double renderStart, double renderEnd) {
Line line = tempo.getLine();
if (line.size() == 1) {
return "t 0 " + line.getLinePoint(0).getY();
}
if (renderStart > line.getLinePoint(line.size() - 1).getX()) {
return "t 0 " + line.getLinePoint(line.size() - 1).getY();
}
StrBuilder buffer = new StrBuilder();
buffer.append("t 0 ").append(line.getValue(renderStart));
for (int i = 0; i < line.size(); i++) {
LinePoint lp = line.getLinePoint(i);
double pointBeat = lp.getX();
if (pointBeat > renderStart) {
if (renderEnd < 0 || pointBeat < renderEnd) {
buffer.append(" ").append(pointBeat - renderStart);
buffer.append(" ").append(lp.getY());
} else {
break;
}
}
}
if (renderEnd > 0) {
buffer.append(" ").append(renderEnd - renderStart);
buffer.append(" ").append(line.getValue(renderEnd));
}
buffer.append("\n");
return buffer.toString();
}
use of blue.components.lines.LinePoint in project blue by kunstmusik.
the class ParameterLineView method editPoints.
private void editPoints() {
TableView<LinePoint> table = new TableView<>();
TableColumn<LinePoint, Double> xCol = new TableColumn<>("x");
TableColumn<LinePoint, Double> yCol = new TableColumn<>("y");
table.getColumns().setAll(xCol, yCol);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
table.setItems(getSelectedLine().getObservableList());
table.setEditable(true);
xCol.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<LinePoint, Double>, ObservableValue<Double>>() {
@Override
public ObservableValue<Double> call(TableColumn.CellDataFeatures<LinePoint, Double> param) {
return new ReadOnlyObjectWrapper<>(param.getValue().getX() * getDuration() + getStartTime());
}
});
xCol.setCellFactory(TextFieldTableCell.forTableColumn(new DoubleStringConverter()));
xCol.setOnEditCommit(te -> {
LinePoint lp = te.getRowValue();
ObservableList<LinePoint> lpList = getSelectedLine().getObservableList();
if (getSelectedLine().getLinePoint(0) == lp || getSelectedLine().getLinePoint(getSelectedLine().size() - 1) == lp) {
return;
}
int index = lpList.indexOf(lp);
double v = (te.getNewValue() - getStartTime()) / getDuration();
lp.setX(Utils.clamp(lpList.get(index - 1).getX(), v, lpList.get(index + 1).getX()));
});
xCol.setEditable(true);
yCol.setCellValueFactory(new PropertyValueFactory<>("y"));
yCol.setCellFactory(TextFieldTableCell.forTableColumn(new DoubleStringConverter()));
yCol.setOnEditCommit(te -> {
te.getRowValue().setY(Utils.clamp(getSelectedLine().getMin(), te.getNewValue(), getSelectedLine().getMax()));
});
yCol.setEditable(true);
Dialog<ButtonType> d = new Dialog<>();
d.initOwner(getScene().getWindow());
d.initModality(Modality.APPLICATION_MODAL);
d.getDialogPane().setContent(new ScrollPane(table));
d.getDialogPane().getStylesheets().add(BlueFX.getBlueFxCss());
d.getDialogPane().getButtonTypes().setAll(ButtonType.OK);
d.setTitle("Edit Points");
TableModelListener tml = tme -> {
repaint();
};
getSelectedLine().addTableModelListener(tml);
Optional<ButtonType> res = d.showAndWait();
getSelectedLine().removeTableModelListener(tml);
}
use of blue.components.lines.LinePoint in project blue by kunstmusik.
the class ParameterLineView method mousePressed.
private void mousePressed(MouseEvent me) {
if (getSelectedLine() == null) {
return;
}
pressX = me.getX();
pressY = me.getY();
me.consume();
if (selectedPoint != null) {
if (me.isSecondaryButtonDown()) {
if (isLocked()) {
return;
}
LinePoint first = getSelectedLine().getLinePoint(0);
LinePoint last = getSelectedLine().getLinePoint(getSelectedLine().size() - 1);
if (selectedPoint != first && selectedPoint != last) {
getSelectedLine().removeLinePoint(selectedPoint);
selectedPoint = null;
repaint();
}
} else {
setBoundaryXValues();
}
} else {
if (me.isSecondaryButtonDown()) {
editPointsMenu.show(ParameterLineView.this, me.getScreenX(), me.getScreenY());
} else if (me.isPrimaryButtonDown()) {
if (!isLocked()) {
selectedPoint = insertGraphPoint(me.getX(), me.getY());
repaint();
setBoundaryXValues();
}
}
}
}
use of blue.components.lines.LinePoint in project blue by kunstmusik.
the class ParameterLineView method findGraphPoint.
public LinePoint findGraphPoint(double x, double y) {
double min = getSelectedLine().getMin();
double max = getSelectedLine().getMax();
for (int i = 0; i < getSelectedLine().size(); i++) {
LinePoint point = getSelectedLine().getLinePoint(i);
double tempX = point.getX() * getWidth();
double tempY = yToScreen(point.getY(), min, max);
if (tempX >= x - 2 && tempX <= x + 2 && tempY >= y - 2 && tempY <= y + 2) {
return point;
}
}
return null;
}
use of blue.components.lines.LinePoint in project blue by kunstmusik.
the class ParameterLineView method insertGraphPoint.
private LinePoint insertGraphPoint(double x, double y) {
if (x < 0 || x > getWidth() || y < 0 || y > getHeight()) {
return null;
}
double min = getSelectedLine().getMin();
double max = getSelectedLine().getMax();
LinePoint point = new LinePoint();
point.setLocation(x / getWidth(), screenToY(y, min, max));
int index = 1;
for (int i = 0; i < getSelectedLine().size() - 1; i++) {
LinePoint p1 = getSelectedLine().getLinePoint(i);
LinePoint p2 = getSelectedLine().getLinePoint(i + 1);
if (point.getX() >= p1.getX() && point.getX() <= p2.getX()) {
index = i + 1;
break;
}
}
getSelectedLine().addLinePoint(index, point);
return point;
}
Aggregations