Path: blob/master/src/java.desktop/share/classes/com/sun/media/sound/MidiInDeviceProvider.java
41161 views
/*1* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.media.sound;2627import javax.sound.midi.MidiDevice;2829/**30* MIDI input device provider.31*32* @author Kara Kytle33* @author Florian Bomers34*/35public final class MidiInDeviceProvider extends AbstractMidiDeviceProvider {3637/** Cache of info objects for all MIDI output devices on the system. */38private static Info[] infos = null;3940/** Cache of open MIDI input devices on the system. */41private static MidiDevice[] devices = null;4243private static final boolean enabled;4445static {46// initialize47Platform.initialize();48enabled = Platform.isMidiIOEnabled();49}5051/**52* Required public no-arg constructor.53*/54public MidiInDeviceProvider() {55}5657// implementation of abstract methods in AbstractMidiDeviceProvider5859@Override60AbstractMidiDeviceProvider.Info createInfo(int index) {61if (!enabled) {62return null;63}64return new MidiInDeviceInfo(index, MidiInDeviceProvider.class);65}6667@Override68MidiDevice createDevice(AbstractMidiDeviceProvider.Info info) {69if (enabled && (info instanceof MidiInDeviceInfo)) {70return new MidiInDevice(info);71}72return null;73}7475@Override76int getNumDevices() {77if (!enabled) {78return 0;79}80int numDevices = nGetNumDevices();81return numDevices;82}8384@Override85MidiDevice[] getDeviceCache() { return devices; }86@Override87void setDeviceCache(MidiDevice[] devices) { MidiInDeviceProvider.devices = devices; }88@Override89Info[] getInfoCache() { return infos; }90@Override91void setInfoCache(Info[] infos) { MidiInDeviceProvider.infos = infos; }9293/**94* Info class for MidiInDevices. Adds the95* provider's Class to keep the provider class from being96* unloaded. Otherwise, at least on JDK1.1.7 and 1.1.8,97* the provider class can be unloaded. Then, then the provider98* is next invoked, the static block is executed again and a new99* instance of the device object is created. Even though the100* previous instance may still exist and be open / in use / etc.,101* the new instance will not reflect that state...102*/103static final class MidiInDeviceInfo extends AbstractMidiDeviceProvider.Info {104private final Class<?> providerClass;105106private MidiInDeviceInfo(int index, Class<?> providerClass) {107super(nGetName(index), nGetVendor(index), nGetDescription(index), nGetVersion(index), index);108this.providerClass = providerClass;109}110111} // class MidiInDeviceInfo112113private static native int nGetNumDevices();114private static native String nGetName(int index);115private static native String nGetVendor(int index);116private static native String nGetDescription(int index);117private static native String nGetVersion(int index);118}119120121