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 - name: Prepare plugin artifacts
if: inputs.build-packages if: inputs.build-packages
shell: bash
run: | run: |
mkdir -p staging/clap staging/vst3 mkdir -p staging/clap staging/vst3
cp -R target/bundled/cagire-plugins.clap staging/clap/ cp -R target/bundled/cagire-plugins.clap staging/clap/

1
Cargo.lock generated
View File

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

View File

@@ -51,7 +51,7 @@ cagire-forth = { path = "crates/forth" }
cagire-markdown = { path = "crates/markdown" } cagire-markdown = { path = "crates/markdown" }
cagire-project = { path = "crates/project" } cagire-project = { path = "crates/project" }
cagire-ratatui = { path = "crates/ratatui" } 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" rusty_link = "0.4"
ratatui = "0.30" ratatui = "0.30"
crossterm = "0.29" crossterm = "0.29"

View File

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

View File

@@ -302,6 +302,7 @@ impl Forth {
&resolved_params, &resolved_params,
ctx.step_duration(), ctx.step_duration(),
delta_secs, delta_secs,
ctx.sr,
outputs, outputs,
); );
Ok(resolved_sound_val.map(|v| v.into_owned())) Ok(resolved_sound_val.map(|v| v.into_owned()))
@@ -1542,7 +1543,7 @@ impl Forth {
.unwrap_or(0); .unwrap_or(0);
let dev = let dev =
get_int("dev").map(|d| d.clamp(0, 3) as u8).unwrap_or(0); 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}") format!("/delta/{delta_secs}")
} else { } else {
String::new() String::new()
@@ -1741,6 +1742,7 @@ fn emit_output(
params: &[(&str, String)], params: &[(&str, String)],
step_duration: f64, step_duration: f64,
nudge_secs: f64, nudge_secs: f64,
sr: f64,
outputs: &mut Vec<String>, outputs: &mut Vec<String>,
) { ) {
use std::fmt::Write; 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('/') { if !out.ends_with('/') {
out.push('/'); 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 { if !has_dur {

View File

@@ -14,7 +14,7 @@ cagire = { path = "../..", default-features = false, features = ["block-renderer
cagire-forth = { path = "../../crates/forth" } cagire-forth = { path = "../../crates/forth" }
cagire-project = { path = "../../crates/project" } cagire-project = { path = "../../crates/project" }
cagire-ratatui = { path = "../../crates/ratatui" } 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 = { git = "https://github.com/robbert-vdh/nih-plug", features = ["standalone"] }
nih_plug_egui = { git = "https://github.com/robbert-vdh/nih-plug" } nih_plug_egui = { git = "https://github.com/robbert-vdh/nih-plug" }
egui_ratatui = "2.1" egui_ratatui = "2.1"

View File

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

View File

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

View File

@@ -6,7 +6,7 @@ use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use super::link::LinkState; 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::sequencer::MidiCommand;
use super::timing::SyncTime; use super::timing::SyncTime;
@@ -55,10 +55,8 @@ pub fn dispatcher_loop(
link: Arc<LinkState>, link: Arc<LinkState>,
) { ) {
let has_rt = set_realtime_priority(); let has_rt = set_realtime_priority();
#[cfg(target_os = "linux")]
if !has_rt { 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); let mut queue: BinaryHeap<TimedMidiCommand> = BinaryHeap::with_capacity(256);

View File

@@ -148,6 +148,17 @@ pub fn set_realtime_priority() -> bool {
false 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. /// High-precision sleep using clock_nanosleep on Linux.
/// Uses monotonic clock for jitter-free sleeping. /// Uses monotonic clock for jitter-free sleeping.
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]

View File

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

View File

@@ -20,6 +20,7 @@ pub fn default_ctx() -> StepContext<'static> {
speed: 1.0, speed: 1.0,
fill: false, fill: false,
nudge_secs: 0.0, nudge_secs: 0.0,
sr: 48000.0,
cc_access: None, cc_access: None,
speed_key: "__speed_0_0__", speed_key: "__speed_0_0__",
mouse_x: 0.5, 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 outputs = expect_outputs(r#"0.5 at "kick" snd ."#, 1);
let deltas = get_deltas(&outputs); let deltas = get_deltas(&outputs);
let step_dur = 0.125; 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] #[test]
@@ -152,8 +153,9 @@ fn at_list_deltas() {
let outputs = expect_outputs(r#"0 0.5 at "kick" snd ."#, 2); let outputs = expect_outputs(r#"0 0.5 at "kick" snd ."#, 2);
let deltas = get_deltas(&outputs); let deltas = get_deltas(&outputs);
let step_dur = 0.125; 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[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] #[test]
@@ -161,9 +163,10 @@ fn at_three_deltas() {
let outputs = expect_outputs(r#"0 0.33 0.67 at "kick" snd ."#, 3); let outputs = expect_outputs(r#"0 0.33 0.67 at "kick" snd ."#, 3);
let deltas = get_deltas(&outputs); let deltas = get_deltas(&outputs);
let step_dur = 0.125; let step_dur = 0.125;
let sr: f64 = 48000.0;
assert!(approx_eq(deltas[0], 0.0), "expected delta 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!(approx_eq(deltas[1], (0.33 * step_dur * sr).round()), "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[2], (0.67 * step_dur * sr).round()), "expected delta at 0.67 of step");
} }
#[test] #[test]
@@ -234,10 +237,11 @@ fn arp_auto_subdivide() {
assert!(approx_eq(notes[3], 71.0)); assert!(approx_eq(notes[3], 71.0));
let deltas = get_deltas(&outputs); let deltas = get_deltas(&outputs);
let step_dur = 0.125; let step_dur = 0.125;
let sr: f64 = 48000.0;
assert!(approx_eq(deltas[0], 0.0)); assert!(approx_eq(deltas[0], 0.0));
assert!(approx_eq(deltas[1], 0.25 * step_dur)); assert!(approx_eq(deltas[1], (0.25 * step_dur * sr).round()));
assert!(approx_eq(deltas[2], 0.5 * step_dur)); assert!(approx_eq(deltas[2], (0.5 * step_dur * sr).round()));
assert!(approx_eq(deltas[3], 0.75 * step_dur)); assert!(approx_eq(deltas[3], (0.75 * step_dur * sr).round()));
} }
#[test] #[test]
@@ -250,10 +254,11 @@ fn arp_with_explicit_at() {
assert!(approx_eq(notes[3], 71.0)); assert!(approx_eq(notes[3], 71.0));
let deltas = get_deltas(&outputs); let deltas = get_deltas(&outputs);
let step_dur = 0.125; let step_dur = 0.125;
let sr: f64 = 48000.0;
assert!(approx_eq(deltas[0], 0.0)); assert!(approx_eq(deltas[0], 0.0));
assert!(approx_eq(deltas[1], 0.25 * step_dur)); assert!(approx_eq(deltas[1], (0.25 * step_dur * sr).round()));
assert!(approx_eq(deltas[2], 0.5 * step_dur)); assert!(approx_eq(deltas[2], (0.5 * step_dur * sr).round()));
assert!(approx_eq(deltas[3], 0.75 * step_dur)); assert!(approx_eq(deltas[3], (0.75 * step_dur * sr).round()));
} }
#[test] #[test]
@@ -273,10 +278,11 @@ fn arp_fewer_deltas_than_notes() {
assert!(approx_eq(notes[3], 71.0)); assert!(approx_eq(notes[3], 71.0));
let deltas = get_deltas(&outputs); let deltas = get_deltas(&outputs);
let step_dur = 0.125; let step_dur = 0.125;
let sr: f64 = 48000.0;
assert!(approx_eq(deltas[0], 0.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[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] #[test]