samples in main

This commit is contained in:
🪞👃🪞 2024-06-29 16:29:20 +03:00
parent 15f71d0973
commit fad0caef88
3 changed files with 30 additions and 45 deletions

View file

@ -16,10 +16,10 @@ impl Voice {
}
pub struct Sample {
name: String,
start: usize,
end: usize,
channels: Vec<Vec<f32>>,
pub name: String,
pub start: usize,
pub end: usize,
pub channels: Vec<Vec<f32>>,
}
impl Sample {
fn new (name: &str) -> Arc<Self> {
@ -41,49 +41,15 @@ pub struct Sampler {
}
impl Sampler {
pub fn new (name: &str) -> Result<DynamicDevice<Self>, Box<dyn Error>> {
pub fn new (
name: &str,
samples: Option<BTreeMap<u7, Arc<Sample>>>,
) -> Result<DynamicDevice<Self>, Box<dyn Error>> {
let (client, _) = Client::new(name, ClientOptions::NO_START_SERVER)?;
DynamicDevice::new(render, handle, Self::process, Self {
name: name.into(),
cursor: (0, 0),
samples: BTreeMap::from([
(u7::from_int_lossy(35), Sample {
name: "Kick 1".into(),
start: 0,
end: 100000,
channels: vec![],
}.into()),
(u7::from_int_lossy(36).into(), Sample {
name: "Kick 2".into(),
start: 0,
end: 100000,
channels: vec![],
}.into()),
(u7::from_int_lossy(38).into(), Sample {
name: "Snare 1".into(),
start: 0,
end: 100000,
channels: vec![],
}.into()),
(u7::from_int_lossy(40).into(), Sample {
name: "Snare 2".into(),
start: 50000,
end: 100000,
channels: vec![],
}.into()),
(u7::from_int_lossy(42).into(), Sample {
name: "HH Closed".into(),
start: 0,
end: 50000,
channels: vec![],
}.into()),
(u7::from_int_lossy(46).into(), Sample {
name: "HH Open".into(),
start: 0,
end: 25000,
channels: vec![]
}.into()),
]),
samples: samples.unwrap_or(BTreeMap::new()),
voices: vec![],
midi_in: client.register_port("midi", ::jack::MidiIn::default())?,
audio_ins: vec![