def _create_neume_element(self): if "climacus" in self.glyph["form"]: neume = mod.ineume_() else: neume = mod.uneume_() neume.id = self._idgen() zone = self._create_zone_element() neume.facs = zone.id neume.attributes = {"name": self.glyph["form"][0]} # get the form so we can find the number of notes we need to construct. try: # since we define the form of the intervals, we're always off-by-one in the number of notes. num_notes = len(self.NEUME_NOTES[self.glyph["form"][0]]) + 1 except KeyError: raise GameraMeiFormNotFoundError("The form {0} was not found.".format(self.glyph["form"][0])) # do we need to add any further notes? form is pretty loaded, so we # have to check manually, from idx 1 on (since the primary form is always first) # we don't have an off-by-one problem here, since an added interval means an added note check_additional = [i for i in self.ADD_NOTES.keys() if i in self.glyph["form"][1:]] num_notes = num_notes + len(check_additional) self._neume_pitches = [] # note elements are everything after the first form. This determines the shape a note takes. self._note_elements = self.glyph["form"][1:] self._neume_pitches.append(self.glyph["strt_pitch"]) nc = [] if num_notes > 1: # we need to figure out the rest of the pitches in the neume. ivals = [int(d) for d in self._note_elements if d.isdigit()] try: idx = self.SCALE.index(self.glyph["strt_pitch"].upper()) except ValueError: raise GameraMeiPitchNotFoundError( "The pitch {0} was not found in the scale".format(self.glyph["strt_pitch"]) ) if len(ivals) != (num_notes - 1): raise GameraMeiNoteIntervalMismatchError( "There is a mismatch between the number of notes and number of intervals." ) # note elements = torculus.2.2.he.ve # ivals = [2,2] # torculus = ['u','d'] lg.debug(ivals) for n in xrange(len(ivals)): # get the direction dir = self.NEUME_NOTES[self.glyph["form"][0]][n] lg.debug("direction is {0}".format(dir)) iv = ivals[n] n_idx = idx lg.debug("index: {0}".format(idx)) if dir == "u": if (idx + (iv - 1)) >= len(self.SCALE): n_idx = 0 + (iv - 1) else: n_idx = idx + (iv - 1) elif dir == "d": if idx - (iv - 1) < 0: n_idx = len(self.SCALE) + (idx - (iv - 1)) else: n_idx = idx - (iv - 1) idx = n_idx lg.debug("Picking pitch {0}".format(self.SCALE[n_idx])) self._neume_pitches.append(self.SCALE[n_idx]) for n in xrange(num_notes): p = self._neume_pitches[n] nc.append(self._create_note_element(p)) neume.add_children(nc) lg.debug(neume.children) return neume