Executable tutorial fixtures
examples/tutorials/tests/walkthroughs.rs · 134 source lines
Read the chapters in source order. Select a numbered source line to expand its explanation; the line numbers and code match this snapshot exactly.
cargo test -p ravet-examples --test walkthroughs --no-default-features --lockedChapters
Isolate executable output files
A temporary fixture directory is uniquely named and removed on Drop. run invokes the compiled tutorial binaries with explicit --render or --offline arguments and checks success; read decodes the produced stereo WAV with bounded worker scratch.
1use ravet_audio_file::{WaveEncoding, WaveReader};
Bring these module/type names into scope for “Isolate executable output files”; the surrounding chapter explains their responsibilities.
Link to line 12use std::{
Bring these module/type names into scope for “Isolate executable output files”; the surrounding chapter explains their responsibilities.
Link to line 23 fs::File,
Define or initialize fs with the displayed type/value. Its ownership and use are described in “Isolate executable output files”.
Link to line 34 path::PathBuf,
Define or initialize path with the displayed type/value. Its ownership and use are described in “Isolate executable output files”.
Link to line 45 process::Command,
Define or initialize process with the displayed type/value. Its ownership and use are described in “Isolate executable output files”.
Link to line 56 sync::atomic::{AtomicUsize, Ordering},
Define or initialize sync with the displayed type/value. Its ownership and use are described in “Isolate executable output files”.
Link to line 67};
Close the surrounding scope, value or argument list in “Isolate executable output files”.
Link to line 78
Blank line separating the surrounding statements.
Link to line 89struct Scratch(PathBuf);
Declare the state/type or implementation used by this chapter. A temporary fixture directory is uniquely named and removed on Drop. run invokes the compiled tutorial binaries with explicit --render or --offline arguments and checks success; read decodes the produced stereo WAV with bounded worker scratch.
Link to line 910impl Scratch {
Declare the state/type or implementation used by this chapter. A temporary fixture directory is uniquely named and removed on Drop. run invokes the compiled tutorial binaries with explicit --render or --offline arguments and checks success; read decodes the produced stereo WAV with bounded worker scratch.
Link to line 1011 fn new() -> Self {
Define new. A temporary fixture directory is uniquely named and removed on Drop. run invokes the compiled tutorial binaries with explicit --render or --offline arguments and checks success; read decodes the produced stereo WAV with bounded worker scratch.
Link to line 1112 static NEXT: AtomicUsize = AtomicUsize::new(0);
Call the displayed operation with these arguments as the next step in “Isolate executable output files”. The chapter describes its role and validation.
Link to line 1213 let path = std::env::temp_dir().join(format!(
Bind path to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.
Link to line 1314 "ravet-examples-{}-{}",
Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Isolate executable output files” explanation above.
Link to line 1415 std::process::id(),
Define or initialize std with the displayed type/value. Its ownership and use are described in “Isolate executable output files”.
Link to line 1516 NEXT.fetch_add(1, Ordering::Relaxed)
Atomically increment this counter and retain the requested synchronization ordering.
Link to line 1617 ));
Close the current expression or scope; no additional processing operation occurs on this line.
Link to line 1718 std::fs::create_dir(&path).unwrap();
Define or initialize std with the displayed type/value. Its ownership and use are described in “Isolate executable output files”.
Link to line 1819 Self(path)
Call the displayed operation with these arguments as the next step in “Isolate executable output files”. The chapter describes its role and validation.
Link to line 1920 }
Close the surrounding scope, value or argument list in “Isolate executable output files”.
Link to line 2021}
Close the surrounding scope, value or argument list in “Isolate executable output files”.
Link to line 2122impl Drop for Scratch {
Declare the state/type or implementation used by this chapter. A temporary fixture directory is uniquely named and removed on Drop. run invokes the compiled tutorial binaries with explicit --render or --offline arguments and checks success; read decodes the produced stereo WAV with bounded worker scratch.
Link to line 2223 fn drop(&mut self) {
Define drop. A temporary fixture directory is uniquely named and removed on Drop. run invokes the compiled tutorial binaries with explicit --render or --offline arguments and checks success; read decodes the produced stereo WAV with bounded worker scratch.
Link to line 2324 std::fs::remove_dir_all(&self.0).unwrap();
Define or initialize std with the displayed type/value. Its ownership and use are described in “Isolate executable output files”.
Link to line 2425 }
Close the surrounding scope, value or argument list in “Isolate executable output files”.
Link to line 2526}
Close the surrounding scope, value or argument list in “Isolate executable output files”.
Link to line 2627
Blank line separating the surrounding statements.
Link to line 2728fn run(binary: &str, path: Option<&std::path::Path>) -> String {
Define run. A temporary fixture directory is uniquely named and removed on Drop. run invokes the compiled tutorial binaries with explicit --render or --offline arguments and checks success; read decodes the produced stereo WAV with bounded worker scratch.
Link to line 2829 let mut command = Command::new(binary);
Bind mutable command to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.
Link to line 2930 if let Some(path) = path {
Evaluate this condition or visit this range in source order. The statements in the following scope implement “Isolate executable output files”.
Link to line 3031 command.arg("--render").arg(path);
Call the displayed operation with these arguments as the next step in “Isolate executable output files”. The chapter describes its role and validation.
Link to line 3132 } else {
Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Isolate executable output files” explanation above.
Link to line 3233 command.arg("--offline");
Call the displayed operation with these arguments as the next step in “Isolate executable output files”. The chapter describes its role and validation.
Link to line 3334 }
Close the surrounding scope, value or argument list in “Isolate executable output files”.
Link to line 3435 let output = command.output().unwrap();
Bind output to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.
Link to line 3536 assert!(
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 3637 output.status.success(),
Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Isolate executable output files” explanation above.
Link to line 3738 "{}",
Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Isolate executable output files” explanation above.
Link to line 3839 String::from_utf8_lossy(&output.stderr)
Define or initialize String with the displayed type/value. Its ownership and use are described in “Isolate executable output files”.
Link to line 3940 );
Close the current expression or scope; no additional processing operation occurs on this line.
Link to line 4041 String::from_utf8(output.stdout).unwrap()
Define or initialize String with the displayed type/value. Its ownership and use are described in “Isolate executable output files”.
Link to line 4142}
Close the surrounding scope, value or argument list in “Isolate executable output files”.
Link to line 4243
Blank line separating the surrounding statements.
Link to line 4344fn read(path: &std::path::Path, frames: usize) -> Vec<f32> {
Define read. A temporary fixture directory is uniquely named and removed on Drop. run invokes the compiled tutorial binaries with explicit --render or --offline arguments and checks success; read decodes the produced stereo WAV with bounded worker scratch.
Link to line 4445 let mut reader = WaveReader::new(File::open(path).unwrap(), 256).unwrap();
Bind mutable reader to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.
Link to line 4546 assert_eq!(reader.format().channels, 2);
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 4647 assert_eq!(reader.format().sample_rate, 48_000);
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 4748 assert_eq!(reader.format().encoding, WaveEncoding::Pcm16);
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 4849 assert_eq!(reader.frames(), frames as u64);
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 4950 let mut audio = Vec::new();
Bind mutable audio to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.
Link to line 5051 let mut block = [0.; 512];
Bind mutable block to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.
Link to line 5152 loop {
Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Isolate executable output files” explanation above.
Link to line 5253 let count = reader.read_frames(&mut block).unwrap();
Bind count to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.
Link to line 5354 if count == 0 {
Evaluate this condition or visit this range in source order. The statements in the following scope implement “Isolate executable output files”.
Link to line 5455 break;
End the nearest loop when its bounded work or input condition is complete.
Link to line 5556 }
Close the surrounding scope, value or argument list in “Isolate executable output files”.
Link to line 5657 audio.extend_from_slice(&block[..2 * count]);
Call the displayed operation with these arguments as the next step in “Isolate executable output files”. The chapter describes its role and validation.
Link to line 5758 }
Close the surrounding scope, value or argument list in “Isolate executable output files”.
Link to line 5859 assert_eq!(audio.len(), frames * 2);
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 5960 audio
Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Isolate executable output files” explanation above.
Link to line 6061}
Close the surrounding scope, value or argument list in “Isolate executable output files”.
Link to line 6162
Blank line separating the surrounding statements.
Link to line 6263#[test]
Apply this Rust attribute to the following item. cfg selects which target/feature/test build contains it; derive generates the named trait implementations.
Link to line 63Test the rendered synth clip
Launch the synth executable, verify silence before scheduled notes and note/pedal/release behavior, and confirm the complete output frame count. This exercises the actual executable/helper path, not just a mock processor call.
64fn synth_renders_timed_notes_pedal_hold_and_complete_release() {
Define synth_renders_timed_notes_pedal_hold_and_complete_release. Launch the synth executable, verify silence before scheduled notes and note/pedal/release behavior, and confirm the complete output frame count. This exercises the actual executable/helper path, not just a mock processor call.
Link to line 6465 let scratch = Scratch::new();
Bind scratch to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.
Link to line 6566 let path = scratch.0.join("nested/synth.wav");
Bind path to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.
Link to line 6667 run(env!("CARGO_BIN_EXE_midi-synth"), Some(&path));
Call the displayed operation with these arguments as the next step in “Test the rendered synth clip”. The chapter describes its role and validation.
Link to line 6768 let audio = read(&path, 72_000);
Bind audio to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.
Link to line 6869 assert!(
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 6970 audio
Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the rendered synth clip” explanation above.
Link to line 7071 .as_chunks::<2>()
Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the rendered synth clip” explanation above.
Link to line 7172 .0
Supply this literal numeric entry to the array or argument list being constructed. Its units/addressing follow the containing fixture or configuration.
Link to line 7273 .iter()
Borrow collection entries for iteration without moving or copying the whole collection.
Link to line 7374 .all(|frame| frame[0] == frame[1])
Call the displayed operation with these arguments as the next step in “Test the rendered synth clip”. The chapter describes its role and validation.
Link to line 7475 );
Close the current expression or scope; no additional processing operation occurs on this line.
Link to line 7576 assert!(audio[..2 * 2_400].iter().all(|v| *v == 0.));
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 7677 for (start, end) in [(3_000, 11_000), (17_000, 27_000), (47_000, 59_000)] {
Evaluate this condition or visit this range in source order. The statements in the following scope implement “Test the rendered synth clip”.
Link to line 7778 assert!(audio[2 * start..2 * end].iter().any(|v| v.abs() > 0.04));
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 7879 }
Close the surrounding scope, value or argument list in “Test the rendered synth clip”.
Link to line 7980 for (start, end) in [(14_500, 16_000), (30_500, 32_000), (62_500, 72_000)] {
Evaluate this condition or visit this range in source order. The statements in the following scope implement “Test the rendered synth clip”.
Link to line 8081 assert!(audio[2 * start..2 * end].iter().all(|v| *v == 0.));
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 8182 }
Close the surrounding scope, value or argument list in “Test the rendered synth clip”.
Link to line 8283 let original = std::fs::read(&path).unwrap();
Bind original to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.
Link to line 8384 assert!(
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 8485 !Command::new(env!("CARGO_BIN_EXE_midi-synth"))
Call the displayed operation with these arguments as the next step in “Test the rendered synth clip”. The chapter describes its role and validation.
Link to line 8586 .arg("--render")
Call the displayed operation with these arguments as the next step in “Test the rendered synth clip”. The chapter describes its role and validation.
Link to line 8687 .arg(&path)
Call the displayed operation with these arguments as the next step in “Test the rendered synth clip”. The chapter describes its role and validation.
Link to line 8788 .output()
Call the displayed operation with these arguments as the next step in “Test the rendered synth clip”. The chapter describes its role and validation.
Link to line 8889 .unwrap()
Call the displayed operation with these arguments as the next step in “Test the rendered synth clip”. The chapter describes its role and validation.
Link to line 8990 .status
Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the rendered synth clip” explanation above.
Link to line 9091 .success()
Call the displayed operation with these arguments as the next step in “Test the rendered synth clip”. The chapter describes its role and validation.
Link to line 9192 );
Close the current expression or scope; no additional processing operation occurs on this line.
Link to line 9293 assert_eq!(std::fs::read(&path).unwrap(), original);
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 9394}
Close the surrounding scope, value or argument list in “Test the rendered synth clip”.
Link to line 9495
Blank line separating the surrounding statements.
Link to line 9596#[test]
Apply this Rust attribute to the following item. cfg selects which target/feature/test build contains it; derive generates the named trait implementations.
Link to line 96Test the actual effect WAV
Launch the delay fixture and check cross-channel impulse timing, feedback decay and the exact sample-timed bypass result. A reader error or missing file fails the fixture.
97fn effect_renders_ping_pong_repeats_and_sample_timed_bypass() {
Define effect_renders_ping_pong_repeats_and_sample_timed_bypass. Launch the delay fixture and check cross-channel impulse timing, feedback decay and the exact sample-timed bypass result. A reader error or missing file fails the fixture.
Link to line 9798 let scratch = Scratch::new();
Bind scratch to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.
Link to line 9899 let path = scratch.0.join("effect.wav");
Bind path to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.
Link to line 99100 run(env!("CARGO_BIN_EXE_effect"), Some(&path));
Call the displayed operation with these arguments as the next step in “Test the actual effect WAV”. The chapter describes its role and validation.
Link to line 100101 let audio = read(&path, 96_000);
Bind audio to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.
Link to line 101102 for (frame, channel, value) in [
Evaluate this condition or visit this range in source order. The statements in the following scope implement “Test the actual effect WAV”.
Link to line 102103 (12000, 0, 0.5),
Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the actual effect WAV” explanation above.
Link to line 103104 (14400, 1, 0.25),
Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the actual effect WAV” explanation above.
Link to line 104105 (24000, 1, 0.25),
Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the actual effect WAV” explanation above.
Link to line 105106 (26400, 0, 0.125),
Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the actual effect WAV” explanation above.
Link to line 106107 (36000, 0, 0.125),
Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the actual effect WAV” explanation above.
Link to line 107108 (38400, 1, 0.0625),
Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the actual effect WAV” explanation above.
Link to line 108109 (48000, 1, 0.0625),
Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the actual effect WAV” explanation above.
Link to line 109110 ] {
Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test the actual effect WAV” explanation above.
Link to line 110111 assert!((audio[2 * frame + channel] - value).abs() < 0.00004);
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 111112 assert_eq!(audio[2 * frame + 1 - channel], 0.);
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 112113 }
Close the surrounding scope, value or argument list in “Test the actual effect WAV”.
Link to line 113114 assert!(audio[2 * 72007..2 * 73600].iter().all(|s| *s == 0.));
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 114115 assert!((audio[2 * 73600] - 0.125).abs() < 0.00004);
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 115116 assert!(audio[2 * 73600 + 1..].iter().all(|s| *s == 0.));
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 116117}
Close the surrounding scope, value or argument list in “Test the actual effect WAV”.
Link to line 117118
Blank line separating the surrounding statements.
Link to line 118119#[test]
Apply this Rust attribute to the following item. cfg selects which target/feature/test build contains it; derive generates the named trait implementations.
Link to line 119Test printed MPE and MIDI 2.0 traces
Run both explicit offline inspectors and assert their reports contain independent member/master expression and exact full-resolution MIDI 2.0 fields. These tests open neither a device nor a window.
120fn expression_walkthroughs_report_independent_mpe_and_lossless_midi2() {
Define expression_walkthroughs_report_independent_mpe_and_lossless_midi2. Run both explicit offline inspectors and assert their reports contain independent member/master expression and exact full-resolution MIDI 2.0 fields. These tests open neither a device nor a window.
Link to line 120121 let mpe = run(env!("CARGO_BIN_EXE_mpe"), None);
Bind mpe to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.
Link to line 121122 assert!(mpe.contains(
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 122123 "channel=1 key=60 Held: member_bend=12.0 master_bend=-2.0 pressure=0.787 timbre=0.504"
Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test printed MPE and MIDI 2.0 traces” explanation above.
Link to line 123124 ));
Close the current expression or scope; no additional processing operation occurs on this line.
Link to line 124125 assert!(mpe.contains(
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 125126 "channel=2 key=64 Held: member_bend=0.0 master_bend=-2.0 pressure=0.000 timbre=0.000"
Continue the surrounding value or expression with this exact operand. Read it together with the preceding statement and the “Test printed MPE and MIDI 2.0 traces” explanation above.
Link to line 126127 ));
Close the current expression or scope; no additional processing operation occurs on this line.
Link to line 127128 assert!(mpe.contains("channel=1 key=60 Released: member_bend=12.0 master_bend=0.0"));
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 128129 let midi2 = run(env!("CARGO_BIN_EXE_midi2"), None);
Bind midi2 to the expression on this and any following continuation lines. The chapter above explains how this intermediate value is used.
Link to line 129130 assert!(midi2.contains("frame=0 group=1 channel=2 words=[41923c00, abcd0000]"));
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 130131 assert!(midi2.contains("frame=17 group=1 channel=2 words=[41623c00, 91234567]"));
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 131132 assert!(midi2.contains("frame=17 group=1 channel=2 words=[41a23c00, deadbeef]"));
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 132133 assert!(midi2.contains("frame=48 group=1 channel=2 words=[41823c00, 12340000]"));
Verify the fixture’s expected result. A mismatch fails the test rather than becoming a successful support claim.
Link to line 133134}
Close the surrounding scope, value or argument list in “Test printed MPE and MIDI 2.0 traces”.
Link to line 134