+
+class Barline(object) :
+
+ def __init__(self, node, measureNotes) :
+ self.node = node
+ location = self.location = node.getAttribute('location') or 'right'
+ try :
+ repeatN = node.getElementsByTagName('repeat')[0]
+ repeat = {'direction' : repeatN.getAttribute('direction'),
+ 'times' : int(repeatN.getAttribute('times') or 1)}
+ if location == 'left' :
+ repeat['note'] = measureNotes[0]
+ elif location == 'right' :
+ repeat['note'] = measureNotes[-1]
+ else :
+ raise ValueError(location)
+ self.repeat = repeat
+ except IndexError :
+ self.repeat = None
+
+ def __str__(self) :
+ if self.repeat :
+ if self.location == 'left' :
+ return '|:'
+ elif self.location == 'right' :
+ return ':|'
+ return '|'
+
+ __repr__ = __str__
+
+
+class Tone(object) :
+
+ @staticmethod
+ def midi_to_step_alter_octave(midi):
+ stepIndex = midi % 12
+ step, alter = CHROM_SCALE[stepIndex]
+ octave = midi / 12 - 1
+ return step, alter, octave
+
+
+ def __init__(self, *args) :
+ if len(args) == 3 :
+ self.step, self.alter, self.octave = args
+ elif len(args) == 1 :
+ midi = args[0]
+ self.step, self.alter, self.octave = Tone.midi_to_step_alter_octave(midi)
+
+ @property
+ def midi(self) :
+ mid = DIATO_SCALE[self.step]
+ mid = mid + (self.octave - OCTAVE_REF) * 12
+ mid = mid + self.alter
+ return mid
+
+
+ @property
+ def name(self) :
+ name = '%s%d' % (self.step, self.octave)
+ if self.alter < 0 :
+ alterext = 'b'
+ else :
+ alterext = '#'
+ name = '%s%s' % (name, abs(self.alter) * alterext)
+ return name
+
+ @property
+ def nom(self) :
+ name = FR_NOTES[self.step]
+ if self.alter < 0 :
+ alterext = 'b'
+ else :
+ alterext = '#'
+ name = '%s%s' % (name, abs(self.alter) * alterext)
+ return name