开发者

How do I send midi Control Change messages (CC's) using pyPortMidi or pygame?

开发者 https://www.devze.com 2023-01-21 00:50 出处:网络
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\

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


It looks like you would use the write_short method to write raw MIDI packets, or the write 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:

self.midi_out.write_short(0xb0, 17, 123)

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.).


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!!!

0

精彩评论

暂无评论...
验证码 换一张
取 消