Enumerating MIDI devices

In addition to audio playback and recording, Windows Multimedia (WinMM) provides a Musical Instrument Digital Interface (MIDI) API.

Here’s how to make a list of all the MIDI devices on the system, their capabilities, and the hardware device interface associated with each of them.

Source and binaries attached.


midiInGetNumDevs or midiOutGetNumDevs
for each device
    midiInGetDevCaps or midiOutGetDevCaps
    log device capabilities
    midiInMessage or midiOutMessage
    log the device interface


midiIn devices: 1
— 0: USB2.0 MIDI Device —
    Device ID: 0
    Manufacturer identifier: 65535
    Product identifier: 65535
    Driver version: 1.6
    Product name: USB2.0 MIDI Device
    Support: 0x0
    Device interface: “\\?\usb#vid_xxxx&pid_yyyy&…”
midiOut devices: 2
— 0: Microsoft GS Wavetable Synth —
    Device ID: 0
    Manufacturer identifier: 1
    Product identifier: 27
    Driver version: 1.0
    Product name: Microsoft GS Wavetable Synth
    Technology: 7 (MOD_SWSYNTH)
    Voices: 32
    Notes: 32
    Channel mask: 0xffff
    Support: 0x1
    Device interface: “”
— 1: USB2.0 MIDI Device —
    Device ID: 1
    Manufacturer identifier: 65535
    Product identifier: 65535
    Driver version: 1.6
    Product name: USB2.0 MIDI Device
    Technology: 1 (MOD_MIDIPORT)
    Voices: 0
    Notes: 0
    Channel mask: 0xffff
    Support: 0x0
    Device interface: “\\?\usb#vid_xxxx&pid_yyyy&…”

(Actual device interface string suppressed.)

Note the Microsoft GS Wavetable Synth device, which is always present.

Why would you want to know the device interface? In our case, because we want to test all the audio-related interfaces of a particular device on the system.

EDIT September 22 2015: moved source to github https://github.com/mvaneerde/blog/tree/master/midienum


Comments (2)

  1. Mike Horgan says:

    I stumbled on your blog post while investigating whether there is some way to associate a specific MIDI device to a particular (specific) USB device. I have an application which is responsible for updating firmware for a variety of our (Line 6) devices. These are all USB devices. The application enumerates the USB devices using SetupDi calls to identify instances of our devices. There is one particular devices which exposes a USB class 1 audio/MIDI interface. The MIDI interface is used to update the firmware on this device. When instanced the abstraction for this device enumerates system MIDI devices to locate the MIDI in/out port to use. It uses midiInGetDevCaps and midiOutGetDevCaps calls and matches the name string. The problem I’d like to solve is how to make this association in cases where there are more than one of this particular device. I don’t believe the string returned from sending DRV_QUERYDEVICEINTERFACE message provides a means for this.

    1. You can use the “container ID” device property to see if two device interfaces are on the same piece of physical hardware. This is how the “Devices and Printers” control panel works.

Skip to main content