Path: blob/master/src/java.desktop/share/classes/com/sun/media/sound/MidiOutDeviceProvider.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 output device provider.31*32* @author Kara Kytle33* @author Florian Bomers34*/35public final class MidiOutDeviceProvider 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 output 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 MidiOutDeviceProvider() {55}5657@Override58AbstractMidiDeviceProvider.Info createInfo(int index) {59if (!enabled) {60return null;61}62return new MidiOutDeviceInfo(index, MidiOutDeviceProvider.class);63}6465@Override66MidiDevice createDevice(AbstractMidiDeviceProvider.Info info) {67if (enabled && (info instanceof MidiOutDeviceInfo)) {68return new MidiOutDevice(info);69}70return null;71}7273@Override74int getNumDevices() {75if (!enabled) {76return 0;77}78return nGetNumDevices();79}8081@Override82MidiDevice[] getDeviceCache() { return devices; }83@Override84void setDeviceCache(MidiDevice[] devices) { MidiOutDeviceProvider.devices = devices; }85@Override86Info[] getInfoCache() { return infos; }87@Override88void setInfoCache(Info[] infos) { MidiOutDeviceProvider.infos = infos; }8990/**91* Info class for MidiOutDevices. Adds the92* provider's Class to keep the provider class from being93* unloaded. Otherwise, at least on JDK1.1.7 and 1.1.8,94* the provider class can be unloaded. Then, then the provider95* is next invoked, the static block is executed again and a new96* instance of the device object is created. Even though the97* previous instance may still exist and be open / in use / etc.,98* the new instance will not reflect that state...99*/100static final class MidiOutDeviceInfo extends AbstractMidiDeviceProvider.Info {101private final Class<?> providerClass;102103private MidiOutDeviceInfo(int index, Class<?> providerClass) {104super(nGetName(index), nGetVendor(index), nGetDescription(index), nGetVersion(index), index);105this.providerClass = providerClass;106}107108} // class MidiOutDeviceInfo109110private static native int nGetNumDevices();111private static native String nGetName(int index);112private static native String nGetVendor(int index);113private static native String nGetDescription(int index);114private static native String nGetVersion(int index);115}116117118