Esempio n. 1
0
 def __init__(self, *args):
     from abjad.tools import scoretools
     if len(args) == 0:
         args = ((1, 4),)
     rest = scoretools.Rest(*args)
     Leaf.__init__(
         self, 
         rest.written_duration, 
         )
Esempio n. 2
0
 def __init__(self, *args):
     from abjad.tools import scoretools
     if len(args) == 0:
         args = ((1, 4), )
     rest = scoretools.Rest(*args)
     Leaf.__init__(
         self,
         rest.written_duration,
     )
Esempio n. 3
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])
Esempio n. 4
0
File: Note.py Progetto: DnMllr/abjad
 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])
Esempio n. 5
0
 def __init__(self, *args):
     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]]
     is_cautionary = []
     is_forced = []
     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]
             is_cautionary = [leaf.note_head.is_cautionary]
             is_forced = [leaf.note_head.is_forced]
         elif hasattr(leaf, 'written_pitches'):
             written_pitches = leaf.written_pitches
             is_cautionary = [x.is_cautionary for x in leaf.note_heads]
             is_forced = [x.is_forced 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 is_cautionary:
         is_cautionary = [False] * len(written_pitches)
     if not is_forced:
         is_forced = [False] * len(written_pitches)
     for written_pitch, cautionary, forced in zip(
         written_pitches, is_cautionary, is_forced):
         note_head = scoretools.NoteHead(
             written_pitch=written_pitch,
             is_cautionary=cautionary,
             is_forced=forced,
             )
         self._note_heads.append(note_head)
     if len(args) == 1 and isinstance(args[0], Leaf):
         self._copy_override_and_set_from_leaf(args[0])
Esempio n. 6
0
 def __init__(self, *args):
     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]]
     is_cautionary = []
     is_forced = []
     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]
             is_cautionary = [leaf.note_head.is_cautionary]
             is_forced = [leaf.note_head.is_forced]
         elif hasattr(leaf, 'written_pitches'):
             written_pitches = leaf.written_pitches
             is_cautionary = [x.is_cautionary for x in leaf.note_heads]
             is_forced = [x.is_forced 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 is_cautionary:
         is_cautionary = [False] * len(written_pitches)
     if not is_forced:
         is_forced = [False] * len(written_pitches)
     for written_pitch, cautionary, forced in zip(written_pitches,
                                                  is_cautionary, is_forced):
         note_head = scoretools.NoteHead(
             written_pitch=written_pitch,
             is_cautionary=cautionary,
             is_forced=forced,
         )
         self._note_heads.append(note_head)
     if len(args) == 1 and isinstance(args[0], Leaf):
         self._copy_override_and_set_from_leaf(args[0])
Esempio n. 7
0
 def _copy_with_indicators_but_without_children_or_spanners(self):
     new = Leaf._copy_with_indicators_but_without_children_or_spanners(self)
     new.note_heads[:] = []
     for note_head in self.note_heads:
         new_note_head = copy.copy(note_head)
         new.note_heads.append(new_note_head)
     return new
Esempio n. 8
0
 def _copy_with_indicators_but_without_children_or_spanners(self):
     new = Leaf._copy_with_indicators_but_without_children_or_spanners(self)
     new.note_heads[:] = []
     for note_head in self.note_heads:
         new_note_head = copy.copy(note_head)
         new.note_heads.append(new_note_head)
     return new
Esempio n. 9
0
File: Rest.py Progetto: adorsk/abjad
 def __init__(self, written_duration=None):
     from abjad.tools import lilypondparsertools
     original_input = written_duration
     if isinstance(written_duration, str):
         string = '{{ {} }}'.format(written_duration)
         parsed = lilypondparsertools.LilyPondParser()(string)
         assert len(parsed) == 1 and isinstance(parsed[0], Leaf)
         written_duration = parsed[0]
     if isinstance(written_duration, Leaf):
         written_duration = written_duration.written_duration
     elif written_duration is None:
         written_duration = durationtools.Duration(1, 4)
     else:
         written_duration = durationtools.Duration(written_duration)
     Leaf.__init__(self, written_duration)
     if isinstance(original_input, Leaf):
         self._copy_override_and_set_from_leaf(original_input)
Esempio n. 10
0
 def __init__(self, written_duration=None):
     from abjad.tools import lilypondparsertools
     original_input = written_duration
     if isinstance(written_duration, str):
         string = '{{ {} }}'.format(written_duration)
         parsed = lilypondparsertools.LilyPondParser()(string)
         assert len(parsed) == 1 and isinstance(parsed[0], Leaf)
         written_duration = parsed[0]
     if isinstance(written_duration, Leaf):
         written_duration = written_duration.written_duration
     elif written_duration is None:
         written_duration = durationtools.Duration(1, 4)
     else:
         written_duration = durationtools.Duration(written_duration)
     Leaf.__init__(self, written_duration)
     if isinstance(original_input, Leaf):
         self._copy_override_and_set_from_leaf(original_input)
Esempio n. 11
0
 def __init__(self, *args):
     from abjad.tools import lilypondparsertools
     input_leaf = None
     written_duration = None
     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)
         input_leaf = parsed[0]
         written_duration = input_leaf.written_duration
     elif len(args) == 1 and isinstance(args[0], Leaf):
         written_duration = args[0].written_duration
         input_leaf = args[0]
     elif len(args) == 1 and not isinstance(args[0], str):
         written_duration = args[0]
     elif len(args) == 0:
         written_duration = durationtools.Duration(1, 4)
     else:
         message = 'can not initialize skip from {!r}.'
         message = message.format(args)
         raise ValueError(message)
     Leaf.__init__(self, written_duration)
     if input_leaf is not None:
         self._copy_override_and_set_from_leaf(input_leaf)
Esempio n. 12
0
 def __init__(self, *args):
     from abjad.tools import lilypondparsertools
     input_leaf = None
     written_duration = None
     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)
         input_leaf = parsed[0]
         written_duration = input_leaf.written_duration
     elif len(args) == 1 and isinstance(args[0], Leaf):
         written_duration = args[0].written_duration
         input_leaf = args[0]
     elif len(args) == 1 and not isinstance(args[0], str):
         written_duration = args[0]
     elif len(args) == 0:
         written_duration = durationtools.Duration(1, 4)
     else:
         message = 'can not initialize skip from {!r}.'
         message = message.format(args)
         raise ValueError(message)
     Leaf.__init__(self, written_duration)
     if input_leaf is not None:
         self._copy_override_and_set_from_leaf(input_leaf)
Esempio n. 13
0
 def __init__(self, *args):
     from abjad.ly import drums
     from abjad.tools import scoretools
     from abjad.tools.topleveltools import parse
     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 = parse(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_pitches = []
         written_duration = leaf.written_duration
         if 'written_pitch' in dir(leaf):
             written_pitches.append(leaf.note_head.written_pitch)
             are_cautionary = [leaf.note_head.is_cautionary]
             are_forced = [leaf.note_head.is_forced]
             are_parenthesized = [leaf.note_head.is_parenthesized]
         elif 'written_pitches' in dir(leaf):
             written_pitches.extend(x.written_pitch
                                    for x in leaf.note_heads)
             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
             ]
     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])