# `Mx.Inputs`
[🔗](https://github.com/mx-music/mx/blob/main/lib/mx/inputs.ex#L1)

Keeps the latest value of every input from outside mx, and the values loops share.

It listens to every MIDI input port connected when it starts, and for OSC on the port the song names with `osc_from`.
It keeps the value of each MIDI controller by number, the velocity of each MIDI note by number, 0 once the note is off, and the arguments of each OSC address, whatever port or channel they came from.
A loop's pass reads a snapshot of them all, so a pass reads one moment of the inputs from start to end.
Each input is also sent to subscribers as `{:input, event}`, so the band can start the loops it triggers.

A shared value is kept with the beat of the set step that set it, and the real time of that beat.
A pass starting on a beat reads, for each name, the value the last set step before that beat left, so a set step on that beat reaches it only from its next pass on.
Loops work out their passes ahead of time and in no fixed order, so each loop the band follows says how far it has worked out, and a pass's snapshot waits until every other followed loop has worked out up to its beat.
The loop furthest behind never waits, so no two loops wait for each other; a snapshot waits no later than the time it is given, so a loop that hangs makes the others read without its values instead of stopping them.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `listen`

Listens for OSC on a UDP port, as the song's `osc_from` asks.

# `put`

Shares a value under `name` with every loop from `beat` on, a set step's beat, which plays at the Unix time `at_us`.

# `snapshot`

The latest value of every input, and each shared value as the set steps whose beat has come left it.

# `snapshot_at`

Every input and shared value as a pass starting at `beat` reads them, as a map it reads from start to end.
It waits until every other loop followed has worked out up to `beat`, or until the Unix time `until_us` in microseconds.

# `start_link`

Starts listening to the MIDI inputs, unless `midi: false`, under the name in `opts`, or `Mx.Inputs` unless `name: nil`.

# `subscribe`

Sends each input that arrives to `pid` as `{:input, event}`.

# `worked_out`

Follows the loop `pid`, which has handed over every set step before `beat`; nil stops following it, as does its exit.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
