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 = abjad.parse('{{ {} }}'.format(measure_dict['t'])) bass = abjad.parse('{{ {} }}'.format(measure_dict['b'])) return treble, bass
def make_mozart_measure(measure_dict): """ Makes Mozart measure. """ # parse the contents of a measure definition dictionary # wrap the expression to be parsed inside a LilyPond { } block treble = abjad.parse("{{ {} }}".format(measure_dict["t"])) bass = abjad.parse("{{ {} }}".format(measure_dict["b"])) return treble, bass
def make_mozart_measure(measure_dict): """ Makes Mozart measure. """ # parse the contents of a measure definition dictionary # wrap the expression to be parsed inside a LilyPond { } block treble = abjad.parse('{{ {} }}'.format(measure_dict['t'])) bass = abjad.parse('{{ {} }}'.format(measure_dict['b'])) return treble, bass
def skeleton( argument: typing.Union[str, abjad.Selection], *, do_not_check_total_duration: bool = None, tag: typing.Optional[abjad.Tag] = abjad.Tag("baca.skeleton()"), ) -> RhythmCommand: """ Makes rhythm command from ``string`` and attaches NOT_YET_PITCHED indicators to music. """ if isinstance(argument, str): string = f"{{ {argument} }}" container = abjad.parse(string) selection = abjad.mutate.eject_contents(container) elif isinstance(argument, abjad.Selection): selection = argument else: message = "baca.skeleton() accepts string or selection," message += " not {repr(argument)}." raise TypeError(message) if tag is not None: tag_selection(selection, tag) return RhythmCommand( selection, annotation_spanner_color="#darkcyan", annotation_spanner_text="baca.skeleton() =|", attach_not_yet_pitched=True, do_not_check_total_duration=do_not_check_total_duration, )
def music( argument: typing.Union[str, abjad.Selection], *, do_not_check_total_duration: bool = None, tag: typing.Optional[abjad.Tag] = abjad.Tag("baca.music()"), ) -> RhythmCommand: """ Makes rhythm command from string or selection ``argument``. """ if isinstance(argument, str): string = f"{{ {argument} }}" container = abjad.parse(string) selection = abjad.mutate.eject_contents(container) elif isinstance(argument, abjad.Selection): selection = argument else: message = "baca.music() accepts string or selection," message += f" not {repr(argument)}." raise TypeError(message) if tag is not None: tag_selection(selection, tag) return RhythmCommand( selection, annotation_spanner_color="#darkcyan", annotation_spanner_text="baca.music() =|", do_not_check_total_duration=do_not_check_total_duration, )
def __init__(self, *arguments): import abjad from abjad.ly import drums assert len(arguments) in (0, 1, 2) if len(arguments) == 1 and isinstance(arguments[0], str): string = '{{ {} }}'.format(arguments[0]) parsed = abjad.parse(string) assert len(parsed) == 1 and isinstance(parsed[0], Leaf) arguments = [parsed[0]] is_cautionary = False is_forced = False is_parenthesized = False if len(arguments) == 1 and isinstance(arguments[0], Leaf): leaf = arguments[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(arguments) == 2: written_pitch, written_duration = arguments elif len(arguments) == 0: written_pitch = 'C4' written_duration = Duration(1, 4) else: message = 'can not initialize note from {!r}.' raise ValueError(message.format(arguments)) Leaf.__init__(self, written_duration) if written_pitch is not None: if written_pitch not in drums: self.note_head = NoteHead( written_pitch=written_pitch, is_cautionary=is_cautionary, is_forced=is_forced, is_parenthesized=is_parenthesized, ) else: self.note_head = DrumNoteHead( written_pitch=written_pitch, is_cautionary=is_cautionary, is_forced=is_forced, is_parenthesized=is_parenthesized, ) else: self.note_head = None if len(arguments) == 1 and isinstance(arguments[0], Leaf): self._copy_override_and_set_from_leaf(arguments[0])
def skeleton(argument): if isinstance(argument, str): string = f"{{ {argument} }}" container = abjad.parse(string) selection = abjad.mutate.eject_contents(container) elif isinstance(argument, abjad.Selection): selection = argument else: message = "evans.skeleton() accepts string or selection," message += " not {repr(argument)}." raise TypeError(message) return selection
def __init__(self, written_duration=None): import abjad original_input = written_duration if isinstance(written_duration, str): string = f'{{ {written_duration} }}' parsed = abjad.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 = abjad.Duration(1, 4) else: written_duration = abjad.Duration(written_duration) Leaf.__init__(self, written_duration) if isinstance(original_input, Leaf): self._copy_override_and_set_from_leaf(original_input)
def test_LilyPondParser__lilypondfile__HeaderBlock_02(): string = r""" \header { composername = "Foo von Bar" composer = \markup { by \bold \composername } title = \markup { The ballad of \composername } tagline = \markup { "" } } { c'1 } """ result = abjad.parse(string) assert isinstance(result, abjad.LilyPondFile) assert len(result.items) == 2 assert format(result.items[0]) == abjad.String.normalize( r""" \header { composername = #"Foo von Bar" composer = \markup { by \bold "Foo von Bar" } title = \markup { The ballad of "Foo von Bar" } tagline = \markup {} } """ ) assert format(result.items[1]) == abjad.String.normalize( r""" { c'1 } """ )
def test_LilyPondParser__lilypondfile__HeaderBlock_01(): string = r""" globalvariable = "This is a global variable." \header { globalvariable = "This abjad.overrides the global variable" localvariable = "and this is a local variable." something = #4 title = \markup { \globalvariable \localvariable } } \score { \new Staff { c'4 ^ \markup { \globalvariable } } } """ result = abjad.parse(string) assert isinstance(result, abjad.LilyPondFile) assert len(result.items) == 2 assert format(result.items[0]) == abjad.String.normalize( r""" \header { globalvariable = #"This abjad.overrides the global variable" localvariable = #"and this is a local variable." something = #4 title = \markup { "This abjad.overrides the global variable" "and this is a local variable." } } """ ) assert format(result.items[1]) == abjad.String.normalize( r""" \score { \new Staff { c'4 ^ \markup { "This is a global variable." } } } """ )
def test_LilyPondParser__lilypondfile__HeaderBlock_02(): string = r""" \header { composername = "Foo von Bar" composer = \markup { by \bold \composername } title = \markup { The ballad of \composername } tagline = \markup { "" } } { c'1 } """ result = abjad.parse(string) assert isinstance(result, abjad.LilyPondFile) assert len(result.items) == 2 assert abjad.lilypond(result.items[0]) == abjad.String.normalize(r""" \header { composername = #"Foo von Bar" composer = \markup { by \bold "Foo von Bar" } title = \markup { The ballad of "Foo von Bar" } tagline = \markup {} } """) assert abjad.lilypond(result.items[1]) == abjad.String.normalize(r""" { c'1 } """)
def __init__(self, *arguments): import abjad input_leaf = None written_duration = None if len(arguments) == 1 and isinstance(arguments[0], str): string = f'{{ {arguments[0]} }}' parsed = abjad.parse(string) assert len(parsed) == 1 and isinstance(parsed[0], Leaf) input_leaf = parsed[0] written_duration = input_leaf.written_duration elif len(arguments) == 1 and isinstance(arguments[0], Leaf): written_duration = arguments[0].written_duration input_leaf = arguments[0] elif len(arguments) == 1 and not isinstance(arguments[0], str): written_duration = arguments[0] elif len(arguments) == 0: written_duration = abjad.Duration(1, 4) else: message = f'can not initialize skip from {arguments!r}.' raise ValueError(message) Leaf.__init__(self, written_duration) if input_leaf is not None: self._copy_override_and_set_from_leaf(input_leaf)
def test_LilyPondParser__lilypondfile__HeaderBlock_01(): string = r""" globalvariable = "This is a global variable." \header { globalvariable = "This abjad.overrides the global variable" localvariable = "and this is a local variable." something = #4 title = \markup { \globalvariable \localvariable } } \score { \new Staff { c'4 ^ \markup { \globalvariable } } } """ result = abjad.parse(string) assert isinstance(result, abjad.LilyPondFile) assert len(result.items) == 2 assert abjad.lilypond(result.items[0]) == abjad.String.normalize(r""" \header { globalvariable = #"This abjad.overrides the global variable" localvariable = #"and this is a local variable." something = #4 title = \markup { "This abjad.overrides the global variable" "and this is a local variable." } } """) assert abjad.lilypond(result.items[1]) == abjad.String.normalize(r""" \score { \new Staff { c'4 ^ \markup { "This is a global variable." } } } """)
def __init__(self, *arguments): import abjad from abjad.ly import drums 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 = abjad.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])