【发布时间】:2016-02-25 16:30:10
【问题描述】:
我正在尝试在我的 iOS 应用程序中实现 CoreMIDI,但现在尝试调试它时遇到了麻烦。目前,我有一个 UILabel,只要调用我的 MIDI 回调,它就会更新。但是,我的 UILabel 永远不会更新!我不确定为什么会发生这种情况,我猜这要么是我在 MIDI 初始化中定义某些东西的方式,要么是我如何调用 UILabel。我仍在尝试解决这个问题,但有没有更好的方法在 iOS 应用程序上调试 MIDI(因为 iOS 设备只有一个端口,并且只能在给定时间使用该端口连接到计算机或 MIDI 控制器) .
我如何创建 MIDI 客户端:
Check(MIDIClientCreate(CFSTR("Yun Client"), NULL, NULL , &client));
Check(MIDIOutputPortCreate(client, CFSTR("Yun Output Port"), &outputPort));
Check(MIDIInputPortCreate(client, CFSTR("Yun Input Port"), MIDIInputCallback,
(__bridge void *)self, &inputPort));
unsigned long sourceCount = MIDIGetNumberOfSources();
CFStringRef endpointName;
for (int i = 0; i < sourceCount; ++i) {
MIDIEndpointRef endPoint = MIDIGetSource(i);
endpointName = NULL;
Check(MIDIObjectGetStringProperty(endPoint, kMIDIPropertyName, &endpointName));
Check(MIDIPortConnectSource(inputPort, endPoint, NULL));
[param addToMIDIInputsArray:[NSString stringWithFormat:@"%@", endpointName]];
}
我的 MIDI 回调:
// MIDI receiver callback
static void MIDIInputCallback(const MIDIPacketList *pktlist,
void *refCon, void *connRefCon) {
SynthViewController *vc = (__bridge SynthViewController*)refCon;
MIDIPacket *packet = (MIDIPacket *)pktlist->packet;
Byte midiCommand = packet->data[0] >> 4;
NSInteger command = midiCommand;
Byte noteByte = packet->data[1] & 0x7F;
NSInteger note = noteByte;
Byte velocityByte = packet->data[2] & 0x7F;
float velocity = [[NSNumber numberWithInt:velocityByte] floatValue];
// Note On event
if (command == 9 && velocity > 0) {
[vc midiKeyDown:(note+4) withVelocity:velocity];
}
// Note off event
else if ((command == 9 || command == 8) && velocity == 0) {
[vc midiKeyUp:(note+4)];
}
[vc.logLabel addLogLine:[NSString stringWithFormat:@"%lu - %lu - %lu",
(long)command, (long)note, (long)velocityByte]];
}
addLogLine方法:
- (void)addLogLine:(NSString *)line {
NSString *str = [NSString stringWithFormat:@"%d - %@", _cnt++, line];
_logLabel.text = str;
}
任何帮助都很棒!谢谢
【问题讨论】:
标签: ios objective-c midi coremidi