use of blue.ui.core.score.undo.AddScoreObjectEdit in project blue by kunstmusik.
the class ImportSoundObjectAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
ScoreTimeCanvas sCanvas = (ScoreTimeCanvas) lGroupPanel;
List<File> retVal = FileChooserManager.getDefault().showOpenDialog(IMPORT_DIALOG, WindowManager.getDefault().getMainWindow());
if (!retVal.isEmpty()) {
File f = retVal.get(0);
Document doc;
try {
doc = new Document(f);
Element root = doc.getRoot();
if (root.getName().equals("soundObject")) {
SoundObject tempSobj = (SoundObject) ObjectUtilities.loadFromXML(root, null);
int start = p.x;
Layer layer = scorePath.getGlobalLayerForY(p.y);
if (timeState.isSnapEnabled()) {
int snapPixels = (int) (timeState.getSnapValue() * timeState.getPixelSecond());
start = start - (start % snapPixels);
}
float startTime = (float) start / timeState.getPixelSecond();
tempSobj.setStartTime(startTime);
((SoundLayer) layer).add(tempSobj);
AddScoreObjectEdit edit = new AddScoreObjectEdit((ScoreObjectLayer) layer, tempSobj);
BlueUndoManager.setUndoManager("score");
BlueUndoManager.addEdit(edit);
} else {
JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), "Error: File did not contain Sound Object", "Error", JOptionPane.ERROR_MESSAGE);
}
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), "Error: Could not read Sound Object from file", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
use of blue.ui.core.score.undo.AddScoreObjectEdit 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.undo.AddScoreObjectEdit in project blue by kunstmusik.
the class RepeatScoreObjectsAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
Collection<? extends ScoreObject> scoreObjects = ScoreController.getInstance().getSelectedScoreObjects();
if (!scoreObjects.isEmpty()) {
Object retVal = JOptionPane.showInputDialog(WindowManager.getDefault().getMainWindow(), "Enter number of times to repeat:", new Integer(1));
if (retVal == null) {
return;
}
int count = -1;
try {
count = Integer.parseInt((String) retVal);
} catch (Exception exception) {
JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), "Entry must be an integer value.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (count < 1) {
JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), "Value must be greater than 0.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
ScorePath path = ScoreController.getInstance().getScorePath();
AddScoreObjectEdit top = null;
for (ScoreObject sObj : scoreObjects) {
double start = sObj.getStartTime();
ScoreObjectLayer layer = (ScoreObjectLayer) path.getLayerForScoreObject(sObj);
for (int j = 0; j < count; j++) {
ScoreObject temp = sObj.deepCopy();
start += sObj.getSubjectiveDuration();
temp.setStartTime(start);
if (layer == null) {
JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), "Could not find SoundLayer for SoundObject", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
layer.add(temp);
AddScoreObjectEdit edit = new AddScoreObjectEdit(layer, temp);
if (top == null) {
top = edit;
} else {
top.addSubEdit(edit);
}
}
}
BlueUndoManager.setUndoManager("score");
BlueUndoManager.addEdit(top);
}
}
use of blue.ui.core.score.undo.AddScoreObjectEdit in project blue by kunstmusik.
the class AddSoundObjectActionsPresenter method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
if (pRef == null || sTimeCanvasRef == null) {
return;
}
ScoreTimeCanvas sTimeCanvas = sTimeCanvasRef.get();
Point p = pRef.get();
int sLayerIndex = sTimeCanvas.getPolyObject().getLayerNumForY((int) p.getY());
ScoreTopComponent stc = (ScoreTopComponent) WindowManager.getDefault().findTopComponent("ScoreTopComponent");
LazyPlugin<SoundObject> plugin = (LazyPlugin<SoundObject>) ((JMenuItem) e.getSource()).getClientProperty("plugin");
try {
SoundObject sObj = (SoundObject) plugin.getInstance().getClass().newInstance();
if (sObj instanceof PolyObject) {
((PolyObject) sObj).newLayerAt(0);
}
TimeState timeState = stc.getTimeState();
double start = (double) p.getX() / timeState.getPixelSecond();
if (timeState.isSnapEnabled()) {
start = ScoreUtilities.getSnapValueStart(start, timeState.getSnapValue());
}
sObj.setStartTime(start);
sTimeCanvas.getPolyObject().addSoundObject(sLayerIndex, sObj);
BlueUndoManager.setUndoManager("score");
BlueUndoManager.addEdit(new AddScoreObjectEdit(sTimeCanvas.getPolyObject().get(sLayerIndex), sObj));
} catch (InstantiationException | IllegalAccessException ex) {
Exceptions.printStackTrace(ex);
}
}
use of blue.ui.core.score.undo.AddScoreObjectEdit in project blue by kunstmusik.
the class PasteAsPolyObjectAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
BlueData data = BlueProjectManager.getInstance().getCurrentBlueData();
SoundObjectLibrary sObjLib = data.getSoundObjectLibrary();
List<Instance> instanceSoundObjects = new ArrayList<>();
ScoreController.ScoreObjectBuffer buffer = ScoreController.getInstance().getScoreObjectBuffer();
double start = (double) p.x / timeState.getPixelSecond();
if (timeState.isSnapEnabled()) {
start = ScoreUtilities.getSnapValueStart(start, timeState.getSnapValue());
}
int minLayer = Integer.MAX_VALUE;
int maxLayer = Integer.MIN_VALUE;
for (Integer layerIndex : layerIndexes) {
if (layerIndex < minLayer) {
minLayer = layerIndex;
}
if (layerIndex > maxLayer) {
maxLayer = layerIndex;
}
}
int numLayers = maxLayer - minLayer + 1;
for (int i = 0; i < numLayers; i++) {
pObj.newLayerAt(-1);
}
for (int i = 0; i < scoreObjects.size(); i++) {
ScoreObject scoreObj = scoreObjects.get(i);
int layerIndex = layerIndexes.get(i);
SoundLayer layer = pObj.get(layerIndex - minLayer);
SoundObject clone = (SoundObject) scoreObj.deepCopy();
layer.add(clone);
if (clone instanceof Instance) {
instanceSoundObjects.add((Instance) clone);
}
}
sObjLib.checkAndAddInstanceSoundObjects(instanceSoundObjects);
pObj.normalizeSoundObjects();
pObj.setStartTime(start);
final ScoreObjectLayer layer = (ScoreObjectLayer) scorePath.getGlobalLayerForY(p.y);
layer.add(pObj);
AddScoreObjectEdit edit = new AddScoreObjectEdit(layer, pObj);
BlueUndoManager.setUndoManager("score");
BlueUndoManager.addEdit(edit);
}
Aggregations