Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/media/sound/MidiOutDeviceProvider.java
38924 views
/*1* Copyright (c) 1999, 2013, 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;282930/**31* MIDI output device provider.32*33* @author Kara Kytle34* @author Florian Bomers35*/36public final class MidiOutDeviceProvider extends AbstractMidiDeviceProvider {3738/** Cache of info objects for all MIDI output devices on the system. */39private static Info[] infos = null;4041/** Cache of open MIDI output devices on the system. */42private static MidiDevice[] devices = null;4344private final static boolean enabled;4546// STATIC4748static {49// initialize50Platform.initialize();51enabled = Platform.isMidiIOEnabled();52}5354// CONSTRUCTOR5556/**57* Required public no-arg constructor.58*/59public MidiOutDeviceProvider() {60if (Printer.trace) Printer.trace("MidiOutDeviceProvider: constructor");61}6263// implementation of abstract methods in AbstractMidiDeviceProvider6465AbstractMidiDeviceProvider.Info createInfo(int index) {66if (!enabled) {67return null;68}69return new MidiOutDeviceInfo(index, MidiOutDeviceProvider.class);70}7172MidiDevice createDevice(AbstractMidiDeviceProvider.Info info) {73if (enabled && (info instanceof MidiOutDeviceInfo)) {74return new MidiOutDevice(info);75}76return null;77}7879int getNumDevices() {80if (!enabled) {81if (Printer.debug)Printer.debug("MidiOutDevice not enabled, returning 0 devices");82return 0;83}84return nGetNumDevices();85}8687MidiDevice[] getDeviceCache() { return devices; }88void setDeviceCache(MidiDevice[] devices) { this.devices = devices; }89Info[] getInfoCache() { return infos; }90void setInfoCache(Info[] infos) { this.infos = infos; }919293// INNER CLASSES9495/**96* Info class for MidiOutDevices. Adds the97* provider's Class to keep the provider class from being98* unloaded. Otherwise, at least on JDK1.1.7 and 1.1.8,99* the provider class can be unloaded. Then, then the provider100* is next invoked, the static block is executed again and a new101* instance of the device object is created. Even though the102* previous instance may still exist and be open / in use / etc.,103* the new instance will not reflect that state...104*/105static final class MidiOutDeviceInfo extends AbstractMidiDeviceProvider.Info {106private final Class providerClass;107108private MidiOutDeviceInfo(int index, Class providerClass) {109super(nGetName(index), nGetVendor(index), nGetDescription(index), nGetVersion(index), index);110this.providerClass = providerClass;111}112113} // class MidiOutDeviceInfo114115116// NATIVE METHODS117118private static native int nGetNumDevices();119private static native String nGetName(int index);120private static native String nGetVendor(int index);121private static native String nGetDescription(int index);122private static native String nGetVersion(int index);123}124125126