Search in sources :

Example 1 with LineListener

use of javax.sound.sampled.LineListener in project jdk8u_jdk by JetBrains.

the class EventDispatcher method processEvent.

/**
     * Invoked when there is at least one event in the queue.
     * Implement this as a callback to process one event.
     */
void processEvent(EventInfo eventInfo) {
    int count = eventInfo.getListenerCount();
    // process an LineEvent
    if (eventInfo.getEvent() instanceof LineEvent) {
        LineEvent event = (LineEvent) eventInfo.getEvent();
        if (Printer.debug)
            Printer.debug("Sending " + event + " to " + count + " listeners");
        for (int i = 0; i < count; i++) {
            try {
                ((LineListener) eventInfo.getListener(i)).update(event);
            } catch (Throwable t) {
                if (Printer.err)
                    t.printStackTrace();
            }
        }
        return;
    }
    // process a MetaMessage
    if (eventInfo.getEvent() instanceof MetaMessage) {
        MetaMessage event = (MetaMessage) eventInfo.getEvent();
        for (int i = 0; i < count; i++) {
            try {
                ((MetaEventListener) eventInfo.getListener(i)).meta(event);
            } catch (Throwable t) {
                if (Printer.err)
                    t.printStackTrace();
            }
        }
        return;
    }
    // process a Controller or Mode Event
    if (eventInfo.getEvent() instanceof ShortMessage) {
        ShortMessage event = (ShortMessage) eventInfo.getEvent();
        int status = event.getStatus();
        // c is the channel they are sent on.
        if ((status & 0xF0) == 0xB0) {
            for (int i = 0; i < count; i++) {
                try {
                    ((ControllerEventListener) eventInfo.getListener(i)).controlChange(event);
                } catch (Throwable t) {
                    if (Printer.err)
                        t.printStackTrace();
                }
            }
        }
        return;
    }
    Printer.err("Unknown event type: " + eventInfo.getEvent());
}
Also used : LineEvent(javax.sound.sampled.LineEvent) ControllerEventListener(javax.sound.midi.ControllerEventListener) ShortMessage(javax.sound.midi.ShortMessage) MetaEventListener(javax.sound.midi.MetaEventListener) LineListener(javax.sound.sampled.LineListener) MetaMessage(javax.sound.midi.MetaMessage)

Example 2 with LineListener

use of javax.sound.sampled.LineListener in project yamcs-studio by yamcs.

the class SoundSystem method beep.

/**
 * Plays a beep, only if there is not currently a previous beep playing.
 */
public static synchronized void beep() {
    try {
        if (beepClip != null) {
            return;
        }
        beepClip = AudioSystem.getClip();
        InputStream in = SoundSystem.class.getResourceAsStream(BEEP_SOUND);
        AudioInputStream audioIn = AudioSystem.getAudioInputStream(new BufferedInputStream(in));
        beepClip.open(audioIn);
        beepClip.start();
        // explicitly stop the clip when sound has stopped
        beepClip.addLineListener(new LineListener() {

            @Override
            public void update(LineEvent event) {
                if (event.getType() == LineEvent.Type.STOP) {
                    event.getLine().close();
                    beepClip = null;
                }
            }
        });
    } catch (Exception e) {
        System.out.println(e);
        log.log(Level.WARNING, "Error playing beep sound", e);
    }
}
Also used : AudioInputStream(javax.sound.sampled.AudioInputStream) LineEvent(javax.sound.sampled.LineEvent) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) AudioInputStream(javax.sound.sampled.AudioInputStream) InputStream(java.io.InputStream) LineListener(javax.sound.sampled.LineListener)

Aggregations

LineEvent (javax.sound.sampled.LineEvent)2 LineListener (javax.sound.sampled.LineListener)2 BufferedInputStream (java.io.BufferedInputStream)1 InputStream (java.io.InputStream)1 ControllerEventListener (javax.sound.midi.ControllerEventListener)1 MetaEventListener (javax.sound.midi.MetaEventListener)1 MetaMessage (javax.sound.midi.MetaMessage)1 ShortMessage (javax.sound.midi.ShortMessage)1 AudioInputStream (javax.sound.sampled.AudioInputStream)1