我使用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
您只需修改线程类即可对
inport
列表执行操作,如下所示:如果在列表上运行多线程,可以使用像
Queue
这样的同步结构。了解更多here相关问题 更多 >
编程相关推荐