From 3f3077c24740ea86b5cecefb6c6ef0d4a0fabe80 Mon Sep 17 00:00:00 2001 From: Russell McClellan Date: Mon, 10 Feb 2025 23:54:56 -0500 Subject: [PATCH] make poly realtime-safe (#35) --- Cargo.lock | 7 +++++++ rust/poly/Cargo.toml | 1 + rust/poly/src/state.rs | 8 +++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1c32f86..3152412 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + [[package]] name = "assert_approx_eq" version = "1.1.0" @@ -232,6 +238,7 @@ dependencies = [ name = "conformal_poly" version = "0.0.0" dependencies = [ + "arrayvec", "conformal_component", ] diff --git a/rust/poly/Cargo.toml b/rust/poly/Cargo.toml index 68f38cd..b52e385 100644 --- a/rust/poly/Cargo.toml +++ b/rust/poly/Cargo.toml @@ -13,3 +13,4 @@ workspace = true [dependencies] conformal_component = { version = "0.0.0", path = "../component" } +arrayvec = "0.7.6" diff --git a/rust/poly/src/state.rs b/rust/poly/src/state.rs index 85b285a..36e5e17 100644 --- a/rust/poly/src/state.rs +++ b/rust/poly/src/state.rs @@ -52,11 +52,13 @@ pub struct Voice { expression: NoteExpressionState, } +const MAX_VOICES: usize = 32; + #[derive(Clone, Debug, PartialEq)] pub struct State { - voices: Vec, + voices: arrayvec::ArrayVec, - voices_compress_order_scratch: Vec<(usize, usize)>, + voices_compress_order_scratch: arrayvec::ArrayVec<(usize, usize), MAX_VOICES>, } struct EventStreamStep { @@ -172,7 +174,7 @@ impl State { expression: NoteExpressionState::default(), }) .collect(), - voices_compress_order_scratch: Vec::with_capacity(max_voices), + voices_compress_order_scratch: Default::default(), } }