Search in sources :

Example 1 with BSBObject

use of blue.orchestra.blueSynthBuilder.BSBObject in project blue by kunstmusik.

the class SubChannelListPanel method reconcileNameChangeInBlueArrangement.

/**
 * A hack to explicitly walk the current blue orchestra to find any
 * BlueSynthBuilder's that contain BSBSubChannelDropdown's and to reconcile
 * the name change.
 *
 * @param oldName
 * @param newName
 */
private void reconcileNameChangeInBlueArrangement(String oldName, String newName) {
    BlueData data = BlueProjectManager.getInstance().getCurrentBlueData();
    if (data == null) {
        return;
    }
    Arrangement arr = data.getArrangement();
    for (int i = 0; i < arr.size(); i++) {
        Instrument instr = arr.getInstrument(i);
        if (instr instanceof BlueSynthBuilder) {
            BlueSynthBuilder bsb = (BlueSynthBuilder) instr;
            BSBGraphicInterface bsbInterface = bsb.getGraphicInterface();
            for (BSBObject bsbObj : bsbInterface.getAllSet()) {
                if (bsbObj instanceof BSBSubChannelDropdown) {
                    BSBSubChannelDropdown bsbSubDrop = (BSBSubChannelDropdown) bsbObj;
                    if (bsbSubDrop.getChannelOutput().equals(oldName)) {
                        bsbSubDrop.setChannelOutput(newName);
                    }
                }
            }
        }
    }
}
Also used : BlueData(blue.BlueData) BSBGraphicInterface(blue.orchestra.blueSynthBuilder.BSBGraphicInterface) BSBObject(blue.orchestra.blueSynthBuilder.BSBObject) BSBSubChannelDropdown(blue.orchestra.blueSynthBuilder.BSBSubChannelDropdown) Instrument(blue.orchestra.Instrument) BlueSynthBuilder(blue.orchestra.BlueSynthBuilder) Arrangement(blue.Arrangement)

Example 2 with BSBObject

use of blue.orchestra.blueSynthBuilder.BSBObject in project blue by kunstmusik.

the class BSBObjectViewHolder method getContextMenu.

private static ContextMenu getContextMenu() {
    if (MENU == null) {
        MENU = new ContextMenu();
        MenuItem cut = new MenuItem("Cut");
        cut.setOnAction(e -> {
            MenuData data = (MenuData) MENU.getUserData();
            BSBEditSelection selection = data.selection;
            selection.cut();
        });
        MenuItem copy = new MenuItem("Copy");
        copy.setOnAction(e -> {
            MenuData data = (MenuData) MENU.getUserData();
            BSBEditSelection selection = data.selection;
            selection.copy();
        });
        MenuItem remove = new MenuItem("Remove");
        remove.setOnAction(e -> {
            MenuData data = (MenuData) MENU.getUserData();
            BSBEditSelection selection = data.selection;
            selection.remove();
        });
        MenuItem makeGroup = new MenuItem("Make Group");
        makeGroup.setOnAction(e -> {
            MenuData data = (MenuData) MENU.getUserData();
            BSBEditSelection selection = data.selection;
            List<BSBGroup> groupsList = data.groupsList;
            List<BSBObject> bsbObjs = selection.selection.stream().map(b -> b.deepCopy()).collect(Collectors.toList());
            int x = Integer.MAX_VALUE;
            int y = Integer.MAX_VALUE;
            for (BSBObject bsbObj : bsbObjs) {
                x = Math.min(x, bsbObj.getX());
                y = Math.min(y, bsbObj.getY());
            }
            for (BSBObject bsbObj : bsbObjs) {
                bsbObj.setX(bsbObj.getX() - x + 10);
                bsbObj.setY(bsbObj.getY() - y + 10);
            }
            selection.remove();
            BSBGroup group = new BSBGroup();
            group.interfaceItemsProperty().addAll(bsbObjs);
            group.setX(x);
            group.setY(y);
            groupsList.get(groupsList.size() - 1).addBSBObject(group);
        });
        MenuItem breakGroup = new MenuItem("Break Group");
        breakGroup.setOnAction((ActionEvent e) -> {
            MenuData data = (MenuData) MENU.getUserData();
            BSBEditSelection selection = data.selection;
            List<BSBGroup> groupsList = data.groupsList;
            BSBGroup group = (BSBGroup) selection.selection.toArray()[0];
            int x = group.getX();
            int y = group.getY();
            selection.remove();
            BSBGroup rootGroup = groupsList.get(groupsList.size() - 1);
            for (BSBObject bsbObj : group) {
                BSBObject temp = bsbObj.deepCopy();
                temp.setX(temp.getX() + x);
                temp.setY(temp.getY() + y);
                rootGroup.addBSBObject(temp);
            }
            ;
        });
        final Menu align = new Menu("Align");
        final Menu distribute = new Menu("Distribute");
        EventHandler<ActionEvent> alignListener = ae -> {
            MenuItem source = (MenuItem) ae.getSource();
            Alignment alignment = (Alignment) source.getUserData();
            MenuData data = (MenuData) MENU.getUserData();
            BSBEditSelection selection = data.selection;
            AlignmentUtils.align(selection.getSelectedNodes(), alignment);
        };
        EventHandler<ActionEvent> distributeListener = ae -> {
            MenuItem source = (MenuItem) ae.getSource();
            Alignment alignment = (Alignment) source.getUserData();
            MenuData data = (MenuData) MENU.getUserData();
            BSBEditSelection selection = data.selection;
            AlignmentUtils.distribute(selection.getSelectedNodes(), alignment);
        };
        for (Alignment alignment : Alignment.values()) {
            MenuItem a = new MenuItem(alignment.toString());
            a.setUserData(alignment);
            a.setOnAction(alignListener);
            MenuItem d = new MenuItem(alignment.toString());
            d.setUserData(alignment);
            d.setOnAction(distributeListener);
            align.getItems().add(a);
            distribute.getItems().add(d);
        }
        MENU.getItems().addAll(cut, copy, remove);
        MENU.getItems().addAll(new SeparatorMenuItem(), makeGroup, breakGroup);
        MENU.getItems().addAll(new SeparatorMenuItem(), align, distribute);
        MENU.setOnHidden(e -> MENU.setUserData(null));
        MENU.setOnShowing(e -> {
            MenuData data = (MenuData) MENU.getUserData();
            BSBEditSelection selection = data.selection;
            align.setDisable(selection.selection.size() < 2);
            distribute.setDisable(selection.selection.size() < 2);
            breakGroup.setDisable(selection.selection.size() != 1 || selection.selection.stream().noneMatch((x) -> x instanceof BSBGroup));
        });
    }
    return MENU;
}
Also used : EventHandler(javafx.event.EventHandler) Scene(javafx.scene.Scene) BooleanBinding(javafx.beans.binding.BooleanBinding) BoundingBox(javafx.geometry.BoundingBox) MouseEvent(javafx.scene.input.MouseEvent) Bindings(javafx.beans.binding.Bindings) BSBGroup(blue.orchestra.blueSynthBuilder.BSBGroup) ContextMenu(javafx.scene.control.ContextMenu) Point2D(javafx.geometry.Point2D) BSBObject(blue.orchestra.blueSynthBuilder.BSBObject) Pane(javafx.scene.layout.Pane) Color(javafx.scene.paint.Color) MenuItem(javafx.scene.control.MenuItem) GridSettings(blue.orchestra.blueSynthBuilder.GridSettings) Rectangle(javafx.scene.shape.Rectangle) Collectors(java.util.stream.Collectors) Menu(javafx.scene.control.Menu) Cursor(javafx.scene.Cursor) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) ActionEvent(javafx.event.ActionEvent) Region(javafx.scene.layout.Region) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) ChangeListener(javafx.beans.value.ChangeListener) ActionEvent(javafx.event.ActionEvent) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) BSBObject(blue.orchestra.blueSynthBuilder.BSBObject) ContextMenu(javafx.scene.control.ContextMenu) Menu(javafx.scene.control.Menu) BSBGroup(blue.orchestra.blueSynthBuilder.BSBGroup)

Example 3 with BSBObject

use of blue.orchestra.blueSynthBuilder.BSBObject in project blue by kunstmusik.

the class BSBEditPane method paste.

protected void paste(int x, int y) {
    int minX = Integer.MAX_VALUE;
    int minY = Integer.MAX_VALUE;
    GridSettings gridSettings = bsbInterface.getGridSettings();
    if (gridSettings.isSnapEnabled()) {
        x = x - (x % gridSettings.getWidth());
        y = y - (y % gridSettings.getHeight());
    }
    for (BSBObject bsbObj : selection.copyBufferProperty()) {
        minX = Math.min(minX, bsbObj.getX());
        minY = Math.min(minY, bsbObj.getY());
    }
    selection.selection.clear();
    for (BSBObject bsbObj : selection.copyBufferProperty()) {
        BSBObject copy = bsbObj.deepCopy();
        copy.setX(x + copy.getX() - minX);
        copy.setY(y + copy.getY() - minY);
        currentBSBGroup.addBSBObject(copy);
        selection.selection.add(copy);
    }
}
Also used : BSBObject(blue.orchestra.blueSynthBuilder.BSBObject) GridSettings(blue.orchestra.blueSynthBuilder.GridSettings)

Example 4 with BSBObject

use of blue.orchestra.blueSynthBuilder.BSBObject in project blue by kunstmusik.

the class BSBEditSelection method initiateMove.

public void initiateMove(BSBObject sourceDragObject) {
    startPositions.clear();
    minX = Double.MAX_VALUE;
    minY = Double.MAX_VALUE;
    for (BSBObject bsbObj : selection) {
        double x = bsbObj.getX();
        double y = bsbObj.getY();
        startPositions.put(bsbObj, new Point(x, y));
        minX = Math.min(minX, x);
        minY = Math.min(minY, y);
    }
    if (gridSettings != null && gridSettings.isSnapEnabled()) {
        gridOffsetX = sourceDragObject.getX() % gridSettings.getWidth();
        gridOffsetY = sourceDragObject.getY() % gridSettings.getHeight();
    } else {
        gridOffsetX = gridOffsetY = 0;
    }
    processingMove = true;
}
Also used : BSBObject(blue.orchestra.blueSynthBuilder.BSBObject)

Example 5 with BSBObject

use of blue.orchestra.blueSynthBuilder.BSBObject in project blue by kunstmusik.

the class BSBEditPane method pasteShortcut.

private void pasteShortcut() {
    int minX = Integer.MAX_VALUE;
    int minY = Integer.MAX_VALUE;
    for (BSBObject bsbObj : selection.copyBufferProperty()) {
        minX = Math.min(minX, bsbObj.getX());
        minY = Math.min(minY, bsbObj.getY());
    }
    int x = minX;
    int y = minY;
    GridSettings gridSettings = bsbInterface.getGridSettings();
    if (gridSettings.isSnapEnabled()) {
        x += gridSettings.getWidth();
        y += gridSettings.getHeight();
    } else {
        x += 10;
        y += 10;
    }
    selection.selection.clear();
    for (BSBObject bsbObj : selection.copyBufferProperty()) {
        BSBObject copy = bsbObj.deepCopy();
        copy.setX(x + copy.getX() - minX);
        copy.setY(y + copy.getY() - minY);
        currentBSBGroup.addBSBObject(copy);
        selection.selection.add(copy);
    }
}
Also used : BSBObject(blue.orchestra.blueSynthBuilder.BSBObject) GridSettings(blue.orchestra.blueSynthBuilder.GridSettings)

Aggregations

BSBObject (blue.orchestra.blueSynthBuilder.BSBObject)13 GridSettings (blue.orchestra.blueSynthBuilder.GridSettings)4 Pane (javafx.scene.layout.Pane)4 BSBGraphicInterface (blue.orchestra.blueSynthBuilder.BSBGraphicInterface)3 Rectangle (javafx.scene.shape.Rectangle)3 Arrangement (blue.Arrangement)2 BlueData (blue.BlueData)2 BlueSynthBuilder (blue.orchestra.BlueSynthBuilder)2 Instrument (blue.orchestra.Instrument)2 BSBGroup (blue.orchestra.blueSynthBuilder.BSBGroup)2 BSBSubChannelDropdown (blue.orchestra.blueSynthBuilder.BSBSubChannelDropdown)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Bindings (javafx.beans.binding.Bindings)2 BooleanProperty (javafx.beans.property.BooleanProperty)2 ChangeListener (javafx.beans.value.ChangeListener)2 ObservableList (javafx.collections.ObservableList)2 ActionEvent (javafx.event.ActionEvent)2 EventHandler (javafx.event.EventHandler)2 BoundingBox (javafx.geometry.BoundingBox)2