title: How do I iterate over a MIDIPacketList with RubyMotion?
body: <p>How would I translate <a href="https://github.com/petegoodliffe/PGMidi/blob/master/Sources/UI/MidiMonitorViewController.mm#L158-172" rel="nofollow">this PGMidi example code</a> to RubyMotion? <a href="https://developer.apple.com/library/mac/#documentation/MusicAudio/Reference/CACoreMIDIRef/MIDIServices/CompositePage.html#//apple_ref/c/tag/MIDIPacketList" rel="nofollow">The documentation the MIDIPacketList</a> mentions special caveats and I'm not sure how to account for them in RubyMotion. Example:</p>
  
  <blockquote>
    <p>Note that the packets in the list, while defined as an array, may not be accessed as an array, since they are variable-length.</p>
  </blockquote>
  
  <p>Here's the example, and further down, as far as I've gotten in the translation:</p>
  
  <pre><code>- (void) midiSource:(PGMidiSource*)midi midiReceived:(const MIDIPacketList *)packetList
  {
      [self performSelectorOnMainThread:@selector(addString:)
                             withObject:@"MIDI received:"
                          waitUntilDone:NO];
  
      const MIDIPacket *packet = &amp;packetList-&gt;packet[0];
      for (int i = 0; i &lt; packetList-&gt;numPackets; ++i)
      {
          [self performSelectorOnMainThread:@selector(addString:)
                                 withObject:StringFromPacket(packet)
                              waitUntilDone:NO];
          packet = MIDIPacketNext(packet);
      }
  }
  </code></pre>
  
  <p>I know I'm losing the pointer referencing/dereferencing with the 'packet' local var and 'packetList', but I'm having a hard time figuring out how to correct it:</p>
  
  <pre><code>def midiSource(midi, midiReceived:packetList)
    self.performSelectorOnMainThread('addString',
                     withObject:'MIDI received:',
                     waitUntilDone:false)
  
    packet = packetList.packet[0]
    i = 0
    while i &lt; packetList.numPackets
      i += 1
  
      self.performSelectorOnMainThread('addString',
                                       withObject:stringFromPacket(packet),
                                       waitUntilDone:false)
      packet = MIDIPacketNext(packet)
    end
  end
  </code></pre>
  
  <p>Thanks for any guidance!</p>