Search in sources :

Example 6 with Instance

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

the class ReplaceWithBufferSoundObjectAction method getReplacementObject.

protected SoundObject getReplacementObject(ScoreController.ScoreObjectBuffer buffer, List<Instance> instances) {
    if (buffer.scoreObjects.size() == 1) {
        SoundObject sObj = (SoundObject) buffer.scoreObjects.get(0).deepCopy();
        if (sObj instanceof Instance) {
            instances.add((Instance) sObj);
        }
        return sObj;
    }
    PolyObject pObj = new PolyObject();
    int minLayer = Integer.MAX_VALUE;
    int maxLayer = Integer.MIN_VALUE;
    for (Integer layerIndex : buffer.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 < buffer.scoreObjects.size(); i++) {
        ScoreObject scoreObj = buffer.scoreObjects.get(i);
        int layerIndex = buffer.layerIndexes.get(i);
        SoundLayer layer = pObj.get(layerIndex - minLayer);
        SoundObject clone = (SoundObject) scoreObj.deepCopy();
        layer.add(clone);
        if (clone instanceof Instance) {
            instances.add((Instance) clone);
        }
    }
    return pObj;
}
Also used : SoundObject(blue.soundObject.SoundObject) Instance(blue.soundObject.Instance) SoundLayer(blue.SoundLayer) ScoreObject(blue.score.ScoreObject) PolyObject(blue.soundObject.PolyObject) Point(java.awt.Point)

Example 7 with Instance

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

the class AddToSoundObjectLibraryAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    SoundObject sObj = (SoundObject) soundObjects.iterator().next().deepCopy();
    if (sObj instanceof Instance) {
        return;
    }
    BlueData data = BlueProjectManager.getInstance().getCurrentBlueData();
    Instance i = new Instance(sObj);
    i.setStartTime(sObj.getStartTime());
    i.setSubjectiveDuration(sObj.getSubjectiveDuration());
    data.getSoundObjectLibrary().addSoundObject(sObj);
    SoundLayer layer = (SoundLayer) scorePath.getGlobalLayerForY(p.y);
    layer.remove(soundObjects.iterator().next());
    layer.add(i);
// BlueUndoManager.setUndoManager("score");
// BlueUndoManager.addEdit(new ReplaceScoreObjectEdit(
// sCanvas.getPolyObject(), oldSoundObject,
// newSoundObject, index));
}
Also used : BlueData(blue.BlueData) SoundObject(blue.soundObject.SoundObject) Instance(blue.soundObject.Instance) SoundLayer(blue.SoundLayer)

Example 8 with Instance

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

the class ExportAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (scoreObjects.size() == 1 && soundObjects.size() == 1) {
        File retVal = FileChooserManager.getDefault().showSaveDialog(EXPORT_DIALOG, WindowManager.getDefault().getMainWindow());
        if (retVal != null) {
            File f = retVal;
            if (f.exists()) {
                int overWrite = JOptionPane.showConfirmDialog(SwingUtilities.getRoot(WindowManager.getDefault().getMainWindow()), "Please confirm you would like to overwrite this file.");
                if (overWrite != JOptionPane.OK_OPTION) {
                    return;
                }
            }
            SoundObject sObj = soundObjects.iterator().next();
            if ((sObj instanceof Instance) || ((sObj instanceof PolyObject) && containsInstance((PolyObject) sObj))) {
                JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), "Error: Export of Instance or " + "PolyObjects containing Instance " + "is not allowed.", "Error", JOptionPane.ERROR_MESSAGE);
                return;
            }
            Element node = sObj.saveAsXML(null);
            PrintWriter out;
            try {
                out = new PrintWriter(new FileWriter(f));
                out.print(node.toString());
                out.flush();
                out.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
}
Also used : SoundObject(blue.soundObject.SoundObject) Instance(blue.soundObject.Instance) Element(electric.xml.Element) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) PolyObject(blue.soundObject.PolyObject) PrintWriter(java.io.PrintWriter)

Example 9 with Instance

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

the class SoundObjectLibraryTopComponent method copyInstanceButtonActionPerformed.

// GEN-LAST:event_copyButtonActionPerformed
private void copyInstanceButtonActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_copyInstanceButtonActionPerformed
    int index = sObjLibTable.getSelectedRow();
    if (index != -1) {
        SoundObject originalSObj = sObjLib.getSoundObject(index);
        Instance tempSObj = new Instance(originalSObj);
        tempSObj.setStartTime(0.0f);
        tempSObj.setSubjectiveDuration(tempSObj.getObjectiveDuration());
        ScoreController.getInstance().setSelectedScoreObjects(Collections.singleton(tempSObj));
        scoreObjectBuffer.clear();
        scoreObjectBuffer.scoreObjects.add(tempSObj);
        scoreObjectBuffer.layerIndexes.add(0);
    }
}
Also used : SoundObject(blue.soundObject.SoundObject) Instance(blue.soundObject.Instance)

Example 10 with Instance

use of blue.soundObject.Instance 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

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