【发布时间】:2020-09-26 15:33:04
【问题描述】:
我有这个问题: 我想在 C,linux 中创建一个 midi 合成器。由于我没有 USB MIDI 键盘,所以我考虑使用 VMPK 之类的虚拟 MIDI 设备。我在一本书中找到了这段代码,该书还解释了如何使用 portmidi 库:
#include <stdio.h>
#include <portmidi.h>
#include <porttime.h>
int main() {
int cnt,i,dev;
PmError retval;
const PmDeviceInfo *info;
PmEvent msg[32];
PortMidiStream *mstream;
Pm_Initialize();
cnt = Pm_CountDevices();
if(cnt) {
for(i=0; i < cnt; i++){
info = Pm_GetDeviceInfo(i);
if(info->input)
printf("%d: %s \n", i, info->name);
}
printf("choose device: ");
scanf("%d", &dev);
Pt_Start(1, NULL, NULL);
retval = Pm_OpenInput(&mstream, dev, NULL, 512L, NULL,NULL);
if(retval != pmNoError)
printf("error: %s \n", Pm_GetErrorText(retval));
else {
while(Pt_Time(NULL) < 60000){
if(Pm_Poll(mstream)) {
cnt = Pm_Read(mstream, msg, 32);
for(i=0; i<cnt; i++) {
printf("status:%d, byte1=%d, "
"byte2=%d, time=%.3f\n",
Pm_MessageStatus(msg[i].message),
Pm_MessageData1(msg[i].message),
Pm_MessageData2(msg[i].message),
msg[i].timestamp/1000.);
}
}
}
}
Pm_Close(mstream);
}
}
else printf("No MIDI devices found\n");
Pm_Terminate();
return 0;
}
简而言之,一旦程序与 MIDI 输入设备连接,它会监听来自它们的 60 条消息,(打印状态字节和两个数据字节,作为 MIDI 协议)
当我启动 VMPK 时,程序似乎将 VMPK 显示为 midi 输入,名称为“out” Program output 我还检查了“JACK 音频连接”程序以验证 VMPK 是否显示为 MIDI 输入设备 JACK audio output
我不明白为什么当我按下 VMPK 键盘上的一个键时,我没有收到来自程序的任何消息...
我尝试更改 VMPK 配置,但没有得到任何更改。
也许我在 VMPK 配置中做错了什么。
欢迎任何帮助。
提前感谢您的光临
【问题讨论】: