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
| Mapping | Question it answers | Example |
|---|---|---|
| Physical layout | Which control is this? | Raw axis 5 is this measured layout's right trigger |
| Application assignment | What should this gesture do? | Right trigger changes expression; south button plays the selected chord's root |
| Output encoding | What 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:
| Signal | Domain | How to display it |
|---|---|---|
semantic_south | 0–1 | Press/release activity |
semantic_rightTrigger | 0–1 | Continuous travel plus any chosen activation threshold |
semantic_leftStick_x | −1–1 | Centered meter with both directions |
button0, axis0 | Browser-provided raw index | Diagnostic value; identify it before assigning a physical meaning |
ch1.cc11 from MidiControllerSignals | 0–1 | Decoded 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 state | Evidence behind it |
|---|---|
| Control moves or lights | An input sample or edge arrived |
| Assignment label changes | The host accepted an assignment edit |
| Piano key lights | A note is held through the host/module's tracked note path |
| Exercise tone is marked explored | The module recorded that practice action |
| Feedback result changes | The 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.