#[derive(Clone, Debug)]
pub struct AudioSequence {
pub start: f32,
pub end: f32,
pub bpm: f32,
pub steps_per_beat: u8,
pub base_pattern: Vec<f32>,
pub accents: Vec<f32>,
pub transpositions: Vec<f32>,
pub root_freq: f32,
pub fade_in: f32,
pub fade_out: f32,
}
impl AudioSequence {
pub fn new(start: f32, end: f32, bpm: f32) -> Self {
Self {
start,
end,
bpm,
steps_per_beat: 4, base_pattern: vec![1.0; 16],
accents: vec![0.0; 16],
transpositions: vec![1.0],
root_freq: 55.0,
fade_in: 0.0,
fade_out: 0.0,
}
}
pub fn with_fades(mut self, fade_in: f32, fade_out: f32) -> Self {
self.fade_in = fade_in;
self.fade_out = fade_out;
self
}
pub fn with_pattern(mut self, pattern: Vec<f32>) -> Self {
self.base_pattern = pattern;
self
}
pub fn with_accents(mut self, accents: Vec<f32>) -> Self {
self.accents = accents;
self
}
pub fn with_transpositions(mut self, trans: Vec<f32>) -> Self {
self.transpositions = trans;
self
}
pub fn with_root(mut self, freq: f32) -> Self {
self.root_freq = freq;
self
}
pub fn with_steps_per_beat(mut self, steps: u8) -> Self {
self.steps_per_beat = steps;
self
}
pub fn step_duration(&self) -> f32 {
60.0 / (self.bpm * self.steps_per_beat as f32)
}
pub fn num_steps(&self) -> usize {
self.base_pattern.len()
}
}