public class MidiBus
extends java.lang.Object
A typical simple Processing MIDI application would begin by invoking the static method list()
to learn what devices are available. Then using that information a new MidiBus object would be instantiated with with the desired MIDI input and/or output devices. The Processing sketch could then send midi via MidiBus's outgoing methods such as sendNoteOn(int channel, int pitch, int velocity)
, sendNoteOff(int channel, int pitch, int velocity)
and sendControllerChange(int channel, int number, int value)
and receive midi via the PApplet methods this package provides support for such as PApplet.noteOn(int channel, int pitch, int velocity)
, PApplet.noteOff(int channel, int pitch, int velocity)
and PApplet.controllerChange(int channel, int number, int value)
.
If you wish to build more complex Processing MIDI applications you can add more input and output devices to any given instance of MidiBus via the addInput() and addOutput() methods. However it is important to understand that each MidiBus object acts like 2 MIDI buses, one for input and one for output. This means, that by design, outgoing MIDI messages are sent to all output devices connected to a given instance of MidiBus, and incomming messages from all input devices connected to a given instance of MidiBus are merged upon reception. In practice, this means that, by design, you cannot tell which of the devices connected to a given instance of MidiBus sent a particular message, nor can you send a MIDI message to one particular device connected to that object. Instead, for independent reception/transmission to different sets of MIDI devices, you can instantiate more than one MidiBus object inside your Processing sketch. Each instance of MidiBus will only send MIDI messages to output devices which are connected to it and inbound MIDI messages arriving at each MidiBus can be diferentiated using the the PApplet
methods with the bus_name parameter.
PApplet
,
MidiListener
,
RawMidiListener
,
StandardMidiListener
,
SimpleMidiListener
Constructor and Description |
---|
MidiBus()
Constructs a new Midibus.
|
MidiBus(java.lang.Object parent)
Constructs a new MidiBus and registers the specified parent (PApplet or other) for callbacks.
|
MidiBus(java.lang.Object parent,
int in_device_num,
int out_device_num)
Constructs a new MidiBus and registers the specified parent (PApplet or other) for callbacks.
|
MidiBus(java.lang.Object parent,
int in_device_num,
int out_device_num,
java.lang.String bus_name)
Constructs a new MidiBus with the specified bus_name and registers the specified parent (PApplet or other) for callbacks.
|
MidiBus(java.lang.Object parent,
int in_device_num,
java.lang.String out_device_name)
More flavors of constructor, similar to the others, but with mixed arguments
|
MidiBus(java.lang.Object parent,
int in_device_num,
java.lang.String out_device_name,
java.lang.String bus_name)
More flavors of constructor, similar to the others, but with mixed arguments
|
MidiBus(java.lang.Object parent,
java.lang.String bus_name)
Constructs a new MidiBus with the specified bus_name and registers the specified parent (PApplet or other) for callbacks.
|
MidiBus(java.lang.Object parent,
java.lang.String in_device_name,
int out_device_num)
More flavors of constructor, similar to the others, but with mixed arguments
|
MidiBus(java.lang.Object parent,
java.lang.String in_device_name,
int out_device_num,
java.lang.String bus_name)
More flavors of constructor, similar to the others, but with mixed arguments
|
MidiBus(java.lang.Object parent,
java.lang.String in_device_name,
java.lang.String out_device_name)
Constructs a new MidiBus and registers the specified parent (PApplet or other) for callbacks.
|
MidiBus(java.lang.Object parent,
java.lang.String in_device_name,
java.lang.String out_device_name,
java.lang.String bus_name)
Constructs a new MidiBus with the specified bus_name and registers the specified parent (PApplet or other) for callbacks.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addInput(int device_num)
Adds a new MIDI input device specified by the index device_num.
|
boolean |
addInput(java.lang.String device_name)
Adds a new MIDI input device specified by the name device_name.
|
boolean |
addMidiListener(MidiListener listener)
Adds a listener who will be notified each time a new MIDI message is received from a MIDI input device.
|
boolean |
addOutput(int device_num)
Adds a new MIDI output device specified by the index device_num.
|
boolean |
addOutput(java.lang.String device_name)
Adds a new MIDI output device specified by the name device_name.
|
java.lang.String[] |
attachedInputs()
Returns the names of all the attached input devices.
|
java.lang.String[] |
attachedOutputs()
Returns the names of all the attached output devices.
|
static java.lang.String[] |
availableInputs()
Returns the names of all the available input devices.
|
static java.lang.String[] |
availableOutputs()
Returns the names of all the available output devices.
|
void |
clearAll()
Closes, clears and disposes of all input and output related Transmitters and Receivers.
|
void |
clearInputs()
Closes, clears and disposes of all input related Transmitters and Receivers.
|
void |
clearOutputs()
Closes, clears and disposes of all output related Receivers.
|
MidiBus |
clone()
Creates and returns a copy of this object.
|
void |
close()
Closes this MidiBus and all connections it has with other MIDI devices.
|
void |
dispose()
Closes this MidiBus and all connections it has with other MIDI devices.
|
boolean |
equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one.
|
protected void |
finalize()
Override the finalize() method from java.lang.Object.
|
static void |
findMidiDevices()
Rescan for Midi Devices.
|
void |
generateBusName()
Generate a name for this MidiBus instance.
|
java.lang.String |
getBusName()
Returns the name of this MidiBus.
|
int |
hashCode()
Returns a hash code value for the object.
|
static void |
list()
List all installed MIDI devices.
|
java.lang.Object |
registerParent(java.lang.Object parent)
Registers an Object as the parent in order to recieve method callbacks as per
PApplet . |
boolean |
removeInput(int device_num)
Removes the MIDI input device specified by the index device_num.
|
boolean |
removeInput(java.lang.String device_name)
Removes the MIDI input device specified by the name device_name.
|
boolean |
removeMidiListener(MidiListener listener)
Removes a given listener.
|
boolean |
removeOutput(int device_num)
Removes the MIDI output device specified by the index device_num.
|
boolean |
removeOutput(java.lang.String device_name)
Removes the MIDI output device specified by the name device_name.
|
void |
sendControllerChange(ControlChange change)
Sends a ControllerChange message to a channel with the specified ControlChange.
|
void |
sendControllerChange(int channel,
int number,
int value)
Sends a ControllerChange message to a channel with the specified number and value.
|
void |
sendMessage(byte[] data)
Sends a MIDI message with an unspecified number of bytes.
|
void |
sendMessage(int status)
Sends a MIDI message that takes no data bytes.
|
void |
sendMessage(int status,
int data)
Sends a MIDI message that takes only one data byte.
|
void |
sendMessage(int status,
int data1,
int data2)
Sends a MIDI message that takes one or two data bytes.
|
void |
sendMessage(int command,
int channel,
int data1,
int data2)
Sends a channel message which takes up to two data bytes.
|
void |
sendMessage(javax.sound.midi.MidiMessage message)
Sends a MidiMessage object.
|
void |
sendNoteOff(int channel,
int pitch,
int velocity)
Sends a NoteOff message to a channel with the specified pitch and velocity.
|
void |
sendNoteOff(Note note)
Sends a NoteOff message to a channel with the specified Note.
|
void |
sendNoteOn(int channel,
int pitch,
int velocity)
Sends a NoteOn message to a channel with the specified pitch and velocity.
|
void |
sendNoteOn(Note note)
Sends a NoteOn message to a channel with the specified Note.
|
boolean |
sendTimestamps()
Returns whether this MidiBus is sending timestamps along with MIDI information to the MIDI subsystem.
|
void |
sendTimestamps(boolean sendTimestamps)
Configure this MidiBus instance to send or not to send timestamps along with MIDI information to the MIDI subsystem.
|
void |
setBusName(java.lang.String bus_name)
Changes the name of this MidiBus.
|
void |
stop()
Closes this MidiBus and all connections it has with other MIDI devices.
|
java.lang.String |
toString()
Returns a string representation of the object.
|
static java.lang.String[] |
unavailableDevices()
Returns the names of all the unavailable devices.
|
public MidiBus()
public MidiBus(java.lang.Object parent)
parent
- the parent to which this MidiBus is attached.addInput(int device_num)
,
addInput(String device_name)
,
addOutput(int device_num)
,
addOutput(String device_name)
,
list()
public MidiBus(java.lang.Object parent, java.lang.String bus_name)
parent
- the parent to which this MidiBus is attached.bus_name
- the String which which identifies this MidiBus.addInput(int device_num)
,
addInput(String device_name)
,
addOutput(int device_num)
,
addOutput(String device_name)
,
list()
public MidiBus(java.lang.Object parent, int in_device_num, int out_device_num)
parent
- the parent to which this MidiBus is attached.in_device_num
- the index of the MIDI input device to be opened.out_device_num
- the index of the MIDI output device to be opened.addInput(int device_num)
,
addInput(String device_name)
,
addOutput(int device_num)
,
addOutput(String device_name)
,
list()
public MidiBus(java.lang.Object parent, int in_device_num, int out_device_num, java.lang.String bus_name)
parent
- the parent to which this MidiBus is attached.in_device_num
- the index of the MIDI input device to be opened.out_device_num
- the index of the MIDI output device to be opened.bus_name
- the String which which identifies this MidiBus.addInput(int device_num)
,
addInput(String device_name)
,
addOutput(int device_num)
,
addOutput(String device_name)
,
list()
public MidiBus(java.lang.Object parent, java.lang.String in_device_name, java.lang.String out_device_name)
If two or more MIDI inputs have the same name, whichever appears first when list()
is called will be added, simlarly for two or more MIDI outputs with the same name. If this behavior is problematic use MidiBus(Object parent, int in_device_num, int out_device_num)
instead.
parent
- the parent to which this MidiBus is attached.in_device_name
- the name of the MIDI input device to be opened.out_device_name
- the name of the MIDI output device to be opened.addInput(int device_num)
,
addInput(String device_name)
,
addOutput(int device_num)
,
addOutput(String device_name)
,
list()
public MidiBus(java.lang.Object parent, java.lang.String in_device_name, java.lang.String out_device_name, java.lang.String bus_name)
If two or more MIDI inputs have the same name, whichever appears first when list()
is called will be added, simlarly for two or more MIDI outputs with the same name. If this behavior is problematic use MidiBus(Object parent, int in_device_num, int out_device_num, String bus_name)
instead.
parent
- the parent to which this MidiBus is attached.in_device_name
- the name of the MIDI input device to be opened.out_device_name
- the name of the MIDI output device to be opened.bus_name
- the String which which identifies this MidiBus.addInput(int device_num)
,
addInput(String device_name)
,
addOutput(int device_num)
,
addOutput(String device_name)
,
list()
public MidiBus(java.lang.Object parent, int in_device_num, java.lang.String out_device_name)
parent
- the parent to which this MidiBus is attached.in_device_num
- the name of the MIDI input device to be opened.out_device_name
- the name of the MIDI output device to be opened.addInput(int device_num)
,
addInput(String device_name)
,
addOutput(int device_num)
,
addOutput(String device_name)
,
list()
public MidiBus(java.lang.Object parent, int in_device_num, java.lang.String out_device_name, java.lang.String bus_name)
parent
- the parent to which this MidiBus is attached.in_device_num
- the name of the MIDI input device to be opened.out_device_name
- the name of the MIDI output device to be opened.bus_name
- the String which which identifies this MidiBus.addInput(int device_num)
,
addInput(String device_name)
,
addOutput(int device_num)
,
addOutput(String device_name)
,
list()
public MidiBus(java.lang.Object parent, java.lang.String in_device_name, int out_device_num)
parent
- the parent to which this MidiBus is attached.in_device_name
- the name of the MIDI input device to be opened.out_device_num
- the name of the MIDI output device to be opened.addInput(int device_num)
,
addInput(String device_name)
,
addOutput(int device_num)
,
addOutput(String device_name)
,
list()
public MidiBus(java.lang.Object parent, java.lang.String in_device_name, int out_device_num, java.lang.String bus_name)
parent
- the parent to which this MidiBus is attached.in_device_name
- the name of the MIDI input device to be opened.out_device_num
- the name of the MIDI output device to be opened.bus_name
- the String which which identifies this MidiBus.addInput(int device_num)
,
addInput(String device_name)
,
addOutput(int device_num)
,
addOutput(String device_name)
,
list()
public java.lang.String[] attachedInputs()
attachedOutputs()
public java.lang.String[] attachedOutputs()
attachedInputs()
public boolean addInput(int device_num)
device_num
- the index of the MIDI input device to be added.addInput(String device_name)
,
list()
public boolean removeInput(int device_num)
device_num
- the index of the MIDI input device to be removed.removeInput(String device_name)
,
attachedInputs()
public boolean addInput(java.lang.String device_name)
If two or more MIDI inputs have the same name, whichever appears first when list()
is called will be added. If this behavior is problematic use addInput(int device_num)
instead.
device_name
- the name of the MIDI input device to be added.addInput(int device_num)
,
list()
public boolean removeInput(java.lang.String device_name)
If two or more attached MIDI inputs have the same name, whichever appears first when attachedInputs()
is called will be removed. If this behavior is problematic use removeInput(int device_num)
instead.
device_name
- the name of the MIDI input device to be removed.removeInput(int device_num)
,
attachedInputs()
public boolean addOutput(int device_num)
device_num
- the index of the MIDI output device to be added.addOutput(String device_name)
,
list()
public boolean removeOutput(int device_num)
device_num
- the index of the MIDI output device to be removed.removeInput(String device_name)
,
attachedOutputs()
public boolean addOutput(java.lang.String device_name)
If two or more MIDI outputs have the same name, whichever appears first when list()
is called will be added. If this behavior is problematic use addOutput(int device_num)
instead.
device_name
- the name of the MIDI output device to be added.addOutput(int device_num)
,
list()
public boolean removeOutput(java.lang.String device_name)
If two or more attached MIDI outputs have the same name, whichever appears first when attachedOutputs()
is called will be removed. If this behavior is problematic use removeOutput(int device_num)
instead.
device_name
- the name of the MIDI output device to be removed.removeOutput(int device_num)
,
attachedOutputs()
public void clearInputs()
clearOutputs()
,
clearAll()
public void clearOutputs()
clearInputs()
,
clearAll()
public void clearAll()
clearInputs()
,
clearOutputs()
public void sendMessage(byte[] data)
data
- the bytes of the MIDI message.sendMessage(int status)
,
sendMessage(int status, int data)
,
sendMessage(int status, int data1, int data2)
,
sendMessage(int command, int channel, int data1, int data2)
,
sendMessage(MidiMessage message)
,
sendNoteOn(int channel, int pitch, int velocity)
,
sendNoteOn(Note note)
,
sendNoteOff(int channel, int pitch, int velocity)
,
sendNoteOff(Note note)
,
sendControllerChange(int channel, int number, int value)
,
sendControllerChange(ControlChange change)
public void sendMessage(int status)
status
- the status bytesendMessage(byte[] data)
,
sendMessage(int status, int data)
,
sendMessage(int status, int data1, int data2)
,
sendMessage(int command, int channel, int data1, int data2)
,
sendMessage(MidiMessage message)
,
sendNoteOn(int channel, int pitch, int velocity)
,
sendNoteOn(Note note)
,
sendNoteOff(int channel, int pitch, int velocity)
,
sendNoteOff(Note note)
,
sendControllerChange(int channel, int number, int value)
,
sendControllerChange(ControlChange change)
public void sendMessage(int status, int data)
status
- the status bytedata
- the data bytesendMessage(byte[] data)
,
sendMessage(int status)
,
sendMessage(int status, int data1, int data2)
,
sendMessage(int command, int channel, int data1, int data2)
,
sendMessage(MidiMessage message)
,
sendNoteOn(int channel, int pitch, int velocity)
,
sendNoteOn(Note note)
,
sendNoteOff(int channel, int pitch, int velocity)
,
sendNoteOff(Note note)
,
sendControllerChange(int channel, int number, int value)
,
sendControllerChange(ControlChange change)
public void sendMessage(int status, int data1, int data2)
status
- the status byte.data1
- the first data byte.data2
- the second data byte.sendMessage(byte[] data)
,
sendMessage(int status)
,
sendMessage(int status, int data)
,
sendMessage(int command, int channel, int data1, int data2)
,
sendMessage(MidiMessage message)
,
sendNoteOn(int channel, int pitch, int velocity)
,
sendNoteOn(Note note)
,
sendNoteOff(int channel, int pitch, int velocity)
,
sendNoteOff(Note note)
,
sendControllerChange(int channel, int number, int value)
,
sendControllerChange(ControlChange change)
public void sendMessage(int command, int channel, int data1, int data2)
command
- the MIDI command represented by this message.channel
- the channel associated with the message.data1
- the first data byte.data2
- the second data byte.sendMessage(byte[] data)
,
sendMessage(int status)
,
sendMessage(int status, int data)
,
sendMessage(int status, int data1, int data2)
,
sendMessage(MidiMessage message)
,
sendNoteOn(int channel, int pitch, int velocity)
,
sendNoteOn(Note note)
,
sendNoteOff(int channel, int pitch, int velocity)
,
sendNoteOff(Note note)
,
sendControllerChange(int channel, int number, int value)
,
sendControllerChange(ControlChange change)
public void sendMessage(javax.sound.midi.MidiMessage message)
message
- the MidiMessage.sendMessage(byte[] data)
,
sendMessage(int status)
,
sendMessage(int status, int data)
,
sendMessage(int status, int data1, int data2)
,
sendMessage(int command, int channel, int data1, int data2)
,
sendNoteOn(int channel, int pitch, int velocity)
,
sendNoteOn(Note note)
,
sendNoteOff(int channel, int pitch, int velocity)
,
sendNoteOff(Note note)
,
sendControllerChange(int channel, int number, int value)
,
sendControllerChange(ControlChange change)
public void sendNoteOn(int channel, int pitch, int velocity)
channel
- the channel associated with the message.pitch
- the pitch associated with the message.velocity
- the velocity associated with the message.sendMessage(byte[] data)
,
sendMessage(int status)
,
sendMessage(int status, int data)
,
sendMessage(int status, int data1, int data2)
,
sendMessage(int command, int channel, int data1, int data2)
,
sendMessage(MidiMessage message)
,
sendNoteOn(Note note)
,
sendNoteOff(int channel, int pitch, int velocity)
,
sendNoteOff(Note note)
,
sendControllerChange(int channel, int number, int value)
,
sendControllerChange(ControlChange change)
public void sendNoteOn(Note note)
note
- the Note object for the message.sendMessage(byte[] data)
,
sendMessage(int status)
,
sendMessage(int status, int data)
,
sendMessage(int status, int data1, int data2)
,
sendMessage(int command, int channel, int data1, int data2)
,
sendMessage(MidiMessage message)
,
sendNoteOn(int channel, int pitch, int velocity)
,
sendNoteOff(int channel, int pitch, int velocity)
,
sendNoteOff(Note note)
,
sendControllerChange(int channel, int number, int value)
,
sendControllerChange(ControlChange change)
public void sendNoteOff(int channel, int pitch, int velocity)
channel
- the channel associated with the message.pitch
- the pitch associated with the message.velocity
- the velocity associated with the message.sendMessage(byte[] data)
,
sendMessage(int status)
,
sendMessage(int status, int data)
,
sendMessage(int status, int data1, int data2)
,
sendMessage(int command, int channel, int data1, int data2)
,
sendMessage(MidiMessage message)
,
sendNoteOn(int channel, int pitch, int velocity)
,
sendNoteOn(Note note)
,
sendNoteOff(Note note)
,
sendControllerChange(int channel, int number, int value)
,
sendControllerChange(ControlChange change)
public void sendNoteOff(Note note)
note
- the Note object for the message.sendMessage(byte[] data)
,
sendMessage(int status)
,
sendMessage(int status, int data)
,
sendMessage(int status, int data1, int data2)
,
sendMessage(int command, int channel, int data1, int data2)
,
sendMessage(MidiMessage message)
,
sendNoteOn(int channel, int pitch, int velocity)
,
sendNoteOn(Note note)
,
sendNoteOff(int channel, int pitch, int velocity)
,
sendControllerChange(int channel, int number, int value)
,
sendControllerChange(ControlChange change)
public void sendControllerChange(int channel, int number, int value)
channel
- the channel associated with the message.number
- the number associated with the message.value
- the value associated with the message.sendMessage(byte[] data)
,
sendMessage(int status)
,
sendMessage(int status, int data)
,
sendMessage(int status, int data1, int data2)
,
sendMessage(int command, int channel, int data1, int data2)
,
sendMessage(MidiMessage message)
,
sendNoteOn(int channel, int pitch, int velocity)
,
sendNoteOn(Note note)
,
sendNoteOff(int channel, int pitch, int velocity)
,
sendNoteOff(Note note)
,
sendControllerChange(ControlChange change)
public void sendControllerChange(ControlChange change)
change
- the ControlChange object for the message.sendMessage(byte[] data)
,
sendMessage(int status)
,
sendMessage(int status, int data)
,
sendMessage(int status, int data1, int data2)
,
sendMessage(int command, int channel, int data1, int data2)
,
sendMessage(MidiMessage message)
,
sendNoteOn(int channel, int pitch, int velocity)
,
sendNoteOn(Note note)
,
sendNoteOff(int channel, int pitch, int velocity)
,
sendNoteOff(Note note)
,
sendControllerChange(int channel, int number, int value)
public java.lang.Object registerParent(java.lang.Object parent)
PApplet
. Calling this will replace the previous parent Object if any was set.parent
- the object to register.addMidiListener(MidiListener listener)
public boolean addMidiListener(MidiListener listener)
listener
- the listener to add.removeMidiListener(MidiListener listener)
,
registerParent(Object parent)
public boolean removeMidiListener(MidiListener listener)
listener
- the listener to remove.addMidiListener(MidiListener listener)
public boolean sendTimestamps()
public void sendTimestamps(boolean sendTimestamps)
sendTimestamps
- set to true if you want timestamps to be sent, otherwise set to false.public java.lang.String getBusName()
setBusName(String bus_name)
,
generateBusName()
public void setBusName(java.lang.String bus_name)
bus_name
- the new name of this MidiBus.getBusName()
,
generateBusName()
public void generateBusName()
setBusName(String bus_name)
,
getBusName()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the reference object with which to compare.public MidiBus clone()
clone
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
protected void finalize()
finalize
in class java.lang.Object
public void close()
public void stop()
public void dispose()
public static void list()
public static void findMidiDevices()
public static java.lang.String[] availableInputs()
list()
,
availableOutputs()
,
unavailableDevices()
public static java.lang.String[] availableOutputs()
list()
,
availableInputs()
,
unavailableDevices()
public static java.lang.String[] unavailableDevices()
list()
,
availableInputs()
,
availableOutputs()