Clean up test formatting
This commit is contained in:
parent
477e94c7f6
commit
9b0d6d0e8c
@ -288,12 +288,58 @@ mod tests {
|
||||
let audio_output_buffer = &mut [0.0; BUFFER_SIZE];
|
||||
let click_output_buffer = &mut [0.0; BUFFER_SIZE];
|
||||
|
||||
// Macros for easier assertions
|
||||
macro_rules! assert_click {
|
||||
() => {
|
||||
assert!(
|
||||
click_output_buffer.iter().any(|f| *f == 1.0),
|
||||
"expected click"
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! assert_no_click {
|
||||
() => {
|
||||
assert!(
|
||||
click_output_buffer.iter().all(|f| *f == 0.0),
|
||||
"expected no click"
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! assert_out_all {
|
||||
($predicate:expr, $msg:literal) => {
|
||||
assert!(
|
||||
audio_output_buffer.iter().all(|f| *f == $predicate as f32),
|
||||
$msg
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! assert_out_any {
|
||||
($predicate:expr, $msg:literal) => {
|
||||
assert!(
|
||||
audio_output_buffer.iter().any(|f| *f == $predicate as f32),
|
||||
$msg
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! assert_track_state {
|
||||
($track:literal, $state:expr) => {
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[$track].current_state,
|
||||
$state
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
// Warm up, no commands here
|
||||
let mut last_frame_time = 0;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
let mut frame_time = 0;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -301,33 +347,19 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.all(|f| *f == last_frame_time as f32),
|
||||
"expected to hear the input signal"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().any(|f| *f == 1.0),
|
||||
"expected click"
|
||||
);
|
||||
assert_out_all!(frame_time, "input signal");
|
||||
assert_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 0);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Empty
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
TrackState::Empty
|
||||
);
|
||||
assert_track_state!(0, TrackState::Empty);
|
||||
assert_track_state!(1, TrackState::Empty);
|
||||
|
||||
// Press record
|
||||
last_frame_time = 10;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 10;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -335,33 +367,19 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.all(|f| *f == last_frame_time as f32),
|
||||
"expected to hear the input signal"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().all(|f| *f == 0.0),
|
||||
"expected no click"
|
||||
);
|
||||
assert_out_all!(frame_time, "input signal");
|
||||
assert_no_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 0);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Empty
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
TrackState::Empty
|
||||
);
|
||||
assert_track_state!(0, TrackState::Empty);
|
||||
assert_track_state!(1, TrackState::Empty);
|
||||
|
||||
// Record track (0, 0) starts
|
||||
last_frame_time = 20;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 20;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -369,33 +387,19 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.all(|f| *f == last_frame_time as f32),
|
||||
"expected to hear the input signal"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().any(|f| *f == 1.0),
|
||||
"expected click"
|
||||
);
|
||||
assert_out_all!(frame_time, "input signal");
|
||||
assert_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 0);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Recording { volume: 1.0 }
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
TrackState::Empty
|
||||
);
|
||||
assert_track_state!(0, TrackState::Recording { volume: 1.0 });
|
||||
assert_track_state!(1, TrackState::Empty);
|
||||
|
||||
// Record track (0, 0) first beat continues
|
||||
last_frame_time = 30;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 30;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -403,33 +407,19 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.all(|f| *f == last_frame_time as f32),
|
||||
"expected to hear the input signal"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().all(|f| *f == 0.0),
|
||||
"expected no click"
|
||||
);
|
||||
assert_out_all!(frame_time, "input signal");
|
||||
assert_no_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 0);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Recording { volume: 1.0 }
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
TrackState::Empty
|
||||
);
|
||||
assert_track_state!(0, TrackState::Recording { volume: 1.0 });
|
||||
assert_track_state!(1, TrackState::Empty);
|
||||
|
||||
// Record track (0, 0) begin second beat
|
||||
last_frame_time = 40;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 40;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -437,33 +427,19 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.all(|f| *f == last_frame_time as f32),
|
||||
"expected to hear the input signal"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().any(|f| *f == 1.0),
|
||||
"expected click"
|
||||
);
|
||||
assert_out_all!(frame_time, "input signal");
|
||||
assert_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 0);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Recording { volume: 1.0 }
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
TrackState::Empty
|
||||
);
|
||||
assert_track_state!(0, TrackState::Recording { volume: 1.0 });
|
||||
assert_track_state!(1, TrackState::Empty);
|
||||
|
||||
// Record track (0, 0) second beat continues
|
||||
last_frame_time = 50;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 50;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -471,33 +447,19 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.all(|f| *f == last_frame_time as f32),
|
||||
"expected to hear the input signal"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().all(|f| *f == 0.0),
|
||||
"expected no click"
|
||||
);
|
||||
assert_out_all!(frame_time, "input signal");
|
||||
assert_no_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 0);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Recording { volume: 1.0 }
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
TrackState::Empty
|
||||
);
|
||||
assert_track_state!(0, TrackState::Recording { volume: 1.0 });
|
||||
assert_track_state!(1, TrackState::Empty);
|
||||
|
||||
// Record track (0, 0) second beat continues
|
||||
last_frame_time = 60;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 60;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -505,33 +467,19 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.all(|f| *f == last_frame_time as f32),
|
||||
"expected to hear the input signal"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().all(|f| *f == 0.0),
|
||||
"expected no click"
|
||||
);
|
||||
assert_out_all!(frame_time, "input signal");
|
||||
assert_no_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 0);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Recording { volume: 1.0 }
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
TrackState::Empty
|
||||
);
|
||||
assert_track_state!(0, TrackState::Recording { volume: 1.0 });
|
||||
assert_track_state!(1, TrackState::Empty);
|
||||
|
||||
// Record track (0, 0) 3rd beat starts
|
||||
last_frame_time = 70;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 70;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -539,33 +487,19 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.all(|f| *f == last_frame_time as f32),
|
||||
"expected to hear the input signal"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().any(|f| *f == 1.0),
|
||||
"expected click"
|
||||
);
|
||||
assert_out_all!(frame_time, "input signal");
|
||||
assert_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 0);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Recording { volume: 1.0 }
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
TrackState::Empty
|
||||
);
|
||||
assert_track_state!(0, TrackState::Recording { volume: 1.0 });
|
||||
assert_track_state!(1, TrackState::Empty);
|
||||
|
||||
// Press record end
|
||||
last_frame_time = 80;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 80;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -573,33 +507,19 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.all(|f| *f == last_frame_time as f32),
|
||||
"expected to hear the input signal"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().all(|f| *f == 0.0),
|
||||
"expected no click"
|
||||
);
|
||||
assert_out_all!(frame_time, "input signal");
|
||||
assert_no_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 0);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Recording { volume: 1.0 }
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
TrackState::Empty
|
||||
);
|
||||
assert_track_state!(0, TrackState::Recording { volume: 1.0 });
|
||||
assert_track_state!(1, TrackState::Empty);
|
||||
|
||||
// Track (0, 0) stops recording, starts playing first beat
|
||||
last_frame_time = 90;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 90;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -607,39 +527,20 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == last_frame_time as f32),
|
||||
"expected to hear the input signal for the first part"
|
||||
);
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 20.0),
|
||||
"expected to hear the input + recording started at frame 24"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().any(|f| *f == 1.0),
|
||||
"expected click"
|
||||
);
|
||||
assert_out_any!(frame_time, "input signal for the first part");
|
||||
assert_out_any!(frame_time + 20, "input + recording started at frame 24");
|
||||
assert_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 0);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Playing
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
TrackState::Empty
|
||||
);
|
||||
assert_track_state!(0, TrackState::Playing);
|
||||
assert_track_state!(1, TrackState::Empty);
|
||||
|
||||
// Press down
|
||||
last_frame_time = 100;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 100;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -647,39 +548,20 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 30.0),
|
||||
"expected to hear the input + recording started at frame 24, second buffer"
|
||||
);
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 40.0),
|
||||
"expected to hear the input + recording started at frame 24, 3rd buffer"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().all(|f| *f == 0.0),
|
||||
"expected no click"
|
||||
);
|
||||
assert_out_any!(frame_time + 30, "input + recording second buffer");
|
||||
assert_out_any!(frame_time + 40, "input + recording 3rd buffer");
|
||||
assert_no_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 1);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Playing
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
TrackState::Empty
|
||||
);
|
||||
assert_track_state!(0, TrackState::Playing);
|
||||
assert_track_state!(1, TrackState::Empty);
|
||||
|
||||
// Press record
|
||||
last_frame_time = 110;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 110;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -687,39 +569,20 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 40.0),
|
||||
"expected to hear the input + recording started at frame 24, 3rd buffer"
|
||||
);
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 50.0),
|
||||
"expected to hear the input + recording started at frame 24, 4th buffer"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().all(|f| *f == 0.0),
|
||||
"expected no click"
|
||||
);
|
||||
assert_out_any!(frame_time + 40, "input + recording 3rd buffer");
|
||||
assert_out_any!(frame_time + 50, "input + recording 4th buffer");
|
||||
assert_no_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 1);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Playing
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
TrackState::Empty
|
||||
);
|
||||
assert_track_state!(0, TrackState::Playing);
|
||||
assert_track_state!(1, TrackState::Empty);
|
||||
|
||||
// Recording track (0, 1) starts recording at second column beat
|
||||
last_frame_time = 120;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 120;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -727,30 +590,14 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 50.0),
|
||||
"expected to hear the input + recording of first track"
|
||||
);
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 60.0),
|
||||
"expected to hear the input + recording of first track"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().any(|f| *f == 1.0),
|
||||
"expected click"
|
||||
);
|
||||
assert_out_any!(frame_time + 50, "input + recording of first track");
|
||||
assert_out_any!(frame_time + 60, "input + recording of first track");
|
||||
assert_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 1);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Playing
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
assert_track_state!(0, TrackState::Playing);
|
||||
assert_track_state!(
|
||||
1,
|
||||
TrackState::RecordingAutoStop {
|
||||
volume: 1.0,
|
||||
target_samples: 72,
|
||||
@ -759,11 +606,11 @@ mod tests {
|
||||
);
|
||||
|
||||
// Recording track (0, 1) continues recording
|
||||
last_frame_time = 130;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 130;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -771,30 +618,14 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 60.0),
|
||||
"expected to hear the input + recording of first track"
|
||||
);
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 70.0),
|
||||
"expected to hear the input + recording of first track"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().all(|f| *f == 0.0),
|
||||
"expected no click"
|
||||
);
|
||||
assert_out_any!(frame_time + 60, "input + recording of first track");
|
||||
assert_out_any!(frame_time + 70, "input + recording of first track");
|
||||
assert_no_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 1);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Playing
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
assert_track_state!(0, TrackState::Playing);
|
||||
assert_track_state!(
|
||||
1,
|
||||
TrackState::RecordingAutoStop {
|
||||
volume: 1.0,
|
||||
target_samples: 72,
|
||||
@ -803,11 +634,11 @@ mod tests {
|
||||
);
|
||||
|
||||
// Track (0, 1) records for second beat, column is at 3rd beat
|
||||
last_frame_time = 140;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 140;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -815,30 +646,14 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 70.0),
|
||||
"expected to hear the input + recording of first track"
|
||||
);
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 80.0),
|
||||
"expected to hear the input + recording of first track"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().any(|f| *f == 1.0),
|
||||
"expected click"
|
||||
);
|
||||
assert_out_any!(frame_time + 70, "input + recording of first track");
|
||||
assert_out_any!(frame_time + 80, "input + recording of first track");
|
||||
assert_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 1);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Playing
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
assert_track_state!(0, TrackState::Playing);
|
||||
assert_track_state!(
|
||||
1,
|
||||
TrackState::RecordingAutoStop {
|
||||
volume: 1.0,
|
||||
target_samples: 72,
|
||||
@ -847,11 +662,11 @@ mod tests {
|
||||
);
|
||||
|
||||
// Column beat 3 continues
|
||||
last_frame_time = 150;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 150;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -859,30 +674,14 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 80.0),
|
||||
"expected to hear the input + recording of first track"
|
||||
);
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 90.0),
|
||||
"expected to hear the input + recording of first track"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().all(|f| *f == 0.0),
|
||||
"expected no click"
|
||||
);
|
||||
assert_out_any!(frame_time + 80, "input + recording of first track");
|
||||
assert_out_any!(frame_time + 90, "input + recording of first track");
|
||||
assert_no_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 1);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Playing
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
assert_track_state!(0, TrackState::Playing);
|
||||
assert_track_state!(
|
||||
1,
|
||||
TrackState::RecordingAutoStop {
|
||||
volume: 1.0,
|
||||
target_samples: 72,
|
||||
@ -891,11 +690,11 @@ mod tests {
|
||||
);
|
||||
|
||||
// Column wraps to first beat, track (0, 1) records 3rd beat
|
||||
last_frame_time = 160;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 160;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -903,30 +702,14 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 90.0),
|
||||
"expected to hear the input + recording of first track"
|
||||
);
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 20.0),
|
||||
"expected to hear the input + recording of first track"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().any(|f| *f == 1.0),
|
||||
"expected click"
|
||||
);
|
||||
assert_out_any!(frame_time + 90, "input + recording of first track");
|
||||
assert_out_any!(frame_time + 20, "input + recording of first track");
|
||||
assert_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 1);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Playing
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
assert_track_state!(0, TrackState::Playing);
|
||||
assert_track_state!(
|
||||
1,
|
||||
TrackState::RecordingAutoStop {
|
||||
volume: 1.0,
|
||||
target_samples: 72,
|
||||
@ -935,11 +718,11 @@ mod tests {
|
||||
);
|
||||
|
||||
// Continue playback and recording
|
||||
last_frame_time = 170;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 170;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -947,24 +730,13 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 30.0),
|
||||
"expected to hear the input + recording of first track"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().all(|f| *f == 0.0),
|
||||
"expected no click"
|
||||
);
|
||||
assert_out_all!(frame_time + 30, "input + recording of first track");
|
||||
assert_no_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 1);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Playing
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
assert_track_state!(0, TrackState::Playing);
|
||||
assert_track_state!(
|
||||
1,
|
||||
TrackState::RecordingAutoStop {
|
||||
volume: 1.0,
|
||||
target_samples: 72,
|
||||
@ -973,11 +745,11 @@ mod tests {
|
||||
);
|
||||
|
||||
// Continue playback and recording
|
||||
last_frame_time = 180;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 180;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -985,24 +757,13 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 40.0),
|
||||
"expected to hear the input + recording of first track"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().all(|f| *f == 0.0),
|
||||
"expected no click"
|
||||
);
|
||||
assert_out_all!(frame_time + 40, "input + recording of first track");
|
||||
assert_no_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 1);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Playing
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
assert_track_state!(0, TrackState::Playing);
|
||||
assert_track_state!(
|
||||
1,
|
||||
TrackState::RecordingAutoStop {
|
||||
volume: 1.0,
|
||||
target_samples: 72,
|
||||
@ -1011,11 +772,11 @@ mod tests {
|
||||
);
|
||||
|
||||
// Recording track (0, 1) auto stops, mixed playback starts
|
||||
last_frame_time = 190;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 190;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -1023,32 +784,13 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 50.0),
|
||||
"expected to hear the input + recording of first track"
|
||||
);
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 50.0 + 120.0),
|
||||
"expected to hear the input + track (0, 0) + track (0, 1)"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().any(|f| *f == 1.0),
|
||||
"expected click"
|
||||
);
|
||||
assert_out_any!(frame_time + 50, "input + recording of first track");
|
||||
assert_out_any!(frame_time + 50 + 120, "input + track (0, 0) + track (0, 1)");
|
||||
assert_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 1);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Playing
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
TrackState::Playing
|
||||
);
|
||||
assert_track_state!(0, TrackState::Playing);
|
||||
assert_track_state!(1, TrackState::Playing);
|
||||
|
||||
// Process audio
|
||||
let prh_result =
|
||||
@ -1057,11 +799,11 @@ mod tests {
|
||||
assert!(prh_result.is_err(), "Expected timeout, got {prh_result:#?}");
|
||||
|
||||
// Playback consolidated
|
||||
last_frame_time = 200;
|
||||
let input = [last_frame_time as f32; BUFFER_SIZE];
|
||||
frame_time = 200;
|
||||
let input = [frame_time as f32; BUFFER_SIZE];
|
||||
let mut backend = MockAudioBackend {
|
||||
n_frames_val: BUFFER_SIZE as _,
|
||||
last_frame_time_val: last_frame_time,
|
||||
last_frame_time_val: frame_time,
|
||||
audio_input_buffer: &input,
|
||||
audio_output_buffer,
|
||||
click_output_buffer,
|
||||
@ -1069,25 +811,11 @@ mod tests {
|
||||
midi_output_events: vec![],
|
||||
};
|
||||
handler.process(&mut backend).unwrap();
|
||||
assert!(
|
||||
audio_output_buffer
|
||||
.iter()
|
||||
.any(|f| *f == (last_frame_time as f32) + 60.0 + 130.0),
|
||||
"expected to hear the input + track (0, 0) + track (0, 1)"
|
||||
);
|
||||
assert!(
|
||||
click_output_buffer.iter().all(|f| *f == 0.0),
|
||||
"expected no click"
|
||||
);
|
||||
assert_out_any!(frame_time + 60 + 130, "input + track (0, 0) + track (0, 1)");
|
||||
assert_no_click!();
|
||||
assert_eq!(handler.selected_column, 0);
|
||||
assert_eq!(handler.selected_row, 1);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[0].current_state,
|
||||
TrackState::Playing
|
||||
);
|
||||
assert_eq!(
|
||||
handler.track_matrix.columns[0].tracks[1].current_state,
|
||||
TrackState::Playing
|
||||
);
|
||||
assert_track_state!(0, TrackState::Playing);
|
||||
assert_track_state!(1, TrackState::Playing);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user