简单的midi信号可以通过note_on()或note_off()方法调用,但我找不到一种使用pygame.midi发送“持续踏板”midi信号的方法。有什么常规的方法可以做到这一点吗?
发布于 2018-06-28 16:33:14
不幸的是,在pygame.midi (或大多数其他常用的Python-MIDI库)中没有实现维护踏板,因此从Pygame模块本机实现是不可能的。
但是,您可以通过稍微重新构建代码来解决此问题。如果你可以使用一个特定的键(或事件)来代替我认为的物理维持踏板(毕竟,大多数MIDI维持踏板都是simple switches),你就可以拉出类似于维持踏板的东西。例如:
import pygame
from pygame.locals import *
# Midi init and setup, other code, etc...
# device_input = pygame.midi.Input(device_id)
sustain = False
# We will use the spacebar in place of a pedal in this case.
while 1:
for event in pygame.event.get():
# You can also use other events in place of KEYDOWN/KEYUP events.
if event.type == KEYDOWN and event.key == K_SPACE:
sustain = True
elif event.type == KEYUP and event.key == K_SPACE:
sustain = False
# ...
for i in device_input:
if sustain:
# Remove all MIDI key-up events here
# Then play sounds or process midi input accordingly afterwards发布于 2018-06-28 22:29:45
规范defines the sustain pedal as controller 64,因此您必须发送控制更改消息。
pygame.midi没有为此提供特殊函数,因此您必须发送原始字节:
write_short(0xb0 + channel, 64, 127 if pressed else 0);https://stackoverflow.com/questions/51072834
复制相似问题