예제 #1
0
    def from_selection(
        class_,
        selection,
        item_class=None,
    ):
        """
        Makes interval segment from component `selection`.

        ..  container:: example

            >>> staff = abjad.Staff("c'8 d'8 e'8 f'8 g'8 a'8 b'8 c''8")
            >>> abjad.IntervalSegment.from_selection(
            ...     staff,
            ...     item_class=abjad.NumberedInterval,
            ...     )
            IntervalSegment([2, 2, 1, 2, 2, 2, 1])

        Returns interval segment.
        """
        import abjad
        pitch_segment = abjad.PitchSegment.from_selection(selection)
        pitches = [_ for _ in pitch_segment]
        intervals = (-x for x in mathtools.difference_series(pitches))
        return class_(
            items=intervals,
            item_class=item_class,
        )
 def _make_timespans(
     self,
     layer=None,
     music_specifiers=None,
     target_timespan=None,
     timespan_list=None,
     ):
     new_timespans = abjad.TimespanList()
     if not self.voice_names and not self.labels:
         return new_timespans
     rotation_indices = self.rotation_indices or (0,)
     rotation_indices = abjad.CyclicTuple(rotation_indices)
     context_counter = collections.Counter()
     preexisting_timespans = self._collect_preexisting_timespans(
         target_timespan=target_timespan,
         timespan_list=timespan_list,
         )
     partitioned_timespans = self._partition_preexisting_timespans(
         preexisting_timespans)
     for group_index, group in enumerate(partitioned_timespans):
         rotation_index = rotation_indices[group_index]
         offsets = set()
         offsets.add(group.start_offset)
         offsets.add(group.stop_offset)
         for timespan in group:
             if self.include_inner_starts:
                 offsets.add(timespan.start_offset)
             if self.include_inner_stops:
                 offsets.add(timespan.stop_offset)
         offsets = tuple(sorted(offsets))
         durations = abjad.Sequence(mathtools.difference_series(offsets))
         durations = durations.rotate(rotation_index)
         start_offset = offsets[0]
         for context_name, music_specifier in music_specifiers.items():
             context_seed = context_counter[context_name]
             timespans = music_specifier(
                 durations=durations,
                 layer=layer,
                 division_masks=self.division_masks,
                 padding=self.padding,
                 seed=context_seed,
                 start_offset=start_offset,
                 timespan_specifier=self.timespan_specifier,
                 voice_name=context_name,
                 )
             context_counter[context_name] += 1
             new_timespans.extend(timespans)
     return new_timespans
예제 #3
0
    def from_selection(class_, selection, item_class=None):
        """
        Initializes interval-class segment from component selection.

        ..  container:: example

            >>> staff_1 = abjad.Staff("c'4 <d' fs' a'>4 b2")
            >>> staff_2 = abjad.Staff("c4. r8 g2")
            >>> selection = abjad.select((staff_1, staff_2))
            >>> abjad.IntervalClassSegment.from_selection(selection)
            IntervalClassSegment(['-M2', '-M3', '-m3', '+m7', '+M7', '-P5'])

        Returns interval-class segment.
        """
        import abjad

        pitch_segment = abjad.PitchSegment.from_selection(selection)
        pitches = [_ for _ in pitch_segment]
        intervals = mathtools.difference_series(pitches)
        return class_(items=intervals, item_class=item_class)