#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
pub mod capture;
pub mod effect_chain;
pub mod engine;
pub mod envelope;
pub mod error;
pub mod instrument;
#[cfg(feature = "io")]
pub mod io;
pub mod loop_mode;
pub mod sample;
pub mod sf2;
pub mod sfz;
pub mod stretch;
pub mod zone;
pub mod prelude {
pub use crate::capture::SampleRecorder;
pub use crate::effect_chain::{EffectChain, EffectType};
pub use crate::engine::{PolyMode, SamplerEngine, StealMode};
pub use crate::envelope::{AdsrConfig, AmpEnvelope, EnvState};
pub use crate::error::{NidhiError, Result};
pub use crate::instrument::Instrument;
pub use crate::loop_mode::LoopMode;
pub use crate::sample::{Sample, SampleBank, SampleId};
pub use crate::sf2::Sf2Preset;
pub use crate::sfz::SfzFile;
pub use crate::zone::{FilterMode, VelocityCurve, Zone};
}
#[cfg(test)]
mod assert_traits {
fn _assert_send_sync<T: Send + Sync>() {}
#[test]
fn public_types_are_send_sync() {
_assert_send_sync::<crate::error::NidhiError>();
_assert_send_sync::<crate::sample::Sample>();
_assert_send_sync::<crate::sample::SampleBank>();
_assert_send_sync::<crate::sf2::Sf2Preset>();
_assert_send_sync::<crate::zone::FilterMode>();
_assert_send_sync::<crate::zone::VelocityCurve>();
_assert_send_sync::<crate::zone::Zone>();
_assert_send_sync::<crate::instrument::Instrument>();
_assert_send_sync::<crate::engine::SamplerEngine>();
_assert_send_sync::<crate::capture::SampleRecorder>();
_assert_send_sync::<crate::effect_chain::EffectChain>();
_assert_send_sync::<crate::effect_chain::EffectType>();
_assert_send_sync::<crate::engine::PolyMode>();
_assert_send_sync::<crate::engine::StealMode>();
_assert_send_sync::<crate::engine::SamplerVoice>();
_assert_send_sync::<crate::envelope::AdsrConfig>();
_assert_send_sync::<crate::envelope::AmpEnvelope>();
_assert_send_sync::<crate::envelope::EnvState>();
_assert_send_sync::<crate::loop_mode::LoopMode>();
_assert_send_sync::<crate::sample::SampleId>();
_assert_send_sync::<crate::sfz::SfzFile>();
_assert_send_sync::<crate::sfz::SfzRegion>();
_assert_send_sync::<crate::stretch::StretchMode>();
_assert_send_sync::<crate::stretch::TimeStretcher>();
}
}
#[cfg(all(test, feature = "std"))]
mod serde_roundtrip {
fn roundtrip<T: serde::Serialize + serde::de::DeserializeOwned + core::fmt::Debug>(val: &T) {
let json = serde_json::to_string(val).expect("serialize");
let _back: T = serde_json::from_str(&json).expect("deserialize");
}
#[test]
fn all_public_types_roundtrip() {
use crate::prelude::*;
roundtrip(&EnvState::Idle);
roundtrip(&LoopMode::Forward);
roundtrip(&LoopMode::LoopSustain);
roundtrip(&FilterMode::HighPass);
roundtrip(&VelocityCurve::Concave);
roundtrip(&EffectType::Reverb);
roundtrip(&AdsrConfig::default());
roundtrip(&AdsrConfig::from_seconds(0.01, 0.1, 0.7, 0.3, 44100.0));
roundtrip(&AmpEnvelope::new(&AdsrConfig::default(), 44100.0));
let sample = Sample::from_mono(vec![0.1, 0.2, 0.3], 44100);
roundtrip(&sample);
roundtrip(&SampleId(42));
let mut bank = SampleBank::new();
let _ = bank.add(Sample::from_mono(vec![0.0; 10], 44100));
roundtrip(&bank);
let zone = Zone::new(SampleId(0))
.with_key_range(36, 84)
.with_vel_range(1, 127)
.with_root_note(60)
.with_tune(50.0)
.with_volume(-3.0)
.with_pan(0.5)
.with_loop(LoopMode::Forward, 100, 5000)
.with_crossfade(64)
.with_sample_offset(10)
.with_sample_end(9000)
.with_filter(2000.0, 0.5)
.with_filter_resonance(2.0)
.with_filter_type(FilterMode::LowPass)
.with_group(1)
.with_choke_group(1)
.with_velocity_curve(VelocityCurve::Convex)
.with_adsr(AdsrConfig::from_seconds(0.01, 0.1, 0.7, 0.3, 44100.0))
.with_filter_envelope(
AdsrConfig::from_seconds(0.05, 0.2, 0.5, 0.1, 44100.0),
2400.0,
)
.with_pitch_lfo(5.0, 50.0)
.with_filter_lfo(3.0, 600.0)
.with_key_tracking(0.5)
.with_time_stretch(1.5);
roundtrip(&zone);
let mut inst = Instrument::new("test_piano");
inst.add_zone(Zone::new(SampleId(0)).with_key_range(0, 127));
roundtrip(&inst);
let sfz = crate::sfz::parse("<region>\nsample=test.wav\n").unwrap();
roundtrip(&sfz);
roundtrip(&Sf2Preset {
name: "Piano".into(),
bank: 0,
preset_number: 0,
});
let rec = SampleRecorder::new(44100, 1);
roundtrip(&rec);
let chain = EffectChain::new(44100.0);
roundtrip(&chain);
let mut engine = SamplerEngine::new(8, 44100.0);
engine.set_adsr(AdsrConfig::from_seconds(0.01, 0.1, 0.7, 0.3, 44100.0));
roundtrip(&engine);
let stretcher = crate::stretch::TimeStretcher::new(vec![0.0; 100], 44100.0);
roundtrip(&stretcher);
}
}