[英]How do you get midi events using python-rtmidi
The documentation for python-rtmidi
is basically the worse that it is ever written. python-rtmidi
的文档基本上是有史以来最糟糕的。 I'm trying to figure out how to get midi event data using that program.我试图弄清楚如何使用该程序获取 midi 事件数据。 The data I want is something like this我想要的数据是这样的
[ [
I'm not even sure if python-rtmidi
can get that data, that's how bad their documentation is that they do not even tell you what it is that their app does.我什至不确定python-rtmidi
可以获取该数据,这就是他们的文档有多糟糕,他们甚至没有告诉您他们的应用程序是做什么的。 But in any case I need that data and I need it to be in a python program.但在任何情况下,我都需要这些数据,并且我需要它在 python 程序中。 The only example that exists on the python-rtmidi
webpage seems to only show how to output a midi-event to an external musical instrument. python-rtmidi
网页上存在的唯一示例似乎只显示了如何 output 将 midi 事件发送到外部乐器。 I want the opposite.我想要相反的。 I want the data from the instrument to show up on my computer.我希望仪器中的数据显示在我的计算机上。 I can at least get the software to sense my external instrument.我至少可以让软件感应我的外部仪器。 For example, when I use the following code例如,当我使用以下代码时
import logging
import sys
import time
from rtmidi.midiutil import open_midiport
from rtmidi.midiutil import open_midiinput
log = logging.getLogger('test_midiin_poll')
log = logging.getLogger('midiin_poll')
logging.basicConfig(level=logging.DEBUG)
# Prompts user for MIDI input port, unless a valid port number or name
# is given as the first argument on the command line.
# API backend defaults to ALSA on Linux.
port = sys.argv[1] if len(sys.argv) > 1 else None
try:
midiin, port_name = open_midiport(port)
midiin, port_name = open_midiinput(port)
except (EOFError, KeyboardInterrupt):
sys.exit()
It can detect my external Alesis keyboard but I see no variable that resembles something like a key being hit on the keyboard.它可以检测到我的外部 Alesis 键盘,但我没有看到类似于键盘上按下键的变量。 I also need to point out that I need python software which can record the events in real time.我还需要指出,我需要可以实时记录事件的 python 软件。 My first goal is to get the midi events then write a program that calculates whether or not the events are timed properly.我的第一个目标是获取 midi 事件,然后编写一个程序来计算事件是否定时正确。
Update更新
This guy at least is sort of doing what I want to do.这家伙至少在做我想做的事。 He can get the midi events but he doesn't say how he got them.他可以得到 midi 事件,但他没有说他是如何得到它们的。
Mido - How to get midi data in realtime from different ports Mido - 如何从不同端口实时获取 midi 数据
Ok, I solved it.好的,我解决了。
import mido
instrument = mido.get_input_names()
inport = mido.open_input(instrument[0])
events = []
while 1:
msg = inport.receive()
events.append(msg)
This will create a list of events.这将创建一个事件列表。 And from there you can make calculations on the events.从那里您可以对事件进行计算。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.