title: How to read the initial state of a MIDI Foot Controller?
body: <p>I know MIDI allows me to read the state of a MIDI Foot Controller by catching a MIDI Message indicating a Control Change. But what if the user has not touched/changed the control yet? Am I still able to read the state/value? What would be the way to do that?</p>
  
  <p>This is my code for catching Midi Messages using OSX CoreMIDI</p>
  
  <pre><code>void initMidi()
  {
      MIDIClientRef   midiClient;
      MIDIPortRef     inputPort;
      OSStatus        status;
      MIDIEndpointRef src;
  
      status = MIDIClientCreate(CFSTR("testing"), NULL, NULL, &amp;midiClient);
      if (status != noErr)
          NSLog(@"Error creating MIDI client: %d", status);
  
      status = MIDIInputPortCreate(midiClient, CFSTR("Input"), midiInputCallback, NULL, &amp;inputPort);
      if (status != noErr)
          NSLog(@"Error creating MIDI input port: %d", status);
  
      ItemCount numOfDevices = MIDIGetNumberOfDevices();
  
      // just try to connect to every device
      for (ItemCount i = 0; i &lt; numOfDevices; i++) {
          src = MIDIGetSource(i);
          status = MIDIPortConnectSource(inputPort, src, NULL);
      }
  }
  
  void midiInputCallback(const MIDIPacketList *list,
      void *procRef,
      void *srcRef)
  {
      for (UInt32 i = 0; i &lt; list-&gt;numPackets; i++) {
          const MIDIPacket *packet = &amp;list-&gt;packet[i];
  
          for (UInt16 j = 0, size = 0; j &lt; packet-&gt;length; j += size) {
              UInt8 status = packet-&gt;data[j];
  
              if (status &lt;  0xC0)  size = 3;
              else if (status &lt;  0xE0)  size = 2;
              else if (status &lt;  0xF0)  size = 3;
              else if (status &lt;  0xF3)  size = 3;
              else if (status == 0xF3)  size = 2;
              else                      size = 1;
  
              switch (status &amp; 0xF0) {
              case 0xb0:
                  NSLog(@"MIDI Control Changed: %d %d", packet-&gt;data[j + 1], packet-&gt;data[j + 2]);
                  break;
              }
          }
      }
  }
  </code></pre>