author | serb |
Mon, 15 Aug 2016 20:08:55 +0300 | |
changeset 40444 | afabcfc2f3ef |
parent 32865 | f9cb6e427f9e |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22567
5816a47fa4dd
8032047: Fix static lint warnings in client libraries
darcy
parents:
18215
diff
changeset
|
2 |
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package com.sun.media.sound; |
|
27 |
||
28 |
import javax.sound.midi.MidiDevice; |
|
29 |
||
30 |
/** |
|
31 |
* MIDI output device provider. |
|
32 |
* |
|
33 |
* @author Kara Kytle |
|
34 |
* @author Florian Bomers |
|
35 |
*/ |
|
18215 | 36 |
public final class MidiOutDeviceProvider extends AbstractMidiDeviceProvider { |
2 | 37 |
|
38 |
/** Cache of info objects for all MIDI output devices on the system. */ |
|
18215 | 39 |
private static Info[] infos = null; |
2 | 40 |
|
41 |
/** Cache of open MIDI output devices on the system. */ |
|
18215 | 42 |
private static MidiDevice[] devices = null; |
2 | 43 |
|
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
25859
diff
changeset
|
44 |
private static final boolean enabled; |
2 | 45 |
|
46 |
static { |
|
47 |
// initialize |
|
48 |
Platform.initialize(); |
|
49 |
enabled = Platform.isMidiIOEnabled(); |
|
50 |
} |
|
51 |
||
52 |
/** |
|
53 |
* Required public no-arg constructor. |
|
54 |
*/ |
|
55 |
public MidiOutDeviceProvider() { |
|
56 |
if (Printer.trace) Printer.trace("MidiOutDeviceProvider: constructor"); |
|
57 |
} |
|
58 |
||
40444
afabcfc2f3ef
8163949: Cleanup of classes which are related to JavaSound
serb
parents:
32865
diff
changeset
|
59 |
@Override |
2 | 60 |
AbstractMidiDeviceProvider.Info createInfo(int index) { |
61 |
if (!enabled) { |
|
62 |
return null; |
|
63 |
} |
|
64 |
return new MidiOutDeviceInfo(index, MidiOutDeviceProvider.class); |
|
65 |
} |
|
66 |
||
40444
afabcfc2f3ef
8163949: Cleanup of classes which are related to JavaSound
serb
parents:
32865
diff
changeset
|
67 |
@Override |
2 | 68 |
MidiDevice createDevice(AbstractMidiDeviceProvider.Info info) { |
69 |
if (enabled && (info instanceof MidiOutDeviceInfo)) { |
|
70 |
return new MidiOutDevice(info); |
|
71 |
} |
|
72 |
return null; |
|
73 |
} |
|
74 |
||
40444
afabcfc2f3ef
8163949: Cleanup of classes which are related to JavaSound
serb
parents:
32865
diff
changeset
|
75 |
@Override |
2 | 76 |
int getNumDevices() { |
77 |
if (!enabled) { |
|
78 |
if (Printer.debug)Printer.debug("MidiOutDevice not enabled, returning 0 devices"); |
|
79 |
return 0; |
|
80 |
} |
|
81 |
return nGetNumDevices(); |
|
82 |
} |
|
83 |
||
40444
afabcfc2f3ef
8163949: Cleanup of classes which are related to JavaSound
serb
parents:
32865
diff
changeset
|
84 |
@Override |
2 | 85 |
MidiDevice[] getDeviceCache() { return devices; } |
40444
afabcfc2f3ef
8163949: Cleanup of classes which are related to JavaSound
serb
parents:
32865
diff
changeset
|
86 |
@Override |
22567
5816a47fa4dd
8032047: Fix static lint warnings in client libraries
darcy
parents:
18215
diff
changeset
|
87 |
void setDeviceCache(MidiDevice[] devices) { MidiOutDeviceProvider.devices = devices; } |
40444
afabcfc2f3ef
8163949: Cleanup of classes which are related to JavaSound
serb
parents:
32865
diff
changeset
|
88 |
@Override |
2 | 89 |
Info[] getInfoCache() { return infos; } |
40444
afabcfc2f3ef
8163949: Cleanup of classes which are related to JavaSound
serb
parents:
32865
diff
changeset
|
90 |
@Override |
22567
5816a47fa4dd
8032047: Fix static lint warnings in client libraries
darcy
parents:
18215
diff
changeset
|
91 |
void setInfoCache(Info[] infos) { MidiOutDeviceProvider.infos = infos; } |
2 | 92 |
|
93 |
/** |
|
94 |
* Info class for MidiOutDevices. Adds the |
|
95 |
* provider's Class to keep the provider class from being |
|
96 |
* unloaded. Otherwise, at least on JDK1.1.7 and 1.1.8, |
|
97 |
* the provider class can be unloaded. Then, then the provider |
|
98 |
* is next invoked, the static block is executed again and a new |
|
99 |
* instance of the device object is created. Even though the |
|
100 |
* previous instance may still exist and be open / in use / etc., |
|
101 |
* the new instance will not reflect that state... |
|
102 |
*/ |
|
18215 | 103 |
static final class MidiOutDeviceInfo extends AbstractMidiDeviceProvider.Info { |
24548
9c007a986347
8042256: Fix raw and unchecked lint warnings in com.sun.media.sound
darcy
parents:
22567
diff
changeset
|
104 |
private final Class<?> providerClass; |
2 | 105 |
|
24548
9c007a986347
8042256: Fix raw and unchecked lint warnings in com.sun.media.sound
darcy
parents:
22567
diff
changeset
|
106 |
private MidiOutDeviceInfo(int index, Class<?> providerClass) { |
2 | 107 |
super(nGetName(index), nGetVendor(index), nGetDescription(index), nGetVersion(index), index); |
108 |
this.providerClass = providerClass; |
|
109 |
} |
|
110 |
||
111 |
} // class MidiOutDeviceInfo |
|
112 |
||
113 |
private static native int nGetNumDevices(); |
|
114 |
private static native String nGetName(int index); |
|
115 |
private static native String nGetVendor(int index); |
|
116 |
private static native String nGetDescription(int index); |
|
117 |
private static native String nGetVersion(int index); |
|
118 |
} |