Пример #1
0
 def test_blob(self):
   self.assertEqual(
       b'\x00\x00\x00\x02\x00\x01\x00\x00',
       osc_types.write_blob(b'\x00\x01'))
   self.assertEqual(
       b'\x00\x00\x00\x04\x00\x01\x02\x03',
       osc_types.write_blob(b'\x00\x01\x02\x03'))
Пример #2
0
def encode_osc_data(type, data):
    if type == "i":
        value = ctypes.c_int32(ctypes.c_uint32(int(data)).value).value
        return osc_types.write_int(value)
    elif type == "f":
        return osc_types.write_float(float(data))
    elif type == "s":
        return osc_types.write_string(data)
    elif type == "b":
        return osc_types.write_blob(data)
    else:
        raise RuntimeError("Unknown OSC type")
Пример #3
0
    def build(self) -> osc_message.OscMessage:
        """Builds an OscMessage from the current state of this builder.

        Raises:
          - BuildError: if the message could not be build or if the address
                        was empty.

        Returns:
          - an osc_message.OscMessage instance.
        """
        if not self._address:
            raise BuildError('OSC addresses cannot be empty')
        dgram = b''
        try:
            # Write the address.
            dgram += osc_types.write_string(self._address)
            if not self._args:
                dgram += osc_types.write_string(',')
                return osc_message.OscMessage(dgram)

            # Write the parameters.
            arg_types = "".join([arg[0] for arg in self._args])
            dgram += osc_types.write_string(',' + arg_types)
            for arg_type, value in self._args:
                if arg_type == self.ARG_TYPE_STRING:
                    dgram += osc_types.write_string(value)
                elif arg_type == self.ARG_TYPE_INT:
                    dgram += osc_types.write_int(value)
                elif arg_type == self.ARG_TYPE_INT64:
                    dgram += osc_types.write_int64(value)
                elif arg_type == self.ARG_TYPE_FLOAT:
                    dgram += osc_types.write_float(value)
                elif arg_type == self.ARG_TYPE_DOUBLE:
                    dgram += osc_types.write_double(value)
                elif arg_type == self.ARG_TYPE_BLOB:
                    dgram += osc_types.write_blob(value)
                elif arg_type == self.ARG_TYPE_RGBA:
                    dgram += osc_types.write_rgba(value)
                elif arg_type == self.ARG_TYPE_MIDI:
                    dgram += osc_types.write_midi(value)
                elif arg_type in (self.ARG_TYPE_TRUE,
                                  self.ARG_TYPE_FALSE,
                                  self.ARG_TYPE_ARRAY_START,
                                  self.ARG_TYPE_ARRAY_STOP,
                                  self.ARG_TYPE_NIL):
                    continue
                else:
                    raise BuildError('Incorrect parameter type found {}'.format(
                        arg_type))

            return osc_message.OscMessage(dgram)
        except osc_types.BuildError as be:
            raise BuildError('Could not build the message: {}'.format(be))
Пример #4
0
  def build(self):
    """Builds an OscMessage from the current state of this builder.

    Raises:
      - BuildError: if the message could not be build or if the address
                    was empty.

    Returns:
      - an osc_message.OscMessage instance.
    """
    if not self._address:
      raise BuildError('OSC addresses cannot be empty')
    dgram = b''
    try:
      # Write the address.
      dgram += osc_types.write_string(self._address)
      if not self._args:
        dgram += osc_types.write_string(',')
        return osc_message.OscMessage(dgram)

      # Write the parameters.
      arg_types = "".join([arg[0] for arg in self._args])
      dgram += osc_types.write_string(',' + arg_types)
      for arg_type, value in self._args:
        if arg_type == self.ARG_TYPE_STRING:
          dgram += osc_types.write_string(value)
        elif arg_type == self.ARG_TYPE_INT:
          dgram += osc_types.write_int(value)
        elif arg_type == self.ARG_TYPE_FLOAT:
          dgram += osc_types.write_float(value)
        elif arg_type == self.ARG_TYPE_DOUBLE:
          dgram += osc_types.write_double(value)
        elif arg_type == self.ARG_TYPE_BLOB:
          dgram += osc_types.write_blob(value)
        elif arg_type == self.ARG_TYPE_RGBA:
          dgram += osc_types.write_rgba(value)
        elif arg_type == self.ARG_TYPE_MIDI:
          dgram += osc_types.write_midi(value)
        elif arg_type in (self.ARG_TYPE_TRUE,
                          self.ARG_TYPE_FALSE,
                          self.ARG_TYPE_ARRAY_START,
                          self.ARG_TYPE_ARRAY_STOP):
          continue
        else:
          raise BuildError('Incorrect parameter type found {}'.format(
              arg_type))

      return osc_message.OscMessage(dgram)
    except osc_types.BuildError as be:
      raise BuildError('Could not build the message: {}'.format(be))
Пример #5
0
  def build_dgram(self):
    """Builds an OscMessage datagram from the current state of this builder.

    Raises:
      - BuildError: if the message could not be build or if the address
                    was empty.

    Returns:
      - an osc_message.OscMessage instance.
    """
    if not self._address:
      raise BuildError('OSC addresses cannot be empty')
    dgram = b''
    try:
      # Write the address.
      dgram += osc_types.write_string(self._address)
      if not self._args:
        dgram += osc_types.write_string(',')
        return osc_message.OscMessage(dgram)

      # Write the parameters.
      arg_types = "".join([arg[0] for arg in self._args])
      dgram += osc_types.write_string(',' + arg_types)
      for arg_type, value in self._args:
        if arg_type == self.ARG_TYPE_STRING:
          dgram += osc_types.write_string(value)
        elif arg_type == self.ARG_TYPE_INT:
          dgram += osc_types.write_int(value)
        elif arg_type == self.ARG_TYPE_FLOAT:
          dgram += osc_types.write_float(value)
        elif arg_type == self.ARG_TYPE_BLOB:
          dgram += osc_types.write_blob(value)
        elif arg_type == self.ARG_TYPE_TRUE or arg_type == self.ARG_TYPE_FALSE:
          continue
        else:
          raise BuildError('Incorrect parameter type found {}'.format(
              arg_type))
      return dgram
    except osc_types.BuildError as be:
      raise BuildError('Could not build the message: {}'.format(be))
    def build(self):
        """Builds an OscMessage from the current state of this builder.

    Raises:
      - BuildError: if the message could not be build or if the address
                    was empty.

    Returns:
      - an osc_message.OscMessage instance.
    """
        if not self._address:
            raise BuildError("OSC addresses cannot be empty")
        dgram = b""
        try:
            # Write the address.
            dgram += osc_types.write_string(self._address)
            if not self._args:
                return osc_message.OscMessage(dgram)

            # Write the parameters.
            arg_types = "".join([arg[0] for arg in self._args])
            dgram += osc_types.write_string("," + arg_types)
            for arg_type, value in self._args:
                if arg_type == self.ARG_TYPE_STRING:
                    dgram += osc_types.write_string(value)
                elif arg_type == self.ARG_TYPE_INT:
                    dgram += osc_types.write_int(value)
                elif arg_type == self.ARG_TYPE_FLOAT:
                    dgram += osc_types.write_float(value)
                elif arg_type == self.ARG_TYPE_BLOB:
                    dgram += osc_types.write_blob(value)
                elif arg_type == self.ARG_TYPE_TRUE or arg_type == self.ARG_TYPE_FALSE:
                    continue
                else:
                    raise BuildError("Incorrect parameter type found {}".format(arg_type))

            return osc_message.OscMessage(dgram)
        except osc_types.BuildError as be:
            raise BuildError("Could not build the message: {}".format(be))
Пример #7
0
 def test_blob(self):
     self.assertEqual(b'\x00\x00\x00\x02\x00\x01\x00\x00',
                      osc_types.write_blob(b'\x00\x01'))
     self.assertEqual(b'\x00\x00\x00\x04\x00\x01\x02\x03',
                      osc_types.write_blob(b'\x00\x01\x02\x03'))