コード例 #1
0
ファイル: osc.py プロジェクト: JoeLeclercq/jesWork
class OscIn():
    def __init__(self, port=57110):

        self.port = port  # holds port to listen to (for incoming events/messages)
        self.oscPortIn = OSCPortIn(self.port)  # create port
        self.oscPortIn.startListening()  # and start it

        # also, get our host IP address (to output below, for the user's convenience)
        self.IPaddress = socket.gethostbyname(socket.getfqdn())
        print "\nOSC Server started:"
        print "Accepting OSC input on IP address", self.IPaddress, "at port", self.port
        print "(use this info to configure OSC clients)"
        print

        ## provide a default OSC message handler
        ## uncomment this to see incoming OSC messages (for troubleshooting)
        #self.onInput( "/.*", self.__echoPrintInput__)

    def onInput(self, OSCaddress, function):
        """
      Associate callback 'function' to OSC messages send to 'OSCaddress' on this device.  An 'OSCaddress'
      looks like a URL, e.g., "/first/second/third".
      """
        self.oscPortIn.addListener(OSCaddress, GenericListener(
            function))  # register function to call for this address

    def __echoPrintInput__(self, message):
        """It just echo-prints the incoming OSC message."""

        OSCaddress = message.getAddress()
        args = message.getArguments()
        print "\nOSC Event:"
        print "OSC In - Address:", OSCaddress,  # print the time and address
        for i in range(
                len(args)):  # and any message arguments (all on the same line)
            print ", Argument " + str(i) + ": " + str(args[i]),
        print
コード例 #2
0
ファイル: osc.py プロジェクト: HenryStevens/jes
class OscIn():

   def __init__(self, port = 57110):

      self.port = port                       # holds port to listen to (for incoming events/messages)
      self.oscPortIn = OSCPortIn(self.port)  # create port
      self.oscPortIn.startListening()        # and start it

      # also, get our host IP address (to output below, for the user's convenience)
      self.IPaddress = socket.gethostbyname(socket.getfqdn())  
      print "\nOSC Server started:"    
      print "Accepting OSC input on IP address", self.IPaddress, "at port", self.port
      print "(use this info to configure OSC clients)"
      print
      
      ## provide a default OSC message handler 
      ## uncomment this to see incoming OSC messages (for troubleshooting)
      #self.onInput( "/.*", self.__echoPrintInput__)
      
   def onInput(self, OSCaddress, function):
      """
      Associate callback 'function' to OSC messages send to 'OSCaddress' on this device.  An 'OSCaddress'
      looks like a URL, e.g., "/first/second/third".
      """
      self.oscPortIn.addListener(OSCaddress, GenericListener( function ))  # register function to call for this address

   def __echoPrintInput__(self, message):
      """It just echo-prints the incoming OSC message."""

      OSCaddress = message.getAddress()
      args = message.getArguments()
      print "\nOSC Event:"
      print "OSC In - Address:", OSCaddress,   # print the time and address         
      for i in range( len(args) ):             # and any message arguments (all on the same line)
         print ", Argument " + str(i) + ": " + str(args[i]),
      print
コード例 #3
0
class OscIn():

   def __init__(self, port = 57110):

      self.port = port                       # holds port to listen to (for incoming events/messages)
      self.oscPortIn = OSCPortIn(self.port)  # create port
      self.oscPortIn.startListening()        # and start it

      # also, get our host IP address (to output below, for the user's convenience)
      self.IPaddress = socket.gethostbyname(socket.gethostname())
      print "\nOSC Server started:"    
      print "Accepting OSC input on IP address", self.IPaddress, "at port", self.port
      print "(use this info to configure OSC clients)"
      print
      
      # create dictionary to hold registered callback functions, so that we can replace them
      # when a new call to onInput() is made for a given address - the dictionary key is the
      # address, and the dictionary value is the GenericListener created for this address,
      # so that may update the callback function it is associated with.
      self.oscAddressHandlers = {}
      
      self.showIncomingMessages = True   # print all incoming OSC messages by default

      # provide a default OSC message handler 
      # prints out all incoming OSC messages (if desired - see showMessages() and hideMessages())
      self.onInput(ALL_MESSAGES, self. _printIncomingMessage_)

      # remember that this OscIn has been created and is active (so that it can be stopped/terminated by JEM, if desired)
      _ActiveOscInObjects_.append(self)
      
      
   def onInput(self, OSCaddress, function):
      """
      Associate callback 'function' to OSC messages send to 'OSCaddress' on this device.  An 'OSCaddress'
      looks like a URL, e.g., "/first/second/third".
      """

      # register callback function for this OSC address
      if self.oscAddressHandlers.has_key( OSCaddress ):   # is there an existing hanlder already?
         
         # yes, so update it (i.e., update the GenericListener's functions attribute)
         self.oscAddressHandlers[ OSCaddress ].functions.append( function )
         
      else:
      
         # no, so add a new handler for this address
         handler = GenericListener( function )            # create the listener
         self.oscAddressHandlers[ OSCaddress ] = handler  # remember it
         self.oscPortIn.addListener(OSCaddress, handler)  # and add it to the OscIn object


   def _printIncomingMessage_(self, message):
      """It prints out the incoming OSC message (if desired)."""

      # determine if we need to print out the message
      if self.showIncomingMessages:   # echo print incoming OSC messages?
      
         # yes, so extract info
         OSCaddress = message.getAddress()
         args = message.getArguments()
         
         # and print out the message
         #print "\nOSC Event:"
         print "OSC In - Address:", '"' + str(OSCaddress) + '"',   # print the address         
         for i in range( len(args) ):                              # and any message arguments (all on the same line)
            if type(args[i]) == unicode:     # is the argument a string?
               print ", Argument " + str(i) + ': "' + args[i] + '"',   # yes, so use double quotes
            else:
               print ", Argument " + str(i) + ": " + str(args[i]),     # no, so print as is
         print

   def showMessages(self):
      """
      Turns on printing of incoming OSC messages (useful for exploring what OSC messages 
      are generated by a particular device).
      """
      self.showIncomingMessages = True

   def hideMessages(self):
      """
      Turns off printing of incoming OSC messages.
      """
      self.showIncomingMessages = False
コード例 #4
0
ファイル: osc.py プロジェクト: Alex-CS/sonify
class OscIn():

   def __init__(self, port = 57110):

      self.port = port                       # holds port to listen to (for incoming events/messages)
      self.oscPortIn = OSCPortIn(self.port)  # create port
      self.oscPortIn.startListening()        # and start it

      # also, get our host IP address (to output below, for the user's convenience)
      self.IPaddress = socket.gethostbyname(socket.getfqdn())  
      print "\nOSC Server started:"    
      print "Accepting OSC input on IP address", self.IPaddress, "at port", self.port
      print "(use this info to configure OSC clients)"
      print
      
      # create dictionary to hold registered callback functions, so that we can replace them
      # when a new call to onInput() is made for a given address - the dictionary key is the
      # address, and the dictionary value is the GenericListener created for this address,
      # so that may update the callback function it is associated with.
      self.oscAddressHandlers = {}
      
      self.showIncomingMessages = True   # print all incoming OSC messages by default

      # provide a default OSC message handler 
      # prints out all incoming OSC messages (if desired - see showMessages() and hideMessages())
      self.onInput(ALL_MESSAGES, self. _printIncomingMessage_)

      # remember that this OscIn has been created and is active (so that it can be stopped/terminated by JEM, if desired)
      _ActiveOscInObjects_.append(self)
      
      
   def onInput(self, OSCaddress, function):
      """
      Associate callback 'function' to OSC messages send to 'OSCaddress' on this device.  An 'OSCaddress'
      looks like a URL, e.g., "/first/second/third".
      """

      # register callback function for this OSC address
      if self.oscAddressHandlers.has_key( OSCaddress ):   # is there an existing hanlder already?
         
         # yes, so update it (i.e., update the GenericListener's function attribute)
         self.oscAddressHandlers[ OSCaddress ].function = function
         
      else:
      
         # no, so add a new handler for this address
         handler = GenericListener( function )            # create the listener
         self.oscAddressHandlers[ OSCaddress ] = handler  # remember it
         self.oscPortIn.addListener(OSCaddress, handler)  # and add it to the OscIn object
               

   def _printIncomingMessage_(self, message):
      """It prints out the incoming OSC message (if desired)."""

      # determine if we need to print out the message
      if self.showIncomingMessages:   # echo print incoming OSC messages?
      
         # yes, so extract info
         OSCaddress = message.getAddress()
         args = message.getArguments()
         
         # and print out the message
         #print "\nOSC Event:"
         print "OSC In - Address:", '"' + str(OSCaddress) + '"',   # print the address         
         for i in range( len(args) ):                              # and any message arguments (all on the same line)
            if type(args[i]) == unicode:     # is the argument a string?
               print ", Argument " + str(i) + ': "' + args[i] + '"',   # yes, so use double quotes
            else:
               print ", Argument " + str(i) + ": " + str(args[i]),     # no, so print as is
         print

   def showMessages(self):
      """
      Turns on printing of incoming OSC messages (useful for exploring what OSC messages 
      are generated by a particular device).
      """
      self.showIncomingMessages = True

   def hideMessages(self):
      """
      Turns off printing of incoming OSC messages.
      """
      self.showIncomingMessages = False