remove Atom. almost there

This commit is contained in:
🪞👃🪞 2025-01-18 15:37:53 +01:00
parent dc7b713108
commit cf1fd5b45a
20 changed files with 539 additions and 739 deletions

View file

@ -349,66 +349,66 @@ impl Sampler {
}
///////////////////////////////////////////////////////////////////////////////////////////////////
type MidiSample = (Option<u7>, Arc<RwLock<crate::Sample>>);
from_atom!("sampler" => |jack: &Arc<RwLock<JackConnection>>, args| -> crate::Sampler {
let mut name = String::new();
let mut dir = String::new();
let mut samples = BTreeMap::new();
atom!(atom in args {
Atom::Map(map) => {
if let Some(Atom::Str(n)) = map.get(&Atom::Key(":name")) {
name = String::from(*n);
}
if let Some(Atom::Str(n)) = map.get(&Atom::Key(":dir")) {
dir = String::from(*n);
}
},
Atom::List(args) => match args.first() {
Some(Atom::Symbol("sample")) => {
let (midi, sample) = MidiSample::from_atom((jack, &dir), &args[1..])?;
if let Some(midi) = midi {
samples.insert(midi, sample);
} else {
panic!("sample without midi binding: {}", sample.read().unwrap().name);
}
},
_ => panic!("unexpected in sampler {name}: {args:?}")
},
_ => panic!("unexpected in sampler {name}: {atom:?}")
});
Self::new(jack, &name)
});
from_atom!("sample" => |(_jack, dir): (&Arc<RwLock<JackConnection>>, &str), args| -> MidiSample {
let mut name = String::new();
let mut file = String::new();
let mut midi = None;
let mut start = 0usize;
atom!(atom in args {
Atom::Map(map) => {
if let Some(Atom::Str(n)) = map.get(&Atom::Key(":name")) {
name = String::from(*n);
}
if let Some(Atom::Str(f)) = map.get(&Atom::Key(":file")) {
file = String::from(*f);
}
if let Some(Atom::Int(i)) = map.get(&Atom::Key(":start")) {
start = *i as usize;
}
if let Some(Atom::Int(m)) = map.get(&Atom::Key(":midi")) {
midi = Some(u7::from(*m as u8));
}
},
_ => panic!("unexpected in sample {name}"),
});
let (end, data) = Sample::read_data(&format!("{dir}/{file}"))?;
Ok((midi, Arc::new(RwLock::new(crate::Sample {
name,
start,
end,
channels: data,
rate: None,
gain: 1.0
}))))
});
//from_atom!("sampler" => |jack: &Arc<RwLock<JackConnection>>, args| -> crate::Sampler {
//let mut name = String::new();
//let mut dir = String::new();
//let mut samples = BTreeMap::new();
//atom!(atom in args {
//Atom::Map(map) => {
//if let Some(Atom::Str(n)) = map.get(&Atom::Key(":name")) {
//name = String::from(*n);
//}
//if let Some(Atom::Str(n)) = map.get(&Atom::Key(":dir")) {
//dir = String::from(*n);
//}
//},
//Atom::List(args) => match args.first() {
//Some(Atom::Symbol("sample")) => {
//let (midi, sample) = MidiSample::from_atom((jack, &dir), &args[1..])?;
//if let Some(midi) = midi {
//samples.insert(midi, sample);
//} else {
//panic!("sample without midi binding: {}", sample.read().unwrap().name);
//}
//},
//_ => panic!("unexpected in sampler {name}: {args:?}")
//},
//_ => panic!("unexpected in sampler {name}: {atom:?}")
//});
//Self::new(jack, &name)
//});
//from_atom!("sample" => |(_jack, dir): (&Arc<RwLock<JackConnection>>, &str), args| -> MidiSample {
//let mut name = String::new();
//let mut file = String::new();
//let mut midi = None;
//let mut start = 0usize;
//atom!(atom in args {
//Atom::Map(map) => {
//if let Some(Atom::Str(n)) = map.get(&Atom::Key(":name")) {
//name = String::from(*n);
//}
//if let Some(Atom::Str(f)) = map.get(&Atom::Key(":file")) {
//file = String::from(*f);
//}
//if let Some(Atom::Int(i)) = map.get(&Atom::Key(":start")) {
//start = *i as usize;
//}
//if let Some(Atom::Int(m)) = map.get(&Atom::Key(":midi")) {
//midi = Some(u7::from(*m as u8));
//}
//},
//_ => panic!("unexpected in sample {name}"),
//});
//let (end, data) = Sample::read_data(&format!("{dir}/{file}"))?;
//Ok((midi, Arc::new(RwLock::new(crate::Sample {
//name,
//start,
//end,
//channels: data,
//rate: None,
//gain: 1.0
//}))))
//});
impl Iterator for Voice {
type Item = [f32;2];
fn next (&mut self) -> Option<Self::Item> {
@ -663,12 +663,12 @@ pub enum SamplerMode {
}
atom_command!(SamplerTuiCommand: |state: SamplerTui| {
("select" [i: usize] Self::Select(i.expect("no index")))
("import" [a, ..b] if let Some(command) = FileBrowserCommand::from_atom(state, a, b) {
("import" [,..a] if let Some(command) = FileBrowserCommand::try_from_expr(state, a) {
Self::Import(command)
} else {
return None
})
("sample" [a, ..b] if let Some(command) = SamplerCommand::from_atom(&state.state, a, b) {
("sample" [,..a] if let Some(command) = SamplerCommand::try_from_expr(&state.state, a) {
Self::Sample(command)
} else {
return None
@ -717,7 +717,7 @@ provide!(u7: |self: Sampler| {});
provide!(Option<Arc<RwLock<Sample>>>: |self: Sampler| {});
provide!(usize: |self: Sampler| {});
provide!(f32: |self: Sampler| {});
input_to_command!(FileBrowserCommand: |state:SamplerTui, input: Event|match input { _ => return None });
//input_to_command!(FileBrowserCommand: |state:SamplerTui, input: Event|match input { _ => return None });
command!(|self: FileBrowserCommand,state:SamplerTui|match self { _ => todo!() });
//input_to_command!(SamplerTuiCommand: |state: SamplerTui, input: Event|match state.mode{
//Some(SamplerMode::Import(..)) => Self::Import(