def voice_scale_degrees_in_open_position(self, scale_degrees): r'''Voice `scale_degrees` in open position: :: >>> scale = tonalanalysistools.Scale('c', 'major') >>> scale_degrees = [1, 3, ('flat', 5), 7, ('sharp', 9)] >>> pitches = scale.voice_scale_degrees_in_open_position( ... scale_degrees) >>> pitches PitchSegment(["c'", "e'", "gf'", "b'", "ds''"]) Return pitch segment. ''' from abjad.tools import pitchtools from abjad.tools import tonalanalysistools scale_degrees = [ tonalanalysistools.ScaleDegree(x) for x in scale_degrees ] pitch_classes = [ self.scale_degree_to_named_pitch_class(x) for x in scale_degrees ] pitches = [pitchtools.NamedPitch(pitch_classes[0])] for pitch_class in pitch_classes[1:]: pitch = pitchtools.NamedPitch(pitch_class) while pitch < pitches[-1]: pitch += 12 pitches.append(pitch) pitches = pitchtools.PitchSegment(pitches) return pitches
def __call__(self, expr): r'''Calls retrogression on `expr`. .. container:: example **Example 1.** Retrograde pitch classes. :: >>> operator_ = pitchtools.Retrogression() >>> pitch_classes = pitchtools.PitchClassSegment([0, 1, 4, 7]) >>> operator_(pitch_classes) PitchClassSegment([7, 4, 1, 0]) .. container:: example **Example 2.** Does not retrograde single pitches or pitch-classes. :: >>> operator_ = pitchtools.Retrogression() >>> pitch_class = pitchtools.NumberedPitchClass(6) >>> operator_(pitch_class) NumberedPitchClass(6) .. container:: example **Example 3.** Periodic retrogression. :: >>> operator_ = pitchtools.Retrogression(period=3) >>> pitches = pitchtools.PitchSegment("c' d' e' f' g' a' b' c''") >>> operator_(pitches) PitchSegment(["e'", "d'", "c'", "a'", "g'", "f'", "c''", "b'"]) Returns new object with type equal to that of `expr`. ''' from abjad.tools import pitchtools if isinstance(expr, (pitchtools.Pitch, pitchtools.PitchClass)): return expr if not isinstance(expr, ( pitchtools.PitchSegment, pitchtools.PitchClassSegment, )): expr = pitchtools.PitchSegment(expr) if not self.period: return type(expr)(reversed(expr)) result = new(expr, items=()) for shard in sequencetools.partition_sequence_by_counts( expr, [self.period], cyclic=True, overhang=True, ): shard = type(expr)(shard) shard = type(expr)(reversed(shard)) result = result + shard return result
def __init__( self, pitches=None, ): from abjad.tools import pitchtools if pitches is not None: if isinstance(pitches, type(self)): pitches = pitches.pitches else: pitches = pitchtools.PitchSegment( items=pitches, item_class=pitchtools.NamedPitch, ) self._pitches = pitches
def written_pitches(self): r'''Written pitches in chord. .. container:: example **Example 1.** Get written pitches: >>> chord = Chord("<g' c'' e''>4") >>> show(chord) # doctest: +SKIP :: >>> chord.written_pitches PitchSegment(["g'", "c''", "e''"]) .. container:: example **Example 2.** Set written pitches with pitch names: :: >>> chord = Chord("<e' g' c''>4") >>> show(chord) # doctest: +SKIP :: >>> chord.written_pitches = "f' b' d''" >>> show(chord) # doctest: +SKIP .. doctest:: >>> print(format(chord)) <f' b' d''>4 :: >>> chord.written_pitches PitchSegment(["f'", "b'", "d''"]) Set written pitches with any iterable. Returns tuple. ''' return pitchtools.PitchSegment( items=(note_head.written_pitch for note_head in self.note_heads), item_class=pitchtools.NamedPitch, )
def voice_vertically(self, initial_octave=4): r'''Voices pitch-class segment as pitch segment, with each pitch always higher than the previous. :: >>> scale_degree_numbers = [1, 3, 5, 7, 9, 11, 13] >>> scale = tonalanalysistools.Scale('c', 'minor') >>> pitch_classes = pitchtools.PitchClassSegment(( ... scale.scale_degree_to_named_pitch_class(x) ... for x in scale_degree_numbers)) >>> pitch_segment = pitch_classes.voice_vertically() >>> pitch_segment PitchSegment(["c'", "ef'", "g'", "bf'", "d''", "f''", "af''"]) >>> show(pitch_segment) # doctest: +SKIP Returns pitch segment. ''' from abjad.tools import pitchtools initial_octave = pitchtools.Octave(initial_octave) pitches = [] if self: pitch_class = pitchtools.NamedPitchClass(self[0]) pitch = pitchtools.NamedPitch(pitch_class, initial_octave) pitches.append(pitch) for pitch_class in self[1:]: pitch_class = pitchtools.NamedPitchClass(pitch_class) pitch = pitchtools.NamedPitch(pitch_class, initial_octave) while pitch < pitches[-1]: pitch += 12 pitches.append(pitch) if self.item_class is pitchtools.NamedPitchClass: item_class = pitchtools.NamedPitch else: item_class = pitchtools.NumberedPitch return pitchtools.PitchSegment( items=pitches, item_class=item_class, )
def voice_horizontally(self, initial_octave=4): r'''Voices pitch-class segment as pitch segment, with each pitch as close in distance to the previous pitch as possible. :: >>> pitch_classes = pitchtools.PitchClassSegment( ... "c b d e f g e b a c") >>> pitch_segment = pitch_classes.voice_horizontally() >>> show(pitch_segment) # doctest: +SKIP Returns pitch segment. ''' from abjad.tools import pitchtools initial_octave = pitchtools.Octave(initial_octave) pitches = [] if self: pitch_class = pitchtools.NamedPitchClass(self[0]) pitch = pitchtools.NamedPitch(pitch_class, initial_octave) pitches.append(pitch) for pitch_class in self[1:]: pitch_class = pitchtools.NamedPitchClass(pitch_class) pitch = pitchtools.NamedPitch(pitch_class, initial_octave) semitones = abs((pitch - pitches[-1]).semitones) while 6 < semitones: if pitch < pitches[-1]: pitch += 12 else: pitch -= 12 semitones = abs((pitch - pitches[-1]).semitones) pitches.append(pitch) if self.item_class is pitchtools.NamedPitchClass: item_class = pitchtools.NamedPitch else: item_class = pitchtools.NumberedPitch return pitchtools.PitchSegment( items=pitches, item_class=item_class, )
def written_pitches(self): r'''Written pitches in chord. .. container:: example Get written pitches: >>> chord = abjad.Chord("<g' c'' e''>4") >>> abjad.show(chord) # doctest: +SKIP >>> chord.written_pitches PitchSegment("g' c'' e''") .. container:: example Set written pitches with pitch names: >>> chord = abjad.Chord("<e' g' c''>4") >>> abjad.show(chord) # doctest: +SKIP >>> chord.written_pitches = "f' b' d''" >>> abjad.show(chord) # doctest: +SKIP .. docs:: >>> abjad.f(chord) <f' b' d''>4 >>> chord.written_pitches PitchSegment("f' b' d''") Set written pitches with any iterable. Returns tuple. ''' return pitchtools.PitchSegment( items=(note_head.written_pitch for note_head in self.note_heads), item_class=pitchtools.NamedPitch, )
def _sort_self(self): from abjad.tools import pitchtools return sorted(pitchtools.PitchSegment(tuple(self)))
percussion_temple_block_fanfare_music_specifier = consort.MusicSpecifier( attachment_handler=consort.AttachmentHandler( accent=consort.AttachmentExpression( attachments=indicatortools.Articulation('accent'), selector=selectortools.Selector() .by_logical_tie(pitched=True) .by_duration('>', (1, 16), preprolated=True) [0] ), chords=consort.AttachmentExpression( attachments=( consort.ChordExpression( chord_expr=pitchtools.PitchSegment([ ersilia.Percussion.WOOD_BLOCK_5, ersilia.Percussion.WOOD_BLOCK_4, ]), ), None, consort.ChordExpression( chord_expr=pitchtools.PitchSegment([ ersilia.Percussion.WOOD_BLOCK_4, ersilia.Percussion.WOOD_BLOCK_3, ]), ), consort.ChordExpression( chord_expr=pitchtools.PitchSegment([ ersilia.Percussion.WOOD_BLOCK_3, ersilia.Percussion.WOOD_BLOCK_2, ]), ),
def list_named_pitches_in_expr(expr): '''List named pitches in `expr`: :: >>> staff = Staff("c'4 d'4 e'4 f'4") >>> beam = spannertools.Beam() >>> attach(beam, staff[:]) :: >>> for x in pitchtools.list_named_pitches_in_expr(beam): ... x ... NamedPitch("c'") NamedPitch("d'") NamedPitch("e'") NamedPitch("f'") Returns tuple. ''' from abjad.tools import pitchtools from abjad.tools import scoretools from abjad.tools import spannertools # TODO: remove try-except try: result = pitchtools.NamedPitch.from_pitch_carrier(expr) return pitchtools.PitchSegment( items=(result, ), item_class=pitchtools.NamedPitch, ) except (TypeError, ValueError): result = [] if hasattr(expr, 'written_pitches'): result.extend(expr.written_pitches) # for pitch arrays elif hasattr(expr, 'pitches'): result.extend(expr.pitches) elif isinstance(expr, spannertools.Spanner): for leaf in expr._get_leaves(): if (hasattr(leaf, 'written_pitch') and not isinstance(leaf, scoretools.Rest)): result.append(leaf.written_pitch) elif hasattr(leaf, 'written_pitches'): result.extend(leaf.written_pitches) elif isinstance(expr, pitchtools.PitchSet): result.extend(sorted(list(expr))) elif isinstance(expr, (list, tuple, set)): for x in expr: result.extend(list_named_pitches_in_expr(x)) else: for leaf in iterate(expr).by_class(scoretools.Leaf): if hasattr(leaf, 'written_pitch') and not isinstance( leaf, scoretools.Rest): result.append(leaf.written_pitch) elif hasattr(leaf, 'written_pitches'): result.extend(leaf.written_pitches) return pitchtools.PitchSegment( items=result, item_class=pitchtools.NamedPitch, )
markuptools.Markup(text), ]) markup = markup.smaller().italic().pad_around(0.5).whiteout().box() markup = markuptools.Markup(markup, Up) return markup def make_text_spanner(text): markup_contents = make_text_markup(text).contents markup = markuptools.Markup(markup_contents) text_spanner = consort.ComplexTextSpanner(markup=markup) return text_spanner guitar_chords = tuple( pitchtools.PitchSegment(_) for _ in ( "d c' f' a'", "df bf e' a'", "c g bf ef' a'", "b, gf a d' af'", "c g b e' a'", "f bf ef' g' c''", "e a d' fs' b'", "ef af df' f' bf'", "d g c' e' a'", "d b d' f' a'", "d f c' d' g'", "d f b d' g'", )) __all__ = [
), tremolo=consort.AttachmentExpression( attachments=spannertools.StemTremoloSpanner(), selector=selectortools.Selector().by_logical_tie( pitched=True).by_duration('>', (1, 16), preprolated=True)), ), color='magenta', pitch_handler=consort.AbsolutePitchHandler( #logical_tie_expressions=[ # ], pitch_specifier=pitchtools.PitchSegment([ ersilia.Percussion.TOM_4, ersilia.Percussion.TOM_3, ersilia.Percussion.TOM_2, ersilia.Percussion.TOM_1, ersilia.Percussion.TOM_4, ersilia.Percussion.TOM_3, ersilia.Percussion.TOM_2, ersilia.Percussion.TOM_3, ersilia.Percussion.TOM_2, ersilia.Percussion.TOM_2, ]), pitch_operation_specifier=consort.PitchOperationSpecifier( pitch_operations=[ None, pitchtools.Retrograde(), None, ], ), pitches_are_nonsemantic=True, ), rhythm_maker=rhythmmakertools.TaleaRhythmMaker( extra_counts_per_division=[0, 1, 2],
dynamic_tokens='p ppp p ppp mf', start_dynamic_tokens='niente', stop_dynamic_tokens='niente', ), stem_tremolo_spanner=consort.AttachmentExpression( attachments=spannertools.StemTremoloSpanner(), selector=selectortools.select_pitched_runs(), ), ), color='red', labels=[], minimum_phrase_duration=(3, 2), pitch_handler=consort.AbsolutePitchHandler( pitch_application_rate='phrase', pitch_specifier=pitchtools.PitchSegment([ ersilia.Percussion.BASS_DRUM, ersilia.Percussion.TAM_TAM, ]), pitches_are_nonsemantic=True, ), rhythm_maker=rhythmmakertools.EvenDivisionRhythmMaker( denominators=[8], division_masks=[ rhythmmakertools.SustainMask(pattern=patterntools.Pattern( indices=[0, 1], period=3, ), ), rhythmmakertools.SustainMask(pattern=patterntools.Pattern( indices=[0, -1], ), ), ], tie_specifier=rhythmmakertools.TieSpecifier( tie_across_divisions=True, ),
def __call__(self, expr): r'''Calls rotation on `expr`. .. container:: example **Example 1.** Rotates pitch classes with transposition. :: >>> operator_ = pitchtools.Rotation(index=1) >>> pitch_classes = pitchtools.PitchClassSegment([0, 1, 4, 7]) >>> operator_(pitch_classes) PitchClassSegment([0, 5, 6, 9]) .. container:: example **Example 2.** Rotates pitch classes without transposition. :: >>> operator_ = pitchtools.Rotation(index=1, transpose=False) >>> pitch_classes = pitchtools.PitchClassSegment([0, 1, 4, 7]) >>> operator_(pitch_classes) PitchClassSegment([7, 0, 1, 4]) .. container:: example **Example 3.** Does not rotate single pitches or pitch-classes. :: >>> operator_ = pitchtools.Rotation(index=1) >>> pitch_class = pitchtools.NumberedPitchClass(6) >>> operator_(pitch_class) NumberedPitchClass(6) .. container:: example **Example 4.** Periodic rotation without transposition. :: >>> operator_ = pitchtools.Rotation( ... index=1, ... period=3, ... transpose=False, ... ) >>> pitches = pitchtools.PitchSegment("c' d' e' f' g' a' b' c''") >>> operator_(pitches) PitchSegment(["e'", "c'", "d'", "a'", "f'", "g'", "c''", "b'"]) .. container:: example **Example 5.** Periodic rotation with transposition. :: >>> operator_ = pitchtools.Rotation( ... index=1, ... period=3, ... ) >>> pitches = pitchtools.PitchSegment("c' d' e' f' g' a' b' c''") >>> operator_(pitches) PitchSegment(["c'", 'af', 'bf', "f'", "df'", "ef'", "b'", "as'"]) Returns new object with type equal to that of `expr`. ''' from abjad.tools import pitchtools if isinstance(expr, (pitchtools.Pitch, pitchtools.PitchClass)): return expr if not isinstance(expr, ( pitchtools.PitchSegment, pitchtools.PitchClassSegment, )): expr = pitchtools.PitchSegment(expr) if not self.period: return expr.rotate(self.index, transpose=self.transpose) result = new(expr, items=()) for shard in sequencetools.partition_sequence_by_counts( expr, [self.period], cyclic=True, overhang=True, ): shard = type(expr)(shard) shard = shard.rotate(self.index, transpose=self.transpose) result = result + shard return result