def _create_custos_element(self): custos = MeiElement("custos") # custos = mod.custos_() # custos.id = self._idgen() zone = self._create_zone_element() custos.facs = zone.id custos.addAttribute("pname", str(self.glyph['strt_pitch'])) custos.addAttribute("oct", str(self.glyph['octv'])) custos.addAttribute("facs", str(custos.facs)) return custos
def _create_clef_element(self): clef = MeiElement("clef") # clef = mod.clef_() # clef.id = self._idgen() zone = self._create_zone_element() clef.facs = zone.id clef.addAttribute("facs", str(clef.facs)) # clef.attributes = {"line": self.glyph['strt_pos'], 'shape': self.glyph['form'][0].upper() } clef.addAttribute("line", str(self.glyph['strt_pos'])) clef.addAttribute("shape", str(self.glyph['form'][0].upper())) lg.debug("clef:{0}".format(clef)) return clef
def _create_neume_element(self): full_width_episema = False has_dot = False has_vertical_episema = False has_horizontal_episema = False has_quilisma = False this_neume_form = None local_horizontal_episema = None start_octave = self.glyph['octv'] clef_pos = self.glyph['clef_pos'] clef_type = self.glyph['clef'].split(".")[-1] # f or c. # neume = mod.neume_() neume = MeiElement("neume") # CHECK! # neume.id = self._idgen() zone = self._create_zone_element() neume.facs = zone.id neume.addAttribute("facs", neume.facs) # neumecomponent = mod.nc_() neumecomponent = MeiElement("nc") # CHECK! # neumecomponent.id = self._idgen() neume.addChild(neumecomponent) if self.glyph['form'][0] == "he": full_width_episema = True del self.glyph['form'][0] # we've removed any global he's, so # any leftovers should be local. if 'he' in self.glyph['form']: has_horizontal_episema = True if 'dot' in self.glyph['form']: has_dot = True if 'q' in self.glyph['form']: has_quilisma = True if 've' in self.glyph['form']: has_vertical_episema = True if 'inclinatum' in self.glyph['form']: # neumecomponent.attributes = {'inclinatum': 'true'} neumecomponent.addAttribute("inclinatum", "true") # neume.attributes = {'name': self.glyph['form'][0]} neume.addAttribute("name", str(self.glyph['form'][0])) if 'compound' in self.glyph['form']: # do something and create a new set of pitch contours this_neume_form = [ y for y in (self.__parse_contour(n) for n in self.glyph['form']) if y ] self._note_elements = [ y for y in (self.__parse_steps(n) for n in self.glyph['form']) if y ] else: this_neume_form = copy.deepcopy( self.NEUME_NOTES[self.glyph['form'][0]]) self._note_elements = self.glyph['form'][1:] # get the form so we can find the number of notes we need to construct. num_notes = len(this_neume_form) + 1 # 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:] ] if check_additional: for f in check_additional: this_neume_form.extend(self.ADD_NOTES[f]) ## THIS SHOULD BE CHANGED. Otherwise we may end up with two attributes with the # same name. neume.addAttribute("variant", str(f)) 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._neume_pitches.append(self.glyph['strt_pitch']) nc = [] note_octaves = [start_octave] 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()] idx = self.SCALE.index(self.glyph['strt_pitch']) if len(ivals) != (num_notes - 1): if 'scandicus' in self.glyph['form']: diffr = abs(len(ivals) - (num_notes - 1)) num_notes = num_notes + diffr this_neume_form.extend(diffr * 'u') else: raise AomrMeiNoteIntervalMismatchError( "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'] this_pos = copy.deepcopy(self.glyph['strt_pos']) for n in xrange(len(ivals)): # get the direction dir = this_neume_form[n] iv = ivals[n] n_idx = idx if dir == "u": n_idx = ((idx + iv) % len(self.SCALE)) - 1 this_pos -= (iv - 1) elif dir == "d": n_idx = idx - (iv - 1) this_pos += (iv - 1) if n_idx < 0: n_idx += len(self.SCALE) idx = n_idx self._neume_pitches.append(self.SCALE[n_idx]) actual_line = 10 - (2 * (clef_pos - 1)) if clef_type: if this_pos <= actual_line: note_octaves.append(4) elif this_pos > actual_line + 7: note_octaves.append(2) else: note_octaves.append(3) # elif clef_type == "f": # if (actual_line + 3) >= this_pos > (actual_line - 3): # note_octaves.append(3) # elif this_pos < (actual_line - 3): # note_octaves.append(4) # elif this_pos > (actual_line + 3): # note_octaves.append(2) if full_width_episema is True: epi = self._create_episema_element() # epi.attributes = {"form": "horizontal"} TROUBLE epi.addAttribute("form", "horizontal") self.layer.addChild(epi) qidxs = [] if has_quilisma: self.__note_addition_figurer_outer("q", qidxs) dotidxs = [] if has_dot: self.__note_addition_figurer_outer("dot", dotidxs) veidxs = [] if has_vertical_episema: self.__note_addition_figurer_outer("ve", veidxs) heidxs = [] if has_horizontal_episema: self.__note_addition_figurer_outer("he", heidxs) for n in xrange(num_notes): p = self._neume_pitches[n] o = note_octaves[n] # lg.debug("n:{0}, p:{1}, o:{2}".format(n, p, o)) nt = self._create_note_element(p) nt.addAttribute("oct", str(o)) # lg.debug("nt.pitchname:{0}".format(nt.pname)) if n == 0 and full_width_episema is True: epi.addAttribute("startid", str(nt.id)) elif n == num_notes and full_width_episema is True: epi.addAttribute("endid", str(nt.id)) if has_quilisma: if n in qidxs: neumecomponent.addAttribute("quilisma", "true") if has_dot: if n in dotidxs: d = self._create_dot_element() nt.addChild(d) if has_vertical_episema: if n in veidxs: ep = self._create_episema_element() ep.addAttribute("form", "vertical") ep.addAttribute("startid", str(nt.id)) self.layer.addChild(ep) if has_horizontal_episema: if n in heidxs: local_horizontal_episema = self._create_episema_element() local_horizontal_episema.addAttribute("form", "horizontal") local_horizontal_episema.addAttribute( "startid", str(nt.id)) self.layer.addChild(local_horizontal_episema) if n == num_notes - 1 and local_horizontal_episema: # we've reached the end, and we have an HE we need to close up. local_horizontal_episema.addAttribute("endid", str(nt.id)) nc.append(nt) for c in nc: neumecomponent.addChild(c) return neume
def _create_neume_element(self): full_width_episema = False has_dot = False has_vertical_episema = False has_horizontal_episema = False has_quilisma = False this_neume_form = None local_horizontal_episema = None start_octave = self.glyph['octv'] clef_pos = self.glyph['clef_pos'] clef_type = self.glyph['clef'].split(".")[-1] # f or c. # neume = mod.neume_() neume = MeiElement("neume") # CHECK! # neume.id = self._idgen() zone = self._create_zone_element() neume.facs = zone.id neume.addAttribute("facs", neume.facs) # neumecomponent = mod.nc_() neumecomponent = MeiElement("nc") # CHECK! # neumecomponent.id = self._idgen() neume.addChild(neumecomponent) if self.glyph['form'][0] == "he": full_width_episema = True del self.glyph['form'][0] # we've removed any global he's, so # any leftovers should be local. if 'he' in self.glyph['form']: has_horizontal_episema = True if 'dot' in self.glyph['form']: has_dot = True if 'q' in self.glyph['form']: has_quilisma = True if 've' in self.glyph['form']: has_vertical_episema = True if 'inclinatum' in self.glyph['form']: # neumecomponent.attributes = {'inclinatum': 'true'} neumecomponent.addAttribute("inclinatum", "true") # neume.attributes = {'name': self.glyph['form'][0]} neume.addAttribute("name", str(self.glyph['form'][0])) if 'compound' in self.glyph['form']: # do something and create a new set of pitch contours this_neume_form = [y for y in (self.__parse_contour(n) for n in self.glyph['form']) if y] self._note_elements = [y for y in (self.__parse_steps(n) for n in self.glyph['form']) if y] else: this_neume_form = copy.deepcopy(self.NEUME_NOTES[self.glyph['form'][0]]) self._note_elements = self.glyph['form'][1:] # get the form so we can find the number of notes we need to construct. num_notes = len(this_neume_form) + 1 # 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:]] if check_additional: for f in check_additional: this_neume_form.extend(self.ADD_NOTES[f]) ## THIS SHOULD BE CHANGED. Otherwise we may end up with two attributes with the # same name. neume.addAttribute("variant", str(f)) 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._neume_pitches.append(self.glyph['strt_pitch']) nc = [] note_octaves = [start_octave] 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()] idx = self.SCALE.index(self.glyph['strt_pitch']) if len(ivals) != (num_notes - 1): if 'scandicus' in self.glyph['form']: diffr = abs(len(ivals) - (num_notes - 1)) num_notes = num_notes + diffr this_neume_form.extend(diffr * 'u') else: raise AomrMeiNoteIntervalMismatchError("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'] this_pos = copy.deepcopy(self.glyph['strt_pos']) for n in xrange(len(ivals)): # get the direction dir = this_neume_form[n] iv = ivals[n] n_idx = idx if dir == "u": n_idx = ((idx + iv) % len(self.SCALE)) - 1 this_pos -= (iv - 1) elif dir == "d": n_idx = idx - (iv - 1) this_pos += (iv - 1) if n_idx < 0: n_idx += len(self.SCALE) idx = n_idx self._neume_pitches.append(self.SCALE[n_idx]) actual_line = 10 - (2*(clef_pos-1)) if clef_type: if this_pos <= actual_line: note_octaves.append(4) elif this_pos > actual_line + 7: note_octaves.append(2) else: note_octaves.append(3) # elif clef_type == "f": # if (actual_line + 3) >= this_pos > (actual_line - 3): # note_octaves.append(3) # elif this_pos < (actual_line - 3): # note_octaves.append(4) # elif this_pos > (actual_line + 3): # note_octaves.append(2) if full_width_episema is True: epi = self._create_episema_element() # epi.attributes = {"form": "horizontal"} TROUBLE epi.addAttribute("form", "horizontal") self.layer.addChild(epi) qidxs = [] if has_quilisma: self.__note_addition_figurer_outer("q", qidxs) dotidxs = [] if has_dot: self.__note_addition_figurer_outer("dot", dotidxs) veidxs = [] if has_vertical_episema: self.__note_addition_figurer_outer("ve", veidxs) heidxs = [] if has_horizontal_episema: self.__note_addition_figurer_outer("he", heidxs) for n in xrange(num_notes): p = self._neume_pitches[n] o = note_octaves[n] # lg.debug("n:{0}, p:{1}, o:{2}".format(n, p, o)) nt = self._create_note_element(p) nt.addAttribute("oct", str(o)) # lg.debug("nt.pitchname:{0}".format(nt.pname)) if n == 0 and full_width_episema is True: epi.addAttribute("startid", str(nt.id)) elif n == num_notes and full_width_episema is True: epi.addAttribute("endid", str(nt.id)) if has_quilisma: if n in qidxs: neumecomponent.addAttribute("quilisma", "true") if has_dot: if n in dotidxs: d = self._create_dot_element() nt.addChild(d) if has_vertical_episema: if n in veidxs: ep = self._create_episema_element() ep.addAttribute("form", "vertical") ep.addAttribute("startid", str(nt.id)) self.layer.addChild(ep) if has_horizontal_episema: if n in heidxs: local_horizontal_episema = self._create_episema_element() local_horizontal_episema.addAttribute("form", "horizontal") local_horizontal_episema.addAttribute("startid", str(nt.id)) self.layer.addChild(local_horizontal_episema) if n == num_notes - 1 and local_horizontal_episema: # we've reached the end, and we have an HE we need to close up. local_horizontal_episema.addAttribute("endid", str(nt.id)) nc.append(nt) for c in nc: neumecomponent.addChild(c) return neume