2016-12-28 40 views
1

我正在使用藍牙連接到合成器,在我的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服務/特性。

這裏的任何想法?加油:) :)

+0

親愛的丹,你用中央設備的Mac(或macbook)和任何可用的商業軟件的MIDI消息傳輸?我想重新創建您的測試環境 –

回答

0

假設你使用CABTMIDILocalPeripheralViewController連接,嘗試用(__bridge void*)self取代arc_cast<void>(self)作爲當前PGMidi庫做,但如果你使用這個庫,你不應該寫這個客戶端初始化自己,這是[[PGMidi alloc] init]內部創建呼叫。反正你可以看到PGMIDINotifyProc被稱爲? 讓我知道