import string
from rational import *
import re
+import sys
def escape_ly_output_string (input_string):
return_string = input_string
return ''.join ([c.get_text () for c in self._children])
def message (self, msg):
- print msg
+ sys.stderr.write (msg)
p = self
while p:
- print ' In: <%s %s>' % (p._name, ' '.join (['%s=%s' % item for item in p._attribute_dict.items()]))
+ sys.stderr.write (' In: <%s %s>' % (p._name, ' '.join (['%s=%s' % item for item in p._attribute_dict.items()])))
p = p.get_parent ()
def get_typed_children (self, klass):
def get_unique_typed_child (self, klass):
cn = self.get_typed_children(klass)
if len (cn) <> 1:
- print self.__dict__
+ sys.stderr.write (self.__dict__)
raise 'Child is not unique for', (klass, 'found', cn)
return cn[0]
return (int (beats.get_text ()),
int (type.get_text ()))
except KeyError:
- print 'error: requested time signature, but time sig unknown'
+ sys.stderr.write ('error: requested time signature, but time sig unknown')
return (4, 4)
# returns clef information in the form ("cleftype", position, octave-shift)
if instrument_name:
return instrument_name
else:
- print "Opps, couldn't find instrument for ID=", id
+ sys.stderr.write ("Opps, couldn't find instrument for ID=%s" % id)
return "Grand Piano"
class Measure (Music_xml_node):
last_measure_position = measure_position
now += dur
measure_position += dur
+ elif dur < Rational (0):
+ # backup element, reset measure position
+ now += dur
+ measure_position += dur
+ if measure_position < 0:
+ # backup went beyond the measure start => reset to 0
+ now -= measure_position
+ measure_position = 0
+ last_moment = now
+ last_measure_position = measure_position
if n._name == 'note':
instrument = n.get_maybe_exist_named_child ('instrument')
if instrument:
def progress (str):
sys.stderr.write (str + '\n')
sys.stderr.flush ()
-
+
+def error_message (str):
+ sys.stderr.write (str + '\n')
+ sys.stderr.flush ()
# score information is contained in the <work>, <identification> or <movement-title> tags
# extract those into a hash, indexed by proper lilypond header attributes
start_pitch.step = n
start_pitch.alteration = a
except KeyError:
- print 'unknown mode', mode
+ error_message ('unknown mode %s' % mode)
fifth = musicexp.Pitch()
fifth.step = 4
if func:
ev = func()
else:
- print 'unknown span event ', mxl_event
+ error_message ('unknown span event %s' % mxl_event)
type = mxl_event.get_type ()
if span_direction != None:
ev.span_direction = span_direction
else:
- print 'unknown span type', type, 'for', name
+ error_message ('unknown span type %s for %s' % (type, name))
ev.set_span_type (type)
ev.line_type = getattr (mxl_event, 'line-type', 'solid')
return ev
-# TODO: Some translations are missing!
short_articulations_dict = {
"staccato": ".",
"tenuto": "-",
#"portato": "_", # does not exist in MusicXML
#"fingering": "", # fingering is special cased, as get_text() will be the event's name
}
+# TODO: Some translations are missing!
articulations_dict = {
##### ORNAMENTS
"trill-mark": "trill",
return event
-## todo
+## TODO
class NegativeSkip:
def __init__ (self, here, dest):
self.here = here
diff = moment - current_end
if diff < Rational (0):
- print 'Negative skip', diff
+ error_message ('Negative skip %s' % diff)
diff = Rational (0)
if diff > Rational (0):
continue
if not n.__class__.__name__ == 'Note':
- print 'not a Note or Attributes?', n
+ error_message ('not a Note or Attributes? %s' % n)
continue
rest = n.get_maybe_exist_typed_child (musicxml.Rest)
if s.get_type () in ('start','stop')]
if slurs:
if len (slurs) > 1:
- print 'more than 1 slur?'
+ error_message ('more than 1 slur?')
lily_ev = musicxml_spanner_to_lily_event (slurs[0])
ev_chord.append (lily_ev)
if len (modes_found) > 1:
- print 'Too many modes found', modes_found.keys ()
+ error_message ('Too many modes found %s' % modes_found.keys ())
return_value = seq_music
for mode in modes_found.keys ():
part_name = part_definition.id
part = part_dict.get (part_name)
if not part:
- print 'unknown part in part-list:', part_name
+ error_message ('unknown part in part-list: %s' % part_name)
continue
- # TODO: Apparently this is broken! There is always only one staff...
nv_dict = voices.get (part)
staves = reduce (lambda x,y: x+ y,
[mxlvoice._staves.keys ()