Search in sources :

Example 1 with Receiver

use of javax.sound.midi.Receiver in project jdk8u_jdk by JetBrains.

the class GetMidiDevice method main.

public static void main(String[] args) throws Exception {
    AudioSynthesizer synth = new SoftSynthesizer();
    synth.openStream(null, null);
    Receiver recv = synth.getReceiver();
    if (((SoftReceiver) recv).getMidiDevice() != synth) {
        throw new Exception("SoftReceiver.getMidiDevice() doesn't return " + "instance of the synthesizer");
    }
    synth.close();
}
Also used : Receiver(javax.sound.midi.Receiver) SoftReceiver(com.sun.media.sound.SoftReceiver) SoftSynthesizer(com.sun.media.sound.SoftSynthesizer) AudioSynthesizer(com.sun.media.sound.AudioSynthesizer)

Example 2 with Receiver

use of javax.sound.midi.Receiver in project jdk8u_jdk by JetBrains.

the class ImplicitOpenClose method main.

public static void main(String[] args) throws Exception {
    Field f = SoftSynthesizer.class.getDeclaredField("testline");
    f.setAccessible(true);
    f.set(null, new DummySourceDataLine());
    Synthesizer synth = new SoftSynthesizer();
    ReferenceCountingDevice rcd = (ReferenceCountingDevice) synth;
    // Test single open/close cycle
    Receiver recv = rcd.getReceiverReferenceCounting();
    if (!synth.isOpen())
        throw new Exception("Synthesizer not open!");
    recv.close();
    if (synth.isOpen())
        throw new Exception("Synthesizer not closed!");
    // Test using 2 receiver cycle
    Receiver recv1 = rcd.getReceiverReferenceCounting();
    if (!synth.isOpen())
        throw new Exception("Synthesizer not open!");
    Receiver recv2 = rcd.getReceiverReferenceCounting();
    if (!synth.isOpen())
        throw new Exception("Synthesizer not open!");
    recv2.close();
    if (!synth.isOpen())
        throw new Exception("Synthesizer was closed!");
    recv1.close();
    if (synth.isOpen())
        throw new Exception("Synthesizer not closed!");
    // Test for explicit,implicit conflict
    synth.open();
    Receiver recv3 = rcd.getReceiverReferenceCounting();
    if (!synth.isOpen())
        throw new Exception("Synthesizer not open!");
    recv3.close();
    if (!synth.isOpen())
        throw new Exception("Synthesizer was closed!");
    synth.close();
    if (synth.isOpen())
        throw new Exception("Synthesizer not closed!");
    // Test for implicit,explicit conflict
    recv3 = rcd.getReceiverReferenceCounting();
    synth.open();
    if (!synth.isOpen())
        throw new Exception("Synthesizer not open!");
    recv3.close();
    if (!synth.isOpen())
        throw new Exception("Synthesizer was closed!");
    synth.close();
    if (synth.isOpen())
        throw new Exception("Synthesizer not closed!");
}
Also used : Field(java.lang.reflect.Field) Receiver(javax.sound.midi.Receiver) Synthesizer(javax.sound.midi.Synthesizer) MidiUnavailableException(javax.sound.midi.MidiUnavailableException)

Example 3 with Receiver

use of javax.sound.midi.Receiver in project jdk8u_jdk by JetBrains.

the class GetReceiver2 method main.

public static void main(String[] args) throws Exception {
    AudioSynthesizer synth = new SoftSynthesizer();
    Receiver recv = synth.getReceiver();
    assertTrue(recv != null);
    ShortMessage sm = new ShortMessage();
    sm.setMessage(ShortMessage.NOTE_OFF, 0, 64, 64);
    synth.open(new DummySourceDataLine(), null);
    recv.send(sm, -1);
    synth.close();
    try {
        recv.send(sm, -1);
        throw new RuntimeException("Exception not thrown!");
    } catch (Exception e) {
    // Just checking if exception is thrown
    }
}
Also used : ShortMessage(javax.sound.midi.ShortMessage) Receiver(javax.sound.midi.Receiver) SoftSynthesizer(com.sun.media.sound.SoftSynthesizer) AudioSynthesizer(com.sun.media.sound.AudioSynthesizer)

Example 4 with Receiver

use of javax.sound.midi.Receiver in project jdk8u_jdk by JetBrains.

the class TestAllDevices method main.

public static void main(String[] args) throws Exception {
    out("default receiver:");
    try {
        Receiver recv = MidiSystem.getReceiver();
        out("  receiver: " + recv);
        if (recv instanceof MidiDeviceReceiver) {
            out("    OK");
        } else {
            out("    ERROR: not an instance of MidiDeviceReceiver");
            failed = true;
        }
    } catch (MidiUnavailableException ex) {
        // this is not an error
        out("  receiver: MidiUnavailableException (test NOT failed)");
    }
    out("default transmitter:");
    try {
        Transmitter tran = MidiSystem.getTransmitter();
        out("  transmitter: " + tran);
        if (tran instanceof MidiDeviceTransmitter) {
            out("    OK");
        } else {
            out("    ERROR: not an instance of MidiDeviceTransmitter");
            failed = true;
        }
    } catch (MidiUnavailableException ex) {
        // this is not an error
        out("  transmitter: MidiUnavailableException (test NOT failed)");
    }
    MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
    for (MidiDevice.Info info : infos) {
        out(info.toString() + ":");
        try {
            MidiDevice dev = MidiSystem.getMidiDevice(info);
            dev.open();
            try {
                Receiver recv = dev.getReceiver();
                out("  receiver: " + recv);
                if (recv instanceof MidiDeviceReceiver) {
                    MidiDeviceReceiver devRecv = (MidiDeviceReceiver) recv;
                    MidiDevice retDev = devRecv.getMidiDevice();
                    if (retDev == dev) {
                        out("    OK");
                    } else {
                        out("    ERROR: getMidiDevice returned incorrect device: " + retDev);
                        failed = true;
                    }
                } else {
                    out("    ERROR: not an instance of MidiDeviceReceiver");
                    failed = true;
                }
            } catch (MidiUnavailableException ex) {
                // this is not an error
                out("  receiver: MidiUnavailableException (test NOT failed)");
            }
            try {
                Transmitter tran = dev.getTransmitter();
                out("  transmitter: " + tran);
                if (tran instanceof MidiDeviceTransmitter) {
                    MidiDeviceTransmitter devTran = (MidiDeviceTransmitter) tran;
                    MidiDevice retDev = devTran.getMidiDevice();
                    if (retDev == dev) {
                        out("    OK");
                    } else {
                        out("    ERROR: getMidiDevice retur4ned incorrect device: " + retDev);
                        failed = true;
                    }
                } else {
                    out("    ERROR: not an instance of MidiDeviceTransmitter");
                    failed = true;
                }
            } catch (MidiUnavailableException ex) {
                // this is not an error
                out("  transmitter: MidiUnavailableException (test NOT failed)");
            }
            dev.close();
        } catch (MidiUnavailableException ex) {
            out("  device: MidiUnavailableException (test NOT failed)");
        }
    }
    if (failed) {
        throw new Exception("Test failed.");
    }
}
Also used : MidiUnavailableException(javax.sound.midi.MidiUnavailableException) MidiDeviceTransmitter(javax.sound.midi.MidiDeviceTransmitter) Transmitter(javax.sound.midi.Transmitter) MidiDeviceReceiver(javax.sound.midi.MidiDeviceReceiver) Receiver(javax.sound.midi.Receiver) MidiDeviceReceiver(javax.sound.midi.MidiDeviceReceiver) MidiDevice(javax.sound.midi.MidiDevice) MidiDeviceTransmitter(javax.sound.midi.MidiDeviceTransmitter) MidiUnavailableException(javax.sound.midi.MidiUnavailableException)

Example 5 with Receiver

use of javax.sound.midi.Receiver in project jdk8u_jdk by JetBrains.

the class SequencerImplicitSynthOpen method getConnectedDevice.

static MidiDevice getConnectedDevice(Sequencer sequencer) {
    List<Transmitter> trans = sequencer.getTransmitters();
    log("  sequencer has " + trans.size() + " opened transmitters:");
    for (Transmitter tr : trans) {
        Receiver r = tr.getReceiver();
        log("    " + getClassStr(tr) + " connected to " + getClassStr(r));
        if (r instanceof MidiDeviceReceiver) {
            MidiDeviceReceiver recv = (MidiDeviceReceiver) r;
            MidiDevice dev = recv.getMidiDevice();
            log("      - receiver of " + getClassStr(dev));
            return dev;
        } else {
            log("      - does NOT implement MidiDeviceReceiver");
        }
    }
    return null;
}
Also used : Transmitter(javax.sound.midi.Transmitter) MidiDeviceReceiver(javax.sound.midi.MidiDeviceReceiver) Receiver(javax.sound.midi.Receiver) MidiDeviceReceiver(javax.sound.midi.MidiDeviceReceiver) MidiDevice(javax.sound.midi.MidiDevice)

Aggregations

Receiver (javax.sound.midi.Receiver)11 MidiUnavailableException (javax.sound.midi.MidiUnavailableException)4 AudioSynthesizer (com.sun.media.sound.AudioSynthesizer)3 SoftSynthesizer (com.sun.media.sound.SoftSynthesizer)3 MidiDevice (javax.sound.midi.MidiDevice)2 MidiDeviceReceiver (javax.sound.midi.MidiDeviceReceiver)2 ShortMessage (javax.sound.midi.ShortMessage)2 Transmitter (javax.sound.midi.Transmitter)2 AudioInputStream (javax.sound.sampled.AudioInputStream)2 SoftReceiver (com.sun.media.sound.SoftReceiver)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Random (java.util.Random)1 MetaMessage (javax.sound.midi.MetaMessage)1 MidiDeviceTransmitter (javax.sound.midi.MidiDeviceTransmitter)1 MidiEvent (javax.sound.midi.MidiEvent)1 MidiMessage (javax.sound.midi.MidiMessage)1 Soundbank (javax.sound.midi.Soundbank)1 Synthesizer (javax.sound.midi.Synthesizer)1 Track (javax.sound.midi.Track)1