def __getitem__(self, argument): r'''Gets item in scale. Returns pitch-class segment. ''' segment = PitchClassSegment(self) return segment.__getitem__(argument)
def __init__(self, items=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)): from abjad.tools import pitchtools assert items is not None PitchClassSegment.__init__( self, items=items, item_class=pitchtools.NumberedPitchClass, ) self._validate_pitch_classes(self)
def __init__(self, tokens=None, name=None): from abjad.tools import pitchtools assert tokens is not None PitchClassSegment.__init__( self, tokens=tokens, item_class=pitchtools.NumberedPitchClass, name=name, ) self._validate_pitch_classes(self)
def __init__( self, items=(0, 1, 11, 9, 3, 6, 7, 5, 4, 10, 2, 8), ): from abjad.tools import pitchtools assert items is not None PitchClassSegment.__init__( self, items=items, item_class=pitchtools.NumberedPitchClass, ) self._validate_pitch_classes(self)
def __init__( self, tokens=(0, 1, 11, 9, 3, 6, 7, 5, 4, 10, 2, 8), custom_identifier=None, ): from abjad.tools import pitchtools assert tokens is not None PitchClassSegment.__init__( self, tokens=tokens, item_class=pitchtools.NumberedPitchClass, custom_identifier=custom_identifier, ) self._validate_pitch_classes(self)
def __getslice__(self, start, stop): r'''Gets items from `start` to `stop` in twelve-tone row. Returns pitch-class segment. ''' from abjad.tools import pitchtools items = self._collection[start:stop] return PitchClassSegment( items=items, item_class=pitchtools.NumberedPitchClass, )
def __init__(self, key_signature=None): import abjad if key_signature is None: key_signature = abjad.KeySignature('c', 'major') elif isinstance(key_signature, tuple): key_signature = abjad.KeySignature(*key_signature) elif isinstance(key_signature, type(self)): key_signature = key_signature.key_signature if not isinstance(key_signature, abjad.KeySignature): raise Exception(key_signature) npcs = [key_signature.tonic] for mdi in key_signature.mode.named_interval_segment[:-1]: named_pitch_class = npcs[-1] + mdi npcs.append(named_pitch_class) PitchClassSegment.__init__( self, items=npcs, item_class=abjad.NamedPitchClass, ) self._key_signature = key_signature
def __init__(self, *args): if len(args) == 0: key_signature = indicatortools.KeySignature('c', 'major') elif len(args) == 1 and isinstance(args[0], indicatortools.KeySignature): key_signature = args[0] elif len(args) == 1 and isinstance(args[0], Scale): key_signature = args[0].key_signature elif len(args) == 2: key_signature = indicatortools.KeySignature(*args) else: raise TypeError npcs = [key_signature.tonic] for mdi in key_signature.mode.named_interval_segment[:-1]: named_pitch_class = npcs[-1] + mdi npcs.append(named_pitch_class) PitchClassSegment.__init__( self, items=npcs, item_class=pitchtools.NamedPitchClass, ) self._key_signature = key_signature
def __init__(self, *args): if len(args) == 0: key_signature = indicatortools.KeySignature('c', 'major') elif len(args) == 1 and isinstance( args[0], indicatortools.KeySignature): key_signature = args[0] elif len(args) == 1 and isinstance(args[0], Scale): key_signature = args[0].key_signature elif len(args) == 2: key_signature = indicatortools.KeySignature(*args) else: raise TypeError npcs = [key_signature.tonic] for mdi in key_signature.mode.named_interval_segment[:-1]: named_pitch_class = npcs[-1] + mdi npcs.append(named_pitch_class) PitchClassSegment.__init__( self, items=npcs, item_class=pitchtools.NamedPitchClass, ) self._key_signature = key_signature
def __rmul__(self, expr): r'''Multiplies `expr` by twelve-tone row. Returns pitch-class segment. ''' return PitchClassSegment(self) * expr
def __rmul__(self, argument): r'''Multiplies `argument` by row. .. container:: example Multiplies integer by row: >>> row = abjad.TwelveToneRow() >>> abjad.show(row) # doctest: +SKIP >>> segment = row * 2 >>> abjad.show(segment) # doctest: +SKIP .. docs:: >>> lilypond_file = segment.__illustrate__() >>> abjad.f(lilypond_file[abjad.Voice]) \new Voice { c'8 cs'8 d'8 ef'8 e'8 f'8 fs'8 g'8 af'8 a'8 bf'8 b'8 c'8 cs'8 d'8 ef'8 e'8 f'8 fs'8 g'8 af'8 a'8 bf'8 b'8 \bar "|." %! SCORE1 \override Score.BarLine.transparent = ##f } .. container:: example Multiplies integer by row: >>> numbers = [1, 11, 9, 3, 6, 7, 5, 4, 10, 2, 8, 0] >>> row = abjad.TwelveToneRow(numbers) >>> abjad.show(row) # doctest: +SKIP >>> segment = row * 2 >>> abjad.show(segment) # doctest: +SKIP .. docs:: >>> lilypond_file = segment.__illustrate__() >>> abjad.f(lilypond_file[abjad.Voice]) \new Voice { cs'8 b'8 a'8 ef'8 fs'8 g'8 f'8 e'8 bf'8 d'8 af'8 c'8 cs'8 b'8 a'8 ef'8 fs'8 g'8 f'8 e'8 bf'8 d'8 af'8 c'8 \bar "|." %! SCORE1 \override Score.BarLine.transparent = ##f } .. container:: example Returns pitch-class segment: >>> segment PitchClassSegment([1, 11, 9, 3, 6, 7, 5, 4, 10, 2, 8, 0, 1, 11, 9, 3, 6, 7, 5, 4, 10, 2, 8, 0]) ''' return PitchClassSegment(self) * argument
def __getitem__(self, argument): r'''Gets item or slice identified by `argument`. .. container:: example Example row: >>> numbers = [1, 11, 9, 3, 6, 7, 5, 4, 10, 2, 8, 0] >>> row = abjad.TwelveToneRow(numbers) >>> abjad.show(row) # doctest: +SKIP .. container:: example Gets first hexachord: >>> abjad.show(row[:6]) # doctest: +SKIP PitchClassSegment([0, 1, 11, 9, 3, 6]) .. docs:: >>> lilypond_file = row[:6].__illustrate__() >>> abjad.f(lilypond_file[abjad.Voice]) \new Voice { cs'8 b'8 a'8 ef'8 fs'8 g'8 \bar "|." %! SCORE1 \override Score.BarLine.transparent = ##f } .. container:: example Gets second hexachord: >>> abjad.show(row[-6:]) # doctest: +SKIP .. docs:: >>> lilypond_file = row[-6:].__illustrate__() >>> abjad.f(lilypond_file[abjad.Voice]) \new Voice { f'8 e'8 bf'8 d'8 af'8 c'8 \bar "|." %! SCORE1 \override Score.BarLine.transparent = ##f } .. container:: example Returns pitch-class segment: >>> row[-6:] PitchClassSegment([5, 4, 10, 2, 8, 0]) ''' from abjad.tools import pitchtools item = self._collection.__getitem__(argument) try: return PitchClassSegment( items=item, item_class=pitchtools.NumberedPitchClass, ) except TypeError: return item