get Midi In Driver List - Java javax.sound.midi

Java examples for javax.sound.midi:MidiSystem

Description

get Midi In Driver List

Demo Code

/*******************************************************************************
 * Copyright (c) 2013 Shuichi Miura./*from  ww  w  .  j a  v a2s  .  co 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 java.util.ArrayList;
import java.util.List;
import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiDevice.Info;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;

public class Main {
    private static final int UNLIMITED = -1;

    public static List<String> getMidiInDriverList() {

        Info[] infoArray = MidiSystem.getMidiDeviceInfo();

        List<String> deviceList = new ArrayList<String>();

        for (Info info : infoArray) {

            try {
                MidiDevice device = MidiSystem.getMidiDevice(info);

                int trsMax = device.getMaxTransmitters();

                if (trsMax == UNLIMITED || trsMax > 0) {

                    deviceList.add(info.getName());
                }

            } catch (MidiUnavailableException ex) {

                System.out.println("Skip device :" + info.getName());
            }
        }

        return deviceList;
    }
}

Related Tutorials