Пример #1
0
 def run(
         self,
         metadata=None,
         persist=None,
         previous_metadata=None,
         previous_persist=None,
         segment_directory=None,
     ):
     """
     Runs segment-maker.
     
     Returns LilyPond file.
     """
     self._metadata = abjad.OrderedDict(metadata)
     self._persist = abjad.OrderedDict(persist)
     self._previous_metadata = abjad.OrderedDict(previous_metadata)
     self._previous_persist = abjad.OrderedDict(previous_persist)
     self._segment_directory = segment_directory
     self._make_score()
     self._make_lilypond_file()
     self._configure_lilypond_file()
     self._call_rhythm_definitions()
     self._configure_score()
     score_block = self._lilypond_file["score"]
     score = score_block["Score"]
     #        if not abjad.inspect(score).wellformed():
     #            string = abjad.inspect(score).tabulate_wellformedness()
     #            raise Exception(string)
     return self._lilypond_file
def test_datastructuretools_OrderedDict_06():
    r'''Implements __len__().
    '''

    dictionary = abjad.OrderedDict(item_class=abjad.Clef)
    assert len(dictionary) == 0

    dictionary = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary['soprano'] = 'treble'
    assert len(dictionary) == 1
Пример #3
0
def test_TypedOrderedDict___eq___02():

    dictionary_1 = abjad.OrderedDict([("flavor", "cherry"), ("count", 2)])
    dictionary_2 = abjad.OrderedDict([("flavor", "cherry"), ("count", 2),
                                      ("color", "red")])

    assert dictionary_1 == dictionary_1
    assert not dictionary_1 == dictionary_2
    assert not dictionary_2 == dictionary_1
    assert dictionary_2 == dictionary_2
def test_datastructuretools_OrderedDict_02():
    r'''Implements __delitem__().
    '''

    dictionary_1 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_1['soprano'] = 'treble'
    del(dictionary_1['soprano'])

    dictionary_2 = abjad.OrderedDict(item_class=abjad.Clef)
    assert dictionary_1 == dictionary_2
Пример #5
0
def test_TypedOrderedDict_02():
    """
    Implements __delitem__().
    """

    dictionary_1 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_1["soprano"] = "treble"
    del dictionary_1["soprano"]

    dictionary_2 = abjad.OrderedDict(item_class=abjad.Clef)
    assert dictionary_1 == dictionary_2
Пример #6
0
def test_TypedOrderedDict_06():
    """
    Implements __len__().
    """

    dictionary = abjad.OrderedDict(item_class=abjad.Clef)
    assert len(dictionary) == 0

    dictionary = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary['soprano'] = 'treble'
    assert len(dictionary) == 1
Пример #7
0
def test_TypedOrderedDict_02():
    """
    Implements __delitem__().
    """

    dictionary_1 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_1['soprano'] = 'treble'
    del(dictionary_1['soprano'])

    dictionary_2 = abjad.OrderedDict(item_class=abjad.Clef)
    assert dictionary_1 == dictionary_2
Пример #8
0
def test_datastructuretools_OrderedDict___eq___02():

    dictionary_1 = abjad.OrderedDict([
        ('flavor', 'cherry'), ('count', 2),
        ])
    dictionary_2 = abjad.OrderedDict([
        ('flavor', 'cherry'), ('count', 2), ('color', 'red'),
        ])

    assert dictionary_1 == dictionary_1
    assert not dictionary_1 == dictionary_2
    assert not dictionary_2 == dictionary_1
    assert dictionary_2 == dictionary_2
def test_datastructuretools_OrderedDict_09():
    r'''Implements clear().
    '''

    dictionary_1 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_1['soprano'] = 'treble'
    dictionary_1['alto'] = 'alto'
    dictionary_1['tenor'] = 'tenor'
    dictionary_1['bass'] = 'bass'
    dictionary_1.clear()

    dictionary_2 = abjad.OrderedDict(item_class=abjad.Clef)
    assert dictionary_1 == dictionary_2
Пример #10
0
def test_TypedOrderedDict_09():
    """
    Implements clear().
    """

    dictionary_1 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_1["soprano"] = "treble"
    dictionary_1["alto"] = "alto"
    dictionary_1["tenor"] = "tenor"
    dictionary_1["bass"] = "bass"
    dictionary_1.clear()

    dictionary_2 = abjad.OrderedDict(item_class=abjad.Clef)
    assert dictionary_1 == dictionary_2
Пример #11
0
def test_TypedOrderedDict_09():
    """
    Implements clear().
    """

    dictionary_1 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_1['soprano'] = 'treble'
    dictionary_1['alto'] = 'alto'
    dictionary_1['tenor'] = 'tenor'
    dictionary_1['bass'] = 'bass'
    dictionary_1.clear()

    dictionary_2 = abjad.OrderedDict(item_class=abjad.Clef)
    assert dictionary_1 == dictionary_2
Пример #12
0
 def __init__(
     self,
     *,
     deactivate: bool = None,
     map: abjad.Expression = None,
     match: typings.Indices = None,
     measures: typings.SliceTyping = None,
     scope: ScopeTyping = None,
     selector: abjad.Expression = None,
     tag_measure_number: bool = None,
     tags: typing.List[typing.Optional[abjad.Tag]] = None,
 ) -> None:
     self._deactivate = deactivate
     self._map = map
     self._match = match
     self._measures: typing.Optional[typings.SliceTyping] = measures
     self._runtime = abjad.OrderedDict()
     self._scope = scope
     selector_ = selector
     if selector_ is not None and not callable(selector_):
         message = "selector must be callable:\n"
         message += f"   {repr(selector_)}"
         raise Exception(message)
     self._selector = selector_
     self._tag_measure_number = tag_measure_number
     self._initialize_tags(tags)
def test_TypedOrderedDict___copy___01():

    dictionary_1 = abjad.OrderedDict([("flavor", "cherry"), ("count", 2)])
    dictionary_2 = copy.copy(dictionary_1)

    assert dictionary_1 == dictionary_2
    assert repr(dictionary_1) == repr(dictionary_2)
Пример #14
0
 def _collect_metadata(self):
     metadata = abjad.OrderedDict()
     metadata["last_tempo"] = self._get_last_tempo()
     metadata["last_time_signature"] = self._get_last_time_signature()
     metadata["empty_beatspan"] = self._get_empty_beatspan()
     metadata["segment_name"] = self._segment_name
     self.metadata.update(metadata)
Пример #15
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)
Пример #16
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)
def test_datastructuretools_OrderedDict_15():
    r'''Implements pop().
    '''

    dictionary_1 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_1['soprano'] = 'treble'
    dictionary_1['alto'] = 'alto'
    dictionary_1['tenor'] = 'tenor'
    dictionary_1['bass'] = 'bass'

    dictionary_2 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_2['alto'] = 'alto'
    dictionary_2['tenor'] = 'tenor'
    dictionary_2['bass'] = 'bass'

    assert dictionary_1.pop('soprano') == abjad.Clef('treble')
    assert dictionary_1 == dictionary_2
Пример #18
0
 def _collect_state(self, state):
     import abjad
     state_ = abjad.OrderedDict()
     for key, value_ in state.items():
         assert hasattr(self, key)
         value = getattr(self, key)
         state_[key] = value
     return state_
Пример #19
0
 def run(self, environment=None, metadata=None):
     """
     Runs the segment-maker.
     """
     self._environment = environment
     self._metadata = abjad.OrderedDict(metadata)
     self._make_lilypond_file()
     self._collect_metadata()
     return self.lilypond_file
Пример #20
0
def test_TypedOrderedDict_15():
    """
    Implements pop().
    """

    dictionary_1 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_1["soprano"] = "treble"
    dictionary_1["alto"] = "alto"
    dictionary_1["tenor"] = "tenor"
    dictionary_1["bass"] = "bass"

    dictionary_2 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_2["alto"] = "alto"
    dictionary_2["tenor"] = "tenor"
    dictionary_2["bass"] = "bass"

    assert dictionary_1.pop("soprano") == abjad.Clef("treble")
    assert dictionary_1 == dictionary_2
Пример #21
0
def test_TypedOrderedDict_15():
    """
    Implements pop().
    """

    dictionary_1 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_1['soprano'] = 'treble'
    dictionary_1['alto'] = 'alto'
    dictionary_1['tenor'] = 'tenor'
    dictionary_1['bass'] = 'bass'

    dictionary_2 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_2['alto'] = 'alto'
    dictionary_2['tenor'] = 'tenor'
    dictionary_2['bass'] = 'bass'

    assert dictionary_1.pop('soprano') == abjad.Clef('treble')
    assert dictionary_1 == dictionary_2
def test_datastructuretools_OrderedDict___deepcopy___01():

    dictionary_1 = abjad.OrderedDict([
        ('flavor', 'cherry'),
        ('count', 2),
    ])
    dictionary_2 = copy.deepcopy(dictionary_1)

    assert dictionary_1 == dictionary_2
    assert repr(dictionary_1) == repr(dictionary_2)
def test_TypedOrderedDict___copy___01():

    dictionary_1 = abjad.OrderedDict([
        ('flavor', 'cherry'),
        ('count', 2),
    ])
    dictionary_2 = copy.copy(dictionary_1)

    assert dictionary_1 == dictionary_2
    assert repr(dictionary_1) == repr(dictionary_2)
Пример #24
0
def test_TypedOrderedDict_07():

    dictionary_1 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_1['soprano'] = 'treble'

    dictionary_2 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_2['soprano'] = 'treble'

    dictionary_3 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_3['bass'] = 'bass'

    assert not dictionary_1 != dictionary_1
    assert not dictionary_1 != dictionary_2
    assert dictionary_1 != dictionary_3
    assert not dictionary_2 != dictionary_1
    assert not dictionary_2 != dictionary_2
    assert dictionary_2 != dictionary_3
    assert dictionary_3 != dictionary_1
    assert dictionary_3 != dictionary_2
    assert not dictionary_3 != dictionary_3
Пример #25
0
def test_TypedOrderedDict_07():

    dictionary_1 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_1["soprano"] = "treble"

    dictionary_2 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_2["soprano"] = "treble"

    dictionary_3 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_3["bass"] = "bass"

    assert not dictionary_1 != dictionary_1
    assert not dictionary_1 != dictionary_2
    assert dictionary_1 != dictionary_3
    assert not dictionary_2 != dictionary_1
    assert not dictionary_2 != dictionary_2
    assert dictionary_2 != dictionary_3
    assert dictionary_3 != dictionary_1
    assert dictionary_3 != dictionary_2
    assert not dictionary_3 != dictionary_3
def test_datastructuretools_OrderedDict_14():
    r'''Implements keys().
    '''

    dictionary = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary['soprano'] = 'treble'
    dictionary['alto'] = 'alto'
    dictionary['tenor'] = 'tenor'
    dictionary['bass'] = 'bass'

    assert list(dictionary.keys()) == ['soprano', 'alto', 'tenor', 'bass']
def test_datastructuretools_OrderedDict_17():
    r'''Implements update().
    '''

    dictionary_1 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_1['soprano'] = 'treble'
    dictionary_1['alto'] = 'alto'

    dictionary_2 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_2['tenor'] = 'tenor'
    dictionary_2['bass'] = 'bass'

    dictionary_3 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_3['soprano'] = 'treble'
    dictionary_3['alto'] = 'alto'
    dictionary_3['tenor'] = 'tenor'
    dictionary_3['bass'] = 'bass'

    dictionary_1.update(dictionary_2)
    assert dictionary_1 == dictionary_3
Пример #28
0
 def run(self, environment=None, metadata=None, previous_metadata=None):
     """
     Runs the segment-maker.
     """
     self._environment = environment
     # self._process_previous_metadata(previous_metadata)
     self._metadata = abjad.OrderedDict(metadata)
     self._make_lilypond_file()
     self._make_build_file(previous_metadata=previous_metadata)
     self._collect_metadata()
     return self.lilypond_file
Пример #29
0
def test_TypedOrderedDict_05():
    """
    Initializes from dictionary items.
    """

    items = [
        ("soprano", abjad.Clef("treble")),
        ("alto", abjad.Clef("alto")),
        ("tenor", abjad.Clef("tenor")),
        ("bass", abjad.Clef("bass")),
    ]
    dictionary_1 = abjad.OrderedDict(item_class=abjad.Clef, items=items)

    dictionary_2 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_2["soprano"] = "treble"
    dictionary_2["alto"] = "alto"
    dictionary_2["tenor"] = "tenor"
    dictionary_2["bass"] = "bass"

    assert dictionary_1 == dictionary_2
Пример #30
0
def test_TypedOrderedDict_17():
    """
    Implements update().
    """

    dictionary_1 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_1['soprano'] = 'treble'
    dictionary_1['alto'] = 'alto'

    dictionary_2 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_2['tenor'] = 'tenor'
    dictionary_2['bass'] = 'bass'

    dictionary_3 = abjad.OrderedDict(item_class=abjad.Clef)
    dictionary_3['soprano'] = 'treble'
    dictionary_3['alto'] = 'alto'
    dictionary_3['tenor'] = 'tenor'
    dictionary_3['bass'] = 'bass'

    dictionary_1.update(dictionary_2)
    assert dictionary_1 == dictionary_3