本文整理汇总了Java中javax.sound.midi.MidiDevice.close方法的典型用法代码示例。如果您正苦于以下问题:Java MidiDevice.close方法的具体用法?Java MidiDevice.close怎么用?Java MidiDevice.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.midi.MidiDevice
的用法示例。
在下文中一共展示了MidiDevice.close方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: close
import javax.sound.midi.MidiDevice; //导入方法依赖的package包/类
/**
* Closes the MIDI device.
*
* @param device the MIDI device.
*/
public static void close(MidiDevice device) {
try {
if (device != null && device.isOpen()) {
device.close();
}
} catch (Exception e) {
logger.warn("close", e);
}
}
示例2: main
import javax.sound.midi.MidiDevice; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
MidiDevice/*Synthesizer*/ synth = null;
try {
synth = MidiSystem.getSynthesizer();
//synth = MidiSystem.getMidiDevice(infos[0]);
System.out.println("Synthesizer: " + synth.getDeviceInfo());
synth.open();
MidiMessage msg = new GenericMidiMessage(0x90, 0x3C, 0x40);
//ShortMessage msg = new ShortMessage();
//msg.setMessage(0x90, 0x3C, 0x40);
synth.getReceiver().send(msg, 0);
Thread.sleep(2000);
} catch (Exception ex) {
ex.printStackTrace();
throw ex;
} finally {
if (synth != null && synth.isOpen())
synth.close();
}
System.out.print("Did you heard a note? (enter 'y' or 'n') ");
int result = System.in.read();
System.in.skip(1000);
if (result == 'y' || result == 'Y')
{
System.out.println("Test passed sucessfully.");
}
else
{
System.out.println("Test FAILED.");
throw new RuntimeException("Test failed.");
}
}
示例3: doTest
import javax.sound.midi.MidiDevice; //导入方法依赖的package包/类
private static boolean doTest(int numIterations, boolean input) throws Exception {
MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
MidiDevice outDevice = null;
MidiDevice inDevice = null;
for (int i = 0; i < infos.length; i++) {
MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
if (! (device instanceof Sequencer) &&
! (device instanceof Synthesizer)) {
if (device.getMaxReceivers() != 0) {
outDevice = device;
}
if (device.getMaxTransmitters() != 0) {
inDevice = device;
}
}
}
MidiDevice testDevice = null;
if (input) {
testDevice = inDevice;
} else {
testDevice = outDevice;
}
if (testDevice == null) {
out("Cannot test: device not available.");
return true;
}
out("Using Device: " + testDevice);
for (int i = 0; i < numIterations; i++) {
out("@@@ ITERATION: " + i);
testDevice.open();
// This sleep ensures that the thread of MidiInDevice is started.
sleep(50);
testDevice.close();
}
return true;
}
示例4: unuseDevice
import javax.sound.midi.MidiDevice; //导入方法依赖的package包/类
private static void unuseDevice(MidiDevice device)
{
Integer i = deviceUsage.get(device);
if (i == null) return;
else if (i <= 1)
{
device.close();
deviceUsage.remove(device);
}
else deviceUsage.put(device, i - 1);
}
示例5: unuseDevice
import javax.sound.midi.MidiDevice; //导入方法依赖的package包/类
private static void unuseDevice(MidiDevice device)
{
Integer i = USAGE.get(device);
if (i == null) return;
else if (i <= 1)
{
device.close();
TIME.remove(device);
USAGE.remove(device);
}
else USAGE.put(device, i - 1);
}
示例6: testDevice
import javax.sound.midi.MidiDevice; //导入方法依赖的package包/类
private static void testDevice(MidiDevice device) throws Exception {
boolean timestampsAvailable = false;
boolean timestampPrecisionOk = false;
try {
// expected behaviour if not opened?
device.open();
/* First, we're testing if timestamps are provided at all.
Returning -1 (unsupported), while allowed by the API
specification, is not sufficient to pass this test. */
long timestamp = device.getMicrosecondPosition();
timestampsAvailable = (timestamp != -1);
/* Then, we're testing the precision. Note that the system time
is measured in milliseconds, while the device time is measured
in microseconds. */
long systemTime1 = System.currentTimeMillis();
long deviceTime1 = device.getMicrosecondPosition();
// rest for 5 seconds
Thread.sleep(5000);
long systemTime2 = System.currentTimeMillis();
long deviceTime2 = device.getMicrosecondPosition();
// now both period measurements are calculated in milliseconds.
long systemDuration = systemTime2 - systemTime1;
long deviceDuration = (deviceTime2 - deviceTime1) / 1000;
long delta = Math.abs(systemDuration - deviceDuration);
// a deviation of 0.5 seconds (= 500 ms) is allowed.
timestampPrecisionOk = (delta <= 500);
} catch (Throwable t) {
System.out.println(" - Caught exception. Not failed.");
System.out.println(" - " + t.toString());
return;
} finally {
device.close();
}
if (! timestampsAvailable) {
throw new Exception("timestamps are not supported");
}
if (! timestampPrecisionOk) {
throw new Exception("device timer not precise enough");
}
successfulTests++;
}