首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mido -如何从不同端口实时获取midi数据

Mido -如何从不同端口实时获取midi数据
EN

Stack Overflow用户
提问于 2020-02-12 06:40:55
回答 1查看 914关注 0票数 1

我已经创建了两个端口作为输入,从键盘和midi表面控制器(它有一堆滑块和旋钮)捕获数据。虽然我不知道如何从这两个

代码语言:javascript
复制
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端口,但是第二个循环从未通过。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-12 07:09:48

找到了一个解决方案;您需要将for循环封装在which循环中,并使用iter_pending()函数,这确实允许mido继续运行,并且不会在第一个循环上停滞不前。

也许有一个更优雅的解决方案,但这正是我所能找到的

代码语言:javascript
复制
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)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60182510

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档