def order_by(self, pitch_class_segment): r'''Orders pitch-class set by `pitch_class_segment`. Returns pitch-class segment. ''' from abjad.tools import pitchtools from abjad.tools import sequencetools if not len(self) == len(pitch_class_segment): message = 'set and segment must be on equal length.' raise ValueError(message) for pitch_classes in sequencetools.yield_all_permutations_of_sequence( tuple(self)): candidate_pitch_class_segment = \ pitchtools.PitchClassSegment(pitch_classes) if candidate_pitch_class_segment.is_equivalent_under_transposition( pitch_class_segment): return candidate_pitch_class_segment message = 'named pitch-class set {} can not order by ' message += 'named pitch-class segment {}.' message = message.format(self, pitch_class_segment) raise ValueError(message)
def voice_pitch_classes( self, pitch_classes, allow_open_strings=True, ): r"""Voices `pitch_classes`. .. container:: example **Example 1.** :: >>> tuning = indicatortools.Tuning(('G3', 'D4', 'A4', 'E5')) >>> voicings = tuning.voice_pitch_classes(('a',)) >>> for voicing in voicings: ... voicing ... (NamedPitch('a'), None, None, None) (NamedPitch("a'"), None, None, None) (None, NamedPitch("a'"), None, None) (None, NamedPitch("a''"), None, None) (None, None, NamedPitch("a'"), None) (None, None, NamedPitch("a''"), None) (None, None, NamedPitch("a'''"), None) (None, None, None, NamedPitch("a''")) (None, None, None, NamedPitch("a'''")) :: >>> voicings = tuning.voice_pitch_classes( ... ('a', 'd'), ... allow_open_strings=False, ... ) >>> for voicing in voicings: ... voicing ... (NamedPitch('a'), NamedPitch("d''"), None, None) (NamedPitch('a'), NamedPitch("d'''"), None, None) (NamedPitch('a'), None, NamedPitch("d''"), None) (NamedPitch('a'), None, NamedPitch("d'''"), None) (NamedPitch('a'), None, None, NamedPitch("d'''")) (NamedPitch('a'), None, None, NamedPitch("d''''")) (NamedPitch("d'"), NamedPitch("a'"), None, None) (NamedPitch("d'"), NamedPitch("a''"), None, None) (NamedPitch("d'"), None, NamedPitch("a''"), None) (NamedPitch("d'"), None, NamedPitch("a'''"), None) (NamedPitch("d'"), None, None, NamedPitch("a''")) (NamedPitch("d'"), None, None, NamedPitch("a'''")) (NamedPitch("a'"), NamedPitch("d''"), None, None) (NamedPitch("a'"), NamedPitch("d'''"), None, None) (NamedPitch("a'"), None, NamedPitch("d''"), None) (NamedPitch("a'"), None, NamedPitch("d'''"), None) (NamedPitch("a'"), None, None, NamedPitch("d'''")) (NamedPitch("a'"), None, None, NamedPitch("d''''")) (NamedPitch("d''"), NamedPitch("a'"), None, None) (NamedPitch("d''"), NamedPitch("a''"), None, None) (NamedPitch("d''"), None, NamedPitch("a''"), None) (NamedPitch("d''"), None, NamedPitch("a'''"), None) (NamedPitch("d''"), None, None, NamedPitch("a''")) (NamedPitch("d''"), None, None, NamedPitch("a'''")) (None, NamedPitch("a'"), NamedPitch("d''"), None) (None, NamedPitch("a'"), NamedPitch("d'''"), None) (None, NamedPitch("a'"), None, NamedPitch("d'''")) (None, NamedPitch("a'"), None, NamedPitch("d''''")) (None, NamedPitch("d''"), NamedPitch("a''"), None) (None, NamedPitch("d''"), NamedPitch("a'''"), None) (None, NamedPitch("d''"), None, NamedPitch("a''")) (None, NamedPitch("d''"), None, NamedPitch("a'''")) (None, NamedPitch("a''"), NamedPitch("d''"), None) (None, NamedPitch("a''"), NamedPitch("d'''"), None) (None, NamedPitch("a''"), None, NamedPitch("d'''")) (None, NamedPitch("a''"), None, NamedPitch("d''''")) (None, NamedPitch("d'''"), NamedPitch("a''"), None) (None, NamedPitch("d'''"), NamedPitch("a'''"), None) (None, NamedPitch("d'''"), None, NamedPitch("a''")) (None, NamedPitch("d'''"), None, NamedPitch("a'''")) (None, None, NamedPitch("d''"), NamedPitch("a''")) (None, None, NamedPitch("d''"), NamedPitch("a'''")) (None, None, NamedPitch("a''"), NamedPitch("d'''")) (None, None, NamedPitch("a''"), NamedPitch("d''''")) (None, None, NamedPitch("d'''"), NamedPitch("a''")) (None, None, NamedPitch("d'''"), NamedPitch("a'''")) (None, None, NamedPitch("a'''"), NamedPitch("d'''")) (None, None, NamedPitch("a'''"), NamedPitch("d''''")) Returns tuple of sequences. """ from abjad.tools import pitchtools pitch_classes = [pitchtools.NamedPitchClass(x) for x in pitch_classes] pitch_classes.extend([None] * (len(self.pitches) - len(pitch_classes))) permutations = set([ tuple(x) for x in sequencetools.yield_all_permutations_of_sequence( pitch_classes) ]) pitch_ranges = self.pitch_ranges result = [] for permutation in permutations: sequences = [] for pitch_range, pitch_class in zip(pitch_ranges, permutation): if pitch_class is None: sequences.append([None]) continue pitches = pitch_range.voice_pitch_class(pitch_class) if not allow_open_strings: pitches = [ pitch for pitch in pitches if pitch != pitch_range.start_pitch ] if not pitches: pitches = [None] sequences.append(pitches) subresult = sequencetools.yield_outer_product_of_sequences( sequences) subresult = [tuple(x) for x in subresult] result.extend(subresult) result.sort() return tuple(result)