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