Component rendering and widget gallery¶
Submediant renders equipment panels to images and movie frames. A component declares its ports, children, and displays; a skin supplies measurements and painting. This guide shows the actual renderers, with reproducible Python examples and PNG specimens for every named built-in skin.
These are offline, read-only visualizations. A painted knob does not handle mouse input or change DSP. Change an owning equipment definition or parameter binding, construct a new session, and render again to change a performance. See Generate PCM from Python for that audio path.
From the repository root, install the dependencies and reproduce the images:
python -m pip install -e '.[docs]'
python docs/sphinx/examples/render_components.py
Images are generated under build/docs/components/. The documentation checker
regenerates them before Sphinx and verifies that they reach the published site.
Pillow is included in the docs extra; FFmpeg and an audio render are unnecessary.
Download the complete runnable example.
The downloaded script also works with an installed Submediant package; output
is relative to the current working directory, under build/docs/components/.
Declare settings and signal displays¶
Import the declaration types from submediant.component_model. The example
uses these definitions for every skin, changing only the selected painter:
def make_elements():
gain = FixedRange(0, 1, 2, 3).bind('.65')
fader = FixedRange(0, 1, 2, 3).bind('.35')
frequency = RangedInteger(440, 20, 999, unit='Hz')
def numeric(id_, label, value, control):
display = NumericDisplay(value, control)
return DisplayElement(id_, label, DisplayKind.SETTING,
value=display.text, numeric=display)
signal = SignalRef(('demo',), 'out')
return (
numeric('gain', 'GAIN', gain, NumericControlKind.KNOB),
numeric('fader', 'FADER', fader, NumericControlKind.SLIDER),
numeric('frequency', 'FREQUENCY', frequency, NumericControlKind.READOUT),
DisplayElement('status', 'STATUS', DisplayKind.SETTING, value='DEMO / ON'),
DisplayElement('wave', 'WAVEFORM', DisplayKind.WAVEFORM, signal=signal),
DisplayElement('meter', 'METER', DisplayKind.METER, signal=signal),
DisplayElement('led', 'LED STRIP', DisplayKind.LED_STRIP, signal=signal),
DisplayElement('vertical-led', 'OUT', DisplayKind.LED_STRIP,
signal=signal, orientation=DisplayOrientation.VERTICAL),
StereoLevelDisplay('stereo-level', 'L/R', signal=signal,right_signal=SignalRef(('demo',),'right')),
)
NumericDisplay requires an exact ranged value plus a
NumericControlKind. DisplayElement.value must equal numeric.text.
A setting has no signal reference; a waveform, meter, or LED strip must have
one and has no static value. ComponentPanel holds the elements under
a title; element IDs must be unique within that panel.
For an adjustable parameter, use the range declared by the owning model rather
than inventing a display-only range. FixedRange.bind accepts display units;
from_dsp converts with the range’s base_scale. NumericParameter binds
a range and control kind once and exposes display(value) for a setting.
The gallery’s synthetic controls deliberately use demonstration ranges.
Skin gallery¶
Every image below is a tabletop-style component panel with the same declarations and signal. Numeric values are gain .65, fader .35, and frequency 440 Hz. The signal is a 440 Hz sine at .32 amplitude, sampled at 24 kHz, with a synthetic history ramp. These are widget specimens, not measurements from a song.
There are nine named themes backed by eight renderer families. Navy uses the Amp renderer with its own palette. A numeric KNOB/SLIDER declaration is a semantic request: the selected skin and presentation decide whether it appears as physical hardware or a textual setting. The gallery does not substitute one skin’s knob painter into another.
Atomcore¶
Import ATOMCORE from submediant.skin_model. It uses the analog material
and Atomcore renderer. In tabletop mode, numeric settings use the base text
presentation; the compound signal view adds the analog VU visualization.
Atomcore, tabletop presentation, shared synthetic signal.¶
LED City¶
Use LED_CITY for the digital chassis and palette. Its tabletop numeric
settings also use text rather than Guitar-style physical controls.
LED City, tabletop presentation, shared synthetic signal.¶
Guitar¶
GUITAR draws glossy wood, physical knobs/sliders, and geometric seven-segment
readouts. Its renderer is also the basis of several hardware-oriented families.
Guitar, tabletop presentation, shared synthetic signal.¶
Diagnostic¶
DIAGNOSTIC uses the explicit plain diagram renderer. Its base numeric
settings are textual, keeping the presentation focused on declared data.
Diagnostic, tabletop presentation, shared synthetic signal.¶
Amplifier¶
AMP uses textured black hardware, amplifier knobs, and an analog VU display
with a small scope for signal observations in tabletop mode.
Amp, tabletop presentation, shared synthetic signal.¶
Mixer¶
MIXER uses its dedicated tabletop vertical fader and segmented level meter.
Its compound-layout controls use the inherited painting path instead.
Mixer, tabletop presentation, shared synthetic signal.¶
Drum machine¶
DRUM_MACHINE paints a horizontal LED_STRIP as an illuminated pad with a
level bar. It is driven by signal amplitude and is not an input button.
Drum machine, tabletop presentation, shared synthetic signal.¶
Bass¶
BASS uses a white resin body and the Guitar-family control geometry.
Bass, tabletop presentation, shared synthetic signal.¶
Individual widget recipes¶
These crops are independently rendered panels, not drawings of hypothetical
widgets. The declaration examples all come from make_elements above.
Their appearance is skin-specific; the values and signal references stay typed.
Knob¶
Use DisplayKind.SETTING with
NumericDisplay(value, NumericControlKind.KNOB). The pointer uses the ranged
value’s normalized position. The exact printed value and units come from that
same ranged object, avoiding a second display-only interpretation of the control.
Guitar knob, value .65 within [0, 1].¶
Slider and mixer fader¶
Use NumericControlKind.SLIDER with the same setting declaration. Guitar
paints a horizontal slider; Mixer tabletop mode paints a vertical fader. No
separate fader value type is required.
Guitar tabletop slider at .35.¶
The same declared SLIDER through Mixer tabletop painting.¶
Numeric readout¶
Use NumericControlKind.READOUT for a displayed parameter without a knob or
slider. RangedInteger(440, 20, 999, unit='Hz') supplies the exact value and
units shown here. Readout metadata does not make a parameter adjustable.
Guitar readout, 440 Hz.¶
Text setting or status¶
Use DisplayElement('status', 'STATUS', DisplayKind.SETTING, value='DEMO / ON')
without numeric for text. This is a label/value display, not a toggle.
Static status text in the Guitar skin.¶
Waveform¶
Use DisplayKind.WAVEFORM with a SignalRef naming an observed output.
The painter receives floating-point signal samples. For this isolated specimen,
demo_signal supplies a known sine; normal performance boards select windows
from the execution result. Never pass WAV container bytes as waveform samples.
Guitar tabletop waveform and its derived level summary.¶
Meter¶
Use DisplayKind.METER and a real observed SignalRef. The selected skin
computes RMS/peak summaries from the supplied samples. Guitar uses a level bar;
Amp and Mixer have specialized tabletop meter appearances.
Guitar tabletop meter; the full skin gallery shows the Amp and Mixer variants.¶
Horizontal LED strip¶
Use DisplayKind.LED_STRIP. Horizontal is the default orientation. Levels
are derived from the signal rather than a separately authored LED percentage.
Guitar tabletop horizontal LED strip.¶
Vertical LED strip¶
Pass orientation=DisplayOrientation.VERTICAL to an LED strip declaration.
The skin measures and paints a vertical strip observing the same signal.
Vertical orientation is rejected for the other DisplayKind values.
Guitar tabletop vertical LED strip.¶
Illuminated drum pad¶
The DrumMachine renderer’s horizontal LED strip looks like a pad. Select
DRUM_MACHINE and use the same LED_STRIP declaration to obtain it.
Signal-driven pad; it does not accept clicks or schedule percussion events.¶
Control endpoints and signed values¶
The same declared range determines the displayed number and control position. This image exercises minimum, middle, and maximum values of a signed [-1, 1] range for both knobs and sliders. Out-of-range or excess-precision parameter values are rejected, rather than silently changing a control’s range to fit.
Signed controls at -1.00, .00, and 1.00; each uses two decimal places.¶
Standard, compact, and tiny presentation¶
The tabletop images above use hardware=True. Compound panels use
hardware=False and STANDARD, COMPACT, or TINY presentation. These comparisons
use the same gain setting and waveform through the Guitar renderer:
STANDARD compound presentation, including waveform and synthetic level history.¶
COMPACT presentation uses compact numeric and signal summaries.¶
TINY presentation uses text summaries. These are rendering choices, not new DSP.¶
Bind, measure, and paint¶
The composition root builds the typed skin factory with Config. Painters do not construct injectors or discover services themselves:
def skin_factory():
# The composition root owns Config/injection. Painters receive typed objects.
return get_injector(EquipmentSkinConfig()).inject(EquipmentSkinFactory)
factory.bind(theme) returns the selected definition/renderer pair.
renderer.measure accounts for labels, units, and the chosen presentation.
The example uses those natural sizes in a small gallery-only shelf layout:
def paint_panel(factory, theme, elements, *, hardware=True,
presentation=Presentation.STANDARD, columns=4):
renderer = factory.bind(theme).renderer
component = ComponentDefinition(
'demo', 'Component demonstration', (audio_out(),audio_out('right')), generator=True,
panel=ComponentPanel('Component demonstration', tuple(elements)),
)
# Measure first. The small gallery uses four shelf-packed columns; production
# performances use PerformanceLayout/TabletopLayout rather than these shelves.
sizes = [renderer.measure(e, presentation, hardware=hardware) for e in elements]
columns = min(columns, len(elements))
widths = [max(sizes[i][0] for i in range(c, len(elements), columns))
for c in range(columns)]
rows = [max(h for _, h in sizes[i:i + columns])
for i in range(0, len(elements), columns)]
width, height = sum(widths) + 24 * (columns + 1), sum(rows) + 24 * (len(rows) + 1) + 64
image = Image.new('RGB', (width, height))
renderer.background(image, theme)
box = Rect(10, 10, width - 20, height - 20)
group = ComponentGroup(('demo',), component.label, box, component.ports, 0, 0)
renderer.paint_group(image, theme, group)
renderer.text(image, theme, (28, 24), theme.name, 14, True)
values, history = demo_signal()
placements = []
for i, element in enumerate(component.panel.elements):
row, col = divmod(i, columns)
x, y = 24 + sum(widths[:col]) + 24 * col, 64 + sum(rows[:row]) + 24 * row
w, h = sizes[i]
placement = DisplayPlacement(DisplayId(('demo',), element.id), component.label,
element, Rect(x, y, w, h), presentation, hardware=hardware)
assert box.contains(placement.box)
assert all(not placement.box.overlaps(other.box) for other in placements)
placements.append(placement)
if isinstance(element,StereoLevelDisplay):
renderer.stereo_levels(image,theme,placement,values,values*.3)
elif presentation is not Presentation.STANDARD:
renderer.compact(image, theme, placement, values)
elif hardware:
renderer.hardware_element(image, theme, placement)
if element.signal is not None:
renderer.hardware_signal(image, theme, placement, values, i)
else:
renderer.element(image, theme, placement)
if element.signal is not None:
renderer.signal(image, theme, placement, values, history, i)
return image
After defining the example’s imports and functions, render a standalone panel:
image = paint_panel(skin_factory(), GUITAR, make_elements())
Path("build").mkdir(exist_ok=True)
image.save("build/component.png")
In a normal equipment performance, PerformanceLayout/TabletopLayout produces
placements and PerformanceBoard/TabletopBoard dispatches the corresponding
painting calls. Custom equipment declares its panel through the equipment’s
component property, returning the complete ComponentDefinition with real
ports and observation paths. Preserve every required display and child; adding
a picture does not create a new signal, exposed port, or DSP node.
Choose a device-specific skin with its typed skin field, or set a studio
skin/render fallback. Equipment resolves device override, then family skin,
then render fallback, then studio default. A fallback does not replace an
instrument’s existing family choice. For a custom palette, use
dataclasses.replace on an existing SkinDefinition and its typed palettes;
for different drawing behavior, override the owning get_*_skin_class hook
in EquipmentStudioConfig, calling super().configure() for extra bindings.
Respect the selected renderer’s measurements before audio execution. Reject insufficient space instead of squeezing controls, truncating numeric values, or overlaying signal regions. Changing only presentation must preserve PCM; widget images and video are observations of the performance, not its controls.
Split stereo levels¶
StereoLevelDisplay observes distinct left and right signal references in one
mono-width vertical meter. Both channels use the same fixed dBFS scale and time
window. This specimen uses the declared synthetic sine on left and a separately
attenuated 0.3-times signal on right. Compound compact/tiny text preserves both
values; tabletop hardware retains the measured 48-pixel footprint.
Mixer-style sliders retain their existing three-digit numeric values, signs and decimal points. The narrower skin measures these complete values and wraps labels instead of rounding settings or removing units.