title: MidiReadProc - using srcConnRefCon to listen to only one source
body: <p>I am trying to write a basic app that uses CoreMidi to receive midi events from a specific source.  I understand that all midi events that come into a port call the proc that I connected via MidiInputPortCreate().  I also understand that when using MidiPortConnectSource() that you can send an identifier (connRefCon) to help know what the source is.  But I'm not sure how to use it.</p>
  
  <p>I figure that within my MidiReadProc that I can use the scrConnRefCon and an if statement to listen to a specific source, but I still dont know what *void I should pass to separate each source.  Ideally my ReadProc will look something like this:</p>
  
  <pre><code>void SourceReadProc (const MIDIPacketList   *pktlist,
                       void                   *readProcRefCon,
                       void                   *srcConnRefCon)
  {
       if (srcConnRefCon == mySourceChoice) {
            // pass the pktlist to do something
       }
  };
  </code></pre>
  
  <p>Any help will be greatly appreciated.
  GW</p>
  
  <hr>
  
  <p>After a break I've come back to this project with a fresh perspective.  When I call MIDIPortConnectSource and pass a unique connRefCon it's not apparently passing for each endpoint.  Here's my code:</p>
  
  <pre><code>ItemCount count = MIDIGetNumberOfSources();
  for (Itemcount i=0; i&lt;count; i++) {
      MIDIEndpointRef endpoint = MIDIGetSource(i);
      MIDIObjectGetStringProperty(endpoint,kMIDIPropertyName, &amp;midiEndpointSourceName);
      NSLog(@"Source %lu: %@", i, midiEndpointSourceName);
  
      MIDIPortConnectSource(midiSourcePort, endpoint, (void*)&amp;i);
  }
  </code></pre>
  
  <p>Then my read proc:</p>
  
  <pre><code>void SourceReadProc (const MIDIPacketList   *pktlist,
                       void                   *readProcRefCon,
                       void                   *srcConnRefCon)
  {
  ItemCount *source = (ItemCount*) srcConnRefCon;
  NSLog(@"source: %lu", *source);
  }
  </code></pre>
  
  <p>I've hooked up two different midi sources and I can find them both just fine.  My first code reports that there are two sources and tells me their names.  But my read proc says that the sources is always the first source.  I've tried three different data types when passing the connRefCon with no luck.  I feel that my issue must be with the MIDIPortConnectSource.  </p>
  
  <p>Any help or even troubleshooting ideas would be great.  I wish that CoreMIDI had functions to query what's connected to ports so I could check that, but alas, there's not.</p>