Пример #1
0
 def __init__(self, *args):
     from abjad.ly import drums
     from abjad.tools import lilypondparsertools
     from abjad.tools import scoretools
     assert len(args) in (0, 1, 2)
     if len(args) == 1 and isinstance(args[0], str):
         string = '{{ {} }}'.format(args[0])
         parsed = lilypondparsertools.LilyPondParser()(string)
         assert len(parsed) == 1 and isinstance(parsed[0], Leaf)
         args = [parsed[0]]
     is_cautionary = False
     is_forced = False
     is_parenthesized = False
     if len(args) == 1 and isinstance(args[0], Leaf):
         leaf = args[0]
         written_pitch = None
         written_duration = leaf.written_duration
         if 'written_pitch' in dir(leaf):
             written_pitch = leaf.note_head.written_pitch
             is_cautionary = leaf.note_head.is_cautionary
             is_forced = leaf.note_head.is_forced
             is_parenthesized = leaf.note_head.is_parenthesized
         elif 'written_pitches' in dir(leaf):
             written_pitches = [x.written_pitch for x in leaf.note_heads]
             if written_pitches:
                 written_pitch = written_pitches[0]
                 is_cautionary = leaf.note_heads[0].is_cautionary
                 is_forced = leaf.note_heads[0].is_forced
                 is_parenthesized = leaf.note_heads[0].is_parenthesized
     elif len(args) == 2:
         written_pitch, written_duration = args
     elif len(args) == 0:
         written_pitch = 'C4'
         written_duration = durationtools.Duration(1, 4)
     else:
         message = 'can not initialize note from {!r}.'
         raise ValueError(message.format(args))
     Leaf.__init__(self, written_duration)
     if written_pitch is not None:
         if written_pitch not in drums:
             self.note_head = scoretools.NoteHead(
                 written_pitch=written_pitch,
                 is_cautionary=is_cautionary,
                 is_forced=is_forced,
                 is_parenthesized=is_parenthesized,
             )
         else:
             self.note_head = scoretools.DrumNoteHead(
                 written_pitch=written_pitch,
                 is_cautionary=is_cautionary,
                 is_forced=is_forced,
                 is_parenthesized=is_parenthesized,
             )
     else:
         self.note_head = None
     if len(args) == 1 and isinstance(args[0], Leaf):
         self._copy_override_and_set_from_leaf(args[0])
Пример #2
0
 def __init__(self, *args):
     from abjad.ly import drums
     from abjad.tools import lilypondparsertools
     from abjad.tools import scoretools
     assert len(args) in (0, 1, 2)
     self._note_heads = scoretools.NoteHeadInventory(client=self, )
     if len(args) == 1 and isinstance(args[0], str):
         string = '{{ {} }}'.format(args[0])
         parsed = lilypondparsertools.LilyPondParser()(string)
         assert len(parsed) == 1 and isinstance(parsed[0], Leaf)
         args = [parsed[0]]
     are_cautionary = []
     are_forced = []
     are_parenthesized = []
     if len(args) == 1 and isinstance(args[0], Leaf):
         leaf = args[0]
         written_duration = leaf.written_duration
         if hasattr(leaf, 'written_pitch'):
             written_pitches = [leaf.written_pitch]
             are_cautionary = [leaf.note_head.is_cautionary]
             are_forced = [leaf.note_head.is_forced]
             are_parenthesized = [leaf.note_head.is_parenthesized]
         elif hasattr(leaf, 'written_pitches'):
             written_pitches = leaf.written_pitches
             are_cautionary = [x.is_cautionary for x in leaf.note_heads]
             are_forced = [x.is_forced for x in leaf.note_heads]
             are_parenthesized = [
                 x.is_parenthesized for x in leaf.note_heads
             ]
         else:
             written_pitches = []
     elif len(args) == 2:
         written_pitches, written_duration = args
         if isinstance(written_pitches, str):
             written_pitches = [x for x in written_pitches.split() if x]
         elif isinstance(written_pitches, type(self)):
             written_pitches = written_pitches.written_pitches
     elif len(args) == 0:
         written_pitches = [0, 4, 7]
         written_duration = durationtools.Duration(1, 4)
     else:
         message = 'can not initialize chord from {!r}.'
         message = message.format(args)
         raise ValueError(message)
     Leaf.__init__(self, written_duration)
     if not are_cautionary:
         are_cautionary = [None] * len(written_pitches)
     if not are_forced:
         are_forced = [None] * len(written_pitches)
     if not are_parenthesized:
         are_parenthesized = [None] * len(written_pitches)
     for written_pitch, is_cautionary, is_forced, is_parenthesized in zip(
             written_pitches, are_cautionary, are_forced,
             are_parenthesized):
         if not is_cautionary:
             is_cautionary = None
         if not is_forced:
             is_forced = None
         if not is_parenthesized:
             is_parenthesized = None
         if written_pitch not in drums:
             note_head = scoretools.NoteHead(
                 written_pitch=written_pitch,
                 is_cautionary=is_cautionary,
                 is_forced=is_forced,
                 is_parenthesized=is_parenthesized,
             )
         else:
             note_head = scoretools.DrumNoteHead(
                 written_pitch=written_pitch,
                 is_cautionary=is_cautionary,
                 is_forced=is_forced,
                 is_parenthesized=is_parenthesized,
             )
         self._note_heads.append(note_head)
     if len(args) == 1 and isinstance(args[0], Leaf):
         self._copy_override_and_set_from_leaf(args[0])