跳转到主要内容

duit数据字段的OSC通信支持。

项目描述

OSC for Duit

PyPI Github

为duit数据字段提供Open Sound Control通信。

这是数据ui工具包(duit)的一个附加模块,它添加了对DataFields的输入和输出支持。

安装

可以从PyPI直接安装此软件包。

pip install duit-osc

文档

Duit-osc使用python-osc~=1.8)作为OSC后端以接收和发送消息。主类是OscService,它处理传入和传出OSC服务器和客户端。它还将注解的DataFields映射到相应的路由。

OscEndpoint

可以使用OscEndpoint注解注解现有的DataFields。此注解稍后会告诉OscService该字段是否需要通过OSC公开。建议将所有DataFields收集在一个单独的对象中。

from duit_osc.OscEndpoint import OscEndpoint

class Config:
    def __init__(self):
        self.name = DataField("Cat") | OscEndpoint()

默认情况下,变量的名称(例如name)用作OSC地址标识符。可以通过OscEndpoint注解更改名称。

self.name = DataField("Cat") | OscEndpoint(name="the-cats-name")

方向

默认情况下,注解的DataField在更改时发送OSC消息,并由传入的OSC消息更改。此行为可以通过OscEndpoint注解的OscDirection选项进行控制。

from duit_osc.OscDirection import OscDirection

# ...
self.name = DataField("Cat") | OscEndpoint(direction=OscDirection.Send)
  • OscDirection
    • 发送 - 仅在更改数据字段值时发送。
    • 接收 - 仅接收数据字段值。
    • 双向(默认) - 通过OSC发送和接收值

OscService

如前所述,OscService处理OSC服务器和与DataFields的映射。以下是一个如何创建OscService、添加之前定义的配置并启动服务的基本示例。

# create an actual instance of the config
config = Config()

# create an osc service
osc_service = OscService()

# add the config object (create mapping) under the route "/config"
osc_service.add_route("/config", config)

# print the api description of the service (experimental)
print(osc_service.api_description())

# run the service
osc_service.run()

设置

OscService有几个默认参数,如hostin_portout_port等。在启动服务之前可以更改这些参数。

# OscService parameters and the default values
host: str = "0.0.0.0", # on which interface the service is running
in_port: Optional[int] = 8000, # on which port the OscServer is started
out_port: Optional[int] = 9000, # on which port the OscClient is sending
allow_broadcast: bool = True, # if broadcasting is allowed
send_on_receive: bool = False # Indicated if a message that has been received should be also sent out again (reply the change back)

路由

可以将各种对象添加到 OscService,每个对象都有一个唯一的路由(地址)。

osc_service.add_route("/config", config)

每个 DataField 都会在这个路由下添加,例如 name 字段将获得 OSC 地址 /config/name

启动

要启动服务,需要调用 run() 方法。这是一个阻塞方法,直到服务关闭才返回。如果它应该作为后台线程运行,请使用 blocking 参数。

osc_service.run(blocking=False)

API 描述

可以打印 API 描述。这是一个高度实验性的功能,未来可能会有所变化。

print(osc_service.api_description())

关于

版权所有 (c) 2024 Florian Bruggisser

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定该选择哪个,请了解更多关于 安装包 的信息。

源代码发行版

此版本没有提供源代码发行版文件。请参阅关于 生成发行版存档 的教程。

构建发行版

duit_osc-0.2.0-py3-none-any.whl (10.4 kB 查看散列值)

上传时间 Python 3

支持

AWSAWS云计算和安全赞助商DatadogDatadog监控FastlyFastlyCDNGoogleGoogle下载分析MicrosoftMicrosoftPSF赞助商PingdomPingdom监控SentrySentry错误日志StatusPageStatusPage状态页面