/usr/bin/mido-play is in python-mido 1.2.7-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | #!/usr/bin/python
"""
Play MIDI file on output port.
Example:
mido-play some_file.mid
Todo:
- add option for printing messages
"""
from __future__ import print_function, division
import sys
import argparse
import mido
from mido import MidiFile, Message, tempo2bpm
def parse_args():
parser = argparse.ArgumentParser(description=__doc__)
arg = parser.add_argument
arg('-o', '--output-port',
help='Mido port to send output to')
arg('-m', '--print-messages',
dest='print_messages',
action='store_true',
default=False,
help='Print messages as they are played back')
arg('-q', '--quiet',
dest='quiet',
action='store_true',
default=False,
help='print nothing')
arg('files',
metavar='FILE',
nargs='+',
help='MIDI file to play')
return parser.parse_args()
def play_file(output, filename, print_messages):
midi_file = MidiFile(filename)
print('Playing {}.'.format(midi_file.filename))
length = midi_file.length
print('Song length: {} minutes, {} seconds.'.format(
int(length / 60),
int(length % 60)))
print('Tracks:')
for i, track in enumerate(midi_file.tracks):
print(' {:2d}: {!r}'.format(i, track.name.strip()))
for message in midi_file.play(meta_messages=True):
if print_messages:
sys.stdout.write(repr(message) + '\n')
sys.stdout.flush()
if isinstance(message, Message):
output.send(message)
elif message.type == 'set_tempo':
print('Tempo changed to {:.1f} BPM.'.format(
tempo2bpm(message.tempo)))
print()
def main():
try:
with mido.open_output(args.output_port) as output:
print('Using output {!r}.'.format(output.name))
output.reset()
try:
for filename in args.files:
play_file(output, filename, args.print_messages)
finally:
print()
output.reset()
except KeyboardInterrupt:
pass
args = parse_args()
if args.quiet:
def print(*args):
pass
main()
|