Search in sources :

Example 1 with AddScoreObjectEdit

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);
        }
    }
}
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 AddScoreObjectEdit

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);
    }
}
Also used : ScorePath(blue.ui.core.score.ScorePath) ScoreObjectLayer(blue.score.layers.ScoreObjectLayer) AddScoreObjectEdit(blue.ui.core.score.undo.AddScoreObjectEdit) ScoreObject(blue.score.ScoreObject)

Example 3 with AddScoreObjectEdit

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);
    }
}
Also used : ScorePath(blue.ui.core.score.ScorePath) ScoreObjectLayer(blue.score.layers.ScoreObjectLayer) AddScoreObjectEdit(blue.ui.core.score.undo.AddScoreObjectEdit) ScoreObject(blue.score.ScoreObject) ScoreObject(blue.score.ScoreObject)

Example 4 with AddScoreObjectEdit

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

Example 5 with AddScoreObjectEdit

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);
}
Also used : BlueData(blue.BlueData) Instance(blue.soundObject.Instance) ArrayList(java.util.ArrayList) ScoreObject(blue.score.ScoreObject) SoundObjectLibrary(blue.SoundObjectLibrary) Point(java.awt.Point) ScoreController(blue.ui.core.score.ScoreController) ScoreObjectLayer(blue.score.layers.ScoreObjectLayer) SoundObject(blue.soundObject.SoundObject) AddScoreObjectEdit(blue.ui.core.score.undo.AddScoreObjectEdit) SoundLayer(blue.SoundLayer)

Aggregations

AddScoreObjectEdit (blue.ui.core.score.undo.AddScoreObjectEdit)7 ScoreObject (blue.score.ScoreObject)5 ScoreObjectLayer (blue.score.layers.ScoreObjectLayer)5 SoundLayer (blue.SoundLayer)4 Point (java.awt.Point)4 BlueData (blue.BlueData)3 Layer (blue.score.layers.Layer)3 SoundObject (blue.soundObject.SoundObject)3 SoundObjectLibrary (blue.SoundObjectLibrary)2 Instance (blue.soundObject.Instance)2 PolyObject (blue.soundObject.PolyObject)2 ScoreController (blue.ui.core.score.ScoreController)2 ScorePath (blue.ui.core.score.ScorePath)2 ScoreTimeCanvas (blue.ui.core.score.layers.soundObject.ScoreTimeCanvas)2 ArrayList (java.util.ArrayList)2 Parameter (blue.automation.Parameter)1 LinePoint (blue.components.lines.LinePoint)1 BlueSynthBuilder (blue.orchestra.BlueSynthBuilder)1 TimeState (blue.score.TimeState)1 Sound (blue.soundObject.Sound)1