从C++发送 MIDI 消息
send midi messages from C++
我使用的是树莓派,所以它有点像Debian(Raspbian)
我有一个正在运行的合成器(Zynaddsubfx),我想从代码向他发送midi消息并让它为我播放音乐。我将为此使用 ALSA。
我设法通过执行以下操作在我的程序中创建了一个"发射端口":
snd_seq_create_simple_port(seq_handle, "My own sequencer",
SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_SUBS_READ,
SND_SEQ_PORT_TYPE_APPLICATION)
现在我可以在aconnect -ol
中看到 ZynSubAddFX,在aconnect -il
中看到我自己的音序器。我能够连接它们:
pi@cacharro:~/projects/tests$ aconnect 129:0 128:0
pi@cacharro:~/projects/tests$ Info, alsa midi port connected
为此,正如CL所建议的那样,我使用了打开的snd_seq_open,存储了序列,然后使用了snd_seq_create_simple_port。但:
如前所述,我只想在用户交互下将命令发送到zynsubaddfx,因此创建队列,添加速度等不是要走的路。
有没有办法通过我打开的端口发送简单的 midi 命令,例如开/关笔记???
在特定时间发送一些事件:
- 打开音序器;
- 创建您自己的(源)端口;
- 构造并发送一些事件。
若要打开排序器,请调用 snd_seq_open
。(您可以使用snd_seq_client_id
获取您的客户编号。
snd_seq_t seq;
snd_seq_open(&seq, "default", SND_SEQ_OPEN_DUPLEX, 0);
要创建端口,请使用 分配端口信息对象 snd_seq_port_info_alloca
,设置端口参数 snd_seq_port_info_set_
xxx 和 call snd_seq_create_port
.或者干脆打电话给snd_seq_create_simple_port
.
int port;
port = snd_seq_create_simple_port(seq, "my port",
SND_SEQ_PORT_CAP_READ | SND_SEQ_POR_CAP_WRITE,
SND_SEQ_PORT_TYPE_APPLICATION);
要发送事件,请分配事件结构(只需对于更改,您可以使用局部snd_seq_event_t
变量),并调用各种 snd_seq_ev_
xxx 函数来设置其属性。然后致电snd_seq_event_output
,并在发送完所有内容后snd_seq_drain_output
事件。
snd_seq_event_t ev;
snd_seq_ev_clear(&ev);
snd_seq_ev_set_direct(&ev);
/* either */
snd_seq_ev_set_dest(&ev, 64, 0); /* send to 64:0 */
/* or */
snd_seq_ev_set_subs(&ev); /* send to subscribers of source port */
snd_seq_ev_set_noteon(&ev, 0, 60, 127);
snd_seq_event_output(seq, &ev);
snd_seq_ev_set_noteon(&ev, 0, 67, 127);
snd_seq_event_output(seq, &ev);
snd_seq_drain_output(seq);
- boost::进程间消息队列引发错误
- 在线编译器中的分段C++没有打印消息
- C++错误消息*成员参考.**初学者*
- 在createdialog创建的窗口中捕获用于编辑控件的OnMouseMove消息
- 要与"if constexpr"一起使用的编译时消息(在预处理器之后)
- 如何通过参数抛出错误消息
- 从服务器传输到客户端的消息不会出现
- ROS2 动态消息模板
- C++秘密消息学校作业
- glad 导致 glfwSwapBuffers 返回错误消息
- C++入门 5 版:类消息和文件夹
- FindPackageHandleStandardArgs.cmake:137 的 CMake 错误(消息):找不到 Boost (缺少:正则表达式)(找到合适的版本"1.72.0",
- 如何处理从一个对象传递到另一个在C++中具有公共抽象类的对象的消息
- 如何接受 [ENTER] 键作为无效输入并发送错误消息
- 由于无效的 ValidateRgn() 子窗口不会收到WM_PAINT消息
- "string.h"在构建适用于iOS的qt应用程序中找不到消息
- 如何将 Firebase 与基于 Linux 的客户端应用配合使用,以便与服务器进行双向消息通信
- 重新定义预定义的 errno 错误消息 (E2BIG)
- 发送到同一通道的连续 MIDI 消息是乱码
- 从C++发送 MIDI 消息