def split_at_offset(self, offset): from abjad.tools import timespantools offset = durationtools.Offset(offset) result = timespantools.TimespanInventory() if self._start_offset < offset < self._stop_offset: left_divisions, right_divisions = None, None if self.divisions is not None: left_divisions, right_divisions = sequencetools.split_sequence( self.divisions, [offset - self.start_offset], overhang=True, ) left = new( self, start_offset=self._start_offset, stop_offset=offset, divisions=left_divisions, ) right = new( self, start_offset=offset, stop_offset=self._stop_offset, divisions=right_divisions, ) if left.duration: result.append(left) if right.duration: result.append(right) else: result.append(new(self)) return result
def split_at_offset(self, offset): offset = abjad.Offset(offset) result = abjad.TimespanList() if self._start_offset < offset < self._stop_offset: left_divisions, right_divisions = None, None if self.divisions is not None: left_divisions, right_divisions = abjad.split_sequence( self.divisions, [offset - self.start_offset], overhang=True, ) left = abjad.new( self, start_offset=self._start_offset, stop_offset=offset, divisions=left_divisions, ) right = abjad.new( self, start_offset=offset, stop_offset=self._stop_offset, divisions=right_divisions, ) if left.duration: result.append(left) if right.duration: result.append(right) else: result.append(abjad.new(self)) return result
def _get_lilypond_format(self, context=None): import abjad result = [] if self.hide: return result markup = self.markup if markup.direction is not None: markup = abjad.new( markup, direction=None, ) if isinstance(context, str): pass elif context is not None: context = context.lilypond_type else: context = self._lilypond_type pieces = markup._get_format_pieces() first_line = r'\set {!s}.instrumentName = {!s}' first_line = first_line.format(context, pieces[0]) result.append(first_line) result.extend(pieces[1:]) short_markup = self.short_markup if short_markup.direction is not None: short_markup = abjad.new( short_markup, direction=None, ) pieces = short_markup._get_format_pieces() first_line = r'\set {!s}.shortInstrumentName = {!s}' first_line = first_line.format(context, pieces[0]) result.append(first_line) result.extend(pieces[1:]) return result
def new( self, first=None, last=None, only=None, default=None, **kwargs ): first = first or self.first last = last or self.last only = only or self.only default = default or self.default if first is not None: first = new(first, **kwargs) if last is not None: last = new(last, **kwargs) if only is not None: only = new(only, **kwargs) if default is not None: default = new(default, **kwargs) result = new( self, first=first, last=last, only=only, default=default, ) return result
def _iterate(self, state=None): queue = state[0] # get first event previous_offset, previous_event, next_event = 0.0, None, None while not previous_event and not queue.empty(): (_, index), iterator = queue.get() try: previous_event = next(iterator) previous_event = new(previous_event, _iterator=iterator) except StopIteration: continue queue.put(((previous_event.delta, index), iterator)) break while not queue.empty(): (next_offset, index), iterator = queue.get() try: next_event = next(iterator) next_event = new(next_event, _iterator=iterator) except StopIteration: continue queue.put(((next_offset + next_event.delta, index), iterator)) delta = next_offset - previous_offset previous_event = new(previous_event, delta=delta) yield previous_event previous_event = next_event previous_offset = next_offset next_event = None if not next_event: yield previous_event
def _apply_division_masks(self, selections): import abjad from abjad.tools import rhythmmakertools if not self.division_masks: return selections new_selections = [] duration_specifier = self._get_duration_specifier() decrease_monotonic = duration_specifier.decrease_monotonic forbidden_duration = duration_specifier.forbidden_duration tie_specifier = self._get_tie_specifier() total_divisions = len(selections) division_masks = self.division_masks leaf_maker = abjad.LeafMaker( decrease_monotonic=decrease_monotonic, forbidden_duration=forbidden_duration, repeat_ties=tie_specifier.repeat_ties, ) previous_divisions_consumed = self._previous_divisions_consumed() for i, selection in enumerate(selections): matching_division_mask = division_masks.get_matching_pattern( i + previous_divisions_consumed, total_divisions + previous_divisions_consumed, rotation=self.previous_state.get('rotation'), ) if not matching_division_mask: new_selections.append(selection) continue duration = abjad.inspect(selection).get_duration() if isinstance( matching_division_mask, rhythmmakertools.SustainMask, ): leaf_maker = abjad.new( leaf_maker, use_multimeasure_rests=False, ) new_selection = leaf_maker([0], [duration]) else: use_multimeasure_rests = getattr( matching_division_mask, 'use_multimeasure_rests', False, ) leaf_maker = abjad.new( leaf_maker, use_multimeasure_rests=use_multimeasure_rests, ) new_selection = leaf_maker([None], [duration]) for component in abjad.iterate(selection).components(): abjad.detach(abjad.Tie, component) new_selections.append(new_selection) return new_selections
def __add__(self, argument): """ Adds typed tuple to ``argument``. Returns new typed tuple. """ import abjad if isinstance(argument, type(self)): items = argument._collection return abjad.new(self, items=self._collection[:] + items) elif isinstance(argument, type(self._collection)): items = argument[:] return abjad.new(self, items=self._collection[:] + items) raise NotImplementedError
def rotate(self, n=0): counts = self.counts if counts is not None: counts = counts.rotate(n) return new(self, counts=counts, )
def _coerce_iterator_output(self, expr, state=None): from supriya.tools import patterntools if not isinstance(expr, patterntools.Event): expr = patterntools.NoteEvent(**expr) if not expr.get('uuid'): expr = new(expr, uuid=uuid.uuid4()) return expr
def reverse(self): counts = self.counts if counts is not None: counts = counts.reverse() return new(self, counts=counts, )
def __call__(self, expr): r'''Calls specifier on `expr`. Returns none. ''' if self.dynamic is None: return #print(expr) selector = self._get_selector() #print(selector) selections = selector(expr) #print(selections) for selection in selections: if isinstance(self.dynamic, abjad.spannertools.Hairpin): hairpin = abjad.new(self.dynamic) leaves = list(abjad.iterate(selection).by_leaf()) if hairpin._attachment_test_all(leaves): abjad.attach(hairpin, leaves) elif isinstance(self.dynamic, (str, abjad.indicatortools.Dynamic)): dynamic = abjad.indicatortools.Dynamic(self.dynamic) abjad.attach(dynamic, selection[0]) else: message = 'invalid dynamic: {!r}.' message = message.format(self.dynamic) raise Exception(message)
def transpose(self, expr): import consort pitch_specifier = self.pitch_specifier or consort.PitchSpecifier( pitch_segments='C4', ) pitch_specifier = pitch_specifier.transpose(expr) return abjad.new(self, pitch_specifier=pitch_specifier)
def resolve_target_timespans( self, segment_timespan, timespan_quantization=None, ): import consort assert isinstance(segment_timespan, timespantools.Timespan) timespan_identifier = self.timespan_identifier if timespan_identifier is None: target_timespans = timespantools.TimespanInventory([ segment_timespan, ]) elif isinstance(self.timespan_identifier, timespantools.Timespan): if timespan_identifier.stop_offset == Infinity: timespan_identifier = new( timespan_identifier, stop_offset=segment_timespan.stop_offset, ) segment_timespan = timespantools.Timespan(start_offset=0) target_timespans = segment_timespan & timespan_identifier else: if isinstance(timespan_identifier, consort.RatioPartsExpression): mask_timespans = timespan_identifier(segment_timespan) else: mask_timespans = timespan_identifier target_timespans = timespantools.TimespanInventory() for mask_timespan in mask_timespans: available_timespans = segment_timespan & mask_timespan target_timespans.extend(available_timespans) if timespan_quantization is not None: target_timespans.round_offsets( timespan_quantization, must_be_well_formed=True, ) return target_timespans
def align(self): r"""Aligns all inflections to a minimum interval of zero. :: >>> import consort >>> inflection = consort.RegisterInflection.zigzag().align() >>> print(format(inflection)) consort.tools.RegisterInflection( inflections=pitchtools.IntervalSegment( ( pitchtools.NumberedInterval(0), pitchtools.NumberedInterval(9), pitchtools.NumberedInterval(3), pitchtools.NumberedInterval(12), ), item_class=pitchtools.NumberedInterval, ), ratio=mathtools.Ratio((1, 1, 1)), ) Emits new register inflection. """ minimum = sorted(self.inflections, key=lambda x: x.semitones)[0] inflections = (_ - minimum for _ in self.inflections) return new(self, inflections=inflections)
def rotate(self, n=1): r"""Rotates register inflection by `n`. :: >>> import consort >>> inflection = consort.RegisterInflection.zigzag().rotate(1) >>> print(format(inflection)) consort.tools.RegisterInflection( inflections=pitchtools.IntervalSegment( ( pitchtools.NumberedInterval(6), pitchtools.NumberedInterval(-6), pitchtools.NumberedInterval(3), pitchtools.NumberedInterval(-3), ), item_class=pitchtools.NumberedInterval, ), ratio=mathtools.Ratio((1, 1, 1)), ) Emits new register inflection. """ return new( self, inflections=sequencetools.rotate_sequence(self.inflections, n), ratio=sequencetools.rotate_sequence(self.ratio, n), )
def test_new_02(): old_aggregate = Aggregate( pitch_segment=abjad.PitchSegment("c d e f"), ratio=abjad.Ratio([1, 2, 3]), ) assert format(old_aggregate) == abjad.String.normalize( r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((1, 2, 3)), ) """ ) new_aggregate = abjad.new(old_aggregate, ratio=(4, 5)) assert new_aggregate is not old_aggregate assert new_aggregate != old_aggregate assert format(old_aggregate) == abjad.String.normalize( r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((1, 2, 3)), ) """ ) assert format(new_aggregate) == abjad.String.normalize( r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((4, 5)), ) """ )
def reverse(self): r'''Reverses register inflection. :: >>> inflection = consort.RegisterInflection.zigzag().reverse() >>> print(format(inflection)) consort.tools.RegisterInflection( inflections=abjad.IntervalSegment( ( abjad.NumberedInterval(6), abjad.NumberedInterval(-3), abjad.NumberedInterval(3), abjad.NumberedInterval(-6), ), item_class=abjad.NumberedInterval, ), ratio=abjad.Ratio((1, 1, 1)), ) Emits new register inflection. ''' return abjad.new( self, inflections=reversed(self.inflections), ratio=reversed(self.ratio), )
def rotate(self, n=1): r'''Rotates register inflection by `n`. :: >>> inflection = consort.RegisterInflection.zigzag().rotate(1) >>> print(format(inflection)) consort.tools.RegisterInflection( inflections=abjad.IntervalSegment( ( abjad.NumberedInterval(6), abjad.NumberedInterval(-6), abjad.NumberedInterval(3), abjad.NumberedInterval(-3), ), item_class=abjad.NumberedInterval, ), ratio=abjad.Ratio((1, 1, 1)), ) Emits new register inflection. ''' import consort return abjad.new( self, inflections=consort.rotate(self.inflections, n), ratio=consort.rotate(self.ratio, n), )
def transpose(self, expr): r""" Transposes music specifier. .. container:: example >>> music_specifier = tsmakers.MusicSpecifier() >>> transposed_music_specifier = music_specifier.transpose('-M2') >>> print(abjad.storage(transposed_music_specifier)) tsmakers.MusicSpecifier() Returns new music specifier. """ if isinstance(expr, str): try: pitch = abjad.NamedPitch(expr) expr = abjad.NamedPitch("C4") - pitch except Exception: expr = abjad.NamedInterval(expr) pitch_handler = self.pitch_handler if pitch_handler is not None: pitch_handler = pitch_handler.transpose(expr) return abjad.new( self, pitch_handler=pitch_handler, )
def transpose(self, n=0): r'''Transposes all pitch-classes in pitch-class set by index `n`. .. container:: example >>> set_ = abjad.PitchClassSet( ... items=[-2, -1.5, 6, 7, -1.5, 7], ... item_class=abjad.NumberedPitchClass, ... ) >>> for n in range(12): ... print(n, set_.transpose(n)) ... 0 PC{6, 7, 10, 10.5} 1 PC{7, 8, 11, 11.5} 2 PC{0, 0.5, 8, 9} 3 PC{1, 1.5, 9, 10} 4 PC{2, 2.5, 10, 11} 5 PC{0, 3, 3.5, 11} 6 PC{0, 1, 4, 4.5} 7 PC{1, 2, 5, 5.5} 8 PC{2, 3, 6, 6.5} 9 PC{3, 4, 7, 7.5} 10 PC{4, 5, 8, 8.5} 11 PC{5, 6, 9, 9.5} Returns new pitch-class set. ''' import abjad items = (pitch_class + n for pitch_class in self) return abjad.new(self, items=items)
def __copy__(self, *arguments): r'''Copies Abjad value object. Returns new Abjad value object. ''' import abjad return abjad.new(self)
def transpose(self, n=0): """ Transposes all pitch-classes in pitch-class set by index `n`. .. container:: example >>> set_ = abjad.PitchClassSet( ... items=[-2, -1.5, 6, 7, -1.5, 7], ... item_class=abjad.NumberedPitchClass, ... ) >>> for n in range(12): ... print(n, set_.transpose(n)) ... 0 PC{6, 7, 10, 10.5} 1 PC{7, 8, 11, 11.5} 2 PC{0, 0.5, 8, 9} 3 PC{1, 1.5, 9, 10} 4 PC{2, 2.5, 10, 11} 5 PC{0, 3, 3.5, 11} 6 PC{0, 1, 4, 4.5} 7 PC{1, 2, 5, 5.5} 8 PC{2, 3, 6, 6.5} 9 PC{3, 4, 7, 7.5} 10 PC{4, 5, 8, 8.5} 11 PC{5, 6, 9, 9.5} Returns new pitch-class set. """ import abjad items = (pitch_class + n for pitch_class in self) return abjad.new(self, items=items)
def __copy__(self, *arguments): """ Copies Abjad value object. Returns new Abjad value object. """ import abjad return abjad.new(self)
def transpose(self, n=0): r'''Transposes pitch set by index `n`. Returns new pitch set. ''' import abjad items = (pitch.transpose(n=n) for pitch in self) return abjad.new(self, items=items)
def invert(self, axis): r'''Inverts pitch set about `axis`. Returns new pitch set. ''' import abjad items = (pitch.invert(axis) for pitch in self) return abjad.new(self, items=items)
def make_final_markup(): place_markup = abjad.Markup('Austin, TX') date_markup = abjad.Markup('Feb. 2006') final_markup = abjad.Markup.right_column([place_markup, date_markup]) final_markup = final_markup.italic() final_markup = final_markup.with_color('black') final_markup = abjad.new(final_markup, direction=Down) return final_markup
def _get_lilypond_format_bundle(self, component=None): import abjad bundle = abjad.LilyPondFormatBundle() markup = self._get_markup() markup = abjad.new(markup, direction=abjad.Up) markup_format_pieces = markup._get_format_pieces() bundle.right.markup.extend(markup_format_pieces) return bundle
def rotate(self, rotation): r'''Rotates pitch specifier. :: >>> pitch_specifier = consort.PitchSpecifier( ... pitch_segments=( ... "c' e' g'", ... "fs' gs'", ... "b", ... ), ... ratio=(1, 2, 3), ... ) >>> rotated_pitch_specifier = pitch_specifier.rotate(1) >>> print(format(rotated_pitch_specifier)) consort.tools.PitchSpecifier( pitch_segments=( abjad.PitchSegment( ( abjad.NamedPitch('b'), ), item_class=abjad.NamedPitch, ), abjad.PitchSegment( ( abjad.NamedPitch("c'"), abjad.NamedPitch('f'), abjad.NamedPitch('a'), ), item_class=abjad.NamedPitch, ), abjad.PitchSegment( ( abjad.NamedPitch("fs'"), abjad.NamedPitch("e'"), ), item_class=abjad.NamedPitch, ), ), ratio=abjad.Ratio((3, 1, 2)), ) Returns new pitch specifier. ''' import consort rotation = int(rotation) pitch_segments = tuple( _.rotate(rotation, stravinsky=True) for _ in self.pitch_segments ) pitch_segments = consort.rotate(pitch_segments, rotation) ratio = consort.rotate(self.ratio, rotation) return abjad.new( self, pitch_segments=pitch_segments, ratio=ratio, )
def __mul__(self, argument): """ Multiplies typed tuple by ``argument``. Returns new typed tuple. """ import abjad items = self._collection * argument return abjad.new(self, items=items)
def test_AbsolutePitchHandler_01(): pitch_handler = consort.AbsolutePitchHandler() segment_maker = consort.SegmentMaker( discard_final_silence=True, desired_duration_in_seconds=1, omit_stylesheets=True, score_template=templatetools.GroupedStavesScoreTemplate( staff_count=1, ), settings=consort.MusicSetting( timespan_maker=consort.FloodedTimespanMaker(), v1=abjad.new(music_specifier, pitch_handler=pitch_handler), ), tempo=abjad.MetronomeMark((1, 4), 60), permitted_time_signatures=((1, 4),), ) lilypond_file, metadata = segment_maker(segment_metadata=segment_metadata) assert format(lilypond_file) == abjad.String.normalize( r''' \version "2.19.65" \language "english" #(ly:set-option 'relative-includes #t) \score { \context Score = "Grouped Staves Score" << \tag #'time \context TimeSignatureContext = "Time Signature Context" { { \tempo 4=60 \time 1/4 s1 * 1/4 } } \context StaffGroup = "Grouped Staves Staff Group" << \context Staff = "Staff 1" { \context Voice = "Voice 1" { { % [Voice 1] Measure 1 { c'16 [ \set stemLeftBeamCount = 2 \set stemRightBeamCount = 2 c'16 \set stemLeftBeamCount = 2 \set stemRightBeamCount = 2 c'16 \set stemLeftBeamCount = 2 c'16 ] } } } } >> >> } ''')
def rotate(self, rotation): r'''Rotates pitch specifier. :: >>> pitch_specifier = consort.PitchSpecifier( ... pitch_segments=( ... "c' e' g'", ... "fs' gs'", ... "b", ... ), ... ratio=(1, 2, 3), ... ) >>> rotated_pitch_specifier = pitch_specifier.rotate(1) >>> print(format(rotated_pitch_specifier)) consort.tools.PitchSpecifier( pitch_segments=( pitchtools.PitchSegment( ( pitchtools.NamedPitch('b'), ), item_class=pitchtools.NamedPitch, ), pitchtools.PitchSegment( ( pitchtools.NamedPitch("c'"), pitchtools.NamedPitch('f'), pitchtools.NamedPitch('a'), ), item_class=pitchtools.NamedPitch, ), pitchtools.PitchSegment( ( pitchtools.NamedPitch("fs'"), pitchtools.NamedPitch("e'"), ), item_class=pitchtools.NamedPitch, ), ), ratio=mathtools.Ratio((3, 1, 2)), ) Returns new pitch specifier. ''' rotation = int(rotation) pitch_segments = tuple( _.rotate(rotation, transpose=True) for _ in self.pitch_segments ) pitch_segments = sequencetools.rotate_sequence( pitch_segments, rotation) ratio = sequencetools.rotate_sequence(self.ratio, rotation) return new( self, pitch_segments=pitch_segments, ratio=ratio, )
def test_AbsolutePitchHandler_02(): pitch_handler = consort.AbsolutePitchHandler( pitch_specifier=consort.PitchSpecifier(pitch_segments=("c' e' g'",), ratio=(1,)) ) segment_maker = consort.SegmentMaker( discard_final_silence=True, desired_duration_in_seconds=1, omit_stylesheets=True, score_template=templatetools.GroupedStavesScoreTemplate(staff_count=1), settings=consort.MusicSetting( timespan_maker=consort.FloodedTimespanMaker(), v1=new(music_specifier, pitch_handler=pitch_handler) ), tempo=indicatortools.Tempo((1, 4), 60), permitted_time_signatures=((1, 4),), ) lilypond_file, metadata = segment_maker(segment_metadata=segment_metadata) assert format(lilypond_file) == systemtools.TestManager.clean_string( r""" \version "2.19.44" \language "english" #(ly:set-option 'relative-includes #t) \score { \context Score = "Grouped Staves Score" << \tag #'time \context TimeSignatureContext = "Time Signature Context" { { \tempo 4=60 \time 1/4 s1 * 1/4 } } \context StaffGroup = "Grouped Staves Staff Group" << \context Staff = "Staff 1" { \context Voice = "Voice 1" { { % [Voice 1] Measure 1 { c'16 [ \set stemLeftBeamCount = 2 \set stemRightBeamCount = 2 e'16 \set stemLeftBeamCount = 2 \set stemRightBeamCount = 2 g'16 \set stemLeftBeamCount = 2 c'16 ] } } } } >> >> } """ )
def test_new_03(): old_aggregate = Aggregate(pitch_segment=abjad.PitchSegment("c d e f")) assert format(old_aggregate) == abjad.String.normalize( r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ) """ ) new_aggregate = abjad.new( old_aggregate, pitch_segment="af bf df", ratio=(5, 4) ) assert new_aggregate is not old_aggregate assert new_aggregate != old_aggregate assert format(old_aggregate) == abjad.String.normalize( r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ) """ ) assert format(new_aggregate) == abjad.String.normalize( r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('af'), abjad.NamedPitch('bf'), abjad.NamedPitch('df'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((5, 4)), ) """ )
def add_rhythms(self, score, rhythm_maker, durations): selection = abjad.select(score).components(abjad.Voice) counts = list(rhythm_maker.talea.counts) for voice in selection: print(counts) rhythm_maker = abjad.new(rhythm_maker, talea__counts=counts) rhythm = rhythm_maker(durations) voice.extend(rhythm) counts = counts[1:] + [counts[0]] return score
def add_rhythms(score, rhythm_maker, durations): selection = abjad.select(score).components(abjad.Voice) counts = list(rhythm_maker.talea.counts) for voice in selection: print(counts) rhythm_maker = abjad.new(rhythm_maker, talea__counts=counts) rhythm = rhythm_maker(durations) voice.extend(rhythm) counts = counts[1:] + [counts[0]] return score
def _iterate(self, state=None): if self.key: for _ in self._loop(self._repetitions): for i, x in enumerate(self._pattern): if i == 0: x = new(x, **{self.key: True}) yield x else: for _ in self._loop(self._repetitions): yield from self._pattern
def test_new_02(): old_aggregate = Aggregate(pitch_segment=abjad.PitchSegment('c d e f'), ratio=abjad.Ratio([1, 2, 3])) assert format(old_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((1, 2, 3)), ) """) new_aggregate = abjad.new( old_aggregate, ratio=(4, 5), ) assert new_aggregate is not old_aggregate assert new_aggregate != old_aggregate assert format(old_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((1, 2, 3)), ) """) assert format(new_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((4, 5)), ) """)
def __call__(self, argument): """ Calls retrograde on `argument`. .. container:: example Gets retrograde pitch classes: >>> retrograde = abjad.Retrograde() >>> segment = abjad.PitchClassSegment([0, 1, 4, 7]) >>> retrograde(segment) PitchClassSegment([7, 4, 1, 0]) .. container:: example Does not retrograde single pitches or pitch-classes: >>> retrogresion = abjad.Retrograde() >>> pitch_class = abjad.NumberedPitchClass(6) >>> retrograde(pitch_class) NumberedPitchClass(6) .. container:: example Periodic retrograde: .. todo:: Deprecated. >>> retrograde = abjad.Retrograde(period=3) >>> segment = abjad.PitchSegment("c' d' e' f' g' a' b' c''") >>> retrograde(segment) PitchSegment("e' d' c' a' g' f' c'' b'") Returns new object with type equal to that of `argument`. """ import abjad if isinstance(argument, (abjad.Pitch, abjad.PitchClass)): return argument if not isinstance(argument, ( abjad.PitchSegment, abjad.PitchClassSegment, )): argument = abjad.PitchSegment(argument) if not self.period: return type(argument)(reversed(argument)) result = abjad.new(argument, items=()) for shard in abjad.sequence(argument).partition_by_counts( [self.period], cyclic=True, overhang=True, ): shard = type(argument)(shard) shard = type(argument)(reversed(shard)) result = result + shard return result
def pitch_class_segment(self, **keywords) -> "Expression": r""" Makes pitch-class segment subclass expression. .. container:: example Makes expression to apply alpha transform to pitch-class segment: >>> mccartney.PitchClassSegment([-2, -1.5, 6, 7, -1.5, 7]) PitchClassSegment([10, 10.5, 6, 7, 10.5, 7]) >>> segment = mccartney.PitchClassSegment([-2, -1.5, 6, 7, -1.5, 7]) >>> abjad.show(segment, strict=89) # doctest: +SKIP .. container:: example expression >>> expression = mccartney.Expression(name='J') >>> expression = expression.pitch_class_segment() >>> expression = expression.alpha() >>> expression([-2, -1.5, 6, 7, -1.5, 7]) PitchClassSegment([11, 11.5, 7, 6, 11.5, 6]) >>> segment = expression([-2, -1.5, 6, 7, -1.5, 7]) >>> markup = expression.get_markup() >>> abjad.show(segment, figure_name=markup) # doctest: +SKIP .. docs:: >>> lilypond_file = segment.__illustrate__( ... figure_name=markup, ... ) >>> abjad.f(lilypond_file[abjad.Staff]) \new Staff { \new Voice { b'8 ^ \markup { \concat { A \bold J } } bqs'8 g'8 fs'8 bqs'8 fs'8 \bar "|." %! SCORE_1 \override Score.BarLine.transparent = ##f } } """ from .pitchclasses import PitchClassSegment class_ = PitchClassSegment callback = self._make_initializer_callback(class_, module_names=["mccartney"], string_template="{}", **keywords) expression = self.append_callback(callback) return abjad.new(expression, proxy_class=class_)
def _get_lilypond_format_bundle(self, component=None): bundle = abjad.LilyPondFormatBundle() if not self.hide: if self.tweaks: tweaks = self.tweaks._list_format_contributions() bundle.after.markup.extend(tweaks) markup = self._get_markup() markup = abjad.new(markup, direction=abjad.Up) markup_format_pieces = markup._get_format_pieces() bundle.after.markup.extend(markup_format_pieces) return bundle
def test_new_01(): old_aggregate = Aggregate( pitch_segment=abjad.PitchSegment("c d e f"), ratio=abjad.Ratio([1, 2, 3]), ) assert abjad.storage(old_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((1, 2, 3)), ) """) new_aggregate = abjad.new(old_aggregate) assert new_aggregate is not old_aggregate assert new_aggregate == old_aggregate assert abjad.storage(old_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((1, 2, 3)), ) """) assert abjad.storage(new_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((1, 2, 3)), ) """)
def _is_equivalent_under_transposition(self, argument): import abjad if not isinstance(argument, type(self)): return False if not len(self) == len(argument): return False difference = -(abjad.NamedPitch(argument[0], 4) - abjad.NamedPitch(self[0], 4)) new_pitches = (x + difference for x in self) new_pitches = abjad.new(self, items=new_pitches) return argument == new_pitches
def _coerce_iterator_output(self, expr, state): from supriya.tools import patterntools expr = super(Pbus, self)._coerce_iterator_output(expr) kwargs = {} if expr.get('target_node') is None: kwargs['target_node'] = state['group_uuid'] if (isinstance(expr, patterntools.NoteEvent) and expr.get('out') is None): kwargs['out'] = state['bus_uuid'] expr = new(expr, **kwargs) return expr
def make_final_markup(): r'''Makes final markup. Returns markup. ''' place_markup = abjad.Markup('Cambridge, MA – Madison, WI – Palo Alto, CA.') date_markup = abjad.Markup('Nov. 2015 – Jul. 2016.') final_markup = abjad.Markup.right_column([place_markup, date_markup]) final_markup = final_markup.italic() final_markup = final_markup.with_color('black') final_markup = abjad.new(final_markup, direction=Down) return final_markup
def test_new_03(): old_aggregate = Aggregate(pitch_segment=abjad.PitchSegment('c d e f'), ) assert format(old_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ) """) new_aggregate = abjad.new( old_aggregate, pitch_segment='af bf df', ratio=(5, 4), ) assert new_aggregate is not old_aggregate assert new_aggregate != old_aggregate assert format(old_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ) """) assert format(new_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('af'), abjad.NamedPitch('bf'), abjad.NamedPitch('df'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((5, 4)), ) """)
def __init__(self, commands: typing.Sequence["CommandTyping"] = None, **keywords) -> None: commands_: typing.List[CommandTyping] = [] for command in commands or []: if isinstance(command, (Command, Suite)): command_ = abjad.new(command, **keywords) commands_.append(command_) continue message = "\n Must contain only commands, maps, suites." message += f"\n Not {type(command).__name__}: {command!r}." raise Exception(message) self._commands = tuple(commands_)
def sequence(self, **keywords) -> "Expression": """ Makes sequence expression. """ name = keywords.pop("name", None) expression = Expression(name=name) callback = expression._make_initializer_callback( Sequence, module_names=["mccartney"], string_template="{}", **keywords) expression_ = expression.append_callback(callback) return abjad.new(expression_, proxy_class=Sequence)
def test_new_05(): old_aggregate = Aggregate(pitch_segment=abjad.PitchSegment("c d e f")) assert abjad.storage(old_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ) """) new_aggregate = abjad.new(old_aggregate, ratio=[4, 5], pitch_segment__rotate=2) assert new_aggregate is not old_aggregate assert new_aggregate != old_aggregate assert abjad.storage(old_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('c'), abjad.NamedPitch('d'), abjad.NamedPitch('e'), abjad.NamedPitch('f'), ), item_class=abjad.NamedPitch, ), ) """) assert abjad.storage(new_aggregate) == abjad.String.normalize(r""" test_new.Aggregate( pitch_segment=abjad.PitchSegment( ( abjad.NamedPitch('e'), abjad.NamedPitch('f'), abjad.NamedPitch('c'), abjad.NamedPitch('d'), ), item_class=abjad.NamedPitch, ), ratio=abjad.Ratio((4, 5)), ) """)
def _handle_last(self, expr, state): from supriya.tools import patterntools _, group_uuids, _ = state delta = expr.delta delta += (self._release_time or 0) expr = new(expr, delta=delta) events = [] for group_uuid in group_uuids: group_event = patterntools.GroupEvent( uuid=group_uuid, is_stop=True, ) events.append(group_event) return expr, events
def multiply(self, n): r'''Multiplies pitch-class set by `n`. .. container:: example >>> abjad.PitchClassSet( ... [-2, -1.5, 6, 7, -1.5, 7], ... ).multiply(5) PitchClassSet([2, 4.5, 6, 11]) Returns new pitch-class set. ''' import abjad items = (pitch_class.multiply(n) for pitch_class in self) return abjad.new(self, items=items)
def _iterate(self, state=None): event_pattern = iter(self._event_pattern) patterns = self._coerce_pattern_pairs(self._patterns) while True: try: event = next(event_pattern) except StopIteration: return template_dict = {} for name, pattern in patterns.items(): try: template_dict[name] = next(pattern) except StopIteration: return yield new(event, **template_dict)
def __call__(self, execution_time, scheduled_time, communicate=True): if self._iterator is None: self._iterator = self._iterate_outer( pattern=self._pattern, server=self._server, timestamp=scheduled_time, uuids=self._uuids, ) event_products, delta = next(self._iterator) node_free_ids, requests = set(), [] for event_product in event_products: if not event_product.event: continue for request in event_product.requests: if isinstance(request, requesttools.NodeFreeRequest): node_free_ids.update(request.node_ids) else: requests.append(request) if event_product.is_stop: proxies = self._uuids[event_product.uuid] for proxy_id, proxy in proxies.items(): if isinstance(proxy, ( servertools.Bus, servertools.BusGroup, )): allocator = servertools.Bus._get_allocator( calculation_rate=proxy.calculation_rate, server=self._server, ) allocator.free(proxy_id) self._uuids.pop(event_product.uuid) if node_free_ids: node_free_ids = sorted(node_free_ids) request = requesttools.NodeFreeRequest(node_ids=node_free_ids) requests.append(request) consolidated_bundle = requesttools.RequestBundle( timestamp=scheduled_time, contents=requests, ) if communicate: osc_bundle = consolidated_bundle.to_osc_bundle() osc_bundle = new( osc_bundle, timestamp=osc_bundle.timestamp + self._server.latency, ) self._server.send_message(osc_bundle) return delta return consolidated_bundle, delta
def _is_equivalent_under_transposition(self, argument): r'''True if pitch set is equivalent to `argument` under transposition. Otherwise false. Returns true or false. ''' import abjad if not isinstance(argument, type(self)): return False if not len(self) == len(argument): return False difference = -(abjad.NamedPitch(argument[0], 4) - abjad.NamedPitch(self[0], 4)) new_pitches = (x + difference for x in self) new_pitches = abjad.new(self, items=new_pitches) return argument == new_pitches