Skip to content

Commit

Permalink
Add 'midiprobe()' function
Browse files Browse the repository at this point in the history
  • Loading branch information
jheinen committed Nov 1, 2022
1 parent ebffe48 commit cfad7b3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
Binary file modified src/lib/libmidi.dylib
Binary file not shown.
43 changes: 43 additions & 0 deletions src/libmidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,49 @@ void readProc(const MIDIPacketList *newPackets, void *refCon,
}
#endif

DLLEXPORT int midiprobe(char *device)
{
#ifdef __APPLE__
int sourceIndex = 0, destIndex = 0;
char *sourceName, *destName;
CFStringRef displayName;
char name[255];
void *conRef = NULL;
int index;

sourceName = strtok(device, ":");
if (sourceName != NULL) sourceIndex = -1;
for (index = 0; sourceName != NULL && index < MIDIGetNumberOfSources(); index++)
{
dest = MIDIGetSource(index);
MIDIObjectGetStringProperty(dest, kMIDIPropertyDisplayName, &displayName);
CFStringGetCString(displayName, name, 255, kCFStringEncodingASCII);
if (strcmp(sourceName, name) == 0)
{
sourceIndex = index;
break;
}
}

destName = strtok(NULL, ":");
if (destName != NULL) destIndex = -1;
for (index = 0; destName != NULL && index < MIDIGetNumberOfDestinations(); index++)
{
dest = MIDIGetDestination(index);
MIDIObjectGetStringProperty(dest, kMIDIPropertyDisplayName, &displayName);
CFStringGetCString(displayName, name, 255, kCFStringEncodingASCII);
if (strcmp(destName, name) == 0)
{
destIndex = index;
break;
}
}

return sourceIndex >= 0 && destIndex >= 0;
#endif
return 0;
}

DLLEXPORT void midiopen(char *device)
{
#ifdef __APPLE__
Expand Down
8 changes: 8 additions & 0 deletions src/midi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ module midi
const libmidi = joinpath(@__DIR__, Sys.KERNEL == :NT ? "lib/libmidi.dll" :
Sys.KERNEL == :Linux ? "lib/libmidi.so" : "lib/libmidi.dylib")

function midiprobe(device)
ret = ccall((:midiprobe, libmidi),
Int32,
(Ptr{UInt8}, ),
device)
end
export midiprobe

function midiopen(device="")
ccall((:midiopen, libmidi),
Nothing,
Expand Down

0 comments on commit cfad7b3

Please sign in to comment.