/usr/bin/mma-rm2std is in mma 15.12-1.
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | #! /usr/bin/python
# Convert mma file with roman numeral chords to std.
import sys, os, platform
# setup for the MMA modules.
platform = platform.system()
if platform == 'Windows':
dirlist = ( sys.path[0], "c:/mma", "c:/program files/mma", ".")
else:
dirlist = ( sys.path[0], "/usr/local/share/mma", "/usr/share/mma", '.' )
for d in dirlist:
moddir = os.path.join(d, 'MMA')
if os.path.isdir(moddir):
if not d in sys.path:
sys.path.insert(0, d)
MMAdir = d
break
import MMA.roman
import MMA.keysig
import MMA.gbl as gbl
import MMA.midi
def error(m):
""" Abort on error with message. """
print m
sys.exit(1)
def usage():
""" Print usage message and exit. """
print "Mma-rm2std, (c) Bob van der Poel"
print "Convert a mma file using roman chords to std."
print
sys.exit(1)
##########################
if len(sys.argv[1:]) != 1:
print "mma-rm2std: requires 1 filename argument."
usage()
filename = sys.argv[1]
if filename[0] == '-':
usage()
try:
inpath = open(filename, 'r')
except:
error("Can't access the file '%s'" % filename)
linenum = 1
m = gbl.mtrks[0] = MMA.midi.Mtrk(0)
for l in inpath:
l=l.rstrip()
if l.strip().upper().startswith("KEYSIG"):
t = l
if '//' in t:
t = t[ :t.find('//')]
t=t.split()
MMA.keysig.keySig.set(t[1:])
if l and l[0].isdigit():
# strip off trailing lyric, notes, repeat or comment
eolstuff = ''
s=[]
for d in ("*", "{", "[", '//'):
if l.count(d):
s.append(l.find(d))
if s:
s.sort()
eolstuff = l[s[0]:]
l = l[:s[0]]
l = l.split()
for i in range(1,len(l)):
c=l[i]
if c[0] == '/':
l[i] = " %6s" % c
continue
lead = end = ''
while c[0] in ('+', '-'):
lead += c[0]
c=c[1:]
# strip from right side of chord barre, invert, etc.
s = []
for d in (":", ">", "/", 'z'):
if c.count(d):
s.append(c.find(d))
if s:
s.sort()
end = c[s[0]:]
c = c[:s[0]]
# all we have now is a chord name
if c and c[0] in ("I", "V", "i", "v"):
c=MMA.roman.convert(c)
# reassemble name
c = lead + c + end
l[i] = " %6s" % c
# reassemble line
l.append(eolstuff) # put back comment, lyric, etc.
l = ' '.join(l)
print l
|