+ def get_type(self):
+ type = self.get_maybe_exist_named_child('credit-type')
+ if(type != None):
+ return type.get_text()
+ else:
+ return None
+
+ def find_type(self, credits):
+ sizes = self.get_font_sizes(credits)
+ sizes.sort(reverse=True)
+ ys = self.get_default_ys(credits)
+ ys.sort(reverse=True)
+ xs = self.get_default_xs(credits)
+ xs.sort(reverse=True)
+
+ # Words child of the self credit-element
+ words = self.get_maybe_exist_named_child('credit-words')
+ size = None
+ x = None
+ y = None
+ halign = None
+ valign = None
+ justify = None
+ if(words != None):
+ if hasattr(words, 'font-size'):
+ size = utilities.string_to_integer(getattr(words, 'font-size'))
+ if hasattr(words, 'default-x'):
+ x = round(float(getattr(words, 'default-x')))
+ if hasattr(words, 'default-y'):
+ y = round(float(getattr(words, 'default-y')))
+ if hasattr(words, 'halign'):
+ halign = getattr(words, 'halign')
+ if hasattr(words, 'valign'):
+ valign = getattr(words, 'valign')
+ if hasattr(words, 'justify'):
+ justify = getattr(words, 'justify')
+ if(size and size == max(sizes) and y and y == max(ys) and(justify or halign) and(justify == 'center' or halign == 'center')):
+ return 'title'
+ elif((y and y > min(ys) and y < max(ys)) and((justify or halign) and(justify == 'center' or halign == 'center'))):
+ return 'subtitle'
+ elif((justify or halign) and(justify == 'left' or halign == 'left') and(not(x) or x == min(xs))):
+ return 'lyricist'
+ elif((justify or halign) and(justify == 'right' or halign == 'right') and(not(x) or x == max(xs))):
+ return 'composer'
+ elif(size and size == min(sizes) and y == min(ys)):
+ return 'rights'
+ # Special cases for Finale NotePad
+ elif((valign and(valign == 'top')) and(y and y == ys[1])):
+ return 'subtitle'
+ elif((valign and(valign == 'top')) and(x and x == min(xs))):
+ return 'lyricist'
+ elif((valign and(valign == 'top')) and(y and y == min(ys))):
+ return 'rights'
+ # Other special cases
+ elif((valign and(valign == 'bottom'))):
+ return 'rights'
+ elif(len([item for item in range(len(ys)) if ys[item] == y]) == 2):
+ # The first one is the composer, the second one is the lyricist
+ return 'composer'
+
+ return None # no type recognized
+
+ def get_font_sizes(self, credits):
+ sizes = []
+ for cred in credits:
+ words = cred.get_maybe_exist_named_child('credit-words')
+ if((words != None) and hasattr(words, 'font-size')):
+ sizes.append(getattr(words, 'font-size'))
+ return map(utilities.string_to_integer, sizes)
+
+ def get_default_xs(self, credits):
+ default_xs = []
+ for cred in credits:
+ words = cred.get_maybe_exist_named_child('credit-words')
+ if((words != None) and hasattr(words, 'default-x')):
+ default_xs.append(getattr(words, 'default-x'))
+ return map(round, map(float, default_xs))
+
+ def get_default_ys(self, credits):
+ default_ys = []
+ for cred in credits:
+ words = cred.get_maybe_exist_named_child('credit-words')
+ if((words != None) and hasattr(words, 'default-y')):
+ default_ys.append(getattr(words, 'default-y'))
+ return map(round, map(float, default_ys))
+
+ def get_text(self):
+ words = self.get_maybe_exist_named_child('credit-words')
+ if(words != None):
+ return words.get_text()
+ else:
+ return ''
+
+
+class Duration(Music_xml_node):
+
+ def get_length(self):
+ dur = int(self.get_text()) * Rational(1, 4)
+ return dur
+
+
+class Hash_text(Music_xml_node):
+
+ def dump(self, indent=''):
+ ly.debug_output('%s' % string.strip(self._data))
+
+
+class Pitch(Music_xml_node):
+
+ def get_step(self):
+ ch = self.get_unique_typed_child(get_class(u'step'))
+ step = ch.get_text().strip()
+ return step
+
+ def get_octave(self):
+ ch = self.get_unique_typed_child(get_class(u'octave'))
+ octave = ch.get_text().strip()
+ return int(octave)
+
+ def get_alteration(self):
+ ch = self.get_maybe_exist_typed_child(get_class(u'alter'))
+ return utilities.interpret_alter_element(ch)
+
+ def to_lily_object(self):
+ p = musicexp.Pitch()
+ p.alteration = self.get_alteration()
+ p.step = musicxml2ly_conversion.musicxml_step_to_lily(self.get_step())
+ p.octave = self.get_octave() - 4
+ return p
+
+
+class Unpitched(Music_xml_node):
+
+ def get_step(self):
+ ch = self.get_unique_typed_child(get_class(u'display-step'))
+ step = ch.get_text().strip()
+ return step
+
+ def get_octave(self):
+ ch = self.get_unique_typed_child(get_class(u'display-octave'))
+
+ if ch:
+ octave = ch.get_text().strip()
+ return int(octave)
+ else:
+ return None
+
+ def to_lily_object(self):
+ p = None
+ step = self.get_step()
+ if step:
+ p = musicexp.Pitch()
+ p.step = musicxml2ly_conversion.musicxml_step_to_lily(step)
+ octave = self.get_octave()
+ if octave and p:
+ p.octave = octave - 4
+ return p