示例#1
0
文件: video.py 项目: compmem/psyqt
    def swapBuffers(self):
        # first call the swap on the QGLWidget
        start = long(now()*1000)

        self.glw.swapBuffers()

        #self.glw.makeCurrent()

        # The following is taken from the PsychToolbox
        # Draw a single pixel in left-top area of back-buffer. 
        # This will wait/stall the rendering pipeline
        # until the buffer flip has happened, aka immediately after the VBL has started.
        # We need the pixel as "synchronization token", so the following glFinish() really
        # waits for VBL instead of just "falling through" due to the asynchronous nature of
        # OpenGL:
        glDrawBuffer(GL_BACK)
        # We draw our single pixel with an alpha-value of zero - so effectively it doesn't
        # change the color buffer - just the z-buffer if z-writes are enabled...
        glColor4f(0.0,0.0,0.0,0.0)
        glBegin(GL_POINTS)
        glVertex2i(10,10)
        glEnd()
        # This glFinish() will wait until point drawing is finished, ergo backbuffer was ready
        # for drawing, ergo buffer swap in sync with start of VBL has happened.
        glFinish()

        finish = long(now()*1000)
        fdiff = finish - self.last_finish
        self.last_finish = finish
        return (start,finish-start,fdiff)
示例#2
0
    def swapBuffers(self):
        # first call the swap on the QGLWidget
        start = long(now() * 1000)

        self.glw.swapBuffers()

        #self.glw.makeCurrent()

        # The following is taken from the PsychToolbox
        # Draw a single pixel in left-top area of back-buffer.
        # This will wait/stall the rendering pipeline
        # until the buffer flip has happened, aka immediately after the VBL has started.
        # We need the pixel as "synchronization token", so the following glFinish() really
        # waits for VBL instead of just "falling through" due to the asynchronous nature of
        # OpenGL:
        glDrawBuffer(GL_BACK)
        # We draw our single pixel with an alpha-value of zero - so effectively it doesn't
        # change the color buffer - just the z-buffer if z-writes are enabled...
        glColor4f(0.0, 0.0, 0.0, 0.0)
        glBegin(GL_POINTS)
        glVertex2i(10, 10)
        glEnd()
        # This glFinish() will wait until point drawing is finished, ergo backbuffer was ready
        # for drawing, ergo buffer swap in sync with start of VBL has happened.
        glFinish()

        finish = long(now() * 1000)
        fdiff = finish - self.last_finish
        self.last_finish = finish
        return (start, finish - start, fdiff)
示例#3
0
文件: video.py 项目: mcauley16/psyqt
    def _run(self):
        start = long(now()*1000)
        vid.swapBuffers()
        print "Swap:", start, long(now()*1000)-start
        # record when the swap returns indicating the vertical retrace
        # just happened.
        
        # essentially, we need to know when the vertical retrace
        # actually happened

        self._finalize()
示例#4
0
    def _pulse_off_callback(self, dt):
        # turn off the code
        start_time = now()
        self._pport.setData(0)
        end_time = now()

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

        # set the pulse time
        time_err = (end_time - start_time) / 2.
        self.pulse_end_time = event_time(start_time + time_err, time_err)
示例#5
0
文件: pulse.py 项目: mjgilles/smile
    def _pulse_off_callback(self, dt):
        # turn off the code
        start_time = now()
        self._pport.setData(0)
        end_time = now()

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

        # set the pulse time
        time_err = (end_time - start_time)/2.
        self.pulse_end_time = event_time(start_time+time_err,
                                         time_err)
示例#6
0
文件: video.py 项目: psederberg/smile
    def update_callback(self, dt):
        # call the user-defined show
        self.shown = self._update_callback(dt)
        self.last_update = now()

        # tell the exp window we need a draw
        self.exp.window.need_draw = True
示例#7
0
 def _callback(self, dt):
     if not self.waiting:
         self.exp.window.key_callbacks.append(self._key_callback)
         self.waiting = True
     if self.wait_duration > 0 and now() >= self.state_time+self.wait_duration:
         # we're done
         self.leave()
示例#8
0
 def _callback(self, dt):
     if not self.waiting:
         self.exp.window.mouse_callbacks.append(self._mouse_callback)
         self.waiting = True
     wait_duration = val(self.wait_duration)
     if ((wait_duration > 0 and now() >= self.state_time+wait_duration) or
         (val(self.wait_until))):
         # we're done
         self.leave()
示例#9
0
    def update_callback(self, dt):
        # call the user-defined show
        self.shown = self._update_callback(dt)
        self.last_update = now()
        if self.first_update == 0:
            self.first_update = self.last_update

        # tell the exp window we need a draw
        self.exp.window.need_draw = True
示例#10
0
 def _callback(self, dt):
     if not self.waiting:
         self.exp.window.key_callbacks.append(self._key_callback)
         self.waiting = True
     if self.base_time is None:
         self.base_time = val(self.base_time_src)
         if self.base_time is None:
             # set it to the state time
             self.base_time = self.state_time
     wait_duration = val(self.wait_duration)
     if (not wait_duration is None) and (now() >= self.base_time + wait_duration):
         self.leave()
     elif val(self.wait_until):
         self.leave()
示例#11
0
文件: keyboard.py 项目: eweich/smile
 def _callback(self, dt):
     if not self.waiting:
         self.exp.window.key_callbacks.append(self._key_callback)
         self.waiting = True
     if self.base_time is None:
         self.base_time = val(self.base_time_src)
         if self.base_time is None:
             # set it to the state time
             self.base_time = self.state_time
     wait_duration = val(self.wait_duration)
     if (not wait_duration is None) and (now() >=
                                         self.base_time + wait_duration):
         self.leave()
     elif val(self.wait_until):
         self.leave()
示例#12
0
文件: pulse.py 项目: mjgilles/smile
    def _callback(self, dt):        
        # Convert code if necessary
        code = val(self.pulse_code)
        if type(code)==str:
            if code[0]=="S":
                # Use first 4 bits
                ncode = int(code[1:])
                if ncode < 0 or ncode > 16: ncode = 15
            elif code[0]=="R":
                # Use last 4 bits
                ncode = int(code[1:])
                if ncode < 0 or ncode > 16: ncode = 15
                ncode = ncode >> 4
            else:
                # Convert to an integer
                ncode = int(code)
        else:
            ncode = int(code)

        # send the code
        if have_parallel:
            # Create a parallel port object (locks it exclusively)
            self._pport = parallel.Parallel(port=self.pulse_port)

            # send the port code and time it
            start_time = now()
            self._pport.setData(ncode)
            end_time = now()

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

            # schedule the off time
            clock.schedule_once(self._pulse_off_callback, val(self.pulse_duration))
示例#13
0
    def _enter(self):
        # reset times
        self.last_update = 0
        self.last_flip = 0
        self.last_draw = 0
        self.first_update = 0
        self.first_flip = 0
        self.first_draw = 0

        # the flip will already be scheduled
        # schedule the show
        update_delay = self.state_time - now()
        if update_delay < 0:
            update_delay = 0
        self.schedule_update(update_delay)
示例#14
0
    def _enter(self):
        # reset times
        self.last_update = 0
        self.last_flip = 0
        self.last_draw = 0
        self.first_update = 0
        self.first_flip = 0
        self.first_draw = 0

        # the flip will already be scheduled
        # schedule the show
        update_delay = self.state_time - now()
        if update_delay < 0:
            update_delay = 0
        self.schedule_update(update_delay)
示例#15
0
    def _callback(self, dt):
        # Convert code if necessary
        code = val(self.pulse_code)
        if type(code) == str:
            if code[0] == "S":
                # Use first 4 bits
                ncode = int(code[1:])
                if ncode < 0 or ncode > 16: ncode = 15
            elif code[0] == "R":
                # Use last 4 bits
                ncode = int(code[1:])
                if ncode < 0 or ncode > 16: ncode = 15
                ncode = ncode >> 4
            else:
                # Convert to an integer
                ncode = int(code)
        else:
            ncode = int(code)

        # send the code
        if have_parallel:
            # Create a parallel port object (locks it exclusively)
            self._pport = parallel.Parallel(port=self.pulse_port)

            # send the port code and time it
            start_time = now()
            self._pport.setData(ncode)
            end_time = now()

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

            # schedule the off time
            clock.schedule_once(self._pulse_off_callback,
                                val(self.pulse_duration))
示例#16
0
文件: video.py 项目: compmem/psyqt
 def _run(self):
     # add the items
     print "Hide:", long(now()*1000)
     for i in self.items:
         gui.scene.removeItem(i)
     self._finalize()
示例#17
0
文件: video.py 项目: compmem/psyqt
 def _run(self):
     # add the items
     print "Show:", long(now()*1000)
     for i in self.items:
         gui.scene.addItem(i)
     self._finalize()
示例#18
0
 def _callback(self, dt):
     self._rec = pyo.Record(
         pyo.Input(), filename=self.filepath, chnls=2, fileformat=0,
         sampletype=1, buffering=16)
     self.rec_start = event_time(now())
     pyo.Clean_objects(self.duration, self._rec).start()
示例#19
0
 def print_dt(state, *txt):
     for t in txt:
         print t
     print now()-state.state_time, state.dt
     print
示例#20
0
 def draw_callback(self, dt):
     # call the draw (not forced, so it can skip it)
     self.exp.window.on_draw()
     self.last_draw = now()
     if self.first_draw == 0:
         self.first_draw = self.last_draw
示例#21
0
文件: audio.py 项目: eweich/smile
 def _callback(self, dt):
     # play the sound
     self._snd.out()
     self.sound_start = event_time(now())
示例#22
0
 def _callback(self, dt):
     self._fader.play()
     self.sound_start = event_time(now())
示例#23
0
 def _run(self):
     # add the items
     print "Show:", long(now() * 1000)
     for i in self.items:
         gui.scene.addItem(i)
     self._finalize()
示例#24
0
 def draw_callback(self, dt):
     # call the draw (not forced, so it can skip it)
     self.exp.window.on_draw()
     self.last_draw = now()
     if self.first_draw == 0:
         self.first_draw = self.last_draw
示例#25
0
 def _run(self):
     # add the items
     print "Hide:", long(now() * 1000)
     for i in self.items:
         gui.scene.removeItem(i)
     self._finalize()
示例#26
0
 def _callback(self, dt):
     # play the sound
     self._snd.out()
     self.sound_start = event_time(now())
示例#27
0
 def print_dt(state, *txt):
     for t in txt:
         print t
     print now()-state.state_time, state.dt
     print
示例#28
0
文件: audio.py 项目: eweich/smile
 def _callback(self, dt):
     self._fader.play()
     self.sound_start = event_time(now())