【问题标题】:Count number of Midi inputs received using Python使用 Python 计算接收到的 Midi 输入的数量
【发布时间】:2018-11-27 03:41:39
【问题描述】:

我正在使用 Mido (https://mido.readthedocs.io/en/latest/) 在 Python 中接收 Midi 消息。 我希望能够记录每次有新输入时收到的消息数量。

问题:

如何将所有输入包装在一个列表中?

然后如何将新的输入项附加到列表中?

当该列表不断变化时,我如何计算该列表中的项目数?

class MyThread(threading.Thread):
def run(self):
    for msg in inport:
        print msg       
m = MyThread()
m.start()

这会产生如下输出:

control_change channel=0 control=16 value=1 time=0
control_change channel=0 control=16 value=2 time=0
control_change channel=0 control=16 value=3 time=0
control_change channel=0 control=16 value=4 time=0
control_change channel=0 control=16 value=5 time=0
control_change channel=0 control=16 value=6 time=0
control_change channel=0 control=16 value=7 time=0

【问题讨论】:

    标签: python count counter midi


    【解决方案1】:

    你可以修改你的线程类来对inport列表进行操作,像这样:

    class MyThread(threading.Thread):
        inport = []
    
        def add(ele):
            inport.append(ele)
        def count(): 
            return len(inport)
        def run(self):
            for msg in self.inport:
                print msg       
        m = MyThread()
        m.start() 
    

    如果您在列表中运行多线程,则可以使用同步结构,例如Queue。了解更多here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-21
      相关资源
      最近更新 更多