MCPcopy Create free account
hub / github.com/alisomay/libpd-rs / open_close_patch

Function open_close_patch

tests/pd_open_close_patch.rs:7–90  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5
6#[test]
7fn open_close_patch() {
8 let mut pd = Pd::init_and_configure(0, 2, 44100).unwrap();
9 let ctx = pd.audio_context();
10
11 assert!(pd.open_patch("tests/patches/sine.pd").is_ok());
12
13 // Re-opens.
14 assert!(pd.open_patch("tests/patches/sine.pd").is_ok());
15 assert!(pd.close_patch().is_ok());
16
17 assert!(pd.open_patch("non existent").is_err());
18
19 // Runs osc~ on 440Hz.
20 assert!(pd
21 .eval_patch(
22 r#"
23 #N canvas 577 549 158 168 12;
24 #X obj 23 116 dac~;
25 #X obj 23 17 osc~ 440;
26 #X obj 23 66 *~ 0.1;
27 #X obj 81 67 *~ 0.1;
28 #X connect 1 0 2 0;
29 #X connect 1 0 3 0;
30 #X connect 2 0 0 0;
31 #X connect 3 0 0 1;
32 "#,
33 )
34 .is_ok());
35
36 assert!(pd.dollar_zero().is_ok());
37
38 let output_channels = pd.output_channels();
39 let sample_rate = pd.sample_rate();
40
41 pd.activate_audio(true).unwrap();
42
43 let sum = std::sync::Arc::new(std::sync::atomic::AtomicI32::new(0));
44
45 let (tx, rx) = mpsc::channel::<()>();
46
47 let sum_clone = sum.clone();
48
49 let handle = std::thread::spawn(move || {
50 // Mimic audio callback buffers.
51 let input_buffer = [0.0f32; 512];
52 let mut output_buffer = [0.0f32; 1024];
53
54 // Run pd
55 loop {
56 // Mimic an audio callback.
57 let approximate_buffer_duration =
58 (output_buffer.len() as f32 / sample_rate as f32) * 1000.0;
59
60 std::thread::sleep(std::time::Duration::from_millis(
61 approximate_buffer_duration as u64,
62 ));
63
64 let ticks = output_buffer.len() as i32 / (block_size() * output_channels);

Callers

nothing calls this directly

Calls 6

block_sizeFunction · 0.85
audio_contextMethod · 0.80
output_channelsMethod · 0.80
sample_rateMethod · 0.80
activate_audioMethod · 0.80
process_floatMethod · 0.80

Tested by

no test coverage detected