From 7c6fbef9abe3d75099f36e174a6f4dfd67eeaccc Mon Sep 17 00:00:00 2001 From: DaveHodder67 Date: Thu, 13 Aug 2015 14:09:07 +0100 Subject: MIDI input to sim working --- tools/osx/simulator-osx.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/osx/simulator-osx.c b/tools/osx/simulator-osx.c index 2c0909b..046fdf8 100644 --- a/tools/osx/simulator-osx.c +++ b/tools/osx/simulator-osx.c @@ -89,13 +89,28 @@ static void sim_app_timer_event() app_timer_event(); } +////////////////////////////////////////////////////////////////////////// +static void processPacket(const unsigned char *data, int length) +{ + while (length > 0) + { + printf("%2.2x ", *data++); + --length; + } + printf("\n"); + + // recieve a pad or button press! +} + + static void readProc(const MIDIPacketList *pktlist, void *readProcRefCon, void *srcConnRefCon) { // farm out the packet list entries const MIDIPacket *packet = &pktlist->packet[0]; for (int i=0; i < pktlist->numPackets; ++i) { - // process the packet + // process the packet - in our case, receive a surface message + processPacket(packet->data, packet->length); // next packet = MIDIPacketNext(packet); @@ -124,6 +139,12 @@ static int findLaunchapdPro() { return -1; } + + + if (noErr != MIDIPortConnectSource(g_inDevPort, endpoint, NULL)) + { + return -1; + } } } } @@ -152,7 +173,13 @@ static int findLaunchapdPro() } } - return (g_inDevPort && g_outDevPort); + return !(g_inDevPort && g_outDevPort); +} + +static int createVirtualPorts() +{ + // create local virtual Launchpad Pro ports + return 0; } // ____________________________________________________________________________ @@ -167,21 +194,33 @@ int main(int argc, char * argv[]) } else { + // failed to open MIDI client return -1; } if (findLaunchapdPro()) { + // no Launchpad Pro connected return -2; } + if (createVirtualPorts()) + { + // unable to open virtual MIDI ports + return -3; + } + // init the app sim_app_init(); // start the terrible busywaiting timer loop for (;;) { - break; + usleep(1000); + app_timer_event(); + + // tickle the runloop so we can recieve events + while (kCFRunLoopRunHandledSource == CFRunLoopRunInMode(kCFRunLoopCommonModes, 0, true)); } return 0; -- cgit v1.2.1