get Midi In Device - Java javax.sound.midi

Java examples for javax.sound.midi:MidiSystem

Description

get Midi In Device

Demo Code

/*******************************************************************************
 * Copyright (c) 2013 Shuichi Miura.//from w w  w  .j  av a 2  s  .  c o m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     Shuichi Miura - initial API and implementation
 ******************************************************************************/
//package com.java2s;

import javax.sound.midi.MidiDevice;

import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;

public class Main {
    public static MidiDevice getMidiInDevice(String deviceName)
            throws MidiUnavailableException {

        MidiDevice.Info[] infoArray = MidiSystem.getMidiDeviceInfo();

        for (MidiDevice.Info info : infoArray) {

            MidiDevice device = MidiSystem.getMidiDevice(info);

            int trsMax = device.getMaxTransmitters();

            if (trsMax == 0) {
                continue;
            }

            if (info.getName().equals(deviceName)) {

                return MidiSystem.getMidiDevice(info);
            }
        }

        return null;
    }
}

Related Tutorials