如何使用 pyPortMidi 或 pygame 发送 midi 控制更改消息 (CC)?
我正在使用 Python 和 Pygame,Pygame 使用 pyPortMidi 作为它的 midi 模块,目前我正在通过 Midi Yoke 向 Ableton live 发送 NoteOn 和 NoteOff 消息,效果很好。但我似乎不知道如何发送抄送消息..
有人吗?
(工人)阶级基本上是这样的。
class MidiIO:
def __init__(self, device_id = None, inst=0):
pygame.midi.init()
pygame.fastevent.init()
if device_id is None:
self.output_id = pygame.midi.get_default_output_id()
else:
self.output_id = device_id
self._print_device_info()
port = self.output_id
print ("using output_id :%s:" % port)
self.midi_out = pygame.midi.Output(port, 0)
self.midi_out.set_instrument(inst)
self.pressed = False
def midiOut(self, btns, note=60, vel=100):
if btns == 1:
if not self.pressed:
self.midi_out.note_on(note, vel)
self.pressed = 1
elif btns == 0:
self.midi_out.note_off(note)
self.pressed = 0
I'm using Python along with Pygame which uses pyPortMidi for it's midi module, and I'm currently sending NoteOn and NoteOff messages through Midi Yoke to Ableton live, which works great. But I can't seem to figure out how I send CC messages..
Anyone?
The (working) class basically looks like this.
class MidiIO:
def __init__(self, device_id = None, inst=0):
pygame.midi.init()
pygame.fastevent.init()
if device_id is None:
self.output_id = pygame.midi.get_default_output_id()
else:
self.output_id = device_id
self._print_device_info()
port = self.output_id
print ("using output_id :%s:" % port)
self.midi_out = pygame.midi.Output(port, 0)
self.midi_out.set_instrument(inst)
self.pressed = False
def midiOut(self, btns, note=60, vel=100):
if btns == 1:
if not self.pressed:
self.midi_out.note_on(note, vel)
self.pressed = 1
elif btns == 0:
self.midi_out.note_off(note)
self.pressed = 0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您可以使用 write_short 方法来写入原始 MIDI 数据包,或者如果您想一次发送多个数据包,则可以使用 write_short 方法。因此,举例来说,如果您想在控制器 17 上发送值 123,则将如下所示:
您可能在文档中没有注意到这一点的原因是术语“状态”经常在 MIDI 协议中使用参考消息类型(即音符打开、音符关闭、控制更改等)。
It looks like you would use the
write_short
method to write raw MIDI packets, or thewrite
method if you want to send several of them at once. So, for example, if you want to send the value 123 on controller 17, that would look like this:The reason you probably didn't notice this in the documentation is that the term "status" is often used in the MIDI protocol to refer to the message type (ie, note on, note off, control change, etc.).
如果除了 CC 之外,您还需要一种发送 NRPN 的方法,请给我留言,我会将我的代码发送给您,因为我正在使用 pygame 制作一个 MIDI 应用程序,它可以与 MIDI CC 和 NRPN 进行通信。
顺便说一句,请小心那些注释打开和注释关闭消息。一些合成器/MIDI 控制器发送相同的音符关闭和音符关闭状态消息,而其他控制器发送不同的音符关闭和音符开启状态消息。您必须确保您的应用程序不会被状态消息混淆。您还必须检查状态消息,以确保它是消息而不是抄送消息,反之亦然,否则您可能会触发注释而不是发送抄送消息。
我所做的是制作一个简单的 MIDI 接收 pygame 应用程序,帮助我研究 MIDI 消息包含的内容以及它们在我的 Alesis Andromeda A6 合成器上触发音符和扭转旋钮时如何形成,使用简单的打印语句。
顺便问一下,您正在制作什么类型的应用程序?我很感兴趣。
祝你好运!!!
if you also need a way to send NRPNs , additionally to CCs, drop me a message and I will send you my code, as I am making a midi app with pygame that communicates both with MIDI CCs and NRPNs.
By the way be careful with those note on and note off messages. Some synth /midi controllers send the same status message for a note off and note off, while others send diffirent note off and note on status messages. You will have to safeguard that your app is not confused by the status messages . You will have also to check the status messages so to make sure that it is a message and not a CC message, or vice versa, or else you might trigger notes instead of sending CC messages.
What I did was to make a simple MIDI receive pygame app that helped me study what the midi messages contained and how they formed while triggering notes and twisting knobs on my Alesis Andromeda A6 synthesizer, using simple print statements.
By the way what type of app you are making ? I am very intrested.
Good luck!!!