将MIDI事件转换为pygame事件

2024-04-29 22:15:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从我的MIDI设备(键盘)获取输入,以便在pygame代码中使用。看起来pygame.midi.midis2events()会很完美,但它们不会告诉您midis是什么意思,这是函数的一个必要参数。在

pygame.midi.midis2events() converts midi events to pygame events

midis2events(midis, device_id) -> [Event, ...]

我的问题是midis是什么意思?我在网上找不到任何指定了这个的地方。在


Tags: to函数代码eventid参数device键盘
1条回答
网友
1楼 · 发布于 2024-04-29 22:15:23

midisread()返回的MIDI事件列表。在

一个example使用它如下:

while not quit:

    # Blit the picture ...
    ...

    # Check for keypresses

    for event in pygame.event.get():
        ...

    for event in midis2events.midis2events(midi_in.read(40), midi_in_id):
        if event.command == midis2events.NOTE_ON:
            play_note(Note().from_int(event.data1))
        ...

    # Update the screen

    pygame.display.update()

相关问题 更多 >