public class CoreMidiSource extends Object implements MidiDevice
MidiDevice.Info| Modifier and Type | Field and Description |
|---|---|
private boolean |
currentDataIsSingleByte |
private int |
currentMessage |
private byte |
firstDataByte |
private CoreMidiDeviceInfo |
info |
private AtomicReference<CoreMidiInputPort> |
input |
private AtomicBoolean |
isOpen |
private long |
startTime |
private Vector<byte[]> |
sysexMessageData |
private int |
sysexMessageLength |
private Set<CoreMidiTransmitter> |
transmitters |
private boolean |
wasFirstByteReceived |
| Constructor and Description |
|---|
CoreMidiSource(CoreMidiDeviceInfo info)
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the Core MIDI Device, which also closes all its transmitters
|
private SysexMessage |
constructSysexMessage()
Creates a SYSEX message from the received (potentially partial) messages.
|
(package private) void |
deviceDisappeared()
Forcibly close because the underlying CoreMIDI device has disappeared.
|
private int |
expectedDataLength(byte status)
Determine how many data bytes are expected for a given MIDI message other than a SYSEX message, which varies.
|
MidiDevice.Info |
getDeviceInfo()
Gets the MIDI Info object
|
private String |
getHexString(byte[] aByteArray)
Formats the provided data into a HEX string, which is useful for debugging
|
int |
getMaxReceivers()
Gets the maximum number of receivers that can be attached to this device.
|
int |
getMaxTransmitters()
Gets the maximum number of transmitters that can be attached to this device.
|
long |
getMicrosecondPosition()
Obtains the time in microseconds that has elapsed since this MIDI Device was opened.
|
private long |
getMicroSecondTime()
Obtains the current system time in microseconds.
|
Receiver |
getReceiver()
Creates and returns a MIDI Receiver for use with this Device
|
List<Receiver> |
getReceivers()
Gets a list of receivers connected to the device
|
Transmitter |
getTransmitter()
Gets a transmitter for this device (which is also added to the internal list)
|
List<Transmitter> |
getTransmitters()
Gets the list of transmitters registered with this MIDI device
|
boolean |
isOpen()
Checks to see if the MIDI Device is open
|
private boolean |
isRealTimeMessage(byte status)
Checks whether a status byte represents a real-time message, which can occur even in the middle of another
multi-byte message.
|
private boolean |
isRunningStatusMessage(int status)
Checks whether a status byte represents a running-status message, which means that multiple messages can be
sent without re-sending the status byte, for example to support multiple note-on messages in a row by simply
sending a stream of data byte pairs after the note-on status byte.
|
void |
messageCallback(long coreTimestamp,
int packetlength,
byte[] data)
The message callback for receiving midi data from the JNI code
|
void |
open()
Opens the Core MIDI Device
|
private int |
processSysexData(int packetLength,
byte[] sourceData,
int startOffset,
long timestamp)
Called when a SYSEX message is being received, either because an F0 byte has been seen at the start of a
message, which starts the process of gathering a SYSEX potentially across multiple packets, or because a
new packet has been received while we are still in the process of gathering bytes of a SYSEX which was
started in a previous message.
|
private void |
transmitMessage(MidiMessage message,
long timestamp)
Sends a MIDI message to all of the registered transmitters
|
(package private) void |
transmitterClosed(CoreMidiTransmitter transmitter)
Reacts to the closing of a transmitter by removing it from the set of active transmitters
|
(package private) void |
updateDeviceInfo(CoreMidiDeviceInfo info)
Changes the MIDI Info object; can only be done by this package as a result of a MIDI environment change event.
|
private CoreMidiDeviceInfo info
private final AtomicBoolean isOpen
private final AtomicReference<CoreMidiInputPort> input
private final Set<CoreMidiTransmitter> transmitters
private int currentMessage
private boolean currentDataIsSingleByte
private byte firstDataByte
private boolean wasFirstByteReceived
private Vector<byte[]> sysexMessageData
private int sysexMessageLength
private long startTime
CoreMidiSource(CoreMidiDeviceInfo info)
info - a CoreMidiDeviceInfo object providing details of the MIDI interfacepublic MidiDevice.Info getDeviceInfo()
getDeviceInfo in interface MidiDevicevoid updateDeviceInfo(CoreMidiDeviceInfo info)
info - CoreMidiDeviceInfo objectpublic void open() throws MidiUnavailableException
open in interface MidiDeviceMidiUnavailableException - if the MIDI system cannot be usedpublic void close()
close in interface AutoCloseableclose in interface MidiDevicevoid deviceDisappeared()
close() without
attempting to detach from the now-nonexistent underlying device.public boolean isOpen()
isOpen in interface MidiDeviceMidiDevice.isOpen()public long getMicrosecondPosition()
getMicrosecondPosition in interface MidiDeviceMidiDevice.getMicrosecondPosition()public int getMaxReceivers()
getMaxReceivers in interface MidiDeviceMidiDevice.getMaxReceivers()public int getMaxTransmitters()
getMaxTransmitters in interface MidiDeviceMidiDevice.getMaxTransmitters()public Receiver getReceiver() throws MidiUnavailableException
getReceiver in interface MidiDeviceMidiUnavailableExceptionMidiDevice.getReceiver()public List<Receiver> getReceivers()
getReceivers in interface MidiDeviceMidiDevice.getReceivers()public Transmitter getTransmitter() throws MidiUnavailableException
getTransmitter in interface MidiDeviceMidiUnavailableException - Thrown if MIDI services unavailable.MidiDevice.getTransmitter()void transmitterClosed(CoreMidiTransmitter transmitter)
transmitter - the transmitter which is reporting itself as having closedpublic List<Transmitter> getTransmitters()
getTransmitters in interface MidiDeviceMidiDevice.getTransmitters()private boolean isRealTimeMessage(byte status)
status - the status byte which has just been received.private boolean isRunningStatusMessage(int status)
status - the status byte which is being processed.private int expectedDataLength(byte status) throws InvalidMidiDataException
status - the status byte introducing the MIDI message.InvalidMidiDataException - if the status byte is not valid.public void messageCallback(long coreTimestamp, int packetlength, byte[] data) throws InvalidMidiDataException
coreTimestamp - The time in microseconds since boot at which the messages should take effectpacketlength - The length of the packet of messagesdata - The data array that holds the messagesInvalidMidiDataException - if the message contained values that could not be interpreted as valid MIDIprivate SysexMessage constructSysexMessage() throws InvalidMidiDataException
InvalidMidiDataException - if the data is not properly formedprivate int processSysexData(int packetLength, byte[] sourceData, int startOffset, long timestamp) throws InvalidMidiDataException
packetLength - The length of the data packetsourceData - The source data received from Core MIDIstartOffset - The position within the packet where the current message begantimestamp - The message timestampInvalidMidiDataException - if the data is not properly formedprivate void transmitMessage(MidiMessage message, long timestamp)
message - the message to sendtimestamp - the time stampprivate String getHexString(byte[] aByteArray)
aByteArray - The data to formatprivate long getMicroSecondTime()
Copyright © 2017. All rights reserved.