[英]How do I send Meta Messages that has more than 3 bytes data with Pygame.midi?
[英]How do I send the 'sustain pedal' midi signal using pygame.midi?
簡單的midi信號可以通過note_on()
或note_off()
方法調用,但是我找不到使用pygame.midi
發送“延音踏板” 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
該規范將延音踏板定義為控制器64 ,因此您必須發送控制更改消息。
pygame.midi
沒有特殊的功能,因此您必須發送原始字節:
write_short(0xb0 + channel, 64, 127 if pressed else 0);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.