Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain six categories:
+Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:
+Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
+Each annotation type has its own separate page with the following sections:
+Each enum has its own separate page with the following sections:
+There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object
. The interfaces do not inherit from java.lang.Object
.
The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
+The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
+These links take you to the next or previous class, interface, package, or related page.
+These links show and hide the HTML frames. All pages are available with or without frames.
+The All Classes link shows all classes and interfaces except non-static nested types.
+Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description.
+The Constant Field Values page lists the static final fields and their values.
+RawMidiListener
, SimpleMidiListener
or StandardMidiListener
.Note
and ControlChange
objects, usually by a MidiBus object which it is connected to.PApplet
.public class ControlChange
+extends java.lang.Object
+MidiBus
,
+ObjectMidiListener
,
+Note
Modifier and Type | +Field and Description | +
---|---|
java.lang.String |
+bus_name |
+
int |
+channel |
+
int |
+number |
+
long |
+timestamp |
+
int |
+value |
+
Constructor and Description | +
---|
ControlChange(int channel,
+ int number,
+ int value)
+Constructs a ControlChange object
+ |
+
ControlChange(int channel,
+ int number,
+ int value,
+ long timestamp,
+ java.lang.String bus_name)
+Constructs a ControlChange object
+ |
+
Modifier and Type | +Method and Description | +
---|---|
int |
+channel()
+Return the channel of the ControlChange
+ |
+
boolean |
+equals(java.lang.Object obj)
+Check if all fields are equal.
+ |
+
int |
+number()
+Return the number of the ControlChange
+ |
+
void |
+setChannel(int channel)
+Set channel of the ControlChange
+ |
+
void |
+setNumber(int number)
+Set number of the ControlChange
+ |
+
void |
+setValue(int value)
+Set value of the ControlChange
+ |
+
java.lang.String |
+toString()
+Returns a string in the format [c:channel, n:number, v:value, ts:timestamp, b:bus_name] e.g "[c:0, n:65, v:123, ts:1234, b:bus123]".
+ |
+
int |
+value()
+Return the value of the ControlChange
+ |
+
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public int channel+
public int number+
public int value+
public long timestamp+
public java.lang.String bus_name+
public ControlChange(int channel, + int number, + int value)+
channel
- the channel of the ControlChangenumber
- the number of the ControlChangevalue
- the value of the ControlChangepublic ControlChange(int channel, + int number, + int value, + long timestamp, + java.lang.String bus_name)+
channel
- the channel of the ControlChangenumber
- the number of the ControlChangevalue
- the value of the ControlChangetimestamp
- the timestamp of the ControlChangebus_name
- the name of MidiBus associated with the ControlChangepublic void setChannel(int channel)+
channel
- the channel to setpublic int channel()+
public void setNumber(int number)+
number
- the number to setpublic int number()+
public void setValue(int value)+
value
- the value to setpublic int value()+
public java.lang.String toString()+
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)+
equals
in class java.lang.Object
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.
+ |
+
getClass, notify, notifyAll, wait, wait, wait
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()+
availableInputs()
,
+availableOutputs()
,
+unavailableDevices()
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()
public interface MidiListener
+RawMidiListener
, SimpleMidiListener
or StandardMidiListener
. It makes it easier to create lists and arrays of such object and allows for a standard method MidiBus.addMidiListener(MidiListener listener)
to add any type of listener to a MidiBus object.RawMidiListener
,
+SimpleMidiListener
,
+StandardMidiListener
,
+ObjectMidiListener
,
+MidiBus
public class Note
+extends java.lang.Object
+MidiBus
,
+ObjectMidiListener
,
+ControlChange
Modifier and Type | +Field and Description | +
---|---|
java.lang.String |
+bus_name |
+
int |
+channel |
+
int |
+pitch |
+
long |
+ticks |
+
long |
+timestamp |
+
int |
+velocity |
+
Constructor and Description | +
---|
Note(int channel,
+ int pitch,
+ int velocity)
+Constructs a Note object
+ |
+
Note(int channel,
+ int pitch,
+ int velocity,
+ int ticks)
+Constructs a Note object
+ |
+
Note(int channel,
+ int pitch,
+ int velocity,
+ int ticks,
+ long timestamp,
+ java.lang.String bus_name)
+Constructs a Note object
+ |
+
Note(int channel,
+ int pitch,
+ int velocity,
+ long timestamp,
+ java.lang.String bus_name)
+Constructs a Note object
+ |
+
Modifier and Type | +Method and Description | +
---|---|
int |
+channel()
+Return the channel of the Note
+ |
+
boolean |
+equals(java.lang.Object obj)
+Check if all fields are equal.
+ |
+
java.lang.String |
+name()
+Return the name of the note, e.g.
+ |
+
int |
+octave()
+Return the octave of the Note.
+ |
+
int |
+pitch()
+Return the pitch of the Note
+ |
+
int |
+relativePitch()
+Return the pitch of the Note relative to C.
+ |
+
void |
+setChannel(int channel)
+Set channel of the Note
+ |
+
void |
+setPitch(int pitch)
+Set pitch of the Note
+ |
+
void |
+setTicks(int ticks)
+Set length in ticks of the Note
+ |
+
void |
+setVelocity(int velocity)
+Set velocity of the Note
+ |
+
long |
+ticks()
+Return the length in ticks of the Note
+ |
+
java.lang.String |
+toString()
+Returns a string in the format [Note Name, c:channel, p:pitch, v:velocity, t:ticks, ts:timestamp, b:bus_name] e.g "[C, c:0, p:65, v:123, t:0, ts:1234, b:bus123]".
+ |
+
int |
+velocity()
+Return the velocity of the Note
+ |
+
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public int channel+
public int pitch+
public int velocity+
public long ticks+
public long timestamp+
public java.lang.String bus_name+
public Note(int channel, + int pitch, + int velocity)+
channel
- the channel of the Notepitch
- the pitch of the Notevelocity
- the velocity of the Notepublic Note(int channel, + int pitch, + int velocity, + int ticks)+
channel
- the channel of the Notepitch
- the pitch of the Notevelocity
- the velocity of the Noteticks
- the length in ticks of the Notepublic Note(int channel, + int pitch, + int velocity, + long timestamp, + java.lang.String bus_name)+
channel
- the channel of the Notepitch
- the pitch of the Notevelocity
- the velocity of the Notetimestamp
- the timestamp of the Notebus_name
- the name of MidiBus associated with the Notepublic Note(int channel, + int pitch, + int velocity, + int ticks, + long timestamp, + java.lang.String bus_name)+
channel
- the channel of the Notepitch
- the pitch of the Notevelocity
- the velocity of the Noteticks
- the length in ticks of the Notetimestamp
- the timestamp of the Notebus_name
- the name of MidiBus associated with the Notepublic void setChannel(int channel)+
channel
- the channel to setpublic int channel()+
public void setPitch(int pitch)+
pitch
- the pitch to setpublic int pitch()+
public int relativePitch()+
public int octave()+
public java.lang.String name()+
public void setVelocity(int velocity)+
velocity
- the velocity to setpublic int velocity()+
public void setTicks(int ticks)+
ticks
- the ticks value to setpublic long ticks()+
public java.lang.String toString()+
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)+
equals
in class java.lang.Object
public interface ObjectMidiListener +extends MidiListener+
Note
and ControlChange
objects, usually by a MidiBus object which it is connected to. Typically it would analyse and react to incomming messages in some useful way.MidiListener
,
+RawMidiListener
,
+SimpleMidiListener
,
+StandardMidiListener
,
+Note
,
+ControlChange
,
+MidiBus
Modifier and Type | +Method and Description | +
---|---|
void |
+controllerChange(ControlChange change)
+Objects notifying this ObjectMidiListener of a new ControllerChange events call this method.
+ |
+
void |
+noteOff(Note note)
+Objects notifying this ObjectMidiListener of a new NoteOff events call this method.
+ |
+
void |
+noteOn(Note note)
+Objects notifying this ObjectMidiListener of a new NoteOn events call this method.
+ |
+
void noteOn(Note note)+
note
- the note object associated with this eventvoid noteOff(Note note)+
note
- the note object associated with this eventvoid controllerChange(ControlChange change)+
change
- the ControlChange object associated with this eventpublic class PApplet
+extends java.lang.Object
++ Note: This page is a dummy page for documentation of the MidiBus' extention of the regular PApplet's functionality, for the full documentation of PApplet please visits the Processing javadocs
MidiBus
,
+MidiListener
,
+RawMidiListener
,
+StandardMidiListener
,
+SimpleMidiListener
Modifier and Type | +Method and Description | +
---|---|
void |
+controllerChange(ControlChange change)
+Is passed a ControlChange object representing controlChange event
+ |
+
void |
+controllerChange(int channel,
+ int number,
+ int value)
+Is passed the channel, controller number and contoller value associated with every new ContollerChange MIDI message recieved by a MidiBus attached to this applet.
+ |
+
void |
+controllerChange(int channel,
+ int number,
+ int value,
+ long timestamp,
+ java.lang.String bus_name)
+Is passed the channel, pitch and velocity associated with every new NoteOff MIDI message recieved by a MidiBus attached to this applet and the name of the MidiBus which recieved the message.
+ |
+
void |
+midiMessage(javax.sound.midi.MidiMessage message)
+Is passed the raw MidiMessage associated with every new MIDI message recieved by a MidiBus attached to this applet.
+ |
+
void |
+midiMessage(javax.sound.midi.MidiMessage message,
+ long timestamp,
+ java.lang.String bus_name)
+Is passed the raw MidiMessage associated with every new MIDI message recieved by a MidiBus attached to this applet and the name of the MidiBus which recieved the message.
+ |
+
void |
+noteOff(int channel,
+ int pitch,
+ int velocity)
+Is passed the channel, pitch and velocity associated with every new NoteOff MIDI message recieved by a MidiBus attached to this applet.
+ |
+
void |
+noteOff(int channel,
+ int pitch,
+ int velocity,
+ long timestamp,
+ java.lang.String bus_name)
+Is passed the channel, pitch and velocity associated with every new NoteOff MIDI message recieved by a MidiBus attached to this applet and the name of the MidiBus which recieved the message.
+ |
+
void |
+noteOff(Note note)
+Is passed a Note object representing noteOff event
+ |
+
void |
+noteOn(int channel,
+ int pitch,
+ int velocity)
+Is passed the channel, pitch and velocity associated with every new NoteOn MIDI message recieved by a MidiBus attached to this applet.
+ |
+
void |
+noteOn(int channel,
+ int pitch,
+ int velocity,
+ long timestamp,
+ java.lang.String bus_name)
+Is passed the channel, pitch and velocity associated with every new NoteOn MIDI message recieved by a MidiBus attached to this applet and the name of the MidiBus which recieved the message.
+ |
+
void |
+noteOn(Note note)
+Is passed a Note object representing noteOn event
+ |
+
void |
+rawMidi(byte[] data)
+Is passed the raw data associated with every new MIDI message recieved by a MidiBus attached to this applet.
+ |
+
void |
+rawMidi(byte[] data,
+ long timestamp,
+ java.lang.String bus_name)
+Is passed the raw data associated with every new MIDI message recieved by a MidiBus attached to this applet and the name of the MidiBus which recieved the message.
+ |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public void controllerChange(int channel, + int number, + int value)+
channel
- the channel on which the ContollerChange arrivednumber
- the controller number associated with the ContollerChangevalue
- the controller value associated with the ContollerChangecontrollerChange(int channel, int pitch, int velocity, long timestamp, String bus_name)
public void controllerChange(int channel, + int number, + int value, + long timestamp, + java.lang.String bus_name)+
channel
- the channel on which the ContollerChange arrivednumber
- the controller number associated with the ContollerChangevalue
- the controller value associated with the ContollerChangetimestamp
- the timestamp on the midi messagebus_name
- the name of MidiBus which recieved the ContollerChangecontrollerChange(int channel, int pitch, int velocity)
public void controllerChange(ControlChange change)+
change
- the ControlChange objectcontrollerChange(int channel, int pitch, int velocity)
,
+ObjectMidiListener.controllerChange(ControlChange)
public void midiMessage(javax.sound.midi.MidiMessage message)+
message
- the MidiMessage recievedmidiMessage(MidiMessage message, long timestamp, String bus_name)
public void midiMessage(javax.sound.midi.MidiMessage message, + long timestamp, + java.lang.String bus_name)+
message
- the MidiMessage recievedtimestamp
- the timestamp on the midi messagebus_name
- the name of MidiBus which recieved the MIDI messagemidiMessage(MidiMessage message)
public void noteOff(int channel, + int pitch, + int velocity)+
channel
- the channel on which the NoteOff arrivedpitch
- the pitch associated with the NoteOffvelocity
- the velocity associated with the NoteOffnoteOff(int channel, int pitch, int velocity, long timestamp, String bus_name)
public void noteOff(int channel, + int pitch, + int velocity, + long timestamp, + java.lang.String bus_name)+
channel
- the channel on which the NoteOff arrivedpitch
- the pitch associated with the NoteOffvelocity
- the velocity associated with the NoteOfftimestamp
- the timestamp on the midi messagebus_name
- the name of MidiBus which recieved the NoteOffnoteOff(int channel, int pitch, int velocity)
public void noteOff(Note note)+
note
- the Note objectnoteOff(int channel, int pitch, int velocity)
,
+ObjectMidiListener.noteOn(Note)
public void noteOn(int channel, + int pitch, + int velocity)+
channel
- the channel on which the NoteOn arrivedpitch
- the pitch associated with the NoteOnvelocity
- the velocity associated with the NoteOnnoteOn(int channel, int pitch, int velocity, long timestamp, String bus_name)
public void noteOn(int channel, + int pitch, + int velocity, + long timestamp, + java.lang.String bus_name)+
channel
- the channel on which the NoteOn arrivedpitch
- the pitch associated with the NoteOnvelocity
- the velocity associated with the NoteOntimestamp
- the timestamp on the midi messagebus_name
- the name of MidiBus which recieved the NoteOnnoteOn(int channel, int pitch, int velocity)
public void noteOn(Note note)+
note
- the Note objectnoteOn(int channel, int pitch, int velocity)
,
+ObjectMidiListener.noteOff(Note)
public void rawMidi(byte[] data)+
data
- the raw data associated with the MIDI messagerawMidi(byte[] data, long timestamp, String bus_name)
public void rawMidi(byte[] data, + long timestamp, + java.lang.String bus_name)+
data
- the raw data associated with the MIDI messagetimestamp
- the timestamp on the midi messagebus_name
- the name of MidiBus which recieved the MIDI messagerawMidi(byte[] data)
public interface RawMidiListener +extends MidiListener+
MidiListener
,
+SimpleMidiListener
,
+StandardMidiListener
,
+ObjectMidiListener
,
+MidiBus
Modifier and Type | +Method and Description | +
---|---|
void |
+rawMidiMessage(byte[] data)
+Objects notifying this RawMidiListener of a new MIDI message call this method and pass the raw message to it.
+ |
+
public interface SimpleMidiListener +extends MidiListener+
MidiListener
,
+RawMidiListener
,
+StandardMidiListener
,
+ObjectMidiListener
,
+MidiBus
Modifier and Type | +Method and Description | +
---|---|
void |
+controllerChange(int channel,
+ int number,
+ int value)
+Objects notifying this SimpleMidiListener of a new ControllerChange MIDI message call this method.
+ |
+
void |
+noteOff(int channel,
+ int pitch,
+ int velocity)
+Objects notifying this SimpleMidiListener of a new NoteOff MIDI message call this method.
+ |
+
void |
+noteOn(int channel,
+ int pitch,
+ int velocity)
+Objects notifying this SimpleMidiListener of a new NoteOn MIDI message call this method.
+ |
+
void noteOn(int channel, + int pitch, + int velocity)+
channel
- the channel on which the NoteOn arrivedpitch
- the pitch associated with the NoteOnvelocity
- the velocity associated with the NoteOnvoid noteOff(int channel, + int pitch, + int velocity)+
channel
- the channel on which the NoteOff arrivedpitch
- the pitch associated with the NoteOffvelocity
- the velocity associated with the NoteOffvoid controllerChange(int channel, + int number, + int value)+
channel
- the channel on which the ContollerChange arrivednumber
- the controller number associated with the ContollerChangevalue
- the controller value associated with the ContollerChangepublic interface StandardMidiListener +extends MidiListener+
MidiListener
,
+RawMidiListener
,
+SimpleMidiListener
,
+ObjectMidiListener
,
+MidiBus
,
+MidiMessage
Modifier and Type | +Method and Description | +
---|---|
void |
+midiMessage(javax.sound.midi.MidiMessage message,
+ long timeStamp)
+Objects notifying this StandardMidiListener of a new MIDI message call this method and pass the MidiMessage
+ |
+
See: Description
+Interface | +Description | +
---|---|
MidiListener | +
+ This is a placeholder interface which makes it easier to program and manipulate objects which implement subinterfaces of MidiListener like
+RawMidiListener , SimpleMidiListener or StandardMidiListener . |
+
ObjectMidiListener | +
+ A ObjectMidiListener can be notified of incomming NoteOn, NoteOff and ControllerChange events via
+Note and ControlChange objects, usually by a MidiBus object which it is connected to. |
+
RawMidiListener | +
+ A RawMidiListener can be notified of incomming MIDI messages in raw form, usually by a MidiBus object which it is connect to.
+ |
+
SimpleMidiListener | +
+ A SimpleMidiListener can be notified of incomming NoteOn, NoteOff and ControllerChange MIDI messages, usually by a MidiBus object which it is connected to.
+ |
+
StandardMidiListener | +
+ A StandardMidiListener can be notified of incomming MIDI messages in MidiMessage form, usually by a MidiBus object which it is connected to.
+ |
+
Class | +Description | +
---|---|
ControlChange | +
+ The ControlChange class represents a change in value from a controller.
+ |
+
MidiBus | +
+ The MidiBus class provides a simple way to send and receive MIDI within Processing sketches.
+ |
+
Note | +
+ The Note class represents a pressed or released key.
+ |
+
PApplet | +
+ PApplet is your processing application or sketch.
+ |
+
+ IMPORTANT: Mac users may want to install mmj, a Mac OS X universal binary java MIDI subsystem - or an equivalent third party MIDI subsystem - because the apple implementation is lacking support for a number of advanced MIDI features. Mmj is recommended because it works, it's free and it's almost open source (CC licence). Please check README.md for more information. If you do use MMJ you will want to set MidiBus.sendTimestamps(boolean sendTimestamps)
to false, otherwise messages won't be sent.
+
+ Keeping with the spirit of Processing's easy to use sketching/prototyping style, the MidiBus offers a clean and simple way to get at MIDI ressources. Getting the basic functionality of the MidiBus up and running in a sketch is a matter of only a few line. The MidiBus
class provides everything needed send and receive MIDI inside a sketch. To jump right into the Midibus, either refer to the paragraph titled "Typical Implementation, Simple" in the description for the MidiBus
class, or check out the code examples distributed with this library.
+
+ It is important to understand that the MidiBus offers little functionality that isn't available from Java's native javax.sound.midi package. Anyone interested in working with MIDI in Java should take the time to read the documentation for the javax.sound.midi. It offers a more full featured and flexible alternative to this package, although it does do so at the cost of added complexity. In addition, it may be worthwhile to skim the "official" Java Tutorial for the javax.sound.* packages. +
+ *
+ * A typical simple Processing MIDI application would begin by invoking the static method {@link #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 {@link #sendNoteOn(int channel, int pitch, int velocity)}, {@link #sendNoteOff(int channel, int pitch, int velocity)} and {@link #sendControllerChange(int channel, int number, int value)} and receive midi via the PApplet methods this package provides support for such as {@link PApplet#noteOn(int channel, int pitch, int velocity)}, {@link PApplet#noteOff(int channel, int pitch, int velocity)} and {@link 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 {@link PApplet} methods with the bus_name parameter.
+ *
+ * @version 008
+ * @author Severin Smith
+ * @see PApplet
+ * @see MidiListener
+ * @see RawMidiListener
+ * @see StandardMidiListener
+ * @see SimpleMidiListener
+*/
+public class MidiBus {
+
+ static MidiDevice.Info[] available_devices;
+
+ String bus_name;
+
+ Vector
+ * If two or more MIDI inputs have the same name, whichever appears first when {@link #list()} is called will be added, simlarly for two or more MIDI outputs with the same name. If this behavior is problematic use {@link #MidiBus(Object parent, int in_device_num, int out_device_num)} instead.
+ *
+ * @param parent the parent to which this MidiBus is attached.
+ * @param in_device_name the name of the MIDI input device to be opened.
+ * @param out_device_name the name of the MIDI output device to be opened.
+ * @see #addInput(int device_num)
+ * @see #addInput(String device_name)
+ * @see #addOutput(int device_num)
+ * @see #addOutput(String device_name)
+ * @see #list()
+ */
+ public MidiBus(Object parent, String in_device_name, String out_device_name) {
+ init(parent, null);
+ addInput(in_device_name);
+ addOutput(out_device_name);
+ }
+
+ /**
+ * Constructs a new MidiBus with the specified bus_name and registers the specified parent (PApplet or other) for callbacks. Opens the MIDI input and output devices specified by the names out_device_name and out_device_name. An empty String can be passed to in_device_name if no input MIDI device is to be opened, or to out_device_name if no output MIDI device is to be opened.
+ *
+ * If two or more MIDI inputs have the same name, whichever appears first when {@link #list()} is called will be added, simlarly for two or more MIDI outputs with the same name. If this behavior is problematic use {@link #MidiBus(Object parent, int in_device_num, int out_device_num, String bus_name)} instead.
+ *
+ * @param parent the parent to which this MidiBus is attached.
+ * @param in_device_name the name of the MIDI input device to be opened.
+ * @param out_device_name the name of the MIDI output device to be opened.
+ * @param bus_name the String which which identifies this MidiBus.
+ * @see #addInput(int device_num)
+ * @see #addInput(String device_name)
+ * @see #addOutput(int device_num)
+ * @see #addOutput(String device_name)
+ * @see #list()
+ */
+ public MidiBus(Object parent, String in_device_name, String out_device_name, String bus_name) {
+ init(parent, bus_name);
+ addInput(in_device_name);
+ addOutput(out_device_name);
+ }
+
+ /* -- Yet even more delicious constructor flavors -- */
+
+ /**
+ * More flavors of constructor, similar to the others, but with mixed arguments
+ *
+ * @param parent the parent to which this MidiBus is attached.
+ * @param in_device_num the name of the MIDI input device to be opened.
+ * @param out_device_name the name of the MIDI output device to be opened.
+ * @see #addInput(int device_num)
+ * @see #addInput(String device_name)
+ * @see #addOutput(int device_num)
+ * @see #addOutput(String device_name)
+ * @see #list()
+ */
+ public MidiBus(Object parent, int in_device_num, String out_device_name) {
+ init(parent, null);
+ addInput(in_device_num);
+ addOutput(out_device_name);
+ }
+
+ /**
+ * More flavors of constructor, similar to the others, but with mixed arguments
+ *
+ * @param parent the parent to which this MidiBus is attached.
+ * @param in_device_num the name of the MIDI input device to be opened.
+ * @param out_device_name the name of the MIDI output device to be opened.
+ * @param bus_name the String which which identifies this MidiBus.
+ * @see #addInput(int device_num)
+ * @see #addInput(String device_name)
+ * @see #addOutput(int device_num)
+ * @see #addOutput(String device_name)
+ * @see #list()
+ */
+ public MidiBus(Object parent, int in_device_num, String out_device_name, String bus_name) {
+ init(parent, bus_name);
+ addInput(in_device_num);
+ addOutput(out_device_name);
+ }
+
+ /**
+ * More flavors of constructor, similar to the others, but with mixed arguments
+ *
+ * @param parent the parent to which this MidiBus is attached.
+ * @param in_device_name the name of the MIDI input device to be opened.
+ * @param out_device_num the name of the MIDI output device to be opened.
+ * @see #addInput(int device_num)
+ * @see #addInput(String device_name)
+ * @see #addOutput(int device_num)
+ * @see #addOutput(String device_name)
+ * @see #list()
+ */
+ public MidiBus(Object parent, String in_device_name, int out_device_num) {
+ init(parent, null);
+ addInput(in_device_name);
+ addOutput(out_device_num);
+ }
+
+ /**
+ * More flavors of constructor, similar to the others, but with mixed arguments
+ *
+ * @param parent the parent to which this MidiBus is attached.
+ * @param in_device_name the name of the MIDI input device to be opened.
+ * @param out_device_num the name of the MIDI output device to be opened.
+ * @param bus_name the String which which identifies this MidiBus.
+ * @see #addInput(int device_num)
+ * @see #addInput(String device_name)
+ * @see #addOutput(int device_num)
+ * @see #addOutput(String device_name)
+ * @see #list()
+ */
+ public MidiBus(Object parent, String in_device_name, int out_device_num, String bus_name) {
+ init(parent, bus_name);
+ addInput(in_device_name);
+ addOutput(out_device_num);
+ }
+
+ /* -- Constructor Functions -- */
+
+ /**
+ * Perfoms the initialisation of new MidiBus objects, is private for a reason, and is only ever called within the constructors. This method exists only for the purpose of cleaner and easier to maintain code.
+ * Creates a new (hopefully/probably) unique bus_name value for new MidiBus objects that weren't given one.
+ * If two MidiBus object were to have the same name, this would be bad, but not fatal, so there's no point in spending too much time worrying about it.
+ */
+ private void init(Object parent, String bus_name) {
+ registerParent(parent);
+
+ /* -- */
+
+ if(bus_name == null) {
+ generateBusName();
+ } else {
+ this.bus_name = bus_name;
+ }
+
+ /* -- */
+
+ input_devices = new Vector
+ * If two or more MIDI inputs have the same name, whichever appears first when {@link #list()} is called will be added. If this behavior is problematic use {@link #addInput(int device_num)} instead.
+ *
+ * @param device_name the name of the MIDI input device to be added.
+ * @return true if and only if the input device was successfully added.
+ * @see #addInput(int device_num)
+ * @see #list()
+ */
+ public boolean addInput(String device_name) {
+ if(device_name.equals("")) return false;
+
+ MidiDevice.Info[] devices = availableInputsMidiDeviceInfo();
+
+ for(int i = 0;i < devices.length;i++) {
+ if(devices[i].getName().equals(device_name)) return addInput(devices[i]);
+ }
+
+ System.err.println("\nThe MidiBus Warning: No available input MIDI devices named: \""+device_name+"\" were found");
+ return false;
+ }
+
+ /**
+ * Removes the MIDI input device specified by the name device_name.
+ *
+ * If two or more attached MIDI inputs have the same name, whichever appears first when {@link #attachedInputs()} is called will be removed. If this behavior is problematic use {@link #removeInput(int device_num)} instead.
+ *
+ * @param device_name the name of the MIDI input device to be removed.
+ * @return true if and only if the input device was successfully removed.
+ * @see #removeInput(int device_num)
+ * @see #attachedInputs()
+ */
+ public synchronized boolean removeInput(String device_name) {
+ for(InputDeviceContainer container : input_devices) {
+ if(container.info.getName().equals(device_name)) {
+ input_devices.remove(container);
+
+ container.transmitter.close();
+ container.receiver.close();
+
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Adds a new MIDI input device specified by the MidiDevice.Info device_info. If the MIDI input device has already been added, it will not be added again.
+ *
+ * @param device_info the MidiDevice.Info of the MIDI input device to be added.
+ * @return true if and only if the input device was successfully added.
+ */
+ synchronized boolean addInput(MidiDevice.Info device_info) {
+ try {
+ MidiDevice new_device = MidiSystem.getMidiDevice(device_info);
+
+ if(new_device.getMaxTransmitters() == 0) {
+ System.err.println("\nThe MidiBus Warning: The chosen input device \""+device_info.getName()+"\" was not added because it is output only");
+ return false;
+ }
+
+ for(InputDeviceContainer container : input_devices) {
+ if(device_info.getName().equals(container.info.getName())) return false;
+ }
+
+ if(!new_device.isOpen()) new_device.open();
+
+ MReceiver receiver = new MReceiver();
+ Transmitter transmitter = new_device.getTransmitter();
+ transmitter.setReceiver(receiver);
+
+ InputDeviceContainer new_container = new InputDeviceContainer(new_device);
+ new_container.transmitter = transmitter;
+ new_container.receiver = receiver;
+
+ input_devices.add(new_container);
+
+ return true;
+ } catch(MidiUnavailableException e) {
+ System.err.println("\nThe MidiBus Warning: The chosen input device \""+device_info.getName()+"\" was not added because it is unavailable");
+ return false;
+ }
+ }
+
+ /**
+ * Adds a new MIDI output device specified by the index device_num. If the MIDI output device has already been added, it will not be added again.
+ *
+ * @param device_num the index of the MIDI output device to be added.
+ * @return true if and only if the output device was successfully added.
+ * @see #addOutput(String device_name)
+ * @see #list()
+ */
+ public boolean addOutput(int device_num) {
+ if(device_num == -1) return false;
+
+ MidiDevice.Info[] devices = availableOutputsMidiDeviceInfo();
+
+ if(device_num >= devices.length || device_num < 0) {
+ System.err.println("\nThe MidiBus Warning: The chosen output device numbered ["+device_num+"] was not added because it doesn't exist");
+ return false;
+ }
+
+ return addOutput(devices[device_num]);
+ }
+
+ /**
+ * Removes the MIDI output device specified by the index device_num.
+ *
+ * @param device_num the index of the MIDI output device to be removed.
+ * @return true if and only if the output device was successfully removed.
+ * @see #removeInput(String device_name)
+ * @see #attachedOutputs()
+ */
+ public synchronized boolean removeOutput(int device_num) {
+ try {
+ OutputDeviceContainer container = output_devices.get(device_num);
+
+ output_devices.remove(container);
+
+ container.receiver.close();
+
+ return true;
+ } catch(ArrayIndexOutOfBoundsException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Adds a new MIDI output device specified by the name device_name. If the MIDI output device has already been added, it will not be added again.
+ *
+ * If two or more MIDI outputs have the same name, whichever appears first when {@link #list()} is called will be added. If this behavior is problematic use {@link #addOutput(int device_num)} instead.
+ *
+ * @param device_name the name of the MIDI output device to be added.
+ * @return true if and only if the output device was successfully added.
+ * @see #addOutput(int device_num)
+ * @see #list()
+ */
+ public boolean addOutput(String device_name) {
+ if(device_name.equals("")) return false;
+
+ MidiDevice.Info[] devices = availableOutputsMidiDeviceInfo();
+
+ for(int i = 0;i < devices.length;i++) {
+ if(devices[i].getName().equals(device_name)) return addOutput(devices[i]);
+ }
+
+ System.err.println("\nThe MidiBus Warning: No available input MIDI devices named: \""+device_name+"\" were found");
+ return false;
+ }
+
+ /**
+ * Removes the MIDI output device specified by the name device_name.
+ *
+ * If two or more attached MIDI outputs have the same name, whichever appears first when {@link #attachedOutputs()} is called will be removed. If this behavior is problematic use {@link #removeOutput(int device_num)} instead.
+ *
+ * @param device_name the name of the MIDI output device to be removed.
+ * @return true if and only if the output device was successfully removed.
+ * @see #removeOutput(int device_num)
+ * @see #attachedOutputs()
+ */
+ public synchronized boolean removeOutput(String device_name) {
+ for(OutputDeviceContainer container : output_devices) {
+ if(container.info.getName().equals(device_name)) {
+ output_devices.remove(container);
+
+ container.receiver.close();
+
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Adds a new MIDI output device specified by the MidiDevice.Info device_info. If the MIDI output device has already been added, it will not be added again.
+ *
+ * @param device_info the MidiDevice.Info of the MIDI output device to be added.
+ * @return true if and only if the input device was successfully added.
+ */
+ synchronized boolean addOutput(MidiDevice.Info device_info) {
+ try {
+ MidiDevice new_device = MidiSystem.getMidiDevice(device_info);
+
+ if(new_device.getMaxReceivers() == 0) {
+ System.err.println("\nThe MidiBus Warning: The chosen output device \""+device_info.getName()+"\" was not added because it is input only");
+ return false;
+ }
+
+ for(OutputDeviceContainer container : output_devices) {
+ if(device_info.getName().equals(container.info.getName())) return false;
+ }
+
+ if(!new_device.isOpen()) new_device.open();
+
+ OutputDeviceContainer new_container = new OutputDeviceContainer(new_device);
+ new_container.receiver = new_device.getReceiver();
+
+ output_devices.add(new_container);
+
+ return true;
+ } catch(MidiUnavailableException e) {
+ System.err.println("\nThe MidiBus Warning: The chosen output device \""+device_info.getName()+"\" was not added because it is unavailable");
+ return false;
+ }
+ }
+
+ /**
+ * Closes, clears and disposes of all input related Transmitters and Receivers.
+ *
+ * @see #clearOutputs()
+ * @see #clearAll()
+ */
+ public synchronized void clearInputs() {
+ //We are purposefully not closing devices here, because in some cases that will be slow, and we might want later
+ //Also it's broken on MAC
+ try{
+ for(InputDeviceContainer container : input_devices) {
+ container.transmitter.close();
+ container.receiver.close();
+ }
+ } catch(Exception e) {
+ System.err.println("The MidiBus Warning: Unexpected error during clearInputs()");
+ }
+
+ input_devices.clear();
+ }
+
+ /**
+ * Closes, clears and disposes of all output related Receivers.
+ *
+ * @see #clearInputs()
+ * @see #clearAll()
+ */
+ public synchronized void clearOutputs() {
+ //We are purposefully not closing devices here, because in some cases that will be slow, and we might want later
+ //Also it's broken on MAC
+ try{
+ for(OutputDeviceContainer container : output_devices) {
+ container.receiver.close();
+ }
+ } catch(Exception e) {
+ System.err.println("The MidiBus Warning: Unexpected error during clearOutputs()");
+ }
+
+ output_devices.clear();
+ }
+
+ /**
+ * Closes, clears and disposes of all input and output related Transmitters and Receivers.
+ *
+ * @see #clearInputs()
+ * @see #clearOutputs()
+ */
+ public void clearAll() {
+ clearInputs();
+ clearOutputs();
+ }
+
+ /**
+ * Closes all MidiDevices, should only be called when closing the application, will interrupt all MIDI I/O. Call publicly from stop(), close() or dispose()
+ *
+ * @see #clearOutputs()
+ * @see #clearInputs()
+ * @see #clearAll()
+ * @see #stop()
+ * @see #close()
+ * @see #dispose()
+ */
+ void closeAllMidiDevices() {
+ if(MidiBus.available_devices == null) findMidiDevices();
+ MidiDevice device;
+
+ for(int i = 0;i < MidiBus.available_devices.length;i++) {
+ try {
+ device = MidiSystem.getMidiDevice(MidiBus.available_devices[i]);
+ if(device.isOpen()) device.close();
+ } catch(MidiUnavailableException e) {
+ //Device wasn't available, which is fine since we wanted to close it anyways
+ }
+ }
+
+ }
+
+ /* -- MIDI Out -- */
+
+ /**
+ * Sends a MIDI message with an unspecified number of bytes. The first byte should be always be the status byte. If the message is a Meta message of a System Exclusive message it can have more than 3 byte, otherwise all extra bytes will be dropped.
+ *
+ * @param data the bytes of the MIDI message.
+ * @see #sendMessage(int status)
+ * @see #sendMessage(int status, int data)
+ * @see #sendMessage(int status, int data1, int data2)
+ * @see #sendMessage(int command, int channel, int data1, int data2)
+ * @see #sendMessage(MidiMessage message)
+ * @see #sendNoteOn(int channel, int pitch, int velocity)
+ * @see #sendNoteOn(Note note)
+ * @see #sendNoteOff(int channel, int pitch, int velocity)
+ * @see #sendNoteOff(Note note)
+ * @see #sendControllerChange(int channel, int number, int value)
+ * @see #sendControllerChange(ControlChange change)
+ */
+ public void sendMessage(byte[] data) {
+ if((int)((byte)data[0] & 0xFF) == MetaMessage.META) {
+ MetaMessage message = new MetaMessage();
+ try {
+ byte[] payload = new byte[data.length-2];
+ System.arraycopy(data, 2, payload, 0, data.length-2);
+ message.setMessage((int)((byte)data[1] & 0xFF), payload, data.length-2);
+ sendMessage(message);
+ } catch(InvalidMidiDataException e) {
+ System.err.println("\nThe MidiBus Warning: Message not sent, invalid MIDI data");
+ }
+ } else if((int)((byte)data[0] & 0xFF) == SysexMessage.SYSTEM_EXCLUSIVE || (int)((byte)data[0] & 0xFF) == SysexMessage.SPECIAL_SYSTEM_EXCLUSIVE) {
+ SysexMessage message = new SysexMessage();
+ try {
+ message.setMessage(data, data.length);
+ sendMessage(message);
+ } catch(InvalidMidiDataException e) {
+ System.err.println("\nThe MidiBus Warning: Message not sent, invalid MIDI data");
+ }
+ } else {
+ ShortMessage message = new ShortMessage();
+ try {
+ if(data.length > 2) message.setMessage((int)((byte)data[0] & 0xFF), (int)((byte)data[1] & 0xFF), (int)((byte)data[2] & 0xFF));
+ else if(data.length > 1) message.setMessage((int)((byte)data[0] & 0xFF), (int)((byte)data[1] & 0xFF), 0);
+ else message.setMessage((int)((byte)data[0] & 0xFF));
+ sendMessage(message);
+ } catch(InvalidMidiDataException e) {
+ System.err.println("\nThe MidiBus Warning: Message not sent, invalid MIDI data");
+ }
+ }
+ }
+
+ /**
+ * Sends a MIDI message that takes no data bytes.
+ *
+ * @param status the status byte
+ * @see #sendMessage(byte[] data)
+ * @see #sendMessage(int status, int data)
+ * @see #sendMessage(int status, int data1, int data2)
+ * @see #sendMessage(int command, int channel, int data1, int data2)
+ * @see #sendMessage(MidiMessage message)
+ * @see #sendNoteOn(int channel, int pitch, int velocity)
+ * @see #sendNoteOn(Note note)
+ * @see #sendNoteOff(int channel, int pitch, int velocity)
+ * @see #sendNoteOff(Note note)
+ * @see #sendControllerChange(int channel, int number, int value)
+ * @see #sendControllerChange(ControlChange change)
+ */
+ public void sendMessage(int status) {
+ ShortMessage message = new ShortMessage();
+ try {
+ message.setMessage(status);
+ sendMessage(message);
+ } catch(InvalidMidiDataException e) {
+ System.out.println(e);
+ System.err.println("\nThe MidiBus Warning: Message not sent, invalid MIDI data");
+ }
+ }
+
+ /**
+ * Sends a MIDI message that takes only one data byte. If the message does not take data, the data byte is ignored.
+ *
+ * @param status the status byte
+ * @param data the data byte
+ * @see #sendMessage(byte[] data)
+ * @see #sendMessage(int status)
+ * @see #sendMessage(int status, int data1, int data2)
+ * @see #sendMessage(int command, int channel, int data1, int data2)
+ * @see #sendMessage(MidiMessage message)
+ * @see #sendNoteOn(int channel, int pitch, int velocity)
+ * @see #sendNoteOn(Note note)
+ * @see #sendNoteOff(int channel, int pitch, int velocity)
+ * @see #sendNoteOff(Note note)
+ * @see #sendControllerChange(int channel, int number, int value)
+ * @see #sendControllerChange(ControlChange change)
+ */
+ public void sendMessage(int status, int data) {
+ sendMessage(status, data, 0);
+ }
+
+ /**
+ * Sends a MIDI message that takes one or two data bytes. If the message takes only one data byte, the second data byte is ignored; if the message does not take any data bytes, both data bytes are ignored.
+ *
+ * @param status the status byte.
+ * @param data1 the first data byte.
+ * @param data2 the second data byte.
+ * @see #sendMessage(byte[] data)
+ * @see #sendMessage(int status)
+ * @see #sendMessage(int status, int data)
+ * @see #sendMessage(int command, int channel, int data1, int data2)
+ * @see #sendMessage(MidiMessage message)
+ * @see #sendNoteOn(int channel, int pitch, int velocity)
+ * @see #sendNoteOn(Note note)
+ * @see #sendNoteOff(int channel, int pitch, int velocity)
+ * @see #sendNoteOff(Note note)
+ * @see #sendControllerChange(int channel, int number, int value)
+ * @see #sendControllerChange(ControlChange change)
+ */
+ public void sendMessage(int status, int data1, int data2) {
+ ShortMessage message = new ShortMessage();
+ try {
+ message.setMessage(status, data1, data2);
+ sendMessage(message);
+ } catch(InvalidMidiDataException e) {
+ System.err.println("\nThe MidiBus Warning: Message not sent, invalid MIDI data");
+ }
+ }
+
+ /**
+ * Sends a channel message which takes up to two data bytes. If the message only takes one data byte, the second data byte is ignored; if the message does not take any data bytes, both data bytes are ignored.
+ *
+ * @param command the MIDI command represented by this message.
+ * @param channel the channel associated with the message.
+ * @param data1 the first data byte.
+ * @param data2 the second data byte.
+ * @see #sendMessage(byte[] data)
+ * @see #sendMessage(int status)
+ * @see #sendMessage(int status, int data)
+ * @see #sendMessage(int status, int data1, int data2)
+ * @see #sendMessage(MidiMessage message)
+ * @see #sendNoteOn(int channel, int pitch, int velocity)
+ * @see #sendNoteOn(Note note)
+ * @see #sendNoteOff(int channel, int pitch, int velocity)
+ * @see #sendNoteOff(Note note)
+ * @see #sendControllerChange(int channel, int number, int value)
+ * @see #sendControllerChange(ControlChange change)
+ */
+ public void sendMessage(int command, int channel, int data1, int data2) {
+ ShortMessage message = new ShortMessage();
+ try {
+ message.setMessage(command, channel, data1, data2);
+ sendMessage(message);
+ } catch(InvalidMidiDataException e) {
+ System.err.println("\nThe MidiBus Warning: Message not sent, invalid MIDI data");
+ }
+ }
+
+ /**
+ * Sends a MidiMessage object.
+ *
+ * @param message the MidiMessage.
+ * @see #sendMessage(byte[] data)
+ * @see #sendMessage(int status)
+ * @see #sendMessage(int status, int data)
+ * @see #sendMessage(int status, int data1, int data2)
+ * @see #sendMessage(int command, int channel, int data1, int data2)
+ * @see #sendNoteOn(int channel, int pitch, int velocity)
+ * @see #sendNoteOn(Note note)
+ * @see #sendNoteOff(int channel, int pitch, int velocity)
+ * @see #sendNoteOff(Note note)
+ * @see #sendControllerChange(int channel, int number, int value)
+ * @see #sendControllerChange(ControlChange change)
+ */
+ public synchronized void sendMessage(MidiMessage message) {
+ for(OutputDeviceContainer container : output_devices) {
+ if(sendTimestamps) container.receiver.send(message, System.currentTimeMillis());
+ else container.receiver.send(message, 0);
+ }
+ }
+
+ /**
+ * Sends a NoteOn message to a channel with the specified pitch and velocity.
+ *
+ * @param channel the channel associated with the message.
+ * @param pitch the pitch associated with the message.
+ * @param velocity the velocity associated with the message.
+ * @see #sendMessage(byte[] data)
+ * @see #sendMessage(int status)
+ * @see #sendMessage(int status, int data)
+ * @see #sendMessage(int status, int data1, int data2)
+ * @see #sendMessage(int command, int channel, int data1, int data2)
+ * @see #sendMessage(MidiMessage message)
+ * @see #sendNoteOn(Note note)
+ * @see #sendNoteOff(int channel, int pitch, int velocity)
+ * @see #sendNoteOff(Note note)
+ * @see #sendControllerChange(int channel, int number, int value)
+ * @see #sendControllerChange(ControlChange change)
+ *
+ */
+ public void sendNoteOn(int channel, int pitch, int velocity) {
+ ShortMessage message = new ShortMessage();
+ try {
+ message.setMessage(ShortMessage.NOTE_ON, constrain(channel,0,15), constrain(pitch,0,127), constrain(velocity,0,127));
+ sendMessage(message);
+ } catch(InvalidMidiDataException e) {
+ System.err.println("\nThe MidiBus Warning: Message not sent, invalid MIDI data");
+ }
+ }
+
+ /**
+ * Sends a NoteOn message to a channel with the specified Note.
+ *
+ * @param note the Note object for the message.
+ * @see #sendMessage(byte[] data)
+ * @see #sendMessage(int status)
+ * @see #sendMessage(int status, int data)
+ * @see #sendMessage(int status, int data1, int data2)
+ * @see #sendMessage(int command, int channel, int data1, int data2)
+ * @see #sendMessage(MidiMessage message)
+ * @see #sendNoteOn(int channel, int pitch, int velocity)
+ * @see #sendNoteOff(int channel, int pitch, int velocity)
+ * @see #sendNoteOff(Note note)
+ * @see #sendControllerChange(int channel, int number, int value)
+ * @see #sendControllerChange(ControlChange change)
+ */
+ public void sendNoteOn(Note note) {
+ sendNoteOn(note.channel(), note.pitch(), note.velocity());
+ }
+
+ /**
+ * Sends a NoteOff message to a channel with the specified pitch and velocity.
+ *
+ * @param channel the channel associated with the message.
+ * @param pitch the pitch associated with the message.
+ * @param velocity the velocity associated with the message.
+ * @see #sendMessage(byte[] data)
+ * @see #sendMessage(int status)
+ * @see #sendMessage(int status, int data)
+ * @see #sendMessage(int status, int data1, int data2)
+ * @see #sendMessage(int command, int channel, int data1, int data2)
+ * @see #sendMessage(MidiMessage message)
+ * @see #sendNoteOn(int channel, int pitch, int velocity)
+ * @see #sendNoteOn(Note note)
+ * @see #sendNoteOff(Note note)
+ * @see #sendControllerChange(int channel, int number, int value)
+ * @see #sendControllerChange(ControlChange change)
+ */
+ public void sendNoteOff(int channel, int pitch, int velocity) {
+ ShortMessage message = new ShortMessage();
+ try {
+ message.setMessage(ShortMessage.NOTE_OFF, constrain(channel,0,15), constrain(pitch,0,127), constrain(velocity,0,127));
+ sendMessage(message);
+ } catch(InvalidMidiDataException e) {
+ System.err.println("\nThe MidiBus Warning: Message not sent, invalid MIDI data");
+ }
+ }
+
+ /**
+ * Sends a NoteOff message to a channel with the specified Note.
+ *
+ * @param note the Note object for the message.
+ * @see #sendMessage(byte[] data)
+ * @see #sendMessage(int status)
+ * @see #sendMessage(int status, int data)
+ * @see #sendMessage(int status, int data1, int data2)
+ * @see #sendMessage(int command, int channel, int data1, int data2)
+ * @see #sendMessage(MidiMessage message)
+ * @see #sendNoteOn(int channel, int pitch, int velocity)
+ * @see #sendNoteOn(Note note)
+ * @see #sendNoteOff(int channel, int pitch, int velocity)
+ * @see #sendControllerChange(int channel, int number, int value)
+ * @see #sendControllerChange(ControlChange change)
+ */
+ public void sendNoteOff(Note note) {
+ sendNoteOff(note.channel, note.pitch(), note.velocity());
+ }
+
+ /**
+ * Sends a ControllerChange message to a channel with the specified number and value.
+ *
+ * @param channel the channel associated with the message.
+ * @param number the number associated with the message.
+ * @param value the value associated with the message.
+ * @see #sendMessage(byte[] data)
+ * @see #sendMessage(int status)
+ * @see #sendMessage(int status, int data)
+ * @see #sendMessage(int status, int data1, int data2)
+ * @see #sendMessage(int command, int channel, int data1, int data2)
+ * @see #sendMessage(MidiMessage message)
+ * @see #sendNoteOn(int channel, int pitch, int velocity)
+ * @see #sendNoteOn(Note note)
+ * @see #sendNoteOff(int channel, int pitch, int velocity)
+ * @see #sendNoteOff(Note note)
+ * @see #sendControllerChange(ControlChange change)
+ */
+ public void sendControllerChange(int channel, int number, int value) {
+ ShortMessage message = new ShortMessage();
+ try {
+ message.setMessage(ShortMessage.CONTROL_CHANGE, constrain(channel,0,15), constrain(number,0,127), constrain(value,0,127));
+ sendMessage(message);
+ } catch(InvalidMidiDataException e) {
+ System.err.println("\nThe MidiBus Warning: Message not sent, invalid MIDI data");
+ }
+ }
+
+ /**
+ * Sends a ControllerChange message to a channel with the specified ControlChange.
+ *
+ * @param change the ControlChange object for the message.
+ * @see #sendMessage(byte[] data)
+ * @see #sendMessage(int status)
+ * @see #sendMessage(int status, int data)
+ * @see #sendMessage(int status, int data1, int data2)
+ * @see #sendMessage(int command, int channel, int data1, int data2)
+ * @see #sendMessage(MidiMessage message)
+ * @see #sendNoteOn(int channel, int pitch, int velocity)
+ * @see #sendNoteOn(Note note)
+ * @see #sendNoteOff(int channel, int pitch, int velocity)
+ * @see #sendNoteOff(Note note)
+ * @see #sendControllerChange(int channel, int number, int value)
+ */
+ public void sendControllerChange(ControlChange change) {
+ sendControllerChange(change.channel(), change.number(), change.value());
+ }
+
+ /* -- MIDI In -- */
+
+ /**
+ * Notifies all types of listeners of a new MIDI message from one of the MIDI input devices.
+ *
+ * @param message the new inbound MidiMessage.
+ */
+ void notifyListeners(MidiMessage message, long timeStamp) {
+ byte[] data = message.getMessage();
+
+ for(MidiListener listener : listeners) {
+
+ /* -- RawMidiListener -- */
+
+ if(listener instanceof RawMidiListener) ((RawMidiListener)listener).rawMidiMessage(data);
+
+ /* -- SimpleMidiListener -- */
+
+ if(listener instanceof SimpleMidiListener) {
+ if((int)((byte)data[0] & 0xF0) == ShortMessage.NOTE_ON) {
+ ((SimpleMidiListener)listener).noteOn((int)(data[0] & 0x0F),(int)(data[1] & 0xFF),(int)(data[2] & 0xFF));
+ } else if((int)((byte)data[0] & 0xF0) == ShortMessage.NOTE_OFF) {
+ ((SimpleMidiListener)listener).noteOff((int)(data[0] & 0x0F),(int)(data[1] & 0xFF),(int)(data[2] & 0xFF));
+ } else if((int)((byte)data[0] & 0xF0) == ShortMessage.CONTROL_CHANGE) {
+ ((SimpleMidiListener)listener).controllerChange((int)(data[0] & 0x0F),(int)(data[1] & 0xFF),(int)(data[2] & 0xFF));
+ }
+ }
+
+ /* -- StandardMidiListener -- */
+
+ if(listener instanceof StandardMidiListener) ((StandardMidiListener)listener).midiMessage(message, timeStamp);
+
+ /* -- ObjectMidiListener -- */
+
+ if(listener instanceof ObjectMidiListener) {
+ if((int)((byte)data[0] & 0xF0) == ShortMessage.NOTE_ON) {
+ ((ObjectMidiListener)listener).noteOn(new Note((int)(data[0] & 0x0F),(int)(data[1] & 0xFF),(int)(data[2] & 0xFF)));
+ } else if((int)((byte)data[0] & 0xF0) == ShortMessage.NOTE_OFF) {
+ ((ObjectMidiListener)listener).noteOff(new Note((int)(data[0] & 0x0F),(int)(data[1] & 0xFF),(int)(data[2] & 0xFF)));
+ } else if((int)((byte)data[0] & 0xF0) == ShortMessage.CONTROL_CHANGE) {
+ ((ObjectMidiListener)listener).controllerChange(new ControlChange((int)(data[0] & 0x0F),(int)(data[1] & 0xFF),(int)(data[2] & 0xFF)));
+ }
+ }
+
+ }
+ }
+
+ /**
+ * Notifies any of the supported methods implemented inside the parent of a new MIDI message from one of the MIDI input devices.
+ *
+ * @param message the new inbound MidiMessage.
+ */
+ void notifyParent(MidiMessage message, long timeStamp) {
+ if(parent == null) return;
+
+ byte[] data = message.getMessage();
+
+ if((int)((byte)data[0] & 0xF0) == ShortMessage.NOTE_ON) {
+ if(method_note_on != null) {
+ try {
+ method_note_on.invoke(parent, new Object[] { (int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF) });
+ } catch(Exception e) {
+ System.err.println("\nThe MidiBus Warning: Disabling noteOn(int channel, int pitch, int velocity) because an unkown exception was thrown and caught");
+ e.printStackTrace();
+ method_note_on = null;
+ }
+
+ }
+ if(method_note_on_with_bus_name != null) {
+ try {
+ method_note_on_with_bus_name.invoke(parent, new Object[] { (int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF), timeStamp, bus_name });
+ } catch(Exception e) {
+ System.err.println("\nThe MidiBus Warning: Disabling noteOn(int channel, int pitch, int velocity, String bus_name) with bus_name because an unkown exception was thrown and caught");
+ e.printStackTrace();
+ method_note_on_with_bus_name = null;
+ }
+ }
+ if(method_note_on_wcla != null){
+ try {
+ method_note_on_wcla.invoke(parent, new Note((int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF), timeStamp, bus_name));
+ } catch(Exception e) {
+ System.err.println("\nThe MidiBus Warning: Disabling noteOn(Note note) because an unkown exception was thrown and caught");
+ e.printStackTrace();
+ method_note_on_wcla = null;
+ }
+ }
+ } else if((int)((byte)data[0] & 0xF0) == ShortMessage.NOTE_OFF) {
+ if(method_note_off != null) {
+ try {
+ method_note_off.invoke(parent, new Object[] { (int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF) });
+ } catch(Exception e) {
+ System.err.println("\nThe MidiBus Warning: Disabling noteOff(int channel, int pitch, int velocity) because an unkown exception was thrown and caught");
+ e.printStackTrace();
+ method_note_off = null;
+ }
+ }
+ if(method_note_off_with_bus_name != null) {
+ try {
+ method_note_off_with_bus_name.invoke(parent, new Object[] { (int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF), timeStamp, bus_name });
+ } catch(Exception e) {
+ System.err.println("\nThe MidiBus Warning: Disabling noteOff(int channel, int pitch, int velocity, String bus_name) with bus_name because an unkown exception was thrown and caught");
+ e.printStackTrace();
+ method_note_off_with_bus_name = null;
+ }
+ }
+ if(method_note_off_wcla != null){
+ try {
+ method_note_off_wcla.invoke(parent, new Note((int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF), timeStamp, bus_name));
+ } catch(Exception e) {
+ System.err.println("\nThe MidiBus Warning: Disabling noteOff(Note note) because an unkown exception was thrown and caught");
+ e.printStackTrace();
+ method_note_off_wcla = null;
+ }
+ }
+ } else if((int)((byte)data[0] & 0xF0) == ShortMessage.CONTROL_CHANGE) {
+ if(method_controller_change != null) {
+ try {
+ method_controller_change.invoke(parent, new Object[] { (int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF) });
+ } catch(Exception e) {
+ System.err.println("\nThe MidiBus Warning: Disabling controllerChange(int channel, int number, int value) because an unkown exception was thrown and caught");
+ e.printStackTrace();
+ method_controller_change = null;
+ }
+ }
+ if(method_controller_change_with_bus_name != null) {
+ try {
+ method_controller_change_with_bus_name.invoke(parent, new Object[] { (int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF), timeStamp, bus_name });
+ } catch(Exception e) {
+ System.err.println("\nThe MidiBus Warning: Disabling controllerChange(int channel, int number, int value, String bus_name) with bus_name because an unkown exception was thrown and caught");
+ e.printStackTrace();
+ method_controller_change_with_bus_name = null;
+ }
+ }
+ if(method_controller_change_wcla != null){
+ try {
+ method_controller_change_wcla.invoke(parent, new ControlChange((int)(data[0] & 0x0F), (int)(data[1] & 0xFF), (int)(data[2] & 0xFF), timeStamp, bus_name));
+ } catch(Exception e) {
+ System.err.println("\nThe MidiBus Warning: Disabling noteOff(Note note) because an unkown exception was thrown and caught");
+ e.printStackTrace();
+ method_controller_change_wcla = null;
+ }
+ }
+ }
+
+ if(method_raw_midi != null) {
+ try {
+ method_raw_midi.invoke(parent, new Object[] { data });
+ } catch(Exception e) {
+ System.err.println("\nThe MidiBus Warning: Disabling rawMidi(byte[] data) because an unkown exception was thrown and caught");
+ e.printStackTrace();
+ method_raw_midi = null;
+ }
+ }
+ if(method_raw_midi_with_bus_name != null) {
+ try {
+ method_raw_midi_with_bus_name.invoke(parent, new Object[] { data, timeStamp, bus_name });
+ } catch(Exception e) {
+ System.err.println("\nThe MidiBus Warning: Disabling rawMidi(byte[] data, String bus_name) with bus_name because an unkown exception was thrown and caught");
+ e.printStackTrace();
+ method_raw_midi_with_bus_name = null;
+ }
+ }
+
+ if(method_midi_message != null) {
+ try {
+ method_midi_message.invoke(parent, new Object[] { message });
+ } catch(Exception e) {
+ System.err.println("\nThe MidiBus Warning: Disabling midiMessage(MidiMessage message) because an unkown exception was thrown and caught");
+ e.printStackTrace();
+ method_midi_message = null;
+ }
+ }
+ if(method_midi_message_with_bus_name != null) {
+ try {
+ method_midi_message_with_bus_name.invoke(parent, new Object[] { message, timeStamp, bus_name });
+ } catch(Exception e) {
+ System.err.println("\nThe MidiBus Warning: Disabling midiMessage(MidiMessage message, String bus_name) with bus_name because an unkown exception was thrown and caught");
+ e.printStackTrace();
+ method_midi_message_with_bus_name = null;
+ }
+ }
+
+ }
+
+ /* -- Listener Handling -- */
+
+ /**
+ * Registers an Object as the parent in order to recieve method callbacks as per {@link PApplet}. Calling this will replace the previous parent Object if any was set.
+ *
+ * @param parent the object to register.
+ * @return the previous parent object if any was set.
+ * @see #addMidiListener(MidiListener listener)
+ */
+ public Object registerParent(Object parent) {
+ Object old_parent = this.parent;
+
+ if(old_parent != null) {
+ method_note_on = null;
+ method_note_off = null;
+ method_controller_change = null;
+ method_raw_midi = null;
+ method_midi_message = null;
+
+ method_note_on_with_bus_name = null;
+ method_note_off_with_bus_name = null;
+ method_controller_change_with_bus_name = null;
+ method_raw_midi_with_bus_name = null;
+ method_midi_message_with_bus_name = null;
+ }
+
+ this.parent = parent;
+
+ if(parent != null) {
+
+ if(parent instanceof processing.core.PApplet) {
+ ((processing.core.PApplet) parent).registerMethod("dispose", this);
+ }
+
+ try {
+ method_note_on = parent.getClass().getMethod("noteOn", new Class[] { Integer.TYPE, Integer.TYPE, Integer.TYPE });
+ } catch(Exception e) {
+ // no such method, or an error.. which is fine, just ignore
+ }
+
+ try {
+ method_note_off = parent.getClass().getMethod("noteOff", new Class[] { Integer.TYPE, Integer.TYPE, Integer.TYPE });
+ } catch(Exception e) {
+ // no such method, or an error.. which is fine, just ignore
+ }
+
+ try {
+ method_controller_change = parent.getClass().getMethod("controllerChange", new Class[] { Integer.TYPE, Integer.TYPE, Integer.TYPE });
+ } catch(Exception e) {
+ // no such method, or an error.. which is fine, just ignore
+ }
+
+ try {
+ method_raw_midi = parent.getClass().getMethod("rawMidi", new Class[] { byte[].class });
+ } catch(Exception e) {
+ // no such method, or an error.. which is fine, just ignore
+ }
+
+ try {
+ method_midi_message = parent.getClass().getMethod("midiMessage", new Class[] { MidiMessage.class });
+ } catch(Exception e) {
+ // no such method, or an error.. which is fine, just ignore
+ }
+
+ try {
+ method_note_on_with_bus_name = parent.getClass().getMethod("noteOn", new Class[] { Integer.TYPE, Integer.TYPE, Integer.TYPE, Long.TYPE, String.class });
+ } catch(Exception e) {
+ // no such method, or an error.. which is fine, just ignore
+ }
+
+ try {
+ method_note_off_with_bus_name = parent.getClass().getMethod("noteOff", new Class[] { Integer.TYPE, Integer.TYPE, Integer.TYPE, Long.TYPE, String.class });
+ } catch(Exception e) {
+ // no such method, or an error.. which is fine, just ignore
+ }
+
+ try {
+ method_controller_change_with_bus_name = parent.getClass().getMethod("controllerChange", new Class[] { Integer.TYPE, Integer.TYPE, Integer.TYPE, Long.TYPE, String.class });
+ } catch(Exception e) {
+ // no such method, or an error.. which is fine, just ignore
+ }
+
+ try {
+ method_raw_midi_with_bus_name = parent.getClass().getMethod("rawMidi", new Class[] { byte[].class, Long.TYPE, String.class });
+ } catch(Exception e) {
+ // no such method, or an error.. which is fine, just ignore
+ }
+
+ try {
+ method_midi_message_with_bus_name = parent.getClass().getMethod("midiMessage", new Class[] { MidiMessage.class, Long.TYPE, String.class });
+ } catch(Exception e) {
+ // no such method, or an error.. which is fine, just ignore
+ }
+
+ try {
+ method_note_on_wcla = parent.getClass().getMethod("noteOn", new Class[] { Note.class});
+ } catch(Exception e) {
+ // no such method, or an error.. which is fine, just ignore
+ }
+
+ try {
+ method_note_off_wcla = parent.getClass().getMethod("noteOff", new Class[] { Note.class });
+ } catch(Exception e) {
+ // no such method, or an error.. which is fine, just ignore
+ }
+
+ try {
+ method_controller_change_wcla = parent.getClass().getMethod("controllerChange", new Class[] { ControlChange.class });
+ } catch(Exception e) {
+ // no such method, or an error.. which is fine, just ignore
+ }
+
+ }
+
+ return old_parent;
+ }
+
+ /**
+ * Adds a listener who will be notified each time a new MIDI message is received from a MIDI input device. If the listener has already been added, it will not be added again.
+ *
+ * @param listener the listener to add.
+ * @return true if and only the listener was sucessfully added.
+ * @see #removeMidiListener(MidiListener listener)
+ * @see #registerParent(Object parent)
+ */
+ public boolean addMidiListener(MidiListener listener) {
+ for(MidiListener current : listeners) if(current == listener) return false;
+
+ listeners.add(listener);
+
+ return true;
+ }
+
+ /**
+ * Removes a given listener.
+ *
+ * @param listener the listener to remove.
+ * @return true if and only the listener was sucessfully removed.
+ * @see #addMidiListener(MidiListener listener)
+ */
+ public boolean removeMidiListener(MidiListener listener) {
+ for(MidiListener current : listeners) {
+ if(current == listener) {
+ listeners.remove(listener);
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ /* -- Utilites -- */
+
+ /**
+ * It's just convient ... move along...
+ */
+ int constrain(int value, int min, int max) {
+ if(value > max) value = max;
+ if(value < min) value = min;
+ return value;
+ }
+
+ /**
+ * Returns whether this MidiBus is sending timestamps along with MIDI information to the MIDI subsystem.
+ *
+ * @return true if this MidiBus is sending timestamps.
+ */
+ public boolean sendTimestamps() {
+ return sendTimestamps;
+ }
+
+ /**
+ * Configure this MidiBus instance to send or not to send timestamps along with MIDI information to the MIDI subsystem.
+ *
+ * @param sendTimestamps set to true if you want timestamps to be sent, otherwise set to false.
+ */
+ public void sendTimestamps(boolean sendTimestamps) {
+ this.sendTimestamps = sendTimestamps;
+ }
+
+ /**
+ * Returns the name of this MidiBus.
+ *
+ * @return the name of this MidiBus.
+ * @see #setBusName(String bus_name)
+ * @see #generateBusName()
+ */
+ public String getBusName() {
+ return bus_name;
+ }
+
+ /**
+ * Changes the name of this MidiBus.
+ *
+ * @param bus_name the new name of this MidiBus.
+ * @see #getBusName()
+ * @see #generateBusName()
+ */
+ public void setBusName(String bus_name) {
+ this.bus_name = bus_name;
+ }
+
+ /**
+ * Generate a name for this MidiBus instance.
+ *
+ * @see #setBusName(String bus_name)
+ * @see #getBusName()
+ */
+ public void generateBusName() {
+ String id = new Formatter().format("%08d", System.currentTimeMillis()%100000000).toString();
+ bus_name = "MidiBus_"+id;
+ }
+
+ /* -- Object -- */
+
+ /**
+ * Returns a string representation of the object.
+ *
+ * @return a string representation of the object.
+ */
+ public String toString() {
+ String output = "MidiBus: "+bus_name+" [";
+ output += input_devices.size()+" input(s), ";
+ output += output_devices.size()+" output(s), ";
+ output += listeners.size()+" listener(s)]";
+ return output;
+ }
+
+ /**
+ * Indicates whether some other object is "equal to" this one.
+ *
+ * @param obj the reference object with which to compare.
+ * @return if this object is the same as the obj argument; false otherwise.
+ */
+ public boolean equals(Object obj) {
+ if(obj instanceof MidiBus) {
+ MidiBus midibus = (MidiBus)obj;
+ if(!this.getBusName().equals(midibus.getBusName())) return false;
+ if(!this.input_devices.equals(midibus.input_devices)) return false;
+ if(!this.output_devices.equals(midibus.output_devices)) return false;
+ if(!this.listeners.equals(midibus.listeners)) return false;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Creates and returns a copy of this object.
+ *
+ * @return a clone of this instance.
+ */
+ public MidiBus clone() {
+ MidiBus clone = new MidiBus(parent, bus_name);
+
+ for(InputDeviceContainer container : input_devices) {
+ clone.addInput(container.info);
+ }
+
+ for(OutputDeviceContainer container : output_devices) {
+ clone.addOutput(container.info);
+ }
+
+ for(MidiListener listener : listeners) {
+ clone.addMidiListener(listener);
+ }
+
+ return clone;
+ }
+
+ /**
+ * Returns a hash code value for the object.
+ *
+ * @return a hash code value for this object.
+ */
+ public int hashCode() {
+ return bus_name.hashCode()+input_devices.hashCode()+output_devices.hashCode()+listeners.hashCode();
+ }
+
+ /**
+ * Override the finalize() method from java.lang.Object.
+ *
+ */
+ protected void finalize() {
+ close();
+ }
+
+ /* -- Shutting Down -- */
+
+ /**
+ * Closes this MidiBus and all connections it has with other MIDI devices. This method exists as per standard javax.sound.midi syntax. It is functionaly equivalent to stop() and dispose().
+ *
+ * @see #stop()
+ * @see #dispose()
+ */
+ public void close() {
+ closeAllMidiDevices();
+ }
+
+ /**
+ * Closes this MidiBus and all connections it has with other MIDI devices. This method exit as per standard Processing syntax for users who are doing their sketch cleanup themselves using the stop() function. It is functionaly equivalent to close() and dispose().
+ *
+ * @see #close()
+ * @see #dispose()
+ */
+ public void stop() {
+ close();
+ }
+
+ /**
+ * Closes this MidiBus and all connections it has with other MIDI devices. This method exit as per standard Processing library syntax and is called automatically whenever the parent applet shuts down. It is functionaly equivalent to close() and stop().
+ *
+ * @see #close()
+ * @see #stop()
+ */
+ public void dispose() {
+ close();
+ }
+
+ /* -- Static methods -- */
+
+ /**
+ * List all installed MIDI devices. The index, name and type (input/output/unavailable) of each devices will be indicated.
+ *
+ * @see #availableInputs()
+ * @see #availableOutputs()
+ * @see #unavailableDevices()
+ */
+ static public void list() {
+ String[] available_inputs = availableInputs();
+ String[] available_outputs = availableOutputs();
+ String[] unavailable = unavailableDevices();
+
+ if(available_inputs.length == 0 && available_outputs.length == 0 && unavailable.length == 0) return;
+
+ System.out.println("\nAvailable MIDI Devices:");
+ if(available_inputs.length != 0) {
+ System.out.println("----------Input----------");
+ for(int i = 0;i < available_inputs.length;i++) System.out.println("["+i+"] \""+available_inputs[i]+"\"");
+ }
+ if(available_outputs.length != 0) {
+ System.out.println("----------Output----------");
+ for(int i = 0;i < available_outputs.length;i++) System.out.println("["+i+"] \""+available_outputs[i]+"\"");
+ }
+ if(unavailable.length != 0) {
+ System.out.println("----------Unavailable----------");
+ for(int i = 0;i < unavailable.length;i++) System.out.println("["+i+"] \""+unavailable[i]+"\"");
+ }
+ }
+
+ /**
+ * Rescan for Midi Devices. This is autocalled once when the MidiBus starts up. It should be called again if you need to refresh the list of available MidiDevices while your program is running.
+ *
+ */
+ static public void findMidiDevices() {
+ MidiBus.available_devices = MidiSystem.getMidiDeviceInfo();
+ }
+
+ /**
+ * Returns the names of all the available input devices.
+ *
+ * @return the names of the available inputs.
+ * @see #list()
+ * @see #availableOutputs()
+ * @see #unavailableDevices()
+ */
+ static public String[] availableInputs() {
+ MidiDevice.Info[] devices_info = availableInputsMidiDeviceInfo();
+ String[] devices = new String[devices_info.length];
+
+ for(int i = 0;i < devices_info.length;i++) {
+ devices[i] = devices_info[i].getName();
+ }
+
+ return devices;
+ }
+
+ /**
+ * Returns the names of all the available output devices.
+ *
+ * @return the names of the available outputs.
+ * @see #list()
+ * @see #availableInputs()
+ * @see #unavailableDevices()
+ */
+ static public String[] availableOutputs() {
+ MidiDevice.Info[] devices_info = availableOutputsMidiDeviceInfo();
+ String[] devices = new String[devices_info.length];
+
+ for(int i = 0;i < devices_info.length;i++) {
+ devices[i] = devices_info[i].getName();
+ }
+
+ return devices;
+ }
+
+ /**
+ * Returns the names of all the unavailable devices.
+ *
+ * @return the names of the unavailable devices.
+ * @see #list()
+ * @see #availableInputs()
+ * @see #availableOutputs()
+ */
+ static public String[] unavailableDevices() {
+ MidiDevice.Info[] devices_info = unavailableMidiDeviceInfo();
+ String[] devices = new String[devices_info.length];
+
+ for(int i = 0;i < devices_info.length;i++) {
+ devices[i] = devices_info[i].getName();
+ }
+
+ return devices;
+ }
+
+ /**
+ * Returns the MidiDevice.Info of all the available input devices.
+ *
+ * @return the MidiDevice.Info of the available inputs.
+ */
+ static MidiDevice.Info[] availableInputsMidiDeviceInfo() {
+ if(MidiBus.available_devices == null) findMidiDevices();
+ MidiDevice device;
+
+ Vector
+ * Note: This page is a dummy page for documentation of the MidiBus' extention of the regular PApplet's functionality, for the full documentation of PApplet please visits the Processing javadocs
+ *
+ * @version 008
+ * @author Severin Smith
+ * @see MidiBus
+ * @see MidiListener
+ * @see RawMidiListener
+ * @see StandardMidiListener
+ * @see SimpleMidiListener
+*/
+public class PApplet{
+
+ /**
+ * Is passed the channel, controller number and contoller value associated with every new ContollerChange MIDI message recieved by a MidiBus attached to this applet.
+ *
+ * @param channel the channel on which the ContollerChange arrived
+ * @param number the controller number associated with the ContollerChange
+ * @param value the controller value associated with the ContollerChange
+ * @see #controllerChange(int channel, int pitch, int velocity, long timestamp, String bus_name)
+ */
+ public void controllerChange(int channel, int number, int value) {
+
+ }
+
+ /**
+ * Is passed the channel, pitch and velocity associated with every new NoteOff MIDI message recieved by a MidiBus attached to this applet and the name of the MidiBus which recieved the message.
+ *
+ * @param channel the channel on which the ContollerChange arrived
+ * @param number the controller number associated with the ContollerChange
+ * @param value the controller value associated with the ContollerChange
+ * @param timestamp the timestamp on the midi message
+ * @param bus_name the name of MidiBus which recieved the ContollerChange
+ * @see #controllerChange(int channel, int pitch, int velocity)
+ */
+ public void controllerChange(int channel, int number, int value, long timestamp, String bus_name) {
+
+ }
+
+ /**
+ * Is passed a ControlChange object representing controlChange event
+ *
+ * @param change the ControlChange object
+ * @see #controllerChange(int channel, int pitch, int velocity)
+ * @see themidibus.ObjectMidiListener#controllerChange(ControlChange)
+ */
+ public void controllerChange(ControlChange change) {
+
+ }
+
+ /**
+ * Is passed the raw MidiMessage associated with every new MIDI message recieved by a MidiBus attached to this applet.
+ *
+ * @param message the MidiMessage recieved
+ * @see #midiMessage(MidiMessage message, long timestamp, String bus_name)
+ */
+ public void midiMessage(MidiMessage message) {
+
+ }
+
+ /**
+ * Is passed the raw MidiMessage associated with every new MIDI message recieved by a MidiBus attached to this applet and the name of the MidiBus which recieved the message.
+ *
+ * @param message the MidiMessage recieved
+ * @param timestamp the timestamp on the midi message
+ * @param bus_name the name of MidiBus which recieved the MIDI message
+ * @see #midiMessage(MidiMessage message)
+ */
+ public void midiMessage(MidiMessage message, long timestamp, String bus_name) {
+
+ }
+
+ /**
+ * Is passed the channel, pitch and velocity associated with every new NoteOff MIDI message recieved by a MidiBus attached to this applet.
+ *
+ * @param channel the channel on which the NoteOff arrived
+ * @param pitch the pitch associated with the NoteOff
+ * @param velocity the velocity associated with the NoteOff
+ * @see #noteOff(int channel, int pitch, int velocity, long timestamp, String bus_name)
+ */
+ public void noteOff(int channel, int pitch, int velocity) {
+
+ }
+
+ /**
+ * Is passed the channel, pitch and velocity associated with every new NoteOff MIDI message recieved by a MidiBus attached to this applet and the name of the MidiBus which recieved the message.
+ *
+ * @param channel the channel on which the NoteOff arrived
+ * @param pitch the pitch associated with the NoteOff
+ * @param velocity the velocity associated with the NoteOff
+ * @param timestamp the timestamp on the midi message
+ * @param bus_name the name of MidiBus which recieved the NoteOff
+ * @see #noteOff(int channel, int pitch, int velocity)
+ */
+ public void noteOff(int channel, int pitch, int velocity, long timestamp, String bus_name) {
+
+ }
+
+ /**
+ * Is passed a Note object representing noteOff event
+ *
+ * @param note the Note object
+ * @see #noteOff(int channel, int pitch, int velocity)
+ * @see themidibus.ObjectMidiListener#noteOn(Note)
+ */
+ public void noteOff(Note note) {
+
+ }
+
+ /**
+ * Is passed the channel, pitch and velocity associated with every new NoteOn MIDI message recieved by a MidiBus attached to this applet.
+ *
+ * @param channel the channel on which the NoteOn arrived
+ * @param pitch the pitch associated with the NoteOn
+ * @param velocity the velocity associated with the NoteOn
+ * @see #noteOn(int channel, int pitch, int velocity, long timestamp, String bus_name)
+ */
+ public void noteOn(int channel, int pitch, int velocity) {
+
+ }
+
+ /**
+ * Is passed the channel, pitch and velocity associated with every new NoteOn MIDI message recieved by a MidiBus attached to this applet and the name of the MidiBus which recieved the message.
+ *
+ * @param channel the channel on which the NoteOn arrived
+ * @param pitch the pitch associated with the NoteOn
+ * @param velocity the velocity associated with the NoteOn
+ * @param timestamp the timestamp on the midi message
+ * @param bus_name the name of MidiBus which recieved the NoteOn
+ * @see #noteOn(int channel, int pitch, int velocity)
+ */
+ public void noteOn(int channel, int pitch, int velocity, long timestamp, String bus_name) {
+
+ }
+
+ /**
+ * Is passed a Note object representing noteOn event
+ *
+ * @param note the Note object
+ * @see #noteOn(int channel, int pitch, int velocity)
+ * @see themidibus.ObjectMidiListener#noteOff(Note)
+ */
+ public void noteOn(Note note) {
+
+ }
+
+ /**
+ * Is passed the raw data associated with every new MIDI message recieved by a MidiBus attached to this applet.
+ *
+ * @param data the raw data associated with the MIDI message
+ * @see #rawMidi(byte[] data, long timestamp, String bus_name)
+ */
+ public void rawMidi(byte[] data) {
+
+ }
+
+ /**
+ * Is passed the raw data associated with every new MIDI message recieved by a MidiBus attached to this applet and the name of the MidiBus which recieved the message.
+ *
+ * @param data the raw data associated with the MIDI message
+ * @param timestamp the timestamp on the midi message
+ * @param bus_name the name of MidiBus which recieved the MIDI message
+ * @see #rawMidi(byte[] data)
+ */
+ public void rawMidi(byte[] data, long timestamp, String bus_name) {
+
+ }
+}
diff --git a/libraries/themidibus/src/themidibus/RawMidiListener.java b/libraries/themidibus/src/themidibus/RawMidiListener.java
new file mode 100644
index 0000000..d08588c
--- /dev/null
+++ b/libraries/themidibus/src/themidibus/RawMidiListener.java
@@ -0,0 +1,40 @@
+/**
+ * Copyright (c) 2009 Severin Smith
+ *
+ * This file is part of a library called The MidiBus (themidibus) - http://www.smallbutdigital.com/themidibus.php.
+ *
+ * The MidiBus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * The MidiBus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the MidiBus. If not, see
+ * IMPORTANT: Mac users may want to install mmj, a Mac OS X universal binary java MIDI subsystem - or an equivalent third party MIDI subsystem - because the apple implementation is lacking support for a number of advanced MIDI features. Mmj is recommended because it works, it's free and it's almost open source (CC licence). Please check README.md for more information. If you do use MMJ you will want to set {@link themidibus.MidiBus#sendTimestamps(boolean sendTimestamps)} to false, otherwise messages won't be sent.
+ *
+ * Keeping with the spirit of Processing's easy to use sketching/prototyping style, the MidiBus offers a clean and simple way to get at MIDI ressources. Getting the basic functionality of the MidiBus up and running in a sketch is a matter of only a few line. The {@link themidibus.MidiBus} class provides everything needed send and receive MIDI inside a sketch. To jump right into the Midibus, either refer to the paragraph titled "Typical Implementation, Simple" in the description for the {@link themidibus.MidiBus} class, or check out the code examples distributed with this library.
+ *
+ * It is important to understand that the MidiBus offers little functionality that isn't available from Java's native javax.sound.midi package. Anyone interested in working with MIDI in Java should take the time to read the documentation for the javax.sound.midi. It offers a more full featured and flexible alternative to this package, although it does do so at the cost of added complexity. In addition, it may be worthwhile to skim the "official" Java Tutorial for the javax.sound.* packages.
+ *
+ * Related Documentation
+ *
+ *
+ * @version 008
+ * @author Severin Smith
+*/
+
+package themidibus;