MidiTest: Setting up MIDI input/output

This example shows how to set up jMusic to receive and send MIDI data.

Lets have a closer look at the code.

import jm.JMC; 
import jm.midi.MidiCommunication;

public class MidiTest extends MidiCommunication implements JMC {

public static void main(String[] args) {
MidiTest mt = new MidiTest();
}

public void handleMidiInput(int status, int channel, int data1, int data2) {
System.out.println(status + " " + channel + " " + data1 + " " + data2);
}
}

The MidiCommunication class contains the MIDI goodness so we extend it.

The class requires that you override the handleMidiInput() method that is called when MIDI data arrives.

When a new instance of the (MidiCommunication) class is instantiated you will be presented with two consecutive popup windows. These will list the available MIDI ports. In the first, choose your preferred MIDI input port. In the second, your preferred MIDI output port.

Add a  sendMidiOutput(int status, int channel, int data1, int data2) method to pass data tot eh selected external MIDI port.

See the javaDoc for more information:

http://explodingart.com/jmusic/jmDocumentation/index.html




jMusic Tutorial Index