Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi Instance Support #22

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Re-design the library with multi instance support and pass all tests.
alisomay committed Nov 28, 2024
commit 12edec62b41da8f0ffabc7720d7d804c07be6e9a
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ jobs:
token: ${{secrets.CODECOV_TOKEN}}

- name: Archive code coverage results
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: cobertura.xml
32 changes: 16 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libpd-rs"
version = "0.2.0"
version = "0.3.0"
authors = ["alisomay <alisomay@runbox.com>"]
edition = "2021"
license = "BSD-3-Clause"
@@ -17,19 +17,28 @@ exclude = [
"assets/logo_*"
]

[lib]
name = "libpd_rs"
path = "src/lib.rs"
test = true
doctest = true
bench = false
doc = true
edition = "2021"
crate-type = ["lib"]

[dependencies]
# libpd-sys = "0.2"
libpd-sys = { path = "../libpd-sys" }
thiserror = "1.0.30"
libpd-sys = "0.3"
thiserror = "2"
libffi = "3.0.0"
tempfile = "3.3.0"
embed-doc-image = "0.1.4"

[dev-dependencies]
cpal = "0.15.2"
sys-info = "0.9.1"
nannou = "0.18"
nannou_audio = "0.18"
nannou = "0.19"
nannou_audio = "0.19"
rand = "0.8.5"

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

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



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

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

// Here we could have done post processing after pd processed our output buffer in place.
},
9 changes: 5 additions & 4 deletions examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use libpd_rs::convenience::PdGlobal;
use libpd_rs::Pd;

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

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

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

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

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

// Here we could have done post processing after pd processed our output buffer in place.
},
3 changes: 2 additions & 1 deletion examples/with_nannou/bubble.rs
Original file line number Diff line number Diff line change
@@ -213,7 +213,8 @@ impl Bubble {
// Collision with the floor!
if distance_to_floor < self.properties.r * 2.0 {
// On collision we tell the right voice to play with the right parameters in pd.
libpd_rs::send::send_list_to("bubble_collision", &self.pack_message()).unwrap();
libpd_rs::functions::send::send_list_to("bubble_collision", &self.pack_message())
.unwrap();

// Physics
self.properties.dy = -self.properties.dy;
19 changes: 7 additions & 12 deletions examples/with_nannou/main.rs
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ fn main() {

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

// Listen for console messages from pd
libpd_rs::receive::on_print(|val| {
libpd_rs::functions::receive::on_print(|val| {
println!("{}", val);
});

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

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

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

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

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

Loading