|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Send all notes and CCs with all possible values an all 16 channels.""" |
| 3 | + |
| 4 | +import argparse |
| 5 | +import logging |
| 6 | +import sys |
| 7 | +import time |
| 8 | + |
| 9 | +from rtmidi.midiutil import open_midioutput |
| 10 | +from rtmidi.midiconstants import * |
| 11 | + |
| 12 | + |
| 13 | +log = logging.getLogger("midi-send-all") |
| 14 | + |
| 15 | +argp = argparse.ArgumentParser() |
| 16 | +argp.add_argument( |
| 17 | + "-v", |
| 18 | + "--verbose", |
| 19 | + action="store_true", |
| 20 | + help="Verbose output" |
| 21 | +) |
| 22 | +argp.add_argument( |
| 23 | + "-c", |
| 24 | + "--channels", |
| 25 | + help="Channel or list of channels (comma-separated) to send on (default: 1..16)", |
| 26 | +) |
| 27 | +argp.add_argument( |
| 28 | + "-d", |
| 29 | + "--delay", |
| 30 | + type=float, |
| 31 | + default=0.01, |
| 32 | + help="Delay between messages (default: %(default).2f s)", |
| 33 | +) |
| 34 | +argp.add_argument( |
| 35 | + "-o", |
| 36 | + "--off-velocity", |
| 37 | + type=int, |
| 38 | + default=64, |
| 39 | + help="Note off velocity (default: %(default)i)" |
| 40 | +) |
| 41 | +argp.add_argument( |
| 42 | + "-V", |
| 43 | + "--velocity", |
| 44 | + type=int, |
| 45 | + default=127, |
| 46 | + help="Note on velocity (default: %(default)i)" |
| 47 | +) |
| 48 | +argp.add_argument( |
| 49 | + "port", |
| 50 | + nargs="?", |
| 51 | + help="MIDI output port (default: ask)" |
| 52 | +) |
| 53 | + |
| 54 | +args = argp.parse_args() |
| 55 | + |
| 56 | +logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) |
| 57 | + |
| 58 | +if args.channels: |
| 59 | + channels = [] |
| 60 | + for ch in args.channels.split(","): |
| 61 | + try: |
| 62 | + ch = int(ch.strip()) - 1 |
| 63 | + if 0 > ch > 16: |
| 64 | + raise ValueError |
| 65 | + except: |
| 66 | + argp.print_help() |
| 67 | + sys.exit(1) |
| 68 | + |
| 69 | + channels.append(ch) |
| 70 | +else: |
| 71 | + channels = range(16) |
| 72 | + |
| 73 | +try: |
| 74 | + midiout, name = open_midioutput() |
| 75 | + |
| 76 | + with midiout: |
| 77 | + for chan in channels: |
| 78 | + for note in range(128): |
| 79 | + log.debug(f"Sending NOTE ON: ch={chan+1:02}, note={note:03}, vel={args.velocity:03}") |
| 80 | + midiout.send_message([NOTE_ON | chan, note, args.velocity]) |
| 81 | + time.sleep(args.delay) |
| 82 | + log.debug(f"Sending NOTE OFF: ch={chan+1:02}, note={note:03}, vel={args.off_velocity:03}") |
| 83 | + midiout.send_message([NOTE_OFF | chan, note, args.off_velocity]) |
| 84 | + time.sleep(args.delay) |
| 85 | + |
| 86 | + for chan in channels: |
| 87 | + for cc in range(128): |
| 88 | + for val in range(128): |
| 89 | + log.debug(f"Sending CONTROL_CHANGE: ch={chan+1:02}, cc={cc:03}, val={val:03}") |
| 90 | + midiout.send_message([CONTROL_CHANGE | chan, cc, val]) |
| 91 | + time.sleep(args.delay) |
| 92 | +except (EOFError, KeyboardInterrupt): |
| 93 | + log.warning("Interrupted.") |
| 94 | + |
| 95 | +log.debug("Done.") |
0 commit comments