本文整理汇总了Java中javax.sound.midi.Receiver.close方法的典型用法代码示例。如果您正苦于以下问题:Java Receiver.close方法的具体用法?Java Receiver.close怎么用?Java Receiver.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.midi.Receiver
的用法示例。
在下文中一共展示了Receiver.close方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReceiverSend
import javax.sound.midi.Receiver; //导入方法依赖的package包/类
/**
* Execute Receiver.send() and expect that there is no exception.
*/
private static boolean testReceiverSend() {
boolean result = true;
Receiver receiver;
ShortMessage shMsg = new ShortMessage();
try {
receiver = MidiSystem.getReceiver();
shMsg.setMessage(ShortMessage.NOTE_ON, 0,60, 93);
try {
receiver.send( shMsg, -1 );
} catch(IllegalStateException ilEx) {
ilEx.printStackTrace(System.out);
out("IllegalStateException was thrown incorrectly!");
result = false;
}
receiver.close();
} catch(MidiUnavailableException e) {
out("Midi unavailable, cannot test.");
} catch(InvalidMidiDataException ine) {
out("InvalidMidiDataException, cannot test.");
}
return result;
}
示例2: captureMidiMessages
import javax.sound.midi.Receiver; //导入方法依赖的package包/类
@Override
protected void captureMidiMessages(final Receiver receiver) throws MidiUnavailableException {
// Modify all MidiMessages so that they specify channel 10 (encoded as 9,
// which I suppose means that 0 indicates midi channel 1)
Receiver setChannelReceiver = new Receiver() {
@Override
public void send(MidiMessage message, long timeStamp) {
if (message instanceof ShortMessage) {
ShortMessage sm = (ShortMessage) message;
byte[] data = sm.getMessage();
byte orig = data[0];
data[0] = (byte) ((orig | 9) & 0xff);
message = Midi.createShortMessage(data);
}
receiver.send(message, timeStamp);
}
@Override
public void close() {
receiver.close();
}
};
super.captureMidiMessages(setChannelReceiver);
}
示例3: close
import javax.sound.midi.Receiver; //导入方法依赖的package包/类
/**
* Closes the MIDI receiver.
*
* @param receiver the MIDI receiver.
*/
public static void close(Receiver receiver) {
try {
if (receiver != null) {
receiver.close();
}
} catch (Exception e) {
logger.warn("close", e);
}
}
示例4: main
import javax.sound.midi.Receiver; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
AudioSynthesizer synth = new SoftSynthesizer();
synth.open(new DummySourceDataLine(), null);
assertTrue(synth.getReceivers().size() == 0);
Receiver recv = synth.getReceiver();
assertTrue(synth.getReceivers().size() == 1);
recv.close();
assertTrue(synth.getReceivers().size() == 0);
synth.close();
}
示例5: closeAllTransmittersAndReceivers
import javax.sound.midi.Receiver; //导入方法依赖的package包/类
/**
* Closes all transmitters and receivers of the midi device
*
* @param device
*/
public static void closeAllTransmittersAndReceivers(MidiDevice device) {
for (Transmitter transmitter : device.getTransmitters()) {
transmitter.close();
}
for (Receiver receiver : device.getReceivers()) {
receiver.close();
}
}
示例6: createMessageSource
import javax.sound.midi.Receiver; //导入方法依赖的package包/类
private void createMessageSource(final Instrument liveInstr) throws MidiUnavailableException,
IOException {
this.liveSynth = getInstrumentInfo(liveInstr);
// Filter incoming MidiMessages to:
// - change to channel 10 (if this is a percussion instrument)
// - add them to capturedEvents list
final Receiver delegate = liveSynth.source;
liveSynth.source = new Receiver() {
@Override
public void send(MidiMessage message, long timeStamp) {
if (liveInstr.getType() == InstrumentType.MIDI_PERCUSSION) {
// Percussion messages should on channel 10
if (message instanceof ShortMessage) {
ShortMessage smsg = (ShortMessage) message;
message = Midi.createShortMessage(smsg.getStatus()|9, smsg.getData1(), smsg.getData2());
}
}
capturedEvents.add(new MidiMessageAndTimeStamp(message, timeStamp));
delegate.send(message, timeStamp);
}
@Override
public void close() {
delegate.close();
}
};
}
示例7: main
import javax.sound.midi.Receiver; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Field f = SoftSynthesizer.class.getDeclaredField("testline");
f.setAccessible(true);
f.set(null, new DummySourceDataLine());
Synthesizer synth = new SoftSynthesizer();
ReferenceCountingDevice rcd = (ReferenceCountingDevice)synth;
// Test single open/close cycle
Receiver recv = rcd.getReceiverReferenceCounting();
if(!synth.isOpen())
throw new Exception("Synthesizer not open!");
recv.close();
if(synth.isOpen())
throw new Exception("Synthesizer not closed!");
// Test using 2 receiver cycle
Receiver recv1 = rcd.getReceiverReferenceCounting();
if(!synth.isOpen())
throw new Exception("Synthesizer not open!");
Receiver recv2 = rcd.getReceiverReferenceCounting();
if(!synth.isOpen())
throw new Exception("Synthesizer not open!");
recv2.close();
if(!synth.isOpen())
throw new Exception("Synthesizer was closed!");
recv1.close();
if(synth.isOpen())
throw new Exception("Synthesizer not closed!");
// Test for explicit,implicit conflict
synth.open();
Receiver recv3 = rcd.getReceiverReferenceCounting();
if(!synth.isOpen())
throw new Exception("Synthesizer not open!");
recv3.close();
if(!synth.isOpen())
throw new Exception("Synthesizer was closed!");
synth.close();
if(synth.isOpen())
throw new Exception("Synthesizer not closed!");
// Test for implicit,explicit conflict
recv3 = rcd.getReceiverReferenceCounting();
synth.open();
if(!synth.isOpen())
throw new Exception("Synthesizer not open!");
recv3.close();
if(!synth.isOpen())
throw new Exception("Synthesizer was closed!");
synth.close();
if(synth.isOpen())
throw new Exception("Synthesizer not closed!");
}
示例8: close
import javax.sound.midi.Receiver; //导入方法依赖的package包/类
/**
* Closes the Core MIDI Device, which also closes all of its receivers
*
*/
@Override
public void close() {
if ( isOpen.compareAndSet(true, false) ) {
// Reset the context data
startTime.set(0);
// Close all our receivers, which will also clear the list.
// We iterate on a copy of the receiver list to avoid issues with concurrent modification.
for ( Receiver receiver : getReceivers() ) {
receiver.close();
}
}
}