@@ -165,6 +165,22 @@ static void Send_Event(REBMID *midi_port, REBINT type) {
165
165
return 0 ;
166
166
}
167
167
168
+ // MIDI notify callback function
169
+ void MIDINotifyCallback (const MIDINotification * message , void * refCon ) {
170
+ #ifdef DEBUG_MIDI
171
+ printf ("MIDINotifyCallback messageID: %u - " , message -> messageID );
172
+ switch (message -> messageID ) {
173
+ case kMIDIMsgSetupChanged : puts ("kMIDIMsgSetupChanged" ); break ;
174
+ case kMIDIMsgObjectAdded : puts ("kMIDIMsgObjectAdded" ); break ;
175
+ case kMIDIMsgObjectRemoved : puts ("kMIDIMsgObjectRemoved" ); break ;
176
+ case kMIDIMsgPropertyChanged : puts ("kMIDIMsgPropertyChanged" ); break ;
177
+ case kMIDIMsgThruConnectionsChanged : puts ("kMIDIMsgThruConnectionsChanged" ); break ;
178
+ case kMIDIMsgSerialPortOwnerChanged : puts ("kMIDIMsgSerialPortOwnerChanged" ); break ;
179
+ case kMIDIMsgIOError : puts ("kMIDIMsgIOError" ); break ;
180
+ }
181
+ #endif
182
+ }
183
+
168
184
/***********************************************************************
169
185
**
170
186
** MidiIn callback procedure.
@@ -245,7 +261,7 @@ static void PrintMidiDevices()
245
261
#endif
246
262
if (gClient ) return DR_DONE ;
247
263
248
- MIDIClientCreate (CFSTR ("Rebol3 MIDI" ), NULL , NULL , & gClient );
264
+ MIDIClientCreate (CFSTR ("Rebol3 MIDI" ), MIDINotifyCallback , NULL , & gClient );
249
265
MIDIInputPortCreate (gClient , CFSTR ("Input port" ), MidiInProc , NULL , & gInPort );
250
266
MIDIOutputPortCreate (gClient , CFSTR ("Output port" ), & gOutPort );
251
267
#ifdef DEBUG_MIDI
@@ -460,6 +476,10 @@ static void PrintMidiDevices()
460
476
CFStringRef pname ;
461
477
462
478
if (!gClient && (DR_DONE != Init_MIDI (req ))) return DR_ERROR ;
479
+
480
+ // We need to run Core foundation loop to receive MIDI notify callbacks
481
+ // Without it the output may be incorrect.
482
+ CFRunLoopRunInMode (kCFRunLoopDefaultMode , 0 , true);
463
483
464
484
#ifdef DEBUG_MIDI
465
485
printf ("Query_MIDI sources: %i dests: %i\n" , MIDIGetNumberOfSources (), MIDIGetNumberOfDestinations ());
0 commit comments