我已经创建了两个端口作为输入,从键盘和midi表面控制器(它有一堆滑块和旋钮)捕获数据。虽然我不知道如何从这两个
for msg1 in input_hw:
if not msg1.type == "clock":
print(msg1)
# Play the note if the note has been triggered
if msg1.type == 'note_on' or msg1.type == 'note_off' and msg1.velocity > 0:
out.send(msg1)
for msg in input_hw2:
#avoid to print the clock message
if not msg.type == "clock":
print(msg)第一个For循环工作,我在弹键盘时得到midi音符,键盘绑定到input_hw端口,但是第二个循环从未通过。
发布于 2020-02-12 07:09:48
找到了一个解决方案;您需要将for循环封装在which循环中,并使用iter_pending()函数,这确实允许mido继续运行,并且不会在第一个循环上停滞不前。
也许有一个更优雅的解决方案,但这正是我所能找到的
while True:
for msg1 in input_hw.iter_pending():
if not msg1.type == "clock":
print(msg1)
# Play the note if the note has been triggered
if msg1.type == 'note_on' or msg1.type == 'note_off' and msg1.velocity > 0:
out.send(msg1)
for msg in input_hw2.iter_pending():
#avoid to print the clock message
if not msg.type == "clock":
print(msg)https://stackoverflow.com/questions/60182510
复制相似问题