use of blue.ui.core.score.ScorePath in project blue by kunstmusik.
the class MoveScoreObjectsListener method mousePressed.
@Override
public void mousePressed(MouseEvent e) {
if (currentScoreObjectView == null || !SwingUtilities.isLeftMouseButton(e)) {
return;
}
ScoreObject scoreObj = currentScoreObjectView.getScoreObject();
Collection<? extends ScoreObject> temp = ScoreController.getInstance().getSelectedScoreObjects();
if (!temp.contains(scoreObj)) {
return;
}
e.consume();
ScorePath scorePath = ScoreController.getInstance().getScorePath();
startPoint = e.getPoint();
selectedScoreObjects = temp.toArray(new ScoreObject[0]);
startTimes = new double[selectedScoreObjects.length];
startLayerIndices = new int[selectedScoreObjects.length];
currentLayerIndices = new int[selectedScoreObjects.length];
minDiffTime = Double.MAX_VALUE;
startLayer = scorePath.getGlobalLayerIndexForY(e.getY());
lastLayerAdjust = 0;
minYAdjust = Integer.MIN_VALUE;
maxYAdjust = Integer.MAX_VALUE;
initialDrag = true;
List<Layer> allLayers = scorePath.getAllLayers();
for (int i = 0; i < selectedScoreObjects.length; i++) {
startTimes[i] = selectedScoreObjects[i].getStartTime();
if (startTimes[i] < minDiffTime) {
minDiffTime = startTimes[i];
}
startLayerIndices[i] = currentLayerIndices[i] = scorePath.getGlobalLayerIndexForScoreObject(selectedScoreObjects[i]);
int minY = getMinYAdjust(allLayers, scoreObj, startLayerIndices[i]);
int maxY = getMaxYAdjust(allLayers, scoreObj, startLayerIndices[i]);
minYAdjust = (minY > minYAdjust) ? minY : minYAdjust;
maxYAdjust = (maxY < maxYAdjust) ? maxY : maxYAdjust;
}
minDiffTime = -minDiffTime;
}
use of blue.ui.core.score.ScorePath in project blue by kunstmusik.
the class AddMarkerAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
BlueProject project = BlueProjectManager.getInstance().getCurrentProject();
if (project == null) {
return;
}
BlueData data = project.getData();
if (data == null) {
return;
}
RenderTimeManager timeManager = Lookup.getDefault().lookup(RenderTimeManager.class);
ScorePath path = ScoreController.getInstance().getScorePath();
if (path.getLastLayerGroup() == null) {
double markerTime = MainToolBar.getInstance().isRendering() ? timeManager.getRenderTime() + timeManager.getRenderStartTime() : data.getRenderStartTime();
data.getMarkersList().addMarker(markerTime);
}
}
use of blue.ui.core.score.ScorePath in project blue by kunstmusik.
the class DuplicateScoreObjectsAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
// FIXME - this needs to work with ScoreObjects...
Collection<? extends ScoreObject> scoreObjects = ScoreController.getInstance().getSelectedScoreObjects();
if (!scoreObjects.isEmpty()) {
ScorePath path = ScoreController.getInstance().getScorePath();
AddScoreObjectEdit top = null;
for (ScoreObject sObj : scoreObjects) {
ScoreObject clone = sObj.deepCopy();
clone.setStartTime(clone.getStartTime() + clone.getSubjectiveDuration());
ScoreObjectLayer layer = (ScoreObjectLayer) path.getLayerForScoreObject(sObj);
if (layer == null) {
JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), "Could not find Layer for ScoreObject", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
layer.add(clone);
AddScoreObjectEdit edit = new AddScoreObjectEdit(layer, clone);
if (top == null) {
top = edit;
} else {
top.addSubEdit(edit);
}
}
BlueUndoManager.setUndoManager("score");
BlueUndoManager.addEdit(top);
}
}
use of blue.ui.core.score.ScorePath 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.ScorePath in project blue by kunstmusik.
the class MoveScoreObjectsListener method mouseDragged.
@Override
public void mouseDragged(MouseEvent e) {
ScoreController scoreController = ScoreController.getInstance();
ScorePath scorePath = ScoreController.getInstance().getScorePath();
List<Layer> allLayers = scorePath.getAllLayers();
e.consume();
if (initialDrag) {
initialDrag = false;
if ((e.getModifiers() & OS_CTRL_KEY) == OS_CTRL_KEY) {
for (int i = 0; i < selectedScoreObjects.length; i++) {
ScoreObject original = selectedScoreObjects[i];
ScoreObject clone = original.deepCopy();
ScoreObjectLayer layer = (ScoreObjectLayer) allLayers.get(startLayerIndices[i]);
layer.add(clone);
scoreController.removeSelectedScoreObject(original);
scoreController.addSelectedScoreObject(clone);
selectedScoreObjects[i] = clone;
}
}
}
double diffTime = e.getX() - startPoint.x;
TimeState timeState = scoreTC.getTimeState();
diffTime = diffTime / timeState.getPixelSecond();
if (diffTime < minDiffTime) {
diffTime = minDiffTime;
}
if (timeState.isSnapEnabled()) {
double tempStart = -minDiffTime + diffTime;
double snappedStart = ScoreUtilities.getSnapValueMove(tempStart, timeState.getSnapValue());
diffTime = snappedStart + minDiffTime;
}
int newLayerIndex = scorePath.getGlobalLayerIndexForY(e.getY());
int layerAdjust = newLayerIndex - startLayer;
layerAdjust = Math.max(layerAdjust, minYAdjust);
layerAdjust = Math.min(layerAdjust, maxYAdjust);
boolean layerAdjusted = lastLayerAdjust != layerAdjust;
if (layerAdjusted) {
lastLayerAdjust = layerAdjust;
}
for (int i = 0; i < selectedScoreObjects.length; i++) {
selectedScoreObjects[i].setStartTime(startTimes[i] + diffTime);
if (layerAdjusted) {
ScoreObject scoreObj = selectedScoreObjects[i];
int startIndex = startLayerIndices[i];
int curLayerIndex = currentLayerIndices[i];
int newSObjLayerIndex = startIndex + layerAdjust;
allLayers.get(curLayerIndex).remove(scoreObj);
// Re-add moved scoreObject as selected
scoreController.addSelectedScoreObject(scoreObj);
((ScoreObjectLayer) allLayers.get(newSObjLayerIndex)).add(scoreObj);
currentLayerIndices[i] = newSObjLayerIndex;
}
}
}
Aggregations