Search in sources :

Example 11 with LinePoint

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

Example 12 with LinePoint

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);
}
Also used : DoubleStringConverter(javafx.util.converter.DoubleStringConverter) NumberUtilities(blue.utility.NumberUtilities) ButtonType(javafx.scene.control.ButtonType) LineList(blue.components.lines.LineList) Glow(javafx.scene.effect.Glow) MouseEvent(javafx.scene.input.MouseEvent) DoubleProperty(javafx.beans.property.DoubleProperty) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) TableModelListener(javax.swing.event.TableModelListener) LinePoint(blue.components.lines.LinePoint) TableColumn(javafx.scene.control.TableColumn) DragDirection(blue.components.DragDirection) Utils(org.controlsfx.tools.Utils) BlueFX(blue.jfx.BlueFX) ScrollPane(javafx.scene.control.ScrollPane) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) ContextMenu(javafx.scene.control.ContextMenu) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) Color(javafx.scene.paint.Color) ObjectProperty(javafx.beans.property.ObjectProperty) Modality(javafx.stage.Modality) Dialog(javafx.scene.control.Dialog) MenuItem(javafx.scene.control.MenuItem) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) GraphicsContext(javafx.scene.canvas.GraphicsContext) Canvas(javafx.scene.canvas.Canvas) Line(blue.components.lines.Line) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Optional(java.util.Optional) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) DoubleStringConverter(javafx.util.converter.DoubleStringConverter) ObservableValue(javafx.beans.value.ObservableValue) TableColumn(javafx.scene.control.TableColumn) LinePoint(blue.components.lines.LinePoint) LinePoint(blue.components.lines.LinePoint) Dialog(javafx.scene.control.Dialog) ScrollPane(javafx.scene.control.ScrollPane) TableModelListener(javax.swing.event.TableModelListener) ButtonType(javafx.scene.control.ButtonType) TableView(javafx.scene.control.TableView)

Example 13 with LinePoint

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

Example 14 with LinePoint

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

Example 15 with LinePoint

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