我如何将这个 PGMidi 示例代码翻译成 RubyMotion?MIDIPacketList 的文档提到了特殊的警告,我不确定如何在 RubyMotion 中解释它们。例子:
请注意,列表中的数据包虽然定义为数组,但可能无法作为数组访问,因为它们是可变长度的。
就我在翻译中得到的而言,这是示例,并且更进一步:
- (void) midiSource:(PGMidiSource*)midi midiReceived:(const MIDIPacketList *)packetList
{
[self performSelectorOnMainThread:@selector(addString:)
withObject:@"MIDI received:"
waitUntilDone:NO];
const MIDIPacket *packet = &packetList->packet[0];
for (int i = 0; i < packetList->numPackets; ++i)
{
[self performSelectorOnMainThread:@selector(addString:)
withObject:StringFromPacket(packet)
waitUntilDone:NO];
packet = MIDIPacketNext(packet);
}
}
我知道我正在丢失使用“packet”本地变量和“packetList”引用/取消引用的指针,但我很难弄清楚如何纠正它:
def midiSource(midi, midiReceived:packetList)
self.performSelectorOnMainThread('addString',
withObject:'MIDI received:',
waitUntilDone:false)
packet = packetList.packet[0]
i = 0
while i < packetList.numPackets
i += 1
self.performSelectorOnMainThread('addString',
withObject:stringFromPacket(packet),
waitUntilDone:false)
packet = MIDIPacketNext(packet)
end
end
感谢您的任何指导!