예제 #1
0
 def test_add_to_head_04(self):
     nodes = [nonrealtimetools.Group(None, i) for i in range(3)]
     nodes_to_children = {
         nodes[0]: (nodes[1], nodes[2]),
         nodes[1]: None,
         nodes[2]: None,
     }
     nodes_to_parents = {
         nodes[0]: None,
         nodes[1]: nodes[0],
         nodes[2]: nodes[0],
     }
     action = nonrealtimetools.NodeAction(
         source=nodes[1],
         target=nodes[0],
         action=servertools.AddAction.ADD_TO_HEAD,
     )
     action.apply_transform(nodes_to_children, nodes_to_parents)
     assert nodes_to_children == {
         nodes[0]: (nodes[1], nodes[2]),
         nodes[1]: None,
         nodes[2]: None,
     }
     assert nodes_to_parents == {
         nodes[0]: None,
         nodes[1]: nodes[0],
         nodes[2]: nodes[0],
     }
예제 #2
0
 def move_node(
     self,
     node,
     add_action=None,
 ):
     from supriya.tools import nonrealtimetools
     assert self.session.active_moments
     state = self.session.active_moments[-1].state
     if state.nodes_to_parents is None:
         state._desparsify()
     if (node in state.nodes_to_parents and node in self.get_parentage()):
         raise ValueError("Can't add parent as a child.")
     add_action = servertools.AddAction.from_expr(add_action)
     node_action = nonrealtimetools.NodeAction(
         source=node,
         target=self,
         action=add_action,
     )
     state.transitions[node] = node_action
     self.session._apply_transitions([state.offset, node.stop_offset])
예제 #3
0
 def set_duration(self, new_duration):
     from supriya.tools import nonrealtimetools
     if self.duration == new_duration:
         return
     if new_duration < self.duration:
         split_offset = self.start_offset + new_duration
         with self.session.at(split_offset):
             old_node, new_node = self.split(
                 split_occupiers=False,
                 split_traversers=False,
             )
             new_node.delete()
         self.session._find_state_at(new_node.stop_offset)._sparsify()
     else:
         old_stop_offset = self.stop_offset
         new_stop_offset = self.start_offset + new_duration
         with self.session.at(old_stop_offset, propagate=False) as moment:
             parent = self.get_parent()
             moment.state.stop_nodes.remove(self)
             moment.state._sparsify()
         self._duration = new_duration
         while parent is not None and parent.stop_offset < new_stop_offset:
             with self.session.at(parent.stop_offset,
                                  propagate=False) as moment:
                 action = nonrealtimetools.NodeAction(
                     source=self,
                     target=parent,
                     action='ADD_BEFORE',
                 )
                 moment.state.transitions[self] = action
                 parent = parent.get_parent()
         with self.session.at(new_stop_offset, propagate=False) as moment:
             moment.state.stop_nodes.add(self)
         with self.session.at(self.start_offset, propagate=False) as moment:
             self.session._apply_transitions(moment.state.offset)
         self.session._apply_transitions([
             self.start_offset,
             old_stop_offset,
             new_stop_offset,
         ])
예제 #4
0
파일: State.py 프로젝트: lisongx/supriya
 def _find_first_inconsistency(
     cls,
     root_node,
     nodes_to_children_one,
     nodes_to_children_two,
     stop_nodes,
     ):
     from supriya.tools import nonrealtimetools
     for parent in cls._iterate_nodes(root_node, nodes_to_children_one):
         if parent in stop_nodes:
             continue
         children_one = nodes_to_children_one.get(parent) or ()
         children_one = [
             node for node in children_one
             if node not in stop_nodes
             ]
         children_two = nodes_to_children_two.get(parent) or ()
         if children_one == children_two or not children_two:
             continue
         for i, child in enumerate(children_two):
             if not children_one:
                 action = 'ADD_TO_HEAD'
                 target = parent
             elif len(children_one) <= i:
                 action = 'ADD_AFTER'
                 target = children_one[i - 1]
             elif children_one[i] is not child:
                 action = 'ADD_BEFORE'
                 target = children_one[i]
             else:
                 continue
             transition = nonrealtimetools.NodeAction(
                 source=child,
                 target=target,
                 action=action,
                 )
             return transition
예제 #5
0
 def _split(
     self,
     split_offset,
     new_nodes=None,
     split_occupiers=True,
     split_traversers=True,
 ):
     from supriya.tools import nonrealtimetools
     new_nodes = new_nodes or []
     state = self.session.states[split_offset]
     entering, exiting, occupying, starting, _ = \
         self.inspect_children()
     children = state.nodes_to_children.get(self) or ()
     start_offset, stop_offset = self.start_offset, self.stop_offset
     if start_offset < split_offset < stop_offset:
         old_actions = state.transitions
         new_duration = stop_offset - split_offset
         with nonrealtimetools.DoNotPropagate():
             if isinstance(self, nonrealtimetools.Synth):
                 new_node = self.add_synth(add_action='ADD_BEFORE',
                                           duration=new_duration,
                                           synthdef=self.synthdef,
                                           **self._synth_kwargs)
             else:
                 new_node = self.add_group(
                     add_action='ADD_BEFORE',
                     duration=new_duration,
                 )
         new_nodes.append(new_node)
         new_actions = collections.OrderedDict()
         for node in new_nodes:
             if node is new_node and self in old_actions:
                 old_actions.pop(node)
                 action = old_actions.pop(self)
                 new_actions[node] = new(
                     action,
                     source=new_node,
                 )
             else:
                 new_actions[node] = old_actions.pop(node)
         for child in reversed(children):
             if child in old_actions:
                 old_actions.pop(child)
             action = nonrealtimetools.NodeAction(
                 source=child,
                 target=new_node,
                 action='ADD_TO_TAIL',
             )
             new_actions[child] = action
         new_actions.update(old_actions)
         state._transitions = new_actions
         self._fixup_events(new_node, split_offset)
         self._fixup_duration(split_offset - start_offset)
         self._fixup_node_actions(new_node, split_offset, stop_offset)
         self.session._apply_transitions(
             [new_node.start_offset, new_node.stop_offset], )
         result = [self, new_node]
     else:
         return [self]
     for child in children + exiting:
         if ((split_occupiers and child in occupying)
                 or (split_traversers and child in entering)
                 or (split_traversers and child in exiting)):
             child._split(
                 split_offset,
                 new_nodes=new_nodes,
                 split_occupiers=split_occupiers,
                 split_traversers=split_traversers,
             )
     return result