.md →
Knob API#
Knob is a rotary control that looks like a knob on a synth or mixing console.
Unlike CircularSlider (a full 360° ring), it sweeps a
partial arc with a gap at the bottom by default, with a pointer showing the
current position. Angles are measured in degrees clockwise from 12 o'clock, so
the default start_angle=-135 / end_angle=135 gives the classic 270° sweep;
pass a full start_angle=0, end_angle=360 for a gapless dial that wraps.
Ticks are configurable — ticks=N for evenly spaced marks, a list of values, or
(value, label) pairs. Pass steps instead for a rotary selector that snaps
to discrete detents (numbers or named positions). With midi=True the knob shows
a "MIDI learn" button: click it, move a control on your hardware, and the next
control-change message binds to the knob (Web MIDI, Chromium browsers). The
binding is remembered in browser localStorage so it survives a restart.
See also: Fader for the linear console version, and CircularSlider for a full-ring dial.
Bases: AnyWidget
Audio-panel style rotary knob for selecting a single value.
Unlike :class:CircularSlider (a full 360° ring), the knob sweeps a partial
arc with a gap at the bottom, like a synth or mixer knob. A pointer line
shows the current position and you can drag it round. Angles are measured in
degrees clockwise from 12 o'clock, so the default start_angle=-135 /
end_angle=135 gives the classic 270° sweep.
The value range increases clockwise from start_angle (mapped to
min_value) to end_angle (mapped to max_value). Pass a full 360°
sweep (e.g. start_angle=0, end_angle=360) for a gapless full-circle
knob that wraps at the seam.
Examples:
import marimo as mo
from wigglystuff import Knob
gain = mo.ui.anywidget(
Knob(min_value=0, max_value=11, value=5, ticks=12, label="Gain")
)
gain
Create a Knob.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Optional[float]
|
Initial value; defaults to |
None
|
min_value
|
float
|
Lower bound of the value range (at |
0.0
|
max_value
|
float
|
Upper bound of the value range (at |
100.0
|
step
|
float
|
Snap increment in value units (must be > 0). |
1.0
|
start_angle
|
float
|
Angle of |
-135.0
|
end_angle
|
float
|
Angle of |
135.0
|
ticks
|
TickSpec
|
Tick/axis marks. |
None
|
steps
|
Optional[Sequence[Any]]
|
Discrete detents to snap to (a rotary selector). Same shape
as |
None
|
size
|
int
|
Diameter in pixels. |
80
|
label
|
str
|
Optional text label shown above the knob. |
''
|
show_value
|
bool
|
Render the current value as text below the knob. |
True
|
color
|
str
|
Optional CSS color for the value arc and pointer. Empty string uses the theme default. |
''
|
midi
|
bool
|
Show a "MIDI learn" button. Click it, then move a control on
your hardware; the next control-change (CC) message binds to
this knob and drives its value. Uses the Web MIDI API (Chromium
browsers, secure context). Read the binding back via
|
False
|
midi_cc
|
int
|
Bind a control-change number (0-127) up front instead of
learning it. |
-1
|
midi_channel
|
int
|
MIDI channel (0-15) for the binding, or |
-1
|
midi_key
|
str
|
localStorage key for persisting the learned binding across
restarts. Defaults to |
''
|
midi_scope
|
Optional[str]
|
Namespace for the persisted binding, so different notebooks don't collide. Empty (default) uses the browser's URL path automatically; pass an explicit string to pin it (or to intentionally share a mapping across notebooks). |
None
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Source code in wigglystuff/knob.py
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 | |
Synced traitlets#
| Traitlet | Type | Notes |
|---|---|---|
value |
float |
Current value, mapped across the arc. |
min_value |
float |
Lower bound (at start_angle). |
max_value |
float |
Upper bound (at end_angle). |
step |
float |
Snap increment in value units (continuous mode). |
start_angle |
float |
Angle of min_value, degrees clockwise from 12 o'clock. |
end_angle |
float |
Angle of max_value; a 360° span makes a full circle. |
ticks |
list[dict] |
Normalized {"value", "label"} tick marks. |
steps |
list[float] |
Discrete detents to snap to; empty means continuous. |
size |
int |
Diameter in pixels. |
label |
str |
Optional text label shown above the knob. |
show_value |
bool |
Render the current value as text below the knob. |
color |
str |
CSS color for the value arc and pointer. Empty follows the theme. |
midi |
bool |
Show the MIDI-learn button and listen for control-change. |
midi_cc |
int |
Bound control-change number (0-127), or -1 when unbound. |
midi_channel |
int |
Bound MIDI channel (0-15), or -1 for any. |
midi_device |
str |
Name of the bound MIDI input device. |
midi_supported |
bool |
Whether the browser exposes Web MIDI (set from JS). |
midi_learning |
bool |
Whether the knob is currently in learn mode. |
midi_key |
str |
localStorage key for the persisted binding (defaults to label). |
midi_scope |
str |
Namespace for the binding; empty uses the browser URL path. |