/usr/bin/lilymidi is in lilypond 2.14.2-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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | #!/usr/bin/python
# Copyright (C) 2006--2011 Brailcom, o.p.s.
#
# Author: Milan Zamazal <pdm@brailcom.org>
#
# This file is part of LilyPond, the GNU music typesetter.
#
# LilyPond is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LilyPond is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
import optparse
import os
import sys
"""
This generic code used for all python scripts.
The quotes are to ensure that the source .py file can still be
run as a python script, but does not include any sys.path handling.
Otherwise, the lilypond-book calls inside the build
might modify installed .pyc files.
"""
for d in ['/usr/share/lilypond/2.14.2',
'/usr/lib/lilypond/2.14.2']:
sys.path.insert (0, os.path.join (d, 'python'))
# dynamic relocation, for GUB binaries.
bindir = os.path.abspath (os.path.dirname (sys.argv[0]))
for p in ['share', 'lib']:
datadir = os.path.abspath (bindir + '/../%s/lilypond/current/python/' % p)
sys.path.insert (0, datadir)
"""
"""
def process_options (args):
parser = optparse.OptionParser (version="2.14.2")
parser.add_option ('', '--filter-tracks', metavar='REGEXP', action='store', type='string', dest='regexp',
help="display only tracks numbers, of those track names matching REGEXP")
parser.add_option ('', '--prefix-tracks', metavar='PREFIX', action='store', type='string', dest='prefix',
help="prefix filtered track numbers with PREFIX")
parser.add_option ('', '--dump', action='store_true', dest='dump',
help="just dump parsed contents of the MIDI file")
parser.usage = parser.usage + " FILE"
options, args = parser.parse_args (args)
if len (args) != 1:
parser.print_help ()
sys.exit (2)
return options, args
def read_midi (file):
import midi
return midi.parse (open (file).read ())
def track_info (data):
tracks = data[1]
def track_name (track):
name = ''
for time, event in track:
if time > 0:
break
if event[0] == 255 and event[1] == 3:
name = event[2]
break
return name
track_info = []
for i in range (len (tracks)):
track_info.append ((i, track_name (tracks[i])))
return track_info
def go ():
options, args = process_options (sys.argv[1:])
midi_file = args[0]
midi_data = read_midi (midi_file)
info = track_info (midi_data)
if options.dump:
print midi_data
elif options.regexp:
import re
regexp = re.compile (options.regexp)
numbers = [str(n+1) for n, name in info if regexp.search (name)]
if numbers:
if options.prefix:
sys.stdout.write ('%s ' % (options.prefix,))
import string
sys.stdout.write (string.join (numbers, ','))
sys.stdout.write ('\n')
else:
for n, name in info:
sys.stdout.write ('%d %s\n' % (n+1, name,))
if __name__ == '__main__':
go ()
|