Example usage for javax.sound.midi MidiDevice getReceiver

List of usage examples for javax.sound.midi MidiDevice getReceiver

Introduction

In this page you can find the example usage for javax.sound.midi MidiDevice getReceiver.

Prototype

Receiver getReceiver() throws MidiUnavailableException;

Source Link

Document

Obtains a MIDI IN receiver through which the MIDI device may receive MIDI data.

Usage

From source file:de.ailis.midi4js.Midi4JS.java

/**
 * Returns MIDI IN receiver for the specified device. A receiver must
 * be closed when no longer needed.//from   ww w  . j av  a  2  s .co  m
 *
 * @param deviceHandle
 *            The handle of the MIDI device.
 * @return The handle of the receiver.
 * @throws MidiUnavailableException
 *             When MIDI device is unavailable.
 */
public int getReceiver(final int deviceHandle) throws MidiUnavailableException {
    final MidiDevice device = resolveDeviceHandle(deviceHandle);
    final Receiver receiver = device.getReceiver();
    final int receiverHandle = System.identityHashCode(receiver);
    this.receiverMap.put(receiverHandle, receiver);
    return receiverHandle;
}

From source file:org.monome.pages.Configuration.java

/**
 * Called when a MIDI output device is selected or de-selected from the MIDI menu
 * //from   w  w  w. ja  v  a 2s  .  c  om
 * @param midiOutDevice The MIDI output device to select or de-select
 */
public void toggleMidiOutDevice(MidiDevice midiOutDevice) {
    // check if the device is already enabled, if so disable it
    for (int i = 0; i < this.midiOutDevices.size(); i++) {
        if (this.midiOutDevices.get(i).equals(midiOutDevice)) {
            System.out.println(
                    "closing midi out device " + i + " / " + this.midiOutDevices.get(i).getDeviceInfo());
            MidiDevice outDevice = this.midiOutDevices.get(i);
            this.midiOutReceivers.remove(i);
            this.midiOutDevices.remove(i);
            outDevice.close();
            outDevice.close();
            return;
        }
    }

    // try to enable the device
    try {
        midiOutDevice.open();
        Receiver recv = midiOutDevice.getReceiver();
        this.midiOutDevices.add(midiOutDevice);
        this.midiOutReceivers.add(recv);
    } catch (MidiUnavailableException e) {
        e.printStackTrace();
    }
}