def test_RhythmTreeContainer___eq___01():

    a = abjad.rhythmtrees.RhythmTreeContainer(children=[])
    b = abjad.rhythmtrees.RhythmTreeContainer(children=[])

    assert abjad.storage(a) == abjad.storage(b)
    assert a != b
Пример #2
0
def test_RhythmTreeLeaf___eq___01():

    a = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=1,
                                         is_pitched=True)
    b = abjad.rhythmtrees.RhythmTreeLeaf(preprolated_duration=1,
                                         is_pitched=True)

    assert abjad.storage(a) == abjad.storage(b)
    assert a != b
Пример #3
0
def test_RhythmTreeNode_pickle_01():

    string = "(1 (1 (2 (1 1 1)) 2))"
    tree = abjad.rhythmtrees.RhythmTreeParser()(string)[0]

    pickled = pickle.loads(pickle.dumps(tree))

    assert abjad.storage(pickled) == abjad.storage(tree)
    assert pickled != tree
    assert pickled is not tree
Пример #4
0
def test_new_02():

    old_aggregate = Aggregate(
        pitch_segment=abjad.PitchSegment("c d e f"),
        ratio=abjad.Ratio([1, 2, 3]),
    )

    assert abjad.storage(old_aggregate) == abjad.String.normalize(r"""
        test_new.Aggregate(
            pitch_segment=abjad.PitchSegment(
                (
                    abjad.NamedPitch('c'),
                    abjad.NamedPitch('d'),
                    abjad.NamedPitch('e'),
                    abjad.NamedPitch('f'),
                    ),
                item_class=abjad.NamedPitch,
                ),
            ratio=abjad.Ratio((1, 2, 3)),
            )
        """)

    new_aggregate = abjad.new(old_aggregate, ratio=(4, 5))

    assert new_aggregate is not old_aggregate
    assert new_aggregate != old_aggregate
    assert abjad.storage(old_aggregate) == abjad.String.normalize(r"""
        test_new.Aggregate(
            pitch_segment=abjad.PitchSegment(
                (
                    abjad.NamedPitch('c'),
                    abjad.NamedPitch('d'),
                    abjad.NamedPitch('e'),
                    abjad.NamedPitch('f'),
                    ),
                item_class=abjad.NamedPitch,
                ),
            ratio=abjad.Ratio((1, 2, 3)),
            )
        """)
    assert abjad.storage(new_aggregate) == abjad.String.normalize(r"""
        test_new.Aggregate(
            pitch_segment=abjad.PitchSegment(
                (
                    abjad.NamedPitch('c'),
                    abjad.NamedPitch('d'),
                    abjad.NamedPitch('e'),
                    abjad.NamedPitch('f'),
                    ),
                item_class=abjad.NamedPitch,
                ),
            ratio=abjad.Ratio((4, 5)),
            )
        """)
Пример #5
0
def test_new_03():

    old_aggregate = Aggregate(pitch_segment=abjad.PitchSegment("c d e f"))

    assert abjad.storage(old_aggregate) == abjad.String.normalize(r"""
        test_new.Aggregate(
            pitch_segment=abjad.PitchSegment(
                (
                    abjad.NamedPitch('c'),
                    abjad.NamedPitch('d'),
                    abjad.NamedPitch('e'),
                    abjad.NamedPitch('f'),
                    ),
                item_class=abjad.NamedPitch,
                ),
            )
        """)

    new_aggregate = abjad.new(old_aggregate,
                              pitch_segment="af bf df",
                              ratio=(5, 4))

    assert new_aggregate is not old_aggregate
    assert new_aggregate != old_aggregate
    assert abjad.storage(old_aggregate) == abjad.String.normalize(r"""
        test_new.Aggregate(
            pitch_segment=abjad.PitchSegment(
                (
                    abjad.NamedPitch('c'),
                    abjad.NamedPitch('d'),
                    abjad.NamedPitch('e'),
                    abjad.NamedPitch('f'),
                    ),
                item_class=abjad.NamedPitch,
                ),
            )
        """)
    assert abjad.storage(new_aggregate) == abjad.String.normalize(r"""
        test_new.Aggregate(
            pitch_segment=abjad.PitchSegment(
                (
                    abjad.NamedPitch('af'),
                    abjad.NamedPitch('bf'),
                    abjad.NamedPitch('df'),
                    ),
                item_class=abjad.NamedPitch,
                ),
            ratio=abjad.Ratio((5, 4)),
            )
        """)
Пример #6
0
    def _make_containers(self, commands):
        print("Making containers ...")

        def make_container(handler, durations):
            selections = handler(durations)
            container = abjad.Container([])
            container.extend(selections)
            return container

        voice_names = sorted(set(_.voice_name for _ in commands))
        handler_to_value = abjad.OrderedDict()
        for voice_name in voice_names:
            voice_commands = [
                _ for _ in commands if _.voice_name == voice_name
            ]
            voice_commands.sort(key=lambda _: _.timespan)
            for handler, grouper in itertools.groupby(voice_commands,
                                                      key=lambda _: _.handler):
                durations = [command.timespan.duration for command in grouper]
                container = make_container(handler, durations)
                voice = self.score_template[voice_name]
                voice.append(container[:])
                handler_to_value[handler.name] = handler.return_state()
        with open(f"{self.current_directory}/.rhythm.py", "w") as fp:
            handler_to_value_format = abjad.storage(handler_to_value)
            string = f"import abjad\nhandler_to_value = {handler_to_value_format}"
            fp.writelines(string)
Пример #7
0
    def __format__(self, format_specification=""):
        r"""Formats Abjad object.
        Set `format_specification` to `''` or `'storage'`.
        Interprets `''` equal to `'storage'`.
        Returns string.
        """

        if format_specification in ("", "storage"):
            return abjad.storage(self)
        return str(self)
Пример #8
0
 def _cache_persistent_info(self):
     print("Caching persistent info ...")
     info = abjad.OrderedDict()
     for i, voice in enumerate(
             abjad.select(self.score_template["Staff Group"]).components(
                 abjad.Staff)  # was Voice
     ):
         penultimate_rest = abjad.select(voice).leaves()[-2]
         persistent_attachments = abjad.get.indicators(penultimate_rest)
         info[f"Voice {i + 1}"] = persistent_attachments
     with open(f"{self.current_directory}/.persistent.py", "w") as fp:
         info_format = abjad.storage(info)
         string = f"import abjad\ninfo = {info_format}"
         fp.writelines(string)
Пример #9
0
 def call_handlers(self, commands):  # bypasses grace notes?
     print("Calling handlers ...")
     handler_to_value = abjad.OrderedDict()
     voice_names = sorted(set(_.voice_name for _ in commands))
     command_groups = []
     for handler_type, command_group in itertools.groupby(
             commands, lambda _: type(_.handler)):
         group = [_ for _ in command_group]
         command_groups.append(group)
     for group in command_groups:
         voice_collections = abjad.OrderedDict()
         global_collection = consort.LogicalTieCollection()
         for tie in abjad.select(
                 self.score_template["Global Context"]).logical_ties():
             global_collection.insert(tie)
         voice_collections["Global Context"] = global_collection
         for voice in abjad.select(self.score_template).components(
                 abjad.Voice):
             collection = consort.LogicalTieCollection()
             for tie in abjad.select(voice).logical_ties():
                 collection.insert(tie)
             voice_collections[voice.name] = collection
         for v_name in voice_names:
             voice_command_list = [
                 command for command in group
                 if command.voice_name == v_name
             ]
             voice_command_list.sort(key=lambda _: _.timespan)
             for command in voice_command_list:
                 voice_tie_collection = voice_collections[
                     command.voice_name]
                 target_timespan = command.timespan
                 selection = abjad.Selection([
                     _ for _ in voice_tie_collection.
                     find_logical_ties_starting_during_timespan(
                         target_timespan)
                 ])
                 if not selection:
                     continue
                 handler = command.handler
                 handler(selection)
                 handler_to_value[handler.name] = handler.state()
     with open(f"{self.current_directory}/.handlers.py", "w") as fp:
         handler_to_value_format = abjad.storage(handler_to_value)
         string = f"import abjad\nhandler_to_value = {handler_to_value_format}"
         fp.writelines(string)
Пример #10
0
 def __repr__(self):
     return abjad.storage(self)
Пример #11
0
 def __str__(self):
     return abjad.storage(self)
Пример #12
0
    def __repr__(self):
        r"""Gets interpreter representation of Abjad object.
        Returns string.
        """

        return abjad.storage(self)
Пример #13
0
import abjad

total_duration = abjad.Timespan(0, 7)
timespans = [abjad.Timespan(*_) for _ in [(1, 2), (2, 3), (4, 5)]]
timespans = abjad.TimespanList(timespans)
print(abjad.storage(timespans))
print()

result = abjad.TimespanList()
result.append(total_duration)
for timespan in timespans:
    result -= timespan
print(abjad.storage(result))
Пример #14
0
 def __format__(self, format_specification=""):
     return abjad.storage(self)