Skip to content

Feature Volume Knob

Xander edited this page Nov 14, 2026 · 3 revisions

Feature Volume Knob

The volume knob is specified to become a bidirectional control, but that work is not built yet. Current-state truth now lives here under the hybrid rule in Wiki-Conventions; the Spec Kit source is frozen at permalink d3cf582 and distilled on Source-Spec-002.

Current state

Implemented today:

  • VolumeKnob.tsx renders one invisible .volume-knob <button> over the painted volume knob and one volume-led-bar below it.
  • Volume is a 12-position step model, 0..11; emitted gain is step / 11.
  • Clicking the current button only moves upward: (step + 1) % 12. At step 11, the next click wraps to 0.
  • The button exposes aria-label="Volume", aria-valuemin="0", aria-valuemax="11", aria-valuenow, and a special max text ending in "one louder".
  • The LED bar has 11 segments. Lit LEDs reflect the current step while enabled; all LEDs dim when disabled.
  • App.tsx holds volume in React state, defaults it to step 6 (6 / 11 gain), calls the audio chain's setVolume(volume), and passes { volume, onVolumeChange, disabled } to VolumeKnob.
  • The indicator maps volume proportionally across the calibrated arc from -235 degrees at step 0 (bottom-left) to 45 degrees at step 11 (down-right). Startup step 6 therefore places it at about 55% of the arc. TV power cycles preserve any volume adjustment made with the knob.
  • voiceStore.ts does not own volume. It tracks speaking, mouth, mic, and greeting flags only.
  • The unit test suite still asserts the old wrap behavior.
  • panel-alignment.spec.ts asserts .volume-knob geometry against the painted TV frame at multiple viewport sizes.

Specified but not implemented:

  • Split hit-area with independent up/down halves.
  • Clamp-at-ends behavior with no wrap and no redundant change notification.
  • Wheel interaction.
  • Keyboard interaction.
  • Rotating indicator animation and reduced-motion behavior.
  • New helper, component, integration, and E2E tests.

Scope carried forward from the frozen spec

The feature preserves the existing public component contract:

{ volume, onVolumeChange, disabled }

It also preserves the current volume meaning:

  • Volume step: integer 0 through 11 inclusive.
  • Gain: normalized audio value, step / 11.
  • Knob angle: presentation-only value derived from the step.

Pointer/tap behavior

  • Click or tap the right half of the knob to raise volume by one step.
  • Click or tap the left half to lower volume by one step.
  • The two halves tile the knob with no dead zone and no overlap; a click on the center line must go to one side.
  • Both halves are inert while the TV is off and must appear unavailable.
  • Both halves remain focusable and enabled at min/max; clamping happens in the handler so focus is not yanked away mid-interaction.
  • The LED readout continues to reflect the current step in both directions.

Clamp behavior

  • Raising at maximum leaves the value at 11.
  • Lowering at zero leaves the value at 0.
  • Attempts to move past either end do not emit onVolumeChange.
  • The old wrap from 11 to 0, and any reverse wrap from 0 to 11, are removed.

Wheel behavior

  • Wheel over the knob changes the volume.
  • deltaY < 0 raises volume, matching the usual "scroll away = more" convention.
  • deltaY > 0 lowers volume.
  • deltaY === 0 does nothing.
  • Wheel input is inert while disabled.
  • The spec notes that React wheel listeners are passive; if page scroll ever becomes a real problem, the escape hatch is a native { passive: false } listener, not a speculative dependency.

Keyboard behavior

  • ArrowUp and ArrowRight raise the volume.
  • ArrowDown and ArrowLeft lower the volume.
  • Home goes to zero.
  • End goes to maximum.
  • Handled keys call preventDefault() so the page does not also scroll.
  • Unrelated keys do nothing.
  • Keyboard input is inert while disabled.
  • The up and down controls expose distinct accessible names: Volume up and Volume down.
  • The knob still exposes current value, minimum, maximum, and max-value text to assistive technology.

Rotating indicator

  • The brass artwork does not rotate. A separate thin cyan pointer overlays the knob and rotates around its center.
  • The frozen source spec described a roughly 270-degree arc from -135deg to 135deg. Current visual calibration follows the requested positions: -235deg at step 0 to 45deg at step 11. Step 2 is 18% of that 280-degree arc.
  • The indicator animates with a springy overshoot: transform 320ms cubic-bezier(0.34, 1.56, 0.64, 1).
  • The indicator must use pointer-events: none so clicks reach the hit-area halves.
  • With prefers-reduced-motion: reduce, the indicator still moves to the correct angle but with no animation.
  • The CSS custom property --knob-angle carries the angle; tests should read it with el.style.getPropertyValue('--knob-angle').

Hard constraints

  1. .volume-knob geometry is test-locked. The E2E alignment suite asserts the hit-area center is within PAINTED.volume.cy = 0.41 with tolerance 0.015 and rechecks viewport sizes 1536x1024, 1280x720, 1920x1080, and 1024x900. Keep the .volume-knob class, width: 55%, aspect-ratio: 1/1, and wrapper positioning stable. The new halves go inside this box with absolute positioning. Do not "fix" failures by editing panel-alignment.spec.ts.
  2. The brass knob is baked pixels in packages/frontend/public/TV-frame.png, not a rendered DOM element. Do not modify the image and do not try to rotate or replace the brass artwork. This is the trap linked from Gotchas.

Implementation outline

The frozen plan breaks the work into TDD cycles:

  1. Add src/config/volume.ts pure helpers and tests: VOLUME_MAX_STEP, VOLUME_LED_COUNT, KNOB_MIN_ANGLE_DEG, KNOB_MAX_ANGLE_DEG, clampStep, gainToStep, stepToGain, stepToAngle.
  2. Rewrite VolumeKnob.tsx so .volume-knob becomes a container group with two real buttons, Volume down and Volume up, plus the unchanged LED bar.
  3. Delete the old wrap-around test and replace it with clamp assertions.
  4. Add keyboard and wheel handling through the same changeStep/clamp path.
  5. Add .volume-knob-indicator and reduced-motion CSS.
  6. Add App-level integration and Playwright E2E coverage, including the unchanged panel-alignment regression.

No new dependencies are required. App.tsx should not need a behavior change, because the component prop contract stays stable.

Tracking

Issue Status Summary
#10 Open Parent scope: bidirectional knob, clamp at ends, wheel, keyboard, rotating indicator, tests, and hard geometry/artwork constraints.
#12 Open P1 bug fix: split left/right hit-area, clamp at zero/max, no redundant notifications, LED tracking, unchanged alignment.
#13 Open P2 affordances: mouse wheel and keyboard-only operation, with handled keys preventing page scroll.
#14 Open P3 polish: cyan rotating pointer, springy settle, reduced-motion behavior, and pointer-events safety.

The four issues had no comments when verified on 2026-09-26.

Out of scope

  • Drag-to-rotate.
  • Touch swipe gestures beyond tapping the split halves.
  • Persisting volume across reloads.
  • A mute toggle.
  • Changing the step count.
  • Changing the gain curve.
  • Retrofitting reduced-motion handling in unrelated components.

See also Component-Volume-Knob, Feature-Max-Height-Core, and Gotchas.

Clone this wiki locally