use super::program::FxCall;
#[derive(Debug, Clone, PartialEq, Default)]
pub struct InstrumentDef {
pub name: String,
pub voice: Option<VoiceDef>,
pub lifecycle: Option<Lifecycle>,
pub tones: Vec<ToneDef>,
pub mix: Option<MixMode>,
pub amplitude: Option<EnvelopeDef>,
pub pitch: Option<EnvelopeDef>,
pub sample: Option<SampleDef>,
pub fx: Vec<FxCall>,
pub gain: Option<f64>,
pub velocity_sensitivity: Option<f64>,
pub base_frequency: Option<f64>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum VoiceDef {
Mono {
track_pitch: bool,
allocation: MonoAllocation,
},
Poly {
voices: u32,
allocation: PolyAllocation,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum MonoAllocation {
#[default]
Replace,
Drop,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum PolyAllocation {
#[default]
ReplaceOldest,
ReplaceYoungest,
ReplaceLoudest,
ReplaceQuietest,
ReplaceRandom,
Drop,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Lifecycle {
OneShot,
#[default]
Gated,
Cutoff,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum MixMode {
#[default]
Sum,
Multiply,
Max,
Average,
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ToneDef {
pub waveform: Waveform,
pub gain: Option<f64>,
pub frequency: Option<f64>,
pub relation: Option<Relation>,
pub envelope: Option<EnvelopeDef>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Waveform {
#[default]
Sine,
Square,
Saw,
Triangle,
SquareRaw,
SawRaw,
TriangleRaw,
Noise,
PinkNoise,
Blank,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Relation {
Identity,
Harmonic(u32),
Ratio(f64),
Offset(f64),
Semitones(i32),
Constant(f64),
}
#[derive(Debug, Clone, PartialEq)]
pub enum EnvelopeDef {
Adsr {
attack: f64,
decay: f64,
sustain: f64,
release: f64,
},
Single(SegmentDef),
Stages {
attack: Option<SegmentDef>,
decay: Option<SegmentDef>,
sustain: Option<SegmentDef>,
release: Option<SegmentDef>,
},
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum SegmentDef {
Linear {
from: f64,
to: f64,
duration: f64,
},
Bezier {
from: f64,
to: f64,
duration: f64,
control: (f64, f64),
},
Constant {
value: f64,
duration: Option<f64>,
},
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct SampleDef {
pub path: String,
pub root_midi: Option<u32>,
pub start_seconds: Option<f64>,
pub end_seconds: Option<f64>,
pub looped: bool,
}