title: Why doesn't this simple CoreMIDI program produce MIDI output?
body: <p>Here is an extremely simple CoreMIDI OS X application that sends MIDI data. The problem is that it doesn't work. It compiles fine, and runs. It reports no errors, and does not crash. The Source created becomes visible in MIDI Monitor. However, <strong>no MIDI data comes out</strong>.</p>
  
  <p>Could somebody let me know what I'm doing wrong here?</p>
  
  <pre><code>#include &lt;CoreMIDI/CoreMIDI.h&gt;
  
  int main(int argc, char *args[])
  {
      MIDIClientRef   theMidiClient;
      MIDIEndpointRef midiOut;
      MIDIPortRef     outPort;
      char pktBuffer[1024];
      MIDIPacketList* pktList = (MIDIPacketList*) pktBuffer;
      MIDIPacket     *pkt;
      Byte            midiDataToSend[] = {0x91, 0x3c, 0x40};
      int             i;
  
      MIDIClientCreate(CFSTR("Magical MIDI"), NULL, NULL,
                       &amp;theMidiClient);
      MIDISourceCreate(theMidiClient, CFSTR("Magical MIDI Source"),
                       &amp;midiOut);
      MIDIOutputPortCreate(theMidiClient, CFSTR("Magical MIDI Out Port"),
                           &amp;outPort);
  
      pkt = MIDIPacketListInit(pktList);
      pkt = MIDIPacketListAdd(pktList, 1024, pkt, 0, 3, midiDataToSend);
  
      for (i = 0; i &lt; 100; i++) {
          if (pkt == NULL || MIDISend(outPort, midiOut, pktList)) {
              printf("failed to send the midi.\n");
          } else {
              printf("sent!\n");
          }
          sleep(1);
      }
  
  return 0;
  }
  </code></pre>