コード例 #1
0
 def _analyze_incomplete_chord(expr):
     from abjad.tools import tonalanalysistools
     pitches = pitchtools.PitchSegment.from_selection(expr)
     npcset = pitchtools.PitchClassSet(
         pitches, item_class=pitchtools.NamedPitchClass)
     dicv = pitchtools.IntervalClassVector(
         items=npcset,
         item_class=pitchtools.NamedInversionEquivalentIntervalClass,
     )
     # TODO: eliminate code duplication #
     if dicv == TonalAnalysisAgent._make_dicv('c', 'ef'):
         model_npcs = ['c', 'ef']
         quality, extent = 'minor', 'triad'
     elif dicv == TonalAnalysisAgent._make_dicv('c', 'e'):
         model_npcs = ['c', 'e']
         quality, extent = 'major', 'triad'
     elif dicv == TonalAnalysisAgent._make_dicv('c', 'ef', 'bff'):
         model_npcs = ['c', 'ef', 'bff']
         quality, extent = 'diminished', 'seventh'
     elif dicv == TonalAnalysisAgent._make_dicv('c', 'ef', 'bf'):
         model_npcs = ['c', 'ef', 'bf']
         quality, extent = 'minor', 'seventh'
     elif dicv == TonalAnalysisAgent._make_dicv('c', 'e', 'bf'):
         model_npcs = ['c', 'e', 'bf']
         quality, extent = 'dominant', 'seventh'
     elif dicv == TonalAnalysisAgent._make_dicv('c', 'e', 'b'):
         model_npcs = ['c', 'e', 'b']
         quality, extent = 'major', 'seventh'
     else:
         message = 'can not identify incomplete tertian chord.'
         raise ValueError(message)
     bass = min(pitches).named_pitch_class
     try:
         npcseg = npcset.order_by(
             pitchtools.PitchClassSegment(
                 model_npcs,
                 item_class=pitchtools.NamedPitchClass,
             ))
     except ValueError:
         message = 'can not identify incomplete tertian chord.'
         raise ValueError(message)
     inversion = npcseg.index(bass)
     root = npcseg[0]
     return tonalanalysistools.RootedChordClass(
         root,
         quality,
         extent,
         inversion,
     )
コード例 #2
0
    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)
コード例 #3
0
 def _analyze_chord(expr):
     from abjad.tools import tonalanalysistools
     pitches = pitchtools.PitchSegment.from_selection(expr)
     npcset = pitchtools.PitchClassSet(
         pitches,
         item_class=pitchtools.NamedPitchClass,
     )
     ordered_npcs = []
     letters = ('c', 'e', 'g', 'b', 'd', 'f', 'a')
     for letter in letters:
         for npc in npcset:
             if npc.diatonic_pitch_class_name == letter:
                 ordered_npcs.append(npc)
     ordered_npcs = pitchtools.PitchClassSegment(
         ordered_npcs, item_class=pitchtools.NamedPitchClass)
     for x in range(len(ordered_npcs)):
         ordered_npcs = ordered_npcs.rotate(1)
         segment = \
             pitchtools.IntervalClassSegment(
                 items=mathtools.difference_series(ordered_npcs),
                 item_class=pitchtools.NamedInversionEquivalentIntervalClass,
                 )
         if segment.is_tertian:
             break
     else:
         return None
     root = ordered_npcs[0]
     class_ = tonalanalysistools.RootlessChordClass
     rootless_chord_class = class_.from_interval_class_segment(segment)
     bass = min(pitches).named_pitch_class
     inversion = ordered_npcs.index(bass)
     return tonalanalysistools.RootedChordClass(
         root,
         rootless_chord_class.quality_string,
         rootless_chord_class.extent,
         inversion,
     )
コード例 #4
0
percussion_staff = consort.AttachmentExpression(attachments=[
    [
        spannertools.StaffLinesSpanner(
            lines=[-4, 4],
            overrides={
                'note_head__style': 'cross',
                'note_head__no_ledgers': True,
            },
        ),
        consort.ClefSpanner('percussion'),
    ],
], )

agitato_pitch_specifier = consort.PitchSpecifier(
    pitch_segments=[
        pitchtools.PitchClassSegment([0, 3, 2, 5, 11, 1]),
        pitchtools.PitchClassSegment([11, 9]),
        pitchtools.PitchClassSegment([2, 4, 5, 8]),
        pitchtools.PitchClassSegment([0, 3, 5]),
        pitchtools.PitchClassSegment([2, 4, 5, 8]),
    ],
    ratio=[1, 2, 1, 2, 1],
)

pitch_operation_specifier = consort.PitchOperationSpecifier(
    pitch_operations=[
        pitchtools.Rotation(1, stravinsky=True),
        None,
        pitchtools.CompoundOperator([
            pitchtools.Transposition(1),
            pitchtools.Inversion(),