Skip to content

Commit cfad7b3

Browse files
committed
Add 'midiprobe()' function
1 parent ebffe48 commit cfad7b3

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

src/lib/libmidi.dylib

48 Bytes
Binary file not shown.

src/libmidi.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,49 @@ void readProc(const MIDIPacketList *newPackets, void *refCon,
9999
}
100100
#endif
101101

102+
DLLEXPORT int midiprobe(char *device)
103+
{
104+
#ifdef __APPLE__
105+
int sourceIndex = 0, destIndex = 0;
106+
char *sourceName, *destName;
107+
CFStringRef displayName;
108+
char name[255];
109+
void *conRef = NULL;
110+
int index;
111+
112+
sourceName = strtok(device, ":");
113+
if (sourceName != NULL) sourceIndex = -1;
114+
for (index = 0; sourceName != NULL && index < MIDIGetNumberOfSources(); index++)
115+
{
116+
dest = MIDIGetSource(index);
117+
MIDIObjectGetStringProperty(dest, kMIDIPropertyDisplayName, &displayName);
118+
CFStringGetCString(displayName, name, 255, kCFStringEncodingASCII);
119+
if (strcmp(sourceName, name) == 0)
120+
{
121+
sourceIndex = index;
122+
break;
123+
}
124+
}
125+
126+
destName = strtok(NULL, ":");
127+
if (destName != NULL) destIndex = -1;
128+
for (index = 0; destName != NULL && index < MIDIGetNumberOfDestinations(); index++)
129+
{
130+
dest = MIDIGetDestination(index);
131+
MIDIObjectGetStringProperty(dest, kMIDIPropertyDisplayName, &displayName);
132+
CFStringGetCString(displayName, name, 255, kCFStringEncodingASCII);
133+
if (strcmp(destName, name) == 0)
134+
{
135+
destIndex = index;
136+
break;
137+
}
138+
}
139+
140+
return sourceIndex >= 0 && destIndex >= 0;
141+
#endif
142+
return 0;
143+
}
144+
102145
DLLEXPORT void midiopen(char *device)
103146
{
104147
#ifdef __APPLE__

src/midi.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ module midi
33
const libmidi = joinpath(@__DIR__, Sys.KERNEL == :NT ? "lib/libmidi.dll" :
44
Sys.KERNEL == :Linux ? "lib/libmidi.so" : "lib/libmidi.dylib")
55

6+
function midiprobe(device)
7+
ret = ccall((:midiprobe, libmidi),
8+
Int32,
9+
(Ptr{UInt8}, ),
10+
device)
11+
end
12+
export midiprobe
13+
614
function midiopen(device="")
715
ccall((:midiopen, libmidi),
816
Nothing,

0 commit comments

Comments
 (0)