< prev index next >
src/java.desktop/share/classes/com/sun/media/sound/MidiOutDevice.java
Print this page
*** 23,66 ****
* questions.
*/
package com.sun.media.sound;
! import javax.sound.midi.*;
!
!
/**
* MidiOutDevice class representing functionality of MidiOut devices.
*
* @author David Rivas
* @author Kara Kytle
* @author Florian Bomers
*/
final class MidiOutDevice extends AbstractMidiDevice {
- // CONSTRUCTOR
-
MidiOutDevice(AbstractMidiDeviceProvider.Info info) {
super(info);
if(Printer.trace) Printer.trace("MidiOutDevice CONSTRUCTOR");
}
!
! // IMPLEMENTATION OF ABSTRACT MIDI DEVICE METHODS
!
protected synchronized void implOpen() throws MidiUnavailableException {
if (Printer.trace) Printer.trace("> MidiOutDevice: implOpen()");
int index = ((AbstractMidiDeviceProvider.Info)getDeviceInfo()).getIndex();
id = nOpen(index); // can throw MidiUnavailableException
if (id == 0) {
throw new MidiUnavailableException("Unable to open native device");
}
if (Printer.trace) Printer.trace("< MidiOutDevice: implOpen(): completed.");
}
!
protected synchronized void implClose() {
if (Printer.trace) Printer.trace("> MidiOutDevice: implClose()");
// prevent further action
long oldId = id;
id = 0;
--- 23,63 ----
* questions.
*/
package com.sun.media.sound;
! import javax.sound.midi.MidiMessage;
! import javax.sound.midi.MidiUnavailableException;
! import javax.sound.midi.Receiver;
! import javax.sound.midi.ShortMessage;
/**
* MidiOutDevice class representing functionality of MidiOut devices.
*
* @author David Rivas
* @author Kara Kytle
* @author Florian Bomers
*/
final class MidiOutDevice extends AbstractMidiDevice {
MidiOutDevice(AbstractMidiDeviceProvider.Info info) {
super(info);
if(Printer.trace) Printer.trace("MidiOutDevice CONSTRUCTOR");
}
! @Override
protected synchronized void implOpen() throws MidiUnavailableException {
if (Printer.trace) Printer.trace("> MidiOutDevice: implOpen()");
int index = ((AbstractMidiDeviceProvider.Info)getDeviceInfo()).getIndex();
id = nOpen(index); // can throw MidiUnavailableException
if (id == 0) {
throw new MidiUnavailableException("Unable to open native device");
}
if (Printer.trace) Printer.trace("< MidiOutDevice: implOpen(): completed.");
}
! @Override
protected synchronized void implClose() {
if (Printer.trace) Printer.trace("> MidiOutDevice: implClose()");
// prevent further action
long oldId = id;
id = 0;
*** 70,110 ****
// close the device
nClose(oldId);
if (Printer.trace) Printer.trace("< MidiOutDevice: implClose(): completed");
}
!
public long getMicrosecondPosition() {
long timestamp = -1;
if (isOpen()) {
timestamp = nGetTimeStamp(id);
}
return timestamp;
}
-
-
- // OVERRIDES OF ABSTRACT MIDI DEVICE METHODS
-
/** Returns if this device supports Receivers.
This implementation always returns true.
@return true, if the device supports Receivers, false otherwise.
*/
protected boolean hasReceivers() {
return true;
}
!
protected Receiver createReceiver() {
return new MidiOutReceiver();
}
-
- // INNER CLASSES
-
final class MidiOutReceiver extends AbstractReceiver {
void implSend(final MidiMessage message, final long timeStamp) {
final int length = message.getLength();
final int status = message.getStatus();
if (length <= 3 && status != 0xF0 && status != 0xF7) {
int packedMsg;
--- 67,102 ----
// close the device
nClose(oldId);
if (Printer.trace) Printer.trace("< MidiOutDevice: implClose(): completed");
}
! @Override
public long getMicrosecondPosition() {
long timestamp = -1;
if (isOpen()) {
timestamp = nGetTimeStamp(id);
}
return timestamp;
}
/** Returns if this device supports Receivers.
This implementation always returns true.
@return true, if the device supports Receivers, false otherwise.
*/
+ @Override
protected boolean hasReceivers() {
return true;
}
! @Override
protected Receiver createReceiver() {
return new MidiOutReceiver();
}
final class MidiOutReceiver extends AbstractReceiver {
+ @Override
void implSend(final MidiMessage message, final long timeStamp) {
final int length = message.getLength();
final int status = message.getStatus();
if (length <= 3 && status != 0xF0 && status != 0xF7) {
int packedMsg;
*** 157,173 ****
synchronized void sendPackedMidiMessage(int packedMsg, long timeStamp) {
if (isOpen() && id != 0) {
nSendShortMessage(id, packedMsg, timeStamp);
}
}
-
-
} // class MidiOutReceiver
-
- // NATIVE METHODS
-
private native long nOpen(int index) throws MidiUnavailableException;
private native void nClose(long id);
private native void nSendShortMessage(long id, int packedMsg, long timeStamp);
private native void nSendLongMessage(long id, byte[] data, int size, long timeStamp);
--- 149,160 ----
< prev index next >