LoginSignup
8
4

More than 3 years have passed since last update.

TouchDesignerとpython間でOSC

Posted at

背景

TouchDesignerには内部でpythonスクリプトを実行することが出来ますが、様々な事情によりTouchDesigner内部ではないpython (もちろん、他のマシン含め)とやり取りをしなければならない日が来ることもあります。

というケースが数回有りましたので、記録しておきます。

環境:
windows10, macos, TouchDesigner 2020.23680
python 3.7

OSC

TouchDesignerでのOSCについて
https://qiita.com/kodai100/items/5b614fed5f3e17b7f8f6
http://satoruhiga.com/TDWS2018/day9/

python側

pythonoscを使います。

OSC-Python.py

'''
setup instruction 
for Install pythonosc
pip install python-osc

'''

from pythonosc import dispatcher
from pythonosc import osc_server
from pythonosc import udp_client

def messege_handler(unused_addr, *p):
    try:
        print(p)
        client.send_message("/message_echo", p)
    except ValueError: pass

dispatcher = dispatcher.Dispatcher()
dispatcher.map("/message", messege_handler)
server = osc_server.ThreadingOSCUDPServer(("127.0.0.1", 5005), dispatcher)
print("Serving on {}".format(server.server_address))

client = udp_client.SimpleUDPClient("127.0.0.1", 5006)

server.serve_forever()

ここでは、port5005で受け取ったデータをそのまま、port5006へ送り返すようにしています。

TouchDesinger側

OSC OutDATOSC InDATを使います。ポート番号が違うのに注意。

image.png

OSCを送るテストとして、textDATに下記を記載して、runします。

textDat

n = op('oscout1')
n.sendOSC('/message',['something', 9999])

Round Trip

同一マシン内(Windows10のRyzen 3960X CPU)でTD→Python→TDの経過時間は6msでした。IP指定をすれば他のマシンとのやり取りも可能です。

code

8
4
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
8
4