Fix: lots of various fixes
All checks were successful
Deploy Website / deploy (push) Has been skipped

This commit is contained in:
2026-03-06 20:48:50 +01:00
parent bc1396d61d
commit 09cfa82809
13 changed files with 57 additions and 28 deletions

View File

@@ -113,6 +113,7 @@ jobs:
- name: Prepare plugin artifacts
if: inputs.build-packages
shell: bash
run: |
mkdir -p staging/clap staging/vst3
cp -R target/bundled/cagire-plugins.clap staging/clap/

1
Cargo.lock generated
View File

@@ -1810,7 +1810,6 @@ dependencies = [
[[package]]
name = "doux"
version = "0.0.7"
source = "git+https://github.com/sova-org/doux#b2acd4d2737e0a981635266bf22926215453380e"
dependencies = [
"arc-swap",
"clap",

View File

@@ -51,7 +51,7 @@ cagire-forth = { path = "crates/forth" }
cagire-markdown = { path = "crates/markdown" }
cagire-project = { path = "crates/project" }
cagire-ratatui = { path = "crates/ratatui" }
doux = { git = "https://github.com/sova-org/doux", features = ["native", "soundfont"] }
doux = { path = "/Users/bubo/doux", features = ["native", "soundfont"] }
rusty_link = "0.4"
ratatui = "0.30"
crossterm = "0.29"

View File

@@ -63,6 +63,7 @@ pub struct StepContext<'a> {
pub speed: f64,
pub fill: bool,
pub nudge_secs: f64,
pub sr: f64,
pub cc_access: Option<&'a dyn CcAccess>,
pub speed_key: &'a str,
pub mouse_x: f64,

View File

@@ -302,6 +302,7 @@ impl Forth {
&resolved_params,
ctx.step_duration(),
delta_secs,
ctx.sr,
outputs,
);
Ok(resolved_sound_val.map(|v| v.into_owned()))
@@ -1542,7 +1543,7 @@ impl Forth {
.unwrap_or(0);
let dev =
get_int("dev").map(|d| d.clamp(0, 3) as u8).unwrap_or(0);
let delta_suffix = if delta_secs > 0.0 {
let delta_suffix = if delta_secs.abs() > 1e-9 {
format!("/delta/{delta_secs}")
} else {
String::new()
@@ -1741,6 +1742,7 @@ fn emit_output(
params: &[(&str, String)],
step_duration: f64,
nudge_secs: f64,
sr: f64,
outputs: &mut Vec<String>,
) {
use std::fmt::Write;
@@ -1772,11 +1774,12 @@ fn emit_output(
}
}
if nudge_secs > 0.0 {
if nudge_secs.abs() > 1e-9 {
if !out.ends_with('/') {
out.push('/');
}
let _ = write!(&mut out, "delta/{nudge_secs}");
let delta_ticks = (nudge_secs * sr).round() as i64;
let _ = write!(&mut out, "delta/{delta_ticks}");
}
if !has_dur {

View File

@@ -14,7 +14,7 @@ cagire = { path = "../..", default-features = false, features = ["block-renderer
cagire-forth = { path = "../../crates/forth" }
cagire-project = { path = "../../crates/project" }
cagire-ratatui = { path = "../../crates/ratatui" }
doux = { git = "https://github.com/sova-org/doux", features = ["native", "soundfont"] }
doux = { path = "/Users/bubo/doux", features = ["native", "soundfont"] }
nih_plug = { git = "https://github.com/robbert-vdh/nih-plug", features = ["standalone"] }
nih_plug_egui = { git = "https://github.com/robbert-vdh/nih-plug" }
egui_ratatui = "2.1"

View File

@@ -34,6 +34,7 @@ impl App {
speed,
fill: false,
nudge_secs: 0.0,
sr: 0.0,
cc_access: None,
speed_key: "",
mouse_x: 0.5,

View File

@@ -443,8 +443,11 @@ pub fn build_stream(
&stream_config,
move |data: &mut [f32], _| {
if !rt_set {
super::realtime::set_realtime_priority();
let ok = super::realtime::set_realtime_priority();
rt_set = true;
if !ok {
super::realtime::warn_no_rt("audio");
}
}
let buffer_samples = data.len() / channels;

View File

@@ -6,7 +6,7 @@ use std::sync::Arc;
use std::time::Duration;
use super::link::LinkState;
use super::realtime::{precise_sleep_us, set_realtime_priority};
use super::realtime::{precise_sleep_us, set_realtime_priority, warn_no_rt};
use super::sequencer::MidiCommand;
use super::timing::SyncTime;
@@ -55,10 +55,8 @@ pub fn dispatcher_loop(
link: Arc<LinkState>,
) {
let has_rt = set_realtime_priority();
#[cfg(target_os = "linux")]
if !has_rt {
eprintln!("[cagire] Warning: Could not set realtime priority for dispatcher thread.");
warn_no_rt("dispatcher");
}
let mut queue: BinaryHeap<TimedMidiCommand> = BinaryHeap::with_capacity(256);

View File

@@ -148,6 +148,17 @@ pub fn set_realtime_priority() -> bool {
false
}
#[cfg(target_os = "linux")]
pub fn warn_no_rt(thread_name: &str) {
eprintln!(
"[cagire] Warning: No realtime priority for {thread_name} thread. \
Add user to 'audio' group and configure rtprio limits."
);
}
#[cfg(not(target_os = "linux"))]
pub fn warn_no_rt(_thread_name: &str) {}
/// High-precision sleep using clock_nanosleep on Linux.
/// Uses monotonic clock for jitter-free sleeping.
#[cfg(target_os = "linux")]

View File

@@ -1007,6 +1007,7 @@ impl SequencerState {
speed: speed_mult,
fill,
nudge_secs,
sr,
cc_access: self.cc_access.as_deref(),
speed_key,
mouse_x,
@@ -1128,6 +1129,7 @@ impl SequencerState {
speed: speed_mult,
fill,
nudge_secs,
sr,
cc_access: self.cc_access.as_deref(),
speed_key: "",
mouse_x,
@@ -1266,13 +1268,16 @@ fn sequencer_loop(
) {
use std::sync::atomic::Ordering;
set_realtime_priority();
let has_rt = set_realtime_priority();
if !has_rt {
super::realtime::warn_no_rt("sequencer");
}
let rng: Rng = Arc::new(Mutex::new(StdRng::seed_from_u64(0)));
let mut seq_state = SequencerState::new(variables, dict, rng, cc_access);
// Lookahead window: ~20ms expressed in beats, recomputed each tick
const LOOKAHEAD_SECS: f64 = 0.02;
// Lookahead window: 20ms normally, 40ms on Linux without RT to compensate for jitter
let lookahead_secs: f64 = if cfg!(target_os = "linux") && !has_rt { 0.04 } else { 0.02 };
// Wake cadence: how long to sleep between scheduling passes
const WAKE_INTERVAL: std::time::Duration = std::time::Duration::from_millis(3);
@@ -1302,7 +1307,7 @@ fn sequencer_loop(
let tempo = state.tempo();
let lookahead_beats = if tempo > 0.0 {
LOOKAHEAD_SECS * tempo / 60.0
lookahead_secs * tempo / 60.0
} else {
0.0
};

View File

@@ -20,6 +20,7 @@ pub fn default_ctx() -> StepContext<'static> {
speed: 1.0,
fill: false,
nudge_secs: 0.0,
sr: 48000.0,
cc_access: None,
speed_key: "__speed_0_0__",
mouse_x: 0.5,

View File

@@ -144,7 +144,8 @@ fn at_single_delta() {
let outputs = expect_outputs(r#"0.5 at "kick" snd ."#, 1);
let deltas = get_deltas(&outputs);
let step_dur = 0.125;
assert!(approx_eq(deltas[0], 0.5 * step_dur), "expected delta at 0.5 of step, got {}", deltas[0]);
let sr: f64 = 48000.0;
assert!(approx_eq(deltas[0], (0.5 * step_dur * sr).round()), "expected delta at 0.5 of step, got {}", deltas[0]);
}
#[test]
@@ -152,8 +153,9 @@ fn at_list_deltas() {
let outputs = expect_outputs(r#"0 0.5 at "kick" snd ."#, 2);
let deltas = get_deltas(&outputs);
let step_dur = 0.125;
let sr: f64 = 48000.0;
assert!(approx_eq(deltas[0], 0.0), "expected delta 0, got {}", deltas[0]);
assert!(approx_eq(deltas[1], 0.5 * step_dur), "expected delta at 0.5 of step, got {}", deltas[1]);
assert!(approx_eq(deltas[1], (0.5 * step_dur * sr).round()), "expected delta at 0.5 of step, got {}", deltas[1]);
}
#[test]
@@ -161,9 +163,10 @@ fn at_three_deltas() {
let outputs = expect_outputs(r#"0 0.33 0.67 at "kick" snd ."#, 3);
let deltas = get_deltas(&outputs);
let step_dur = 0.125;
let sr: f64 = 48000.0;
assert!(approx_eq(deltas[0], 0.0), "expected delta 0");
assert!((deltas[1] - 0.33 * step_dur).abs() < 0.001, "expected delta at 0.33 of step");
assert!((deltas[2] - 0.67 * step_dur).abs() < 0.001, "expected delta at 0.67 of step");
assert!(approx_eq(deltas[1], (0.33 * step_dur * sr).round()), "expected delta at 0.33 of step");
assert!(approx_eq(deltas[2], (0.67 * step_dur * sr).round()), "expected delta at 0.67 of step");
}
#[test]
@@ -234,10 +237,11 @@ fn arp_auto_subdivide() {
assert!(approx_eq(notes[3], 71.0));
let deltas = get_deltas(&outputs);
let step_dur = 0.125;
let sr: f64 = 48000.0;
assert!(approx_eq(deltas[0], 0.0));
assert!(approx_eq(deltas[1], 0.25 * step_dur));
assert!(approx_eq(deltas[2], 0.5 * step_dur));
assert!(approx_eq(deltas[3], 0.75 * step_dur));
assert!(approx_eq(deltas[1], (0.25 * step_dur * sr).round()));
assert!(approx_eq(deltas[2], (0.5 * step_dur * sr).round()));
assert!(approx_eq(deltas[3], (0.75 * step_dur * sr).round()));
}
#[test]
@@ -250,10 +254,11 @@ fn arp_with_explicit_at() {
assert!(approx_eq(notes[3], 71.0));
let deltas = get_deltas(&outputs);
let step_dur = 0.125;
let sr: f64 = 48000.0;
assert!(approx_eq(deltas[0], 0.0));
assert!(approx_eq(deltas[1], 0.25 * step_dur));
assert!(approx_eq(deltas[2], 0.5 * step_dur));
assert!(approx_eq(deltas[3], 0.75 * step_dur));
assert!(approx_eq(deltas[1], (0.25 * step_dur * sr).round()));
assert!(approx_eq(deltas[2], (0.5 * step_dur * sr).round()));
assert!(approx_eq(deltas[3], (0.75 * step_dur * sr).round()));
}
#[test]
@@ -273,10 +278,11 @@ fn arp_fewer_deltas_than_notes() {
assert!(approx_eq(notes[3], 71.0));
let deltas = get_deltas(&outputs);
let step_dur = 0.125;
let sr: f64 = 48000.0;
assert!(approx_eq(deltas[0], 0.0));
assert!(approx_eq(deltas[1], 0.5 * step_dur));
assert!(approx_eq(deltas[1], (0.5 * step_dur * sr).round()));
assert!(approx_eq(deltas[2], 0.0)); // wraps: 2 % 2 = 0
assert!(approx_eq(deltas[3], 0.5 * step_dur)); // wraps: 3 % 2 = 1
assert!(approx_eq(deltas[3], (0.5 * step_dur * sr).round())); // wraps: 3 % 2 = 1
}
#[test]