5 # source file of the GNU LilyPond music typesetter
7 # (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
24 return name
+ ' version ' + version
;
27 sys
.stdout
.write (program_id () + '\n')
30 sys
.stdout
.write ("Usage: %s [options] [files]\n"
31 "Convert mup to ly\n\n"
33 + " -h, --help print this help\n"
39 (options
, files
) = getopt
.getopt (
40 sys
.argv
[1:], 'hp:', ['help', 'package'])
44 if o
== '--help' or o
== '-h':
46 elif o
== '-p' or o
== '--package':
53 sys
.stderr
.write ('[%s' % f
)
60 sys
.stderr
.write ('can\'t open file %s\n ' % f
)
63 sys
.stderr
.write (']')
65 sys
.stderr
.write ('gulped empty file: %s\n'% f
)
71 i
= regex
.search (";", s
)
77 i
= regex
.search (";", s
[o
+1:])
80 name
= regsub
.gsub ("[0-9<>\.&]*", "", note
)
81 duration
= regsub
.gsub ("[a-z+<>#+&\-]*", "", note
)
82 duration
= regsub
.gsub (" ", "", duration
)
88 last_duration
= duration
90 duration
= last_duration
91 name
= regsub
.sub ("#", "is", name
)
92 name
= regsub
.sub ("+", "'", name
)
93 name
= regsub
.sub ("-", ",", name
)
94 name
= regsub
.sub ("ms", "s1", name
)
95 notes
= notes
+ " %s%s" % (name
, duration
)
98 def get_voice (staff
, s
, staffs
):
99 voice
= len (staffs
[staff
-1]) + 1
100 tag
= "^%d [0-9-]*%d[0-9-]*:" % (staff
, voice
)
103 i
= regex
.search (tag
, s
)
106 n
= regex
.search ("$", s
[o
:])
108 line
= regsub
.sub (tag
, "", line
)
109 line
= line_to_ly (line
)
111 i
= regex
.search (tag
, s
[o
+n
:])
115 sys
.stderr
.write ('%d ' % voice
)
116 staffs
[staff
-1].append (notes
)
119 def get_staff (s
, staffs
):
122 sys
.stderr
.write ('Staff %d ( ' % staff
)
124 i
= get_voice (staff
, s
, staffs
)
126 sys
.stderr
.write (')\n')
129 sys
.stderr
.write ('Staff %d ( ' % staff
)
130 i
= get_voice (staff
, s
, staffs
)
137 ly
= os
.path
.basename (os
.path
.splitext (mup
)[0]) + ".ly"
139 sys
.stderr
.write ('\n')
142 i
=get_staff (s
, staffs
)
143 sys
.stderr
.write ('\n')
144 sys
.stderr
.write ('Ly output to: %s...' % ly
)
145 lyfile
= open (ly
, "w")
146 for i
in range (len (staffs
)):
147 for v
in range (len (staffs
[i
])):
148 lyfile
.write ("$staff%d_voice_%d = \\notes {\n %s\n}\n\n" % (i
+1, v
+1, staffs
[i
][v
]))
149 lyfile
.write ("\\score{\n")
150 lyfile
.write ("\\notes <\n")
151 for i
in range (len (staffs
)):
152 lyfile
.write ("\\type Staff=staff%s <\n" % chr(ord('A')+i
))
153 for v
in range (len (staffs
[i
])):
154 lyfile
.write ("{ \\$staff%d_voice_%d } " % (i
+1, v
+1))
155 lyfile
.write ("\n>\n")
159 sys
.stderr
.write ('\n')