File: send_sysex.py

package info (click to toggle)
python-rtmidi 1.5.8-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,248 kB
  • sloc: cpp: 4,228; python: 2,853; makefile: 287; sh: 109; ansic: 19
file content (31 lines) | stat: -rwxr-xr-x 745 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python

import argparse
import sys
import time

from rtmidi.midiutil import open_midioutput


def main(args=None):
    ap = argparse.ArgumentParser()
    ap.add_argument("-p", "--port", help="MIDI output port")
    ap.add_argument("sysex-byte", nargs="+",
                    help="SysEx bytes as hexadecimal")
    args = ap.parse_args()

    midiout, name = open_midioutput(args.port)
    print("Opened port '%s'." % name)

    data = bytearray.fromhex("".join(getattr(args, "sysex-byte")))
    assert data[0] == 0xF0 and data[-1] == 0xF7
    print("Sending %d bytes" % len(data))
    midiout.send_message(data)

    time.sleep(0.5)
    midiout.close_port()
    del midiout


if __name__ == "__main__":
    sys.exit(main() or 0)