Search in sources :

Example 1 with AudioClip

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

the class AudioLayersPanel method layerGroupChanged.

@Override
public void layerGroupChanged(final LayerGroupDataEvent event) {
    final ArrayList<Layer> layers = event.getLayers();
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            if (event.getType() == LayerGroupDataEvent.DATA_ADDED) {
                for (Layer layer : layers) {
                    ((AudioLayer) layer).addPropertyChangeListener(heightListener);
                    ((AudioLayer) layer).addAudioLayerListener(AudioLayersPanel.this);
                    for (AudioClip clip : (AudioLayer) layer) {
                        addClipPanel(clip, timeState, 0, 0);
                    }
                }
            } else if (event.getType() == LayerGroupDataEvent.DATA_REMOVED) {
                for (Layer layer : layers) {
                    ((AudioLayer) layer).removePropertyChangeListener(heightListener);
                    ((AudioLayer) layer).removeAudioLayerListener(AudioLayersPanel.this);
                    for (AudioClip clip : (AudioLayer) layer) {
                        removeClipPanel(clip);
                    }
                }
            }
            updateAudioClipYandHeight();
            checkSize();
            repaint();
        }
    });
}
Also used : AudioClip(blue.score.layers.audio.core.AudioClip) AudioLayer(blue.score.layers.audio.core.AudioLayer) AudioLayer(blue.score.layers.audio.core.AudioLayer) Layer(blue.score.layers.Layer)

Example 2 with AudioClip

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

the class AudioClipPanel method addNotify.

@Override
public void addNotify() {
    super.addNotify();
    audioClip.addScoreObjectListener(this);
    audioClip.fileStartTimeProperty().addListener(this);
    audioClip.fadeInProperty().addListener(fadeListener);
    audioClip.fadeInTypeProperty().addListener(fadeTypeListener);
    audioClip.fadeOutProperty().addListener(fadeListener);
    audioClip.fadeOutTypeProperty().addListener(fadeTypeListener);
    timeState.addPropertyChangeListener(this);
    ScoreTopComponent scoreTopComponent = (ScoreTopComponent) WindowManager.getDefault().findTopComponent("ScoreTopComponent");
    result = scoreTopComponent.getLookup().lookupResult(AudioClip.class);
    result.addLookupListener(this);
    Collection<? extends AudioClip> soundObjects = result.allInstances();
    setSelected(soundObjects.contains(this.audioClip));
    updateWaveformData();
    this.addMouseListener(mouseAdapter);
    this.addMouseMotionListener(mouseAdapter);
}
Also used : ScoreTopComponent(blue.ui.core.score.ScoreTopComponent) AudioClip(blue.score.layers.audio.core.AudioClip)

Example 3 with AudioClip

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

the class AudioLayerGroupUtils method splitAudioClip.

public static void splitAudioClip(AudioLayer layer, AudioClip clip, double time) {
    AudioClip first = new AudioClip(clip);
    AudioClip second = new AudioClip(clip);
    if (first.getFadeIn() > time) {
        first.setFadeIn(0.0f);
    } else if (time > first.getDuration() - first.getFadeOut()) {
        second.setFadeOut(0.0f);
    }
    first.setFadeOut(0.0f);
    second.setFadeIn(0.0f);
    first.setDuration(time);
    second.setDuration(second.getDuration() - time);
    second.setStart(second.getStart() + time);
    second.setFileStartTime(second.getFileStartTime() + time);
    layer.remove(clip);
    layer.add(first);
    layer.add(second);
}
Also used : AudioClip(blue.score.layers.audio.core.AudioClip)

Example 4 with AudioClip

use of blue.score.layers.audio.core.AudioClip 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 5 with AudioClip

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

the class AudioLayersPanel method updateAudioClipYandHeight.

private void updateAudioClipYandHeight() {
    int y = 0;
    int height = 0;
    for (AudioLayer layer : layerGroup) {
        height = layer.getAudioLayerHeight();
        for (AudioClip clip : layer) {
            AudioClipPanel panel = clipPanelMap.get(clip);
            panel.setBounds(new Rectangle(panel.getX(), y, panel.getWidth(), height));
        }
        y += height;
    }
}
Also used : AudioClip(blue.score.layers.audio.core.AudioClip) Rectangle(java.awt.Rectangle) AudioLayer(blue.score.layers.audio.core.AudioLayer) Point(java.awt.Point)

Aggregations

AudioClip (blue.score.layers.audio.core.AudioClip)6 AudioLayer (blue.score.layers.audio.core.AudioLayer)3 Point (java.awt.Point)2 Layer (blue.score.layers.Layer)1 AudioLayerGroup (blue.score.layers.audio.core.AudioLayerGroup)1 ScoreTopComponent (blue.ui.core.score.ScoreTopComponent)1 Rectangle (java.awt.Rectangle)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