Implemented more MidiP tests

This commit is contained in:
Weird Constructor 2022-08-12 18:57:42 +02:00
parent 2e1c006d8d
commit e46802870a
2 changed files with 97 additions and 0 deletions

View file

@ -335,6 +335,20 @@ pub fn collect_signal_changes(inp: &[f32], thres: i64) -> Vec<(usize, i64)> {
return idxs_big; return idxs_big;
} }
#[allow(dead_code)]
pub fn collect_signal_changes_flt(inp: &[f32], delta: f32) -> Vec<(usize, f32)> {
let mut idxs = vec![];
let mut last_sig = 0.0;
for i in 0..inp.len() {
if (inp[i] - last_sig).abs() > delta {
idxs.push((i, inp[i]));
last_sig = inp[i];
}
}
return idxs;
}
#[allow(dead_code)] #[allow(dead_code)]
pub fn collect_non_zero(inp: &[f32]) -> Vec<(usize, usize)> { pub fn collect_non_zero(inp: &[f32]) -> Vec<(usize, usize)> {
let mut idxs = vec![]; let mut idxs = vec![];

View file

@ -39,3 +39,86 @@ fn check_node_midip_gate_inserts() {
] ]
); );
} }
#[test]
fn check_node_midip_pitch_track() {
let (node_conf, mut node_exec) = new_node_engine();
let mut matrix = Matrix::new(node_conf, 3, 3);
// Create a DSP matrix with a "MidiP" node and an Out node:
let mut chain = MatrixCellChain::new(CellDir::B);
chain.node_out("midip", "freq").node_inp("out", "ch1").place(&mut matrix, 0, 0).unwrap();
matrix.sync().unwrap();
// Test run for 5ms with 3 Note On events at sample positions
// 5, 10 and 130 in this block of samples:
let (ch1, _) = node_exec.test_run(
0.005,
false,
vec![
HxTimedEvent::note_on(5, 0, 69, 1.0),
HxTimedEvent::note_on(10, 0, 68, 1.0),
HxTimedEvent::note_on(130, 0, 57, 1.0),
],
);
let changes = collect_signal_changes_flt(&ch1[..], 0.01);
assert_eq!(changes, vec![(0, -0.575), (5, 0.0), (130, -0.1)]);
}
#[test]
fn check_node_midip_pitch_det() {
let (node_conf, mut node_exec) = new_node_engine();
let mut matrix = Matrix::new(node_conf, 3, 3);
// Create a DSP matrix with a "MidiP" node and an Out node:
let mut chain = MatrixCellChain::new(CellDir::B);
chain
.node_out("midip", "freq")
.set_denorm("det", 0.1)
.node_inp("out", "ch1")
.place(&mut matrix, 0, 0)
.unwrap();
matrix.sync().unwrap();
// Test run for 5ms with 3 Note On events at sample positions
// 5, 10 and 130 in this block of samples:
let (ch1, _) = node_exec.test_run(
0.005,
false,
vec![
HxTimedEvent::note_on(5, 0, 69, 1.0),
HxTimedEvent::note_on(10, 0, 68, 1.0),
HxTimedEvent::note_on(130, 0, 57, 1.0),
],
);
let changes = collect_signal_changes_flt(&ch1[..], 0.01);
assert_eq!(changes, vec![(0, -0.475), (5, 0.1), (130, 0.0)]);
}
#[test]
fn check_node_midip_vel_track() {
let (node_conf, mut node_exec) = new_node_engine();
let mut matrix = Matrix::new(node_conf, 3, 3);
// Create a DSP matrix with a "MidiP" node and an Out node:
let mut chain = MatrixCellChain::new(CellDir::B);
chain.node_out("midip", "vel").node_inp("out", "ch1").place(&mut matrix, 0, 0).unwrap();
matrix.sync().unwrap();
// Test run for 5ms with 3 Note On events at sample positions
// 5, 10 and 130 in this block of samples:
let (ch1, _) = node_exec.test_run(
0.005,
false,
vec![
HxTimedEvent::note_on(5, 0, 69, 0.4),
HxTimedEvent::note_on(10, 0, 68, 1.0),
HxTimedEvent::note_on(130, 0, 57, 0.6),
],
);
let changes = collect_signal_changes_flt(&ch1[..], 0.01);
assert_eq!(changes, vec![(5, 0.4), (10, 1.0), (130, 0.6)]);
}