Question

I'm a musician and a programmer and would like to create my own program to make music. I'll start with a console application in C++ before I make a GUI.

I'm quiet new to C/C++ and know how to make a basic console application and have read about the Win32 API.

I was looking into MSDN for multimedia in Win32 applications and I found a lot of functions for MIDI: http://msdn.microsoft.com/en-us/library/dd798495(VS.85).aspx

I can receive how many MIDI devices are plugged in this way:

#include <windows.h>
#include <iostream>
using namespace std;
int main() {
    cout << midiInGetNumDevs();
    cout << " MIDI devices connected" << endl;
    return 0;
}

But now i want to find out how these devices are called, with the midiInGetID function I think and a while loop. Can somebody help me with this? The function requires a HMIDIIN parameter and I don't know how I can get one since almost all the MIDI functions use this parameter.

I know this is not the most obvious topic but it would be great if someone could help me.

Thanks :)

Was it helpful?

Solution

To get information, you loop calling midiInGetDevCaps, with a first parameter varying from 0 included to the result of midiInGetNumDevs excluded. Each call fills a MIDIINCAPS struct (you pass a pointer to the struct when you call the function) with information about the Nth device. To open a device, and fill the HMIDIIN needed for other calls, you call midiInOpen with the device number (again, 0 to N-1 included) as the second parameter.

The same concept applies to output devices, except that the names have Out instead of In (and for the structures OUT instead of IN).

OTHER TIPS

Ok I figured it out. I didn't know midiInGetDevCaps requires a call to the specific properties of it to return the device name.

Here is my code:

#include <windows.h>
#include <iostream>
using namespace std;
int main() {
    unsigned int devCount = midiInGetNumDevs();
    cout << devCount << " MIDI devices connected:" << endl;
    MIDIINCAPS inputCapabilities;
    for (unsigned int i = 0; i < devCount; i++) {
        midiInGetDevCaps(i, &inputCapabilities, sizeof(inputCapabilities));
        cout << "[" << i << "] " << inputCapabilities.szPname << endl;
    }
}

And thanks for your help!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top