Sonntag, 20. Februar 2011

Looking for MIDI Network Connections iOS

My next project will include a combined MIDI/OSC controller for iPad as well as a SysEx Editor/Bank Manager for my DSI Evolver. Since we don't really want another 3rd party application to be involved with the MIDI data, I will make use of Network MIDI.
You get the Network session simply by accessing the default session and activating it. Like this:
MIDINetworkSession *session = [MIDINetworkSession defaultSession];
session.connectionPolicy = MIDINetworkConnectionPolicy_Anyone;
session.enabled=YES;
But now you still don't have any connections, so you will have to listen for them until your host has connected to your application. The best way to do this, is by using a thread:
[NSThread detachNewThreadSelector:@selector(waitForConnections:) toTarget:self withObject:session];
Now you will have to create the waitForConnections: method:
- (void) waitForConnections:(id) argument {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    MIDINetworkSession *session = (MIDINetworkSession *)argument;
    BOOL found = NO;

    while (!found) {
        NSSet *connections =[session connections];
        if ((cons = [connections count]) > 0) {

            found = YES;
        } else {
            [NSThread sleepForTimeInterval:1];
        }
    }

    [... do something with connections ....]
    [pool release];
}
To use Network MIDI on a PC, you will have to install rtpMIDI, works just like Network MIDI on the Mac. I will post more on handling the MIDI part when I get there later.

Keine Kommentare:

Kommentar veröffentlichen