6 Commits
Author SHA1 Message Date
Bendik Aagaard Lynghaug b53fdd5a6d chore: Release galdr version 0.2.4
Release / update-aur (push) Successful in 14s
Release / build (x86_64, ubuntu-latest, /sccache, x86_64-unknown-linux-gnu) (push) Successful in 14m57s
Release / build (aarch64, aarch64, /var/lib/gitea-runner/sccache, aarch64-unknown-linux-gnu) (push) Successful in 1m24s
2026-10-07 22:37:26 +02:00
Bendik Aagaard LynghaugandClaude Fable 5.1 f9f06568bf audio: render only the frames PipeWire requests per cycle
The process callback filled the whole mapped buffer every cycle. PipeWire
sizes that buffer by clock.quantum-limit (8192 frames by default) while the
graph drives galdr at the 256-frame quantum we ask for, so each cycle did
~32x the work and everything past the quantum was dropped: choppy output,
constant deadline misses in pw-top, and envelopes that sounded 32x faster
than their settings. Use Buffer::requested (pipewire feature v0_3_49),
clamped to the buffer, with the --latency value as fallback.

tui: typing a glyph no longer advances the cursor to the right.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-07 22:37:17 +02:00
Bendik Aagaard LynghaugandClaude Opus 4.8 392ceceeff ci: no sccache install on the bare aarch64 (klokka) runner; builtin:checkout
Gate the sccache install to the ephemeral x86_64 container; on the bare klokka
runner check-and-fail (the tarball was x86_64-only, so it was a host mutation
and a wrong-arch binary). Switch checkout to v4 builtin:checkout.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-28 12:39:09 +02:00
Bendik Aagaard LynghaugandClaude Opus 4.8 3bee9426f8 CI: run cargo test in the build job (gates releases, like orca-rs)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GLUwWE2KmFPzhKaf67tWbx
2026-09-13 16:56:36 +02:00
Bendik Aagaard Lynghaug 9bc44a08d5 chore: Release galdr version 0.2.3
Release / build (x86_64, ubuntu-latest, /sccache, x86_64-unknown-linux-gnu) (push) Successful in 1m31s
Release / update-aur (push) Successful in 21s
Release / build (aarch64, aarch64, /var/lib/gitea-runner/sccache, aarch64-unknown-linux-gnu) (push) Successful in 1m12s
2026-09-13 16:56:05 +02:00
Bendik Aagaard LynghaugandClaude Opus 4.8 3b4782565b Tests: 22 covering grid/compile/eval/engine (was 0; orca-rs has 11)
grid: ruler_snap, resize clamps, bounds, fixed-stride preservation.
dsp:  op mapping, input/param/CC wiring, env detection, sine bounds,
      exact saw/mix samples, output summing, note gating, envelope
      rise+release, cutoff curve.
engine: A4->440, oldest-voice steal, note reaping, CC registers, limiter.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GLUwWE2KmFPzhKaf67tWbx
2026-09-13 16:56:03 +02:00
9 changed files with 273 additions and 12 deletions
+12 -4
View File
@@ -25,7 +25,7 @@ jobs:
runs-on: ${{ matrix.runs-on }} runs-on: ${{ matrix.runs-on }}
steps: steps:
- uses: actions/checkout@v4 - uses: builtin:checkout
- name: Install Rust stable - name: Install Rust stable
uses: dtolnay/rust-toolchain@stable uses: dtolnay/rust-toolchain@stable
@@ -40,11 +40,16 @@ jobs:
echo "RUSTC_WRAPPER=sccache" >> "$GITHUB_ENV" echo "RUSTC_WRAPPER=sccache" >> "$GITHUB_ENV"
echo "SCCACHE_DIR=${{ matrix.sccache_dir }}" >> "$GITHUB_ENV" echo "SCCACHE_DIR=${{ matrix.sccache_dir }}" >> "$GITHUB_ENV"
mkdir -p "${{ matrix.sccache_dir }}" mkdir -p "${{ matrix.sccache_dir }}"
if ! command -v sccache >/dev/null 2>&1; then if command -v sccache >/dev/null 2>&1; then sccache --version; exit 0; fi
# Bare runners (aarch64 = klokka host) are pre-provisioned; CI must not
# install onto them (and this tarball is x86_64-only). Only the
# ephemeral x86_64 container installs; a bare host missing it fails loud.
if [ "${{ matrix.arch }}" != x86_64 ]; then
echo "::error::sccache missing on the bare ${{ matrix.arch }} runner — provision klokka; CI must not install on bare hosts"; exit 1
fi
V=0.8.2 V=0.8.2
curl -sSL "https://github.com/mozilla/sccache/releases/download/v${V}/sccache-v${V}-x86_64-unknown-linux-musl.tar.gz" | tar -xz curl -sSL "https://github.com/mozilla/sccache/releases/download/v${V}/sccache-v${V}-x86_64-unknown-linux-musl.tar.gz" | tar -xz
sudo install -m0755 "sccache-v${V}-x86_64-unknown-linux-musl/sccache" /usr/local/bin/sccache sudo install -m0755 "sccache-v${V}-x86_64-unknown-linux-musl/sccache" /usr/local/bin/sccache
fi
sccache --version sccache --version
- name: Ensure build deps (libpipewire for output, alsa for MIDI, clang for bindgen) - name: Ensure build deps (libpipewire for output, alsa for MIDI, clang for bindgen)
@@ -67,6 +72,9 @@ jobs:
echo "bare runner already has libpipewire + alsa + clang" echo "bare runner already has libpipewire + alsa + clang"
fi fi
- name: Test
run: cargo test --release --locked --target ${{ matrix.target }}
- name: Build - name: Build
run: cargo build --release --locked --target ${{ matrix.target }} run: cargo build --release --locked --target ${{ matrix.target }}
@@ -120,7 +128,7 @@ jobs:
runs-on: aarch64 runs-on: aarch64
steps: steps:
- uses: actions/checkout@v4 - uses: builtin:checkout
- name: Compute checksums and update PKGBUILD - name: Compute checksums and update PKGBUILD
run: | run: |
Generated
+1 -1
View File
@@ -320,7 +320,7 @@ dependencies = [
[[package]] [[package]]
name = "galdr" name = "galdr"
version = "0.2.2" version = "0.2.4"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"arc-swap", "arc-swap",
+2 -2
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "galdr" name = "galdr"
version = "0.2.2" version = "0.2.4"
edition = "2021" edition = "2021"
description = "A terminal grid synthesizer: signal flows spatially through single-glyph unit generators, voiced by MIDI, rendered low-latency to PipeWire" description = "A terminal grid synthesizer: signal flows spatially through single-glyph unit generators, voiced by MIDI, rendered low-latency to PipeWire"
license = "MIT" license = "MIT"
@@ -11,7 +11,7 @@ codegen-units = 1
[dependencies] [dependencies]
anyhow = "1" anyhow = "1"
pipewire = "0.10" pipewire = { version = "0.10", features = ["v0_3_49"] } # Buffer::requested
midir = "0.10" midir = "0.10"
arc-swap = "1.7" arc-swap = "1.7"
rtrb = "0.3" rtrb = "0.3"
+1 -1
View File
@@ -1,6 +1,6 @@
# Maintainer: Bendik Aagaard Lynghaug <bendik.lynghaug@gmail.com> # Maintainer: Bendik Aagaard Lynghaug <bendik.lynghaug@gmail.com>
pkgname=galdr pkgname=galdr
pkgver=0.2.2 pkgver=0.2.4
pkgrel=1 pkgrel=1
pkgdesc="Terminal grid synthesizer: signal flows through single-glyph unit generators, MIDI in, low-latency PipeWire out" pkgdesc="Terminal grid synthesizer: signal flows through single-glyph unit generators, MIDI in, low-latency PipeWire out"
arch=('x86_64' 'aarch64') arch=('x86_64' 'aarch64')
+8 -1
View File
@@ -75,6 +75,7 @@ fn run(
.add_local_listener_with_user_data(()) .add_local_listener_with_user_data(())
.process(move |stream, _| { .process(move |stream, _| {
let Some(mut buffer) = stream.dequeue_buffer() else { return }; let Some(mut buffer) = stream.dequeue_buffer() else { return };
let requested = buffer.requested() as usize;
let datas = buffer.datas_mut(); let datas = buffer.datas_mut();
let Some(data) = datas.first_mut() else { return }; let Some(data) = datas.first_mut() else { return };
let stride = ch * 4; let stride = ch * 4;
@@ -85,9 +86,15 @@ fn run(
engine.apply(ev); engine.apply(ev);
} }
// Render only what the graph asked for this cycle. The mapped
// buffer is sized by clock.quantum-limit (8192 frames by default),
// so filling it whole would do ~32x the work of a 256-frame
// quantum and PipeWire would drop everything past the quantum:
// choppy output and envelopes that race through their stages.
let want = if requested > 0 { requested } else { latency as usize };
let mut n_frames = 0usize; let mut n_frames = 0usize;
if let Some(slice) = data.data() { if let Some(slice) = data.data() {
n_frames = slice.len() / stride; n_frames = want.min(slice.len() / stride);
for f in 0..n_frames { for f in 0..n_frames {
let smp = engine.render(&program); let smp = engine.render(&program);
let bytes = smp.to_le_bytes(); let bytes = smp.to_le_bytes();
+133
View File
@@ -302,3 +302,136 @@ pub fn eval_voice(v: &mut Voice, p: &Program, regs: &[f32], sr: f32) -> f32 {
v.env_level = env_max; v.env_level = env_max;
out out
} }
#[cfg(test)]
mod tests {
use super::*;
use crate::grid::Grid;
fn grid_from(src: &str) -> Grid {
let mut g = Grid::new();
for (r, line) in src.lines().enumerate() {
for (c, ch) in line.chars().enumerate() {
g.set(c, r, ch);
}
}
g
}
fn voice(freq: f32, gate: f32, vel: f32) -> Voice {
let mut v = Voice::new();
v.active = true;
v.freq = freq;
v.gate = gate;
v.vel = vel;
v
}
fn render(v: &mut Voice, p: &Program, n: usize) -> Vec<f32> {
let regs = [0.0f32; 128];
(0..n).map(|_| eval_voice(v, p, &regs, 48000.0)).collect()
}
#[test]
fn compile_ignores_non_operators() {
// digits and dots are params/empty, not nodes
let p = compile(&grid_from("O5.\n!.."));
assert_eq!(p.nodes.len(), 2); // O and !
}
#[test]
fn compile_wires_input_from_above() {
// O over ! -> the ! node's input is the O's slot
let p = compile(&grid_from("O\n!"));
let out_node = p.nodes.iter().find(|n| matches!(n.op, Op::Out)).unwrap();
assert!(out_node.input.is_some());
}
#[test]
fn compile_reads_left_param() {
// '5' left of L becomes a constant param
let p = compile(&grid_from("5L"));
let lp = p.nodes.iter().find(|n| matches!(n.op, Op::Low)).unwrap();
assert!(matches!(lp.left, Param::Const(x) if (x - 5.0).abs() < 1e-6));
}
#[test]
fn compile_lowercase_left_is_cc_reg() {
let p = compile(&grid_from("aG"));
let g = p.nodes.iter().find(|n| matches!(n.op, Op::Gain)).unwrap();
assert!(matches!(g.left, Param::Reg(0)));
}
#[test]
fn compile_detects_envelope() {
assert!(compile(&grid_from("O\nE\n!")).has_env);
assert!(!compile(&grid_from("O\n!")).has_env);
}
#[test]
fn empty_grid_is_silent() {
let p = compile(&grid_from("...\n..."));
let mut v = voice(440.0, 1.0, 1.0);
assert!(render(&mut v, &p, 64).iter().all(|&y| y == 0.0));
}
#[test]
fn sine_is_bounded_and_audible() {
let p = compile(&grid_from("O\n!"));
let mut v = voice(440.0, 1.0, 1.0);
let out = render(&mut v, &p, 2048);
assert!(out.iter().all(|&y| y.abs() <= 1.0 + 1e-6));
assert!(out.iter().cloned().fold(0.0, f32::max) > 0.5); // reaches amplitude
}
#[test]
fn saw_first_sample_is_minus_one() {
// phase starts at 0 -> saw = 2*0-1 = -1
let p = compile(&grid_from("A\n!"));
let mut v = voice(440.0, 1.0, 1.0);
assert!((render(&mut v, &p, 1)[0] - (-1.0)).abs() < 1e-6);
}
#[test]
fn outputs_sum_across_columns() {
// two saw->out columns: first sample -1 + -1 = -2
let p = compile(&grid_from("A.A\n!.!"));
let mut v = voice(440.0, 1.0, 1.0);
assert!((render(&mut v, &p, 1)[0] - (-2.0)).abs() < 1e-6);
}
#[test]
fn no_envelope_is_gated_by_note() {
let p = compile(&grid_from("A\n!"));
let mut open = voice(440.0, 1.0, 1.0);
let mut shut = voice(440.0, 0.0, 1.0);
assert!(render(&mut open, &p, 1)[0].abs() > 0.5);
assert_eq!(render(&mut shut, &p, 1)[0], 0.0); // gate 0 -> silent
}
#[test]
fn envelope_rises_then_releases() {
let p = compile(&grid_from("O\nE\n!"));
let mut v = voice(440.0, 1.0, 1.0);
render(&mut v, &p, 8000); // ~sustain reached
let peak = v.env_level;
assert!(peak > 0.9, "env should rise to sustain, got {peak}");
v.gate = 0.0;
render(&mut v, &p, 24000); // release (~0.5s >> 0.15s release)
assert!(v.env_level < 0.1, "env should decay after note off, got {}", v.env_level);
}
#[test]
fn mix_adds_left_cell() {
// (1,0)=A saw(-1); (1,1)=M reads above(empty=0) + left cell A(-1) = -1
let p = compile(&grid_from("A.\nAM\n.!"));
let mut v = voice(440.0, 1.0, 1.0);
assert!((render(&mut v, &p, 1)[0] - (-1.0)).abs() < 1e-6);
}
#[test]
fn cutoff_hz_is_monotonic() {
assert!(cutoff_hz(0.0) < cutoff_hz(5.0));
assert!(cutoff_hz(5.0) < cutoff_hz(9.0));
}
}
+72
View File
@@ -91,3 +91,75 @@ impl Engine {
(mix * 0.3).tanh() (mix * 0.3).tanh()
} }
} }
#[cfg(test)]
mod tests {
use super::*;
use crate::dsp::compile;
use crate::grid::Grid;
#[cfg(test)]
impl Engine {
fn first_freq(&self) -> Option<f32> {
self.voices.iter().find(|v| v.active).map(|v| v.freq)
}
fn reg(&self, i: usize) -> f32 {
self.regs[i]
}
}
fn grid_from(src: &str) -> Grid {
let mut g = Grid::new();
for (r, line) in src.lines().enumerate() {
for (c, ch) in line.chars().enumerate() {
g.set(c, r, ch);
}
}
g
}
#[test]
fn noteon_maps_a4_to_440() {
let mut e = Engine::new(4, 48000.0);
e.apply(Event::NoteOn { note: 69, vel: 100 });
assert!((e.first_freq().unwrap() - 440.0).abs() < 0.01);
assert_eq!(e.active_voices(), 1);
}
#[test]
fn noteoff_reaps_gated_voice() {
let p = compile(&grid_from("A\n!")); // no envelope -> gate reaps immediately
let mut e = Engine::new(4, 48000.0);
e.apply(Event::NoteOn { note: 60, vel: 100 });
e.render(&p);
assert_eq!(e.active_voices(), 1);
e.apply(Event::NoteOff { note: 60 });
e.render(&p);
assert_eq!(e.active_voices(), 0);
}
#[test]
fn monophonic_steals_the_oldest_voice() {
let mut e = Engine::new(1, 48000.0);
e.apply(Event::NoteOn { note: 60, vel: 100 });
e.apply(Event::NoteOn { note: 72, vel: 100 });
assert_eq!(e.active_voices(), 1);
assert!((e.first_freq().unwrap() - 440.0 * 2f32.powf((72.0 - 69.0) / 12.0)).abs() < 0.01);
}
#[test]
fn cc_writes_register() {
let mut e = Engine::new(2, 48000.0);
e.apply(Event::Cc { idx: 0, val: 127 });
assert!((e.reg(0) - 1.0).abs() < 1e-6);
}
#[test]
fn master_output_is_limited() {
// many stacked saws would exceed 1.0 without the limiter
let p = compile(&grid_from("A.A.A.A\n!.!.!.!"));
let mut e = Engine::new(4, 48000.0);
e.apply(Event::NoteOn { note: 60, vel: 127 });
assert!(e.render(&p).abs() <= 1.0);
}
}
+42
View File
@@ -53,3 +53,45 @@ pub fn ruler_snap(size: usize, delta_rulers: isize) -> usize {
let n = ((size as isize - 1) / RULER as isize + delta_rulers).max(0); let n = ((size as isize - 1) / RULER as isize + delta_rulers).max(0);
(RULER as isize * n + 1) as usize (RULER as isize * n + 1) as usize
} }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn ruler_snap_grows_and_shrinks() {
// ruler-aligned sizes are 1, 9, 17, ...
assert_eq!(ruler_snap(24, 1), 25);
assert_eq!(ruler_snap(24, -1), 17);
assert_eq!(ruler_snap(1, -1), 1); // cannot go below 1
}
#[test]
fn resize_clamps_to_bounds() {
let mut g = Grid::new();
g.resize(9999, 9999);
assert_eq!((g.h, g.w), (MAX_H, MAX_W));
g.resize(0, 0);
assert_eq!((g.h, g.w), (1, 1));
}
#[test]
fn get_out_of_bounds_is_empty() {
let g = Grid::new();
assert_eq!(g.get(MAX_W + 5, MAX_H + 5), '.');
assert_eq!(g.get(g.w, 0), '.'); // just past the right edge
}
#[test]
fn set_get_roundtrip_and_resize_preserves() {
let mut g = Grid::new();
g.set(3, 2, 'O');
assert_eq!(g.get(3, 2), 'O');
g.resize(4, 4); // shrink below the cell? (3,2) still inside 4x4
assert_eq!(g.get(3, 2), 'O');
g.resize(2, 2); // now (3,2) is out of bounds -> hidden
assert_eq!(g.get(3, 2), '.');
g.resize(MAX_H, MAX_W); // grow back -> content returns (fixed stride)
assert_eq!(g.get(3, 2), 'O');
}
}
-1
View File
@@ -169,7 +169,6 @@ pub fn run(
KeyCode::Char(c) => { KeyCode::Char(c) => {
grid.set(cx, cy, if c == ' ' { '.' } else { c }); grid.set(cx, cy, if c == ' ' { '.' } else { c });
edited = true; edited = true;
cx = (cx + 1).min(grid.w - 1);
} }
_ => {} _ => {}
} }