Osc
OssiaNodes
Bases: object
Manage a collection of OSC nodes.
Internal static methods allow to
- add nodes
- remove nodes
- set node parameters
- set node values
- get node values
- set endpoints (nodes with parameters)
Multiple endpoints can be set simultaenously with
- list of paths.
- dictionary of paths (k) and parameter arguments (v)
Parameter arguments must be lists containing
pyossia.ValueType- callback function (optional)
- initial / default value (optional)
- Note: to set a parameter value without a callback, pass None as
- the second argument
Source code in src/cuemsengine/osc/OssiaNodes.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
create_endpoint(path, param_args=None)
Create an endpoint as a node with parameter
Source code in src/cuemsengine/osc/OssiaNodes.py
278 279 280 281 282 283 284 285 286 287 | |
create_endpoints(paths)
Create multiple endpoints
Source code in src/cuemsengine/osc/OssiaNodes.py
289 290 291 292 293 294 295 296 297 | |
get_endpoints()
Get all endpoints (node paths with their parameter arguments)
Source code in src/cuemsengine/osc/OssiaNodes.py
299 300 301 302 303 304 305 306 307 308 309 310 311 | |
get_node(path)
Get a node from the collection
Source code in src/cuemsengine/osc/OssiaNodes.py
81 82 83 | |
get_value(node)
Get a value from a node Parameters: - node: The node to get the value from - str: The path of the node - Node: The node object
Returns:
| Type | Description |
|---|---|
|
Raises:
| Type | Description |
|---|---|
-ValueError
|
If the node is not found |
Source code in src/cuemsengine/osc/OssiaNodes.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
get_value_if_set(path)
Return the node's current value only if set_value(path, ...) has explicitly been called for it; None otherwise.
pyossia gives a freshly-created parameter a raw type-default value (e.g. 0.0 for a Float) with no signal distinguishing "nothing has ever been pushed here" from "explicitly pushed this same value" — get_value() alone can't tell the two apart. Callers that need to fall back to some other source of truth when nothing has been deployed to this client yet (e.g. ActionHandler._build_fade_payload falling back to the CuemsScript-stored level) must use this instead of get_value().
Source code in src/cuemsengine/osc/OssiaNodes.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
record_value(path, value)
Record a value engine-side WITHOUT pushing it over OSC.
For player-side changes the engine commanded but does not itself perform (e.g. gradient-motiond driving a fade to end_value): the parameter mirror never sees them, so get_value_if_set() would keep returning the pre-change level. A later real set_value() push supersedes the recorded value.
Source code in src/cuemsengine/osc/OssiaNodes.py
267 268 269 270 271 272 273 274 275 276 | |
remove_device()
Remove the device and all nodes from the collection.
Safe when __init__ was skipped (e.g. tests that patch a subclass
__init__): missing nodes/device is a no-op, not an error.
Source code in src/cuemsengine/osc/OssiaNodes.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
remove_node(path)
Remove a node from the collection and all its children
Source code in src/cuemsengine/osc/OssiaNodes.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
set_node(path)
Add a new node to the device Node memory address is stored in self.nodes[path] and must be kept to access the node later
Source code in src/cuemsengine/osc/OssiaNodes.py
69 70 71 72 73 74 75 76 77 78 79 | |
set_node_callback(node, callback)
Set a callback to a node
Source code in src/cuemsengine/osc/OssiaNodes.py
155 156 157 158 159 160 161 162 163 164 | |
set_parameter(node, value_type, callback=None, value=None, repetition_filter=True)
staticmethod
Set a parameter to a node
Source code in src/cuemsengine/osc/OssiaNodes.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
set_value(node, value)
Set a value to a node Parameters: - node: The node to set the value to - str: The path of the node - Node: The node object - value: The value to set to the node
Raises:
| Type | Description |
|---|---|
-ValueError
|
If the node is not found |
-ValueError
|
If the value could not be set to the node |
Source code in src/cuemsengine/osc/OssiaNodes.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
OssiaServer
Bases: OssiaNodes
Source code in src/cuemsengine/osc/OssiaServer.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
setup_server(server)
Create a local OSC server
Create a local device and set it up to handle oscquery or osc requests
Source code in src/cuemsengine/osc/OssiaServer.py
42 43 44 45 46 47 48 49 50 51 52 53 54 | |
PyOscServer
Bases: object
Source code in src/cuemsengine/osc/PyOsc.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
add_handlers()
Add handlers to the dispatcher and store them in the handlers dict
Source code in src/cuemsengine/osc/PyOsc.py
79 80 81 82 83 84 85 86 | |
WebSocket OSC Handler for receiving OSC messages via WebSocket.
This module provides an async WebSocket listener that receives and parses OSC messages sent over WebSocket connections (as used by OSCQuery protocol). It bypasses pyossia's unreliable WebSocket handling while keeping pyossia for OSCQuery discovery and metadata.
Usage
In an AsyncCommsThread subclass:
async def websocket_osc_task(self): await websocket_osc_listener( host="0.0.0.0", port=9190, message_handler=self.handle_osc_message, stop_check=lambda: self.stop_requested )
def create_all_tasks(self): return [ asyncio.create_task(self.websocket_osc_task()), # ... other tasks ]
WebSocketOscRouter
Routes OSC messages to registered handlers based on address patterns.
This class provides a simple routing mechanism for OSC messages, allowing handlers to be registered for specific OSC addresses or address patterns.
Usage
router = WebSocketOscRouter() router.register('/engine/command/go', handle_go_command) router.register('/engine/command/*', handle_any_command) # Wildcard
In the message handler:
def handle_osc_message(address, args): router.route(address, args)
Source code in src/cuemsengine/osc/WebSocketOscHandler.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
clear()
Remove all registered handlers.
Source code in src/cuemsengine/osc/WebSocketOscHandler.py
389 390 391 392 | |
register(pattern, handler)
Register a handler for an OSC address pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
OSC address or pattern. Use '*' at the end for wildcard |
required |
handler
|
Callable[[str, list[Any]], None]
|
Callback function to handle messages matching the pattern. Called with (address: str, args: list) |
required |
Source code in src/cuemsengine/osc/WebSocketOscHandler.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
route(address, args)
Route an OSC message to the appropriate handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
OSC address (e.g., '/engine/command/go') |
required |
args
|
list[Any]
|
List of OSC arguments |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if a handler was found and called, False otherwise |
Source code in src/cuemsengine/osc/WebSocketOscHandler.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 | |
build_osc_message(address, value)
Build a binary OSC message for the given address and value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
OSC address (e.g. '/engine/status/running') |
required |
value
|
Any
|
Value to send. Type is inferred: str -> 's', int -> 'i', float |
required |
Returns:
| Type | Description |
|---|---|
Optional[bytes]
|
Bytes to send over WebSocket, or None if building failed. |
Source code in src/cuemsengine/osc/WebSocketOscHandler.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
handle_websocket_connection(websocket, message_handler, stop_check, client_set=None, on_connect=None)
async
Handle a single WebSocket connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
websocket
|
The WebSocket connection |
required | |
message_handler
|
Callable[[str, list[Any]], None]
|
Callback function to handle parsed OSC messages. Called with (address: str, args: list) |
required |
stop_check
|
Callable[[], bool]
|
Function that returns True when the listener should stop |
required |
client_set
|
Optional[set]
|
Optional set to track connected clients for broadcast. If |
None
|
on_connect
|
Optional[Callable]
|
Optional async callback called with the websocket after |
None
|
Source code in src/cuemsengine/osc/WebSocketOscHandler.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
parse_osc_message(data)
Parse a binary OSC message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
Raw binary OSC message data |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, list[Any]] | None
|
Tuple of (address, arguments) if successful, None if parsing fails |
Source code in src/cuemsengine/osc/WebSocketOscHandler.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
websocket_osc_listener(host, port, message_handler, stop_check, existing_server_check=None, client_set=None, on_connect=None)
async
Async WebSocket OSC listener.
Listens for WebSocket connections and parses incoming binary OSC messages. Routes parsed messages to the provided handler callback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
Host address to bind to (e.g., "0.0.0.0" or "127.0.0.1") |
required |
port
|
int
|
Port to listen on (typically the OSCQuery WebSocket port) |
required |
message_handler
|
Callable[[str, list[Any]], None]
|
Callback function to handle parsed OSC messages. Called with (address: str, args: list) |
required |
stop_check
|
Callable[[], bool]
|
Function that returns True when the listener should stop |
required |
existing_server_check
|
Optional[Callable[[], bool]]
|
Optional function that returns True if an |
None
|
Note
The OSCQuery protocol uses the same WebSocket port for both discovery (JSON messages) and OSC value updates (binary messages). This listener only processes binary OSC messages and ignores JSON messages.
If pyossia's OSCQuery server is already using the port, you may need to either: 1. Disable pyossia's WebSocket handler and use this one exclusively 2. Run this on a different port and update the UI configuration 3. Intercept messages at a different layer
Source code in src/cuemsengine/osc/WebSocketOscHandler.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
add_callback_to_all(endpoints, func)
Include the function to the endpoints dictionary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoints
|
dict
|
the endpoints dictionary |
required |
func
|
Callable
|
the function to include |
required |
Source code in src/cuemsengine/osc/helpers.py
159 160 161 162 163 164 165 166 | |
add_callbacks_from_dict(endpoints, cmd_dict)
Include the function endpoints in the endpoints dictionary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoints
|
dict
|
the endpoints dictionary |
required |
cmd_dict
|
dict
|
the command dictionary |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
the endpoints dictionary with the function endpoints included |
Source code in src/cuemsengine/osc/helpers.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
add_prefix_to_all(endpoints, prefix)
Add a prefix to the endpoints dictionary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoints
|
dict
|
the endpoints dictionary |
required |
prefix
|
str
|
the prefix to add |
required |
Source code in src/cuemsengine/osc/helpers.py
169 170 171 172 173 174 175 176 | |
deserialize_node(node_data, parent_node=None)
Deserialize a dictionary structure into pyossia nodes.
Parameters: - node_data: The serialized node structure - parent_node: Optional parent node to attach to
Returns: - pyossia.ossia.Node: The reconstructed node
Source code in src/cuemsengine/osc/helpers.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
new_osc_device(cls)
An OSC device is required to deal with a remote application using OSC protocol
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the device |
required |
host
|
str
|
host ip address |
required |
remote_port
|
int
|
port where osc messages have to be sent to be catch |
required |
local_port
|
int
|
port where OSC requests have to be sent by any remote |
required |
Returns:
| Name | Type | Description |
|---|---|---|
OSCDevice |
OSCDevice
|
an OSC device |
Source code in src/cuemsengine/osc/helpers.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
serialize_node(node)
Serialize a pyossia node and its children to a dictionary structure.
Parameters: - node: The pyossia node to serialize
Returns: - dict: Serialized node structure
Source code in src/cuemsengine/osc/helpers.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
set_osc_server(cls)
LocalDevice.create_osc_server
Make the local device able to handle osc request and emit osc message
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
host ip address |
required |
remote_port
|
int
|
port where osc messages have to be sent to be catch |
required |
local_port
|
int
|
port where OSC requests have to be sent by any remote |
required |
log
|
bool
|
enable protocol logging |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the server has been created successfully |
Source code in src/cuemsengine/osc/helpers.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
set_oscquery_server(cls)
LocalDevice.create_oscquery_server
Make the local device able to handle oscquery request
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
osc_port
|
int
|
port where OSC requests have to be sent by any remote |
required |
log
|
bool
|
enable protocol logging |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the server has been created successfully |
Source code in src/cuemsengine/osc/helpers.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |