Esempio n. 1
0
 def sendMsg(self, msg):
     builder = OscMessageBuilder(address=self.address)
     for v in msg[0]:
         builder.add_arg(v)
     out = builder.build()
     # print("sent osc message to",self.ip,"on port",self.port,"with address",self.address)
     self.client.send(out)
Esempio n. 2
0
def oscReceive(unused_addr, bang):
    print('Receive Number: ' + bang)
    msg = OscMessageBuilder(address='/')
    msg.add_arg('is genius.')

    m = msg.build()
    client.send(m)
Esempio n. 3
0
 def send_knob(self, knob_num, knob_val):
     if self.verbose:
         print("knob %d: %f" % (knob_num, knob_val))
     builder = OscMessageBuilder(address="/repatcher/knob" + str(knob_num))
     builder.add_arg(knob_val)
     msg = builder.build()
     self.client.send(msg)
Esempio n. 4
0
 def get_message(self)-> OscMessage:
     """
     returns the OSC message of the Blob with the TUIO spezification
     """
     x, y = self.position
     X, Y = self.velocity
     w, h = self.dimension
     builder = OscMessageBuilder(address=TUIO_BLOB)
     for val in [
             "set",
             self.session_id,
             float(x),
             float(y),
             float(self.angle),
             float(w),
             float(h),
             float(self.area),
             float(X),
             float(Y),
             float(self.velocity_rotation),
             float(self.motion_acceleration),
             float(self.rotation_acceleration)
     ]:
         builder.add_arg(val)
     return builder.build()
Esempio n. 5
0
 async def send_message(self, node, client_address, *args, **kwargs):
     when = kwargs.get('when', time.time())
     builder = OscMessageBuilder(address=node.osc_address)
     for arg in args:
         builder.add_arg(arg)
     msg = builder.build()
     await self.server.sendto(msg, client_address, when)
Esempio n. 6
0
def osc_message(d):
    """
    create OSC message from a dict
    """
    msg = OscMessageBuilder(address="/send")
    msg.add_arg(json.dumps(d))
    return msg.build()
    def _build_message(
            msg_address: str,
            msg_parameters: Optional[Union[Sequence,
                                           Any]] = None) -> OscMessage:
        """Builds pythonsosc OSC message.

        Parameters
        ----------
        msg_address : str
            SuperCollider address.
        msg_parameters : list, optional
            List of parameters to add to message.

        Returns
        -------
        OscMessage
            Message ready to be sent.

        """
        if msg_parameters is None:
            msg_parameters = []
        elif not isinstance(msg_parameters, Sequence) or isinstance(
                msg_parameters, (str, bytes)):
            msg_parameters = [msg_parameters]

        if not msg_address.startswith("/"):
            msg_address = "/" + msg_address

        builder = OscMessageBuilder(address=msg_address)
        for msg_arg in msg_parameters:
            if isinstance(msg_arg, np.number):
                msg_arg = msg_arg.item()
            builder.add_arg(msg_arg)
        return builder.build()
 def publishSensorData(self, sensor_data, calibration_status):
     """Make the OSC sensor data package and publishes it."""
     self.msg_builder = OscMessageBuilder("/sensordata")
     self.msg_builder.add_arg(int(1000 * (time() - self.current_time)))
     # current_time = time()
     self.addSensorData(sensor_data)
     self.addCalibrationStatus(calibration_status)
Esempio n. 9
0
def send_color(r, g, b):
    msg = OscMessageBuilder(address='/CV07/color/')
    #msg.add_arg(r, 'i')
    #msg.add_arg(g, 'i')
    msg.add_arg(b, 'i')
    m = msg.build()
    print(m.address, m.params)
    client.send(m)
Esempio n. 10
0
 def publish_sensor_data(self, sensor_data, calibration_status):
     """Makes the OSC sensor data package and publishes it"""
     self.msg_builder = OscMessageBuilder("/sensordata")
     self.msg_builder.add_arg(int(1000 * (time.time() - self.current_time)))
     # current_time = time()
     self.add_sensor_data(sensor_data)
     self.add_calibration_status(calibration_status)
     self.osc_udp_client.send(self.msg_builder.build())
Esempio n. 11
0
def osc_message(address, args=()):
    print(args)
    builder = OscMessageBuilder(address)
    if not isinstance(args, Iterable) or isinstance(args, (str, bytes)):
        args = [args]
    for arg in args:
        builder.add_arg(arg)
    return builder.build()
Esempio n. 12
0
def adjust_balloons():
    global balloon_osc
    if not balloon_osc:
        balloon_osc = UDPClient('0.0.0.0', 5005)
    
    msg = OscMessageBuilder("/adjust")
    balloon_osc.send(msg.build())
    logging.info("sent adjustment")
Esempio n. 13
0
 def send_patch_bay(self, output_num, values):
     if self.verbose:
         print("bay %d: %s" % (output_num, str(values)))
     builder = OscMessageBuilder(address="/repatcher/output" +
                                 str(output_num))
     for v in values:
         builder.add_arg(v)
     msg = builder.build()
     self.client.send(msg)
Esempio n. 14
0
def callback(gpio_id):
    client = UDPClient(HOST, PORT)
    if GPIO.input(gpio_id) == 0:
        msg = OscMessageBuilder('/start').build()
        GPIO.output(LED, GPIO.HIGH)
    else:
        msg = OscMessageBuilder('/stop').build()
        GPIO.output(LED, GPIO.LOW)
    client.send(msg)
Esempio n. 15
0
 def publishSensorData(self, sensor_data, calibration_status,
                       attributeToLog, elapsed, timeDifference, index):
     """Makes the OSC sensor data package and publishes it"""
     self.msg_builder = OscMessageBuilder("/sensordata")
     self.msg_builder.add_arg(int(1000 * (time() - self.current_time)))
     current_time = time()
     self.addSensorData(sensor_data)
     self.printSensorData(sensor_data, attributeToLog, elapsed,
                          timeDifference)
     self.addCalibrationStatus(calibration_status)
     self.osc_udp_client.send(self.msg_builder.build())
Esempio n. 16
0
 def send_message(self, address, value):
     builder = OscMessageBuilder(address=address)
     if value is None:
         values = []
     elif isinstance(value, list):
         values = value
     else:
         values = [value]
     for val in values:
         builder.add_arg(val)
     msg = builder.build()
     self.socket.sendto(msg.dgram, self.xr_address)
Esempio n. 17
0
 def send_message(self, address, value):
     builder = OscMessageBuilder(address=address)
     if value != '':
         if not isinstance(value, Iterable) or isinstance(
                 value, (str, bytes)):
             values = [value]
         else:
             values = value
         for val in values:
             builder.add_arg(val)
     msg = builder.build()
     self.send(msg)
Esempio n. 18
0
def main():
    ip = '127.0.0.1'
    port = 6700

    client = udp_client.UDPClient(ip, port)

    args = [0, 228, 123]
    data = OscMessageBuilder(address='/address')
    data.add_arg(args)
    data = data.build()

    client.send(data)
Esempio n. 19
0
 def send_message(self, address, *args):
     msg = OscMessageBuilder(address)
     for arg in args:
         msg.add_arg(arg)
     data = msg.build().dgram
     if self.osc_spec == 1.0:
         length = len(data)
         data = struct.pack('>i', length) + data
         self._to_write.put_nowait(data)
     else:
         data = self._slip_driver.send(data)
         self._to_write.put_nowait(data)
Esempio n. 20
0
def SendBPM(BPM):
	if BPM.isdecimal():
		BPM=int(BPM)
		if 0<BPM<=960:
			msg = OscMessageBuilder(address='/BPM')
			msg.add_arg(int(BPM))
			m = msg.build()
			print(m.address, m.params)
			client.send(m)
		else:
			print("error: 0<BPM<=960");
	else:
		print ("error:Please enter the correct value")
Esempio n. 21
0
    def build_osc_message(self, address, value):
        """
        composes OSC message in proper format for sending
        """
        builder = OscMessageBuilder(address=address)
        if not isinstance(value, Iterable) or isinstance(value, (str, bytes)):
            values = [value]
        else:
            values = value
        for val in values:
            builder.add_arg(val)
        msg = builder.build()

        return msg.dgram
Esempio n. 22
0
    def _convertMessageListToMessageBuilder(
            self, messageList: List[Any]) -> OscMessageBuilder:
        """
        NB  Remove elements set to None, but otherwise preserve order of MessageList.
        """

        oscPath: str = messageList[0]
        messageBuilder: OscMessageBuilder = None

        self._validateOSCPath(oscPath)  # Handle OSC path.
        messageBuilder = OscMessageBuilder(oscPath)

        for arg in messageList[1:]:  # Handle OSC arguments.
            if None is arg: continue
            messageBuilder.add_arg(arg)

        return messageBuilder
def main():
    #print("\n" + "get sensor data")
    sensordata = np.array(sensor.pixels)
    sensordata = sensordata[:, ::-1]
    #for row in sensordata:
    #    print (["{0:.1f}".format(temp) for temp in row])

    print("\n")
    print(sensordata.max())

    if sensordata.max() > basetemp:
        #pos =list(zip(*np.where(sensordata > sensordata.max() * 0.95)))
        pos = list(zip(*np.where(sensordata == sensordata.max())))
        print(pos)
        msg = OscMessageBuilder(address="/pos")
        for i in pos:
            msg = OscMessageBuilder(address="/pos")
            x, y = i
            msg.add_arg(int(x))
            msg.add_arg(int(y))
            m = msg.build()
            print(m.address, m.params)
            client.send(m)

            time.sleep(0.05)
    else:
        print("nobody is here")
Esempio n. 24
0
    def __init__(self, 
                 scsynth_address=('127.0.0.1', 50000),
                 message_address=('192.168.2.1', 50001),
                 recipient_addresses=(
                     ('192.168.2.2', 50001),
                     ('192.168.2.3', 50001), 
                 ),
                 nids_start=10000,
                 nids_end=40000,
                 pan=0,
                 personality_assertiveness=0.10,
                 personality_moodiness=0.02,
                 personality_confidence=0.05,
                 personality_irritability=0.10,
                 **kwargs
                 ):
        super().__init__(**kwargs)
        self._client = UDPClient(*scsynth_address) 
        self._message_server = _MessageServer(message_address, self)
        self._message_client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self._recipient_addresses = recipient_addresses
        self._moods = [
                Mood(self, SimpleBlipperEngine),
                Mood(self, SimpleBlipperEngine),
                Mood(self, SimpleBlipperEngine),
                Mood(self, SimpleBlipperEngine),
                Mood(self, FlitterEngine),
                Mood(self, FlitterEngine),
                Mood(self, FlitterEngine),
                Mood(self, BellsEngine),
                ]

        self.running = False
        self.parameter_lock = threading.Lock()
        self.manager = manager.SynthManager(self._client,
                nids_start=nids_start, nids_end=nids_end, pan=pan)

        msg = OscMessageBuilder(address='/d_recv') # send synthdefs to scsynth
        msg.add_arg(synthdefs.pisynth1)
        self._client.send(msg.build())

        self.personality_assertiveness = personality_assertiveness
        self.personality_moodiness = personality_moodiness
        self.personality_confidence = personality_confidence
        self.personality_irritability = personality_irritability
Esempio n. 25
0
    def send_message(self, address: str, value: Union[int, float, bytes, str, bool, tuple, list]) -> None:
        """Build :class:`OscMessage` from arguments and send to server

        Args:
            address: OSC address the message shall go to
            value: One or more arguments to be added to the message
        """
        builder = OscMessageBuilder(address=address)
        if value is None:
            values = []
        elif not isinstance(value, Iterable) or isinstance(value, (str, bytes)):
            values = [value]
        else:
            values = value
        for val in values:
            builder.add_arg(val)
        msg = builder.build()
        self.send(msg)
Esempio n. 26
0
 def get_message(self)-> OscMessage:
     """
     returns the OSC message of the Cursor with the TUIO spezification
     """
     x, y = self.position
     X, Y = self.velocity
     builder = OscMessageBuilder(address=TUIO_CURSOR)
     for val in [
             "set",
             self.session_id,
             float(x),
             float(y),
             float(X),
             float(Y),
             float(self.motion_acceleration)
     ]:
         builder.add_arg(val)
     return builder.build()
Esempio n. 27
0
def main():
    # 受信先のVRChat
    IP = '127.0.0.1'
    PORT = 9000

    # OSCメッセージ情報の読み込み
    address = sys.argv[1]
    arg = sys.argv[2]

    print('Address: ' + address)
    print('Arg: ' + arg)

    # OSCメッセージの構築
    client = udp_client.UDPClient(IP, PORT)
    msg = OscMessageBuilder(address=address)
    msg.add_arg(arg)
    m = msg.build()

    # OSCメッセージの送信
    client.send(m)
Esempio n. 28
0
def affect_candidate(candidate, osc_msg, amount):
    global balloon_osc
    if not balloon_osc:
        balloon_osc = UDPClient('0.0.0.0', 5005)

    osc_callback_msg = pickle.dumps(osc_msg)

    msg = OscMessageBuilder("/instruction")
    msg.add_arg(candidate)
    msg.add_arg(amount)
    msg.add_arg(osc_callback_msg)
    balloon_osc.send(msg.build())
    logging.info("sent instruction %s, %d" % (candidate, amount))
Esempio n. 29
0
 def get_message(self) -> OscMessage:
     """
     returns the OSC message of the Object with the TUIO spezification
     """
     x, y = self.position
     X, Y = self.velocity
     builder = OscMessageBuilder(address=TUIO_OBJECT)
     for val in [
             "set",
             int(self.session_id),
             int(self.class_id),
             float(x),
             float(y),
             float(self.angle),
             float(X),
             float(Y),
             float(self.velocity_rotation),
             float(self.motion_acceleration),
             float(self.rotation_acceleration)
     ]:
         builder.add_arg(val)
     return builder.build()
Esempio n. 30
0
    def send(self, pose_id, pose_proba):
        if not self._is_running:
            return False

        msg = OscMessageBuilder(address=self.POSE_LABEL)
        msg.add_arg(pose_id)
        msg.add_arg(pose_proba)
        m = msg.build()

        self._client.send(m)
        return True
Esempio n. 31
0
    def _build_alive(address, profile_list):
        """
        builds a OSC which implements a alive message of TUIO
        returns the message
        """
        builder = OscMessageBuilder(address=address)
        builder.add_arg("alive")
        for profile in profile_list:
            builder.add_arg(profile.session_id)  ## add id of cursors

        alive_msg = builder.build()
        return alive_msg
Esempio n. 32
0
    def send_bundle(self):
        """Build :class:`OscMessage` from arguments and send to server

        Args:
            address: OSC address the message shall go to
            value: One or more arguments to be added to the message
        """

        bundle_builder = OscBundleBuilder(0)

        # build alive message

        bundle_builder.add_content(
            TuioServer._build_alive(TUIO_CURSOR, self.cursors))

        bundle_builder.add_content(
            TuioServer._build_alive(TUIO_BLOB, self.blobs))

        bundle_builder.add_content(
            TuioServer._build_alive(TUIO_OBJECT, self.objects))

        # set message of cursor
        for cursor in self.cursors:
            cursor_msg = cursor.get_message()
            bundle_builder.add_content(cursor_msg)

        # set message of blob
        for blob in self.blobs:
            blob_msg = blob.get_message()
            bundle_builder.add_content(blob_msg)

        # set message of object
        for o in self.objects:
            object_msg = o.get_message()
            bundle_builder.add_content(object_msg)

        # message fseq to end the bundle and send (optinal) frame id
        builder = OscMessageBuilder(address=TUIO_CURSOR)
        builder.add_arg("fseq")
        builder.add_arg(-1)
        fseq = builder.build()
        bundle_builder.add_content(fseq)

        # build bundle and send
        bundle = bundle_builder.build()
        self.send(bundle)
Esempio n. 33
0
def updateLines(lineName):
    if not lineName in lines:
        lines.append(lineName)

        msg = OscMessageBuilder(address='/tubeLines')
        msg.add_arg(lineName)

        #color
        if lineName in colorIndex:
            color = colorIndex[lineName]
        else:
            color = colorIndex['Others']
        msg.add_arg(color)

        m = msg.build()
        client.send(m)
        print('sent a new line: {} ({})'. format(lineName, color))
Esempio n. 34
0
def build_osc_message(array):
    builder = OscMessageBuilder(address='/wek/inputs')
    for val in array:
        builder.add_arg(val)
    return builder.build()
Esempio n. 35
0
def control_wekinator(endpoint, arg=None):
    builder = OscMessageBuilder('/wekinator/control/{}'.format(endpoint))
    if arg is not None:
        builder.add_arg(arg)
    msg = builder.build()
    udp_client.UDPClient('127.0.0.1', 6448).send(msg)
Esempio n. 36
0
class Orientation3D(object):
    """Reads out all sensor data from either a local or remote Pozyx"""
    def __init__(self, pozyx, osc_udp_client, remote_id=None):
        self.pozyx = pozyx
        self.remote_id = remote_id

        self.osc_udp_client = osc_udp_client

    def setup(self):
        """There is no specific setup functionality"""
        self.current_time = time()

    def loop(self):
        """Gets new IMU sensor data"""
        sensor_data = SensorData()
        calibration_status = SingleRegister()
        if self.remote_id is not None or self.pozyx.checkForFlag(
                POZYX_INT_MASK_IMU, 0.01) == POZYX_SUCCESS:
            status = self.pozyx.getAllSensorData(sensor_data, self.remote_id)
            status &= self.pozyx.getCalibrationStatus(calibration_status,
                                                      self.remote_id)
            if status == POZYX_SUCCESS:
                self.publishSensorData(sensor_data, calibration_status)
                return sensor_data

        return "Error, no data to print for this line"

    def publishSensorData(self, sensor_data, calibration_status):
        """Makes the OSC sensor data package and publishes it"""
        self.msg_builder = OscMessageBuilder("/sensordata")
        self.msg_builder.add_arg(int(1000 * (time() - self.current_time)))
        current_time = time()
        self.addSensorData(sensor_data)
        self.addCalibrationStatus(calibration_status)
        self.osc_udp_client.send(self.msg_builder.build())

    def addSensorData(self, sensor_data):
        """Adds the sensor data to the OSC message"""
        self.msg_builder.add_arg(sensor_data.pressure)
        self.addComponentsOSC(sensor_data.acceleration)
        self.addComponentsOSC(sensor_data.magnetic)
        self.addComponentsOSC(sensor_data.angular_vel)
        self.addComponentsOSC(sensor_data.euler_angles)
        self.addComponentsOSC(sensor_data.quaternion)
        self.addComponentsOSC(sensor_data.linear_acceleration)
        self.addComponentsOSC(sensor_data.gravity_vector)

    def addComponentsOSC(self, component):
        """Adds a sensor data component to the OSC message"""
        for data in component.data:
            self.msg_builder.add_arg(float(data))

    def addCalibrationStatus(self, calibration_status):
        """Adds the calibration status data to the OSC message"""
        self.msg_builder.add_arg(calibration_status[0] & 0x03)
        self.msg_builder.add_arg((calibration_status[0] & 0x0C) >> 2)
        self.msg_builder.add_arg((calibration_status[0] & 0x30) >> 4)
        self.msg_builder.add_arg((calibration_status[0] & 0xC0) >> 6)
Esempio n. 37
0
def build_osc_message(positioning_values):
    builder = OscMessageBuilder(address='/wek/inputs')
    for v in positioning_values:
        builder.add_arg(v)
    return builder.build()