get MidiDevice for Input. - Java javax.sound.midi

Java examples for javax.sound.midi:MidiDevice

Description

get MidiDevice for Input.

Demo Code

/*//ww w. j a  v a2  s .  c om
 * Copyright 2004 Hiroo Hayashi
 *
 * This file is part of JSynthLib.
 *
 * JSynthLib is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 2 of the License,
 * or(at your option) any later version.
 *
 * JSynthLib is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with JSynthLib; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */
import java.io.File;
import javax.sound.midi.*;
import java.util.*;

public class Main{
    private static MidiDevice.Info[] inputMidiDeviceInfo;
    /**
     * get MidiDevice for Input.
     *
     * @param port an index in an array returned by
     * <code>getInputMidiDeviceInfo()</code>.
     * @return a <code>MidiDevice</code> object for MIDI input.  The
     * MidiDevice is already opened.
     * @see #getInputMidiDeviceInfo()
     * @see #clearSysexInputQueue
     * @see #getMessage
     */
    private static MidiDevice getInputMidiDevice(int port) {
        MidiDevice dev = null;
        if (inputMidiDeviceInfo.length == 0)
            return null;
        try {
            dev = MidiSystem.getMidiDevice(inputMidiDeviceInfo[port]);
            if (!dev.isOpen()) {
                ErrorMsg.reportStatus("open inport: "
                        + dev.getDeviceInfo().getName() + ", port: " + port);
                dev.open();
            }
        } catch (MidiUnavailableException e) {
            ErrorMsg.reportStatus(e);
        }
        return dev;
    }
}

Related Tutorials