Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-midi

MIDI for Luce programs: list sources and destinations, hear every message timestamped on the host clock through lock-free rings (one for a realtime audio thread, one for the UI), and send short messages. macOS (CoreMIDI) first.

A library written in luce-base. Latest release 0.1.0.

Install#

luc add dymokomi/luce-midi

Documentation#

luce-midi

MIDI for Luce programs. macOS (CoreMIDI) first; Windows and Linux answer unsupported for now.

Modules

  • midi — list the MIDI sources and destinations; open an input that hears every source (or a chosen set, by unique id), turning each message into a fixed-size Event stamped on the host clock in nanoseconds; send short messages through an Output.

Two rings, two threads

An Input pushes every message into two lock-free single-producer rings:

  • audio() for a realtime audio thread, drained at the start of each block so notes play with no lock and no allocation;
  • main() for the UI thread, for recording, an activity light or MIDI learn.

The read proc runs on CoreMIDI's own (non-realtime) thread and calls a wake you pass to Input.open — a luce-std wake.Waker (a luce-ui Notifier.waker()), or a plain function and context — so the UI hears new messages without polling. The sources coming and going reconnect the port, bump generation and wake the same way.

from luce_midi import midi

var input = try midi.Input.open(waker = notifier_waker)
defer input.close()
var event: midi.Event
let ring = input.main() else return
while ring.next(&event):
    # event.status, event.data1, event.data2, event.source, event.nanos

Messages

Channel messages and system common become events, running status expanded. A note on with velocity 0 is kept raw (callers treat it as a note off). SysEx is dropped; clock, start, continue and stop are kept; active sensing is dropped. See the module header in src/midi.lucb for the details.

Tools

tools/midi-probe lists the sources and destinations and logs what comes in for a few seconds; given a destination id it sends a note and listens for it back (a loopback through a virtual bus).

Licence

MIT or Apache-2.0, at your option.

Dependencies#

PackageVersion
dymokomi/luce-stdnewest

Versions#

0.1.0

Browse source · pack · commit 338e7db6107a

SHA-256 0ed338efe9e70beee450d4ee43c63b934309ced9b9f98afbd891f8d5e9d006ee

luce-midi 0.1.0: first release