python - 如何使用 pygame.midi 发送“延音踏板”midi 信号?
问题描述
可以通过note_on()
ornote_off()
方法调用简单的 midi 信号,但我找不到使用pygame.midi
. 有没有传统的方法可以做到这一点?
解决方案
pygame.midi
不幸的是,在(或大多数其他常用的 Python-MIDI 库)中没有实现延音踏板,因此从 Pygame 模块本地执行它是不可能的。
但是,您可以通过稍微重新构建代码来解决此问题。如果您可以使用特定的键(或事件)代替我假设的物理延音踏板(毕竟,大多数 MIDI 延音踏板都是简单的开关),您可以拉出类似于延音的东西。例如:
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
推荐阅读
- vscode-remote - 从 vscode-remote-WSL 中启动 vscode-remote-containers 时如何设置环境变量?
- javascript - 如何告诉 React 组件调用它的 HTML 页面是活动的
- reactjs - this.setState() on react native 不使用文本输入
- angular - 如何将值发送到一个特定角度的组件页面到应用程序组件页面
- python - Tkinter 标签没有被破坏
- haskell - ghci 设置断点失败
- flutter - 键盘溢出 Flutter 中的文本字段
- apache-spark - 在 Hive-S3 表的情况下,pyspark 命令行出错
- angular - 当单击图标或图标列表时,将所选图标显示为活动
- excel - 如果特定列中的单元格发生更改,则从表中复制行