diff options
author | Joe Noel <joe.noel@focusrite.com> | 2015-08-19 10:07:51 +0100 |
---|---|---|
committer | Joe Noel <joe.noel@focusrite.com> | 2015-08-19 10:07:51 +0100 |
commit | 5b97aa71c2d10dff5a3c43e9ef1f9b91a35862c7 (patch) | |
tree | 501cafc908b678e11937381f8726c8049f0ff874 | |
parent | 8504fff60d88ed1205c7c1f9df6018cdaee771a4 (diff) | |
download | launchpad-polymaker-5b97aa71c2d10dff5a3c43e9ef1f9b91a35862c7.tar.gz launchpad-polymaker-5b97aa71c2d10dff5a3c43e9ef1f9b91a35862c7.zip |
Switched busy loop for CFRunLoopTimer
-rw-r--r-- | tools/osx/simulator-osx.c | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/tools/osx/simulator-osx.c b/tools/osx/simulator-osx.c index 38fa4dd..0888533 100644 --- a/tools/osx/simulator-osx.c +++ b/tools/osx/simulator-osx.c | |||
@@ -41,6 +41,8 @@ static MIDIPortRef g_inDevPort = 0; | |||
41 | static MIDIPortRef g_outDevPort = 0; | 41 | static MIDIPortRef g_outDevPort = 0; |
42 | static MIDIEndpointRef g_outDevEndpoint = 0; | 42 | static MIDIEndpointRef g_outDevEndpoint = 0; |
43 | 43 | ||
44 | static const float TIMER_INTERVAL_S = 0.001; //s | ||
45 | |||
44 | // ____________________________________________________________________________ | 46 | // ____________________________________________________________________________ |
45 | // | 47 | // |
46 | // Simulator "hal". This lets you exercise your device code without having to upload | 48 | // Simulator "hal". This lets you exercise your device code without having to upload |
@@ -189,6 +191,14 @@ static int findLaunchpadPro() | |||
189 | 191 | ||
190 | // ____________________________________________________________________________ | 192 | // ____________________________________________________________________________ |
191 | 193 | ||
194 | static void timerCallback(CFRunLoopTimerRef timer, void * info) | ||
195 | { | ||
196 | app_timer_event(); | ||
197 | CFRunLoopSourceSignal(info); | ||
198 | } | ||
199 | |||
200 | // ____________________________________________________________________________ | ||
201 | |||
192 | int main(int argc, char * argv[]) | 202 | int main(int argc, char * argv[]) |
193 | { | 203 | { |
194 | // open MIDI ports and wire them up | 204 | // open MIDI ports and wire them up |
@@ -212,15 +222,19 @@ int main(int argc, char * argv[]) | |||
212 | // now start things up | 222 | // now start things up |
213 | app_init(); | 223 | app_init(); |
214 | 224 | ||
215 | // start a terrible busywaiting timer loop | 225 | // start a timer loop |
216 | for (;;) | 226 | CFRunLoopSourceContext source_context; |
217 | { | 227 | bzero(&source_context, sizeof(source_context)); |
218 | usleep(1000); | 228 | CFRunLoopSourceRef source = CFRunLoopSourceCreate(NULL, 0, & source_context); |
219 | app_timer_event(); | 229 | CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopCommonModes); |
220 | 230 | ||
221 | // run the runloop so we can receive MIDI events | 231 | CFRunLoopTimerContext timer_context; |
222 | while (kCFRunLoopRunHandledSource == CFRunLoopRunInMode(kCFRunLoopCommonModes, 0, true)); | 232 | bzero(&timer_context, sizeof(timer_context)); |
223 | } | 233 | timer_context.info = source; |
224 | 234 | CFRunLoopTimerRef timer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent(), TIMER_INTERVAL_S, 0, 0, timerCallback, &timer_context); | |
225 | return 0; | 235 | CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopCommonModes); |
236 | |||
237 | CFRunLoopRun(); | ||
238 | |||
239 | return EXIT_SUCCESS; | ||
226 | } \ No newline at end of file | 240 | } \ No newline at end of file |