0N/A/*
6321N/A * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.media.sound;
0N/A
0N/Aimport javax.sound.midi.MidiDevice;
0N/A
0N/A
0N/A/**
0N/A * MIDI input device provider.
0N/A *
0N/A * @author Kara Kytle
0N/A * @author Florian Bomers
0N/A */
6321N/Apublic final class MidiInDeviceProvider extends AbstractMidiDeviceProvider {
0N/A
0N/A /** Cache of info objects for all MIDI output devices on the system. */
6321N/A private static Info[] infos = null;
0N/A
0N/A /** Cache of open MIDI input devices on the system. */
6321N/A private static MidiDevice[] devices = null;
0N/A
6321N/A private static final boolean enabled;
0N/A
0N/A // STATIC
0N/A
0N/A static {
0N/A // initialize
0N/A Platform.initialize();
0N/A enabled = Platform.isMidiIOEnabled();
0N/A }
0N/A
0N/A // CONSTRUCTOR
0N/A
0N/A /**
0N/A * Required public no-arg constructor.
0N/A */
0N/A public MidiInDeviceProvider() {
0N/A if (Printer.trace) Printer.trace("MidiInDeviceProvider: constructor");
0N/A }
0N/A
0N/A // implementation of abstract methods in AbstractMidiDeviceProvider
0N/A
0N/A AbstractMidiDeviceProvider.Info createInfo(int index) {
0N/A if (!enabled) {
0N/A return null;
0N/A }
0N/A return new MidiInDeviceInfo(index, MidiInDeviceProvider.class);
0N/A }
0N/A
0N/A MidiDevice createDevice(AbstractMidiDeviceProvider.Info info) {
0N/A if (enabled && (info instanceof MidiInDeviceInfo)) {
0N/A return new MidiInDevice(info);
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A int getNumDevices() {
0N/A if (!enabled) {
0N/A if (Printer.debug)Printer.debug("MidiInDevice not enabled, returning 0 devices");
0N/A return 0;
0N/A }
0N/A int numDevices = nGetNumDevices();
0N/A if (Printer.debug)Printer.debug("MidiInDeviceProvider.getNumDevices(): devices: " + numDevices);
0N/A return numDevices;
0N/A }
0N/A
0N/A MidiDevice[] getDeviceCache() { return devices; }
0N/A void setDeviceCache(MidiDevice[] devices) { this.devices = devices; }
0N/A Info[] getInfoCache() { return infos; }
0N/A void setInfoCache(Info[] infos) { this.infos = infos; }
0N/A
0N/A
0N/A // INNER CLASSES
0N/A
0N/A /**
0N/A * Info class for MidiInDevices. Adds the
0N/A * provider's Class to keep the provider class from being
0N/A * unloaded. Otherwise, at least on JDK1.1.7 and 1.1.8,
0N/A * the provider class can be unloaded. Then, then the provider
0N/A * is next invoked, the static block is executed again and a new
0N/A * instance of the device object is created. Even though the
0N/A * previous instance may still exist and be open / in use / etc.,
0N/A * the new instance will not reflect that state...
0N/A */
6321N/A static final class MidiInDeviceInfo extends AbstractMidiDeviceProvider.Info {
6321N/A private final Class providerClass;
0N/A
0N/A private MidiInDeviceInfo(int index, Class providerClass) {
0N/A super(nGetName(index), nGetVendor(index), nGetDescription(index), nGetVersion(index), index);
0N/A this.providerClass = providerClass;
0N/A }
0N/A
0N/A } // class MidiInDeviceInfo
0N/A
0N/A
0N/A // NATIVE METHODS
0N/A
0N/A private static native int nGetNumDevices();
0N/A private static native String nGetName(int index);
0N/A private static native String nGetVendor(int index);
0N/A private static native String nGetDescription(int index);
0N/A private static native String nGetVersion(int index);
0N/A}