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

Java examples for javax.sound.midi:MidiSystem

Description

get Midi Out Driver List

Demo Code

/*******************************************************************************
 * Copyright (c) 2013 Shuichi Miura./*from   w  w  w . ja  v 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 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> getMidiOutDriverList() {

        Info[] infoArray = MidiSystem.getMidiDeviceInfo();

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

        for (Info info : infoArray) {

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

                int recMax = device.getMaxReceivers();
                int trsMax = device.getMaxTransmitters();

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

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

            } catch (MidiUnavailableException ex) {

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

        return deviceList;
    }
}

Related Tutorials