我正在使用蓝牙连接到合成器,在我的iPad上编程一个MIDI工具。通过BT MIDI连接iPad作为外围设备(CABTMidiLocalPeripheralViewController)
我做的第一件事就是将iPad作为中央控制器与CABTMidiCentralViewController一起使用 - 如果我在此处连接到蓝牙设备,我会立即得到一个新MIDI设备已连接并且一切正常的通知。
现在为了支持另一个蓝牙适配器,我需要将iPad配置为外设,为此我使用CABTMidiLocalPeripheralViewController。在BT的另一端(不是iPad的中央设备),我看到iPad广告它的服务,我可以连接到它,但是我不知道如何识别iPad侧的这种连接 - 我没有任何关于新设备的通知。可能我在这里失去了一些东西?
我用CABTMidiLocalPeripheralViewController就像在CABTMidiCentralViewController文档例子,所以这是该代码(这只是显示了VC反正,不是吗?):
- (void)configCABTMIDIPeripheral:(id)sender
{
CABTMIDILocalPeripheralViewController *viewController =[CABTMIDILocalPeripheralViewController new];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
viewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone target: self action: @selector(didConfigCABTMIDIPeripheral:)];
navController.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popC = navController.popoverPresentationController;
popC.permittedArrowDirections = UIPopoverArrowDirectionAny;
popC.sourceRect = [sender frame];
UIButton *button = (UIButton *)sender;
popC.sourceView = button.superview;
[self.delegateBaseViewController presentViewController:navController animated:YES completion:nil];
}
至于通知我注册一个静态回调函数,当我创建一个MIDI客户 - 我的猜测是,作为外围设备工作原理的不同,也许这里有人能指出我在正确的方向:
OSStatus s = 0;
s = MIDIClientCreate((CFStringRef)@"MIDI Client", PGMIDINotifyProc, arc_cast<void>(self), &_client); // Create MIDI Client
s = MIDIOutputPortCreate(_client, (CFStringRef)@"Output Port", &_outputPort); // Create MIDI output port
s = MIDIInputPortCreate(_client, (CFStringRef)@"Input Port", PGMIDIReadProc, arc_cast<void>(self), &_inputPort); // Create MIDI input port
...与PGMIDINotifyProc看起来像...
void PGMIDINotifyProc(const MIDINotification *message, void *refCon)
{
NSLog(@"PGMIDINotifyProc");
PGMidi *self = arc_cast<PGMidi>(refCon);
[self midiNotify:message];
}
(贷PGMidi在https://github.com/petegoodliffe/PGMidi)
所以...我怎么能看到,如果我的周围的iPad没有连接到MIDI设备?
UPDATE
经过长时间的休息,我决定给它一个尝试,这一次我通过对两个设备实现CBPeripheralManager和CBCentralManager(一个外围和一个中心)做了一些测试,以有关于这是怎么回事幕后一探究竟:
没有去过多细说,这里有一些意见:
如果p外设不通电CBPeripheralManager,不提供蓝牙服务。说得通。
如果外围设备提供一些随机服务,中央设备将发现它们连接的服务并且可以交换数据。大。
如果外围设备仍提供一些随机服务,而中央专门查找MIDI服务/特性,则它将找到MIDI服务并连接到它。我在外设方面没有收到任何关于此的通知,因为我只是提供一些随机服务的外设代表。
如果外围设备和中央提供/扫描MIDI服务/特性,它们都没有找到任何东西。
这就像MIDI服务自己出现,如果我提供一些其他服务,但不提供服务,如果我没有提供服务。此外,如果我尝试自己提供,iPad似乎会阻止或捕获MIDI服务/特性。
这里的任何想法?加油:) :)
亲爱的丹,你用中央设备的Mac(或macbook)和任何可用的商业软件的MIDI消息传输?我想重新创建您的测试环境 –