Discussion:
[Alsa-user] enumerate MIDI devices
Brian Sorahan
2017-02-22 16:31:52 UTC
Permalink
Hi all,

I am hoping to get some guidance on how to properly use the information I
get when I list MIDI devices.
I'm tinkering with this code
https://github.com/scgolang/midi/blob/d50a32b1725ae42044c84f02a53c69004926bd93/midi_linux.go#L94-L152
which seems to list MIDI devices ok.
But if I prefer to use the RawMIDI API to actually connect to the device is
this a reasonable way to formulate the device ID?
https://github.com/scgolang/midi/blob/d50a32b1725ae42044c84f02a53c69004926bd93/midi_linux.go#L125
I'm guessing there is a better way to implement this, but I'm pretty new to
the Sequencer API so I'm not sure what that better way might look like.
Does it even make sense to use the Sequencer API to list devices, but then
use the RawMIDI API to open, read, and write?
The code I'm sharing is hopefully readable for C programmers despite the
fact that it is Go.
Thanks in advance for any feedback!
Clemens Ladisch
2017-02-22 19:04:46 UTC
Permalink
if card := C.snd_seq_client_info_get_card(cinfo); card >= 0 {
device.ID = fmt.Sprintf("hw:%d", card)
}
But if I prefer to use the RawMIDI API to actually connect to the device
That particular device might not be available as a RawMIDI port.
is this a reasonable way to formulate the device ID?
"hw:x" identifies the first RawMIDI port on that card, which is not
necessarily the same as the sequencer port.

To enumerate RawMIDI ports, use snd_ctl_rawmidi_next_device() (see the
source of amidi for an example).
Does it even make sense to use the Sequencer API to list devices, but then
use the RawMIDI API to open, read, and write?
No.


Regards,
Clemens
Brian Sorahan
2017-02-23 02:02:35 UTC
Permalink
I think that's exactly what I needed! Thanks
Post by Clemens Ladisch
if card := C.snd_seq_client_info_get_card(cinfo); card >= 0 {
device.ID = fmt.Sprintf("hw:%d", card)
}
But if I prefer to use the RawMIDI API to actually connect to the device
That particular device might not be available as a RawMIDI port.
is this a reasonable way to formulate the device ID?
"hw:x" identifies the first RawMIDI port on that card, which is not
necessarily the same as the sequencer port.
To enumerate RawMIDI ports, use snd_ctl_rawmidi_next_device() (see the
source of amidi for an example).
Does it even make sense to use the Sequencer API to list devices, but
then
use the RawMIDI API to open, read, and write?
No.
Regards,
Clemens
Loading...