Search in sources :

Example 1 with AudioLayerGroup

use of blue.score.layers.audio.core.AudioLayerGroup in project blue by kunstmusik.

the class BlueProjectPropertyChangeListener method detachListeners.

protected void detachListeners(BlueProject project) {
    if (project == null) {
        return;
    }
    Score score = project.getData().getScore();
    for (LayerGroup<? extends Layer> lg : score) {
        if (lg instanceof AudioLayerGroup) {
            lg.removeLayerGroupListener(layerGroupListener);
        }
    }
    score.removeListener(scoreListener);
}
Also used : Score(blue.score.Score) AudioLayerGroup(blue.score.layers.audio.core.AudioLayerGroup)

Example 2 with AudioLayerGroup

use of blue.score.layers.audio.core.AudioLayerGroup in project blue by kunstmusik.

the class AudioLayersDropTargetListener method drop.

/*
     * (non-Javadoc)
     * 
     * @see java.awt.dnd.DropTargetListener#drop(java.awt.dnd.DropTargetDropEvent)
     */
@Override
public void drop(DropTargetDropEvent dtde) {
    Node node = NodeTransfer.node(dtde.getTransferable(), NodeTransfer.DND_COPY);
    if (node != null) {
        File f = node.getLookup().lookup(File.class);
        if (f == null || !f.isFile()) {
            dtde.dropComplete(false);
            return;
        }
        dtde.acceptDrop(DnDConstants.ACTION_COPY);
        Point p = dtde.getLocation();
        AudioLayerGroup audioLayerGroup = audioLayersPanel.getAudioLayerGroup();
        int index = audioLayerGroup.getLayerNumForY(p.y);
        AudioClip af = new AudioClip();
        af.setName(f.getName());
        af.setAudioFile(f);
        float startTime = (float) p.x / audioLayersPanel.getTimeState().getPixelSecond();
        af.setStartTime(startTime);
        af.setSubjectiveDuration(af.getAudioDuration());
        AudioLayer layer = audioLayerGroup.get(index);
        layer.add(af);
        dtde.dropComplete(true);
    }
    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();
            System.out.println("file flavor found: " + s);
            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();
            AudioLayerGroup audioLayerGroup = audioLayersPanel.getAudioLayerGroup();
            int index = audioLayerGroup.getLayerNumForY(p.y);
            AudioClip af = new AudioClip();
            af.setName(sObjName);
            af.setAudioFile(new File(s));
            float startTime = (float) p.x / audioLayersPanel.getTimeState().getPixelSecond();
            af.setStartTime(startTime);
            af.setSubjectiveDuration(af.getAudioDuration());
            AudioLayer layer = audioLayerGroup.get(index);
            layer.add(af);
            dtde.dropComplete(true);
            return;
        } else if (dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            dtde.acceptDrop(DnDConstants.ACTION_LINK);
            String str = (String) tr.getTransferData(DataFlavor.stringFlavor);
            System.out.println("String flavor found: " + str);
            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();
            AudioLayerGroup audioLayerGroup = audioLayersPanel.getAudioLayerGroup();
            int index = audioLayerGroup.getLayerNumForY(p.y);
            AudioClip af = new AudioClip();
            af.setName(sObjName);
            af.setAudioFile(f);
            float startTime = (float) p.x / audioLayersPanel.getTimeState().getPixelSecond();
            af.setStartTime(startTime);
            af.setSubjectiveDuration(af.getAudioDuration());
            AudioLayer layer = audioLayerGroup.get(index);
            layer.add(af);
            dtde.dropComplete(true);
            return;
        }
        dtde.rejectDrop();
    } catch (UnsupportedFlavorException | IOException | InvalidDnDOperationException e) {
        e.printStackTrace();
        dtde.rejectDrop();
    }
}
Also used : InvalidDnDOperationException(java.awt.dnd.InvalidDnDOperationException) Node(org.openide.nodes.Node) AudioClip(blue.score.layers.audio.core.AudioClip) Transferable(java.awt.datatransfer.Transferable) AudioLayerGroup(blue.score.layers.audio.core.AudioLayerGroup) Point(java.awt.Point) IOException(java.io.IOException) AudioLayer(blue.score.layers.audio.core.AudioLayer) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Point(java.awt.Point) List(java.util.List) File(java.io.File)

Example 3 with AudioLayerGroup

use of blue.score.layers.audio.core.AudioLayerGroup in project blue by kunstmusik.

the class BlueProjectPropertyChangeListener method attachListeners.

protected void attachListeners(BlueProject project) {
    if (project == null) {
        return;
    }
    Score score = project.getData().getScore();
    Mixer mixer = project.getData().getMixer();
    for (LayerGroup<? extends Layer> lg : score) {
        if (lg instanceof AudioLayerGroup) {
            AudioLayerGroup alg = (AudioLayerGroup) lg;
            ChannelList channelList = findChannelListForAudioLayerGroup(mixer, alg);
            lg.addLayerGroupListener(layerGroupListener);
            AudioLayerGroupBinding binding = new AudioLayerGroupBinding(alg, channelList);
            layerGroupBindings.put(alg, binding);
            for (AudioLayer layer : alg) {
                Channel channel = ChannelList.findChannelByAssociation(channelList, layer.getUniqueId());
                if (channel != null) {
                    layerBindings.put(layer, new AudioLayerChannelBinding(layer, channel));
                }
            }
        }
    }
    score.addListener(scoreListener);
}
Also used : Score(blue.score.Score) Mixer(blue.mixer.Mixer) Channel(blue.mixer.Channel) AudioLayerChannelBinding(blue.score.layers.audio.ui.bindings.AudioLayerChannelBinding) AudioLayerGroup(blue.score.layers.audio.core.AudioLayerGroup) ChannelList(blue.mixer.ChannelList) AudioLayerGroupBinding(blue.score.layers.audio.ui.bindings.AudioLayerGroupBinding) AudioLayer(blue.score.layers.audio.core.AudioLayer)

Aggregations

AudioLayerGroup (blue.score.layers.audio.core.AudioLayerGroup)3 Score (blue.score.Score)2 AudioLayer (blue.score.layers.audio.core.AudioLayer)2 Channel (blue.mixer.Channel)1 ChannelList (blue.mixer.ChannelList)1 Mixer (blue.mixer.Mixer)1 AudioClip (blue.score.layers.audio.core.AudioClip)1 AudioLayerChannelBinding (blue.score.layers.audio.ui.bindings.AudioLayerChannelBinding)1 AudioLayerGroupBinding (blue.score.layers.audio.ui.bindings.AudioLayerGroupBinding)1 Point (java.awt.Point)1 Transferable (java.awt.datatransfer.Transferable)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 InvalidDnDOperationException (java.awt.dnd.InvalidDnDOperationException)1 File (java.io.File)1 IOException (java.io.IOException)1 List (java.util.List)1 Node (org.openide.nodes.Node)1