#
# source file of the GNU LilyPond music typesetter
#
-# convert MIDI to LilyPond source
-#
+# (c) 1998--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+# Jan Nieuwenhuizen <janneke@gnu.org>
'''
################################################################
# Users of python modules should include this snippet.
#
-# If set, LILYPONDPREFIX must take prevalence
-# if datadir is not set, we're doing a build and LILYPONDPREFIX
-datadir = '@local_lilypond_datadir@'
-if not os.path.isdir (datadir):
- datadir = '@lilypond_datadir@'
-if os.environ.has_key ('LILYPONDPREFIX') :
- datadir = os.environ['LILYPONDPREFIX']
- while datadir[-1] == os.sep:
- datadir= datadir[:-1]
-
-sys.path.insert (0, os.path.join (datadir, 'python'))
+# This soon to be removed for: import lilypond.lilylib as ly
+libdir = '@local_lilypond_libdir@'
+if not os.path.isdir (libdir):
+ libdir = '@lilypond_libdir@'
+sys.path.insert (0, os.path.join (libdir, 'python'))
+
+
################################################################
import midi
def _ (s):
return s
-program_name = 'midi2ly'
+program_name = sys.argv[0]
program_version = '@TOPLEVEL_VERSION@'
errorport = sys.stderr
# keep_temp_dir_p = 0
-help_summary = _ ("Convert MIDI to LilyPond source")
+help_summary = _ ("Convert MIDI to LilyPond source.")
option_definitions = [
('', 'a', 'absolute-pitches', _ ("print absolute pitches")),
(_ ("DUR"), 'd', 'duration-quant', _ ("quantise note durations on DUR")),
('', 'e', 'explicit-durations', _ ("print explicit durations")),
- ('', 'h', 'help', _ ("this help")),
+ ('', 'h', 'help', _ ("print this help")),
(_ ("ALT[:MINOR]"), 'k', 'key', _ ("set key: ALT=+sharps|-flats; MINOR=1")),
- (_ ("FILE"), 'o', 'output', _ ("write ouput to FILE")),
+ (_ ("FILE"), 'o', 'output', _ ("write output to FILE")),
(_ ("DUR"), 's', 'start-quant', _ ("quantise note starts on DUR")),
(_ ("DUR*NUM/DEN"), 't', 'allow-tuplet', _ ("allow tuplet durations DUR*NUM/DEN")),
- ('', 'V', 'verbose', _ ("verbose")),
+ ('', 'V', 'verbose', _ ("be verbose")),
('', 'v', 'version', _ ("print version number")),
('', 'w', 'warranty', _ ("show warranty and copyright")),
('', 'x', 'text-lyrics', _ ("treat every text as a lyric")),
def warranty ():
identify ()
sys.stdout.write ('\n')
- sys.stdout.write (_ ('Copyright (c) %s by' % ' 2001--2002'))
+ sys.stdout.write (_ ('Copyright (c) %s by') % ' 2001--2004')
sys.stdout.write ('\n')
sys.stdout.write (' Han-Wen Nienhuys')
sys.stdout.write (' Jan Nieuwenhuizen')
- sys.stdout.write ('\n')
- sys.stdout.write (_ (r'''
-Distributed under terms of the GNU General Public License. It comes with
-NO WARRANTY.'''))
+ sys.stdout.write ('\n\n')
+ sys.stdout.write (_ ("Distributed under terms of the GNU General Public License."))
+ sys.stdout.write (_ ("It comes with NO WARRANTY."))
sys.stdout.write ('\n')
def progress (s):
if o[1]:
sh = '-%s' % o[1]
- sep = ' '
+ sep = ' '
if o[1] and o[2]:
- sep = ','
+ sep = ', '
long = ''
if o[2]:
return str
def help ():
- ls = [(_ ("Usage: %s [OPTION]... FILE") % program_name),
+ ls = [(_ ("Usage: %s [OPTIONS]... FILE") % program_name),
('\n\n'),
(help_summary),
('\n\n'),
('\n'),
(options_help_str (option_definitions)),
('\n\n'),
- (_ ("Report bugs to %s") % 'bug-lilypond@gnu.org'),
+ (_ ("Report bugs to %s.") % 'bug-lilypond@gnu.org'),
('\n')]
map (sys.stdout.write, ls)
return (o, n, a)
- def dump (self):
+ def dump (self, dump_dur = 1):
+ global reference_note
s = chr ((self.notename + 2) % 7 + ord ('a'))
s = s + self.alteration_names[self.alteration + 2]
if absolute_p:
elif commas < 0:
s = s + "," * -commas
- if explicit_durations_p \
- or Duration.compare (self.duration, reference_note.duration):
+ ## FIXME: compile fix --jcn
+ if dump_dur and (explicit_durations_p \
+ or Duration.compare (self.duration,
+ reference_note.duration)):
s = s + self.duration.dump ()
- global reference_note
reference_note = self
# TODO: move space
elif len (notes) > 1:
global reference_note
s = s + '<'
- s = s + notes[0].dump ()
+ s = s + notes[0].dump (dump_dur = 0)
r = reference_note
for i in notes[1:]:
- s = s + i.dump ()
+ s = s + i.dump (dump_dur = 0 )
s = s + '>'
+
+ s = s + notes[0].duration.dump() + ' '
reference_note = r
return s
s = s + '\\relative c '
elif item and item.__class__ == Text:
skip = '" "'
- s = s + '%s = \\lyrics ' % (track + channel)
+ s = s + '%s = \\lyricmode ' % (track + channel)
else:
skip = '\\skip '
# must be in \notes mode for parsing \skip
s = s + ' ' + dump_channel (channels[i][0], skip)
s = s + '}\n\n'
- s = s + '%s = <\n' % track
+ s = s + '%s = <<\n' % track
if clef.type != 2:
s = s + clef.dump () + '\n'
else:
s = s + ' \\context Voice = %s \\%s\n' % (channel,
track + channel)
- s = s + '>\n\n'
+ s = s + '>>\n\n'
return s
def thread_first_item (thread):
for i in range (len (tracks)):
s = s + dump_track (tracks[i], i)
- s = s + '\n\\score {\n <\n'
+ s = s + '\n\\score {\n <<\n'
for i in range (len (tracks)):
track = track_name (i)
item = track_first_item (tracks[i])
s = s + ' \\context Staff=%s \\%s\n' % (track, track)
elif item and item.__class__ == Text:
s = s + ' \\context Lyrics=%s \\%s\n' % (track, track)
- s = s + ' >\n}\n'
+ s = s + ' >>\n}\n'
progress (_ ("%s output to `%s'...") % ('LY', o))
elif o == '--absolute-pitches' or o == '-a':
- global absolute_p
absolute_p = 1
elif o == '--duration-quant' or o == '-d':
- global duration_quant
duration_quant = string.atoi (a)
elif o == '--explicit-durations' or o == '-e':
- global explicit_durations_p
explicit_durations_p = 1
elif o == '--key' or o == '-k':
(alterations, minor) = map (string.atoi, string.split (a + ':0', ':'))[0:2]
sharps = alterations
else:
flats = - alterations
- global key
key = Key (sharps, flats, minor)
elif o == '--start-quant' or o == '-s':
start_quant = string.atoi (a)