Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
a50f40f7
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a50f40f7
编写于
9月 14, 2010
作者:
A
amenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
4933700: RFE: Add way to get device from Receiver and Transmitter
Reviewed-by: art
上级
50664a88
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
392 addition
and
11 deletion
+392
-11
src/share/classes/com/sun/media/sound/AbstractMidiDevice.java
...share/classes/com/sun/media/sound/AbstractMidiDevice.java
+9
-2
src/share/classes/com/sun/media/sound/MidiDeviceReceiverEnvelope.java
...asses/com/sun/media/sound/MidiDeviceReceiverEnvelope.java
+80
-0
src/share/classes/com/sun/media/sound/MidiDeviceTransmitterEnvelope.java
...es/com/sun/media/sound/MidiDeviceTransmitterEnvelope.java
+85
-0
src/share/classes/com/sun/media/sound/SoftReceiver.java
src/share/classes/com/sun/media/sound/SoftReceiver.java
+1
-0
src/share/classes/javax/sound/midi/MidiDevice.java
src/share/classes/javax/sound/midi/MidiDevice.java
+14
-0
src/share/classes/javax/sound/midi/MidiDeviceReceiver.java
src/share/classes/javax/sound/midi/MidiDeviceReceiver.java
+7
-9
src/share/classes/javax/sound/midi/MidiDeviceTransmitter.java
...share/classes/javax/sound/midi/MidiDeviceTransmitter.java
+41
-0
src/share/classes/javax/sound/midi/MidiSystem.java
src/share/classes/javax/sound/midi/MidiSystem.java
+12
-0
test/javax/sound/midi/MidiDeviceConnectors/TestAllDevices.java
...javax/sound/midi/MidiDeviceConnectors/TestAllDevices.java
+143
-0
未找到文件。
src/share/classes/com/sun/media/sound/AbstractMidiDevice.java
浏览文件 @
a50f40f7
...
...
@@ -474,7 +474,7 @@ abstract class AbstractMidiDevice implements MidiDevice, ReferenceCountingDevice
This is necessary for Receivers retrieved via MidiSystem.getReceiver()
(which opens the device implicitely).
*/
protected
abstract
class
AbstractReceiver
implements
Receiver
{
protected
abstract
class
AbstractReceiver
implements
MidiDevice
Receiver
{
private
boolean
open
=
true
;
...
...
@@ -508,6 +508,10 @@ abstract class AbstractMidiDevice implements MidiDevice, ReferenceCountingDevice
AbstractMidiDevice
.
this
.
closeInternal
(
this
);
}
public
MidiDevice
getMidiDevice
()
{
return
AbstractMidiDevice
.
this
;
}
protected
boolean
isOpen
()
{
return
open
;
}
...
...
@@ -529,7 +533,7 @@ abstract class AbstractMidiDevice implements MidiDevice, ReferenceCountingDevice
* Also, it has some optimizations regarding sending to the Receivers,
* for known Receivers, and managing itself in the TransmitterList.
*/
protected
class
BasicTransmitter
implements
Transmitter
{
protected
class
BasicTransmitter
implements
MidiDevice
Transmitter
{
private
Receiver
receiver
=
null
;
TransmitterList
tlist
=
null
;
...
...
@@ -568,6 +572,9 @@ abstract class AbstractMidiDevice implements MidiDevice, ReferenceCountingDevice
}
}
public
MidiDevice
getMidiDevice
()
{
return
AbstractMidiDevice
.
this
;
}
}
// class BasicTransmitter
...
...
src/share/classes/com/sun/media/sound/MidiDeviceReceiverEnvelope.java
0 → 100644
浏览文件 @
a50f40f7
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package
com.sun.media.sound
;
import
javax.sound.midi.*
;
/**
* Helper class which allows to convert {@code Receiver}
* to {@code MidiDeviceReceiver}.
*
* @author Alex Menkov
*/
public
class
MidiDeviceReceiverEnvelope
implements
MidiDeviceReceiver
{
private
final
MidiDevice
device
;
private
final
Receiver
receiver
;
/**
* Creates a new {@code MidiDeviceReceiverEnvelope} object which
* envelops the specified {@code Receiver}
* and is owned by the specified {@code MidiDevice}.
*
* @param device the owner {@code MidiDevice}
* @param receiver the {@code Receiver} to be enveloped
*/
public
MidiDeviceReceiverEnvelope
(
MidiDevice
device
,
Receiver
receiver
)
{
if
(
device
==
null
||
receiver
==
null
)
{
throw
new
NullPointerException
();
}
this
.
device
=
device
;
this
.
receiver
=
receiver
;
}
// Receiver implementation
public
void
close
()
{
receiver
.
close
();
}
public
void
send
(
MidiMessage
message
,
long
timeStamp
)
{
receiver
.
send
(
message
,
timeStamp
);
}
// MidiDeviceReceiver implementation
public
MidiDevice
getMidiDevice
()
{
return
device
;
}
/**
* Obtains the receiver enveloped
* by this {@code MidiDeviceReceiverEnvelope} object.
*
* @return the enveloped receiver
*/
public
Receiver
getReceiver
()
{
return
receiver
;
}
}
src/share/classes/com/sun/media/sound/MidiDeviceTransmitterEnvelope.java
0 → 100644
浏览文件 @
a50f40f7
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package
com.sun.media.sound
;
import
javax.sound.midi.*
;
/**
* Helper class which allows to convert {@code Transmitter}
* to {@code MidiDeviceTransmitter}.
*
* @author Alex Menkov
*/
public
class
MidiDeviceTransmitterEnvelope
implements
MidiDeviceTransmitter
{
private
final
MidiDevice
device
;
private
final
Transmitter
transmitter
;
/**
* Creates a new {@code MidiDeviceTransmitterEnvelope} object which
* envelops the specified {@code Transmitter}
* and is owned by the specified {@code MidiDevice}.
*
* @param device the owner {@code MidiDevice}
* @param transmitter the {@code Transmitter} to be enveloped
*/
public
MidiDeviceTransmitterEnvelope
(
MidiDevice
device
,
Transmitter
transmitter
)
{
if
(
device
==
null
||
transmitter
==
null
)
{
throw
new
NullPointerException
();
}
this
.
device
=
device
;
this
.
transmitter
=
transmitter
;
}
// Transmitter implementation
public
void
setReceiver
(
Receiver
receiver
)
{
transmitter
.
setReceiver
(
receiver
);
}
public
Receiver
getReceiver
()
{
return
transmitter
.
getReceiver
();
}
public
void
close
()
{
transmitter
.
close
();
}
// MidiDeviceReceiver implementation
public
MidiDevice
getMidiDevice
()
{
return
device
;
}
/**
* Obtains the transmitter enveloped
* by this {@code MidiDeviceTransmitterEnvelope} object.
*
* @return the enveloped transmitter
*/
public
Transmitter
getTransmitter
()
{
return
transmitter
;
}
}
src/share/classes/com/sun/media/sound/SoftReceiver.java
浏览文件 @
a50f40f7
...
...
@@ -27,6 +27,7 @@ package com.sun.media.sound;
import
java.util.TreeMap
;
import
javax.sound.midi.MidiDevice
;
import
javax.sound.midi.MidiDeviceReceiver
;
import
javax.sound.midi.MidiMessage
;
import
javax.sound.midi.ShortMessage
;
...
...
src/share/classes/javax/sound/midi/MidiDevice.java
浏览文件 @
a50f40f7
...
...
@@ -204,6 +204,9 @@ public interface MidiDevice extends AutoCloseable {
* MIDI data. The returned receiver must be closed when the application
* has finished using it.
*
* <p>Usually the returned receiver implements
* the {@code MidiDeviceReceiver} interface.
*
* <p>Obtaining a <code>Receiver</code> with this method does not
* open the device. To be able to use the device, it has to be
* opened explicitly by calling {@link #open}. Also, closing the
...
...
@@ -223,6 +226,10 @@ public interface MidiDevice extends AutoCloseable {
* connected with this MidiDevice.
* A receiver can be removed
* from the device by closing it.
*
* <p>Usually the returned receivers implement
* the {@code MidiDeviceReceiver} interface.
*
* @return an unmodifiable list of the open receivers
* @since 1.5
*/
...
...
@@ -234,6 +241,9 @@ public interface MidiDevice extends AutoCloseable {
* MIDI data The returned transmitter must be closed when the application
* has finished using it.
*
* <p>Usually the returned transmitter implements
* the {@code MidiDeviceTransmitter} interface.
*
* <p>Obtaining a <code>Transmitter</code> with this method does not
* open the device. To be able to use the device, it has to be
* opened explicitly by calling {@link #open}. Also, closing the
...
...
@@ -253,6 +263,10 @@ public interface MidiDevice extends AutoCloseable {
* connected with this MidiDevice.
* A transmitter can be removed
* from the device by closing it.
*
* <p>Usually the returned transmitters implement
* the {@code MidiDeviceTransmitter} interface.
*
* @return an unmodifiable list of the open transmitters
* @since 1.5
*/
...
...
src/share/classes/
com/sun/media/sound
/MidiDeviceReceiver.java
→
src/share/classes/
javax/sound/midi
/MidiDeviceReceiver.java
浏览文件 @
a50f40f7
/*
* Copyright (c) 20
09
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 20
10
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
...
...
@@ -22,20 +22,18 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package
com.sun.media.sound
;
import
javax.sound.midi.MidiDevice
;
import
javax.sound.midi.Receiver
;
package
javax.sound.midi
;
/**
* A Receiver with reference to it's MidiDevice object.
* <p>{@code MidiDeviceReceiver} is a {@code Receiver} which represents
* a MIDI input connector of a {@code MidiDevice}
* (see {@link MidiDevice#getReceiver()}).
*
* @
author Karl Helgason
* @
since 1.7
*/
public
interface
MidiDeviceReceiver
extends
Receiver
{
/** Obtains the MidiDevice object associated with this Receiver.
/** Obtains a MidiDevice object which is an owner of this Receiver.
*/
public
MidiDevice
getMidiDevice
();
}
src/share/classes/javax/sound/midi/MidiDeviceTransmitter.java
0 → 100644
浏览文件 @
a50f40f7
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package
javax.sound.midi
;
/**
* <p>{@code MidiDeviceTransmitter} is a {@code Transmitter} which represents
* a MIDI input connector of a {@code MidiDevice}
* (see {@link MidiDevice#getTransmitter()}).
*
* @since 1.7
*/
public
interface
MidiDeviceTransmitter
extends
Transmitter
{
/** Obtains a MidiDevice object which is an owner of this Transmitter.
*/
public
MidiDevice
getMidiDevice
();
}
src/share/classes/javax/sound/midi/MidiSystem.java
浏览文件 @
a50f40f7
...
...
@@ -47,6 +47,8 @@ import javax.sound.midi.spi.MidiDeviceProvider;
import
com.sun.media.sound.JDK13Services
;
import
com.sun.media.sound.ReferenceCountingDevice
;
import
com.sun.media.sound.AutoConnectSequencer
;
import
com.sun.media.sound.MidiDeviceReceiverEnvelope
;
import
com.sun.media.sound.MidiDeviceTransmitterEnvelope
;
/**
...
...
@@ -225,6 +227,8 @@ public class MidiSystem {
/**
* Obtains a MIDI receiver from an external MIDI port
* or other default device.
* The returned receiver always implements
* the {@code MidiDeviceReceiver} interface.
*
* <p>If the system property
* <code>javax.sound.midi.Receiver</code>
...
...
@@ -261,6 +265,9 @@ public class MidiSystem {
}
else
{
receiver
=
device
.
getReceiver
();
}
if
(!(
receiver
instanceof
MidiDeviceReceiver
))
{
receiver
=
new
MidiDeviceReceiverEnvelope
(
device
,
receiver
);
}
return
receiver
;
}
...
...
@@ -268,6 +275,8 @@ public class MidiSystem {
/**
* Obtains a MIDI transmitter from an external MIDI port
* or other default source.
* The returned transmitter always implements
* the {@code MidiDeviceTransmitter} interface.
*
* <p>If the system property
* <code>javax.sound.midi.Transmitter</code>
...
...
@@ -301,6 +310,9 @@ public class MidiSystem {
}
else
{
transmitter
=
device
.
getTransmitter
();
}
if
(!(
transmitter
instanceof
MidiDeviceReceiver
))
{
transmitter
=
new
MidiDeviceTransmitterEnvelope
(
device
,
transmitter
);
}
return
transmitter
;
}
...
...
test/javax/sound/midi/MidiDeviceConnectors/TestAllDevices.java
0 → 100644
浏览文件 @
a50f40f7
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 4933700
* @summary Tests that default devices return MidiDeviceTransmitter/Receiver and returned objects return correct MidiDevice
* @compile -source 1.7 TestAllDevices.java
* @run main TestAllDevices
* @author Alex Menkov
*/
import
javax.sound.midi.MidiDevice
;
import
javax.sound.midi.MidiDeviceReceiver
;
import
javax.sound.midi.MidiDeviceTransmitter
;
import
javax.sound.midi.MidiSystem
;
import
javax.sound.midi.MidiUnavailableException
;
import
javax.sound.midi.Receiver
;
import
javax.sound.midi.Transmitter
;
public
class
TestAllDevices
{
static
boolean
failed
=
false
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
out
(
"default receiver:"
);
try
{
Receiver
recv
=
MidiSystem
.
getReceiver
();
out
(
" receiver: "
+
recv
);
if
(
recv
instanceof
MidiDeviceReceiver
)
{
out
(
" OK"
);
}
else
{
out
(
" ERROR: not an instance of MidiDeviceReceiver"
);
failed
=
true
;
}
}
catch
(
MidiUnavailableException
ex
)
{
// this is not an error
out
(
" receiver: MidiUnavailableException (test NOT failed)"
);
}
out
(
"default transmitter:"
);
try
{
Transmitter
tran
=
MidiSystem
.
getTransmitter
();
out
(
" transmitter: "
+
tran
);
if
(
tran
instanceof
MidiDeviceTransmitter
)
{
out
(
" OK"
);
}
else
{
out
(
" ERROR: not an instance of MidiDeviceTransmitter"
);
failed
=
true
;
}
}
catch
(
MidiUnavailableException
ex
)
{
// this is not an error
out
(
" transmitter: MidiUnavailableException (test NOT failed)"
);
}
MidiDevice
.
Info
[]
infos
=
MidiSystem
.
getMidiDeviceInfo
();
for
(
MidiDevice
.
Info
info:
infos
)
{
out
(
info
.
toString
()
+
":"
);
try
{
MidiDevice
dev
=
MidiSystem
.
getMidiDevice
(
info
);
dev
.
open
();
try
{
Receiver
recv
=
dev
.
getReceiver
();
out
(
" receiver: "
+
recv
);
if
(
recv
instanceof
MidiDeviceReceiver
)
{
MidiDeviceReceiver
devRecv
=
(
MidiDeviceReceiver
)
recv
;
MidiDevice
retDev
=
devRecv
.
getMidiDevice
();
if
(
retDev
==
dev
)
{
out
(
" OK"
);
}
else
{
out
(
" ERROR: getMidiDevice returned incorrect device: "
+
retDev
);
failed
=
true
;
}
}
else
{
out
(
" ERROR: not an instance of MidiDeviceReceiver"
);
failed
=
true
;
}
}
catch
(
MidiUnavailableException
ex
)
{
// this is not an error
out
(
" receiver: MidiUnavailableException (test NOT failed)"
);
}
try
{
Transmitter
tran
=
dev
.
getTransmitter
();
out
(
" transmitter: "
+
tran
);
if
(
tran
instanceof
MidiDeviceTransmitter
)
{
MidiDeviceTransmitter
devTran
=
(
MidiDeviceTransmitter
)
tran
;
MidiDevice
retDev
=
devTran
.
getMidiDevice
();
if
(
retDev
==
dev
)
{
out
(
" OK"
);
}
else
{
out
(
" ERROR: getMidiDevice retur4ned incorrect device: "
+
retDev
);
failed
=
true
;
}
}
else
{
out
(
" ERROR: not an instance of MidiDeviceTransmitter"
);
failed
=
true
;
}
}
catch
(
MidiUnavailableException
ex
)
{
// this is not an error
out
(
" transmitter: MidiUnavailableException (test NOT failed)"
);
}
dev
.
close
();
}
catch
(
MidiUnavailableException
ex
)
{
out
(
" device: MidiUnavailableException (test NOT failed)"
);
}
}
if
(
failed
)
{
throw
new
Exception
(
"Test failed."
);
}
}
static
void
out
(
String
s
)
{
System
.
out
.
println
(
s
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录