Example usage for javax.sound.midi MidiUnavailableException printStackTrace

List of usage examples for javax.sound.midi MidiUnavailableException printStackTrace

Introduction

In this page you can find the example usage for javax.sound.midi MidiUnavailableException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

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

/**
 * Enables or disables a MIDI input device
 * //from   ww w  .j a v  a2 s  .  c  o m
 * @param sMidiDevice The name of the MIDI device to toggle
 */
public void actionAddMidiInput(String sMidiDevice) {
    Info[] midiInfo = MidiSystem.getMidiDeviceInfo();
    MidiDevice midiDevice;

    for (int i = 0; i < midiInfo.length; i++) {
        try {
            midiDevice = MidiSystem.getMidiDevice(midiInfo[i]);
            if (sMidiDevice.compareTo(midiDevice.getDeviceInfo().toString()) == 0) {
                if (midiDevice.getMaxTransmitters() != 0) {
                    MidiDeviceFactory.toggleMidiInDevice(midiDevice);
                }
            }
        } catch (MidiUnavailableException e) {
            e.printStackTrace();
        }
    }
}

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

/**
 * Enables or disables a MIDI output device
 * //  w ww  . ja  v  a  2 s  .  c om
 * @param sMidiDevice The MIDI output device to enable or disable
 */
public void actionAddMidiOutput(String sMidiDevice) {
    Info[] midiInfo = MidiSystem.getMidiDeviceInfo();
    MidiDevice midiDevice;

    for (int i = 0; i < midiInfo.length; i++) {
        try {
            midiDevice = MidiSystem.getMidiDevice(midiInfo[i]);
            if (sMidiDevice.compareTo(midiDevice.getDeviceInfo().toString()) == 0) {
                if (midiDevice.getMaxReceivers() != 0) {
                    MidiDeviceFactory.toggleMidiOutDevice(midiDevice);
                }
            }
        } catch (MidiUnavailableException e) {
            e.printStackTrace();
        }
    }
}

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 va  2 s  . c  o  m
 * @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.
 * //from ww  w.  j av  a2 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();
    }
}