Search in sources :

Example 1 with MidiDevice

use of javax.sound.midi.MidiDevice 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 2 with MidiDevice

use of javax.sound.midi.MidiDevice 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)

Example 3 with MidiDevice

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

the class SequencerImplicitSynthOpen method test.

static boolean test(Sequencer sequencer) throws MidiUnavailableException {
    log("");
    log("opening sequencer...");
    // opens connected synthesizer implicitly
    sequencer.open();
    MidiDevice synth = getConnectedDevice(sequencer);
    log("  connected device: " + getDeviceStr(synth));
    log("closing sequencer...");
    // closes the synth implicitly
    sequencer.close();
    log("  synth is " + getDeviceStr(synth));
    MidiDevice synth2 = getConnectedDevice(sequencer);
    log("  currently connected device: " + getDeviceStr(synth2));
    if (synth != null && synth.isOpen()) {
        log("FAIL.");
        return false;
    }
    log("OK.");
    return true;
}
Also used : MidiDevice(javax.sound.midi.MidiDevice)

Example 4 with MidiDevice

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

the class SequencerImplicitSynthOpen method main.

public static void main(String[] args) {
    try {
        log("getting sequencer...");
        Sequencer sequencer = MidiSystem.getSequencer();
        log("  - got " + getDeviceStr(sequencer));
        // obtain connected device (usually synthesizer)
        MidiDevice synth = getConnectedDevice(sequencer);
        if (synth == null) {
            log("could not get connected device, returning");
            return;
        }
        log("connected device: " + getDeviceStr(synth));
        int success = 0;
        for (int i = 0; i < TEST_COUNT; i++) {
            if (test(sequencer)) {
                success++;
            }
        }
        if (success != TEST_COUNT) {
            throw new RuntimeException("test FAILS");
        }
    } catch (MidiUnavailableException ex) {
        // this is not a failure
        log("Could not get Sequencer");
    }
    log("test PASSED.");
}
Also used : Sequencer(javax.sound.midi.Sequencer) MidiUnavailableException(javax.sound.midi.MidiUnavailableException) MidiDevice(javax.sound.midi.MidiDevice)

Example 5 with MidiDevice

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

the class GetDevice method main.

public static void main(String[] args) throws Exception {
    SoftProvider provider = new SoftProvider();
    Info[] infos = provider.getDeviceInfo();
    assertTrue(infos.length > 0);
    for (int i = 0; i < infos.length; i++) {
        assertTrue(infos[i] != null);
        MidiDevice d = provider.getDevice(infos[i]);
        assertTrue(d instanceof SoftSynthesizer);
    }
    assertTrue(provider.getDevice(new FakeInfo()) == null);
}
Also used : MidiDevice(javax.sound.midi.MidiDevice) Info(javax.sound.midi.MidiDevice.Info)

Aggregations

MidiDevice (javax.sound.midi.MidiDevice)5 MidiDeviceReceiver (javax.sound.midi.MidiDeviceReceiver)2 MidiUnavailableException (javax.sound.midi.MidiUnavailableException)2 Receiver (javax.sound.midi.Receiver)2 Transmitter (javax.sound.midi.Transmitter)2 Info (javax.sound.midi.MidiDevice.Info)1 MidiDeviceTransmitter (javax.sound.midi.MidiDeviceTransmitter)1 Sequencer (javax.sound.midi.Sequencer)1