Search in sources :

Example 11 with Instance

use of blue.soundObject.Instance in project blue by kunstmusik.

the class PasteSoundObjectAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    double start = (double) p.x / timeState.getPixelSecond();
    if (timeState.isSnapEnabled()) {
        start = ScoreUtilities.getSnapValueStart(start, timeState.getSnapValue());
    }
    ScoreController.ScoreObjectBuffer buffer = ScoreController.getInstance().getScoreObjectBuffer();
    List<Layer> allLayers = scorePath.getAllLayers();
    int selectedLayerIndex = scorePath.getGlobalLayerIndexForY(p.y);
    int minLayer = Integer.MAX_VALUE;
    int maxLayer = Integer.MIN_VALUE;
    double bufferStart = Double.POSITIVE_INFINITY;
    for (int i = 0; i < buffer.scoreObjects.size(); i++) {
        ScoreObject scoreObj = buffer.scoreObjects.get(i);
        int layer = buffer.layerIndexes.get(i);
        if (scoreObj.getStartTime() < bufferStart) {
            bufferStart = scoreObj.getStartTime();
        }
        if (layer < minLayer) {
            minLayer = layer;
        }
        if (layer > maxLayer) {
            maxLayer = layer;
        }
    }
    int layerTranslation = selectedLayerIndex - minLayer;
    double startTranslation = start - bufferStart;
    if ((maxLayer + layerTranslation) >= allLayers.size()) {
        JOptionPane.showMessageDialog(null, "Not Enough Layers to Paste");
        return;
    }
    for (int i = 0; i < buffer.scoreObjects.size(); i++) {
        ScoreObject scoreObj = buffer.scoreObjects.get(i);
        int index = buffer.layerIndexes.get(i);
        Layer layer = allLayers.get(index + layerTranslation);
        if (!layer.accepts(scoreObj)) {
            JOptionPane.showMessageDialog(null, "Unable to paste due to target layers not " + "accepting types of objects within the copy buffer (i.e. trying to " + "paste a SoundObject into an AudioLayer");
            return;
        }
    }
    BlueData data = BlueProjectManager.getInstance().getCurrentBlueData();
    SoundObjectLibrary sObjLib = data.getSoundObjectLibrary();
    AddScoreObjectEdit undoEdit = null;
    // FIXME - Need a generic way to handle shadow objects; perhaps need to
    // deal with this in the model...
    List<Instance> instanceSoundObjects = new ArrayList<>();
    for (int i = 0; i < buffer.scoreObjects.size(); i++) {
        ScoreObject sObj = buffer.scoreObjects.get(i).deepCopy();
        int newLayerIndex = buffer.layerIndexes.get(i) + layerTranslation;
        if (sObj instanceof Instance) {
            instanceSoundObjects.add((Instance) sObj);
        } else if (sObj instanceof PolyObject) {
            PolyObject pObj = (PolyObject) sObj;
            getInstancesFromPolyObject(instanceSoundObjects, pObj);
        }
        sObj.setStartTime(sObj.getStartTime() + startTranslation);
        ScoreObjectLayer<ScoreObject> layer = (ScoreObjectLayer<ScoreObject>) allLayers.get(newLayerIndex);
        layer.add(sObj);
        AddScoreObjectEdit tempEdit = new AddScoreObjectEdit(layer, sObj);
        if (undoEdit == null) {
            undoEdit = tempEdit;
        } else {
            undoEdit.addSubEdit(tempEdit);
        }
    }
    checkAndAddInstanceSoundObjects(sObjLib, instanceSoundObjects);
    BlueUndoManager.setUndoManager("score");
    BlueUndoManager.addEdit(undoEdit);
}
Also used : BlueData(blue.BlueData) Instance(blue.soundObject.Instance) ScoreObject(blue.score.ScoreObject) ArrayList(java.util.ArrayList) SoundObjectLibrary(blue.SoundObjectLibrary) SoundLayer(blue.SoundLayer) ScoreObjectLayer(blue.score.layers.ScoreObjectLayer) Layer(blue.score.layers.Layer) Point(java.awt.Point) ScoreController(blue.ui.core.score.ScoreController) ScoreObjectLayer(blue.score.layers.ScoreObjectLayer) AddScoreObjectEdit(blue.ui.core.score.undo.AddScoreObjectEdit) PolyObject(blue.soundObject.PolyObject)

Example 12 with Instance

use of blue.soundObject.Instance in project blue by kunstmusik.

the class PasteSoundObjectAction method getInstancesFromPolyObject.

private void getInstancesFromPolyObject(List<Instance> instanceSoundObjects, PolyObject pObj) {
    for (SoundLayer layer : pObj) {
        for (SoundObject sObj : layer) {
            if (sObj instanceof Instance) {
                Instance instance = (Instance) sObj;
                instanceSoundObjects.add(instance);
            } else if (sObj instanceof PolyObject) {
                getInstancesFromPolyObject(instanceSoundObjects, (PolyObject) sObj);
            }
        }
    }
}
Also used : SoundObject(blue.soundObject.SoundObject) Instance(blue.soundObject.Instance) SoundLayer(blue.SoundLayer) PolyObject(blue.soundObject.PolyObject)

Example 13 with Instance

use of blue.soundObject.Instance in project blue by kunstmusik.

the class SoundObjectLibraryUtils method removeSoundObjectInstances.

protected static void removeSoundObjectInstances(PolyObject polyObject, SoundObject sObj) {
    for (int i = 0; i < polyObject.size(); i++) {
        SoundLayer layer = polyObject.get(i);
        ArrayList<SoundObject> instances = new ArrayList<>();
        for (SoundObject tempObject : layer) {
            if (tempObject instanceof Instance) {
                Instance instance = (Instance) tempObject;
                if (instance.getSoundObject() == sObj) {
                    instances.add(instance);
                }
            } else if (tempObject instanceof PolyObject) {
                removeSoundObjectInstances((PolyObject) tempObject, sObj);
            }
        }
        for (SoundObject tempObject : instances) {
            layer.remove(tempObject);
        }
    }
}
Also used : SoundObject(blue.soundObject.SoundObject) Instance(blue.soundObject.Instance) SoundLayer(blue.SoundLayer) ArrayList(java.util.ArrayList) PolyObject(blue.soundObject.PolyObject)

Aggregations

Instance (blue.soundObject.Instance)13 SoundObject (blue.soundObject.SoundObject)11 SoundLayer (blue.SoundLayer)8 BlueData (blue.BlueData)6 PolyObject (blue.soundObject.PolyObject)6 SoundObjectLibrary (blue.SoundObjectLibrary)4 ScoreObject (blue.score.ScoreObject)4 ArrayList (java.util.ArrayList)4 ScoreObjectLayer (blue.score.layers.ScoreObjectLayer)3 ScoreController (blue.ui.core.score.ScoreController)3 Point (java.awt.Point)3 Layer (blue.score.layers.Layer)2 AddScoreObjectEdit (blue.ui.core.score.undo.AddScoreObjectEdit)2 HashMap (java.util.HashMap)2 Score (blue.score.Score)1 GenericScore (blue.soundObject.GenericScore)1 ScoreObjectEditor (blue.soundObject.editor.ScoreObjectEditor)1 ReplaceScoreObjectEdit (blue.ui.core.score.undo.ReplaceScoreObjectEdit)1 Element (electric.xml.Element)1 File (java.io.File)1