From 0f10840b04fecf032e9016e76ba280a392e8834b Mon Sep 17 00:00:00 2001 From: "google-labs-stitch[bot]" <315546542+google-labs-stitch[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 04:19:50 +0000 Subject: [PATCH 1/6] feat: add partial configuration patches and patch events - Define Copy and Default patch structs for ProcessorConfig and stages - Derive optional camelCase Wasm types and TypeScript declarations - Add Processor::patch_config and Tunelet.patchConfig methods - Add ControlEvent::Patch and track pitch bounds in event preflight - Export all ten patch types from src/lib.rs and src/index.ts - Document patch controls in README.md and check them in verify-pack --- README.md | 20 ++- scripts/verify-pack.mjs | 43 +++++- src/config.rs | 120 ++++++++++++++++- src/effects/alien.rs | 49 +++++++ src/effects/punch.rs | 87 ++++++++++++ src/effects/reverb.rs | 97 ++++++++++++++ src/effects/warm.rs | 48 +++++++ src/events.rs | 69 +++++++++- src/formant.rs | 89 +++++++++++++ src/harmony.rs | 178 +++++++++++++++++++++++++ src/index.ts | 12 ++ src/lib.rs | 25 ++-- src/pitch.rs | 110 ++++++++++++++-- src/processor.rs | 29 +++- src/resynthesis.rs | 283 +++++++++++++++++++++++++++++++++++++++- src/wasm.rs | 30 ++++- 16 files changed, 1245 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 83a8f47..736bf72 100644 --- a/README.md +++ b/README.md @@ -244,8 +244,8 @@ These rules apply to the offsets: - An offset must not be less than the offset before it. Events with equal offsets execute in slice order. An empty block accepts no -events. A stage event replaces all settings of that stage. To change one -field, start from `processor.config()`. +events. A stage event replaces all settings of that stage. To change selected +fields, use `ControlEvent::Patch`, or start from `processor.config()`. Harmony MIDI uses `ControlEvent::Midi`. MIDI for the correction keyboard uses `ControlEvent::CorrectionMidi`. For example, this event starts a harmony note @@ -418,7 +418,7 @@ page that opens the JavaScript. | Shared initialization | `loadTunelet(source?)` | | Mono PCM to planar stereo | `process(input, left, right, events?)` | | In-place mono downmix | `processMono(audio, events?)` | -| Configuration | `config()`, `setConfig(config)`, `defaultConfig()` | +| Configuration | `config()`, `setConfig(config)`, `patchConfig(patch)`, `defaultConfig()` | | Information about the preparation | `sampleRate`, `maxBlockFrames`, `latencyFrames` | | Feedback | `feedback()`, `takeFeedback()` | | Telemetry | `telemetry()`, `takeTelemetry()` | @@ -456,6 +456,13 @@ to 4 if it is absent. The conversion ignores extra object properties. The generated declarations contain the parameter documentation from the Rust types. +To change selected fields without a full configuration copy, give a +`ProcessorConfigPatch` object to `patchConfig(patch)`. All fields in +`ProcessorConfigPatch` and the stage patches are optional. Omitted fields keep +their active values on the processor. `patchConfig()` validates the supplied +fields and the pitch bounds before any state changes. Each successful call +cancels an active drain, also for an empty `{}` patch. + `resynthesis.randomSeed` and the `processedFrames` field of feedback and telemetry use `bigint`. Frame offsets, block lengths and latency use `number`. @@ -470,6 +477,13 @@ example, this event changes the final gain before the first frame: { offset: 0, event: { type: "outputGain", value: 0.5 } } ``` +To merge selected configuration fields before a frame, use +`ControlEvent::Patch` (`type: "patch"`): + +```ts +{ offset: 0, event: { type: "patch", value: { resynthesis: { dryMix: 0.2 } } } } +``` + A harmony Note On event has this form: ```ts diff --git a/scripts/verify-pack.mjs b/scripts/verify-pack.mjs index 921fa6f..3156bc0 100644 --- a/scripts/verify-pack.mjs +++ b/scripts/verify-pack.mjs @@ -171,10 +171,13 @@ function verifyRuntimeImport(consumerDir, packageName) { "const config = rootModule.defaultConfig();", "const processor = new rootModule.Tunelet(48000, 128, config);", "try {", + " processor.patchConfig({ outputGain: 0.9 });", + " assert.equal(Math.fround(processor.config().outputGain), Math.fround(0.9));", " const input = new Int16Array(128);", " const left = new Int16Array(128);", " const right = new Int16Array(128);", - " processor.process(input, left, right);", + ' processor.process(input, left, right, [{ offset: 0, event: { type: "patch", value: { resynthesis: { dryMix: 0.2 } } } }]);', + " assert.equal(Math.fround(processor.config().resynthesis.dryMix), Math.fround(0.2));", "} finally {", " processor.free();", "}", @@ -201,7 +204,18 @@ function verifyTypeDeclarations(consumerDir, packageName) { " initSync as rootInitSync,", " loadTunelet as namedLoadTunelet,", " Tunelet,", + " type AlienConfigPatch,", + " type ControlEvent,", + " type CorrectionConfigPatch,", + " type FormantConfigPatch,", + " type HarmonyConfigPatch,", + " type PitchConfigPatch,", " type ProcessorConfig,", + " type ProcessorConfigPatch,", + " type PunchConfigPatch,", + " type ResynthesisConfigPatch,", + " type ReverbConfigPatch,", + " type WarmConfigPatch,", `} from ${pkgLiteral};`, "import init, {", " initSync as wasmInitSync,", @@ -215,10 +229,35 @@ function verifyTypeDeclarations(consumerDir, packageName) { " const exportsFromWasm: InitOutput = await init(source);", " const config: ProcessorConfig = defaultConfig();", " const processor = new Tunelet(48000, 128, config);", + " const punchPatch: PunchConfigPatch = { enabled: true };", + " const warmPatch: WarmConfigPatch = { driveDb: 2 };", + " const pitchPatch: PitchConfigPatch = { minFrequencyHz: 80 };", + " const correctionPatch: CorrectionConfigPatch = { retuneMs: 15 };", + " const formantPatch: FormantConfigPatch = { width: 1.1 };", + " const harmonyPatch: HarmonyConfigPatch = { voices: 2 };", + " const resynthesisPatch: ResynthesisConfigPatch = {", + " pitch: pitchPatch,", + " correction: correctionPatch,", + " formant: formantPatch,", + " harmony: harmonyPatch,", + " dryMix: 0.2,", + " };", + " const alienPatch: AlienConfigPatch = { loopFrames: 1000 };", + " const reverbPatch: ReverbConfigPatch = { mix: 0.4 };", + " const patch: ProcessorConfigPatch = {", + " punch: punchPatch,", + " warm: warmPatch,", + " resynthesis: resynthesisPatch,", + " alien: alienPatch,", + " reverb: reverbPatch,", + " outputGain: 0.9,", + " };", + " const patchEvent: ControlEvent = { type: \"patch\", value: patch };", + " processor.patchConfig(patch);", " const input = new Int16Array(128);", " const left = new Int16Array(128);", " const right = new Int16Array(128);", - " processor.process(input, left, right);", + " processor.process(input, left, right, [{ offset: 0, event: patchEvent }]);", " processor.free();", " void rootInitSync;", " void wasmInitSync;", diff --git a/src/config.rs b/src/config.rs index 75bcd82..934f0a3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,12 +1,12 @@ //! Sample rates, block limits and the complete processor configuration. -use crate::effects::alien::AlienConfig; -use crate::effects::punch::PunchConfig; -use crate::effects::reverb::ReverbConfig; -use crate::effects::warm::WarmConfig; +use crate::effects::alien::{AlienConfig, AlienConfigPatch}; +use crate::effects::punch::{PunchConfig, PunchConfigPatch}; +use crate::effects::reverb::{ReverbConfig, ReverbConfigPatch}; +use crate::effects::warm::{WarmConfig, WarmConfigPatch}; use crate::error::{check_range, ConfigProblem}; use crate::Error; -use crate::ResynthesisConfig; +use crate::{ResynthesisConfig, ResynthesisConfigPatch}; use std::num::NonZeroUsize; /// The sample rate of the input and the output. @@ -205,6 +205,116 @@ impl ProcessorConfig { } } +/// Optional changes to [`ProcessorConfig`], in the order of the stages. +/// +/// Apply a patch with [`crate::Processor::patch_config`] or +/// [`crate::ControlEvent::Patch`]. Each `None` field keeps its active value on +/// the processor. Validation examines only the supplied stages and fields +/// before any state changes. +#[derive(Clone, Copy, Debug, Default, PartialEq)] +#[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + derive(serde::Serialize, serde::Deserialize, tsify::Tsify), + serde(default, rename_all = "camelCase"), + tsify(large_number_types_as_bigints) +)] +pub struct ProcessorConfigPatch { + /// Optional changes to [`PunchConfig`]. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub punch: Option, + /// Optional changes to [`WarmConfig`]. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub warm: Option, + /// Optional changes to [`ResynthesisConfig`]. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub resynthesis: Option, + /// Optional changes to [`AlienConfig`]. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub alien: Option, + /// Optional changes to [`ReverbConfig`]. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub reverb: Option, + /// The linear gain after all effects, 0..=64. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub output_gain: Option, +} + +impl ProcessorConfigPatch { + /// Checks all supplied stages and fields in signal order. + pub(crate) fn validate(self) -> Result<(), Error> { + if let Some(punch) = self.punch { + punch.validate()?; + } + if let Some(warm) = self.warm { + warm.validate()?; + } + if let Some(resynthesis) = self.resynthesis { + resynthesis.validate()?; + } + if let Some(alien) = self.alien { + alien.validate()?; + } + if let Some(reverb) = self.reverb { + reverb.validate()?; + } + if let Some(output_gain) = self.output_gain { + validate_output_gain(output_gain)?; + } + Ok(()) + } + + /// Validates all supplied stages and fields in signal order, then writes + /// them into `config`. + pub(crate) fn apply_to(self, config: &mut ProcessorConfig) -> Result<(), Error> { + let mut next = *config; + if let Some(punch) = self.punch { + punch.apply_to(&mut next.punch)?; + } + if let Some(warm) = self.warm { + warm.apply_to(&mut next.warm)?; + } + if let Some(resynthesis) = self.resynthesis { + resynthesis.apply_to(&mut next.resynthesis)?; + } + if let Some(alien) = self.alien { + alien.apply_to(&mut next.alien)?; + } + if let Some(reverb) = self.reverb { + reverb.apply_to(&mut next.reverb)?; + } + if let Some(output_gain) = self.output_gain { + validate_output_gain(output_gain)?; + next.output_gain = output_gain; + } + *config = next; + Ok(()) + } +} + /// Checks the output gain range. /// /// `ProcessorConfig` and `ControlEvent::OutputGain` use the same range. diff --git a/src/effects/alien.rs b/src/effects/alien.rs index 271cae5..a96b1a3 100644 --- a/src/effects/alien.rs +++ b/src/effects/alien.rs @@ -57,6 +57,55 @@ impl AlienConfig { } } +/// Optional changes to [`AlienConfig`]. +/// +/// Each `None` field keeps its active value on the processor. +#[derive(Clone, Copy, Debug, Default, PartialEq)] +#[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + derive(serde::Serialize, serde::Deserialize, tsify::Tsify), + serde(default, rename_all = "camelCase") +)] +pub struct AlienConfigPatch { + /// Selects reversed playback instead of the direct input (`true` or + /// `false`). + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub enabled: Option, + /// The loop length in frames, 1..=96000. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub loop_frames: Option, +} + +impl AlienConfigPatch { + /// Checks all supplied fields and does not change the processor state. + pub(crate) fn validate(self) -> Result<(), Error> { + if let Some(loop_frames) = self.loop_frames { + check_count("alien.loop_frames", i64::from(loop_frames), 1, 96_000)?; + } + Ok(()) + } + + /// Validates all supplied fields and writes them into `config`. + pub(crate) fn apply_to(self, config: &mut AlienConfig) -> Result<(), Error> { + self.validate()?; + if let Some(enabled) = self.enabled { + config.enabled = enabled; + } + if let Some(loop_frames) = self.loop_frames { + config.loop_frames = loop_frames; + } + Ok(()) + } +} + /// A stereo ring recorder with a reverse reader and an independent loop /// phase. #[derive(Debug)] diff --git a/src/effects/punch.rs b/src/effects/punch.rs index 867dc09..cb240c3 100644 --- a/src/effects/punch.rs +++ b/src/effects/punch.rs @@ -85,6 +85,93 @@ impl PunchConfig { } } +/// Optional changes to [`PunchConfig`]. +/// +/// Each `None` field keeps its active value on the processor. +#[derive(Clone, Copy, Debug, Default, PartialEq)] +#[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + derive(serde::Serialize, serde::Deserialize, tsify::Tsify), + serde(default, rename_all = "camelCase") +)] +pub struct PunchConfigPatch { + /// Enables this input stage (`true` or `false`). + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub enabled: Option, + /// The input gain in decibels, -96..=12. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub gain_db: Option, + /// The transient emphasis without a unit, 0..=1. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub impact: Option, + /// The output limit of the saturation in dBFS, -96..=0. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub ceiling_db: Option, + /// The attack half-life of the peak follower in milliseconds, 0.01..=5000. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub attack_ms: Option, +} + +impl PunchConfigPatch { + /// Checks all supplied fields and does not change the processor state. + pub(crate) fn validate(self) -> Result<(), Error> { + if let Some(gain_db) = self.gain_db { + check_range("punch.gain_db", gain_db, -96.0, 12.0)?; + } + if let Some(impact) = self.impact { + check_range("punch.impact", impact, 0.0, 1.0)?; + } + if let Some(ceiling_db) = self.ceiling_db { + check_range("punch.ceiling_db", ceiling_db, -96.0, 0.0)?; + } + if let Some(attack_ms) = self.attack_ms { + check_range("punch.attack_ms", attack_ms, 0.01, 5000.0)?; + } + Ok(()) + } + + /// Validates all supplied fields and writes them into `config`. + pub(crate) fn apply_to(self, config: &mut PunchConfig) -> Result<(), Error> { + self.validate()?; + if let Some(enabled) = self.enabled { + config.enabled = enabled; + } + if let Some(gain_db) = self.gain_db { + config.gain_db = gain_db; + } + if let Some(impact) = self.impact { + config.impact = impact; + } + if let Some(ceiling_db) = self.ceiling_db { + config.ceiling_db = ceiling_db; + } + if let Some(attack_ms) = self.attack_ms { + config.attack_ms = attack_ms; + } + Ok(()) + } +} + /// Two peak followers that control an arctangent saturator, with all buffers /// inline. #[derive(Debug)] diff --git a/src/effects/reverb.rs b/src/effects/reverb.rs index 3a7dfce..6650956 100644 --- a/src/effects/reverb.rs +++ b/src/effects/reverb.rs @@ -115,6 +115,103 @@ impl ReverbConfig { } } +/// Optional changes to [`ReverbConfig`]. +/// +/// Each `None` field keeps its active value on the processor. +#[derive(Clone, Copy, Debug, Default, PartialEq)] +#[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + derive(serde::Serialize, serde::Deserialize, tsify::Tsify), + serde(default, rename_all = "camelCase") +)] +pub struct ReverbConfigPatch { + /// Enables the selected network (`true` or `false`). + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub enabled: Option, + /// The topology of the delay network (`ReverbMode`). + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub mode: Option, + /// The wet fraction, 0..=1. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub mix: Option, + /// The diffusion control without a unit, 0..=1. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub diffusion: Option, + /// The feedback control without a unit, 0..=1. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub decay: Option, + /// The low-pass cutoff in hertz for networks with damped paths, 80..=20000. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub brightness_hz: Option, +} + +impl ReverbConfigPatch { + /// Checks all supplied fields and does not change the processor state. + pub(crate) fn validate(self) -> Result<(), Error> { + if let Some(mix) = self.mix { + check_range("reverb.mix", mix, 0.0, 1.0)?; + } + if let Some(diffusion) = self.diffusion { + check_range("reverb.diffusion", diffusion, 0.0, 1.0)?; + } + if let Some(decay) = self.decay { + check_range("reverb.decay", decay, 0.0, 1.0)?; + } + if let Some(brightness_hz) = self.brightness_hz { + check_range("reverb.brightness_hz", brightness_hz, 80.0, 20000.0)?; + } + Ok(()) + } + + /// Validates all supplied fields and writes them into `config`. + pub(crate) fn apply_to(self, config: &mut ReverbConfig) -> Result<(), Error> { + self.validate()?; + if let Some(enabled) = self.enabled { + config.enabled = enabled; + } + if let Some(mode) = self.mode { + config.mode = mode; + } + if let Some(mix) = self.mix { + config.mix = mix; + } + if let Some(diffusion) = self.diffusion { + config.diffusion = diffusion; + } + if let Some(decay) = self.decay { + config.decay = decay; + } + if let Some(brightness_hz) = self.brightness_hz { + config.brightness_hz = brightness_hz; + } + Ok(()) + } +} + /// The shared Q14 delay network with two low-pass damping filters that keep /// state. #[derive(Debug)] diff --git a/src/effects/warm.rs b/src/effects/warm.rs index 9721ced..512fe25 100644 --- a/src/effects/warm.rs +++ b/src/effects/warm.rs @@ -55,6 +55,54 @@ impl WarmConfig { } } +/// Optional changes to [`WarmConfig`]. +/// +/// Each `None` field keeps its active value on the processor. +#[derive(Clone, Copy, Debug, Default, PartialEq)] +#[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + derive(serde::Serialize, serde::Deserialize, tsify::Tsify), + serde(default, rename_all = "camelCase") +)] +pub struct WarmConfigPatch { + /// Enables the saturation stage (`true` or `false`). + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub enabled: Option, + /// The drive in decibels, 0..=6. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub drive_db: Option, +} + +impl WarmConfigPatch { + /// Checks all supplied fields and does not change the processor state. + pub(crate) fn validate(self) -> Result<(), Error> { + if let Some(drive_db) = self.drive_db { + check_range("warm.drive_db", drive_db, 0.0, 6.0)?; + } + Ok(()) + } + + /// Validates all supplied fields and writes them into `config`. + pub(crate) fn apply_to(self, config: &mut WarmConfig) -> Result<(), Error> { + self.validate()?; + if let Some(enabled) = self.enabled { + config.enabled = enabled; + } + if let Some(drive_db) = self.drive_db { + config.drive_db = drive_db; + } + Ok(()) + } +} + /// An adaptive asymmetric saturator with one persistent high-pass output /// filter. #[derive(Debug)] diff --git a/src/events.rs b/src/events.rs index e1c975c..5d08c0d 100644 --- a/src/events.rs +++ b/src/events.rs @@ -6,16 +6,16 @@ use crate::effects::punch::PunchConfig; use crate::effects::reverb::ReverbConfig; use crate::effects::warm::WarmConfig; use crate::midi::MidiEvent; -use crate::{Error, EventProblem, ProcessorConfig, ResynthesisConfig}; +use crate::{Error, EventProblem, ProcessorConfig, ProcessorConfigPatch, ResynthesisConfig}; /// A configuration or MIDI control that applies before a frame in the block. /// /// Give controls to a process call as [`TimedEvent`] values. The call borrows /// the slice only for that call. There is no heap allocation and no deferred -/// queue. A stage event replaces all settings of that stage. To change one -/// field, start from the current configuration of the processor. -/// Configuration changes have the same effects on state as -/// [`crate::Processor::set_config`]. +/// queue. A stage event replaces all settings of that stage. To change +/// selected fields, use [`Self::Patch`], or start from the current +/// configuration of the processor. Configuration changes have the same effects +/// on state as [`crate::Processor::set_config`]. #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), @@ -25,6 +25,8 @@ use crate::{Error, EventProblem, ProcessorConfig, ResynthesisConfig}; pub enum ControlEvent { /// This event replaces the full configuration. Configure(ProcessorConfig), + /// This event merges supplied fields into the active configuration. + Patch(ProcessorConfigPatch), /// This event replaces the resynthesis configuration. Resynthesis(ResynthesisConfig), /// This event replaces the Punch configuration. @@ -66,6 +68,10 @@ impl ControlEvent { /// Checks the configuration or MIDI ranges of the event, and does not /// apply the event. /// + /// For [`Self::Patch`], this method checks all supplied fields, and checks + /// the pitch frequency order if the patch gives both bounds. A process + /// call also checks a single pitch bound against the active configuration. + /// /// # Errors /// /// Returns [`Error::InvalidConfig`] for an invalid configuration or gain. @@ -75,6 +81,7 @@ impl ControlEvent { pub fn validate(self) -> Result<(), Error> { match self { Self::Configure(config) => config.validate(), + Self::Patch(patch) => patch.validate(), Self::Resynthesis(config) => config.validate(), Self::Punch(config) => config.validate(), Self::Warm(config) => config.validate(), @@ -140,7 +147,11 @@ impl<'a> ValidatedEvents<'a> { /// first invalid event. The offset bounds have priority over the order. /// The order has priority over the payload validation. The function gives /// no tokens unless the full slice passes. - pub(crate) fn new(events: &'a [TimedEvent], frames: usize) -> Result { + pub(crate) fn new( + events: &'a [TimedEvent], + frames: usize, + mut config: ProcessorConfig, + ) -> Result { let mut previous = 0; for (index, event) in events.iter().enumerate() { let problem = if event.offset >= frames { @@ -148,7 +159,7 @@ impl<'a> ValidatedEvents<'a> { } else if event.offset < previous { Some(EventProblem::OffsetDecreasing) } else { - match event.event.validate() { + match validate_in_sequence(event.event, &mut config) { Ok(()) => None, Err(Error::InvalidConfig { field, problem }) => { Some(EventProblem::Config { field, problem }) @@ -179,3 +190,47 @@ impl<'a> ValidatedEvents<'a> { Some(ValidatedEvent(event.event)) } } + +/// Validates one event and advances the stack configuration copy. +fn validate_in_sequence(event: ControlEvent, config: &mut ProcessorConfig) -> Result<(), Error> { + match event { + ControlEvent::Configure(value) => { + value.validate()?; + *config = value; + Ok(()) + } + ControlEvent::Patch(patch) => patch.apply_to(config), + ControlEvent::Resynthesis(value) => { + value.validate()?; + config.resynthesis = value; + Ok(()) + } + ControlEvent::Punch(value) => { + value.validate()?; + config.punch = value; + Ok(()) + } + ControlEvent::Warm(value) => { + value.validate()?; + config.warm = value; + Ok(()) + } + ControlEvent::Alien(value) => { + value.validate()?; + config.alien = value; + Ok(()) + } + ControlEvent::Reverb(value) => { + value.validate()?; + config.reverb = value; + Ok(()) + } + ControlEvent::OutputGain(gain) => { + validate_output_gain(gain)?; + config.output_gain = gain; + Ok(()) + } + ControlEvent::Midi(midi) | ControlEvent::CorrectionMidi(midi) => midi.validate(), + ControlEvent::Reset => Ok(()), + } +} diff --git a/src/formant.rs b/src/formant.rs index bf9ee5a..eeab4de 100644 --- a/src/formant.rs +++ b/src/formant.rs @@ -104,6 +104,95 @@ impl FormantConfig { } } +/// Optional changes to [`FormantConfig`]. +/// +/// Each `None` field keeps its active value on the processor. +#[derive(Clone, Copy, Debug, Default, PartialEq)] +#[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + derive(serde::Serialize, serde::Deserialize, tsify::Tsify), + serde(default, rename_all = "camelCase") +)] +pub struct FormantConfigPatch { + /// Enables formant analysis and synthesis (`true` or `false`). + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub enabled: Option, + /// The vocal-tract width factor, 0.5..=2. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub width: Option, + /// The vocal-tract length factor, 0.5..=2. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub stretch: Option, + /// The aspiration level, 0..=1, without a unit. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub aspiration_mix: Option, + /// The high-pass cutoff for aspiration in hertz, 500..=10000. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub aspiration_cutoff_hz: Option, +} + +impl FormantConfigPatch { + /// Checks all supplied fields and does not change the processor state. + pub(crate) fn validate(self) -> Result<(), Error> { + if let Some(width) = self.width { + check_range("resynthesis.formant.width", width, 0.5, 2.0)?; + } + if let Some(stretch) = self.stretch { + check_range("resynthesis.formant.stretch", stretch, 0.5, 2.0)?; + } + if let Some(aspiration_mix) = self.aspiration_mix { + let field = "resynthesis.formant.aspiration_mix"; + check_range(field, aspiration_mix, 0.0, 1.0)?; + } + if let Some(aspiration_cutoff_hz) = self.aspiration_cutoff_hz { + let field = "resynthesis.formant.aspiration_cutoff_hz"; + check_range(field, aspiration_cutoff_hz, 500.0, 10000.0)?; + } + Ok(()) + } + + /// Validates all supplied fields and writes them into `config`. + pub(crate) fn apply_to(self, config: &mut FormantConfig) -> Result<(), Error> { + self.validate()?; + if let Some(enabled) = self.enabled { + config.enabled = enabled; + } + if let Some(width) = self.width { + config.width = width; + } + if let Some(stretch) = self.stretch { + config.stretch = stretch; + } + if let Some(aspiration_mix) = self.aspiration_mix { + config.aspiration_mix = aspiration_mix; + } + if let Some(aspiration_cutoff_hz) = self.aspiration_cutoff_hz { + config.aspiration_cutoff_hz = aspiration_cutoff_hz; + } + Ok(()) + } +} + /// The number of frames of input history for analysis and synthesis. The /// value is equal to the resynthesis history length. pub(crate) const HISTORY_FRAMES: usize = 11568; diff --git a/src/harmony.rs b/src/harmony.rs index ce9fb1f..4549744 100644 --- a/src/harmony.rs +++ b/src/harmony.rs @@ -393,6 +393,184 @@ impl HarmonyConfig { } } +/// Optional changes to [`HarmonyConfig`]. +/// +/// Each `None` field keeps its active value on the processor. +#[derive(Clone, Copy, Debug, Default, PartialEq)] +#[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + derive(serde::Serialize, serde::Deserialize, tsify::Tsify), + serde(default, rename_all = "camelCase") +)] +pub struct HarmonyConfigPatch { + /// The pitch source (`HarmonySource`). + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub source: Option, + /// The pitch class of the tonic (`PitchClass`). + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub key: Option, + /// The scale for smart intervals and degree chords (`HarmonyScale`). + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub scale: Option, + /// Four fixed semitone offsets, each in -24..=24. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional, type = "[number, number, number, number]") + )] + pub chromatic_intervals: Option<[i8; HARMONY_VOICES]>, + /// Four offsets in scale steps, each in -14..=14. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional, type = "[number, number, number, number]") + )] + pub diatonic_intervals: Option<[i8; HARMONY_VOICES]>, + /// The named chord for [`HarmonySource::ChordByName`] (`ChordName`). + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub chord: Option, + /// The chord on a scale degree for [`HarmonySource::ChordByDegree`] + /// (`ChordDegree`). + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub degree: Option, + /// The inversion for named chords and degree chords (`Inversion`). + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub inversion: Option, + /// The chord register from low to high, 0..=100%. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub register_percent: Option, + /// The chord spread from close to open, 0..=100%. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub voicing_spread_percent: Option, + /// The half-life of the target period in milliseconds, 0..=10000. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub portamento_ms: Option, + /// The number of voices that sound in the interval sources, 0..=4. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub voices: Option, +} + +impl HarmonyConfigPatch { + /// Checks all supplied fields and does not change the processor state. + pub(crate) fn validate(self) -> Result<(), Error> { + if let Some(chromatic_intervals) = self.chromatic_intervals { + for interval in chromatic_intervals { + let field = "resynthesis.harmony.chromatic_intervals"; + check_count(field, i64::from(interval), -24, 24)?; + } + } + if let Some(diatonic_intervals) = self.diatonic_intervals { + for interval in diatonic_intervals { + let field = "resynthesis.harmony.diatonic_intervals"; + check_count(field, i64::from(interval), -14, 14)?; + } + } + if let Some(voices) = self.voices { + let field = "resynthesis.harmony.voices"; + check_count(field, i64::from(voices), 0, HARMONY_VOICES as i64)?; + } + if let Some(register_percent) = self.register_percent { + let field = "resynthesis.harmony.register_percent"; + check_range(field, register_percent, 0.0, 100.0)?; + } + if let Some(voicing_spread_percent) = self.voicing_spread_percent { + let field = "resynthesis.harmony.voicing_spread_percent"; + check_range(field, voicing_spread_percent, 0.0, 100.0)?; + } + if let Some(portamento_ms) = self.portamento_ms { + check_range( + "resynthesis.harmony.portamento_ms", + portamento_ms, + 0.0, + 10_000.0, + )?; + } + Ok(()) + } + + /// Validates all supplied fields and writes them into `config`. + pub(crate) fn apply_to(self, config: &mut HarmonyConfig) -> Result<(), Error> { + self.validate()?; + if let Some(source) = self.source { + config.source = source; + } + if let Some(key) = self.key { + config.key = key; + } + if let Some(scale) = self.scale { + config.scale = scale; + } + if let Some(chromatic_intervals) = self.chromatic_intervals { + config.chromatic_intervals = chromatic_intervals; + } + if let Some(diatonic_intervals) = self.diatonic_intervals { + config.diatonic_intervals = diatonic_intervals; + } + if let Some(chord) = self.chord { + config.chord = chord; + } + if let Some(degree) = self.degree { + config.degree = degree; + } + if let Some(inversion) = self.inversion { + config.inversion = inversion; + } + if let Some(register_percent) = self.register_percent { + config.register_percent = register_percent; + } + if let Some(voicing_spread_percent) = self.voicing_spread_percent { + config.voicing_spread_percent = voicing_spread_percent; + } + if let Some(portamento_ms) = self.portamento_ms { + config.portamento_ms = portamento_ms; + } + if let Some(voices) = self.voices { + config.voices = voices; + } + Ok(()) + } +} + /// The prepared controller of periods and gains, and the MIDI allocator, for /// four voices. /// diff --git a/src/index.ts b/src/index.ts index 8526d77..4571496 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,6 +11,18 @@ import init from "../pkg/tunelet.js"; import type { InitInput, InitOutput } from "../pkg/tunelet.js"; export * from "../pkg/tunelet.js"; +export type { + AlienConfigPatch, + CorrectionConfigPatch, + FormantConfigPatch, + HarmonyConfigPatch, + PitchConfigPatch, + ProcessorConfigPatch, + PunchConfigPatch, + ResynthesisConfigPatch, + ReverbConfigPatch, + WarmConfigPatch, +} from "../pkg/tunelet.js"; /** The shared initialization promise, which a failure clears. */ let initialization: Promise | undefined; diff --git a/src/lib.rs b/src/lib.rs index f17bc85..0c0ae46 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,7 +19,8 @@ //! that are not active. //! //! A configuration value is a copy. If you change it, the processor does not -//! change until [`Processor::set_config`] or a configuration event applies it. +//! change until [`Processor::set_config`], [`Processor::patch_config`] or a +//! configuration event applies it. //! You can change settings between blocks, or at a frame offset with a //! [`TimedEvent`]. To change the sample rate or the block limit, you //! must make a new processor. @@ -121,19 +122,23 @@ mod scale; #[cfg(all(feature = "wasm", target_arch = "wasm32"))] pub mod wasm; -pub use config::{PrepareConfig, ProcessorConfig, SampleRate}; -pub use effects::alien::AlienConfig; -pub use effects::punch::PunchConfig; -pub use effects::reverb::{ReverbConfig, ReverbMode}; -pub use effects::warm::WarmConfig; +pub use config::{PrepareConfig, ProcessorConfig, ProcessorConfigPatch, SampleRate}; +pub use effects::alien::{AlienConfig, AlienConfigPatch}; +pub use effects::punch::{PunchConfig, PunchConfigPatch}; +pub use effects::reverb::{ReverbConfig, ReverbConfigPatch, ReverbMode}; +pub use effects::warm::{WarmConfig, WarmConfigPatch}; pub use error::{ConfigProblem, Error, EventProblem}; pub use events::{ControlEvent, TimedEvent}; -pub use formant::FormantConfig; +pub use formant::{FormantConfig, FormantConfigPatch}; pub use harmony::{ - ChordDegree, ChordName, HarmonyConfig, HarmonyScale, HarmonySource, Inversion, HARMONY_VOICES, + ChordDegree, ChordName, HarmonyConfig, HarmonyConfigPatch, HarmonyScale, HarmonySource, + Inversion, HARMONY_VOICES, }; pub use midi::MidiEvent; -pub use pitch::PitchConfig; +pub use pitch::{PitchConfig, PitchConfigPatch}; pub use processor::{Feedback, Processor, Telemetry}; -pub use resynthesis::{CorrectionConfig, MultiVoiceMode, ResynthesisConfig}; +pub use resynthesis::{ + CorrectionConfig, CorrectionConfigPatch, MultiVoiceMode, ResynthesisConfig, + ResynthesisConfigPatch, +}; pub use scale::{CorrectionScale, NoteMask, PitchClass}; diff --git a/src/pitch.rs b/src/pitch.rs index 6b682ca..4fd8cb6 100644 --- a/src/pitch.rs +++ b/src/pitch.rs @@ -80,15 +80,109 @@ impl PitchConfig { /// `resynthesis.pitch.max_frequency_hz`. pub fn validate(self) -> Result<(), Error> { check_range("resynthesis.pitch.threshold", self.threshold, 0.002, 0.2)?; - let (min, max) = ( - "resynthesis.pitch.min_frequency_hz", - "resynthesis.pitch.max_frequency_hz", - ); - check_range(min, self.min_frequency_hz, 40.0, 2000.0)?; - check_range(max, self.max_frequency_hz, 40.0, 2000.0)?; - if self.min_frequency_hz >= self.max_frequency_hz { - return Err(Error::config(min, ConfigProblem::Unordered { other: max })); + check_range(MIN_FIELD, self.min_frequency_hz, 40.0, 2000.0)?; + check_range(MAX_FIELD, self.max_frequency_hz, 40.0, 2000.0)?; + check_frequency_order(self.min_frequency_hz, self.max_frequency_hz) + } +} + +/// The dotted field path of the lower pitch bound. +const MIN_FIELD: &str = "resynthesis.pitch.min_frequency_hz"; +/// The dotted field path of the upper pitch bound. +const MAX_FIELD: &str = "resynthesis.pitch.max_frequency_hz"; + +/// Checks that `min_frequency_hz` is strictly below `max_frequency_hz`. +fn check_frequency_order(min_frequency_hz: f32, max_frequency_hz: f32) -> Result<(), Error> { + if min_frequency_hz >= max_frequency_hz { + return Err(Error::config( + MIN_FIELD, + ConfigProblem::Unordered { other: MAX_FIELD }, + )); + } + Ok(()) +} + +/// Optional changes to [`PitchConfig`]. +/// +/// Each `None` field keeps its active value on the processor. After a merge, +/// `min_frequency_hz` must stay strictly below `max_frequency_hz`. +#[derive(Clone, Copy, Debug, Default, PartialEq)] +#[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + derive(serde::Serialize, serde::Deserialize, tsify::Tsify), + serde(default, rename_all = "camelCase") +)] +pub struct PitchConfigPatch { + /// The normalized cycle-difference threshold for acquisition, 0.002..=0.2. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub threshold: Option, + /// The lower bound of the feedback in hertz (inclusive), 40..=2000. + /// + /// It must stay strictly below `max_frequency_hz`. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub min_frequency_hz: Option, + /// The upper bound of the feedback in hertz (inclusive), 40..=2000. + /// + /// It must stay strictly above `min_frequency_hz`. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub max_frequency_hz: Option, +} + +impl PitchConfigPatch { + /// Checks all supplied fields, and checks their order if both bounds are + /// present. + pub(crate) fn validate(self) -> Result<(), Error> { + if let Some(threshold) = self.threshold { + check_range("resynthesis.pitch.threshold", threshold, 0.002, 0.2)?; + } + if let Some(min_frequency_hz) = self.min_frequency_hz { + check_range(MIN_FIELD, min_frequency_hz, 40.0, 2000.0)?; + } + if let Some(max_frequency_hz) = self.max_frequency_hz { + check_range(MAX_FIELD, max_frequency_hz, 40.0, 2000.0)?; + } + if let (Some(min_frequency_hz), Some(max_frequency_hz)) = + (self.min_frequency_hz, self.max_frequency_hz) + { + check_frequency_order(min_frequency_hz, max_frequency_hz)?; + } + Ok(()) + } + + /// Validates all supplied fields, checks the frequency order against + /// `config` and writes the fields into `config`. + pub(crate) fn apply_to(self, config: &mut PitchConfig) -> Result<(), Error> { + if let Some(threshold) = self.threshold { + check_range("resynthesis.pitch.threshold", threshold, 0.002, 0.2)?; + } + if let Some(min_frequency_hz) = self.min_frequency_hz { + check_range(MIN_FIELD, min_frequency_hz, 40.0, 2000.0)?; + } + if let Some(max_frequency_hz) = self.max_frequency_hz { + check_range(MAX_FIELD, max_frequency_hz, 40.0, 2000.0)?; + } + let min_frequency_hz = self.min_frequency_hz.unwrap_or(config.min_frequency_hz); + let max_frequency_hz = self.max_frequency_hz.unwrap_or(config.max_frequency_hz); + if self.min_frequency_hz.is_some() || self.max_frequency_hz.is_some() { + check_frequency_order(min_frequency_hz, max_frequency_hz)?; + } + if let Some(threshold) = self.threshold { + config.threshold = threshold; } + config.min_frequency_hz = min_frequency_hz; + config.max_frequency_hz = max_frequency_hz; Ok(()) } } diff --git a/src/processor.rs b/src/processor.rs index 83bccf6..670f184 100644 --- a/src/processor.rs +++ b/src/processor.rs @@ -8,7 +8,9 @@ use crate::events::{ValidatedEvent, ValidatedEvents}; use crate::numeric::rng::RandomStream; use crate::numeric::NumericContext; use crate::resynthesis::{self, Resynthesis}; -use crate::{ControlEvent, Error, PrepareConfig, ProcessorConfig, TimedEvent}; +use crate::{ + ControlEvent, Error, PrepareConfig, ProcessorConfig, ProcessorConfigPatch, TimedEvent, +}; /// A prepared vocal processor with state, mono input and stereo synthesis. /// @@ -477,6 +479,26 @@ impl Processor { Ok(()) } + /// Merges supplied fields onto the active configuration, validates touched + /// stages and applies the result. + /// + /// State retention, resets on a change of `stereo_output`, restarts on a + /// change of `random_seed` and drain cancellation are the same as for + /// [`set_config`](Self::set_config). An empty patch also cancels an active + /// drain. + /// + /// # Errors + /// + /// Returns [`Error::InvalidConfig`] if a supplied field or the merged + /// pitch frequency order is not valid. The method returns this error + /// before it changes any state or any active drain. + pub fn patch_config(&mut self, patch: ProcessorConfigPatch) -> Result<(), Error> { + let mut config = self.config; + patch.apply_to(&mut config)?; + self.apply_config(config); + Ok(()) + } + /// Applies a configuration that the public setter or the preflight checked. fn apply_config(&mut self, config: ProcessorConfig) { if self.config.punch != config.punch { @@ -558,7 +580,7 @@ impl Processor { events: &'a [TimedEvent], ) -> Result, Error> { self.check_block(frames)?; - ValidatedEvents::new(events, frames) + ValidatedEvents::new(events, frames, self.config) } /// Enforces the prepared block limit for each call. @@ -581,6 +603,9 @@ impl Processor { let mut config = self.config; match event.into_inner() { ControlEvent::Configure(value) => config = value, + ControlEvent::Patch(patch) => { + let _ = patch.apply_to(&mut config); + } ControlEvent::Resynthesis(value) => config.resynthesis = value, ControlEvent::Punch(value) => config.punch = value, ControlEvent::Warm(value) => config.warm = value, diff --git a/src/resynthesis.rs b/src/resynthesis.rs index 7f5eda5..5edb0e5 100644 --- a/src/resynthesis.rs +++ b/src/resynthesis.rs @@ -31,13 +31,13 @@ mod history; use crate::error::{check_count, check_range}; use crate::filter::{Biquad, Design}; -use crate::formant::{Formant, FormantConfig, ANALYSIS_FRAMES}; -use crate::harmony::{HarmonyConfig, HarmonyState, HARMONY_VOICES}; +use crate::formant::{Formant, FormantConfig, FormantConfigPatch, ANALYSIS_FRAMES}; +use crate::harmony::{HarmonyConfig, HarmonyConfigPatch, HarmonyState, HARMONY_VOICES}; use crate::midi::MidiEvent; use crate::numeric::fixed::{Q12, Q14, Q6, Q8}; use crate::numeric::{clamp_i32, ring, NumericContext, HISTORY}; use crate::pitch::tracker::PitchTracker; -use crate::pitch::{PitchConfig, PitchEstimate}; +use crate::pitch::{PitchConfig, PitchConfigPatch, PitchEstimate}; use crate::scale::{CorrectionTable, NoteMask}; use crate::{Error, SampleRate}; use history::prepare_history; @@ -139,6 +139,64 @@ impl CorrectionConfig { } } +/// Optional changes to [`CorrectionConfig`]. +/// +/// Each `None` field keeps its active value on the processor. +#[derive(Clone, Copy, Debug, Default, PartialEq)] +#[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + derive(serde::Serialize, serde::Deserialize, tsify::Tsify), + serde(default, rename_all = "camelCase") +)] +pub struct CorrectionConfigPatch { + /// Enables the selection of correction targets (`true` or `false`). + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub enabled: Option, + /// The configured target pitch classes (`NoteMask`). + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub notes: Option, + /// The half-life of the ratio in milliseconds, 0..=400. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub retune_ms: Option, +} + +impl CorrectionConfigPatch { + /// Checks all supplied fields and does not change the processor state. + pub(crate) fn validate(self) -> Result<(), Error> { + if let Some(retune_ms) = self.retune_ms { + check_range("resynthesis.correction.retune_ms", retune_ms, 0.0, 400.0)?; + } + Ok(()) + } + + /// Validates all supplied fields and writes them into `config`. + pub(crate) fn apply_to(self, config: &mut CorrectionConfig) -> Result<(), Error> { + self.validate()?; + if let Some(enabled) = self.enabled { + config.enabled = enabled; + } + if let Some(notes) = self.notes { + config.notes = notes; + } + if let Some(retune_ms) = self.retune_ms { + config.retune_ms = retune_ms; + } + Ok(()) + } +} + /// The controls for pitch correction, pitch shift, voice arrangement and /// formants. /// @@ -311,6 +369,225 @@ impl ResynthesisConfig { } } +/// Optional changes to [`ResynthesisConfig`]. +/// +/// Each `None` field keeps its active value on the processor. +#[derive(Clone, Copy, Debug, Default, PartialEq)] +#[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + derive(serde::Serialize, serde::Deserialize, tsify::Tsify), + serde(default, rename_all = "camelCase"), + tsify(large_number_types_as_bigints) +)] +pub struct ResynthesisConfigPatch { + /// Optional changes to [`PitchConfig`]. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub pitch: Option, + /// Optional changes to [`CorrectionConfig`]. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub correction: Option, + /// The pitch multiplier, 0.25..=4. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub pitch_ratio: Option, + /// Optional changes to [`FormantConfig`]. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub formant: Option, + /// The voice arrangement (`MultiVoiceMode`). + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub mode: Option, + /// The total number of choir voices, with the lead voice, 1..=16. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub choir_voices: Option, + /// The drift control for secondary voices, 10..=100, without a unit. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub choir_detune: Option, + /// The scale of the choir delay table, 20..=200, without a unit. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub choir_delay: Option, + /// The stereo width of the choir, 0..=100%. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub choir_spread_percent: Option, + /// Enables a stereo pan for each voice (`true` or `false`). + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub stereo_output: Option, + /// Optional changes to [`HarmonyConfig`]. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub harmony: Option, + /// The linear gain of the four harmony voices, 0..=1. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub harmony_gain: Option, + /// The modulation depth, 0..=24, without a unit. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub harmonic_modulation: Option, + /// The dry fraction at the resynthesis stage, 0..=1. + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub dry_mix: Option, + /// The seed for choir drift and aspiration (`0..=u64::MAX`). + #[cfg_attr( + all(feature = "wasm", target_arch = "wasm32"), + serde(skip_serializing_if = "Option::is_none"), + tsify(optional) + )] + pub random_seed: Option, +} + +impl ResynthesisConfigPatch { + /// Checks the supplied scalar fields of resynthesis. + fn validate_scalars(self) -> Result<(), Error> { + if let Some(pitch_ratio) = self.pitch_ratio { + check_range("resynthesis.pitch_ratio", pitch_ratio, 0.25, 4.0)?; + } + if let Some(choir_detune) = self.choir_detune { + check_range("resynthesis.choir_detune", choir_detune, 10.0, 100.0)?; + } + if let Some(choir_delay) = self.choir_delay { + check_range("resynthesis.choir_delay", choir_delay, 20.0, 200.0)?; + } + if let Some(choir_spread_percent) = self.choir_spread_percent { + let field = "resynthesis.choir_spread_percent"; + check_range(field, choir_spread_percent, 0.0, 100.0)?; + } + if let Some(harmony_gain) = self.harmony_gain { + check_range("resynthesis.harmony_gain", harmony_gain, 0.0, 1.0)?; + } + if let Some(harmonic_modulation) = self.harmonic_modulation { + let field = "resynthesis.harmonic_modulation"; + check_range(field, harmonic_modulation, 0.0, 24.0)?; + } + if let Some(dry_mix) = self.dry_mix { + check_range("resynthesis.dry_mix", dry_mix, 0.0, 1.0)?; + } + if let Some(choir_voices) = self.choir_voices { + check_count("resynthesis.choir_voices", i64::from(choir_voices), 1, 16)?; + } + Ok(()) + } + + /// Checks all supplied sub-stages and scalar fields. + pub(crate) fn validate(self) -> Result<(), Error> { + if let Some(pitch) = self.pitch { + pitch.validate()?; + } + if let Some(correction) = self.correction { + correction.validate()?; + } + if let Some(formant) = self.formant { + formant.validate()?; + } + if let Some(harmony) = self.harmony { + harmony.validate()?; + } + self.validate_scalars() + } + + /// Validates all supplied fields and writes them into `config`. + pub(crate) fn apply_to(self, config: &mut ResynthesisConfig) -> Result<(), Error> { + if let Some(pitch) = self.pitch { + pitch.apply_to(&mut config.pitch)?; + } + if let Some(correction) = self.correction { + correction.apply_to(&mut config.correction)?; + } + if let Some(formant) = self.formant { + formant.apply_to(&mut config.formant)?; + } + if let Some(harmony) = self.harmony { + harmony.apply_to(&mut config.harmony)?; + } + self.validate_scalars()?; + if let Some(pitch_ratio) = self.pitch_ratio { + config.pitch_ratio = pitch_ratio; + } + if let Some(mode) = self.mode { + config.mode = mode; + } + if let Some(choir_voices) = self.choir_voices { + config.choir_voices = choir_voices; + } + if let Some(choir_detune) = self.choir_detune { + config.choir_detune = choir_detune; + } + if let Some(choir_delay) = self.choir_delay { + config.choir_delay = choir_delay; + } + if let Some(choir_spread_percent) = self.choir_spread_percent { + config.choir_spread_percent = choir_spread_percent; + } + if let Some(stereo_output) = self.stereo_output { + config.stereo_output = stereo_output; + } + if let Some(harmony_gain) = self.harmony_gain { + config.harmony_gain = harmony_gain; + } + if let Some(harmonic_modulation) = self.harmonic_modulation { + config.harmonic_modulation = harmonic_modulation; + } + if let Some(dry_mix) = self.dry_mix { + config.dry_mix = dry_mix; + } + if let Some(random_seed) = self.random_seed { + config.random_seed = random_seed; + } + Ok(()) + } +} + /// The fixed choir delay offsets in frames, before the scale by /// `choir_delay / 200`. /// diff --git a/src/wasm.rs b/src/wasm.rs index 15262e2..aa8e1f6 100644 --- a/src/wasm.rs +++ b/src/wasm.rs @@ -18,8 +18,10 @@ //! //! - Field names use camelCase. //! - Enum values are strings. -//! - Each object must contain all required fields. +//! - Each object for `setConfig` must contain all required fields. //! - The optional harmony `voices` field defaults to 4. +//! - Patch objects in `ProcessorConfigPatch` can omit fields that do not +//! change. //! //! [`default_config`] gives a configuration to start from. Control events use //! `{ type, value }`, and the reset control has no `value`. MIDI messages use @@ -42,7 +44,8 @@ //! `free()` method. use crate::{ - Error, Feedback, PrepareConfig, Processor, ProcessorConfig, SampleRate, Telemetry, TimedEvent, + Error, Feedback, PrepareConfig, Processor, ProcessorConfig, ProcessorConfigPatch, SampleRate, + Telemetry, TimedEvent, }; use js_sys::{Float32Array, Int16Array}; use serde::{Deserialize, Serialize}; @@ -203,8 +206,8 @@ impl WasmProcessor { /// Returns a copy of the active configuration as a new JavaScript object. /// - /// A change to the object has no effect until `setConfig` or a timed event - /// applies it. + /// A change to the object has no effect until `setConfig`, `patchConfig` + /// or a timed event applies it. /// /// # Errors /// @@ -229,6 +232,25 @@ impl WasmProcessor { Ok(()) } + /// Decodes and validates a partial configuration, then merges its supplied + /// fields into the active configuration. + /// + /// Omitted fields keep their active values. State retention and drain + /// cancellation are the same as for `setConfig`. An empty object also + /// cancels an active drain. The conversion ignores additional properties of + /// the JavaScript object. + /// + /// # Errors + /// + /// The method throws if an object, a supplied value or the pitch bound + /// order is not valid. After an error, all processor state and any active + /// drain stay the same. + #[wasm_bindgen(js_name = patchConfig)] + pub fn patch_config(&mut self, patch: Ts) -> Result<(), JsError> { + self.processor.patch_config(patch.to_rust()?)?; + Ok(()) + } + /// Processes mono input into left and right `Int16Array` buffers of equal /// length. /// From 20507da16c8ed11309856bc074e10e23857b7181 Mon Sep 17 00:00:00 2001 From: "google-labs-stitch[bot]" <315546542+google-labs-stitch[bot]@users.noreply.github.com> Date: Wed, 25 Nov 2026 09:19:15 +0000 Subject: [PATCH 2/6] refactor: share validation helpers across config patches - Extract pub(crate) validate_* helpers for all stage fields. - Call the shared helpers from *Config::validate and *ConfigPatch. - Share PitchConfigPatch::validate_fields in validate and apply_to. - Align PunchConfigPatch rustdoc terms with PunchConfig. --- src/effects/alien.rs | 9 +++- src/effects/punch.rs | 40 +++++++++++---- src/effects/reverb.rs | 36 ++++++++++--- src/effects/warm.rs | 9 +++- src/formant.rs | 50 +++++++++++++----- src/harmony.rs | 114 +++++++++++++++++++++++++++--------------- src/pitch.rs | 49 +++++++++++------- src/resynthesis.rs | 105 ++++++++++++++++++++++++++------------ 8 files changed, 288 insertions(+), 124 deletions(-) diff --git a/src/effects/alien.rs b/src/effects/alien.rs index a96b1a3..488e36c 100644 --- a/src/effects/alien.rs +++ b/src/effects/alien.rs @@ -53,10 +53,15 @@ impl AlienConfig { /// Returns the first [`Error::InvalidConfig`] with its dotted field path /// and the problem. pub fn validate(self) -> Result<(), Error> { - check_count("alien.loop_frames", i64::from(self.loop_frames), 1, 96_000) + validate_loop_frames(self.loop_frames) } } +/// Checks the range of the loop length of Alien. +pub(crate) fn validate_loop_frames(loop_frames: u32) -> Result<(), Error> { + check_count("alien.loop_frames", i64::from(loop_frames), 1, 96_000) +} + /// Optional changes to [`AlienConfig`]. /// /// Each `None` field keeps its active value on the processor. @@ -88,7 +93,7 @@ impl AlienConfigPatch { /// Checks all supplied fields and does not change the processor state. pub(crate) fn validate(self) -> Result<(), Error> { if let Some(loop_frames) = self.loop_frames { - check_count("alien.loop_frames", i64::from(loop_frames), 1, 96_000)?; + validate_loop_frames(loop_frames)?; } Ok(()) } diff --git a/src/effects/punch.rs b/src/effects/punch.rs index ad39b03..f455847 100644 --- a/src/effects/punch.rs +++ b/src/effects/punch.rs @@ -90,13 +90,33 @@ impl PunchConfig { /// Returns the first [`Error::InvalidConfig`] with its dotted field path /// and the problem. pub fn validate(self) -> Result<(), Error> { - check_range("punch.gain_db", self.gain_db, -96.0, 12.0)?; - check_range("punch.impact", self.impact, 0.0, 1.0)?; - check_range("punch.ceiling_db", self.ceiling_db, -96.0, 0.0)?; - check_range("punch.attack_ms", self.attack_ms, 0.01, 5000.0) + validate_gain_db(self.gain_db)?; + validate_impact(self.impact)?; + validate_ceiling_db(self.ceiling_db)?; + validate_attack_ms(self.attack_ms) } } +/// Checks the range of the input gain of Punch. +pub(crate) fn validate_gain_db(gain_db: f32) -> Result<(), Error> { + check_range("punch.gain_db", gain_db, -96.0, 12.0) +} + +/// Checks the range of the transient emphasis of Punch. +pub(crate) fn validate_impact(impact: f32) -> Result<(), Error> { + check_range("punch.impact", impact, 0.0, 1.0) +} + +/// Checks the range of the output ceiling of Punch. +pub(crate) fn validate_ceiling_db(ceiling_db: f32) -> Result<(), Error> { + check_range("punch.ceiling_db", ceiling_db, -96.0, 0.0) +} + +/// Checks the range of the attack half-life of Punch. +pub(crate) fn validate_attack_ms(attack_ms: f32) -> Result<(), Error> { + check_range("punch.attack_ms", attack_ms, 0.01, 5000.0) +} + /// Optional changes to [`PunchConfig`]. /// /// Each `None` field keeps its active value on the processor. @@ -128,14 +148,14 @@ pub struct PunchConfigPatch { tsify(optional) )] pub impact: Option, - /// The output limit of the saturation in dBFS, -96..=0. + /// The output ceiling of the saturation in dBFS, -96..=0. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), tsify(optional) )] pub ceiling_db: Option, - /// The attack half-life of the peak follower in milliseconds, 0.01..=5000. + /// The attack half-life of the peak followers in milliseconds, 0.01..=5000. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), @@ -148,16 +168,16 @@ impl PunchConfigPatch { /// Checks all supplied fields and does not change the processor state. pub(crate) fn validate(self) -> Result<(), Error> { if let Some(gain_db) = self.gain_db { - check_range("punch.gain_db", gain_db, -96.0, 12.0)?; + validate_gain_db(gain_db)?; } if let Some(impact) = self.impact { - check_range("punch.impact", impact, 0.0, 1.0)?; + validate_impact(impact)?; } if let Some(ceiling_db) = self.ceiling_db { - check_range("punch.ceiling_db", ceiling_db, -96.0, 0.0)?; + validate_ceiling_db(ceiling_db)?; } if let Some(attack_ms) = self.attack_ms { - check_range("punch.attack_ms", attack_ms, 0.01, 5000.0)?; + validate_attack_ms(attack_ms)?; } Ok(()) } diff --git a/src/effects/reverb.rs b/src/effects/reverb.rs index ca2df9a..bf6e4e1 100644 --- a/src/effects/reverb.rs +++ b/src/effects/reverb.rs @@ -108,13 +108,33 @@ impl ReverbConfig { /// Returns the first [`Error::InvalidConfig`] with its dotted field path /// and the problem. pub fn validate(self) -> Result<(), Error> { - check_range("reverb.mix", self.mix, 0.0, 1.0)?; - check_range("reverb.diffusion", self.diffusion, 0.0, 1.0)?; - check_range("reverb.decay", self.decay, 0.0, 1.0)?; - check_range("reverb.brightness_hz", self.brightness_hz, 80.0, 20000.0) + validate_mix(self.mix)?; + validate_diffusion(self.diffusion)?; + validate_decay(self.decay)?; + validate_brightness_hz(self.brightness_hz) } } +/// Checks the range of the wet mix of the reverb. +pub(crate) fn validate_mix(mix: f32) -> Result<(), Error> { + check_range("reverb.mix", mix, 0.0, 1.0) +} + +/// Checks the range of the diffusion control of the reverb. +pub(crate) fn validate_diffusion(diffusion: f32) -> Result<(), Error> { + check_range("reverb.diffusion", diffusion, 0.0, 1.0) +} + +/// Checks the range of the decay control of the reverb. +pub(crate) fn validate_decay(decay: f32) -> Result<(), Error> { + check_range("reverb.decay", decay, 0.0, 1.0) +} + +/// Checks the range of the low-pass cutoff of the reverb. +pub(crate) fn validate_brightness_hz(brightness_hz: f32) -> Result<(), Error> { + check_range("reverb.brightness_hz", brightness_hz, 80.0, 20000.0) +} + /// Optional changes to [`ReverbConfig`]. /// /// Each `None` field keeps its active value on the processor. @@ -173,16 +193,16 @@ impl ReverbConfigPatch { /// Checks all supplied fields and does not change the processor state. pub(crate) fn validate(self) -> Result<(), Error> { if let Some(mix) = self.mix { - check_range("reverb.mix", mix, 0.0, 1.0)?; + validate_mix(mix)?; } if let Some(diffusion) = self.diffusion { - check_range("reverb.diffusion", diffusion, 0.0, 1.0)?; + validate_diffusion(diffusion)?; } if let Some(decay) = self.decay { - check_range("reverb.decay", decay, 0.0, 1.0)?; + validate_decay(decay)?; } if let Some(brightness_hz) = self.brightness_hz { - check_range("reverb.brightness_hz", brightness_hz, 80.0, 20000.0)?; + validate_brightness_hz(brightness_hz)?; } Ok(()) } diff --git a/src/effects/warm.rs b/src/effects/warm.rs index f1a8f88..52b1149 100644 --- a/src/effects/warm.rs +++ b/src/effects/warm.rs @@ -48,10 +48,15 @@ impl WarmConfig { /// Returns the first [`Error::InvalidConfig`] with its dotted field path /// and the problem. pub fn validate(self) -> Result<(), Error> { - check_range("warm.drive_db", self.drive_db, 0.0, 6.0) + validate_drive_db(self.drive_db) } } +/// Checks the range of the drive of Warm. +pub(crate) fn validate_drive_db(drive_db: f32) -> Result<(), Error> { + check_range("warm.drive_db", drive_db, 0.0, 6.0) +} + /// Optional changes to [`WarmConfig`]. /// /// Each `None` field keeps its active value on the processor. @@ -82,7 +87,7 @@ impl WarmConfigPatch { /// Checks all supplied fields and does not change the processor state. pub(crate) fn validate(self) -> Result<(), Error> { if let Some(drive_db) = self.drive_db { - check_range("warm.drive_db", drive_db, 0.0, 6.0)?; + validate_drive_db(drive_db)?; } Ok(()) } diff --git a/src/formant.rs b/src/formant.rs index 5816d53..84f5f7d 100644 --- a/src/formant.rs +++ b/src/formant.rs @@ -95,15 +95,43 @@ impl FormantConfig { /// Returns the first [`Error::InvalidConfig`], with the dotted path of the /// field and the problem. pub fn validate(self) -> Result<(), Error> { - check_range("resynthesis.formant.width", self.width, 0.5, 2.0)?; - check_range("resynthesis.formant.stretch", self.stretch, 0.5, 2.0)?; - let field = "resynthesis.formant.aspiration_mix"; - check_range(field, self.aspiration_mix, 0.0, 1.0)?; - let field = "resynthesis.formant.aspiration_cutoff_hz"; - check_range(field, self.aspiration_cutoff_hz, 500.0, 10000.0) + validate_width(self.width)?; + validate_stretch(self.stretch)?; + validate_aspiration_mix(self.aspiration_mix)?; + validate_aspiration_cutoff_hz(self.aspiration_cutoff_hz) } } +/// Checks the range of the vocal-tract width. +pub(crate) fn validate_width(width: f32) -> Result<(), Error> { + check_range("resynthesis.formant.width", width, 0.5, 2.0) +} + +/// Checks the range of the vocal-tract length. +pub(crate) fn validate_stretch(stretch: f32) -> Result<(), Error> { + check_range("resynthesis.formant.stretch", stretch, 0.5, 2.0) +} + +/// Checks the range of the aspiration mix. +pub(crate) fn validate_aspiration_mix(aspiration_mix: f32) -> Result<(), Error> { + check_range( + "resynthesis.formant.aspiration_mix", + aspiration_mix, + 0.0, + 1.0, + ) +} + +/// Checks the range of the aspiration high-pass cutoff. +pub(crate) fn validate_aspiration_cutoff_hz(aspiration_cutoff_hz: f32) -> Result<(), Error> { + check_range( + "resynthesis.formant.aspiration_cutoff_hz", + aspiration_cutoff_hz, + 500.0, + 10000.0, + ) +} + /// Optional changes to [`FormantConfig`]. /// /// Each `None` field keeps its active value on the processor. @@ -155,18 +183,16 @@ impl FormantConfigPatch { /// Checks all supplied fields and does not change the processor state. pub(crate) fn validate(self) -> Result<(), Error> { if let Some(width) = self.width { - check_range("resynthesis.formant.width", width, 0.5, 2.0)?; + validate_width(width)?; } if let Some(stretch) = self.stretch { - check_range("resynthesis.formant.stretch", stretch, 0.5, 2.0)?; + validate_stretch(stretch)?; } if let Some(aspiration_mix) = self.aspiration_mix { - let field = "resynthesis.formant.aspiration_mix"; - check_range(field, aspiration_mix, 0.0, 1.0)?; + validate_aspiration_mix(aspiration_mix)?; } if let Some(aspiration_cutoff_hz) = self.aspiration_cutoff_hz { - let field = "resynthesis.formant.aspiration_cutoff_hz"; - check_range(field, aspiration_cutoff_hz, 500.0, 10000.0)?; + validate_aspiration_cutoff_hz(aspiration_cutoff_hz)?; } Ok(()) } diff --git a/src/harmony.rs b/src/harmony.rs index d76e866..9338943 100644 --- a/src/harmony.rs +++ b/src/harmony.rs @@ -369,27 +369,75 @@ impl HarmonyConfig { /// and the problem. For an array control, the error identifies the array /// field, not the index of an element. pub fn validate(self) -> Result<(), Error> { - for interval in self.chromatic_intervals { - let field = "resynthesis.harmony.chromatic_intervals"; - check_count(field, i64::from(interval), -24, 24)?; - } - for interval in self.diatonic_intervals { - let field = "resynthesis.harmony.diatonic_intervals"; - check_count(field, i64::from(interval), -14, 14)?; - } - let field = "resynthesis.harmony.voices"; - check_count(field, i64::from(self.voices), 0, HARMONY_VOICES as i64)?; - let field = "resynthesis.harmony.register_percent"; - check_range(field, self.register_percent, 0.0, 100.0)?; - let field = "resynthesis.harmony.voicing_spread_percent"; - check_range(field, self.voicing_spread_percent, 0.0, 100.0)?; - check_range( - "resynthesis.harmony.portamento_ms", - self.portamento_ms, - 0.0, - 10_000.0, - ) + validate_chromatic_intervals(self.chromatic_intervals)?; + validate_diatonic_intervals(self.diatonic_intervals)?; + validate_voices(self.voices)?; + validate_register_percent(self.register_percent)?; + validate_voicing_spread_percent(self.voicing_spread_percent)?; + validate_portamento_ms(self.portamento_ms) + } +} + +/// Checks the four fixed semitone offsets of harmony. +pub(crate) fn validate_chromatic_intervals( + chromatic_intervals: [i8; HARMONY_VOICES], +) -> Result<(), Error> { + for interval in chromatic_intervals { + let field = "resynthesis.harmony.chromatic_intervals"; + check_count(field, i64::from(interval), -24, 24)?; } + Ok(()) +} + +/// Checks the four offsets in scale steps of harmony. +pub(crate) fn validate_diatonic_intervals( + diatonic_intervals: [i8; HARMONY_VOICES], +) -> Result<(), Error> { + for interval in diatonic_intervals { + let field = "resynthesis.harmony.diatonic_intervals"; + check_count(field, i64::from(interval), -14, 14)?; + } + Ok(()) +} + +/// Checks the count of interval harmony voices. +pub(crate) fn validate_voices(voices: u8) -> Result<(), Error> { + check_count( + "resynthesis.harmony.voices", + i64::from(voices), + 0, + HARMONY_VOICES as i64, + ) +} + +/// Checks the range of the chord register. +pub(crate) fn validate_register_percent(register_percent: f32) -> Result<(), Error> { + check_range( + "resynthesis.harmony.register_percent", + register_percent, + 0.0, + 100.0, + ) +} + +/// Checks the range of the chord spread. +pub(crate) fn validate_voicing_spread_percent(voicing_spread_percent: f32) -> Result<(), Error> { + check_range( + "resynthesis.harmony.voicing_spread_percent", + voicing_spread_percent, + 0.0, + 100.0, + ) +} + +/// Checks the range of the portamento half-life. +pub(crate) fn validate_portamento_ms(portamento_ms: f32) -> Result<(), Error> { + check_range( + "resynthesis.harmony.portamento_ms", + portamento_ms, + 0.0, + 10_000.0, + ) } /// Optional changes to [`HarmonyConfig`]. @@ -493,36 +541,22 @@ impl HarmonyConfigPatch { /// Checks all supplied fields and does not change the processor state. pub(crate) fn validate(self) -> Result<(), Error> { if let Some(chromatic_intervals) = self.chromatic_intervals { - for interval in chromatic_intervals { - let field = "resynthesis.harmony.chromatic_intervals"; - check_count(field, i64::from(interval), -24, 24)?; - } + validate_chromatic_intervals(chromatic_intervals)?; } if let Some(diatonic_intervals) = self.diatonic_intervals { - for interval in diatonic_intervals { - let field = "resynthesis.harmony.diatonic_intervals"; - check_count(field, i64::from(interval), -14, 14)?; - } + validate_diatonic_intervals(diatonic_intervals)?; } if let Some(voices) = self.voices { - let field = "resynthesis.harmony.voices"; - check_count(field, i64::from(voices), 0, HARMONY_VOICES as i64)?; + validate_voices(voices)?; } if let Some(register_percent) = self.register_percent { - let field = "resynthesis.harmony.register_percent"; - check_range(field, register_percent, 0.0, 100.0)?; + validate_register_percent(register_percent)?; } if let Some(voicing_spread_percent) = self.voicing_spread_percent { - let field = "resynthesis.harmony.voicing_spread_percent"; - check_range(field, voicing_spread_percent, 0.0, 100.0)?; + validate_voicing_spread_percent(voicing_spread_percent)?; } if let Some(portamento_ms) = self.portamento_ms { - check_range( - "resynthesis.harmony.portamento_ms", - portamento_ms, - 0.0, - 10_000.0, - )?; + validate_portamento_ms(portamento_ms)?; } Ok(()) } diff --git a/src/pitch.rs b/src/pitch.rs index 4fd8cb6..eb6c785 100644 --- a/src/pitch.rs +++ b/src/pitch.rs @@ -79,9 +79,9 @@ impl PitchConfig { /// [`ConfigProblem::Unordered`]. The `other` value of that problem is /// `resynthesis.pitch.max_frequency_hz`. pub fn validate(self) -> Result<(), Error> { - check_range("resynthesis.pitch.threshold", self.threshold, 0.002, 0.2)?; - check_range(MIN_FIELD, self.min_frequency_hz, 40.0, 2000.0)?; - check_range(MAX_FIELD, self.max_frequency_hz, 40.0, 2000.0)?; + validate_threshold(self.threshold)?; + validate_min_frequency_hz(self.min_frequency_hz)?; + validate_max_frequency_hz(self.max_frequency_hz)?; check_frequency_order(self.min_frequency_hz, self.max_frequency_hz) } } @@ -91,6 +91,21 @@ const MIN_FIELD: &str = "resynthesis.pitch.min_frequency_hz"; /// The dotted field path of the upper pitch bound. const MAX_FIELD: &str = "resynthesis.pitch.max_frequency_hz"; +/// Checks the range of the pitch acquisition threshold. +pub(crate) fn validate_threshold(threshold: f32) -> Result<(), Error> { + check_range("resynthesis.pitch.threshold", threshold, 0.002, 0.2) +} + +/// Checks the range of the lower bound for pitch reports. +pub(crate) fn validate_min_frequency_hz(min_frequency_hz: f32) -> Result<(), Error> { + check_range(MIN_FIELD, min_frequency_hz, 40.0, 2000.0) +} + +/// Checks the range of the upper bound for pitch reports. +pub(crate) fn validate_max_frequency_hz(max_frequency_hz: f32) -> Result<(), Error> { + check_range(MAX_FIELD, max_frequency_hz, 40.0, 2000.0) +} + /// Checks that `min_frequency_hz` is strictly below `max_frequency_hz`. fn check_frequency_order(min_frequency_hz: f32, max_frequency_hz: f32) -> Result<(), Error> { if min_frequency_hz >= max_frequency_hz { @@ -141,18 +156,24 @@ pub struct PitchConfigPatch { } impl PitchConfigPatch { - /// Checks all supplied fields, and checks their order if both bounds are - /// present. - pub(crate) fn validate(self) -> Result<(), Error> { + /// Checks the ranges of all supplied fields. + fn validate_fields(self) -> Result<(), Error> { if let Some(threshold) = self.threshold { - check_range("resynthesis.pitch.threshold", threshold, 0.002, 0.2)?; + validate_threshold(threshold)?; } if let Some(min_frequency_hz) = self.min_frequency_hz { - check_range(MIN_FIELD, min_frequency_hz, 40.0, 2000.0)?; + validate_min_frequency_hz(min_frequency_hz)?; } if let Some(max_frequency_hz) = self.max_frequency_hz { - check_range(MAX_FIELD, max_frequency_hz, 40.0, 2000.0)?; + validate_max_frequency_hz(max_frequency_hz)?; } + Ok(()) + } + + /// Checks all supplied fields, and checks their order if both bounds are + /// present. + pub(crate) fn validate(self) -> Result<(), Error> { + self.validate_fields()?; if let (Some(min_frequency_hz), Some(max_frequency_hz)) = (self.min_frequency_hz, self.max_frequency_hz) { @@ -164,15 +185,7 @@ impl PitchConfigPatch { /// Validates all supplied fields, checks the frequency order against /// `config` and writes the fields into `config`. pub(crate) fn apply_to(self, config: &mut PitchConfig) -> Result<(), Error> { - if let Some(threshold) = self.threshold { - check_range("resynthesis.pitch.threshold", threshold, 0.002, 0.2)?; - } - if let Some(min_frequency_hz) = self.min_frequency_hz { - check_range(MIN_FIELD, min_frequency_hz, 40.0, 2000.0)?; - } - if let Some(max_frequency_hz) = self.max_frequency_hz { - check_range(MAX_FIELD, max_frequency_hz, 40.0, 2000.0)?; - } + self.validate_fields()?; let min_frequency_hz = self.min_frequency_hz.unwrap_or(config.min_frequency_hz); let max_frequency_hz = self.max_frequency_hz.unwrap_or(config.max_frequency_hz); if self.min_frequency_hz.is_some() || self.max_frequency_hz.is_some() { diff --git a/src/resynthesis.rs b/src/resynthesis.rs index 79c5ef2..cbb4ce3 100644 --- a/src/resynthesis.rs +++ b/src/resynthesis.rs @@ -127,15 +127,15 @@ impl CorrectionConfig { /// Returns [`Error::InvalidConfig`], with the dotted path of the field and /// the problem, if `retune_ms` is not valid. pub fn validate(self) -> Result<(), Error> { - check_range( - "resynthesis.correction.retune_ms", - self.retune_ms, - 0.0, - 400.0, - ) + validate_retune_ms(self.retune_ms) } } +/// Checks the range of the retune half-life. +pub(crate) fn validate_retune_ms(retune_ms: f32) -> Result<(), Error> { + check_range("resynthesis.correction.retune_ms", retune_ms, 0.0, 400.0) +} + /// Optional changes to [`CorrectionConfig`]. /// /// Each `None` field keeps its active value on the processor. @@ -173,7 +173,7 @@ impl CorrectionConfigPatch { /// Checks all supplied fields and does not change the processor state. pub(crate) fn validate(self) -> Result<(), Error> { if let Some(retune_ms) = self.retune_ms { - check_range("resynthesis.correction.retune_ms", retune_ms, 0.0, 400.0)?; + validate_retune_ms(retune_ms)?; } Ok(()) } @@ -349,24 +349,67 @@ impl ResynthesisConfig { self.correction.validate()?; self.formant.validate()?; self.harmony.validate()?; - check_range("resynthesis.pitch_ratio", self.pitch_ratio, 0.25, 4.0)?; - check_range("resynthesis.choir_detune", self.choir_detune, 10.0, 100.0)?; - check_range("resynthesis.choir_delay", self.choir_delay, 20.0, 200.0)?; - let field = "resynthesis.choir_spread_percent"; - check_range(field, self.choir_spread_percent, 0.0, 100.0)?; - check_range("resynthesis.harmony_gain", self.harmony_gain, 0.0, 1.0)?; - let field = "resynthesis.harmonic_modulation"; - check_range(field, self.harmonic_modulation, 0.0, 24.0)?; - check_range("resynthesis.dry_mix", self.dry_mix, 0.0, 1.0)?; - check_count( - "resynthesis.choir_voices", - i64::from(self.choir_voices), - 1, - 16, - ) + validate_pitch_ratio(self.pitch_ratio)?; + validate_choir_detune(self.choir_detune)?; + validate_choir_delay(self.choir_delay)?; + validate_choir_spread_percent(self.choir_spread_percent)?; + validate_harmony_gain(self.harmony_gain)?; + validate_harmonic_modulation(self.harmonic_modulation)?; + validate_dry_mix(self.dry_mix)?; + validate_choir_voices(self.choir_voices) } } +/// Checks the range of the global pitch multiplier. +pub(crate) fn validate_pitch_ratio(pitch_ratio: f32) -> Result<(), Error> { + check_range("resynthesis.pitch_ratio", pitch_ratio, 0.25, 4.0) +} + +/// Checks the range of the choir voice count. +pub(crate) fn validate_choir_voices(choir_voices: u8) -> Result<(), Error> { + check_count("resynthesis.choir_voices", i64::from(choir_voices), 1, 16) +} + +/// Checks the range of the choir detune. +pub(crate) fn validate_choir_detune(choir_detune: f32) -> Result<(), Error> { + check_range("resynthesis.choir_detune", choir_detune, 10.0, 100.0) +} + +/// Checks the range of the choir delay scale. +pub(crate) fn validate_choir_delay(choir_delay: f32) -> Result<(), Error> { + check_range("resynthesis.choir_delay", choir_delay, 20.0, 200.0) +} + +/// Checks the range of the choir stereo width. +pub(crate) fn validate_choir_spread_percent(choir_spread_percent: f32) -> Result<(), Error> { + check_range( + "resynthesis.choir_spread_percent", + choir_spread_percent, + 0.0, + 100.0, + ) +} + +/// Checks the range of the linear gain of the harmony voices. +pub(crate) fn validate_harmony_gain(harmony_gain: f32) -> Result<(), Error> { + check_range("resynthesis.harmony_gain", harmony_gain, 0.0, 1.0) +} + +/// Checks the range of the harmonic modulation depth. +pub(crate) fn validate_harmonic_modulation(harmonic_modulation: f32) -> Result<(), Error> { + check_range( + "resynthesis.harmonic_modulation", + harmonic_modulation, + 0.0, + 24.0, + ) +} + +/// Checks the range of the resynthesis dry mix. +pub(crate) fn validate_dry_mix(dry_mix: f32) -> Result<(), Error> { + check_range("resynthesis.dry_mix", dry_mix, 0.0, 1.0) +} + /// Optional changes to [`ResynthesisConfig`]. /// /// Each `None` field keeps its active value on the processor. @@ -489,30 +532,28 @@ impl ResynthesisConfigPatch { /// Checks the supplied scalar fields of resynthesis. fn validate_scalars(self) -> Result<(), Error> { if let Some(pitch_ratio) = self.pitch_ratio { - check_range("resynthesis.pitch_ratio", pitch_ratio, 0.25, 4.0)?; + validate_pitch_ratio(pitch_ratio)?; } if let Some(choir_detune) = self.choir_detune { - check_range("resynthesis.choir_detune", choir_detune, 10.0, 100.0)?; + validate_choir_detune(choir_detune)?; } if let Some(choir_delay) = self.choir_delay { - check_range("resynthesis.choir_delay", choir_delay, 20.0, 200.0)?; + validate_choir_delay(choir_delay)?; } if let Some(choir_spread_percent) = self.choir_spread_percent { - let field = "resynthesis.choir_spread_percent"; - check_range(field, choir_spread_percent, 0.0, 100.0)?; + validate_choir_spread_percent(choir_spread_percent)?; } if let Some(harmony_gain) = self.harmony_gain { - check_range("resynthesis.harmony_gain", harmony_gain, 0.0, 1.0)?; + validate_harmony_gain(harmony_gain)?; } if let Some(harmonic_modulation) = self.harmonic_modulation { - let field = "resynthesis.harmonic_modulation"; - check_range(field, harmonic_modulation, 0.0, 24.0)?; + validate_harmonic_modulation(harmonic_modulation)?; } if let Some(dry_mix) = self.dry_mix { - check_range("resynthesis.dry_mix", dry_mix, 0.0, 1.0)?; + validate_dry_mix(dry_mix)?; } if let Some(choir_voices) = self.choir_voices { - check_count("resynthesis.choir_voices", i64::from(choir_voices), 1, 16)?; + validate_choir_voices(choir_voices)?; } Ok(()) } From 25e0ca5d96dfa0a4b5ac6aaf55cc12c68de3a6ec Mon Sep 17 00:00:00 2001 From: "google-labs-stitch[bot]" <315546542+google-labs-stitch[bot]@users.noreply.github.com> Date: Wed, 25 Nov 2026 09:31:49 +0000 Subject: [PATCH 3/6] feat(events)!: mark ControlEvent as non-exhaustive - Add #[non_exhaustive] to ControlEvent for the 0.4.0 release. BREAKING CHANGE: ControlEvent adds Patch and is #[non_exhaustive]. --- src/events.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/events.rs b/src/events.rs index 5d08c0d..3be2dbc 100644 --- a/src/events.rs +++ b/src/events.rs @@ -17,6 +17,7 @@ use crate::{Error, EventProblem, ProcessorConfig, ProcessorConfigPatch, Resynthe /// configuration of the processor. Configuration changes have the same effects /// on state as [`crate::Processor::set_config`]. #[derive(Clone, Copy, Debug, PartialEq)] +#[non_exhaustive] #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), derive(serde::Serialize, serde::Deserialize, tsify::Tsify), From a4170f2b8b7baedad1af2a886279814c07ef3a79 Mon Sep 17 00:00:00 2001 From: "google-labs-stitch[bot]" <315546542+google-labs-stitch[bot]@users.noreply.github.com> Date: Thu, 26 Nov 2026 03:46:46 +0000 Subject: [PATCH 4/6] fix: allow undefined in TypeScript patch fields - Add `| undefined` to all optional `tsify` types on patch structs. - Check `undefined` patch fields in `scripts/verify-pack.mjs`. - Document `undefined` patch fields in `README.md`. --- README.md | 8 +-- scripts/verify-pack.mjs | 132 ++++++++++++++++++++++++++++++++++++---- src/config.rs | 12 ++-- src/effects/alien.rs | 4 +- src/effects/punch.rs | 10 +-- src/effects/reverb.rs | 12 ++-- src/effects/warm.rs | 4 +- src/formant.rs | 10 +-- src/harmony.rs | 24 ++++---- src/pitch.rs | 6 +- src/resynthesis.rs | 40 ++++++------ 11 files changed, 185 insertions(+), 77 deletions(-) diff --git a/README.md b/README.md index f031176..b41b177 100644 --- a/README.md +++ b/README.md @@ -540,10 +540,10 @@ the Rust types. To change selected fields without a full configuration copy, give a `ProcessorConfigPatch` object to `patchConfig(patch)`. All fields in -`ProcessorConfigPatch` and the stage patches are optional. Omitted fields keep -their active values on the processor. `patchConfig()` validates the supplied -fields and the pitch bounds before any state changes. Each successful call -cancels an active drain, also for an empty `{}` patch. +`ProcessorConfigPatch` and the stage patches are optional. Absent or `undefined` +fields keep their active values on the processor. `patchConfig()` validates the +supplied fields and the pitch bounds before any state changes. Each successful +call cancels an active drain, also for an empty `{}` patch. `resynthesis.randomSeed` and the `processedFrames` field of feedback and telemetry use `bigint`. Frame offsets, block lengths and latency use diff --git a/scripts/verify-pack.mjs b/scripts/verify-pack.mjs index a707f1c..78a133a 100644 --- a/scripts/verify-pack.mjs +++ b/scripts/verify-pack.mjs @@ -364,10 +364,48 @@ function verifyRuntimeImport(consumerDir, packageName) { " assert.equal(processor.config().resynthesis.correction.flexTune, 0);", " assert.equal(processor.config().resynthesis.harmony.voices, 4);", "", - " processor.patchConfig({ outputGain: 0.9, resynthesis: { correction: { humanize: 0.4, flexTune: 0.3 } } });", + " processor.patchConfig({", + " outputGain: 0.9,", + " resynthesis: {", + " correction: { humanize: 0.4, flexTune: 0.3 },", + " harmony: { chromaticIntervals: [3, 7, 10, 12] },", + " randomSeed: 7n,", + " },", + " });", " assert.equal(Math.fround(processor.config().outputGain), Math.fround(0.9));", " assert.equal(Math.fround(processor.config().resynthesis.correction.humanize), Math.fround(0.4));", " assert.equal(Math.fround(processor.config().resynthesis.correction.flexTune), Math.fround(0.3));", + " assert.deepEqual(processor.config().resynthesis.harmony.chromaticIntervals, [3, 7, 10, 12]);", + " assert.equal(processor.config().resynthesis.randomSeed, 7n);", + " processor.patchConfig({", + " punch: undefined,", + " warm: { enabled: undefined, driveDb: undefined },", + " resynthesis: {", + " pitch: undefined,", + " correction: {", + " enabled: undefined,", + " notes: undefined,", + " retuneMs: undefined,", + " humanize: undefined,", + " flexTune: undefined,", + " },", + " formant: undefined,", + " harmony: {", + " chromaticIntervals: undefined,", + " diatonicIntervals: undefined,", + " voices: undefined,", + " },", + " randomSeed: undefined,", + " },", + " alien: undefined,", + " reverb: undefined,", + " outputGain: undefined,", + " });", + " assert.equal(Math.fround(processor.config().outputGain), Math.fround(0.9));", + " assert.equal(Math.fround(processor.config().resynthesis.correction.humanize), Math.fround(0.4));", + " assert.equal(Math.fround(processor.config().resynthesis.correction.flexTune), Math.fround(0.3));", + " assert.deepEqual(processor.config().resynthesis.harmony.chromaticIntervals, [3, 7, 10, 12]);", + " assert.equal(processor.config().resynthesis.randomSeed, 7n);", " assert.equal(processor.controlActivity().choirVoices, true);", ' processor.patchConfig({ resynthesis: { mode: "harmony" } });', " assert.equal(processor.controlActivity().choirVoices, false);", @@ -375,8 +413,10 @@ function verifyRuntimeImport(consumerDir, packageName) { " const input = new Int16Array(128);", " const left = new Int16Array(128);", " const right = new Int16Array(128);", - ' processor.process(input, left, right, [{ offset: 0, event: { type: "patch", value: { resynthesis: { dryMix: 0.2 } } } }]);', + ' processor.process(input, left, right, [{ offset: 0, event: { type: "patch", value: { outputGain: undefined, resynthesis: { dryMix: 0.2, randomSeed: undefined } } } }]);', + " assert.equal(Math.fround(processor.config().outputGain), Math.fround(0.9));", " assert.equal(Math.fround(processor.config().resynthesis.dryMix), Math.fround(0.2));", + " assert.equal(processor.config().resynthesis.randomSeed, 7n);", "} finally {", " processor.free();", "}", @@ -804,35 +844,103 @@ function verifyTypeDeclarations(consumerDir, packageName) { " }", " const processor = new Tunelet(48000, 128, configWithUndefined);", " processor.setConfig(configWithUndefined);", - " const punchPatch: PunchConfigPatch = { enabled: true };", - " const warmPatch: WarmConfigPatch = { driveDb: 2 };", - " const pitchPatch: PitchConfigPatch = { minFrequencyHz: 80 };", + " const punchPatch: PunchConfigPatch = {", + " enabled: true,", + " gainDb: optionalVoices,", + " impact: undefined,", + " ceilingDb: undefined,", + " attackMs: undefined,", + " };", + " const warmPatch: WarmConfigPatch = {", + " enabled: undefined,", + " driveDb: optionalVoices ?? 2,", + " };", + " const pitchPatch: PitchConfigPatch = {", + " threshold: undefined,", + " minFrequencyHz: 80,", + " maxFrequencyHz: optionalVoices,", + " };", " const correctionPatch: CorrectionConfigPatch = {", + " enabled: undefined,", + " notes: undefined,", " retuneMs: 15,", - " humanize: 0.25,", - " flexTune: 0.5,", + " humanize: optionalVoices,", + " flexTune: optionalVoices,", + " };", + " const formantPatch: FormantConfigPatch = {", + " enabled: undefined,", + " width: 1.1,", + " stretch: undefined,", + " aspirationMix: optionalVoices,", + " aspirationCutoffHz: undefined,", + " };", + " const harmonyPatch: HarmonyConfigPatch = {", + " source: undefined,", + " key: undefined,", + " scale: undefined,", + " chromaticIntervals: undefined,", + " diatonicIntervals: undefined,", + " chord: undefined,", + " degree: undefined,", + " inversion: undefined,", + " registerPercent: optionalVoices,", + " voicingSpreadPercent: undefined,", + " portamentoMs: undefined,", + " voices: optionalVoices,", " };", - " const formantPatch: FormantConfigPatch = { width: 1.1 };", - " const harmonyPatch: HarmonyConfigPatch = { voices: 2 };", " const resynthesisPatch: ResynthesisConfigPatch = {", " pitch: pitchPatch,", " correction: correctionPatch,", + " pitchRatio: optionalVoices,", " formant: formantPatch,", + " mode: undefined,", + " choirVoices: optionalVoices,", + " choirDetune: undefined,", + " choirDelay: undefined,", + " choirSpreadPercent: undefined,", + " stereoOutput: undefined,", " harmony: harmonyPatch,", + " harmonyGain: undefined,", + " harmonicModulation: undefined,", " dryMix: 0.2,", + " randomSeed: undefined,", + " };", + " const alienPatch: AlienConfigPatch = {", + " enabled: undefined,", + " loopFrames: 1000,", + " };", + " const reverbPatch: ReverbConfigPatch = {", + " enabled: undefined,", + " mode: undefined,", + " mix: 0.4,", + " diffusion: optionalVoices,", + " decay: undefined,", + " brightnessHz: undefined,", " };", - " const alienPatch: AlienConfigPatch = { loopFrames: 1000 };", - " const reverbPatch: ReverbConfigPatch = { mix: 0.4 };", " const patch: ProcessorConfigPatch & WasmProcessorConfigPatch = {", " punch: punchPatch,", " warm: warmPatch,", " resynthesis: resynthesisPatch,", " alien: alienPatch,", " reverb: reverbPatch,", - " outputGain: 0.9,", + " outputGain: optionalVoices,", + " };", + " const emptyUndefinedPatch: ProcessorConfigPatch & WasmProcessorConfigPatch = {", + " punch: undefined,", + " warm: undefined,", + " resynthesis: {", + " pitch: undefined,", + " correction: undefined,", + " formant: undefined,", + " harmony: undefined,", + " },", + " alien: undefined,", + " reverb: undefined,", + " outputGain: undefined,", " };", ' const patchEvent: ControlEvent = { type: "patch", value: patch };', " processor.patchConfig(patch);", + " processor.patchConfig(emptyUndefinedPatch);", " const activity: ControlActivity = processor.controlActivity();", " const views = new TuneletAudioViews(exportsFromRoot.memory, processor);", " const ptrs: [number, number, number] = [", diff --git a/src/config.rs b/src/config.rs index 39c0a81..e0c8d21 100644 --- a/src/config.rs +++ b/src/config.rs @@ -344,42 +344,42 @@ pub struct ProcessorConfigPatch { #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "PunchConfigPatch | undefined") )] pub punch: Option, /// Optional changes to [`WarmConfig`]. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "WarmConfigPatch | undefined") )] pub warm: Option, /// Optional changes to [`ResynthesisConfig`]. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "ResynthesisConfigPatch | undefined") )] pub resynthesis: Option, /// Optional changes to [`AlienConfig`]. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "AlienConfigPatch | undefined") )] pub alien: Option, /// Optional changes to [`ReverbConfig`]. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "ReverbConfigPatch | undefined") )] pub reverb: Option, /// The linear gain after all effects, 0..=64. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub output_gain: Option, } diff --git a/src/effects/alien.rs b/src/effects/alien.rs index 488e36c..9440e9d 100644 --- a/src/effects/alien.rs +++ b/src/effects/alien.rs @@ -77,14 +77,14 @@ pub struct AlienConfigPatch { #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "boolean | undefined") )] pub enabled: Option, /// The loop length in frames, 1..=96000. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub loop_frames: Option, } diff --git a/src/effects/punch.rs b/src/effects/punch.rs index 218c3bc..3667d49 100644 --- a/src/effects/punch.rs +++ b/src/effects/punch.rs @@ -131,35 +131,35 @@ pub struct PunchConfigPatch { #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "boolean | undefined") )] pub enabled: Option, /// The input gain in decibels, -96..=12. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub gain_db: Option, /// The transient emphasis without a unit, 0..=1. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub impact: Option, /// The output ceiling of the saturation in dBFS, -96..=0. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub ceiling_db: Option, /// The attack half-life of the peak followers in milliseconds, 0.01..=5000. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub attack_ms: Option, } diff --git a/src/effects/reverb.rs b/src/effects/reverb.rs index 171fe83..79e048b 100644 --- a/src/effects/reverb.rs +++ b/src/effects/reverb.rs @@ -149,42 +149,42 @@ pub struct ReverbConfigPatch { #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "boolean | undefined") )] pub enabled: Option, /// The topology of the delay network (`ReverbMode`). #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "ReverbMode | undefined") )] pub mode: Option, /// The wet fraction, 0..=1. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub mix: Option, /// The diffusion control without a unit, 0..=1. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub diffusion: Option, /// The feedback control without a unit, 0..=1. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub decay: Option, /// The low-pass cutoff in hertz for networks with damped paths, 80..=20000. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub brightness_hz: Option, } diff --git a/src/effects/warm.rs b/src/effects/warm.rs index 52b1149..2037b67 100644 --- a/src/effects/warm.rs +++ b/src/effects/warm.rs @@ -71,14 +71,14 @@ pub struct WarmConfigPatch { #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "boolean | undefined") )] pub enabled: Option, /// The drive in decibels, 0..=6. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub drive_db: Option, } diff --git a/src/formant.rs b/src/formant.rs index 3bd93a3..209d8df 100644 --- a/src/formant.rs +++ b/src/formant.rs @@ -148,35 +148,35 @@ pub struct FormantConfigPatch { #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "boolean | undefined") )] pub enabled: Option, /// The vocal-tract width factor, 0.5..=2. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub width: Option, /// The vocal-tract length factor, 0.5..=2. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub stretch: Option, /// The aspiration level, 0..=1, without a unit. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub aspiration_mix: Option, /// The high-pass cutoff for aspiration in hertz, 500..=10000. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub aspiration_cutoff_hz: Option, } diff --git a/src/harmony.rs b/src/harmony.rs index fd3027c..74c98db 100644 --- a/src/harmony.rs +++ b/src/harmony.rs @@ -462,42 +462,42 @@ pub struct HarmonyConfigPatch { #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "HarmonySource | undefined") )] pub source: Option, /// The pitch class of the tonic (`PitchClass`). #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "PitchClass | undefined") )] pub key: Option, /// The scale for smart intervals and degree chords (`HarmonyScale`). #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "HarmonyScale | undefined") )] pub scale: Option, /// Four fixed semitone offsets, each in -24..=24. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional, type = "[number, number, number, number]") + tsify(optional, type = "[number, number, number, number] | undefined") )] pub chromatic_intervals: Option<[i8; HARMONY_VOICES]>, /// Four offsets in scale steps, each in -14..=14. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional, type = "[number, number, number, number]") + tsify(optional, type = "[number, number, number, number] | undefined") )] pub diatonic_intervals: Option<[i8; HARMONY_VOICES]>, /// The named chord for [`HarmonySource::ChordByName`] (`ChordName`). #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "ChordName | undefined") )] pub chord: Option, /// The chord on a scale degree for [`HarmonySource::ChordByDegree`] @@ -505,42 +505,42 @@ pub struct HarmonyConfigPatch { #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "ChordDegree | undefined") )] pub degree: Option, /// The inversion for named chords and degree chords (`Inversion`). #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "Inversion | undefined") )] pub inversion: Option, /// The chord register from low to high, 0..=100%. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub register_percent: Option, /// The chord spread from close to open, 0..=100%. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub voicing_spread_percent: Option, /// The half-life of the target period in milliseconds, 0..=10000. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub portamento_ms: Option, /// The number of voices that sound in the interval sources, 0..=4. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub voices: Option, } diff --git a/src/pitch.rs b/src/pitch.rs index eb6c785..b6298ca 100644 --- a/src/pitch.rs +++ b/src/pitch.rs @@ -132,7 +132,7 @@ pub struct PitchConfigPatch { #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub threshold: Option, /// The lower bound of the feedback in hertz (inclusive), 40..=2000. @@ -141,7 +141,7 @@ pub struct PitchConfigPatch { #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub min_frequency_hz: Option, /// The upper bound of the feedback in hertz (inclusive), 40..=2000. @@ -150,7 +150,7 @@ pub struct PitchConfigPatch { #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub max_frequency_hz: Option, } diff --git a/src/resynthesis.rs b/src/resynthesis.rs index 666998e..d361f4e 100644 --- a/src/resynthesis.rs +++ b/src/resynthesis.rs @@ -206,35 +206,35 @@ pub struct CorrectionConfigPatch { #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "boolean | undefined") )] pub enabled: Option, /// The configured target pitch classes (`NoteMask`). #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "NoteMask | undefined") )] pub notes: Option, /// The half-life of the ratio in milliseconds, 0..=400. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub retune_ms: Option, /// The relaxation on sustained notes without a unit, 0..=1. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub humanize: Option, /// The outer soft-zone width of each target bin without a unit, 0..=1. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub flex_tune: Option, } @@ -507,105 +507,105 @@ pub struct ResynthesisConfigPatch { #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "PitchConfigPatch | undefined") )] pub pitch: Option, /// Optional changes to [`CorrectionConfig`]. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "CorrectionConfigPatch | undefined") )] pub correction: Option, /// The pitch multiplier, 0.25..=4. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub pitch_ratio: Option, /// Optional changes to [`FormantConfig`]. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "FormantConfigPatch | undefined") )] pub formant: Option, /// The voice arrangement (`MultiVoiceMode`). #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "MultiVoiceMode | undefined") )] pub mode: Option, /// The total number of choir voices, with the lead voice, 1..=16. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub choir_voices: Option, /// The drift control for secondary voices, 10..=100, without a unit. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub choir_detune: Option, /// The scale of the choir delay table, 20..=200, without a unit. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub choir_delay: Option, /// The stereo width of the choir, 0..=100%. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub choir_spread_percent: Option, /// Enables a stereo pan for each voice (`true` or `false`). #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "boolean | undefined") )] pub stereo_output: Option, /// Optional changes to [`HarmonyConfig`]. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "HarmonyConfigPatch | undefined") )] pub harmony: Option, /// The linear gain of the four harmony voices, 0..=1. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub harmony_gain: Option, /// The modulation depth, 0..=24, without a unit. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub harmonic_modulation: Option, /// The dry fraction at the resynthesis stage, 0..=1. #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "number | undefined") )] pub dry_mix: Option, /// The seed for choir drift and aspiration (`0..=u64::MAX`). #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), serde(skip_serializing_if = "Option::is_none"), - tsify(optional) + tsify(optional, type = "bigint | undefined") )] pub random_seed: Option, } From 6808f3d6aaf55232065637d1a2e4b724ecdd0213 Mon Sep 17 00:00:00 2001 From: "google-labs-stitch[bot]" <315546542+google-labs-stitch[bot]@users.noreply.github.com> Date: Thu, 26 Nov 2026 09:41:18 +0000 Subject: [PATCH 5/6] feat: mark configuration patch structures non-exhaustive - Add #[non_exhaustive] to ProcessorConfigPatch in src/config.rs - Add #[non_exhaustive] to all nine stage and sub-stage patch types --- src/config.rs | 1 + src/effects/alien.rs | 1 + src/effects/punch.rs | 1 + src/effects/reverb.rs | 1 + src/effects/warm.rs | 1 + src/formant.rs | 1 + src/harmony.rs | 1 + src/pitch.rs | 1 + src/resynthesis.rs | 2 ++ 9 files changed, 10 insertions(+) diff --git a/src/config.rs b/src/config.rs index e0c8d21..825432b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -333,6 +333,7 @@ pub struct ControlActivity { /// the processor. Validation examines only the supplied stages and fields /// before any state changes. #[derive(Clone, Copy, Debug, Default, PartialEq)] +#[non_exhaustive] #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), derive(serde::Serialize, serde::Deserialize, tsify::Tsify), diff --git a/src/effects/alien.rs b/src/effects/alien.rs index 9440e9d..407dc89 100644 --- a/src/effects/alien.rs +++ b/src/effects/alien.rs @@ -66,6 +66,7 @@ pub(crate) fn validate_loop_frames(loop_frames: u32) -> Result<(), Error> { /// /// Each `None` field keeps its active value on the processor. #[derive(Clone, Copy, Debug, Default, PartialEq)] +#[non_exhaustive] #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), derive(serde::Serialize, serde::Deserialize, tsify::Tsify), diff --git a/src/effects/punch.rs b/src/effects/punch.rs index 57985f8..14914e0 100644 --- a/src/effects/punch.rs +++ b/src/effects/punch.rs @@ -121,6 +121,7 @@ pub(crate) fn validate_attack_ms(attack_ms: f32) -> Result<(), Error> { /// /// Each `None` field keeps its active value on the processor. #[derive(Clone, Copy, Debug, Default, PartialEq)] +#[non_exhaustive] #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), derive(serde::Serialize, serde::Deserialize, tsify::Tsify), diff --git a/src/effects/reverb.rs b/src/effects/reverb.rs index aed6865..e1f5d59 100644 --- a/src/effects/reverb.rs +++ b/src/effects/reverb.rs @@ -139,6 +139,7 @@ pub(crate) fn validate_brightness_hz(brightness_hz: f32) -> Result<(), Error> { /// /// Each `None` field keeps its active value on the processor. #[derive(Clone, Copy, Debug, Default, PartialEq)] +#[non_exhaustive] #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), derive(serde::Serialize, serde::Deserialize, tsify::Tsify), diff --git a/src/effects/warm.rs b/src/effects/warm.rs index aec4ff5..b437c88 100644 --- a/src/effects/warm.rs +++ b/src/effects/warm.rs @@ -61,6 +61,7 @@ pub(crate) fn validate_drive_db(drive_db: f32) -> Result<(), Error> { /// /// Each `None` field keeps its active value on the processor. #[derive(Clone, Copy, Debug, Default, PartialEq)] +#[non_exhaustive] #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), derive(serde::Serialize, serde::Deserialize, tsify::Tsify), diff --git a/src/formant.rs b/src/formant.rs index f9c49b8..2f211d8 100644 --- a/src/formant.rs +++ b/src/formant.rs @@ -138,6 +138,7 @@ pub(crate) fn validate_aspiration_cutoff_hz(aspiration_cutoff_hz: f32) -> Result /// /// Each `None` field keeps its active value on the processor. #[derive(Clone, Copy, Debug, Default, PartialEq)] +#[non_exhaustive] #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), derive(serde::Serialize, serde::Deserialize, tsify::Tsify), diff --git a/src/harmony.rs b/src/harmony.rs index bab67e5..3bd0872 100644 --- a/src/harmony.rs +++ b/src/harmony.rs @@ -452,6 +452,7 @@ pub(crate) fn validate_portamento_ms(portamento_ms: f32) -> Result<(), Error> { /// /// Each `None` field keeps its active value on the processor. #[derive(Clone, Copy, Debug, Default, PartialEq)] +#[non_exhaustive] #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), derive(serde::Serialize, serde::Deserialize, tsify::Tsify), diff --git a/src/pitch.rs b/src/pitch.rs index b6298ca..d5f95b7 100644 --- a/src/pitch.rs +++ b/src/pitch.rs @@ -122,6 +122,7 @@ fn check_frequency_order(min_frequency_hz: f32, max_frequency_hz: f32) -> Result /// Each `None` field keeps its active value on the processor. After a merge, /// `min_frequency_hz` must stay strictly below `max_frequency_hz`. #[derive(Clone, Copy, Debug, Default, PartialEq)] +#[non_exhaustive] #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), derive(serde::Serialize, serde::Deserialize, tsify::Tsify), diff --git a/src/resynthesis.rs b/src/resynthesis.rs index 2c7f13a..e817115 100644 --- a/src/resynthesis.rs +++ b/src/resynthesis.rs @@ -196,6 +196,7 @@ pub(crate) fn validate_flex_tune(flex_tune: f32) -> Result<(), Error> { /// /// Each `None` field keeps its active value on the processor. #[derive(Clone, Copy, Debug, Default, PartialEq)] +#[non_exhaustive] #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), derive(serde::Serialize, serde::Deserialize, tsify::Tsify), @@ -496,6 +497,7 @@ pub(crate) fn validate_dry_mix(dry_mix: f32) -> Result<(), Error> { /// /// Each `None` field keeps its active value on the processor. #[derive(Clone, Copy, Debug, Default, PartialEq)] +#[non_exhaustive] #[cfg_attr( all(feature = "wasm", target_arch = "wasm32"), derive(serde::Serialize, serde::Deserialize, tsify::Tsify), From 938dc3161bf172a702f497f2a07a3bd3274e7d55 Mon Sep 17 00:00:00 2001 From: "google-labs-stitch[bot]" <315546542+google-labs-stitch[bot]@users.noreply.github.com> Date: Thu, 26 Nov 2026 09:41:19 +0000 Subject: [PATCH 6/6] refactor(npm): remove redundant patch type re-exports - Remove the redundant export list of patch types from src/index.ts --- src/index.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/index.ts b/src/index.ts index 90592ec..4f6e6e1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,18 +12,6 @@ import init from "../pkg/tunelet.js"; import type { InitInput, InitOutput, Tunelet } from "../pkg/tunelet.js"; export * from "../pkg/tunelet.js"; -export type { - AlienConfigPatch, - CorrectionConfigPatch, - FormantConfigPatch, - HarmonyConfigPatch, - PitchConfigPatch, - ProcessorConfigPatch, - PunchConfigPatch, - ResynthesisConfigPatch, - ReverbConfigPatch, - WarmConfigPatch, -} from "../pkg/tunelet.js"; /** * Cached `Float32Array` views over the in-place `Tunelet` buffers in Wasm