Orrery musical time illustration

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.

Repositorygithub.com/shiehn/orrery-musical-time
LicenseMIT, free for commercial and closed-source use
StatusIn preparation
LayerThe 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 READMEopen in new window. 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:

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.

Extend and display
The engine
Musical structure
Signal flow
ComponentRepositoryRoleStatus
Runecraftrunecraft-audio-coreShared contracts, realtime safety, process isolation and realtime-safe logging: the floor every other component stands onIn preparation
Orreryorrery-musical-timeTempo and meter, transports, bar, beat and sample maths, timed MIDIIn preparation
Summonersummoner-plugin-hostOut-of-process VST3 and Audio Unit plugin hosting with crash isolationIn preparation
Aethergateaethergate-audio-platformAudio devices (cpal, CoreAudio, a fake device for tests) and shared-memory metersPlanned
Leylineleyline-audio-graphA realtime audio graph with delay compensation, and a compiler from an edit model to a graphPlanned
Cantripscantrips-audio-dspBuilt-in mixer DSP: sampler, fader, pan, meters, compressorPlanned
Scriptoriumscriptorium-audio-mediaDecode and encode, a sample store, streaming voices, crash-safe recordingPlanned
Tapestrytapestry-session-modelTracks, clips, lanes and scenes; edits with undo; a crash-safe project storePlanned
Processionprocession-timeline-engineWhat plays in each block: regions, notes, automation, launchesPlanned
Grimoiregrimoire-daw-engineThe assembled engine and its headless JSON-RPC protocolPlanned
Familiarfamiliar-plugin-sdkAn SDK for plugins and panels that extend a Signals & Sorcery enginePlanned
Glyphworkglyphwork-audio-uiAudio UI widgets: meters, knobs, faders, waveformsPlanned

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.

Last Updated:
Contributors: shiehn