
Orrery
Musical time: tempo and meter, transports, bar, beat and sample maths, timed MIDI.
Orrery is the component that turns sample frames into musical time and back. It is part of Signals & Sorcery, a coherent set of Rust audio building blocks for audio apps, plugins, players and DAWs.
| Repository | github.com/shiehn/orrery-musical-time |
|---|---|
| License | MIT, free for commercial and closed-source use |
| Status | In preparation |
| Layer | The floor (how the layers stack) |
| Crates (planned names) | orrery |
What it is
An audio callback counts samples. Musicians count bars and beats. Almost every audio application translates between the two, and almost every one writes its own version: what quarter note is this frame, where did the bar start, what should a plugin be told about the loop, when does this MIDI event land in this block. Orrery is that arithmetic as a small, dependency-free crate that a sequencer, a plugin host, a game's music system and a full DAW engine can share.
What exists today:
Tempo: beats per minute, time signature, and the musical position where the current meter's bar grid starts, so bars count from where a new meter began.Transport: everything a block needs to know about musical time: playing or looping, position in quarter notes, seconds and samples, tempo, time signature, loop points and current bar start. A looping clock wraps the way a DAW's play head jumps back at the loop end, and its flags let a plugin host fill a plugin's transport information.bar_start: the last whole bar at or before a position.- Note chasing offsets: when playback starts or loops mid-note, the offsets that make a chased note start cleanly and skip notes about to end.
TimedMidi: a short MIDI message at a frame relative to the loop start.
Every function is pure and safe to call from the audio callback: no allocation, no lock, no system call. No dependencies and no unsafe code. A non-finite or zero sample rate or tempo falls back to a sane default instead of producing NaN.
What is planned: a tempo map (steps and ramps, frame to quarter note in both directions), a meter map with bar, beat and tick positions for display, many named transports on one timeline, a Clock trait with a fake clock for tests, quantisation helpers for launching clips in time, and richer events (longer MIDI messages and MIDI 2.0 style per-note data).
Usage example
Illustrative sketch
The shape of today's types under their planned public names, taken from the README. It is not final.
use orrery::{Tempo, Transport};
let tempo = Tempo { bpm: 128.0, numerator: 4, denominator: 4, bar_origin_ppq: 0.0 };
let sample_rate = 48_000.0;
// The transport for a block starting at frame 96_000, looping over the first 8 bars, while playing.
let loop_frames = (8.0 * 4.0 * 60.0 / 128.0 * sample_rate) as u64;
let t = Transport::at(96_000, loop_frames, sample_rate, tempo, true);
assert!(t.is_playing());
println!("quarter note {:.3}, bar starts at {:.3}", t.ppq, t.bar_start_ppq);
A plugin host passes the same Transport to a plugin. A sequencer uses it to decide which events fall in the block. A metronome uses bar_start to find the downbeat.
The planned tempo map (not written yet):
use orrery::{TempoMap, MeterMap};
let mut tempo = TempoMap::constant(120.0);
tempo.insert_step(Bars(17), 140.0);
tempo.insert_ramp(Bars(33)..Bars(41), 140.0, 90.0);
let ppq = tempo.frame_to_ppq(frame, sample_rate);
let back = tempo.ppq_to_frame(ppq, sample_rate);
let meter = MeterMap::new(4, 4).with_change(Bars(25), 7, 8);
let pos = meter.bar_beat_tick(ppq, 960); // for a display: 25.3.480
How it fits in the ecosystem
Orrery is in the bottom row, the floor, beside Runecraft. Dependencies point down, never up.
Below it: nothing. It depends on no other crate at all, so it is cheap to add to anything, including a plugin or a game.
Above it:
- Summoner (repo) uses
Tempo,Transportand the chase offsets today, to give hosted plugins the transport and to chase notes. - Procession (repo) will use the tempo and meter maps to decide what falls in each block.
- Tapestry (repo) will store a project's tempo and meter maps in Orrery's types.
- Leyline (repo) and Grimoire (repo) will run one or more transports through it.
What it deliberately doesn't do: no scheduling (deciding what plays is Procession's job; Orrery answers "what time is it"), no clocks or threads of its own, no MIDI I/O (crates such as midir do that), and no project data.
| Component | Repository | Role | Status |
|---|---|---|---|
| Runecraft | runecraft-audio-core | Shared contracts, realtime safety, process isolation and realtime-safe logging: the floor every other component stands on | In preparation |
| Orrery | orrery-musical-time | Tempo and meter, transports, bar, beat and sample maths, timed MIDI | In preparation |
| Summoner | summoner-plugin-host | Out-of-process VST3 and Audio Unit plugin hosting with crash isolation | In preparation |
| Aethergate | aethergate-audio-platform | Audio devices (cpal, CoreAudio, a fake device for tests) and shared-memory meters | Planned |
| Leyline | leyline-audio-graph | A realtime audio graph with delay compensation, and a compiler from an edit model to a graph | Planned |
| Cantrips | cantrips-audio-dsp | Built-in mixer DSP: sampler, fader, pan, meters, compressor | Planned |
| Scriptorium | scriptorium-audio-media | Decode and encode, a sample store, streaming voices, crash-safe recording | Planned |
| Tapestry | tapestry-session-model | Tracks, clips, lanes and scenes; edits with undo; a crash-safe project store | Planned |
| Procession | procession-timeline-engine | What plays in each block: regions, notes, automation, launches | Planned |
| Grimoire | grimoire-daw-engine | The assembled engine and its headless JSON-RPC protocol | Planned |
| Familiar | familiar-plugin-sdk | An SDK for plugins and panels that extend a Signals & Sorcery engine | Planned |
| Glyphwork | glyphwork-audio-ui | Audio UI widgets: meters, knobs, faders, waveforms | Planned |
Status
In preparation. The core arithmetic under "What exists today" is written and tested in another repository, under a working crate name. The planned parts are not written yet. Names and signatures may change before the first release.
Pure Rust, so it builds anywhere Rust does: macOS, Windows and Linux. It is a natural fit for WebAssembly and Web Audio players; a no_std build is a later exploration.
Links
- Repository: github.com/shiehn/orrery-musical-time (README, LICENSE)
- Beside it on the floor: runecraft-audio-core
- Used by: summoner-plugin-host, procession-timeline-engine, tapestry-session-model, leyline-audio-graph, grimoire-daw-engine
- All twelve components · For agents · llms.txt