我很難解析Midi包。有時它的3個字節在一個數據流上可以是155個字節。 如何迭代大量數據包並獲得我所需要的? 對於「b0」來說,它只有12字節的3個字節,我只想分割「b0」及其後面的字節: [b02c2c],然後其他[b02c2d]或[f0 ....]包...在iOS中解析Midi包
繼承人什麼,我一直在努力,並讓我頭疼..
NSString *StringFromPacket(const MIDIPacket *packet,id self)
{
NSMutableString * result = [[NSMutableString alloc] init];
for (int i = 0; i < packet->length; i++)
{
NSString *s = [NSString stringWithFormat:@"%02x",packet->data[i]];
for (NSString *line in [s componentsSeparatedByString:@"b0"])
{
// This appends to string but b0 disappears and only get the following 2 bytes
// Along with the others like f0,a0,90. I would like to filter without losing b0
[result appendFormat:line];
}
}
[self controlEvent:result];
}
-(void)controlEvent:(NSString *)line
{
if (line == @"b02c2c")
{
//Do Something
}
}
我對你的問題和代碼感到困惑 - 你能展示一些MIDI數據包以及你想對它們做什麼操作嗎? – sarnold 2012-01-02 01:24:43
請勿使用字符串匹配來分析二進制數據。在使用之前,請確保您完全理解MIDI數據格式。 – Till 2012-01-02 01:25:52
我基本上會收到這樣一個數據包: 18字節:[b0,0c,0e,b0,2c,05,b0,0c,0f,b0,2c,02,b0,0c,0d,b0,2c,02 ] 如何將它們分成3個字節然後發送到一個方法? – Cocell 2012-01-02 02:40:03