Control surfaces¶
Building a layout from a list of parameters. This is what the
py2tosc build subcommand calls, and what
tests/demos/control_surface.py demonstrates.
read ¶
Read a parameter list, in either of the shapes worth accepting.
A list of names is the short form. A list of objects is the long one, and
only name is required:
["Threshold", "Ratio"]
[{"name": "Threshold", "cc": 20, "channel": 1}, {"name": "Ratio"}]
A plugin host exports an index alongside each name. It is deliberately
ignored: an index identifies the parameter to the host and is not a
controller number, and a real one runs well past the 127 a CC allows. Say
cc if you mean a controller number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
Any
|
The parsed JSON. |
required |
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
The parameters, in order. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the payload is not a list, or an entry is neither a string nor an object. |
ValueError
|
If an entry is an object with no name. |
Source code in src/py2tosc/surface.py
Parameter
dataclass
¶
One thing to put on the surface.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
What it is called. Shown as the caption, and slugged for the control's name, which is what the OSC address is built from. |
cc |
int | None
|
The MIDI control change number. |
channel |
int
|
The MIDI channel, 0-15. |
Source code in src/py2tosc/surface.py
build ¶
build(
parameters: Sequence[Parameter],
*,
prefix: str = "surface",
midi: bool = True,
osc: bool = True,
columns: int = COLUMNS,
rows: int = ROWS,
frame: tuple[int, int, int, int] = (0, 0, *SIZE),
) -> Document
Lay parameters out across as many pages as they need.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
Sequence[Parameter]
|
What to put on it, in order. |
required |
prefix
|
str
|
The OSC namespace every address hangs off. |
'surface'
|
midi
|
bool
|
Whether to bind each control to a MIDI CC. |
True
|
osc
|
bool
|
Whether to give each control an OSC address. |
True
|
columns
|
int
|
Controls across each page. |
COLUMNS
|
rows
|
int
|
Controls down each page. |
ROWS
|
frame
|
tuple[int, int, int, int]
|
The design canvas, as |
(0, 0, *SIZE)
|
Returns:
| Type | Description |
|---|---|
Document
|
The document, resolved and ready to save. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are no parameters, or neither binding is wanted. |
Source code in src/py2tosc/surface.py
slug ¶
An OSC-safe name, since an address cannot contain a space.
OSC also reserves #, *, ,, ?, [, ], { and }, so anything
that is not alphanumeric is dropped rather than substituted.
Source code in src/py2tosc/surface.py
namespace ¶
An OSC-safe address prefix, which may be more than one segment deep.
Each segment is slugged on its own, so Synth/Bank 1 survives as
synth/bank1 rather than collapsing into a single name.