use of blue.ui.core.score.ScoreTopComponent 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);
}
}
Aggregations