Search in sources :

Example 1 with MoveScoreObjectsEdit

use of blue.ui.core.score.undo.MoveScoreObjectsEdit in project blue by kunstmusik.

the class NudgeDownAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    Collection<? extends ScoreObject> selected = ScoreController.getInstance().getSelectedScoreObjects();
    if (!selected.isEmpty()) {
        ScorePath path = ScoreController.getInstance().getScorePath();
        ScoreObject[] scoreObjects = selected.<ScoreObject>toArray(new ScoreObject[selected.size()]);
        List<Layer> layers = path.getAllLayers();
        int[] indexes = new int[selected.size()];
        int lastIndex = layers.size() - 1;
        for (int i = 0; i < scoreObjects.length; i++) {
            int index = path.getGlobalLayerIndexForScoreObject(scoreObjects[i]);
            if (index >= lastIndex) {
                return;
            }
            Layer layer = layers.get(index + 1);
            if (!layer.accepts(scoreObjects[i])) {
                return;
            }
            indexes[i] = index;
        }
        int len = scoreObjects.length;
        ScoreObjectLayer[] startLayers = new ScoreObjectLayer[len];
        ScoreObjectLayer[] endLayers = new ScoreObjectLayer[len];
        for (int i = 0; i < scoreObjects.length; i++) {
            startLayers[i] = (ScoreObjectLayer) layers.get(indexes[i]);
            endLayers[i] = (ScoreObjectLayer) layers.get(indexes[i] + 1);
            startLayers[i].remove(scoreObjects[i]);
            endLayers[i].add(scoreObjects[i]);
        }
        MoveScoreObjectsEdit edit = new MoveScoreObjectsEdit(scoreObjects, startLayers, endLayers, null, null);
        BlueUndoManager.setUndoManager("score");
        BlueUndoManager.addEdit(edit);
    }
}
Also used : MoveScoreObjectsEdit(blue.ui.core.score.undo.MoveScoreObjectsEdit) ScorePath(blue.ui.core.score.ScorePath) ScoreObjectLayer(blue.score.layers.ScoreObjectLayer) ScoreObject(blue.score.ScoreObject) Layer(blue.score.layers.Layer) ScoreObjectLayer(blue.score.layers.ScoreObjectLayer)

Example 2 with MoveScoreObjectsEdit

use of blue.ui.core.score.undo.MoveScoreObjectsEdit in project blue by kunstmusik.

the class MoveScoreObjectsListener method mouseReleased.

@Override
public void mouseReleased(MouseEvent e) {
    e.consume();
    if (!initialDrag) {
        List<Layer> allLayers = ScoreController.getInstance().getScorePath().getAllLayers();
        int len = startTimes.length;
        double[] endTimes = new double[len];
        ScoreObjectLayer[] startLayers = new ScoreObjectLayer[len];
        ScoreObjectLayer[] endLayers = new ScoreObjectLayer[len];
        for (int i = 0; i < selectedScoreObjects.length; i++) {
            endTimes[i] = selectedScoreObjects[i].getStartTime();
            startLayers[i] = (ScoreObjectLayer) allLayers.get(startLayerIndices[i]);
            endLayers[i] = (ScoreObjectLayer) allLayers.get(currentLayerIndices[i]);
        }
        MoveScoreObjectsEdit edit = new MoveScoreObjectsEdit(selectedScoreObjects, startLayers, endLayers, startTimes, endTimes);
        BlueUndoManager.setUndoManager("score");
        BlueUndoManager.addEdit(edit);
    }
    selectedScoreObjects = null;
    startTimes = null;
    startLayerIndices = null;
    currentLayerIndices = null;
}
Also used : MoveScoreObjectsEdit(blue.ui.core.score.undo.MoveScoreObjectsEdit) ScoreObjectLayer(blue.score.layers.ScoreObjectLayer) Layer(blue.score.layers.Layer) ScoreObjectLayer(blue.score.layers.ScoreObjectLayer) Point(java.awt.Point)

Example 3 with MoveScoreObjectsEdit

use of blue.ui.core.score.undo.MoveScoreObjectsEdit in project blue by kunstmusik.

the class NudgeUpAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    Collection<? extends ScoreObject> selected = ScoreController.getInstance().getSelectedScoreObjects();
    if (!selected.isEmpty()) {
        ScorePath path = ScoreController.getInstance().getScorePath();
        ScoreObject[] scoreObjects = selected.<ScoreObject>toArray(new ScoreObject[selected.size()]);
        List<Layer> layers = path.getAllLayers();
        int[] indexes = new int[selected.size()];
        for (int i = 0; i < scoreObjects.length; i++) {
            int index = path.getGlobalLayerIndexForScoreObject(scoreObjects[i]);
            if (index < 1) {
                return;
            }
            Layer layer = layers.get(index - 1);
            if (!layer.accepts(scoreObjects[i])) {
                return;
            }
            indexes[i] = index;
        }
        int len = scoreObjects.length;
        ScoreObjectLayer[] startLayers = new ScoreObjectLayer[len];
        ScoreObjectLayer[] endLayers = new ScoreObjectLayer[len];
        for (int i = 0; i < scoreObjects.length; i++) {
            startLayers[i] = (ScoreObjectLayer) layers.get(indexes[i]);
            endLayers[i] = (ScoreObjectLayer) layers.get(indexes[i] - 1);
            startLayers[i].remove(scoreObjects[i]);
            endLayers[i].add(scoreObjects[i]);
        }
        MoveScoreObjectsEdit edit = new MoveScoreObjectsEdit(scoreObjects, startLayers, endLayers, null, null);
        BlueUndoManager.setUndoManager("score");
        BlueUndoManager.addEdit(edit);
    }
}
Also used : MoveScoreObjectsEdit(blue.ui.core.score.undo.MoveScoreObjectsEdit) ScorePath(blue.ui.core.score.ScorePath) ScoreObjectLayer(blue.score.layers.ScoreObjectLayer) ScoreObject(blue.score.ScoreObject) Layer(blue.score.layers.Layer) ScoreObjectLayer(blue.score.layers.ScoreObjectLayer)

Example 4 with MoveScoreObjectsEdit

use of blue.ui.core.score.undo.MoveScoreObjectsEdit in project blue by kunstmusik.

the class NudgeUtils method nudgeHorizontal.

// TODO - Respect snap values, Make Undoable
public static void nudgeHorizontal(double timeValue, Collection<? extends ScoreObject> scoreObjects) {
    if (scoreObjects == null || scoreObjects.size() == 0) {
        return;
    }
    double adjustedTime = timeValue;
    if (timeValue < 0.0f) {
        for (ScoreObject scoreObj : scoreObjects) {
            double start = scoreObj.getStartTime();
            if (start == 0.0) {
                return;
            }
            if (adjustedTime < -start) {
                adjustedTime = -start;
            }
        }
    }
    // FIXME - handle for translating automations
    // mBuffer.motionBufferObjects();
    // setSelectionDragRegions();
    int len = scoreObjects.size();
    ScoreObject[] objects = scoreObjects.<ScoreObject>toArray(new ScoreObject[scoreObjects.size()]);
    double[] startTimes = new double[len];
    double[] endTimes = new double[len];
    for (int i = 0; i < objects.length; i++) {
        ScoreObject scoreObj = objects[i];
        startTimes[i] = scoreObj.getStartTime();
        endTimes[i] = scoreObj.getStartTime() + adjustedTime;
        scoreObj.setStartTime(endTimes[i]);
    }
    MoveScoreObjectsEdit edit = new MoveScoreObjectsEdit(objects, null, null, startTimes, endTimes);
    BlueUndoManager.setUndoManager("score");
    BlueUndoManager.addEdit(edit);
// automationPanel.setMultiLineTranslation(timeValue);
// automationPanel.commitMultiLineDrag();
}
Also used : MoveScoreObjectsEdit(blue.ui.core.score.undo.MoveScoreObjectsEdit) ScoreObject(blue.score.ScoreObject)

Example 5 with MoveScoreObjectsEdit

use of blue.ui.core.score.undo.MoveScoreObjectsEdit in project blue by kunstmusik.

the class ReverseAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (scoreObjects.size() < 2) {
        return;
    }
    double start = Double.MAX_VALUE;
    double end = Double.MIN_VALUE;
    for (ScoreObject scoreObject : scoreObjects) {
        double tempStart = scoreObject.getStartTime();
        double tempEnd = tempStart + scoreObject.getSubjectiveDuration();
        if (tempStart < start) {
            start = tempStart;
        }
        if (tempEnd > end) {
            end = tempEnd;
        }
    }
    int len = scoreObjects.size();
    ScoreObject[] objects = scoreObjects.<ScoreObject>toArray(new ScoreObject[scoreObjects.size()]);
    double[] startTimes = new double[len];
    double[] endTimes = new double[len];
    for (int i = 0; i < len; i++) {
        ScoreObject scoreObj = objects[i];
        double tempStart = scoreObj.getStartTime();
        double tempEnd = tempStart + scoreObj.getSubjectiveDuration();
        double newStart = start + (end - tempEnd);
        scoreObj.setStartTime(newStart);
        startTimes[i] = tempStart;
        endTimes[i] = newStart;
    }
    BlueUndoManager.setUndoManager("score");
    MoveScoreObjectsEdit edit = new MoveScoreObjectsEdit(objects, null, null, startTimes, endTimes);
    BlueUndoManager.setUndoManager("score");
    BlueUndoManager.addEdit(edit);
}
Also used : MoveScoreObjectsEdit(blue.ui.core.score.undo.MoveScoreObjectsEdit) ScoreObject(blue.score.ScoreObject)

Aggregations

MoveScoreObjectsEdit (blue.ui.core.score.undo.MoveScoreObjectsEdit)5 ScoreObject (blue.score.ScoreObject)4 Layer (blue.score.layers.Layer)3 ScoreObjectLayer (blue.score.layers.ScoreObjectLayer)3 ScorePath (blue.ui.core.score.ScorePath)2 Point (java.awt.Point)1