Returns an array of MidiDevice.Info for MIDI input device. - Java javax.sound.midi

Java examples for javax.sound.midi:MidiDevice

Description

Returns an array of MidiDevice.Info for MIDI input device.

Demo Code

/*//  www.j  av  a2s.co m
 * 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
 */
//package com.java2s;

import javax.sound.midi.*;
import java.util.*;

public class Main {
    /** emulate the no MIDI device condition for debugging */
    private final static boolean EMULATE_NO_MIDI_IN = false;

    /** Returns an array of MidiDevice.Info for MIDI input device. */
    private static MidiDevice.Info[] createInputMidiDeviceInfo()
            throws MidiUnavailableException {
        ArrayList list = new ArrayList();

        MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
        for (int i = 0; i < infos.length; i++) {
            // throws MidiUnavailableException
            MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
            if (device.getMaxTransmitters() != 0
                    && !(device instanceof Synthesizer)
                    && !(device instanceof Sequencer)
                    && !EMULATE_NO_MIDI_IN)
                list.add(infos[i]);
        }
        return (MidiDevice.Info[]) list.toArray(new MidiDevice.Info[0]);
    }
}

Related Tutorials