Exemplo n.º 1
0
    def new_event(self, date, event_index=None):
        '''returns a new event'''

        # if not any memory is loaded
        if not "_self" in self.current_streamview.atoms.keys():
            return None

        # if event is specified, play it now
        if event_index != None:
            self.reset()
            event_index = int(event_index)
            z_, event = self.current_streamview.atoms["_self"].memorySpace[
                event_index]
            # using actual transformation?
            transforms = [Transforms.NoTransform()]
            self.waiting_to_jump = False
        else:
            # get global activity
            global_activity = self.get_merged_activity(
                date, merge_actions=self.merge_actions)

            # if going to jump, erases peak in neighbour event
            if self.waiting_to_jump:
                zetas = global_activity.get_dates_list()
                states, _ = self.current_streamview.atoms[
                    "_self"].memorySpace.get_events(zetas)
                for i in range(0, len(states)):
                    if states[i].index == self.improvisation_memory[-1][
                            0].index + 1:
                        del global_activity[i]
                self.waiting_to_jump = False

            if len(global_activity) != 0 and len(
                    self.improvisation_memory) > 0:
                event, transforms = self.decide(global_activity)
                if event == None:
                    # if no event returned, choose default
                    event, transforms = self.decide_default()
                if type(transforms) != list:
                    transforms = [transforms]
            else:
                # if activity is empty, choose default
                event, transforms = self.decide_default()
            for transform in transforms:
                event = transform.decode(event)
        # add event to improvisation memory
        self.improvisation_memory.append((event, transforms))
        # influences private streamview if auto-influence activated
        if self.self_influence:
            self.current_streamview.influence("_self", date, event.get_label())
        # sends state num
        self.send([
            event.index,
            event.get_contents().get_zeta(),
            event.get_contents().get_state_length()
        ], "/state")
        return event
Exemplo n.º 2
0
 def decide_default(self):
     '''default decision method : selecting conjoint event'''
     if len(self.improvisation_memory) != 0:
         previousState = self.improvisation_memory[-1][0]
         new = self.current_streamview.atoms["_self"].memorySpace[
             (previousState.index + 1) %
             len(self.current_streamview.atoms["_self"].memorySpace)]
         trans = self.improvisation_memory[-1][1]
     else:
         new = self.current_streamview.atoms["_self"].memorySpace[0]
         trans = [Transforms.NoTransform()]
     return new[1], trans