
pytosc: generate and edit TouchOSC layouts from Python.
GitHub repo: pytosc
$ pip install py2tosc
No dependencies. Python 3.10 or newer. Documentation
Why
TouchOSC layouts are drawn by hand in a GUI editor, which is the right tool right up until the work is repetitive. Laying out a fader per parameter for a plugin with fifty-four of them, numbering an eight-by-eight pad grid, renaming two hundred controls, restyling everything, or keeping a layout in step with a config file -- all of it is an afternoon of clicking, or a few lines of Python:
import py2tosc
from py2tosc import ui
faders = [py2tosc.fader(name=f"ch{n}", messages=[ui.midi_cc(n - 1)])
for n in range(1, 9)]
doc = py2tosc.Document(root=ui.row(
*faders,
gap=4,
pad=8,
frame=(0, 0, 1024, 768),
name="mixer",
))
# `ui.row` records how the faders should be arranged but cannot size them,
# since it runs before the frame above it exists. `resolve` walks the finished
# tree and divides that frame among them -- nothing has coordinates until it does.
doc.resolve()
doc.save("mixer.tosc")
Note that py2tosc is a rewrite of tosclib by Alberto Valdez, whose work established the original mapping between the .tosc format and Python that this library is built on.
u/alikesu — 6 days ago