Exemplo n.º 1
0
    def parse_function(self, data):
        # OSCulator uses big endian, OSC.py uses big endian
        name, rest = OSC.readString(data)
        
        if not name.startswith("/wii"):
            return
        
        type, rest = OSC.readString(rest)
        
        if name.endswith("/pry/0"):
            self.parse_field(rest, 'pitch', 'y')

        if name.endswith("pry/1"):
            self.parse_field(rest, 'roll', 'x')
        
        if name.endswith("pry/2"):
            self.parse_field(rest, 'yaw', 'z')
        
        if name.endswith("button/A"):
            self.a = self.readFloat(rest)[0]
            
        if name.endswith("button/B"):
            b = self.readFloat(rest)[0]
            
            if self.b and not b:
                self.tool_server.on_mouse_release(0, 0, 0, 0)
            elif not self.b and b:
                self.tool_server.on_mouse_press(0, 0, 0, 0)               
            
            self.b = b
Exemplo n.º 2
0
def decode(data):
    """Converts a typetagged OSC message to a Python list.
    modified for supercollider-specific messages.
    """
    table = { "i":OSC.readInt,
              "f":OSC.readFloat,
              "s":OSC.readString,
              "b":OSC.readBlob,
              "d":OSC.readDouble}
    decoded = []
    address,  rest = OSC.readString(data)
    typetags = ""
    
    if address == "#bundle":
        time, rest = OSC.readLong(rest)
        decoded.append(address)
        decoded.append(time)
        while len(rest)>0:
            length, rest = OSC.readInt(rest)
            decoded.append(OSC.decodeOSC(rest[:length]))
            rest = rest[length:]
          
    elif len(rest) > 0:
        typetags, rest = OSC.readString(rest)
        
        decoded.append(address)
        decoded.append(typetags)
        if(typetags[0] == ","):
            for tag in typetags[1:]:
               try:
                   value, rest = table[tag](rest)
                   decoded.append(value)
               except:
                   print "%s probably not in tags list" %tag
                   print "check scOSCMessage.py - def decodeSCOSC():"
        else:
            print "Oops, typetag lacks the magic ,"
    try:
        returnList = [decoded[0]]
    except IndexError:
        returnList = []
    try:
        oldRtnList = returnList
        returnList.extend(decoded[2:])
    except IndexError:
        returnList = oldRtnList
    return returnList
Exemplo n.º 3
0
    def parse_function(self, data):
        # OSC.py uses big endian, OSC.readInt changed to little endian for p5osc
        name, rest = OSC.readString(data)
        
        if not name.startswith("/sp"):
            return    
        
        type, rest = OSC.readString(rest)
        
        if name.endswith("rot/xyz/0"):
            self.parse_field(rest, 'pitch', 'y')

        if name.endswith("rot/xyz/1"):
            self.parse_field(rest, 'roll', 'x')
        
        if name.endswith("rot/xyz/2"):
            self.parse_field(rest, 'yaw', 'z')        
Exemplo n.º 4
0
 def parse_function(self, data):
     # OSC.py uses big endian, OSC.readInt changed to little endian for p5osc
     address, rest   = OSC.readString(data)
     time, rest      = OSC.readLong(rest)
     length, rest    = self.readInt(rest)
     name, rest      = OSC.readString(rest)
     
     if name != "/p5glove_data":
         return
     
     junk, rest      = OSC.readString(rest)         
     a, rest    = self.readInt(rest)
     b, rest         = self.readInt(rest)
     c, rest         = self.readInt(rest)
     thumb, rest     = self.readInt(rest)
     index, rest     = self.readInt(rest)
     middle, rest    = self.readInt(rest)
     ring, rest      = self.readInt(rest)
     pinky, rest     = self.readInt(rest)
     x, rest         = self.readInt(rest)
     y, rest         = self.readInt(rest)
     z, rest         = self.readInt(rest)
     
     if self.initialized:
         self.dx = self.speed * (x - self.x_old)
         self.dy = self.speed * (y - self.y_old)
         self.dz = self.speed * (z - self.z_old)    
    
         # if hand is at least semi clenched, enable rotation
         if index > 30 and index > 30:
             self.tool_server.on_mouse_drag(0, 0, self.dx, -self.dy, 0, 0)
             self.tool_server.on_mouse_scroll(0, 0, 0, self.dz)  
     else:
         self.initialized = True
         
     self.x_old = x
     self.y_old = y
     self.z_old = z