Class CoreMidiSource
- java.lang.Object
-
- uk.co.xfactorylibrarians.coremidi4j.CoreMidiSource
-
- All Implemented Interfaces:
AutoCloseable
,MidiDevice
public class CoreMidiSource extends Object implements MidiDevice
Provides a working Java MIDI interface to a CoreMIDI device to which we can send messages.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface javax.sound.midi.MidiDevice
MidiDevice.Info
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the Core MIDI Device, which also closes all its transmittersMidiDevice.Info
getDeviceInfo()
Gets the MIDI Info objectint
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.Receiver
getReceiver()
Creates and returns a MIDI Receiver for use with this DeviceList<Receiver>
getReceivers()
Gets a list of receivers connected to the deviceTransmitter
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 deviceboolean
isOpen()
Checks to see if the MIDI Device is openvoid
messageCallback(long coreTimestamp, int packetlength, byte[] data)
The message callback for receiving midi data from the JNI codevoid
open()
Opens the Core MIDI Device
-
-
-
Method Detail
-
getDeviceInfo
public MidiDevice.Info getDeviceInfo()
Gets the MIDI Info object- Specified by:
getDeviceInfo
in interfaceMidiDevice
- Returns:
- the MIDI Info object, which provides details about the interface
-
open
public void open() throws MidiUnavailableException
Opens the Core MIDI Device- Specified by:
open
in interfaceMidiDevice
- Throws:
MidiUnavailableException
- if the MIDI system cannot be used
-
close
public void close()
Closes the Core MIDI Device, which also closes all its transmitters- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceMidiDevice
-
isOpen
public boolean isOpen()
Checks to see if the MIDI Device is open- Specified by:
isOpen
in interfaceMidiDevice
- Returns:
- true if the device is open, otherwise false;
- See Also:
MidiDevice.isOpen()
-
getMicrosecondPosition
public long getMicrosecondPosition()
Obtains the time in microseconds that has elapsed since this MIDI Device was opened.- Specified by:
getMicrosecondPosition
in interfaceMidiDevice
- Returns:
- the time in microseconds that has elapsed since this MIDI Device was opened.
- See Also:
MidiDevice.getMicrosecondPosition()
-
getMaxReceivers
public int getMaxReceivers()
Gets the maximum number of receivers that can be attached to this device.- Specified by:
getMaxReceivers
in interfaceMidiDevice
- Returns:
- the maximum number of receivers that can be attached to this device. This is always 0 as a CoreMidiSource has no receivers
- See Also:
MidiDevice.getMaxReceivers()
-
getMaxTransmitters
public int getMaxTransmitters()
Gets the maximum number of transmitters that can be attached to this device.- Specified by:
getMaxTransmitters
in interfaceMidiDevice
- Returns:
- the maximum number of transmitters that can be attached to this device. -1 is returned to indicate that the number is unlimited
- See Also:
MidiDevice.getMaxTransmitters()
-
getReceiver
public Receiver getReceiver() throws MidiUnavailableException
Creates and returns a MIDI Receiver for use with this Device- Specified by:
getReceiver
in interfaceMidiDevice
- Returns:
- the created receiver
- Throws:
MidiUnavailableException
- See Also:
MidiDevice.getReceiver()
-
getReceivers
public List<Receiver> getReceivers()
Gets a list of receivers connected to the device- Specified by:
getReceivers
in interfaceMidiDevice
- Returns:
- an empty list - we do not maintain a list of receivers
- See Also:
MidiDevice.getReceivers()
-
getTransmitter
public Transmitter getTransmitter() throws MidiUnavailableException
Gets a transmitter for this device (which is also added to the internal list)- Specified by:
getTransmitter
in interfaceMidiDevice
- Returns:
- a transmitter for this device
- Throws:
MidiUnavailableException
- See Also:
MidiDevice.getTransmitter()
-
getTransmitters
public List<Transmitter> getTransmitters()
Gets the list of transmitters registered with this MIDI device- Specified by:
getTransmitters
in interfaceMidiDevice
- Returns:
- The list of transmitters created from this MIDI device that are still open
- See Also:
MidiDevice.getTransmitters()
-
messageCallback
public void messageCallback(long coreTimestamp, int packetlength, byte[] data) throws InvalidMidiDataException
The message callback for receiving midi data from the JNI code- Parameters:
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 messages- Throws:
InvalidMidiDataException
- if the message contained values that could not be interpreted as valid MIDI
-
-