Search in sources :

Example 1 with ScoreTimeCanvas

use of blue.ui.core.score.layers.soundObject.ScoreTimeCanvas 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);
        }
    }
}
Also used : SoundObject(blue.soundObject.SoundObject) AddScoreObjectEdit(blue.ui.core.score.undo.AddScoreObjectEdit) SoundLayer(blue.SoundLayer) Element(electric.xml.Element) ScoreTimeCanvas(blue.ui.core.score.layers.soundObject.ScoreTimeCanvas) Document(electric.xml.Document) File(java.io.File) SoundLayer(blue.SoundLayer) ScoreObjectLayer(blue.score.layers.ScoreObjectLayer) Layer(blue.score.layers.Layer) Point(java.awt.Point)

Example 2 with ScoreTimeCanvas

use of blue.ui.core.score.layers.soundObject.ScoreTimeCanvas 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);
    }
}
Also used : Point(java.awt.Point) Point(java.awt.Point) LazyPlugin(blue.ui.nbutilities.lazyplugin.LazyPlugin) ScoreTopComponent(blue.ui.core.score.ScoreTopComponent) SoundObject(blue.soundObject.SoundObject) AddScoreObjectEdit(blue.ui.core.score.undo.AddScoreObjectEdit) ScoreTimeCanvas(blue.ui.core.score.layers.soundObject.ScoreTimeCanvas) TimeState(blue.score.TimeState) PolyObject(blue.soundObject.PolyObject)

Aggregations

SoundObject (blue.soundObject.SoundObject)2 ScoreTimeCanvas (blue.ui.core.score.layers.soundObject.ScoreTimeCanvas)2 AddScoreObjectEdit (blue.ui.core.score.undo.AddScoreObjectEdit)2 Point (java.awt.Point)2 SoundLayer (blue.SoundLayer)1 TimeState (blue.score.TimeState)1 Layer (blue.score.layers.Layer)1 ScoreObjectLayer (blue.score.layers.ScoreObjectLayer)1 PolyObject (blue.soundObject.PolyObject)1 ScoreTopComponent (blue.ui.core.score.ScoreTopComponent)1 LazyPlugin (blue.ui.nbutilities.lazyplugin.LazyPlugin)1 Document (electric.xml.Document)1 Element (electric.xml.Element)1 File (java.io.File)1