Search in sources :

Example 26 with PolyObject

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

the class ScoreObjectEditorTopComponent method resultChanged.

@Override
public void resultChanged(LookupEvent ev) {
    if (!(TopComponent.getRegistry().getActivated() instanceof SoundObjectProvider)) {
        return;
    }
    Collection<? extends ScoreObject> scoreObjects = result.allInstances();
    if (scoreObjects.size() == 1) {
        SwingUtilities.invokeLater(() -> {
            BlueData data = BlueProjectManager.getInstance().getCurrentBlueData();
            ScoreObject sObj = scoreObjects.iterator().next();
            if (sObj instanceof PolyObject && data.getSoundObjectLibrary().contains(sObj)) {
                PolyObject pObj = (PolyObject) sObj;
                ScoreController.getInstance().editLayerGroup(pObj);
                editScoreObject(null);
            } else {
                editScoreObject(sObj);
            }
        });
    // FIXME - figure out how to discern if editing is from BlueLive...
    } else {
        SwingUtilities.invokeLater(() -> {
            editScoreObject(null);
        });
    }
}
Also used : SoundObjectProvider(blue.ui.core.score.layers.SoundObjectProvider) BlueData(blue.BlueData) ScoreObject(blue.score.ScoreObject) PolyObject(blue.soundObject.PolyObject)

Example 27 with PolyObject

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

Example 28 with PolyObject

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

Example 29 with PolyObject

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

the class ScoreTimelineDropTargetListener method drop.

/*
     * (non-Javadoc)
     * 
     * @see java.awt.dnd.DropTargetListener#drop(java.awt.dnd.DropTargetDropEvent)
     */
@Override
public void drop(DropTargetDropEvent dtde) {
    try {
        Transferable tr = dtde.getTransferable();
        if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            dtde.acceptDrop(DnDConstants.ACTION_LINK);
            List list = (List) tr.getTransferData(DataFlavor.javaFileListFlavor);
            if (list.size() != 1) {
                dtde.dropComplete(false);
                return;
            }
            String s = list.get(0).toString().trim();
            if (!s.toLowerCase().endsWith("wav") && !s.toLowerCase().endsWith("aif") && !s.toLowerCase().endsWith("aiff")) {
                dtde.dropComplete(false);
                return;
            }
            String sObjName = s.substring(s.lastIndexOf(File.separator) + 1);
            Point p = dtde.getLocation();
            int index = sTimeCanvas.pObj.getLayerNumForY(p.y);
            AudioFile af = new AudioFile();
            af.setName(sObjName);
            af.setSoundFileName(BlueSystem.getRelativePath(s));
            PolyObject pObj = sTimeCanvas.getPolyObject();
            float startTime = (float) p.x / timeState.getPixelSecond();
            float dur = SoundFileUtilities.getDurationInSeconds(s);
            af.setStartTime(startTime);
            af.setSubjectiveDuration(dur);
            pObj.addSoundObject(index, af);
            dtde.dropComplete(true);
            return;
        } else if (dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            dtde.acceptDrop(DnDConstants.ACTION_LINK);
            String str = (String) tr.getTransferData(DataFlavor.stringFlavor);
            if (!str.startsWith("file://")) {
                dtde.dropComplete(false);
                return;
            }
            str = str.substring(7).trim();
            if (!str.toLowerCase().endsWith("wav") && !str.toLowerCase().endsWith("aif") && !str.toLowerCase().endsWith("aiff")) {
                System.err.println("Could not open file: " + str);
                dtde.dropComplete(false);
                return;
            }
            str = URLDecoder.decode(str);
            str = str.replaceAll(" ", "\\ ");
            File f = new File(str);
            if (!f.exists()) {
                dtde.dropComplete(false);
                return;
            }
            String sObjName = str.substring(str.lastIndexOf(File.separator) + 1);
            Point p = dtde.getLocation();
            int index = sTimeCanvas.pObj.getLayerNumForY(p.y);
            AudioFile af = new AudioFile();
            af.setName(sObjName);
            af.setSoundFileName(str);
            PolyObject pObj = sTimeCanvas.getPolyObject();
            float startTime = (float) p.x / timeState.getPixelSecond();
            float dur = SoundFileUtilities.getDurationInSeconds(str);
            af.setStartTime(startTime);
            af.setSubjectiveDuration(dur);
            pObj.addSoundObject(index, af);
            dtde.dropComplete(true);
            return;
        }
        dtde.rejectDrop();
    } catch (UnsupportedFlavorException | IOException | UnsupportedAudioFileException e) {
        e.printStackTrace();
        dtde.rejectDrop();
    }
}
Also used : Transferable(java.awt.datatransfer.Transferable) Point(java.awt.Point) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Point(java.awt.Point) AudioFile(blue.soundObject.AudioFile) UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) List(java.util.List) AudioFile(blue.soundObject.AudioFile) File(java.io.File) PolyObject(blue.soundObject.PolyObject)

Aggregations

PolyObject (blue.soundObject.PolyObject)29 SoundLayer (blue.SoundLayer)10 SoundObject (blue.soundObject.SoundObject)10 BlueData (blue.BlueData)8 Score (blue.score.Score)8 Instance (blue.soundObject.Instance)6 ScoreObject (blue.score.ScoreObject)5 GenericScore (blue.soundObject.GenericScore)5 Point (java.awt.Point)4 ArrayList (java.util.ArrayList)4 SoundObjectLibrary (blue.SoundObjectLibrary)3 Layer (blue.score.layers.Layer)3 LayerGroup (blue.score.layers.LayerGroup)3 AudioFile (blue.soundObject.AudioFile)3 File (java.io.File)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 AbstractLookup (org.openide.util.lookup.AbstractLookup)3 Mixer (blue.mixer.Mixer)2 TimeState (blue.score.TimeState)2