Controller mappings and feedback

Keep physical layout, musical assignments, live values and device feedback connected without duplicating input handling.

Map a control by what it reports and what your app should do with it. Keep its physical identity available for learning, labels and highlighting. That lets a gamepad trigger and a MIDI expression pedal perform the same musical job while keeping their setup understandable.

Start with Choose a controller connection if you are deciding between browser capture, native input and MIDI relay. The controller API guide owns the complete capture, calibration, learning and MIDI-mapping examples.

Three different mappings

MappingQuestion it answersExample
Physical layoutWhich control is this?Raw axis 5 is this measured layout's right trigger
Application assignmentWhat should this gesture do?Right trigger changes expression; south button plays the selected chord's root
Output encodingWhat does the destination receive?Expression becomes a parameter value directly, or CC11 for a MIDI destination

An SVG region should reference the physical or spatial ID used by the input adapter. Its label can show the manufacturer's legend; its annotation can show the current musical assignment. Changing a chord should not change which region represents the south button.

Read values without losing their meaning

gamepadSignalFrame(state) provides scalar samples for shared inspection, learning and MIDI mapping. For example:

SignalDomainHow to display it
semantic_south0–1Press/release activity
semantic_rightTrigger0–1Continuous travel plus any chosen activation threshold
semantic_leftStick_x−1–1Centered meter with both directions
button0, axis0Browser-provided raw indexDiagnostic value; identify it before assigning a physical meaning
ch1.cc11 from MidiControllerSignals0–1Decoded channel-MIDI value; physical identity needs a device profile

These IDs describe the existing scalar API. A state snapshot does not replace an ordered relative-encoder stream or touch-contact protocol. Use the profiled MIDI bridge at maruaudio/controllers/midi for established device dialects; do not treat an encoder's repeated step code as an absolute fader position.

Learn deliberately

Begin learning from the selected connection's resting state. Move one control, then inspect the candidate before saving its assignment. The shared ControllerSignalLearner returns listening, learned, ambiguous or cancelled states as the gesture proceeds. Its idle state precedes a run.

If several candidates move together, let the person choose. Raw and semantic signals can mirror the same control; prefer semantic IDs for ordinary musical assignments. An observed gesture's minimum and maximum are not proof that the person reached the hardware's full travel. Measure endpoints separately when calibrating an unfamiliar layout.

Changing connections cancels that learning run. Release controls before rearming, and require a fresh press after reconnecting. Preserve the source's connection/configuration lifetime so a replacement controller cannot complete another device's pending gesture.

Reuse the host's parameter assignments

For MIDI parameter control, Maru already has host-owned roles, defaults, learning, curves, takeover behavior and saved overrides. Keep parameter identity tied to its declaration; a display label is not an automation ID. See MIDI CC mapping for that workflow.

The scalar controller library does not make arbitrary gamepad signals into inputs to every host's MIDI Learn UI. A face can interpret its host-provided gamepad and invoke declared note/parameter handles. A MIDI destination can use ControllerSignalMidiMapper through a supplied transport. Generalizing the existing assignment UI to all input types requires host integration.

Keep musical state with the instrument: the chord set, voicing, register and notes it owns. Store the emitted pitch at note-on. If a chord changes while the button is held, release that pitch rather than calculating a new one from the new chord.

Give each visual state one meaning

Visual stateEvidence behind it
Control moves or lightsAn input sample or edge arrived
Assignment label changesThe host accepted an assignment edit
Piano key lightsA note is held through the host/module's tracked note path
Exercise tone is marked exploredThe module recorded that practice action
Feedback result changesThe output request completed, failed or was unsupported

Keep held notes distinct from exercise history. A completed tone can stay marked after release; the piano key should clear when its final owner releases it. Several input sources can share a pitch, so releasing one must not extinguish another source's held note.

Test output separately

Read the selected input's state.feedback.supported before offering vibration. Request an effect from a deliberate action through playFeedback, offer stopFeedback, and display state.feedback.status and any error. The browser adapter supplies bounded whole-controller dual rumble where advertised. It does not supply controller LEDs, adaptive resistance or speaker output.

Completion is a browser acknowledgement, rather than proof someone felt the motor. Record a physical check separately. Selection changes, disconnect, blur/hide, disable and disposal cancel the effect on a best-effort basis.

For MIDI controller lights and displays, use the profile's feedback capabilities and the host's admitted output plan. A command sent to an LED and a button observed as pressed are separate states, even when their colors look similar.

Use the shared GamepadDebugPanel rather than opening a second device session for debugging. Troubleshooting gives a repeatable check from raw input to accepted musical output.