Mx.Inputs (mx v0.1.0)

Copy Markdown View Source

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.

Summary

Functions

Returns a specification to start this module under a supervisor.

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

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

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

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.

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

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

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

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

listen(inputs \\ __MODULE__, port)

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

put(inputs \\ __MODULE__, name, value, beat, at_us)

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(inputs \\ __MODULE__)

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

snapshot_at(inputs \\ __MODULE__, beat, until_us)

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(opts)

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

subscribe(inputs \\ __MODULE__, pid)

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

worked_out(inputs \\ __MODULE__, pid, beat)

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