Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
HW0a: a page plays a sound now, on raea's mixer. raea's window has no Web Audio graph (sdk/ui platform audio.ts leaves AudioContext out), so a page's interaction sounds had no way to be heard: only a composition reached the mixer, a frame at a time. Live::fire (systems/mix live/fire.rs) plays raea/tone events at the clock's now plus the head plus their own time, building the graph when it changes; raea-page-sound (engine/page/sound) is the page's sound.fire and sound.report calls, a mixer of the page's own on a thread that opens the device on the first fire and rests its stream after 10 s idle; raea/tone's fire(play) runs play as <Sfx> runs a game's one-shot and sends its events, and the graph when it changed, to sound.fire (a browser gets no sound and one console line). Spec: docs/hardware.feature (Shane 11-14: a dark kit of our own, SPEC-01's idiom, its sounds on raea/tone and Firewheel)
shinyobjectz4c392f60d696
diff --git a/Cargo.lock b/Cargo.lockindex df40d696..f9ed88d7 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -14677,6 +14677,7 @@ dependencies = ["raea-io-net-calls","raea-io-os","raea-page",+ "raea-page-sound","raea-page-stage","raea-page-window","raea-rune-slots",@@ -14693,6 +14694,16 @@ dependencies = ["tiny_http",]+[[package]]+name = "raea-page-sound"+version = "0.1.0"+dependencies = [+ "bevy",+ "raea-runtime-js",+ "raea-sys-mix",+ "serde_json",+]+[[package]]name = "raea-page-stage"version = "0.1.0"diff --git a/Cargo.toml b/Cargo.tomlindex 2ebd2761..b5426bf5 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -53,6 +53,7 @@ members = ["engine/rune/js","engine/rune/layer","engine/rune/slots",+ "engine/page/sound","engine/page/stage","engine/page/window","io/trace",diff --git a/docs/hardware.feature b/docs/hardware.featurenew file mode 100644index 00000000..4cb5a032--- /dev/null+++ b/docs/hardware.feature@@ -0,0 +1,115 @@+@spec+Feature: Hardware: controls that feel like instruments, heard on raea's own mixer+ Shane, 2026-11-14, pointing at SPEC-01 (spec-01.vercel.app, a shadcn registry of controls drawn as hardware, its+ sounds made with the browser's Web Audio): "i want to have this ui kit installed across the app where relevant with+ sounds especially for controllers ... wrap the app in <Hardware> ... and have a sound off button in settings. this+ could be used for so many things and feels aligned with our vibe and brand." Then, on how its sounds would play in+ raea's window: "why web audio isnt it in a raea engine its rendering wouldnt we use raea tone.js/firewheel?" And:+ "we would make our own version of it no need to use theirs for real unless it makes sense. we keep dark mode."++ So: raea's own kit, dark, in the idiom SPEC-01 shows (keys that go down and come back, latches, detents, knobs,+ faders, readouts), with its sounds written in raea/tone and played by raea's mixer on Firewheel. None of SPEC-01's+ code is taken; it is credited as the inspiration (Apache-2.0, Vercel Labs' ui-sdk).++ What there is to build on (read 11-14):+ - raea's window has no Web Audio graph on purpose (sdk/ui/src/platform/audio.ts: decodeAudioData only, AudioContext+ not installed, "so a page that looks for it finds it missing rather than half there"). A web kit's sounds are+ silent there.+ - raea/tone (sdk/audio/src/tone) is Tone.js's API on raea's one mixer core: instruments, effects and buses (one of+ them `ui`) as a graph (`<audio data-tone-graph>`) and events (`<audio data-tone-evs>`). Today only a composition+ reaches the mixer: a render bounces it (systems/mix offline.rs) and the stage plays it live (systems/mix live.rs,+ `Live::sync` a frame at a time). A page's own interactions have no way in.+ - The page's host calls (raea-runtime-js HostCalls; the stage's in engine/page/stage calls.rs), reached from a page+ as `__raea_engine.call(name, args)`.++ Status, 11-14: spec written; HW0 to HW4 being built.++ Background:+ Given the engine's part is systems/mix (the mixer) and engine/page/sound (the page's call), the SDK's is+ sdk/audio/src/tone (fire), and the app's is raea-feed src/hardware++ Rule: HW0. A page plays a sound now, on raea's mixer+ # Plan (crate or package | file | lines | job)+ # raea-sys-mix | src/live/fire.rs | 80 | Live::fire: a graph built when it changes, events at the clock's now+ # raea-page-sound | src/lib.rs | 120 | the page's `sound.fire` call: a mixer of its own on a thread, resting when idle+ # @raea/audio | src/tone/fire.ts | 80 | fire(play): a page's one-shot, as <Sfx> is a game's, sent to the call++ Scenario: HW0a. sound.fire+ Given a page in raea's window (the app, a plugin's page, any page the page host shows)+ When it calls sound.fire with a raea/tone graph and a list of events+ Then the graph is built on the page's own mixer when it is new or changed, and each event plays at the clock's+ now plus the mixer's head plus the event's own time: no frame and no timeline stand in between+ And the call answers at once; it never waits for the sound+ And RAEA_AUDIO_MUTE=1 silences it as it silences every mixer++ Scenario: HW0b. Heard within a frame of the press+ Then a fired event reaches the speaker within the mixer's head (two 256-sample blocks and 5 ms: 15.7 ms at+ 48 kHz) of the call, measured on the mixer's own clock (the late-event count stays 0 over 200 fires)++ Scenario: HW0c. Nothing runs while nothing sounds+ Then the page's mixer opens the device on its first fire, and stops its stream after 10 s with nothing fired+ (the stage's rest, lightspeed R6); the next fire starts it again++ Scenario: HW0d. fire() in raea/tone+ Then `fire(play)` runs `play(time)` the way <Sfx> runs a game's one-shot: its triggers become events, keyed so+ no two fires share one, sent with the graph (only when the graph changed since the last fire) to sound.fire+ And with no raea engine under the page (a browser) it returns without a sound, and says so once in the console++ Rule: HW1. The kit's voices, in raea/tone+ Scenario: HW1a. A voice for each kind of touch+ Then a key going down thocks and coming up clicks lighter, a primary key deeper; a latch catches going down and+ springs going up; a detent (a knob's step, a switch's position, a wheel's row) ticks; anything on a screen (a+ readout, a list row) blips; a popup opens with a soft pop; typing clicks, deeper for space and heavier for+ Enter and Backspace; an outcome chimes (done, warning, error)+ And each is written with raea/tone's instruments and effects on the `ui` bus, never an audio file+ And no two presses sound quite alike: each varies its pitch and level a little, by raea/tone's seeded variation++ Scenario: HW1b. Quiet by default+ Then the kit's loudest voice peaks at least 18 dB under full scale on the ui bus, under any music or voice a+ stage plays at the same time++ Rule: HW2. The kit, dark, drawn by raea's window+ Scenario: HW2a. The controls+ Then the kit has a key (a button), a latch (a key that stays down), a switch and a slide switch, a knob with+ detents, a fader, a segmented selector, a stepper with its readout, a readout (an LCD-like screen), and a lamp+ And each is drawn on the app's dark palette (its ground, its raised greys, its ink and its accent), as anodised+ panels, keycaps and screens; there is no light skin+ And each works by pointer and by keyboard (arrows step a knob, a fader, a selector; Space and Enter press a key),+ with a focus ring shown only for the keyboard+ And each plays its HW1 voice as it moves, and nothing when sound is off (HW4)++ Scenario: HW2b. Drawn the same in raea's window and in Chrome+ Then every control is drawn with what raea's window paints (no `<input type=range>`, whose thumb the window doesn't+ move; no SVG for anything a pointer presses; a drag followed by window pointer listeners), and a screenshot of+ the kit's sheet in a headless raea window matches Chrome's within the ui-parity bar++ Scenario: HW2c. <Hardware>+ Then the app sits in one <Hardware> root, which installs the kit's sounds and keyboard-only focus once and changes+ nothing else about how the app looks++ Rule: HW3. Where the kit is used+ Scenario: HW3a. Controllers+ Then a controller's fields are the kit's: a toggle is a switch, a choice a segmented selector (a dial past five+ options), a number a knob or a fader with its readout, and each change sounds as it is made++ Scenario: HW3b. Settings+ Then Settings' toggles and choices are the kit's switches and selectors++ Scenario: HW3c. The rest of the app, where a control is a control+ Then the Send keycap, the timeline's sliders and the player's transport use the kit's keys, faders and their+ voices; lists, menus and text stay the app's own++ Rule: HW4. Sound off+ Scenario: HW4a. Settings › General › Interface sounds+ Then one switch turns every interface sound off and on, at once, remembered on this Mac+ And it is on by default+ And it never silences a film, a sound or a game: only the interface++ Rule: HW5. Open+ Scenario: HW5a. Felt on a Mac's trackpad+ Then a knob's detent, a switch's catch and a fader's end are felt on a Force Touch trackpad (the system's haptic+ feedback, through a host call), as they are heard++ Scenario: HW5b. A browser hears them too+ Then the kit's voices are bounced by raea once into small files a browser plays, so the app's page in Chrome (the+ tutorials' stage on raea.io) clicks as raea's window doesdiff --git a/engine/page/host/Cargo.toml b/engine/page/host/Cargo.tomlindex bb08d1e7..89648cd5 100644--- a/engine/page/host/Cargo.toml+++ b/engine/page/host/Cargo.toml@@ -46,6 +46,8 @@ image = { version = "0.25", default-features = false, features = ["png"] }serde_json = "1"# the live stage: <img data-raea-stage> (raea-page-stage)raea-page-stage = { path = "../stage" }+# a page's interaction sounds: sound.fire (raea-page-sound, docs/hardware.feature HW0)+raea-page-sound = { path = "../sound" }# Rune layers in the page: what's under a data-raea-renderer="rune" element drawn by Rune on this device (T6c)raea-rune-slots = { path = "../../rune/slots" }# the window build turns bevy_winit on for every Bevy app in the process; the stage's engine is told to leave it out (main.rs)diff --git a/engine/page/host/src/main.rs b/engine/page/host/src/main.rsindex 4aee8951..90911a09 100644--- a/engine/page/host/src/main.rs+++ b/engine/page/host/src/main.rs@@ -115,6 +115,8 @@ fn main() {app.add_plugins(HostPlugin { size: a.size, double_click: Duration::from_millis(500), picking }).add_plugins(brp::plugins(brp::port(), |r| r)).add_plugins(stage::StagePlugin)+ // a page's interaction sounds, fired on a mixer of its own (docs/hardware.feature HW0)+ .add_plugins(raea_page_sound::PageSoundPlugin)// the clipboard, links, notifications, the dock badge, raea:// links and the chrome (raea-page-window).add_plugins(raea_page_window::DesktopPlugin { chrome: a.chrome, live: a.window });raea_page_host::page_plugins(&mut app, picking);diff --git a/engine/page/sound/Cargo.toml b/engine/page/sound/Cargo.tomlnew file mode 100644index 00000000..1b31e883--- /dev/null+++ b/engine/page/sound/Cargo.toml@@ -0,0 +1,13 @@+[package]+name = "raea-page-sound"+version = "0.1.0"+edition = "2024"+license = "FSL-1.1-ALv2"+publish = false+description = "A page's interaction sounds: the sound.fire host call, raea/tone events played now on a mixer of the page's own (docs/hardware.feature HW0)"++[dependencies]+bevy = { version = "=0.20.0", default-features = false, features = ["std"] }+raea-runtime-js = { path = "../../../runtime/js" }+raea-sys-mix = { path = "../../../systems/mix" }+serde_json = "1"diff --git a/engine/page/sound/src/lib.rs b/engine/page/sound/src/lib.rsnew file mode 100644index 00000000..8dd8abd9--- /dev/null+++ b/engine/page/sound/src/lib.rs@@ -0,0 +1,111 @@+//! A page's interaction sounds (docs/hardware.feature HW0): raea/tone events a page fires, played now on a mixer of+//! the page's own, the same mixer core (Firewheel) a render bounces and the stage plays. raea's window has no Web Audio+//! graph (sdk/ui/src/platform/audio.ts), so this is how a page in it is heard:+//!+//! sound.fire {graph?: string, evs: [..]} -> null+//! sound.report {} -> {fired, late}+//!+//! `graph` is raea/tone's graph JSON (as `<audio data-tone-graph>` holds it), sent when it changed; `evs` are its events,+//! each at its own time ("t", seconds) after now. The call answers at once; the mixer runs on a thread of its own,+//! opens the device on the first fire and stops its stream after IDLE with nothing fired (the stage's rest).++use std::sync::mpsc::{Receiver, RecvTimeoutError, Sender, channel};+use std::sync::{Mutex, OnceLock};+use std::time::{Duration, Instant};++use bevy::prelude::*;+use raea_runtime_js::calls::HostCalls;+use serde_json::{Value, json};++/// How long the mixer runs with nothing fired before its stream stops.+const IDLE: Duration = Duration::from_secs(10);++enum Msg {+ Fire(Option<String>, Vec<Value>),+ Report(Sender<Value>),+}++/// The mixer's thread, started by the first call.+fn mixer() -> &'static Mutex<Sender<Msg>> {+ static TX: OnceLock<Mutex<Sender<Msg>>> = OnceLock::new();+ TX.get_or_init(|| {+ let (tx, rx) = channel();+ let _ = std::thread::Builder::new().name("raea page sound".into()).spawn(move || run(rx));+ Mutex::new(tx)+ })+}++fn run(rx: Receiver<Msg>) {+ let mut live: Option<raea_sys_mix::live::Live> = None;+ let mut failed = false;+ let (mut fired, mut last) = (0u64, Instant::now());+ loop {+ match rx.recv_timeout(Duration::from_millis(100)) {+ Ok(Msg::Fire(graph, evs)) => {+ if live.is_none() && !failed {+ match raea_sys_mix::live::Live::open() {+ Ok(l) => live = Some(l),+ Err(e) => {+ failed = true;+ eprintln!("raea page sound: no output device, the page's sounds stay silent ({e})");+ }+ }+ }+ if let Some(l) = live.as_mut() {+ l.fire(graph.as_deref(), &evs);+ fired += 1;+ last = Instant::now();+ }+ }+ Ok(Msg::Report(back)) => {+ let late = live.as_ref().map_or(0, |l| l.late_events());+ let _ = back.send(json!({ "fired": fired, "late": late }));+ }+ Err(RecvTimeoutError::Timeout) => {+ if let Some(l) = live.as_mut() {+ l.tend();+ if last.elapsed() > IDLE {+ l.rest();+ }+ }+ }+ Err(RecvTimeoutError::Disconnected) => return,+ }+ }+}++fn send(m: Msg) -> Result<(), String> {+ mixer().lock().map_err(|_| "the page's mixer stopped".to_string())?.send(m).map_err(|_| "the page's mixer stopped".to_string())+}++/// The calls, onto the page's HostCalls.+fn calls(mut calls: ResMut<HostCalls>) {+ calls+ .on("sound.fire", |_w, a, answer| {+ let graph = a.get("graph").and_then(Value::as_str).map(str::to_string);+ let evs = a.get("evs").and_then(Value::as_array).cloned().unwrap_or_default();+ match send(Msg::Fire(graph, evs)) {+ Ok(()) => answer.ok(Value::Null),+ Err(e) => answer.err(e),+ }+ })+ .on("sound.report", |_w, _a, answer| {+ let (tx, rx) = channel();+ if let Err(e) = send(Msg::Report(tx)) {+ return answer.err(e);+ }+ std::thread::spawn(move || match rx.recv_timeout(Duration::from_secs(2)) {+ Ok(v) => answer.ok(v),+ Err(_) => answer.err("the page's mixer didn't answer"),+ });+ });+}++/// The page's sound calls (HW0a).+pub struct PageSoundPlugin;++impl Plugin for PageSoundPlugin {+ fn build(&self, app: &mut App) {+ app.init_resource::<HostCalls>().add_systems(Startup, calls);+ }+}diff --git a/sdk/audio/src/tone.tsx b/sdk/audio/src/tone.tsxindex 311c720e..616995e2 100644--- a/sdk/audio/src/tone.tsx+++ b/sdk/audio/src/tone.tsx@@ -15,4 +15,5 @@import { fish, lyria, sao } from "@raea/asset/assets";export { getContext, context, setContext, start, loaded, now, immediate, version, mtof, ftom, dbToGain, gainToDb, intervalToFrequencyRatio, Frequency, Midi, Time, TransportTime, Ticks, Param, Signal, ToneAudioNode, getDestination, Destination, Master, Instrument, Synth, MonoSynth, FMSynth, AMSynth, DuoSynth, MembraneSynth, NoiseSynth, MetalSynth, PluckSynth, PolySynth, Sampler, Player, GrainPlayer, Players, Oscillator, OmniOscillator, FatOscillator, PulseOscillator, Noise, Effect, Reverb, Freeverb, JCReverb, FeedbackDelay, PingPongDelay, Filter, AutoFilter, Compressor, Limiter, EQ3, Distortion, Chorus, BitCrusher, Tremolo, Vibrato, Phaser, AutoPanner, Gain, Volume, Panner, Channel, PanVol, Solo, Meter, FFT, Waveform, Analyser, LFO, Convolver, PitchShift, Offline, bus, buses, tokensynth, getTransport, Transport, Draw, Loop, Part, Sequence, Pattern, ToneOut, Sfx, vary, snapshot, reset } from "./tone/all";+export { fire } from "./tone/fire";export { sao, lyria, fish };diff --git a/sdk/audio/src/tone/fire.ts b/sdk/audio/src/tone/fire.tsnew file mode 100644index 00000000..f7ca7024--- /dev/null+++ b/sdk/audio/src/tone/fire.ts@@ -0,0 +1,45 @@+// raea/tone in a page: a sound fired now (docs/hardware.feature HW0d), as <Sfx> is a game's one-shot on a frame.+import { type Ev, ctx } from "./all";++type Engine = { call: <T>(name: string, args?: unknown) => Promise<T> };++/** the graph the page's mixer has, as last sent */+let sent = "";+let fires = 0;+let said = false;++/**+ * raea: a page's one-shot, heard now. `play(time)` runs the way an <Sfx>'s does, its triggers become events, and the+ * page's mixer in raea's window plays them at once (the host call sound.fire, on raea's mixer core). Make the+ * instruments and effects once, at the top level of a module, as a composition does; `play` only triggers them.+ * const click = new Tone.NoiseSynth({ envelope: { attack: 0.001, decay: 0.03, sustain: 0 } }).connect(Tone.buses.ui);+ * button.onpointerdown = () => Tone.fire((t) => click.triggerAttackRelease("32n", t));+ * Returns false, with no sound, where no raea engine is under the page (a browser).+ */+export function fire(play: (time: number) => void): boolean {+ const engine = (globalThis as { __raea_engine?: Engine }).__raea_engine;+ const evs: Ev[] = [];+ const prev = [ctx.sink, ctx.sinkKey, ctx.seq, ctx.now] as const;+ ctx.sink = evs;+ // each fire's own keys: the mixer hears a key once+ ctx.sinkKey = `fire${++fires}`;+ ctx.seq = 0;+ ctx.now = 0;+ try {+ play(0);+ } finally {+ [ctx.sink, ctx.sinkKey, ctx.seq, ctx.now] = prev;+ }+ if (!engine) {+ if (!said) console.info("raea/tone fire: no raea engine under this page, so its sounds are silent");+ said = true;+ return false;+ }+ if (evs.length === 0) return true;+ const graph = ctx.graphJson();+ const args = graph === sent ? { evs } : { graph, evs };+ sent = graph;+ // a call that failed sends the graph again with the next+ engine.call("sound.fire", args).catch(() => void (sent = ""));+ return true;+}diff --git a/systems/mix/src/live.rs b/systems/mix/src/live.rsindex 05671d57..45e43d4b 100644--- a/systems/mix/src/live.rs+++ b/systems/mix/src/live.rs@@ -24,6 +24,9 @@ use crate::score::Score;use crate::score::ToneOut;use crate::{RATE, Sound, ToneCue};+/// a page's sounds, fired now off any timeline (docs/hardware.feature HW0)+mod fire;+/// past this a frame puts the timeline back in place; over DEADBAND its start moves by at most SLEW a frameconst DRIFT: f64 = 0.040;const DEADBAND: f64 = 0.002;diff --git a/systems/mix/src/live/fire.rs b/systems/mix/src/live/fire.rsnew file mode 100644index 00000000..68a9ee54--- /dev/null+++ b/systems/mix/src/live/fire.rs@@ -0,0 +1,53 @@+//! Sounds fired now, off any timeline (docs/hardware.feature HW0a): a page's interaction sounds, raea/tone's `fire()`.+//! A stage's mixer places a timeline and plays each frame's events on it (`Live::sync`); a page has no frames, so its+//! events play at the clock's now plus the head plus their own time. One mixer does one or the other: the page's+//! (raea-page-sound) only fires, the stage's only syncs.++use super::*;++impl Live {+ /// raea/tone's `evs` played now, each at the clock's now plus the head plus its own time ("t", seconds). `graph`+ /// (raea/tone's graph JSON, as `<audio data-tone-graph>` holds it) is built when it is new or changed; without one+ /// the graph built last plays them. The call returns at once: the voices run on the device's clock.+ pub fn fire(&mut self, graph: Option<&str>, evs: &[serde_json::Value]) {+ self.wake();+ self.settle_clock();+ let now = self.cx.audio_clock_corrected().samples.0 + self.head_base;+ if let Some(g) = graph+ && raea_sys_tone::tonegraph::hash(g) != self.built.hash+ {+ self.built.tear_down(&mut self.cx, self.voices);+ match raea_sys_tone::tonegraph::build(&mut self.cx, self.voices, self.master, g, now, &mut |f| crate::open_whole(f)) {+ Ok(b) => self.built = b,+ Err(e) => eprintln!("raea mixer: {e}"),+ }+ }+ let rate = self.rate;+ let score = self.score.get_or_insert_with(|| Score::new(60.0, rate));+ // a fire is heard once: its keys are never asked for again, so none is kept+ score.forget_notes();+ for (t, out) in score.tone(0, &self.built, evs) {+ let at = Some(EventInstant::AtClockSamples(InstantSamples(now + t.max(0))));+ match out {+ ToneOut::Voice(ev) => self.cx.schedule_event_for(self.voices, event(ev), at),+ ToneOut::Fx(node, fe) => {+ if let Some(id) = self.built.fx.get(&node) {+ self.cx.schedule_event_for(*id, event(fe), at);+ }+ }+ }+ }+ let _ = self.cx.update();+ }++ /// The graph's housekeeping between fires (what the audio thread hands back, the clock's correction): a firing+ /// mixer has no frames to do it on.+ pub fn tend(&mut self) {+ let _ = self.cx.update();+ }++ /// Late events so far: those that reached the audio thread after their sample (HW0b's count).+ pub fn late_events(&self) -> u64 {+ self.stats.late.load(Ordering::Relaxed) as u64+ }+}diff --git a/systems/mix/src/score.rs b/systems/mix/src/score.rsindex 2e2dc944..545af3e6 100644--- a/systems/mix/src/score.rs+++ b/systems/mix/src/score.rs@@ -151,6 +151,11 @@ impl Score {out}+ /// The notes heard so far forgotten: a fired sound's keys are never asked for again (Live::fire).+ pub fn forget_notes(&mut self) {+ self.heard_notes.clear();+ }+/// Every voice stops (fading out) at frame `f`: the end of a render, a pause, a seek.pub fn stop_all(&mut self, f: i64) -> Vec<(i64, Ev)> {let t = self.t(f);