MidiOutPort class overview

MidiOutPort handles the MIDI output connections to hardware/software devices for the MidiOutput class. Normally, you should use the MidiOutput class instead of MidiOutPort since MidiOutPort is only for lower-level MIDI access. MidiOutPort is derived from protected classes which define hardware/operating specific behavior for MIDI output. See the inheritance organization of MIDI classes in the control classes overview.

There can be any number of MidiOuputPort instances, each of which directs MIDI output to a common set of MIDI out port locations. The maximum number of hardware ports for the system can be found with the getNumPorts function. Multiple connections of MidiOutPort objects to physical output ports on the computer is demonstrated in Figure 1 below.

MidiOutPort Figure 1

In general, a MIDI out port will be opened automatically when an instance belonging to that port is created, and all MIDI ports will be closed just before the last instance of a MidiPort class goes out of scope. The functions open and close can alternatively be used to manually control connection to a MIDI port. See the constructor for disabling automatic opening of a MIDI port.

MidiOutPort Example 1  

   MidiOutPort outport(0);              // open MIDI port on output 0 
  
   // send a MIDI note on, Middle-C (60), very loud (127).
   outport.rawsend(0x90, 60, 127);

   // set the MIDI tracing on and send trace output to a file:
   // default location to send trace stream is to console output.
   fstream outfile("midi-trace.txt", ios::out );
   outport.setTraceStream(outfile);
   outport.setTrace(1);
   outport.rawsend(0x90, 60, 127);











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