Exemple #1
0
   def main(self):
      """Main loop."""
      
      displayservice = PygameDisplay.getDisplayService()
      self.link((self,"display_signal"), displayservice)
      
      # request a surface
      self.send(self.disprequest, "display_signal")


      # main loop
      done = False
      change = False    
      alpha = 255
      dir = -10
      while not done:
         if self.dataReady("alphacontrol"):
              alpha = self.recv("alphacontrol")
              self.display.set_alpha(alpha)
         if self.dataReady("control"):
            print "we do get here..."
            cmsg = self.recv("control")
            if isinstance(cmsg, producerFinished) or isinstance(cmsg, shutdownMicroprocess):
               self.send(cmsg,"signal")
               done = True
         
         # if we're given a new surface, use that instead
         if self.dataReady("callback"):
            if self.display is None:
               self.display = self.recv("callback")
               change = True
               for x in xrange(15): yield 1
               message = { "ADDLISTENEVENT" : pygame.KEYDOWN,
                           "surface" : self.display}
               self.send(message, "display_signal")

         if self.dataReady("inbox"):
            newImg = self.recv("inbox")
            if not self.expect_file_strings:
                self.fetchImage(newImg)
            else:
                self.imageFromString(newImg)
            change = True
            
         if self.dataReady("bgcolour"):
             self.backgroundColour = self.recv("bgcolour")
             change = True
            
         if change:
            self.blitToSurface()
            self.send({"REDRAW":True, "surface":self.display}, "display_signal")
            change = False

         self.pause()
         yield 1
      print "HERE"
      self.display.set_alpha(0)
      self.send(Axon.Ipc.producerFinished(message=self.display), "display_signal") 
      yield 1
      print "NOT HERE"
Exemple #2
0
    def main(self):
        """Main loop."""
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayservice)

        self.send(self.disprequest, "display_signal")

        for _ in self.waitBox("callback"):
            yield 1
        self.display = self.recv("callback")

        self.send(
            {
                "ADDLISTENEVENT": pygame.MOUSEBUTTONDOWN,
                "surface": self.display
            }, "display_signal")
        if (self.key_events is not None) or self.allkeys or (self.key_up_events
                                                             is not None):
            message = {
                "ADDLISTENEVENT": pygame.KEYDOWN,
                "surface": self.display,
                "TRACE": "ME"
            }
            self.send(message, "display_signal")

        if self.allkeys or (self.key_up_events is not None):
            message = {
                "ADDLISTENEVENT": pygame.KEYUP,
                "surface": self.display,
                "TRACE": "METO"
            }
            self.send(message, "display_signal")

        done = False
        while not done:
            if self.dataReady("control"):
                cmsg = self.recv("control")
                if isinstance(cmsg, producerFinished) or isinstance(
                        cmsg, shutdownMicroprocess):
                    done = True

            while self.dataReady("inbox"):
                for event in self.recv("inbox"):
                    if event.type == pygame.KEYDOWN:
                        if event.key in self.key_events:
                            self.send(self.key_events[event.key][0],
                                      self.key_events[event.key][1])
                        if self.allkeys:
                            self.send(("DOWN", event.key), "allkeys")
                    if event.type == pygame.KEYUP:
                        if event.key in self.key_up_events:
                            self.send(self.key_up_events[event.key][0],
                                      self.key_up_events[event.key][1])
                        if self.allkeys:
                            self.send(("UP", event.key), "allkeys")
            yield 1

        self.send(Axon.Ipc.producerFinished(message=self.display),
                  "display_signal")
        yield 1
 def main(self):
     """Main loop."""
     
     displayservice = PygameDisplay.getDisplayService()
     self.link((self,"display_signal"), displayservice)
     
     while 1:
         # wait for a frame
         frame = False
         while not frame:
             if self.dataReady("inbox"):
                 frame = self.recv("inbox")
                 
                 if self.shutdown():
                     return
           
             if not self.anyReady():
                 self.pause()
             yield 1
           
         # is it the same format as our current frame?
         if self.formatChanged(frame):
             if self.display:
                 raise "Can't cope with a format change yet!"
             
             self.size = frame['size']
             self.pixformat = frame['pixformat']
             
             if self.pixformat != "RGB_interleaved":
                 raise "Can't cope with any pixformat other than RGB_interleaved"
           
   
             # request a surface
             # build the initial request to send to Pygame Display to obtain a surface
             # but store it away until main() main loop is activated.
             dispRequest = { "DISPLAYREQUEST" : True,
                             "callback" : (self,"callback"),
                             "size": self.size,
                             "position" : self.position
                           }
                           
             self.send(dispRequest, "display_signal")
             
             # wait for the surface back
             yield WaitComplete(self.waitBox("callback"))
             self.display = self.recv("callback")
             
         # now render our frame
         image = pygame.image.fromstring(frame['rgb'], frame['size'], "RGB", False)
   
         self.display.blit(image, (0,0))
         self.send({"REDRAW":True, "surface":self.display}, "display_signal")
         
         # deal with possible shutdown requests
         if self.shutdown():
             return
         
         if not self.anyReady():
             self.pause()
             yield 1
Exemple #4
0
    def main(self):
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayservice)
        self.send(self.disprequest, "display_signal")
        while not self.dataReady("callback"):
            self.pause()
            yield 1

        self.init_cat()  # can only do this after we have a display!
        surface = self.recv("callback")
        surface.blit(self.img, (0, 0))
        self.send({"REDRAW": True, "surface": surface}, "display_signal")
        self.send(
            {
                "CHANGEDISPLAYGEO": True,
                "surface": surface,
                "position": (100, 100)
            }, "display_signal")
        yield 1
        while 1:
            for i in xrange(100, 800, 10):
                self.send(
                    {
                        "CHANGEDISPLAYGEO": True,
                        "surface": surface,
                        "position": (i, 100)
                    }, "display_signal")
                time.sleep(0.02)
                yield 1

            for i in xrange(100, 600, 10):
                self.send(
                    {
                        "CHANGEDISPLAYGEO": True,
                        "surface": surface,
                        "position": (800, i)
                    }, "display_signal")
                time.sleep(0.02)
                yield 1

            for i in xrange(800, 100, -10):
                self.send(
                    {
                        "CHANGEDISPLAYGEO": True,
                        "surface": surface,
                        "position": (i, 600)
                    }, "display_signal")
                time.sleep(0.02)
                yield 1

            for i in xrange(600, 100, -10):
                self.send(
                    {
                        "CHANGEDISPLAYGEO": True,
                        "surface": surface,
                        "position": (100, i)
                    }, "display_signal")
                time.sleep(0.02)
                yield 1
Exemple #5
0
 def getDisplay(self):
    displayservice = PygameDisplay.getDisplayService()
    self.link((self,"display_signal"), displayservice)
    self.send(self.disprequest, "display_signal")
    while not self.dataReady("callback"):
        self.pause()
        yield 1
    self.display = self.recv("callback")
Exemple #6
0
 def getDisplay(self):
     displayservice = PygameDisplay.getDisplayService()
     self.link((self, "display_signal"), displayservice)
     self.send(self.disprequest, "display_signal")
     while not self.dataReady("callback"):
         self.pause()
         yield 1
     self.display = self.recv("callback")
Exemple #7
0
   def requestDisplay(self, **argd):
      """\
      Generator. Gets a display surface from the Pygame Display service.

      Makes the request, then yields 1 until a display surface is returned.
      """
      displayservice = PygameDisplay.getDisplayService()
      self.link((self,"displaysignal"), displayservice)
      self.send(argd, "displaysignal")
      for _ in self.waitBox("display_control"): yield 1
      display = self.recv("display_control")
      self.display = display
Exemple #8
0
   def main(self):
      """Main loop."""
      displayservice = PygameDisplay.getDisplayService()
      self.link((self,"display_signal"), displayservice)

      self.send( self.disprequest,
                  "display_signal")
             
      for _ in self.waitBox("callback"): yield 1
      self.display = self.recv("callback")
      self.blitToSurface()
      
      self.send({ "ADDLISTENEVENT" : pygame.MOUSEBUTTONDOWN,
                  "surface" : self.display},
                  "display_signal")
      if self.key is not None:
###         print "ADDING LISTEN", self.key, pygame.KEYDOWN, self.display
         message = { "ADDLISTENEVENT" : pygame.KEYDOWN,
                     "surface" : self.display,
                     "TRACE" : "ME"}
###         print "----------------", message
         self.send(message, "display_signal")
#      while self.outboxes["display_signal"]  != []:
#         print dir(self)
#         print "Waiting clean out", self.outboxes["display_signal"], self
#         yield 1
      done = False
      while not done:
         while self.dataReady("control"):
            cmsg = self.recv("control")
            if isinstance(cmsg, producerFinished) or isinstance(cmsg, shutdownMicroprocess):
               self.send(cmsg, "signal")
               done = True
#               print "Shutdown recieved, exitting", self.caption
         
         while self.dataReady("inbox"):
            for event in self.recv("inbox"):
###                print event
                if event.type == pygame.MOUSEBUTTONDOWN:
#                   print "BUTTON", event.button
                   bounds = self.display.get_rect()
                   if bounds.collidepoint(*event.pos):
                      self.send( self.eventMsg, "outbox" )
                if event.type == pygame.KEYDOWN:
###                   print "EVENT", event.type, event.key
                   if event.key == self.key:
                      self.send( self.eventMsg, "outbox" )
         self.pause()
         yield 1

      self.display.set_alpha(0)
      self.send(Axon.Ipc.producerFinished(message=self.display), "display_signal")
      yield 1
Exemple #9
0
   def requestDisplay(self, **argd):
      """\
      Generator. Gets a display surface from the Pygame Display service.

      Makes the request, then yields 1 until a display surface is returned.
      """
      displayservice = PygameDisplay.getDisplayService()
      self.link((self,"displaysignal"), displayservice)
      self.send(argd, "displaysignal")
      for _ in self.waitBox("display_control"): yield 1
      display = self.recv("display_control")
      self.display = display
Exemple #10
0
   def main(self):
      """Main loop."""
      displayservice = PygameDisplay.getDisplayService()
      self.link((self,"display_signal"), displayservice)

      self.send( self.disprequest,
                  "display_signal")

      for _ in self.waitBox("callback"): yield 1
      self.display = self.recv("callback")

      self.send({ "ADDLISTENEVENT" : pygame.MOUSEBUTTONDOWN,
                  "surface" : self.display},
                  "display_signal")
      if (self.key_events is not None) or self.allkeys or (self.key_up_events is not None):
         message = { "ADDLISTENEVENT" : pygame.KEYDOWN,
                     "surface" : self.display,
                     "TRACE" : "ME"}
         self.send(message, "display_signal")

      if self.allkeys or (self.key_up_events is not None):
         message = { "ADDLISTENEVENT" : pygame.KEYUP,
                     "surface" : self.display,
                     "TRACE" : "METO"}
         self.send(message, "display_signal")

      done = False
      while not done:
         if self.dataReady("control"):
            cmsg = self.recv("control")
            if isinstance(cmsg, producerFinished) or isinstance(cmsg, shutdownMicroprocess):
               done = True

         while self.dataReady("inbox"):
            for event in self.recv("inbox"):
                if event.type == pygame.KEYDOWN:
                   if event.key in self.key_events:
                      self.send( self.key_events[event.key][0] , self.key_events[event.key][1] )
                   if self.allkeys:
                      self.send(("DOWN", event.key), "allkeys")
                if event.type == pygame.KEYUP:
                   if event.key in self.key_up_events:
                      self.send( self.key_up_events[event.key][0] , self.key_up_events[event.key][1] )
                   if self.allkeys:
                      self.send(("UP", event.key), "allkeys")
         yield 1

      self.send(Axon.Ipc.producerFinished(message=self.display), "display_signal")
      yield 1
Exemple #11
0
    def main(self):
        displayservice = PygameDisplay.getDisplayService()
        self.link((self,"display_signal"), displayservice)
        self.send(self.disprequest, "display_signal")
        while not self.dataReady("callback"):
            self.pause()
            yield 1

        self.init_cat() # can only do this after we have a display!
        surface = self.recv("callback")
        surface.blit(self.img, (0,0))
        self.send({"REDRAW":True, "surface":surface}, "display_signal")
        self.send({ "CHANGEDISPLAYGEO" : True,
                    "surface" : surface,
                    "position": (100,100) }, "display_signal")
        yield 1
        while 1:
            for i in xrange(100,800,10):
                self.send({ "CHANGEDISPLAYGEO" : True,
                            "surface" : surface,
                            "position": (i,100) }, "display_signal")
                time.sleep(0.02)
                yield 1

            for i in xrange(100,600,10):
                self.send({ "CHANGEDISPLAYGEO" : True,
                            "surface" : surface,
                            "position": (800,i) }, "display_signal")
                time.sleep(0.02)
                yield 1

            for i in xrange(800,100,-10):
                self.send({ "CHANGEDISPLAYGEO" : True,
                            "surface" : surface,
                            "position": (i,600) }, "display_signal")
                time.sleep(0.02)
                yield 1


            for i in xrange(600,100,-10):
                self.send({ "CHANGEDISPLAYGEO" : True,
                            "surface" : surface,
                            "position": (100,i) }, "display_signal")
                time.sleep(0.02)
                yield 1
Exemple #12
0
    def main(self):
        """Main loop. Do not override"""
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "displaysignal"), displayservice)
        displayrequest = {
            "DISPLAYREQUEST": True,
            "events": (self, "events"),
            "callback": (self, "displaycontrol"),
            "transparency": self.transparency,
            "size": self.screensize,
        }
        if self.position is not None:
            displayrequest["position"] = self.position
        self.send(displayrequest, "displaysignal")
        for _ in self.waitBox("displaycontrol"):
            #             print ("Waiting for display")
            yield 1
        display = self.recv("displaycontrol")

        self.screen = display
        pygame.display.set_caption(self.caption)
        self.screensize = self.screen.get_width(), self.screen.get_height()
        self.addHandler(QUIT, lambda event: self.quit(event))
        self.flip = True

        self.initialiseComponent()
        self.quitting = False
        # Event loop
        while not self.quitting:
            self._dispatch()
            if not self.quitting:
                self.mainLoop()
            self.send({
                "REDRAW": True,
                "surface": self.screen
            }, "displaysignal")
            if not self.quitting and self.flip:
                # FIXME: This does not play nicely at all with the standard pygame display
                #        handling, despite requesting it's display from the standard
                #        location.
                pygame.display.flip()
                yield 1
            else:
                yield 0
        print("QUIT")
Exemple #13
0
    def main(self):
        """Main loop."""
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayservice)

        self.send(self.disprequest, "display_signal")

        for _ in self.waitBox("callback"):
            yield 1
        self.display = self.recv("callback")
        self.blitToSurface()

        self.send(
            {
                "ADDLISTENEVENT": pygame.MOUSEBUTTONDOWN,
                "surface": self.display
            }, "display_signal")

        done = False
        while not done:

            if self.dataReady("control"):
                cmsg = self.recv("control")
                if isinstance(cmsg, producerFinished) or isinstance(
                        cmsg, shutdownMicroprocess):
                    done = True

            while self.dataReady("inbox"):
                for event in self.recv("inbox"):
                    if event.type == pygame.MOUSEBUTTONDOWN:
                        bounds = self.display.get_rect()
                        if bounds.collidepoint(*event.pos):
                            try:
                                message = self.msgs[event.button]
                            except KeyError:  # No message for this key
                                continue
                            except IndexError:  # No message for this key
                                continue
                            except TypeError:  # No lookup table
                                message = self.eventMsg
                            self.send(message, "outbox")
            yield 1

        self.send(Axon.Ipc.producerFinished(message=self.display),
                  "display_signal")
    def newOverlay(self, frame):
        """Request an overlay to suit the supplied frame of data"""
        self.size = frame['size']
        self.pixformat = frame['pixformat']
        self.pygamepixformat = pygame_pixformat_map[self.pixformat]
                
        displayservice = PygameDisplay.getDisplayService()
        self.link((self,"displayctrl"), displayservice)
        self.send({ "OVERLAYREQUEST":True,
                    "pixformat":self.pygamepixformat,
                    "yuvservice":(self, "yuvdata"),
                    "size":(self.size[0]-OVERLAY_FUDGE_OFFSET_FACTOR, self.size[1]),
                    "position":self.position,
                    "yuv":frame['yuv'],
                  },
                  "displayctrl")

        yield 1
Exemple #15
0
    def main(self):
        """Main loop. Do not override"""
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "displaysignal"), displayservice)
        displayrequest = {
            "DISPLAYREQUEST": True,
            "events": (self, "events"),
            "callback": (self, "displaycontrol"),
            "transparency": self.transparency,
            "size": self.screensize,
        }
        if self.position is not None:
            displayrequest["position"] = self.position
        self.send(displayrequest, "displaysignal")
        for _ in self.waitBox("displaycontrol"):
            #             print "Waiting for display"
            yield 1
        display = self.recv("displaycontrol")

        self.screen = display
        pygame.display.set_caption(self.caption)
        self.screensize = self.screen.get_width(), self.screen.get_height()
        self.addHandler(QUIT, lambda event: self.quit(event))
        self.flip = True

        self.initialiseComponent()
        self.quitting = False
        # Event loop
        while not self.quitting:
            self._dispatch()
            if not self.quitting:
                self.mainLoop()
            self.send({"REDRAW": True, "surface": self.screen}, "displaysignal")
            if not self.quitting and self.flip:
                # FIXME: This does not play nicely at all with the standard pygame display
                #        handling, despite requesting it's display from the standard
                #        location.
                pygame.display.flip()
                yield 1
            else:
                yield 0
        print "QUIT"
Exemple #16
0
    def newOverlay(self, frame):
        """Request an overlay to suit the supplied frame of data"""
        self.size = frame['size']
        self.pixformat = frame['pixformat']
        self.pygamepixformat = pygame_pixformat_map[self.pixformat]

        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "displayctrl"), displayservice)
        self.send(
            {
                "OVERLAYREQUEST": True,
                "pixformat": self.pygamepixformat,
                "yuvservice": (self, "yuvdata"),
                "size":
                (self.size[0] - OVERLAY_FUDGE_OFFSET_FACTOR, self.size[1]),
                "position": self.position,
                "yuv": frame['yuv'],
            }, "displayctrl")

        yield 1
Exemple #17
0
   def main(self):
      """Main loop."""
      displayservice = PygameDisplay.getDisplayService()
      self.link((self,"display_signal"), displayservice)

      self.send( self.disprequest,
                  "display_signal")
             
      for _ in self.waitBox("callback"): yield 1
      self.display = self.recv("callback")
      self.blitToSurface()
      
      self.send({ "ADDLISTENEVENT" : pygame.MOUSEBUTTONDOWN,
                  "surface" : self.display},
                  "display_signal")

      done = False
      while not done:
      
         if self.dataReady("control"):
            cmsg = self.recv("control")
            if isinstance(cmsg, producerFinished) or isinstance(cmsg, shutdownMicroprocess):
               done = True
         
         while self.dataReady("inbox"):
            for event in self.recv("inbox"):
                if event.type == pygame.MOUSEBUTTONDOWN:
                   bounds = self.display.get_rect()
                   if bounds.collidepoint(*event.pos):
                      try:
                         message = self.msgs[event.button]
                      except KeyError: # No message for this key
                         continue
                      except IndexError: # No message for this key
                         continue
                      except TypeError: # No lookup table
                         message = self.eventMsg
                      self.send( message, "outbox" )
         yield 1

      self.send(Axon.Ipc.producerFinished(message=self.display), "display_signal")
Exemple #18
0
    def main(self):
        """Main loop."""
        displayService = PygameDisplay.getDisplayService()
        self.link((self,"display_signal"), displayService)

        self.send(self.dispRequest, "display_signal")

        # Wait until we get a display
        while not self.dataReady("callback"):
            self.pause()
        self.display = self.recv("callback")

        self.drawMarkings()

        self.send({"ADDLISTENEVENT" : pygame.MOUSEBUTTONDOWN,
                   "surface" : self.display},
                  "display_signal")

        self.send({"ADDLISTENEVENT" : pygame.MOUSEBUTTONUP,
                   "surface" : self.display},
                  "display_signal")

        # Timing init
        # In main because timingSync needs the scheduler to be working
        if self.sync:
            self.timingSync()
        else:
            self.lastBeatTime = time.time()
        self.startBeat()
        self.startStep()

        while 1:
            if self.dataReady("inbox"):
                for event in self.recv("inbox"):
                    if event.type == pygame.MOUSEBUTTONDOWN:
                        bounds = self.display.get_rect()
                        # Don't respond to clicks in the position bar
                        bounds.top += self.positionSize[1]
                        bounds.height -= self.positionSize[1]
                        # Don't respond to clicks on the bottom or right border
                        bounds.width -= 1
                        bounds.height -= 1
                        if bounds.collidepoint(*event.pos):
                            step, channel = self.positionToStep(event.pos)
                            velocity = self.channels[channel][step][0]
                            if event.button == 1:
                                # Left click
                                if velocity > 0:
                                    # Step off
                                    self.removeStep(step, channel, True) 
                                else:
                                    # Step on
                                    self.addStep(step, channel, 0.7, True)
                            if event.button == 4:
                                # Scroll up
                                if velocity > 0 and velocity <= 0.95:
                                    velocity += 0.05
                                    self.setVelocity(step, channel, velocity,
                                                     True)
                            if event.button == 5:
                                # Scroll down
                                if velocity > 0.05:
                                    velocity -= 0.05
                                    self.setVelocity(step, channel, velocity,
                                                     True)
                            self.drawStepRect(step, channel)
                            self.send({"REDRAW":True, "surface":self.display},
                                      "display_signal")

            if self.dataReady("remoteChanges"):
                data = self.recv("remoteChanges")
                # Only the last part of an OSC address
                address = data[0].split("/")[-1]
                if address == "Add":
                    self.addStep(*data[1])
                if address == "Remove":
                    self.removeStep(*data[1])
                if address == "Velocity":
                    self.setVelocity(*data[1])
                step, channel = data[1][0], data[1][1]
                self.drawStepRect(step, channel)

            if self.dataReady("event"):
                data = self.recv("event")
                if data == "Beat":
                    self.updateBeat()
                elif data == "Step":
                    self.updateStep()
                elif data[0] == "StepActive":
                    message, step, channel = data
                    velocity = self.channels[channel][step][0]
                    self.send((self.messagePrefix + "On", (channel, velocity)),
                              "outbox")
                    self.rescheduleStep(step, channel)

            if self.dataReady("sync"):
                # Ignore any sync messages once as we have already synced by
                # now
                self.recv("sync")

            if not self.anyReady():
                self.pause()
Exemple #19
0
                        "CHANGEDISPLAYGEO": True,
                        "surface": surface,
                        "position": (800, i)
                    }, "display_signal")
                time.sleep(0.02)
                yield 1

            for i in xrange(800, 100, -10):
                self.send(
                    {
                        "CHANGEDISPLAYGEO": True,
                        "surface": surface,
                        "position": (i, 600)
                    }, "display_signal")
                time.sleep(0.02)
                yield 1

            for i in xrange(600, 100, -10):
                self.send(
                    {
                        "CHANGEDISPLAYGEO": True,
                        "surface": surface,
                        "position": (100, i)
                    }, "display_signal")
                time.sleep(0.02)
                yield 1


PygameDisplay(width=1024, height=768, fullscreen=0).activate()
Cat().run()
Exemple #20
0
    from VideoSurface import VideoSurface

    class Framer(Axon.Component.component):
        def main(self):
            while 1:
                while self.dataReady("inbox"):
                    D = self.recv("inbox")
                    print D, D[1].get_width(),D[1].get_height(),
                    X = {
                          "yuv" : (D[1], D[1], D[1]),  # a tuple of strings
                          "size" : (D[1].get_width(), D[1].get_width()),          # in pixels
                          "pixformat" :  "YUV420_planar"    # format of raw video data
                        }
                    self.send(X, "outbox")
                yield 1
    X = PygameDisplay(width=640,height=480).activate()
    PygameDisplay.setDisplayService(X)
    Pipeline(
        VideoCaptureSource(fps=32),
#        Framer(),
#        VideoOverlay(),
        ProperSurfaceDisplayer(),
    ).run()

if 1:
    X = VideoCaptureSource(fps=32)
    snap = X.capture_one()

    pygame.image.save(snap, "photo.bmp")
#    pygame.image.save(snap, "photo.png")
Exemple #21
0
if __name__=="__main__":

    from Kamaelia.Util.Console import ConsoleEchoer 

    dictArgs, optlist, remargs = parseArgs(sys.argv[1:])

    if "help" in dictArgs:
        print dictArgs["help"]
        sys.exit(0)
   
    resolution = dictArgs.get("screensize",(800,600))
    doNavelgaze = dictArgs.pop("navelgaze", None)
    doIntrospect = dictArgs.pop("introspect", None)

    pgd = PygameDisplay(width=resolution[0],height=resolution[1]).activate()
    PygameDisplay.setDisplayService(pgd)

    if doIntrospect is not None:
        (server, port) = doIntrospect
        
        Pipeline( Introspector(), 
                  TCPClient(server, port) 
                ).activate()

    if doNavelgaze:
        if "serverPort" in dictArgs:
            raise ValueError("Makes no sense to navelgaze and use --port option - they're mutually exclusive")
        app = Pipeline(
                 Introspector(),
                 ConsoleEchoer(forwarder=True),
                 text_to_token_lists(),
Exemple #22
0
    def main(self):
        """Main loop."""

        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayservice)

        while 1:
            # wait for a frame
            frame = False
            while not frame:
                if self.dataReady("inbox"):
                    frame = self.recv("inbox")

                    if self.shutdown():
                        return

                if not self.anyReady():
                    self.pause()
                yield 1

            # is it the same format as our current frame?
            if self.formatChanged(frame):
                if self.display:
                    raise "Can't cope with a format change yet!"

                self.size = frame['size']
                self.pixformat = frame['pixformat']

                if self.pixformat != "RGB_interleaved":
                    raise "Can't cope with any pixformat other than RGB_interleaved"

                # request a surface
                # build the initial request to send to Pygame Display to obtain a surface
                # but store it away until main() main loop is activated.
                dispRequest = {
                    "DISPLAYREQUEST": True,
                    "callback": (self, "callback"),
                    "size": self.size,
                    "position": self.position
                }

                self.send(dispRequest, "display_signal")

                # wait for the surface back
                yield WaitComplete(self.waitBox("callback"))
                self.display = self.recv("callback")

            # now render our frame
            image = pygame.image.fromstring(frame['rgb'], frame['size'], "RGB",
                                            False)

            self.display.blit(image, (0, 0))
            self.send({
                "REDRAW": True,
                "surface": self.display
            }, "display_signal")

            # deal with possible shutdown requests
            if self.shutdown():
                return

            if not self.anyReady():
                self.pause()
                yield 1
Exemple #23
0
    def main(self):
        """Main loop."""

        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayservice)

        # request a surface
        self.send(self.disprequest, "display_signal")

        # main loop
        done = False
        change = False
        alpha = 255
        dir = -10
        while not done:
            if self.dataReady("alphacontrol"):
                alpha = self.recv("alphacontrol")
                self.display.set_alpha(alpha)
            if self.dataReady("control"):
                cmsg = self.recv("control")
                if isinstance(cmsg, producerFinished) or isinstance(
                        cmsg, shutdownMicroprocess):
                    self.send(cmsg, "signal")
                    done = True

            # if we're given a new surface, use that instead
            if self.dataReady("callback"):
                if self.display is None:
                    self.display = self.recv("callback")
                    change = True
                    for x in xrange(15):
                        yield 1
                    message = {
                        "ADDLISTENEVENT": pygame.KEYDOWN,
                        "surface": self.display
                    }
                    self.send(message, "display_signal")

            if self.dataReady("inbox"):
                newImg = self.recv("inbox")
                if not self.expect_file_strings:
                    self.fetchImage(newImg)
                else:
                    self.imageFromString(newImg)
                change = True

            if self.dataReady("bgcolour"):
                self.backgroundColour = self.recv("bgcolour")
                change = True

            if change:
                self.blitToSurface()
                self.send({
                    "REDRAW": True,
                    "surface": self.display
                }, "display_signal")
                change = False

            if not done:
                self.pause()
                yield 1

        self.display.set_alpha(0)
        self.send(Axon.Ipc.producerFinished(message=self.display),
                  "display_signal")
        yield 1
Exemple #24
0
    def main(self):
        """Main loop."""
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayservice)

        self.send(self.disprequest, "display_signal")

        for _ in self.waitBox("callback"):
            yield 1
        self.display = self.recv("callback")
        self.blitToSurface()

        self.send(
            {
                "ADDLISTENEVENT": pygame.MOUSEBUTTONDOWN,
                "surface": self.display
            }, "display_signal")
        if self.key is not None:
            ###         print "ADDING LISTEN", self.key, pygame.KEYDOWN, self.display
            message = {
                "ADDLISTENEVENT": pygame.KEYDOWN,
                "surface": self.display,
                "TRACE": "ME"
            }
            ###         print "----------------", message
            self.send(message, "display_signal")
#      while self.outboxes["display_signal"]  != []:
#         print dir(self)
#         print "Waiting clean out", self.outboxes["display_signal"], self
#         yield 1
        done = False
        while not done:
            while self.dataReady("control"):
                cmsg = self.recv("control")
                if isinstance(cmsg, producerFinished) or isinstance(
                        cmsg, shutdownMicroprocess):
                    self.send(cmsg, "signal")
                    done = True


#               print "Shutdown recieved, exitting", self.caption

            while self.dataReady("inbox"):
                for event in self.recv("inbox"):
                    ###                print event
                    if event.type == pygame.MOUSEBUTTONDOWN:
                        #                   print "BUTTON", event.button
                        bounds = self.display.get_rect()
                        if bounds.collidepoint(*event.pos):
                            self.send(self.eventMsg, "outbox")
                    if event.type == pygame.KEYDOWN:
                        ###                   print "EVENT", event.type, event.key
                        if event.key == self.key:
                            self.send(self.eventMsg, "outbox")
            self.pause()
            yield 1

        self.display.set_alpha(0)
        self.send(Axon.Ipc.producerFinished(message=self.display),
                  "display_signal")
        yield 1
Exemple #25
0
    def main(self):
        """Main loop."""
        displayService = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayService)

        self.send(self.dispRequest, "display_signal")

        # Wait until we get a display
        while 1:
            yield WaitComplete(self.waitBox("callback"))
            break
        self.display = self.recv("callback")

        # Initial render so we don't see a blank screen
        self.render()

        if self.editable:
            self.send(
                {
                    "ADDLISTENEVENT": pygame.MOUSEBUTTONDOWN,
                    "surface": self.display
                }, "display_signal")

            self.send(
                {
                    "ADDLISTENEVENT": pygame.MOUSEBUTTONUP,
                    "surface": self.display
                }, "display_signal")

            self.send(
                {
                    "ADDLISTENEVENT": pygame.MOUSEMOTION,
                    "surface": self.display
                }, "display_signal")

        done = False
        while not done:
            if not self.anyReady():
                self.pause()
            yield 1

            while self.dataReady("control"):
                cmsg = self.recv("control")
                if (isinstance(cmsg, producerFinished)
                        or isinstance(cmsg, shutdownMicroprocess)):
                    self.send(cmsg, "signal")
                    done = True

            while self.dataReady("inbox"):
                for event in self.recv("inbox"):
                    if event.type == pygame.MOUSEBUTTONDOWN:
                        self.clickTime = time.time()
                        if self.display.get_rect().collidepoint(*event.pos):
                            self.mouseDown = True
                            self.isBouncing = False
                            self.mousePositions = []
                            self.puckVel = [0, 0]
                            self.puckPos = list(event.pos)
                            self.lastMousePos = event.pos
                            self.send(
                                (self.messagePrefix + self.positionMsg,
                                 (float(self.puckPos[0]) / self.size[0],
                                  float(self.puckPos[1]) / self.size[1])),
                                "localChanges")

                            self.send((self.messagePrefix + "Velocity",
                                       self.puckVel), "localChanges")

                    if event.type == pygame.MOUSEBUTTONUP:
                        if self.mouseDown:
                            if (self.bouncingPuck
                                    and time.time() - self.clickTime > 0.1):
                                # Click and drag
                                self.isBouncing = True
                                if len(self.mousePositions):
                                    for i in xrange(2):
                                        # Use the average of the last 50
                                        # relative mouse positions
                                        positions = [
                                            x[i] for x in self.mousePositions
                                        ]
                                        self.puckVel[i] = sum(positions)
                                        self.puckVel[i] /= float(
                                            len(positions))
                            else:
                                # Just a click
                                self.puckVel = [0, 0]
                                self.render()
                            self.send((self.messagePrefix + "Velocity",
                                       self.puckVel), "localChanges")
                        self.mouseDown = False

                    if event.type == pygame.MOUSEMOTION and self.mouseDown:
                        if self.display.get_rect().collidepoint(*event.pos):
                            # We are dragging inside the display
                            # Keep a buffer of 50 mouse positions
                            if len(self.mousePositions) > 50:
                                del self.mousePositions[0]
                            relPos = []
                            for i in xrange(2):
                                relPos.append(event.pos[i] -
                                              self.lastMousePos[i])
                            self.mousePositions.append(relPos)
                            # Move the puck to where the mouse is and remember
                            # where it is
                            self.puckPos = list(event.pos)
                            self.lastMousePos = event.pos
                            self.send(
                                (self.messagePrefix + self.positionMsg,
                                 (float(self.puckPos[0]) / self.size[0],
                                  float(self.puckPos[1]) / self.size[1])),
                                "localChanges")
                            self.render()

            if self.dataReady("remoteChanges"):
                bundle = self.recv("remoteChanges")
                # The action to take is given by the last section of the
                # OSC address - this should maybe be done by a component and
                # we just listen for ("Velocity", (xVel, yVel)) tuples
                action = bundle[0].split("/")[-1]
                if action == "Velocity":
                    if self.bouncingPuck:
                        self.puckVel = bundle[1]
                        self.isBouncing = 1
                elif action == "Position":
                    for i in xrange(2):
                        self.puckPos[i] = self.size[i] * bundle[1][i]
                self.render()

            if self.dataReady("newframe"):
                # Time to render a new frame
                # Clear any backlog of render messages
                while self.dataReady("newframe"):
                    self.recv("newframe")

                # Change the direction of the puck if it hits a wall
                if self.isBouncing:
                    self.processCollisions()

                if self.isBouncing:
                    # Update the position
                    for i in xrange(2):
                        self.puckPos[i] += self.puckVel[i]
                        if self.puckPos[i] < 0:
                            self.puckPos[i] = 0
                        if self.puckPos[i] > self.size[i]:
                            self.puckPos[i] = self.size[i]
                    self.render()
Exemple #26
0
    def main(self):
        """Main loop."""
        displayService = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayService)

        self.send(self.dispRequest, "display_signal")

        # Wait until we get a display
        while not self.dataReady("callback"):
            self.pause()
        self.display = self.recv("callback")

        self.drawMarkings()

        self.send(
            {
                "ADDLISTENEVENT": pygame.MOUSEBUTTONDOWN,
                "surface": self.display
            }, "display_signal")

        self.send(
            {
                "ADDLISTENEVENT": pygame.MOUSEBUTTONUP,
                "surface": self.display
            }, "display_signal")

        # Timing init
        # In main because timingSync needs the scheduler to be working
        if self.sync:
            self.timingSync()
        else:
            self.lastBeatTime = time.time()
        self.startBeat()
        self.startStep()

        while 1:
            if self.dataReady("inbox"):
                for event in self.recv("inbox"):
                    if event.type == pygame.MOUSEBUTTONDOWN:
                        bounds = self.display.get_rect()
                        # Don't respond to clicks in the position bar
                        bounds.top += self.positionSize[1]
                        bounds.height -= self.positionSize[1]
                        # Don't respond to clicks on the bottom or right border
                        bounds.width -= 1
                        bounds.height -= 1
                        if bounds.collidepoint(*event.pos):
                            step, channel = self.positionToStep(event.pos)
                            velocity = self.channels[channel][step][0]
                            if event.button == 1:
                                # Left click
                                if velocity > 0:
                                    # Step off
                                    self.removeStep(step, channel, True)
                                else:
                                    # Step on
                                    self.addStep(step, channel, 0.7, True)
                            if event.button == 4:
                                # Scroll up
                                if velocity > 0 and velocity <= 0.95:
                                    velocity += 0.05
                                    self.setVelocity(step, channel, velocity,
                                                     True)
                            if event.button == 5:
                                # Scroll down
                                if velocity > 0.05:
                                    velocity -= 0.05
                                    self.setVelocity(step, channel, velocity,
                                                     True)
                            self.drawStepRect(step, channel)
                            self.send({
                                "REDRAW": True,
                                "surface": self.display
                            }, "display_signal")

            if self.dataReady("remoteChanges"):
                data = self.recv("remoteChanges")
                # Only the last part of an OSC address
                address = data[0].split("/")[-1]
                if address == "Add":
                    self.addStep(*data[1])
                if address == "Remove":
                    self.removeStep(*data[1])
                if address == "Velocity":
                    self.setVelocity(*data[1])
                step, channel = data[1][0], data[1][1]
                self.drawStepRect(step, channel)

            if self.dataReady("event"):
                data = self.recv("event")
                if data == "Beat":
                    self.updateBeat()
                elif data == "Step":
                    self.updateStep()
                elif data[0] == "StepActive":
                    message, step, channel = data
                    velocity = self.channels[channel][step][0]
                    self.send((self.messagePrefix + "On", (channel, velocity)),
                              "outbox")
                    self.rescheduleStep(step, channel)

            if self.dataReady("sync"):
                # Ignore any sync messages once as we have already synced by
                # now
                self.recv("sync")

            if not self.anyReady():
                self.pause()
Exemple #27
0
if __name__ == "__main__":

    from Kamaelia.Util.Console import ConsoleEchoer

    dictArgs, optlist, remargs = parseArgs(sys.argv[1:])

    if "help" in dictArgs:
        print(dictArgs["help"])
        sys.exit(0)

    resolution = dictArgs.get("screensize", (800, 600))
    doNavelgaze = dictArgs.pop("navelgaze", None)
    doIntrospect = dictArgs.pop("introspect", None)

    pgd = PygameDisplay(width=resolution[0], height=resolution[1]).activate()
    PygameDisplay.setDisplayService(pgd)

    if doIntrospect is not None:
        (server, port) = doIntrospect

        Pipeline(Introspector(), TCPClient(server, port)).activate()

    if doNavelgaze:
        if "serverPort" in dictArgs:
            raise ValueError(
                "Makes no sense to navelgaze and use --port option - they're mutually exclusive"
            )
        app = Pipeline(
            Introspector(), ConsoleEchoer(forwarder=True),
            text_to_token_lists(),
Exemple #28
0
    def main(self):
        """Main loop."""
        displayService = PygameDisplay.getDisplayService()
        self.link((self,"display_signal"), displayService)

        self.send(self.dispRequest,
                  "display_signal")
        
        # Wait until we get a display
        while 1:
            yield WaitComplete(self.waitBox("callback"))
            break
        self.display = self.recv("callback")

        # Initial render so we don't see a blank screen
        self.render()
        
        if self.editable:
            self.send({"ADDLISTENEVENT" : pygame.MOUSEBUTTONDOWN,
                       "surface" : self.display},
                      "display_signal")

            self.send({"ADDLISTENEVENT" : pygame.MOUSEBUTTONUP,
                       "surface" : self.display},
                      "display_signal")

            self.send({"ADDLISTENEVENT" : pygame.MOUSEMOTION,
                       "surface" : self.display},
                      "display_signal")

        done = False
        while not done:
            if not self.anyReady():
                self.pause()
            yield 1

            while self.dataReady("control"):
                cmsg = self.recv("control")
                if (isinstance(cmsg, producerFinished) or
                    isinstance(cmsg, shutdownMicroprocess)):
                    self.send(cmsg, "signal")
                    done = True
         
            while self.dataReady("inbox"):
                for event in self.recv("inbox"):
                    if event.type == pygame.MOUSEBUTTONDOWN:
                        self.clickTime = time.time()
                        if self.display.get_rect().collidepoint(*event.pos):
                            self.mouseDown = True
                            self.isBouncing = False
                            self.mousePositions = []
                            self.puckVel = [0, 0]
                            self.puckPos = list(event.pos)
                            self.lastMousePos = event.pos
                            self.send((self.messagePrefix + self.positionMsg,
                                       (float(self.puckPos[0])/self.size[0],
                                        float(self.puckPos[1])/self.size[1])),
                                      "localChanges")

                            self.send((self.messagePrefix + "Velocity",
                                       self.puckVel), "localChanges")
                                    

                    if event.type == pygame.MOUSEBUTTONUP:
                        if self.mouseDown:
                            if (self.bouncingPuck and
                                time.time() - self.clickTime > 0.1):
                                # Click and drag
                                self.isBouncing = True
                                if len(self.mousePositions):
                                    for i in xrange(2):
                                        # Use the average of the last 50
                                        # relative mouse positions
                                        positions = [x[i] for x in self.mousePositions]
                                        self.puckVel[i] = sum(positions)
                                        self.puckVel[i] /= float(len(positions))
                            else:
                                # Just a click
                                self.puckVel = [0, 0]
                                self.render()
                            self.send((self.messagePrefix + "Velocity",
                                      self.puckVel), "localChanges")
                        self.mouseDown = False
                    
                    if event.type == pygame.MOUSEMOTION and self.mouseDown:
                        if self.display.get_rect().collidepoint(*event.pos):
                            # We are dragging inside the display
                            # Keep a buffer of 50 mouse positions
                            if len(self.mousePositions) > 50:
                                del self.mousePositions[0]
                            relPos = []
                            for i in xrange(2):
                                relPos.append(event.pos[i] -
                                              self.lastMousePos[i])
                            self.mousePositions.append(relPos)
                            # Move the puck to where the mouse is and remember
                            # where it is
                            self.puckPos = list(event.pos)
                            self.lastMousePos = event.pos
                            self.send((self.messagePrefix + self.positionMsg,
                                       (float(self.puckPos[0])/self.size[0],
                                       float(self.puckPos[1])/self.size[1])),
                                      "localChanges")
                            self.render()

            if self.dataReady("remoteChanges"):
                bundle = self.recv("remoteChanges")
                # The action to take is given by the last section of the
                # OSC address - this should maybe be done by a component and
                # we just listen for ("Velocity", (xVel, yVel)) tuples
                action = bundle[0].split("/")[-1]
                if action == "Velocity":
                    if self.bouncingPuck:
                        self.puckVel =  bundle[1]
                        self.isBouncing = 1
                elif action == "Position":
                    for i in xrange(2):
                        self.puckPos[i] = self.size[i] * bundle[1][i]
                self.render()

            if self.dataReady("newframe"):
                # Time to render a new frame
                # Clear any backlog of render messages
                while self.dataReady("newframe"):
                    self.recv("newframe")

                # Change the direction of the puck if it hits a wall
                if self.isBouncing:
                    self.processCollisions()

                if self.isBouncing:
                    # Update the position
                    for i in xrange(2):
                        self.puckPos[i] += self.puckVel[i]
                        if self.puckPos[i] < 0:
                            self.puckPos[i] = 0
                        if self.puckPos[i] > self.size[i]:
                            self.puckPos[i] = self.size[i]
                    self.render()
Exemple #29
0
    def main(self):
        """Main loop."""
        displayService = PygameDisplay.getDisplayService()
        self.link((self,"display_signal"), displayService)

        # Display surface - this is what we call to redraw
        displayRequest = {"DISPLAYREQUEST" : True,
                          "callback" : (self,"callback"),
                          "events" : (self, "inbox"),
                          "size" : self.size,
                          "position" : (0, 0)
                         }
        if self.position:
            displayRequest["position"] = self.position
        self.display = self.createSurface(displayRequest)

        self.addListenEvent(pygame.MOUSEBUTTONDOWN)
        self.addListenEvent(pygame.MOUSEBUTTONUP)
        self.addListenEvent(pygame.MOUSEMOTION)

        # Background surface - this is what we draw the background markings onto
        displayRequest = {"DISPLAYREQUEST" : True,
                          "callback" : (self,"callback"),
                          "size": self.size,
                          "position" : (0, 0)
                         }
        if self.position:
            displayRequest["position"] = self.position
        self.background = self.createSurface(displayRequest)

        # Initial render
        self.drawMarkings()
        self.requestRedraw()

        # Timing init
        # In main because timingSync needs the scheduler to be working
        if self.sync:
            self.timingSync()
        else:
            self.lastBeatTime = time.time()
        self.startBeat()

        while 1:
            if self.dataReady("inbox"):
                for event in self.recv("inbox"):
                    if event.type == pygame.MOUSEBUTTONDOWN:
                        bounds = self.display.get_rect()
                        if bounds.collidepoint(*event.pos):
                            self.handleMouseDown(event)

                    if event.type == pygame.MOUSEBUTTONUP:
                        self.handleMouseUp(event)

                    if event.type == pygame.MOUSEMOTION:
                        self.handleMouseMotion(event)

            if self.dataReady("remoteChanges"):
                data = self.recv("remoteChanges")
                # Only the last part of an OSC address
                address = data[0].split("/")[-1]
                if address == "Add":
                    noteId = data[1][0]
                    # Add the note to the scheduler
                    self.addNote(noteId=noteId, *data[1][1:])
                    # Draw it if we need to see it
                    if self.noteIsVisible(noteId):
                        self.drawNoteRect(noteId)
                if address == "Remove":
                    noteId = data[1][0]
                    if self.notes.has_key(noteId):
                        # We know about the note
                        # Delete the rect first so we still know the note info
                        if self.noteIsVisible(noteId):
                            self.deleteNoteRect(noteId)
                        # Remove the note fully
                        self.removeNote(noteId)
                if address == "Velocity":
                    noteId = data[1][0]
                    if self.notes.has_key(noteId):
                        # We know about the note
                        velocity = data[1][1]
                        surface = self.notes[noteId]["surface"]
                        self.setVelocity(noteId, velocity)
                        # Set the opacity if the note is on screen
                        if self.noteIsVisible(noteId):
                            surface = self.notes[noteId]["surface"]
                            surface.set_alpha(255 * velocity)
                if address == "Move":
                    noteId = data[1][0]
                    if self.notes.has_key(noteId):
                        # We know about the note
                        oldNoteNumber = self.notes[noteId]["noteNumber"]
                        beat = data[1][1]
                        noteNumber = data[1][2]
                        # Stop the note if it is playing
                        if self.notes[noteId]["playing"]:
                            self.sendNoteOff(noteId)
                        # Whether the note is visible
                        isVisible = self.noteIsVisible(noteId)
                        # Set the new beat and note number
                        self.notes[noteId]["beat"] = beat
                        self.setNoteNumber(noteId, noteNumber)
                        # Reschedule the note for the new time
                        self.cancelNote(noteId)
                        self.moveNote(noteId)
                        # Whether the note should be visible
                        needVisible = self.noteIsVisible(noteId)
                        # Either draw, move or delete the note rect, depending
                        # on whether it was and should be visible
                        if isVisible:
                            if needVisible:
                                self.moveNoteRect(noteId)
                            else:
                                self.deleteNoteRect(noteId)
                        elif needVisible:
                            self.drawNoteRect(noteId)
                if address == "Resize":
                    noteId = data[1][0]
                    if self.notes.has_key(noteId):
                        # We know about the note
                        length = data[1][1]
                        # Stop the note if it's playing 
                        if self.notes[noteId]["playing"]:
                            self.sendNoteOff(noteId)
                        self.notes[noteId]["length"] = length
                        # Cancel and reschedule the note
                        self.cancelNote(noteId)
                        self.resizeNote(noteId)
                        # Draw it if we need to
                        if self.noteIsVisible(noteId):
                            self.redrawNoteRect(noteId)
                self.requestRedraw()

            if self.dataReady("event"):
                data = self.recv("event")
                if data == "Beat":
                    self.updateBeat()

                elif data == "Scroll":
                    if self.scrolling == 1:
                        if self.maxVisibleNote < len(noteList):
                            self.scrollUp()
                            # Make sure the note we are dragging stays at the
                            # top of the piano roll
                            noteId = self.moving[0]
                            self.setNoteNumber(noteId, self.maxVisibleNote)
                            self.moveNoteRect(noteId)

                    if self.scrolling == -1:
                        if self.minVisibleNote > 0:
                            self.scrollDown()
                            noteId = self.moving[0]
                            self.setNoteNumber(noteId, self.minVisibleNote)
                            self.moveNoteRect(noteId)

                    if self.scrolling != 0:
                        self.scrollEvent = self.scheduleRel("Scroll", 0.2, 4)
                    else:
                        self.scrollEvent = None

                elif data[0] == "NoteOn":
                    noteId = data[1]
                    self.sendNoteOn(noteId)
                    self.scheduleNoteOn(noteId)
                elif data[0] == "NoteOff":
                    noteId = data[1]
                    self.sendNoteOff(noteId)
                    self.scheduleNoteOff(noteId)

            if self.dataReady("sync"):
                # Ignore any sync messages once as we have already synced by
                # now
                self.recv("sync")

            if not self.anyReady():
                self.pause()