Example usage for javax.sound.midi MidiDevice close

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

Introduction

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

Prototype

@Override
void close();

Source Link

Document

Closes the device, indicating that the device should now release any system resources it is using.

Usage

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

/**
 * Closes the specified MIDI device./*from  w w w.j  av  a2s  . co  m*/
 *
 * @param deviceHandle
 *            The device handle.
 * @throws MidiUnavailableException
 *             When MIDI device is not available.
 */
public void closeMidiDevice(final int deviceHandle) throws MidiUnavailableException {
    final MidiDevice device = resolveDeviceHandle(deviceHandle);
    device.close();
}

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

/**
 * @see java.applet.Applet#stop()//from  w ww  .  ja  va2 s.  c  om
 */
@Override
public void stop() {
    for (final Receiver receiver : this.receiverMap.values())
        receiver.close();
    for (final Transmitter transmitter : this.transmitterMap.values())
        transmitter.close();
    for (final MidiDevice device : this.deviceMap.values())
        if (device.isOpen())
            device.close();
    this.deviceMap = null;
    this.receiverMap = null;
    this.transmitterMap = null;
    System.out.println("Stopped midi4js applet (Instance #" + System.identityHashCode(this) + ")");
}

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

/**
 * Called when a MIDI output device is selected or de-selected from the MIDI menu
 * /*from www  .j a v  a2 s.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();
    }
}

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

/**
 * Enables a MIDI in device to receive MIDI clock.
 * /*ww  w  .  j av  a  2 s . c o m*/
 * @param midiInDevice The MIDI input device to enable
 */
public void toggleMidiInDevice(MidiDevice midiInDevice) {
    // close the currently open device if we have one
    for (int i = 0; i < this.midiInDevices.size(); i++) {
        if (this.midiInDevices.get(i).equals(midiInDevice)) {
            MidiDevice inDevice = this.midiInDevices.get(i);
            System.out
                    .println("closing midi in device " + i + " / " + this.midiInDevices.get(i).getDeviceInfo());
            Transmitter transmitter = this.midiInTransmitters.get(i);
            this.midiInTransmitters.remove(i);
            this.midiInDevices.remove(i);
            transmitter.close();
            inDevice.close();
            return;
        }
    }

    // try to open the new midi in device
    try {
        midiInDevice.open();
        Transmitter transmitter = midiInDevice.getTransmitter();
        transmitter.setReceiver(this);
        this.midiInDevices.add(midiInDevice);
        this.midiInTransmitters.add(transmitter);
    } catch (MidiUnavailableException e) {
        e.printStackTrace();
    }
}