Send MIDI to iOS Simulator

Viewed 73

I want to send Midi messages from my mac computer to the iOS simulator to test my iOS App (my real iPad needs repair so I'm stick with the emulator for now).

I found information about creating a network session in Audio&Midi utility and click connect once the iOS Simulator appears in Directory. Il left the port unchanged (5004).

In my App code I created an input port and linked it to the default network session :

MIDIPortRef inPort = 0;
MIDIInputPortCreate(client, CFSTR("Input port"), MyMIDIReadProc, (bridge void * _Nullable) player, &inPort);
session = [MIDINetworkSession defaultSession];
session.enabled = YES;
session.connectionPolicy = MIDINetworkConnectionPolicy_Anyone;
MIDIPortConnectSource(inPort, session.sourceEndpoint, (bridge void * _Nullable) player);

I also added MIDI services discovery :

browser = [[NSNetServiceBrowser alloc] init];
browser.delegate = self;
browser searchForServicesOfType:MIDINetworkBonjourServiceType /* i.e. @"_apple-midi._udp"*/
                            inDomain:@""];

I then implemented some NSNetServiceDelegate and NSNetServiceBrowserDelegate methods.

-(void)netServiceDidResolveAddress:(NSNetService *)service {
    
    if (![[service name] isEqualToString:[[UIDevice currentDevice] name]]) {
        
        [service setDelegate:nil];
        NSLog(@"Resolved service name: %@ host name: %@", [service name], [service hostName]);
        MIDINetworkHost* host = [MIDINetworkHost hostWithName:[service name] netService:service];
        MIDINetworkConnection* newConnection = [MIDINetworkConnection connectionWithHost:host];
        [session addConnection:newConnection];
        NSLog(@"Connected to %@", [service name]);
    }
}

- (void)netServiceBrowser:(NSNetServiceBrowser *)aBrowser didFindService:(NSNetService *)aService {
        NSLog(@"Found service %@ on %@", [aService name], [aService hostName]);
if (![[service name] isEqualToString:[[UIDevice currentDevice] name]]) {
        
        [service setDelegate:nil];
        NSLog(@"Resolved service name: %@ host name: %@", [service name], [service hostName]);
        MIDINetworkHost* host = [MIDINetworkHost hostWithName:[service name] netService:service];
        MIDINetworkConnection* newConnection = [MIDINetworkConnection connectionWithHost:host];
        [networkSession addConnection:newConnection];
        NSLog(@"Connected to %@", [service name]);
    }

The two delegate methods didn't get called.

Also when I send midi messages (fom Logic using Network session 1 as Port) the ios app midi handler is not called.

UPDATE : I created the network connection manually (without discovering), passing the Bonjour name and IP Adresss displayed in Audio&Midi utility

MIDINetworkHost *host = [MIDINetworkHost hostWithName:@"Mac mini xxx" address:@"xxx.xxx.0.10" port:5004];
MIDINetworkConnection *connection = [MIDINetworkConnection connectionWithHost:host];
[networkSession addConnection:connection];

The MyMIDIReadProc handler was called once in debug mode, the first note started playing, however it was cut shortly thereafter, and subsequent MIDI messages were ignored. Also there was a low buzz sound.

0 Answers
Related