def __call__(self, q_events): r'''Calls concatenating grace handler. ''' from abjad.tools import quantizationtools grace_events, final_event = q_events[:-1], q_events[-1] if isinstance(final_event, quantizationtools.PitchedQEvent): pitches = final_event.pitches else: pitches = () if grace_events: grace_container = scoretools.GraceContainer() for q_event in grace_events: if isinstance(q_event, quantizationtools.PitchedQEvent): if len(q_event.pitches) == 1: leaf = scoretools.Note(q_event.pitches[0], self.grace_duration) else: leaf = scoretools.Chord(q_event.pitches, self.grace_duration) else: leaf = scoretools.Rest(self.grace_duration) grace_container.append(leaf) else: grace_container = None return pitches, grace_container
def edit_cello_voice(score, durated_reservoir): r'''Edits cello voice. ''' voice = score['Cello Voice'] descents = durated_reservoir['Cello'] logical_tie = inspect_(voice[-1]).get_logical_tie() for leaf in logical_tie.leaves: parent = leaf._get_parentage().parent index = parent.index(leaf) parent[index] = scoretools.Chord(['e,', 'a,'], leaf.written_duration) selection = voice[-len(descents[-1]):] unison_descent = mutate(selection).copy() voice.extend(unison_descent) for chord in unison_descent: index = inspect_(chord).get_parentage().parent.index(chord) parent[index] = scoretools.Note( chord.written_pitches[1], chord.written_duration) articulation = indicatortools.Articulation('accent') attach(articulation, parent[index]) articulation = indicatortools.Articulation('tenuto') attach(articulation, parent[index]) voice.extend('a,1. ~ a,2') voice.extend('b,1 ~ b,1. ~ b,1.') voice.extend('a,1. ~ a,1. ~ a,1. ~ a,1. ~ a,1. ~ a,2') voice.extend('r4 r2.')
def _notate_leaves( self, grace_handler=None, voice=None, ): for leaf in iterate(voice).by_leaf(): if leaf._has_indicator(indicatortools.Annotation): annotation = leaf._get_indicator(indicatortools.Annotation) pitches, grace_container = grace_handler(annotation.value) if not pitches: new_leaf = scoretools.Rest(leaf) elif 1 < len(pitches): new_leaf = scoretools.Chord(leaf) new_leaf.written_pitches = pitches else: new_leaf = scoretools.Note(leaf) new_leaf.written_pitch = pitches[0] if grace_container: attach(grace_container, new_leaf) tie = spannertools.Tie() if tie._attachment_test(new_leaf): attach(tie, new_leaf) mutate(leaf).replace(new_leaf) else: previous_leaf = leaf._get_leaf(-1) if isinstance(previous_leaf, scoretools.Rest): new_leaf = type(previous_leaf)( leaf.written_duration, ) elif isinstance(previous_leaf, scoretools.Note): new_leaf = type(previous_leaf)( previous_leaf.written_pitch, leaf.written_duration, ) else: new_leaf = type(previous_leaf)( previous_leaf.written_pitch, leaf.written_duration, ) mutate(leaf).replace(new_leaf) tie = inspect_(previous_leaf).get_spanner(spannertools.Tie) if tie is not None: tie._append(new_leaf) if leaf._has_indicator(indicatortools.Tempo): tempo = leaf._get_indicator(indicatortools.Tempo) detach(indicatortools.Tempo, leaf) attach(tempo, new_leaf)
def t_notes_417(self, t): pitch_names = self.client._pitch_names if t.value in pitch_names: t.type = 'NOTENAME_PITCH' t.value = pitch_names[t.value] elif t.value in ['r', 's']: t.type = 'RESTNAME' elif t.value == 'R': t.type = 'MULTI_MEASURE_REST' elif t.value == 'q': if self.client._last_chord is None: self.client._last_chord = scoretools.Chord(['c', 'g', "c'"], (1, 4)) t.type = 'CHORD_REPETITION' else: t.type = 'STRING' return t
def make_desordre_cell(pitches): '''The function constructs and returns a *Désordre cell*. `pitches` is a list of numbers or, more generally, pitch tokens. ''' notes = [scoretools.Note(pitch, (1, 8)) for pitch in pitches] beam = spannertools.Beam() attach(beam, notes) slur = spannertools.Slur() attach(slur, notes) clef = indicatortools.Dynamic('f') attach(clef, notes[0]) dynamic = indicatortools.Dynamic('p') attach(dynamic, notes[1]) # make the lower voice lower_voice = scoretools.Voice(notes) lower_voice.name = 'RH Lower Voice' command = indicatortools.LilyPondCommand('voiceTwo') attach(command, lower_voice) n = int(math.ceil(len(pitches) / 2.)) chord = scoretools.Chord([pitches[0], pitches[0] + 12], (n, 8)) articulation = indicatortools.Articulation('>') attach(articulation, chord) # make the upper voice upper_voice = scoretools.Voice([chord]) upper_voice.name = 'RH Upper Voice' command = indicatortools.LilyPondCommand('voiceOne') attach(command, upper_voice) # combine them together container = scoretools.Container([lower_voice, upper_voice]) container.is_simultaneous = True # make all 1/8 beats breakable leaves = select(lower_voice).by_leaf() for leaf in leaves[:-1]: bar_line = indicatortools.BarLine('') attach(bar_line, leaf) return container
def __call__(self, expr): r'''Calls diatonic cluster handler on `expr`. Returns none. ''' for i, note in enumerate(iterate(expr).by_class(scoretools.Note)): cluster_width = self.cluster_widths[i] start = note.written_pitch.diatonic_pitch_number diatonic_numbers = range(start, start + cluster_width) chromatic_numbers = [ (12 * (x // 7)) + pitchtools.PitchClass. _diatonic_pitch_class_number_to_pitch_class_number[x % 7] for x in diatonic_numbers ] chord_pitches = [ pitchtools.NamedPitch(x) for x in chromatic_numbers ] chord = scoretools.Chord(note) chord.note_heads[:] = chord_pitches mutate(note).replace(chord)
def p_chord_body__chord_pitches__positive_leaf_duration(self, p): r'''chord_body : chord_pitches positive_leaf_duration ''' p[0] = scoretools.Chord(p[1], p[2])
def p_chord_body__chord_pitches(self, p): r'''chord_body : chord_pitches ''' p[0] = scoretools.Chord(p[1], self._default_duration)