[英]Get ID from MIDI devices in C++
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.
在制作GUI之前,我将从C ++中的控制台应用程序开始。
I'm quiet new to C/C++ and know how to make a basic console application and have read about the Win32 API. 我是C / C ++的新手,并且知道如何制作基本的控制台应用程序,并且已阅读有关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 我一直在研究Win32应用程序中用于多媒体的MSDN,并且发现了很多MIDI功能: http : //msdn.microsoft.com/zh-cn/library/dd798495(VS.85).aspx
I can receive how many MIDI devices are plugged in this way: 我可以收到以这种方式插入的MIDI设备数量:
#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. 但是现在我想用我认为的
midiInGetID
函数和一个while
循环来找出这些设备的调用方式。 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. 该函数需要一个
HMIDIIN
参数,而且由于几乎所有的MIDI函数都使用此参数,因此我不知道该如何获得。
I know this is not the most obvious topic but it would be great if someone could help me. 我知道这不是最明显的话题,但是如果有人可以帮助我,那将是很好的。
Thanks :) 谢谢 :)
To get information, you loop calling midiInGetDevCaps , with a first parameter varying from 0 included to the result of midiInGetNumDevs
excluded. 要获取信息,请循环调用midiInGetDevCaps ,其第一个参数的范围从0到不包括
midiInGetNumDevs
的结果。 Each call fills a MIDIINCAPS struct (you pass a pointer to the struct when you call the function) with information about the Nth device. 每次调用都使用第N个设备的信息填充MIDIINCAPS结构(在调用函数时将指针传递给该结构)。 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.
要打开设备并填充其他呼叫所需的HMIDIIN,请使用设备号(再次包括0到N-1)作为第二个参数来调用midiInOpen 。
The same concept applies to output devices, except that the names have Out
instead of In
(and for the structures OUT
instead of IN
). 相同的概念适用于输出设备,除了名称使用
Out
而不是In
(以及使用OUT
代替IN
的结构)之外。
Ok I figured it out. 好吧,我知道了。 I didn't know
midiInGetDevCaps
requires a call to the specific properties of it to return the device name. 我不知道
midiInGetDevCaps
需要调用它的特定属性以返回设备名称。
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! 并感谢您的帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.