Search in sources :

Example 1 with SoundObjectLibrary

use of blue.SoundObjectLibrary in project blue by kunstmusik.

the class SoundObjectLibraryUtilsTest method testRemoveLibrarySoundObject.

/**
 * Test of removeLibrarySoundObject method, of class SoundObjectLibraryUtils.
 */
@Test
public void testRemoveLibrarySoundObject() {
    BlueData data = new BlueData();
    Score score = data.getScore();
    PolyObject polyObj = new PolyObject(true);
    score.add(polyObj);
    SoundObjectLibrary library = data.getSoundObjectLibrary();
    SoundLayer layer = polyObj.newLayerAt(0);
    SoundObject sObj = new GenericScore();
    SoundObject sObj2 = new GenericScore();
    PolyObject pObjInner = new PolyObject(true);
    SoundLayer layerInner = pObjInner.newLayerAt(0);
    layerInner.add(new Instance(sObj));
    layer.add(new Instance(sObj));
    layer.add(new Instance(sObj));
    layer.add(new Instance(sObj));
    layer.add(sObj2);
    layer.add(pObjInner);
    library.add(sObj);
    assertEquals(5, layer.size());
    assertEquals(1, library.size());
    assertEquals(1, layerInner.size());
    SoundObjectLibraryUtils.removeLibrarySoundObject(data, sObj);
    assertEquals(2, layer.size());
    assertEquals(0, library.size());
    assertEquals(0, layerInner.size());
}
Also used : BlueData(blue.BlueData) Score(blue.score.Score) GenericScore(blue.soundObject.GenericScore) SoundObject(blue.soundObject.SoundObject) Instance(blue.soundObject.Instance) SoundLayer(blue.SoundLayer) SoundObjectLibrary(blue.SoundObjectLibrary) GenericScore(blue.soundObject.GenericScore) PolyObject(blue.soundObject.PolyObject) Test(org.junit.Test)

Example 2 with SoundObjectLibrary

use of blue.SoundObjectLibrary in project blue by kunstmusik.

the class ReplaceWithBufferSoundObjectAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    ScoreController.ScoreObjectBuffer buffer = ScoreController.getInstance().getScoreObjectBuffer();
    List<Layer> layers = scorePath.getAllLayers();
    BlueData data = BlueProjectManager.getInstance().getCurrentBlueData();
    SoundObjectLibrary sObjLib = data.getSoundObjectLibrary();
    List<Instance> instances = new ArrayList<>();
    ReplaceScoreObjectEdit top = null;
    for (SoundObject sObj : soundObjects) {
        SoundObject replacement = getReplacementObject(buffer, instances);
        replacement.setStartTime(sObj.getStartTime());
        replacement.setSubjectiveDuration(sObj.getSubjectiveDuration());
        ScoreObjectLayer layer = (ScoreObjectLayer) findLayerForSoundObject(layers, sObj);
        layer.remove(sObj);
        layer.add(replacement);
        ReplaceScoreObjectEdit edit = new ReplaceScoreObjectEdit(layer, sObj, replacement);
        if (top == null) {
            top = edit;
        } else {
            top.addEdit(edit);
        }
    }
    // FIXME - this part is not undoable...
    sObjLib.checkAndAddInstanceSoundObjects(instances);
    BlueUndoManager.setUndoManager("score");
    BlueUndoManager.addEdit(top);
}
Also used : ScoreController(blue.ui.core.score.ScoreController) BlueData(blue.BlueData) ScoreObjectLayer(blue.score.layers.ScoreObjectLayer) SoundObject(blue.soundObject.SoundObject) Instance(blue.soundObject.Instance) ReplaceScoreObjectEdit(blue.ui.core.score.undo.ReplaceScoreObjectEdit) ArrayList(java.util.ArrayList) SoundObjectLibrary(blue.SoundObjectLibrary) SoundLayer(blue.SoundLayer) ScoreObjectLayer(blue.score.layers.ScoreObjectLayer) Layer(blue.score.layers.Layer)

Example 3 with SoundObjectLibrary

use of blue.SoundObjectLibrary 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)

Example 4 with SoundObjectLibrary

use of blue.SoundObjectLibrary 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 5 with SoundObjectLibrary

use of blue.SoundObjectLibrary in project blue by kunstmusik.

the class SoundObjectLibraryUtils method removeLibrarySoundObject.

public static void removeLibrarySoundObject(BlueData data, SoundObject sObj) {
    SoundObjectLibrary library = data.getSoundObjectLibrary();
    library.removeSoundObject(sObj);
    for (SoundObject tempObj : library) {
        if (tempObj instanceof PolyObject) {
            removeSoundObjectInstances((PolyObject) tempObj, sObj);
        }
    }
    Score score = data.getScore();
    for (LayerGroup layerGroup : score) {
        if (layerGroup instanceof PolyObject) {
            PolyObject pObj = (PolyObject) layerGroup;
            removeSoundObjectInstances(pObj, sObj);
        }
    }
}
Also used : Score(blue.score.Score) SoundObject(blue.soundObject.SoundObject) SoundObjectLibrary(blue.SoundObjectLibrary) LayerGroup(blue.score.layers.LayerGroup) PolyObject(blue.soundObject.PolyObject)

Aggregations

SoundObjectLibrary (blue.SoundObjectLibrary)5 BlueData (blue.BlueData)4 SoundLayer (blue.SoundLayer)4 Instance (blue.soundObject.Instance)4 SoundObject (blue.soundObject.SoundObject)4 ScoreObjectLayer (blue.score.layers.ScoreObjectLayer)3 PolyObject (blue.soundObject.PolyObject)3 ScoreController (blue.ui.core.score.ScoreController)3 ArrayList (java.util.ArrayList)3 Score (blue.score.Score)2 ScoreObject (blue.score.ScoreObject)2 Layer (blue.score.layers.Layer)2 AddScoreObjectEdit (blue.ui.core.score.undo.AddScoreObjectEdit)2 Point (java.awt.Point)2 LayerGroup (blue.score.layers.LayerGroup)1 GenericScore (blue.soundObject.GenericScore)1 ReplaceScoreObjectEdit (blue.ui.core.score.undo.ReplaceScoreObjectEdit)1 Test (org.junit.Test)1