Bridges¶
A Bridge is a subprocess MyoGestic spawns alongside the app for heavy-data acquisition that doesn't fit the LSL pull model - typically a webcam decoder that writes frames straight to Zarr and publishes an LSL clock outlet so the rest of the app can align timestamps.
Bridges are registered via app.bridges(...), started before the GUI loop, and terminated as part of App.run()'s cleanup hook chain.
Bridge ¶
A subprocess MyoGestic spawns alongside the app and tears down on exit.
The escape hatch for heavy-data acquisition that doesn't fit the LSL pull model - a webcam decoder that writes frames straight to Zarr, an ultrasound capture daemon, a custom script that owns its own buffer. The bridge subprocess runs whatever it wants; MyoGestic only cares that it stays alive and exits cleanly.
The bridge pattern is intentionally minimal: no IPC contract beyond "the subprocess exists, is alive, and stops on terminate". For data flowing back into the app, the subprocess publishes an LSL outlet (or writes to a Zarr file the app reads) - the same machinery every other source uses.
Registered via app.bridges(...); the app starts them after
streams and tears them down on cleanup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Human label, used in the bridge panel and logs. |
required |
command
|
list[str]
|
argv passed to |
required |
Source code in myogestic/bridges/__init__.py
WebCamBridge ¶
Bases: Bridge
Bridge that runs the built-in webcam decoder subprocess.
Wraps python -m myogestic.bridges.webcam: captures frames from an
OpenCV device, writes them to a Zarr array, and publishes the
per-frame LSL clock so the rest of the app can align webcam time
with EMG time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Bridge label. The published LSL clock outlet is named
|
required |
device
|
int
|
OpenCV device index. |
0
|
zarr_path
|
str
|
Where to write the frame array. Created if missing. |
'session/cam.zarr'
|
Source code in myogestic/bridges/__init__.py
CustomBridge ¶
Bases: Bridge
Bridge that runs an arbitrary user Python script as a subprocess.
The unstructured escape hatch: when the heavy-data source you want
doesn't fit :class:WebCamBridge and you'd rather write the
decoder yourself than subclass :class:Bridge. The script runs
with the same Python interpreter as the app
(sys.executable); the rest is up to you (publish LSL, write
Zarr, talk to a custom message bus, ...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Bridge label. |
required |
script
|
str
|
Path to the Python script to spawn (e.g.
|
required |
Source code in myogestic/bridges/__init__.py
The webcam runner¶
WebCamBridge invokes python -m myogestic.bridges.webcam as a subprocess. The same runner can be launched directly for testing:
uv run python -m myogestic.bridges.webcam --device 0 --zarr session/cam.zarr --lsl-name webcam_clock
Flags:
--device N- OpenCV device index (default0).--zarr PATH- where to write the Zarr array. Frames are appended one chunk per capture.--lsl-name NAME- LSL outlet name for the per-frame timestamp clock; the app subscribes to this to align webcam frames with EMG.