def musicxml_duration_to_lily (mxl_note):
d = musicexp.Duration ()
- if mxl_note.get_maybe_exist_typed_child (musicxml.Type):
- d.duration_log = mxl_note.get_duration_log ()
- else:
- d.duration_log = 0
+ # if the note has no Type child, then that method spits out a warning and
+ # returns 0, i.e. a whole note
+ d.duration_log = mxl_note.get_duration_log ()
d.dots = len (mxl_note.get_typed_children (musicxml.Dot))
d.factor = mxl_note._duration / d.get_length ()
'glissando' : musicexp.GlissandoEvent,
'pedal' : musicexp.PedalEvent,
'wavy-line' : musicexp.TrillSpanEvent,
- 'octave-shift' : musicexp.OctaveShiftEvent
+ 'octave-shift' : musicexp.OctaveShiftEvent,
+ 'wedge' : musicexp.HairpinEvent
}
spanner_type_dict = {
'start': -1,
'begin': -1,
- 'up': -2,
+ 'crescendo': -1,
+ 'decreschendo': -1,
+ 'diminuendo': -1,
+ 'continue': 0,
+ 'up': -1,
'down': -1,
'stop': 1,
'end' : 1
}
-spanner_line_type_dict = {
- 'solid': 0,
- 'dashed': 1,
- 'dotted': 2,
- 'wavy': 3
-}
def musicxml_spanner_to_lily_event (mxl_event):
ev = None
print 'unknown span event ', mxl_event
- key = mxl_event.get_type ()
- span_direction = spanner_type_dict.get (key)
- if span_direction:
+ type = mxl_event.get_type ()
+ span_direction = spanner_type_dict.get (type)
+ # really check for None, because some types will be translated to 0, which
+ # would otherwise also lead to the unknown span warning
+ if span_direction != None:
ev.span_direction = span_direction
else:
- print 'unknown span type', key, 'for', name
+ print 'unknown span type', type, 'for', name
+
+ ev.set_span_type (type)
+ ev.line_type = getattr (mxl_event, 'line-type', 'solid')
- if hasattr (mxl_event, 'line-type'):
- span_line_type = spanner_line_type_dict.get (getattr (mxl_event, 'line-type'))
- if span_line_type:
- ev.line_type = span_line_type
# assign the size, which is used for octave-shift, etc.
ev.size = mxl_event.get_size ()
return event
-direction_spanners = [ 'octave-shift', 'pedal' ]
+direction_spanners = [ 'octave-shift', 'pedal', 'wedge' ]
def musicxml_direction_to_lily (n):
# TODO: Handle the <staff> element!
ev = musicxml_dynamics_to_lily_event (dynentry)
if ev:
res.append (ev)
-
- if entry.get_name() == "wedge":
- if hasattr (entry, 'type'):
- wedgetype = entry.type;
- wedgetypeval = {"crescendo" : 1, "decrescendo" : -1,
- "diminuendo" : -1, "stop" : 0 }.get (wedgetype)
- # Really check for != None, becaus otherwise 0 will also cause
- # the code to be executed!
- if wedgetypeval != None:
- event = musicexp.HairpinEvent (wedgetypeval)
- res.append (event)
-
-
- # octave shifts. pedal marks etc. are spanners:
+
+ # octave shifts. pedal marks, hairpins etc. are spanners:
if entry.get_name() in direction_spanners:
event = musicxml_spanner_to_lily_event (entry)
if event:
if not options.output_name:
options.output_name = os.path.basename (filename)
options.output_name = os.path.splitext (options.output_name)[0]
+ elif re.match (".*\.ly", options.output_name):
+ options.output_name = os.path.splitext (options.output_name)[0]
defs_ly_name = options.output_name + '-defs.ly'
printer = musicexp.Output_printer()
printer.set_file (open (driver_ly_name, 'w'))
print_ly_preamble (printer, filename)
- printer.dump (r'\include "%s"' % defs_ly_name)
+ printer.dump (r'\include "%s"' % os.path.basename (defs_ly_name))
print_score_setup (printer, part_list, voices)
printer.newline ()
return voices
+def get_existing_filename_with_extension (filename, ext):
+ if os.path.exists (filename):
+ return filename
+ newfilename = filename + ".xml"
+ if os.path.exists (newfilename):
+ return newfilename;
+ newfilename = filename + "xml"
+ if os.path.exists (newfilename):
+ return newfilename;
+ return ''
def main ():
opt_parser = option_parser()
if not args:
opt_parser.print_usage()
sys.exit (2)
-
- voices = convert (args[0], options)
+
+ # Allow the user to leave out the .xml or xml on the filename
+ filename = get_existing_filename_with_extension (args[0], "xml")
+ if filename and os.path.exists (filename):
+ voices = convert (filename, options)
+ else:
+ progress ("Unable to find input file %s" % args[0])
if __name__ == '__main__':
main()