Exemple #1
0
 def _enter(self):
     self.__initial_params = None
     self.__target_clone = self.__target.current_clone
     first_update_time = self._start_time + self._exp._app.flip_interval
     clock.schedule(self.update, event_time=first_update_time,
                    repeat_interval=self._exp._app.flip_interval)
     clock.schedule(self.leave)
Exemple #2
0
    def _enter(self):
        super(If, self)._enter()

        self._outcome_index = self._cond.index(True)
        self.__selected_child = (
            self._out_states[self._outcome_index].get_inactive_state(self))
        clock.schedule(partial(self.__selected_child.enter, self._start_time))
Exemple #3
0
    def _enter(self):
        super(SoundFile, self)._enter()
        default_init_audio_server()
        self._sound_start_time = None

        # init the sound table (two steps to get mono in both speakers)
        sndtab = pyo.SndTable(initchnls=_pyo_server.getNchnls())
        sndtab.setSound(path=self._filename,
                        start=self._start,
                        stop=self._stop)

        # set the end time
        if not self._loop:
            self.cancel(self._start_time + sndtab.getDur())

        # read in sound info
        self.__snd = pyo.TableRead(sndtab,
                                   freq=sndtab.getRate(),
                                   loop=self._loop,
                                   mul=self._volume)
        if self.__snd is None:
            raise RuntimeError("Could not load sound file: %r" %
                               self._filename)

        # schedule playing the sound
        clock.schedule(self._start_sound, event_time=self._start_time)

        # schedule stopping the sound
        if self._end_time is not None:
            clock.schedule(self._stop_sound, event_time=self._end_time)
Exemple #4
0
    def _enter(self):
        super(SoundFile, self)._enter()
        default_init_audio_server()
        self._sound_start_time = None
        self._sound_stop_time = None

        # init the sound table (two steps to get mono in both speakers)
        sndtab = pyo.SndTable(initchnls=_pyo_server.getNchnls())
        sndtab.setSound(path=self._filename, start=self._start,
                        stop=self._stop)

        # set the end time
        if not self._loop:
            self.cancel(self._start_time + sndtab.getDur())

        # read in sound info
        self.__snd = pyo.TableRead(sndtab, freq=sndtab.getRate(),
                                   loop=self._loop,
                                   mul=self._volume)
        if self.__snd is None:
            raise RuntimeError("Could not load sound file: %r" %
                               self._filename)

        # schedule playing the sound
        clock.schedule(self._start_sound, event_time=self._start_time)

        # schedule stopping the sound
        if self._end_time is not None:
                clock.schedule(self._stop_sound, event_time=self._end_time)
Exemple #5
0
 def cancel(self, cancel_time):
     if self._active:
         cancel_time = max(cancel_time, self._start_time)
         if self._end_time is None or cancel_time < self._end_time:
             clock.unschedule(self.leave)
             clock.schedule(self.leave, event_time=cancel_time)
             self._end_time = cancel_time
Exemple #6
0
    def leave(self):
        """
        Gets the end time of the state (logs current time)
        """
        # ignore leave call if not active
        if self._following_may_run or not self._active:
            return

        self.claim_exceptions()

        self._leave_time = clock.now()

        self._following_may_run = True
        if self._parent:
            clock.schedule(partial(self._parent.child_leave_callback, self))

        # call custom leave code
        self._leave()

        if self.__tracing:
            call_time = self._leave_time - self._exp._root_state._start_time
            call_duration = clock.now() - self._leave_time
            if self._end_time is None:
                 self.print_trace_msg(
                    "LEAVE time=%fs, duration=%fs, perpetual" %
                    (call_time, call_duration))
            else:
                end_time = self._end_time - self._exp._root_state._start_time
                self.print_trace_msg(
                    "LEAVE time=%fs, duration=%fs, end_time=%fs" %
                    (call_time, call_duration, end_time))
Exemple #7
0
 def _enter(self):
     self.__initial_params = None
     self.__target_clone = self.__target.current_clone
     first_update_time = self._start_time + self._exp._app.flip_interval
     clock.schedule(self.update,
                    event_time=first_update_time,
                    repeat_interval=self._exp._app.flip_interval)
     clock.schedule(self.leave)
Exemple #8
0
 def _enter(self):
     super(RecordSoundFile, self)._enter()
     default_init_audio_server()
     if self._filename is None:
         self._filename = self._exp.reserve_data_filename(
             "audio_%s" % self._name, "wav", use_timestamp=True)
     clock.schedule(self._start_recording, event_time=self._start_time)
     if self._end_time is not None:
         clock.schedule(self._stop_recording, event_time=self._end_time)
Exemple #9
0
 def start_next_iteration(self, next_time):
     try:
         self._i = self.__i_iterator.next()
     except StopIteration:
         self._end_time = next_time
         clock.schedule(self.leave)
         return
     self.__current_child = self.__body_state.get_inactive_state(self)
     clock.schedule(partial(self.__current_child.enter, next_time))
Exemple #10
0
 def _enter(self):
     super(RecordSoundFile, self)._enter()
     default_init_audio_server()
     if self._filename is None:
         self._filename = self._exp.reserve_data_filename(
             "audio_%s" % self._name, "wav", use_timestamp=True)
     clock.schedule(self._start_recording, event_time=self._start_time)
     if self._end_time is not None:
         clock.schedule(self._stop_recording, event_time=self._end_time)
Exemple #11
0
    def _pulse_off_callback(self):
        self._task.write([0.0])
        ev = clock.now()

        # set the pulse time
        self._pulse_off = event_time(ev, 0.0)

        # let's schedule finalizing
        self._ended = True
        clock.schedule(self.finalize)
Exemple #12
0
 def cancel(self, cancel_time):
     if self._active:
         clock.schedule(self.leave)
         cancel_time = max(cancel_time, self._start_time)
         if self._end_time is not None:
             cancel_time = min(cancel_time, self._end_time)
         if self._end_time is None or cancel_time < self._end_time:
             if self.__disappear_video is not None:
                 self._exp._app.cancel_video(self.__disappear_video)
             self.__disappear_video = self._exp._app.schedule_video(
                 self.disappear, cancel_time, self.set_disappear_time)
             self._end_time = cancel_time
Exemple #13
0
 def _enter(self):
     super(Serial, self)._enter()
     self.__child_iterator = iter(self._children)
     self.__current_child = None
     self.__cancel_time = None
     try:
         self.__current_child = (
             self.__child_iterator.next().get_inactive_state(self))
         clock.schedule(partial(self.__current_child.enter, self._start_time))
     except StopIteration:
         self._end_time = self._start_time
         clock.schedule(self.leave)
Exemple #14
0
 def cancel(self, cancel_time):
     if self._active:
         clock.schedule(self.leave)
         cancel_time = max(cancel_time, self._start_time)
         if self._end_time is not None:
             cancel_time = min(cancel_time, self._end_time)
         if self._end_time is None or cancel_time < self._end_time:
             if self.__disappear_video is not None:
                 self._exp._app.cancel_video(self.__disappear_video)
             self.__disappear_video = self._exp._app.schedule_video(
                 self.disappear, cancel_time, self.set_disappear_time)
             self._end_time = cancel_time
Exemple #15
0
 def start_next_iteration(self, next_time):
     try:
         self._i = self.__i_iterator.next()
         if self._iterable is None or isinstance(self._iterable, int):
             self._current = self._i
         else:
             self._current = self._iterable[self._i]
     except StopIteration:
         self._end_time = next_time
         clock.schedule(self.leave)
         return
     self.__current_child = self.__body_state.get_inactive_state(self)
     clock.schedule(partial(self.__current_child.enter, next_time))
Exemple #16
0
    def finalize(self):  #TODO: call a _finalize method?
        if not self._active:
            return

        self._finalize_time = clock.now()
        self._active = False
        if self.__save_log:
            self.save_log()
        if self._parent:
            clock.schedule(partial(self._parent.child_finalize_callback, self))
        if self.__tracing:
            call_time = self._finalize_time - self._exp._root_state._start_time
            call_duration = clock.now() - self._finalize_time
            self.print_trace_msg("FINALIZE time=%fs, duration=%fs" %
                                 (call_time, call_duration))
Exemple #17
0
 def _enter(self):
     super(Beep, self)._enter()
     default_init_audio_server()
     self._sound_start_time = None
     if self._start_time == self._end_time:
         self.__fader = None
         self.__sine = None
     else:
         self.__fader = pyo.Fader(fadein=self._fadein,
                                  fadeout=self._fadeout,
                                  mul=self._volume)
         self.__sine = pyo.Sine(freq=self._freq, mul=self.__fader)
         clock.schedule(self._start_sound, event_time=self._start_time)
         if self._end_time is not None:
             clock.schedule(self._stop_sound,
                            event_time=self._end_time-self._fadeout)
Exemple #18
0
 def _enter(self):
     super(Parallel, self)._enter()
     self.__blocking_children = []
     self.__my_children = []
     if len(self._children):
         for child in self._children:
             inactive_child = child.get_inactive_state(self)
             self.__my_children.append(inactive_child)
             if child._blocking:
                 self.__blocking_children.append(inactive_child)
             clock.schedule(partial(inactive_child.enter, self._start_time))
         self.__remaining = set(self.__my_children)
         self.__blocking_remaining = set(self.__blocking_children)
     else:
         self._end_time = self._start_time
         clock.schedule(self.leave)
Exemple #19
0
 def _enter(self):
     super(Beep, self)._enter()
     default_init_audio_server()
     self._sound_start_time = None
     if self._start_time == self._end_time:
         self.__fader = None
         self.__sine = None
     else:
         self.__fader = pyo.Fader(fadein=self._fadein,
                                  fadeout=self._fadeout,
                                  mul=self._volume)
         self.__sine = pyo.Sine(freq=self._freq, mul=self.__fader)
         clock.schedule(self._start_sound, event_time=self._start_time)
         if self._end_time is not None:
             clock.schedule(self._stop_sound,
                            event_time=self._end_time - self._fadeout)
Exemple #20
0
 def child_leave_callback(self, child):
     super(Serial, self).child_leave_callback(child)
     next_time = self.__current_child._end_time
     if next_time is None:
         self.leave()
     elif (self.__cancel_time is not None and
         next_time >= self.__cancel_time):
         self._end_time = self.__cancel_time
         self.leave()
     else:
         try:
             self.__current_child = (
                 self.__child_iterator.next().get_inactive_state(self))
             clock.schedule(partial(self.__current_child.enter, next_time))
         except StopIteration:
             self._end_time = next_time
             clock.schedule(self.leave)
Exemple #21
0
    def _pulse_off_callback(self):
        # turn off the code
        start_time = clock.now()
        self._pport.setData(0)
        end_time = clock.now()

        # clean up / close the port
        self._pport = None

        # set the pulse time
        time_err = (end_time - start_time)/2.
        self._pulse_off = event_time(start_time+time_err,
                                     time_err)

        # let's schedule finalizing
        self._ended = True
        clock.schedule(self.finalize)
Exemple #22
0
 def update(self):
     self.claim_exceptions()
     now = clock.now()
     if self.__initial_params is None:
         self.__initial_params = {
             name : getattr(self.__target_clone, name).eval() for
             name in self.__anim_params.iterkeys()}
     if self._end_time is not None and now >= self._end_time:
         clock.unschedule(self.update)
         clock.schedule(self.finalize)
         now = self._end_time
     t = now - self._start_time
     params = {name : func(t, self.__initial_params[name]) for
               name, func in
               self.__anim_params.iteritems()}
     self.__target_clone.live_change(
         **self.__target_clone.transform_params(
             self.__target_clone.apply_aliases(params)))
Exemple #23
0
 def update(self):
     self.claim_exceptions()
     now = clock.now()
     if self.__initial_params is None:
         self.__initial_params = {
             name: getattr(self.__target_clone, name).eval()
             for name in self.__anim_params.iterkeys()
         }
     if self._end_time is not None and now >= self._end_time:
         clock.unschedule(self.update)
         clock.schedule(self.finalize)
         now = self._end_time
     t = now - self._start_time
     params = {
         name: func(t, self.__initial_params[name])
         for name, func in self.__anim_params.iteritems()
     }
     self.__target_clone.live_change(**self.__target_clone.transform_params(
         self.__target_clone.apply_aliases(params)))
Exemple #24
0
    def _pulse_off_callback(self):
        # turn off the code
        if self._sync_style == "parallel":
            start_time = clock.now()
            self._sport.setData(0)
            end_time = clock.now()
        else:
            start_time = clock.now()
            self._sport.setData("0")
            end_time = clock.now()
        # clean up / close the port
        self._sport = None

        # set the pulse time
        time_err = (end_time - start_time) / 2.
        self._pulse_off = event_time(start_time + time_err, time_err)

        # let's schedule finalizing
        self._ended = True
        clock.schedule(self.finalize)
Exemple #25
0
    def enter(self, start_time):
        self.claim_exceptions()
        self._start_time = start_time
        self._enter_time = clock.now()
        self._leave_time = None
        self._finalize_time = None
        self.__original_state.__most_recently_entered_clone = self

        # say we're active
        self._active = True
        self._following_may_run = False

        if self._parent:
            clock.schedule(partial(self._parent.child_enter_callback, self))

        # if we don't have the exp reference, get it now
        if self._exp is None:
            from experiment import Experiment
            self._exp = Experiment._last_instance()

        for name, value in self.__dict__.items():
            if name[:6] == "_init_":
                setattr(self, name[5:], val(value))

        if self._duration is None:
            self._end_time = None
        else:
            self._end_time = self._start_time + self._duration

        # custom enter code
        self._enter()

        if self.__tracing:
            call_time = self._enter_time - self._exp._root_state._start_time
            call_duration = clock.now() - self._enter_time
            start_time = self._start_time - self._exp._root_state._start_time
            self.print_trace_msg(
                "ENTER time=%fs, duration=%fs, start_time=%fs" %
                (call_time, call_duration, start_time))
Exemple #26
0
    def _callback(self):
        # we've started
        self._started = True

        # push it outlet
        global _got_nidaqmx
        if _got_nidaqmx:
            if type(self._push_vals == list):
                self._task.write(self._push_vals)
            else:
                self._task.write([self.push_vals])
            ev = clock.now()

        else:
            self._pulse_on = None
            self._pulse_off = None
            self._ended = True
            clock.schedule(self.leave)
            clock.schedule(self.finalize)
            return

        # set the pulse time
        self._pulse_on = event_time(ev, 0.0)

        # schedule leaving (as soon as this method is done)
        clock.schedule(self.leave)

        # schedule the off time
        if self._width > 0.0:
            # we're gonna turn off ourselves
            clock.schedule(self._pulse_off_callback,
                           event_time=self._pulse_on['time'] + self._width)
        else:
            # we're gonna leave it
            self._pulse_off = None

            # so we can finalize now, too
            clock.schedule(self.finalize)
            self._ended = True
Exemple #27
0
 def cancel(self, cancel_time):
     if self._active:
         if cancel_time < self._start_time:
             clock.unschedule(self.leave)
             clock.schedule(self.leave)
             clock.unschedule(self.finalize)
             clock.schedule(self.finalize)
             self._end_time = self._start_time
         elif self._end_time is None or cancel_time < self._end_time:
             clock.unschedule(self.finalize)
             clock.schedule(self.finalize, event_time=cancel_time)
             self._end_time = cancel_time
Exemple #28
0
 def cancel(self, cancel_time):
     if self._active:
         cancel_time = max(cancel_time, self._start_time)
         if self._end_time is not None:
             cancel_time = min(cancel_time, self._end_time)
         if self.__until is None:
             if self._end_time is None or cancel_time < self._end_time:
                 clock.unschedule(self.finalize)
                 clock.schedule(self.finalize, event_time=cancel_time)
                 self._end_time = cancel_time
         else:
             if self._end_time is None or cancel_time < self._end_time:
                 clock.unschedule(self.leave)
                 clock.unschedule(self.finalize)
                 clock.schedule(self.leave, event_time=cancel_time)
                 clock.schedule(self.finalize, event_time=cancel_time)
                 self._end_time = cancel_time
Exemple #29
0
 def cancel(self, cancel_time):
     super(Beep, self).cancel(cancel_time)
     clock.unschedule(self._stop_sound)
     clock.schedule(self._stop_sound,
                    event_time=self._end_time-self._fadeout)
Exemple #30
0
 def set_appear_time(self, appear_time):
     self._appear_time = appear_time
     clock.schedule(self.leave)
Exemple #31
0
 def set_disappear_time(self, disappear_time):
     self._disappear_time = disappear_time
     clock.schedule(self.finalize)
Exemple #32
0
 def set_disappear_time(self, disappear_time):
     self._disappear_time = disappear_time
     clock.schedule(self.finalize)
Exemple #33
0
 def child_enter_callback(self, child):
     super(Serial, self).child_enter_callback(child)
     if self.__cancel_time is not None:
         clock.schedule(partial(child.cancel, self.__cancel_time))
Exemple #34
0
 def _schedule_start(self):
     clock.schedule(self._callback, event_time=self._start_time)
Exemple #35
0
 def cancel(self, cancel_time):
     super(RecordSoundFile, self).cancel(cancel_time)
     clock.unschedule(self._stop_recording)
     clock.schedule(self._stop_recording, event_time=self._end_time)
Exemple #36
0
 def set_appear_time(self, appear_time):
     self._appear_time = appear_time
     self._on_screen = True
     self._appeared = True
     clock.schedule(self.leave)
Exemple #37
0
 def cancel(self, cancel_time):
     super(SoundFile, self).cancel(cancel_time)
     clock.unschedule(self._stop_sound)
     clock.schedule(self._stop_sound, event_time=self._end_time)
Exemple #38
0
    def _callback(self):
        # we've started
        self._started = True
        # Pull in the global variables
        global PI
        global SI
        if PI or SI:
            # send the port code and time it
            try:
                if self._sync_style == "parallel":
                    # Create a parallel port object
                    # from the global variable (locks it exclusively)
                    self._sport = PI(address=self._port)
                    start_time = clock.now()
                    self._sport.setData(self._code_num)
                    end_time = clock.now()
                elif self._sync_style == "serial":
                    self._sport = SI(address=self._port)
                    start_time = clock.now()
                    self._sport.setData(self._code_num)
                    end_time = clock.now()
            except:  # eventually figure out which errors to catch
                sys.stderr.write(
                    "\nWARNING: The sync module could not send pulses,\n" +
                    "\tso no sync pulsing will be generated.\n\n")
                PI = None
                self._pport = None
                self._pulse_on = None
                self._pulse_off = None
                self._ended = True
                clock.schedule(self.leave)
                clock.schedule(self.finalize)
                return

            # set the pulse time
            time_err = (end_time - start_time) / 2.
            self._pulse_on = event_time(start_time + time_err, time_err)

            # schedule leaving (as soon as this method is done)
            clock.schedule(self.leave)

            # schedule the off time
            if self._width > 0.0:
                # we're gonna turn off ourselves
                clock.schedule(self._pulse_off_callback,
                               event_time=self._pulse_on['time'] + self._width)
            else:
                # we're gonna leave it
                self._pulse_off = None

                # clean up/ close the port
                self._sport = None

                # so we can finalize now, too
                clock.schedule(self.finalize)
                self._ended = True

        else:
            # we can leave and finalize now
            self._pulse_on = None
            self._pulse_off = None
            self._ended = True
            clock.schedule(self.leave)
            clock.schedule(self.finalize)
Exemple #39
0
 def cancel(self, cancel_time):
     super(RecordSoundFile, self).cancel(cancel_time)
     clock.unschedule(self._stop_recording)
     clock.schedule(self._stop_recording, event_time=self._end_time)
Exemple #40
0
 def cancel(self, cancel_time):
     if self._active:
         clock.schedule(partial(self.__current_child.cancel, cancel_time))
         self.__cancel_time = cancel_time
Exemple #41
0
 def set_disappear_time(self, disappear_time):
     self._disappear_time = disappear_time
     self._on_screen = False
     self._disappeared = True
     clock.schedule(self.finalize)
Exemple #42
0
 def set_disappear_time(self, disappear_time):
     self._disappear_time = disappear_time
     self._on_screen = False
     self._disappeared = True
     clock.schedule(self.finalize)
Exemple #43
0
 def cancel(self, cancel_time):
     super(SoundFile, self).cancel(cancel_time)
     clock.unschedule(self._stop_sound)
     clock.schedule(self._stop_sound, event_time=self._end_time)
Exemple #44
0
 def cancel(self, cancel_time):
     super(Beep, self).cancel(cancel_time)
     clock.unschedule(self._stop_sound)
     clock.schedule(self._stop_sound,
                    event_time=self._end_time - self._fadeout)
Exemple #45
0
 def set_appear_time(self, appear_time):
     self._appear_time = appear_time
     self._on_screen = True
     self._appeared = True
     clock.schedule(self.leave)
Exemple #46
0
 def set_appear_time(self, appear_time):
     self._appear_time = appear_time
     clock.schedule(self.leave)
Exemple #47
0
 def _leave(self):
     if not len(self._children) or not len(self.__unfinalized_children):
         clock.schedule(self.finalize)
Exemple #48
0
 def cancel(self, cancel_time):
     if self._active and not self._following_may_run:
         clock.schedule(self.leave, event_time=cancel_time)
         #QUESTION: Should this do anything in the base class at all?
         if self._end_time is None or cancel_time < self._end_time:
             self._end_time = cancel_time