-
- def get_encoding_software (self):
- return self.get_encoding_information ('software')
- def get_encoding_date (self):
- return self.get_encoding_information ('encoding-date')
- def get_encoding_person (self):
- return self.get_encoding_information ('encoder')
- def get_encoding_description (self):
- return self.get_encoding_information ('encoding-description')
-
-
-class Duration (Music_xml_node):
- def get_length (self):
- dur = int (self.get_text ()) * Rational (1,4)
- return dur
-
-class Hash_comment (Music_xml_node):
- pass
-class Hash_text (Music_xml_node):
- pass
-
-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'))
-
- step = ch.get_text ().strip ()
- return int (step)
-
- def get_alteration (self):
- ch = self.get_maybe_exist_typed_child (get_class (u'alter'))
- alter = 0
- if ch:
- alter = int (ch.get_text ().strip ())
- return alter
-
-class Measure_element (Music_xml_node):
- def get_voice_id (self):
- voice_id = self.get_maybe_exist_named_child ('voice')
- if voice_id:
- return voice_id.get_text ()
- else:
- return None
-
- def is_first (self):
- cn = self._parent.get_typed_children (self.__class__)
- cn = [c for c in cn if c.get_voice_id () == self.get_voice_id ()]
- return cn[0] == self
-
-class Attributes (Measure_element):
- def __init__ (self):
- Measure_element.__init__ (self)
- self._dict = {}
-
- def set_attributes_from_previous (self, dict):
- self._dict.update (dict)
-
- def read_self (self):
- for c in self.get_all_children ():
- self._dict[c.get_name()] = c
-
- def get_named_attribute (self, name):
- return self._dict.get (name)
-
- def get_measure_length (self):
- (n,d) = self.get_time_signature ()
- return Rational (n,d)
-
- def get_time_signature (self):
- "return time sig as a (beat, beat-type) tuple"
+
+ 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
+
+
+class Attributes(Measure_element):
+
+ def __init__(self):
+ Measure_element.__init__(self)
+ self._dict = {}
+ self._original_tag = None
+ self._time_signature_cache = None
+
+ def is_first(self):
+ cn = self._parent.get_typed_children(self.__class__)
+ if self._original_tag:
+ return cn[0] == self._original_tag
+ else:
+ return cn[0] == self
+
+ def set_attributes_from_previous(self, dict):
+ self._dict.update(dict)
+
+ def read_self(self):
+ for c in self.get_all_children():
+ self._dict[c.get_name()] = c
+
+ def get_named_attribute(self, name):
+ return self._dict.get(name)
+
+ def single_time_sig_to_fraction(self, sig):
+ if len(sig) < 2:
+ return 0
+ n = 0
+ for i in sig[0:-1]:
+ n += i
+ return Rational(n, sig[-1])
+
+ def get_measure_length(self):
+ sig = self.get_time_signature()
+ if not sig or len(sig) == 0:
+ return 1
+ if isinstance(sig[0], list):
+ # Complex compound time signature
+ l = 0
+ for i in sig:
+ l += self.single_time_sig_to_fraction(i)
+ return l
+ else:
+ # Simple(maybe compound) time signature of the form(beat, ..., type)
+ return self.single_time_sig_to_fraction(sig)
+ return 0
+
+ def get_time_signature(self):
+ "Return time sig as a(beat, beat-type) tuple. For compound signatures,"
+ "return either(beat, beat,..., beat-type) or((beat,..., type), "
+ "(beat,..., type), ...)."
+ if self._time_signature_cache:
+ return self._time_signature_cache