jm.midi

## Class MidiCommunication

- java.lang.Object
- - jm.midi.MidiCommunication

- All Implemented Interfaces:
    java.lang.AutoCloseable, javax.sound.midi.Receiver

      public abstract class MidiCommunication
      extends java.lang.Object
      implements javax.sound.midi.Receiver

  This class provides an easy interface to the MIDI input and output facilities in JavaSound. Classes that extend this abstract class will need to implement the handleMidiInput() method to respond to MIDI data from external sources. MIDI data can be sent using the senMidiOutput() method. The default constructor will prompt the user (via a GUI interface) to choose the MIDI ports to use. To prevent this from hapenning pass the boolean false as an argument to the constructor using the super call from th extending class. A third constructor can be used if you know the ports you want to use, it accepts the input and output port IDs as arguments.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MidiCommunication()` A constructor that automatically prompts for the MIDI i/o ports.
    `MidiCommunication(boolean prompt)` A constructor that supresses the automatic prompting of ports, allowing the programmer to call midiSetup when it suits them.
    `MidiCommunication(int inputDeviceID, int outputDeviceID)` A constructor that automatic assigns MIDI input and output to the ports you define.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `abstract void` | `handleMidiInput(int status, int channel, int data1, int data2)` Handle external MIDI events sent to this computer.
    `void` | `midiSetup()` Choose the MIDI ports to use.
    `void` | `send(javax.sound.midi.MidiMessage message, long timeStamp)` The method required by the recieve interface - It has a stupid name so we pass data for short messages to handleMidiInput (a better name).
    `void` | `sendMidiOutput(int status, int channel, int data1, int data2)` Construct a MIDI message and pass to the designated MIDi output.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### MidiCommunication

          public MidiCommunication()

      A constructor that automatically prompts for the MIDI i/o ports.

    - #### MidiCommunication

          public MidiCommunication(boolean prompt)

      A constructor that supresses the automatic prompting of ports, allowing the programmer to call midiSetup when it suits them. Warning: Attempting to send a MIDI message before setting up ports will cause a NullPointerException.

    - #### MidiCommunication

          public MidiCommunication(int inputDeviceID,
                           int outputDeviceID)

      A constructor that automatic assigns MIDI input and output to the ports you define. Use this as a convenient way of setting up MIDI IO if your application is running on a hardware setup that never (or rarely) changes. Warning: Attempting to assigning unavailible devicePortID's will cause a NullPointerException.
      Parameters:
        `inputDeviceID` - The MIDI port number to use for input to Java.
        `outputDeviceID` - The MIDI port number to use for output from Java.

  - ### Method Detail

    - #### midiSetup

          public void midiSetup()

      Choose the MIDI ports to use. This method will prompt you with a list of the availible MIDI inputs and outputs, double click on the desired ports.

    - #### handleMidiInput

          public abstract void handleMidiInput(int status,
                             int channel,
                             int data1,
                             int data2)

      Handle external MIDI events sent to this computer. This method should be overridden in the class that implements this interface, and the messages handled as appropriate.
      Parameters:
        `status` - The MIDI status type. 11 = Controller, ? = Note on, etc.
        `channel` - The MIDi channel this message is sent on.
        `data1` - The first byte of data in the message. Often controller number of Note pitch.
        `data2` - The second byte of data. Usually the controller value or Note velocity.

    - #### sendMidiOutput

          public void sendMidiOutput(int status,
                            int channel,
                            int data1,
                            int data2)

      Construct a MIDI message and pass to the designated MIDi output.
      Parameters:
        `status` - The MIDI status type. 11 = Controller, 144 = Note on, 128 = Note Off, 192 = Program Change, etc.
        `channel` - The MIDi channel this message is sent on.
        `data1` - The first byte of data in the message. Often controller number of Note pitch.
        `data2` - The second byte of data. Usually the controller value or Note velocity.

    - #### send

          public void send(javax.sound.midi.MidiMessage message,
                  long timeStamp)

      The method required by the recieve interface - It has a stupid name so we pass data for short messages to handleMidiInput (a better name).
      Specified by:
        `send` in interface `javax.sound.midi.Receiver`

    - #### close

          public void close()

      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Specified by:
        `close` in interface `javax.sound.midi.Receiver`