Skip to content

Commit

Permalink
Use our own fork of libpd until the bug-fix merges
Browse files Browse the repository at this point in the history
  • Loading branch information
alisomay committed Apr 17, 2022
1 parent 021db8a commit e9e48fb
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
Cargo.lock
.vscode
src/main.rs
2 changes: 2 additions & 0 deletions src/convenience.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

use crate::error::{InitializationError, LibpdError};
use crate::send::{
add_float_to_started_message, finish_message_as_typed_message_and_send_to, start_message,
Expand Down
70 changes: 35 additions & 35 deletions tests/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,57 @@ use libpd_rs::{

#[test]
fn all_main_functionality() {
let x = init();
assert!(x.is_ok());
let x = init();
assert!(x.is_err());
let result = init();
assert!(result.is_ok());
let result = init();
assert!(result.is_err());

let x = initialize_audio(0, 2, 44100);
assert!(x.is_ok());
let x = initialize_audio(0, 1, 44100);
assert!(x.is_ok());
let result = initialize_audio(0, 2, 44100);
assert!(result.is_ok());
let result = initialize_audio(0, 1, 44100);
assert!(result.is_ok());

let x = open_patch("tests/patches/no_existent.pd");
assert!(x.is_err());
let x = open_patch("/bad_path");
assert!(x.is_err());
let x = open_patch("tests/patches/simple.pd");
assert!(x.is_ok());
let result = open_patch("tests/patches/no_eresultistent.pd");
assert!(result.is_err());
let result = open_patch("/bad_path");
assert!(result.is_err());
let result = open_patch("tests/patches/simple.pd");
assert!(result.is_ok());

let x = close_patch(x.unwrap());
assert!(x.is_ok());
let result = close_patch(result.unwrap());
assert!(result.is_ok());

let handle: PatchFileHandle = (std::ptr::null_mut() as *mut std::ffi::c_void).into();
let x = close_patch(handle);
assert!(x.is_err());
let result = close_patch(handle);
assert!(result.is_err());

let x = add_to_search_paths("tests/patches");
assert!(x.is_ok());
let x = add_to_search_paths("/bad_path");
assert!(x.is_err());
let result = add_to_search_paths("tests/patches");
assert!(result.is_ok());
let result = add_to_search_paths("/bad_path");
assert!(result.is_err());

clear_search_paths();
release_internal_queues();

let patch_handle = open_patch("tests/patches/simple.pd").unwrap();

let x = get_dollar_zero(&patch_handle);
assert!(x.is_ok());
assert_ne!(x.unwrap(), 0);
let result = get_dollar_zero(&patch_handle);
assert!(result.is_ok());
assert_ne!(result.unwrap(), 0);

let handle: PatchFileHandle = (std::ptr::null_mut() as *mut std::ffi::c_void).into();
let x = get_dollar_zero(&handle);
assert!(x.is_err());
let result = get_dollar_zero(&handle);
assert!(result.is_err());

let x = block_size();
assert_eq!(x, 64);
let result = block_size();
assert_eq!(result, 64);

let x = verbose_print_state_active();
assert!(!x);
let result = verbose_print_state_active();
assert!(!result);
verbose_print_state(true);
let x = verbose_print_state_active();
assert!(x);
let result = verbose_print_state_active();
assert!(result);
verbose_print_state(false);
let x = verbose_print_state_active();
assert!(!x);
let result = verbose_print_state_active();
assert!(!result);
}
1 change: 1 addition & 0 deletions tests/gui.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(clippy::restriction)]
#![allow(unused)]

use libpd_rs::gui::{poll_gui, start_gui, stop_gui};
use std::{env, path::PathBuf};
Expand Down
1 change: 0 additions & 1 deletion tests/send_and_receive_after_touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use libpd_rs::{
};

#[test]
#[ignore]
fn send_and_receive_after_touch() {
let sample_rate = 44100;
let output_channels = 2;
Expand Down
13 changes: 4 additions & 9 deletions tests/send_and_receive_bang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,25 @@ use libpd_rs::{
send::send_bang_to,
};

#[test]
fn send_and_receive_bang() {
let sample_rate = 44100;
let output_channels = 2;

let bangs: Arc<Mutex<Vec<&str>>> = Arc::new(Mutex::new(vec![]));

let a = init().unwrap();
dbg!(a);
let b = initialize_audio(0, output_channels, sample_rate).unwrap();
dbg!(b);
let _ = init().unwrap();
let _ = initialize_audio(0, output_channels, sample_rate).unwrap();
dsp_on().unwrap();

let patch_handle = open_patch("tests/patches/echo.pd").unwrap();
dbg!(&patch_handle);

let bangs_to_fill = bangs.clone();
on_bang(move |source| {
assert_eq!(source, "bang_from_pd");
bangs_to_fill.lock().unwrap().push("bang");
});
let receiver_handle = start_listening_from("bang_from_pd").unwrap();
dbg!(&receiver_handle);

// Mimic audio callback buffers.
let input_buffer = [0.0f32; 512];
Expand All @@ -51,7 +48,6 @@ fn send_and_receive_bang() {
));

receive_messages_from_pd();
dbg!("Runs?");
let ticks = output_buffer.len() as i32 / (block_size() * output_channels);
process_float(ticks, &input_buffer, &mut output_buffer);
match rx.try_recv() {
Expand All @@ -66,13 +62,12 @@ fn send_and_receive_bang() {
send_bang_to("bang_from_rust").unwrap();
}

std::thread::sleep(std::time::Duration::from_millis(2000));
std::thread::sleep(std::time::Duration::from_millis(50));

// Stop pd.
tx.send(()).unwrap();
handle.join().unwrap();

dbg!(bangs.lock().unwrap());
assert_eq!(bangs.lock().unwrap().len(), 5);

// Stop listening and close handle.
Expand Down
1 change: 1 addition & 0 deletions tests/send_and_receive_control_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use libpd_rs::{
send::send_control_change,
};

#[test]
fn send_and_receive_control_change() {
let sample_rate = 44100;
let output_channels = 2;
Expand Down
1 change: 1 addition & 0 deletions tests/send_and_receive_double.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use libpd_rs::{
send::send_double_to,
};

#[test]
fn send_and_receive_double() {
let sample_rate = 44100;
let output_channels = 2;
Expand Down
11 changes: 5 additions & 6 deletions tests/send_and_receive_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@ fn send_and_receive_float() {
let output_channels = 2;

let floats: Arc<Mutex<Vec<f32>>> = Arc::new(Mutex::new(vec![]));
let floats_to_fill = floats.clone();
on_float(move |source, value| {
dbg!("RECEIVES?");
assert_eq!(source, "float_from_pd");
floats_to_fill.lock().unwrap().push(value);
});

let _ = init().unwrap();
let _ = initialize_audio(0, output_channels, sample_rate).unwrap();
dsp_on().unwrap();

let patch_handle = open_patch("tests/patches/echo.pd").unwrap();

let floats_to_fill = floats.clone();
on_float(move |source, value| {
assert_eq!(source, "float_from_pd");
floats_to_fill.lock().unwrap().push(value);
});
let receiver_handle = start_listening_from("float_from_pd").unwrap();

// Mimic audio callback buffers.
Expand Down
1 change: 1 addition & 0 deletions tests/send_and_receive_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use libpd_rs::{
types::Atom,
};

#[test]
fn send_and_receive_list() {
let sample_rate = 44100;
let output_channels = 2;
Expand Down
1 change: 1 addition & 0 deletions tests/send_and_receive_midi_byte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use libpd_rs::{
send::send_midi_byte,
};

#[test]
fn send_and_receive_midi_byte() {
let sample_rate = 44100;
let output_channels = 2;
Expand Down
1 change: 1 addition & 0 deletions tests/send_and_receive_note_on.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use libpd_rs::{
send::send_note_on,
};

#[test]
fn send_and_receive_note_on() {
let sample_rate = 44100;
let output_channels = 2;
Expand Down
1 change: 1 addition & 0 deletions tests/send_and_receive_pitch_bend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use libpd_rs::{
send::send_pitch_bend,
};

#[test]
fn send_and_receive_pitch_bend() {
let sample_rate = 44100;
let output_channels = 2;
Expand Down
1 change: 1 addition & 0 deletions tests/send_and_receive_poly_after_touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use libpd_rs::{
send::send_poly_after_touch,
};

#[test]
fn send_and_receive_poly_after_touch() {
let sample_rate = 44100;
let output_channels = 2;
Expand Down
1 change: 1 addition & 0 deletions tests/send_and_receive_program_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use libpd_rs::{
send::send_program_change,
};

#[test]
fn send_and_receive_program_change() {
let sample_rate = 44100;
let output_channels = 2;
Expand Down
1 change: 1 addition & 0 deletions tests/send_and_receive_sys_realtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use libpd_rs::{
send::send_sys_realtime,
};

#[test]
fn send_and_receive_sys_realtime() {
let sample_rate = 44100;
let output_channels = 2;
Expand Down
1 change: 1 addition & 0 deletions tests/send_and_receive_sysex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use libpd_rs::{
send::send_sysex,
};

#[test]
fn send_and_receive_sysex() {
let sample_rate = 44100;
let output_channels = 2;
Expand Down
1 change: 1 addition & 0 deletions tests/send_and_receive_typed_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use libpd_rs::{
verbose_print_state,
};

#[test]
fn send_and_receive_typed_message() {
let sample_rate = 44100;
let output_channels = 2;
Expand Down

0 comments on commit e9e48fb

Please sign in to comment.