Skip to content

Commit cae3efe

Browse files
committed
FIX: changes of the MIDI setup not recognized on macOS
1 parent 9dbc8e9 commit cae3efe

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/os/osx/dev-midi.c

+21-1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,22 @@ static void Send_Event(REBMID *midi_port, REBINT type) {
165165
return 0;
166166
}
167167

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+
168184
/***********************************************************************
169185
**
170186
** MidiIn callback procedure.
@@ -245,7 +261,7 @@ static void PrintMidiDevices()
245261
#endif
246262
if (gClient) return DR_DONE;
247263

248-
MIDIClientCreate(CFSTR("Rebol3 MIDI"), NULL, NULL, &gClient);
264+
MIDIClientCreate(CFSTR("Rebol3 MIDI"), MIDINotifyCallback, NULL, &gClient);
249265
MIDIInputPortCreate(gClient, CFSTR("Input port"), MidiInProc, NULL, &gInPort);
250266
MIDIOutputPortCreate(gClient, CFSTR("Output port"), &gOutPort);
251267
#ifdef DEBUG_MIDI
@@ -460,6 +476,10 @@ static void PrintMidiDevices()
460476
CFStringRef pname;
461477

462478
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);
463483

464484
#ifdef DEBUG_MIDI
465485
printf("Query_MIDI sources: %i dests: %i\n", MIDIGetNumberOfSources(), MIDIGetNumberOfDestinations());

0 commit comments

Comments
 (0)