handling sample loading errors gracefully
This commit is contained in:
parent
bc97d238ec
commit
cd2bbafcb6
3 changed files with 49 additions and 2 deletions
|
@ -597,6 +597,10 @@ impl Matrix {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn pop_error(&mut self) -> Option<String> {
|
||||||
|
self.config.pop_error()
|
||||||
|
}
|
||||||
|
|
||||||
/// Assign [SAtom] values to input parameters and atoms.
|
/// Assign [SAtom] values to input parameters and atoms.
|
||||||
pub fn set_param(&mut self, param: ParamId, at: SAtom) {
|
pub fn set_param(&mut self, param: ParamId, at: SAtom) {
|
||||||
self.config.set_param(param, at);
|
self.config.set_param(param, at);
|
||||||
|
|
|
@ -147,6 +147,9 @@ pub struct NodeConfigurator {
|
||||||
/// for nodes.
|
/// for nodes.
|
||||||
sample_lib: SampleLibrary,
|
sample_lib: SampleLibrary,
|
||||||
|
|
||||||
|
/// Error messages:
|
||||||
|
errors: Vec<String>,
|
||||||
|
|
||||||
/// Contains (automateable) parameters
|
/// Contains (automateable) parameters
|
||||||
params: std::collections::HashMap<ParamId, NodeInputParam>,
|
params: std::collections::HashMap<ParamId, NodeInputParam>,
|
||||||
/// Stores the most recently set parameter values
|
/// Stores the most recently set parameter values
|
||||||
|
@ -231,6 +234,7 @@ impl NodeConfigurator {
|
||||||
(NodeConfigurator {
|
(NodeConfigurator {
|
||||||
nodes,
|
nodes,
|
||||||
shared,
|
shared,
|
||||||
|
errors: vec![],
|
||||||
sample_lib: SampleLibrary::new(),
|
sample_lib: SampleLibrary::new(),
|
||||||
feedback_filter: FeedbackFilter::new(),
|
feedback_filter: FeedbackFilter::new(),
|
||||||
output_fb_values: vec![],
|
output_fb_values: vec![],
|
||||||
|
@ -277,6 +281,10 @@ impl NodeConfigurator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn pop_error(&mut self) -> Option<String> {
|
||||||
|
self.errors.pop()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn unique_index_for(&self, ni: &NodeId) -> Option<usize> {
|
pub fn unique_index_for(&self, ni: &NodeId) -> Option<usize> {
|
||||||
self.node2idx.get(&ni).copied()
|
self.node2idx.get(&ni).copied()
|
||||||
}
|
}
|
||||||
|
@ -299,8 +307,17 @@ impl NodeConfigurator {
|
||||||
pub fn set_param(&mut self, param: ParamId, at: SAtom) {
|
pub fn set_param(&mut self, param: ParamId, at: SAtom) {
|
||||||
if param.is_atom() {
|
if param.is_atom() {
|
||||||
let at =
|
let at =
|
||||||
if let SAtom::AudioSample((path, None)) = at {
|
if let SAtom::AudioSample((path, None)) = at.clone() {
|
||||||
self.sample_lib.load(&path).unwrap().clone()
|
match self.sample_lib.load(&path) {
|
||||||
|
Ok(sample) => sample.clone(),
|
||||||
|
Err(e) => {
|
||||||
|
self.errors.push(
|
||||||
|
format!(
|
||||||
|
"Couldn't load sample '{}': {:?}",
|
||||||
|
path, e));
|
||||||
|
at
|
||||||
|
},
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
at
|
at
|
||||||
};
|
};
|
||||||
|
|
|
@ -1199,3 +1199,29 @@ fn check_node_sampl_reload() {
|
||||||
assert_eq!(fft[0], (441, 940));
|
assert_eq!(fft[0], (441, 940));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_node_sampl_load_err() {
|
||||||
|
let (node_conf, mut node_exec) = new_node_engine();
|
||||||
|
let mut matrix = Matrix::new(node_conf, 3, 3);
|
||||||
|
|
||||||
|
let smpl = NodeId::Sampl(0);
|
||||||
|
let out = NodeId::Out(0);
|
||||||
|
matrix.place(0, 0, Cell::empty(smpl)
|
||||||
|
.out(None, None, smpl.out("sig")));
|
||||||
|
matrix.place(0, 1, Cell::empty(out)
|
||||||
|
.input(out.inp("ch1"), None, None));
|
||||||
|
matrix.sync().unwrap();
|
||||||
|
|
||||||
|
let sample_p = smpl.inp_param("sample").unwrap();
|
||||||
|
let freq_p = smpl.inp_param("freq").unwrap();
|
||||||
|
matrix.set_param(sample_p, SAtom::audio_unloaded("tests/sample_NOSIN.wav"));
|
||||||
|
|
||||||
|
let (rms, min, max) = run_and_get_l_rms_mimax(&mut node_exec, 50.0);
|
||||||
|
assert_float_eq!(rms, 0.0);
|
||||||
|
assert_float_eq!(min, 0.0);
|
||||||
|
assert_float_eq!(max, 0.0);
|
||||||
|
|
||||||
|
let err = matrix.pop_error();
|
||||||
|
assert_eq!(err.unwrap(), "Couldn't load sample 'tests/sample_NOSIN.wav': LoadError(IoError(Os { code: 2, kind: NotFound, message: \"No such file or directory\" }))");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue