MidiInPort class overview

MidiInPort is a class which stores incoming MIDI messages for interpretation later by a derived class or the user with the extract function. This class is analogous to the MidiOutPort class and serves as a low-level interface to the MIDI input stream. The class is derived privately from the hardware/OS-specific implementation.

There are several function which manage the input MIDI message buffer:

  1. getCount -- this function will return the number of MIDIMessages waiting in the input buffer. You cannot extract a MIDI message from the buffer if getCount return 0 messages in the buffer; this will result in a fatal error.
  2. extract -- use this function to extract one MIDI message from the input buffer.
  3. setBufferSize -- use this function to set the size of the input buffer. The default size is 1024 messages.
  4. operator[] -- use this function to return a message relative to the last inserted message. [0] is the currently inserted message, [-1] is the message inserted just before the [0] message, etc. .
  5. insert -- use this function to spoof the MIDI input buffer into thinking that a MIDI message came from the hardware input when it actually came from the computer program using the MidiInPort object.

MidiInPort objects link to an array of hardware MIDI input ports. These ports can be open/closed. Also if open, these ports can be paused or unpaused with the pause/unpause functions. If the port is closed, then no MIDI messages will be read from the port by the lower level MIDI driver of the operating system. If the port is open and unpaused, then the MIDI input driver of the operating system will insert messages into the objects MIDI message buffer. If the object's port is open but paused, then there will be no messages inserted into the MIDI buffer as they come into the computer.

The port to which a MidiInPort object can be attached to can change after being assigned to a port. Use the setPort function to change ports. The getNumPorts function will return how many valid ports are available in the input port array; you must set to a valid port number. Once the object has selected a port, then the port may be opened with the open function. Opening a port which is already opened is not an error since the MidiInPorts keep track of when a port is open/closed, and will not reopen an opened port, nor reclose a closed port.












Send comments/errors on this page to craig@ccrma.stanford.edu