Ejemplo n.º 1
0
def make_mozart_measure(measure_dict):
    r'''Makes Mozart measure.
    '''

    # parse the contents of a measure definition dictionary
    # wrap the expression to be parsed inside a LilyPond { } block
    treble = parse('{{ {} }}'.format(measure_dict['t']))
    bass = parse('{{ {} }}'.format(measure_dict['b']))
    return treble, bass
Ejemplo n.º 2
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)
     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]]
     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])
Ejemplo n.º 3
0
    def register_material(self, material):
        r'''Register `material`.

        Change tuple or list to payload expression.

        Change parseable string to start-positioned rhythm payload expression.
        '''
        from experimental.tools import musicexpressiontools
        if isinstance(material, (tuple, list)):
            return musicexpressiontools.IterablePayloadExpression(material)
        elif isinstance(material, (str)):
            component = topleveltools.parse(material)
            return musicexpressiontools.StartPositionedRhythmPayloadExpression(
                [component], start_offset=0)
        else:
            raise TypeError(material)
Ejemplo n.º 4
0
 def __init__(self, written_duration=None):
     from abjad.tools.topleveltools import parse
     original_input = written_duration
     if isinstance(written_duration, str):
         string = '{{ {} }}'.format(written_duration)
         parsed = parse(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)
Ejemplo n.º 5
0
Archivo: Rest.py Proyecto: ajyoon/abjad
 def __init__(self, written_duration=None):
     from abjad.tools.topleveltools import parse
     original_input = written_duration
     if isinstance(written_duration, str):
         string = '{{ {} }}'.format(written_duration)
         parsed = parse(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)
Ejemplo n.º 6
0
 def _expr_to_expression(self, expr):
     from abjad.tools import rhythmmakertools
     from experimental.tools import musicexpressiontools
     if isinstance(expr, musicexpressiontools.Expression):
         return expr
     elif self._all_are_expressions(expr):
         return musicexpressiontools.ExpressionInventory(expr)
     elif isinstance(expr, (tuple, list, datastructuretools.TypedList)):
         return musicexpressiontools.IterablePayloadExpression(expr)
     elif isinstance(expr, (str)):
         component = topleveltools.parse(expr)
         return musicexpressiontools.StartPositionedRhythmPayloadExpression(
             [component], start_offset=0)
     elif isinstance(expr, rhythmmakertools.RhythmMaker):
         return musicexpressiontools.RhythmMakerExpression(expr)
     else:
         message = 'do not know how to change {!r} to expression.'
         raise TypeError(message.format(expr))
Ejemplo n.º 7
0
 def _expr_to_expression(self, expr):
     from abjad.tools import rhythmmakertools
     from experimental.tools import musicexpressiontools
     if isinstance(expr, musicexpressiontools.Expression):
         return expr
     elif self._all_are_expressions(expr):
         return musicexpressiontools.ExpressionInventory(expr)
     elif isinstance(expr,
         (tuple, list, datastructuretools.TypedList)):
         return musicexpressiontools.IterablePayloadExpression(expr)
     elif isinstance(expr, (str)):
         component = topleveltools.parse(expr)
         return musicexpressiontools.StartPositionedRhythmPayloadExpression(
             [component], start_offset=0)
     elif isinstance(expr, rhythmmakertools.RhythmMaker):
         return musicexpressiontools.RhythmMakerExpression(expr)
     else:
         message = 'do not know how to change {!r} to expression.'
         raise TypeError(message.format(expr))
Ejemplo n.º 8
0
 def __init__(self, *args):
     from abjad.tools.topleveltools import parse
     input_leaf = None
     written_duration = None
     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)
         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)
Ejemplo n.º 9
0
 def __init__(self, *arguments):
     import abjad
     from abjad.ly import drums
     from abjad.tools.topleveltools import parse
     assert len(arguments) in (0, 1, 2)
     self._note_heads = abjad.NoteHeadList(client=self)
     if len(arguments) == 1 and isinstance(arguments[0], str):
         string = '{{ {} }}'.format(arguments[0])
         parsed = parse(string)
         assert len(parsed) == 1 and isinstance(parsed[0], Leaf)
         arguments = [parsed[0]]
     are_cautionary = []
     are_forced = []
     are_parenthesized = []
     if len(arguments) == 1 and isinstance(arguments[0], Leaf):
         leaf = arguments[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(arguments) == 2:
         written_pitches, written_duration = arguments
         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(arguments) == 0:
         written_pitches = [0, 4, 7]
         written_duration = abjad.Duration(1, 4)
     else:
         message = 'can not initialize chord from {!r}.'
         message = message.format(arguments)
         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 = abjad.NoteHead(
                 written_pitch=written_pitch,
                 is_cautionary=is_cautionary,
                 is_forced=is_forced,
                 is_parenthesized=is_parenthesized,
             )
         else:
             note_head = abjad.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(arguments) == 1 and isinstance(arguments[0], Leaf):
         self._copy_override_and_set_from_leaf(arguments[0])