Browse Source

Enable auto-detection in OSS mode

Auto-detect a connected microX device also when using the OSS MIDI
driver, by sending a request through all available /dev/midi??
files.
develop
Damien Goutte-Gattat 8 years ago
parent
commit
f0872e118d
  1. 34
      src/midi.c

34
src/midi.c

@ -178,6 +178,8 @@ midi_list_ports(midi_list_port_cb cb, void *user)
#elif USE_OSS_MIDI_API
/* Open Sound System MIDI API */
#include <fcntl.h>
#include <string.h>
#include <dirent.h>
#define MIDI_IO_BUFFER_SIZE 256
@ -299,6 +301,38 @@ midi_error(midi_io_t *midi)
return strerror(midi->error);
}
static int
is_midi_device(const struct dirent *entry)
{
if ( strncmp(entry->d_name, "midi", 4) == 0 )
return 1;
return 0;
}
#include <stdio.h>
int
midi_list_ports(midi_list_port_cb cb, void *user)
{
int n, ret;
struct dirent **namelist;
char path[32];
ret = 0;
if ( (n = scandir("/dev", &namelist, is_midi_device, alphasort)) != -1 ) {
while ( n-- ) {
if ( ret == 0 ) {
snprintf(path, sizeof(path), "/dev/%s", namelist[n]->d_name);
ret = cb(path, user);
}
free(namelist[n]);
}
free(namelist);
}
return ret;
}
#else
#error "No MIDI API available"

Loading…
Cancel
Save