目前我正在编写一个python脚本,它接受来自键盘yamahap-45的输出。我的目标是将键盘上播放的每个音符与存储在文本文件中的音符进行比较,并标记出错误的音符(例如:当播放某种乐曲时,它会显示出你在哪里出错)。
到目前为止,它可以打印任何音符或踏板事件,不过将来我希望它以
[note, on/off, velocity, tone, time] #for notes
[pedal, on/off, time] #for pedal
问题是键盘发出了我认为是键盘时钟的信号
像这样:
[[248, 0, 0, 0], 1497]
[[248, 0, 0, 0], 1518]
[[248, 0, 0, 0], 1538]
[[248, 0, 0, 0], 1559]
[[248, 0, 0, 0], 1580]
[[248, 0, 0, 0], 1601]
[[248, 0, 0, 0], 1622]
我的问题是,如何过滤出定时midi事件?有没有一种方法可以直接过滤除音符和踏板事件以外的任何midi事件?我觉得有一堆“如果”并不是最好的解决方案
我的脚本的缩短版本:
midi.init()
midiId = 1 #id of my keyboard
midi_out = midi.Input(midiId)
try: # try finally for ctrl-cing
t0 = time.clock() #define beginning time
while True: #begin main loop
for f in midi_out.read(10):
#the events gets read in nested list [[status, numbers, numbers numbers . . .] time]
print(f)
finally:
midi_out.close()
midi.quit()
pygame.quit()
目前没有回答
相关问题 更多 >
编程相关推荐