Skip to content

Commit d22e929

Browse files
committed
Re-design the library with multi instance support and pass all tests.
1 parent 0e485ab commit d22e929

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2300
-1665
lines changed

Cargo.toml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "libpd-rs"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
authors = ["alisomay <[email protected]>"]
55
edition = "2021"
66
license = "BSD-3-Clause"
@@ -17,19 +17,28 @@ exclude = [
1717
"assets/logo_*"
1818
]
1919

20+
[lib]
21+
name = "libpd_rs"
22+
path = "src/lib.rs"
23+
test = true
24+
doctest = true
25+
bench = false
26+
doc = true
27+
edition = "2021"
28+
crate-type = ["lib"]
29+
2030
[dependencies]
21-
# libpd-sys = "0.2"
22-
libpd-sys = { path = "../libpd-sys" }
23-
thiserror = "1.0.30"
31+
libpd-sys = "0.3"
32+
thiserror = "2"
2433
libffi = "3.0.0"
2534
tempfile = "3.3.0"
2635
embed-doc-image = "0.1.4"
2736

2837
[dev-dependencies]
2938
cpal = "0.15.2"
3039
sys-info = "0.9.1"
31-
nannou = "0.18"
32-
nannou_audio = "0.18"
40+
nannou = "0.19"
41+
nannou_audio = "0.19"
3342
rand = "0.8.5"
3443

3544
# For local development,
@@ -40,15 +49,6 @@ rand = "0.8.5"
4049
# [patch."https://github.com/alisomay/libpd-sys"]
4150
# libpd-sys = { path = "../libpd-sys" }
4251

43-
[lib]
44-
name = "libpd_rs" # The name of the target.
45-
path = "src/lib.rs" # The source file of the target.
46-
test = true # Is tested by default.
47-
doctest = true # Documentation examples are tested by default.
48-
bench = false # Is benchmarked by default.
49-
doc = true # Is documented by default.
50-
proc-macro = false # Set to `true` for a proc-macro library.
51-
edition = "2021" # The edition of the target.
52-
crate-type = ["lib"] # The crate types to generate.
52+
5353

5454

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
8585
// Here if we had an input buffer we could have modified it to do pre-processing.
8686

8787
// Process audio, advance internal scheduler.
88-
libpd_rs::process::process_float(ticks, &[], data);
88+
libpd_rs::functions::process::process_float(ticks, &[], data);
8989

9090
// Here we could have done post processing after pd processed our output buffer in place.
9191
},

examples/simple.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
2-
use libpd_rs::convenience::PdGlobal;
2+
use libpd_rs::Pd;
33

44
fn main() -> Result<(), Box<dyn std::error::Error>> {
55
// Initialize cpal
@@ -19,7 +19,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1919

2020
// Initialize libpd with that configuration,
2121
// with no input channels since we're not going to use them.
22-
let mut pd = PdGlobal::init_and_configure(0, output_channels, sample_rate)?;
22+
let mut pd = Pd::init_and_configure(0, output_channels, sample_rate)?;
2323

2424
// Let's evaluate a pd patch.
2525
// We could have opened a `.pd` file also.
@@ -43,12 +43,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
4343
&config.into(),
4444
move |data: &mut [f32], _: &cpal::OutputCallbackInfo| {
4545
// Provide the ticks to advance per iteration for the internal scheduler.
46-
let ticks = libpd_rs::convenience::calculate_ticks(output_channels, data.len() as i32);
46+
let ticks =
47+
libpd_rs::functions::util::calculate_ticks(output_channels, data.len() as i32);
4748

4849
// Here if we had an input buffer we could have modified it to do pre-processing.
4950

5051
// Process audio, advance internal scheduler.
51-
libpd_rs::process::process_float(ticks, &[], data);
52+
libpd_rs::functions::process::process_float(ticks, &[], data);
5253

5354
// Here we could have done post processing after pd processed our output buffer in place.
5455
},

examples/with_nannou/bubble.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ impl Bubble {
213213
// Collision with the floor!
214214
if distance_to_floor < self.properties.r * 2.0 {
215215
// On collision we tell the right voice to play with the right parameters in pd.
216-
libpd_rs::send::send_list_to("bubble_collision", &self.pack_message()).unwrap();
216+
libpd_rs::functions::send::send_list_to("bubble_collision", &self.pack_message())
217+
.unwrap();
217218

218219
// Physics
219220
self.properties.dy = -self.properties.dy;

examples/with_nannou/main.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() {
1414

1515
// This data structure will be shared across nannou functions.
1616
pub struct Model {
17-
pd: libpd_rs::convenience::PdGlobal,
17+
pd: libpd_rs::Pd,
1818
output_stream: audio::Stream<()>,
1919
gravity: f32,
2020
bubbles: RefCell<Vec<Bubble>>,
@@ -62,19 +62,14 @@ fn model(app: &App) -> Model {
6262
.unwrap();
6363

6464
// Listen for console messages from pd
65-
libpd_rs::receive::on_print(|val| {
65+
libpd_rs::functions::receive::on_print(|val| {
6666
println!("{}", val);
6767
});
6868

6969
// This data structure will be shared across nannou functions.
7070
let mut model = Model {
7171
// Initialize pd
72-
pd: libpd_rs::convenience::PdGlobal::init_and_configure(
73-
0,
74-
channels as i32,
75-
sample_rate as i32,
76-
)
77-
.unwrap(),
72+
pd: libpd_rs::Pd::init_and_configure(0, channels as i32, sample_rate as i32).unwrap(),
7873
output_stream,
7974
gravity: 0.8,
8075
bubbles: RefCell::new(vec![]),
@@ -95,7 +90,7 @@ fn model(app: &App) -> Model {
9590

9691
// Initially pd needs to know how many bubbles we have.
9792
// Because it will create adequate amount of voices for them.
98-
libpd_rs::send::send_float_to("bubble_count", model.bubble_count as f32).unwrap();
93+
libpd_rs::functions::send::send_float_to("bubble_count", model.bubble_count as f32).unwrap();
9994

10095
// Run pd!
10196
model.pd.activate_audio(true).unwrap();
@@ -145,14 +140,14 @@ impl Model {
145140
// We hand over all tasks to our pd patch!
146141
fn audio_callback(_: &mut (), buffer: &mut Buffer) {
147142
let ticks =
148-
libpd_rs::convenience::calculate_ticks(buffer.channels() as i32, buffer.len() as i32);
149-
libpd_rs::process::process_float(ticks, &[], buffer);
143+
libpd_rs::functions::util::calculate_ticks(buffer.channels() as i32, buffer.len() as i32);
144+
libpd_rs::functions::process::process_float(ticks, &[], buffer);
150145
}
151146

152147
// This is where we draw repeatedly!
153148
fn view(app: &App, model: &Model, frame: Frame) {
154149
// Let's poll pd messages here, for every frame.
155-
libpd_rs::receive::receive_messages_from_pd();
150+
libpd_rs::functions::receive::receive_messages_from_pd();
156151

157152
let background_color = nannou::color::srgb8(238, 108, 77);
158153

0 commit comments

Comments
 (0)