tags:

views:

225

answers:

3

Hi all

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%28VS.85%29.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 :)

+4  A: 

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).

Alex Martelli
I replied to you in a new answer, because I can't markup my code here.
Midas
A: 

Thanks for your quick reply!

But I don't really understand what to do with that MIDIINCAPS struct? So I have this:

unsigned int devCount = midiInGetNumDevs();
cout << devCount << " MIDI devices connected:" << endl;
for (unsigned int i = 0; i < devCount; i++) {
 cout << "[" << i << "] " << midiInGetDevCaps(i, NULL, NULL) << endl;
}
Midas
Alex Martelli
Thanks again. But what actually is MIDIINCAPS for? Now I get this as my output:`3 MIDI devices connected: [0] 0 [1] 0 [2] 0`
Midas
A: 

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!

Midas