本文整理匯總了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();
}
}
}