1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

python-oscで0がFalseになってしまう時の対処方法

Last updated at Posted at 2018-04-11

概要

python-oscOscMessageBuilderを使ったOSCクライアントからメッセージ引数で0を送受信すると、Type TagがiではなくFすなわちFalseになってしまい、相手のアプリが正しく動かないなどの不具合が発生することがあります。
SimpleUDPClientsend_message()でも同様の問題が起きているようなので、以下の例が参考になれば幸いです。

実例

以下に実例を掲載します。

まず、0Falseになってしまう駄目な場合。

from pythonosc import osc_message_builder
from pythonosc import udp_client

if __name__ == "__main__":
    client = udp_client.UDPClient("127.0.0.1", 5005)

    msg = osc_message_builder.OscMessageBuilder(address="/my_address")
    msg.add_arg(0)
    msg = msg.build()

    client.send(msg)

これを意図通りに0intになるようにするには次のようにします。

from pythonosc import osc_message_builder
from pythonosc import udp_client

if __name__ == "__main__":
    client = udp_client.UDPClient("127.0.0.1", 5005)

    msg = osc_message_builder.OscMessageBuilder(address="/my_address")
    msg.add_arg(0, osc_message_builder.OscMessageBuilder.ARG_TYPE_INT)
    msg = msg.build()

    client.send(msg)

まとめ

このようにadd_argの第二引数にosc_message_builder.OscMessageBuilder.ARG_TYPE_INTを加えることで、0intとして送ることが出来るようになります。
ちなみに、osc_message_builder.OscMessageBuilder.ARG_TYPE_INTの代わりにosc_message_builder.OscMessageBuilder.ARG_TYPE_FLOATを指定すれば、0floatの値として送ることも出来ます。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?