diff --git a/Cargo.toml b/Cargo.toml index 095cf36f..8c0a0e2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" name = "jack" readme = "README.md" repository = "https://github.com/RustAudio/rust-jack" -version = "0.11.4" +version = "0.12.0" [dependencies] bitflags = "1" diff --git a/examples/playback_capture.rs b/examples/playback_capture.rs index 065f6804..e070df9a 100644 --- a/examples/playback_capture.rs +++ b/examples/playback_capture.rs @@ -9,18 +9,10 @@ fn main() { // Register ports. They will be used in a callback that will be // called when new data is available. - let in_a = client - .register_port("rust_in_l", jack::AudioIn::default()) - .unwrap(); - let in_b = client - .register_port("rust_in_r", jack::AudioIn::default()) - .unwrap(); - let mut out_a = client - .register_port("rust_out_l", jack::AudioOut::default()) - .unwrap(); - let mut out_b = client - .register_port("rust_out_r", jack::AudioOut::default()) - .unwrap(); + let in_a = client.register_port("rust_in_l", jack::AudioIn).unwrap(); + let in_b = client.register_port("rust_in_r", jack::AudioIn).unwrap(); + let mut out_a = client.register_port("rust_out_l", jack::AudioOut).unwrap(); + let mut out_b = client.register_port("rust_out_r", jack::AudioOut).unwrap(); let process_callback = move |_: &jack::Client, ps: &jack::ProcessScope| -> jack::Control { let out_a_p = out_a.as_mut_slice(ps); let out_b_p = out_b.as_mut_slice(ps); diff --git a/examples/show_midi.rs b/examples/show_midi.rs index 9e248ef4..ae0484d9 100644 --- a/examples/show_midi.rs +++ b/examples/show_midi.rs @@ -50,10 +50,10 @@ fn main() { // process logic let mut maker = client - .register_port("rust_midi_maker", jack::MidiOut::default()) + .register_port("rust_midi_maker", jack::MidiOut) .unwrap(); let shower = client - .register_port("rust_midi_shower", jack::MidiIn::default()) + .register_port("rust_midi_shower", jack::MidiIn) .unwrap(); let cback = move |_: &jack::Client, ps: &jack::ProcessScope| -> jack::Control { diff --git a/examples/sine.rs b/examples/sine.rs index 6232a87f..8cd2e238 100644 --- a/examples/sine.rs +++ b/examples/sine.rs @@ -11,9 +11,7 @@ fn main() { jack::Client::new("rust_jack_sine", jack::ClientOptions::NO_START_SERVER).unwrap(); // 2. register port - let mut out_port = client - .register_port("sine_out", jack::AudioOut::default()) - .unwrap(); + let mut out_port = client.register_port("sine_out", jack::AudioOut).unwrap(); // 3. define process callback handler let mut frequency = 220.0; diff --git a/jack-sys/src/types.rs b/jack-sys/src/types.rs index a5ba3a7e..a56def3c 100644 --- a/jack-sys/src/types.rs +++ b/jack-sys/src/types.rs @@ -1,3 +1,4 @@ +#![allow(non_camel_case_types)] #[cfg(not(target_os = "windows"))] pub type jack_native_thread_t = ::libc::pthread_t; pub type jack_uuid_t = u64; diff --git a/src/client/async_client.rs b/src/client/async_client.rs index b1a785a8..c019a750 100644 --- a/src/client/async_client.rs +++ b/src/client/async_client.rs @@ -104,15 +104,13 @@ impl AsyncClient { // Helper function for deactivating. Any function that calls this should // have ownership of self and no longer use it after this call. - unsafe fn maybe_deactivate(&mut self) -> Result, Error> { + unsafe fn maybe_deactivate(&mut self) -> Result>, Error> { let _m = CREATE_OR_DESTROY_CLIENT_MUTEX.lock().unwrap(); if self.callback.is_none() { return Err(Error::ClientIsNoLongerAlive); } - let client = self.callback.as_ref().unwrap().client.raw(); - // Prevent the callback from being deallocated in case deactivation - // fails. - let callback = Box::into_raw(self.callback.take().unwrap()); + let cb = self.callback.take().unwrap(); + let client = cb.client.raw(); // deactivate sleep_on_test(); @@ -123,15 +121,14 @@ impl AsyncClient { // clear the callbacks sleep_on_test(); clear_callbacks(client)?; - // done, take ownership of callback - Ok(*Box::from_raw(callback)) + Ok(cb) } } /// Closes the client. impl Drop for AsyncClient { - /// Deactivate and close the client. + // Deactivate and close the client. fn drop(&mut self) { let _ = unsafe { self.maybe_deactivate() }; } diff --git a/src/client/callbacks.rs b/src/client/callbacks.rs index 0050556f..eb240dbe 100644 --- a/src/client/callbacks.rs +++ b/src/client/callbacks.rs @@ -75,7 +75,7 @@ pub trait NotificationHandler: Send { pub trait ProcessHandler: Send { /// Indicates whether or not this process handler represents a /// slow-sync client - const SLOW_SYNC:bool = false; + const SLOW_SYNC: bool = false; /// Called whenever there is work to be done. /// @@ -108,11 +108,12 @@ pub trait ProcessHandler: Send { /// It should return `false` until the handler is ready process audio. /// /// Ignored unless Self::SLOW_SYNC == true. - fn sync(&mut self, - _: &Client, - _state: crate::TransportState, - _pos: &crate::TransportPosition - )->bool { + fn sync( + &mut self, + _: &Client, + _state: crate::TransportState, + _pos: &crate::TransportPosition, + ) -> bool { true } } @@ -156,7 +157,7 @@ where unsafe extern "C" fn sync( state: jack_sys::jack_transport_state_t, pos: *mut jack_sys::jack_position_t, - data: *mut libc::c_void + data: *mut libc::c_void, ) -> libc::c_int where N: 'static + Send + Sync + NotificationHandler, @@ -166,10 +167,10 @@ where match ctx.process.sync( &ctx.client, crate::Transport::state_from_ffi(state), - &*(pos as *mut crate::TransportPosition) + &*(pos as *mut crate::TransportPosition), ) { true => 1, - false => 0 + false => 0, } } @@ -295,9 +296,11 @@ where /// # TODO /// /// * Implement correctly. Freezes on my system. -pub unsafe fn clear_callbacks(_client: *mut j::jack_client_t) -> Result<(), Error> { - // j::jack_set_thread_init_callback(client, None, ptr::null_mut()); - // j::jack_set_process_callback(client, None, ptr::null_mut()); + +//maybe this makes sense now? it doesn't disturb my program +pub unsafe fn clear_callbacks(client: *mut j::jack_client_t) -> Result<(), Error> { + j::jack_set_thread_init_callback(client, None, std::ptr::null_mut()); + j::jack_set_process_callback(client, None, std::ptr::null_mut()); Ok(()) } diff --git a/src/client/client_impl.rs b/src/client/client_impl.rs index 90b144c1..77fe1185 100644 --- a/src/client/client_impl.rs +++ b/src/client/client_impl.rs @@ -30,6 +30,7 @@ use crate::{ pub type InternalClientID = j::jack_intclient_t; +#[allow(dead_code)] pub struct Client( *mut j::jack_client_t, Arc<()>, @@ -659,7 +660,6 @@ impl Client { impl Drop for Client { fn drop(&mut self) { let _m = CREATE_OR_DESTROY_CLIENT_MUTEX.lock().unwrap(); - debug_assert!(!self.raw().is_null()); // Rep invariant // Close the client sleep_on_test(); diff --git a/src/client/test_callback.rs b/src/client/test_callback.rs index 4daa8d5e..ca4c2f9c 100644 --- a/src/client/test_callback.rs +++ b/src/client/test_callback.rs @@ -201,14 +201,8 @@ fn client_cback_reports_xruns() { #[test] fn client_cback_calls_port_registered() { let ac = active_test_client("client_cback_cpr"); - let _pa = ac - .as_client() - .register_port("pa", AudioIn::default()) - .unwrap(); - let _pb = ac - .as_client() - .register_port("pb", AudioIn::default()) - .unwrap(); + let _pa = ac.as_client().register_port("pa", AudioIn).unwrap(); + let _pb = ac.as_client().register_port("pb", AudioIn).unwrap(); let counter = ac.deactivate().unwrap().1; assert_eq!( counter.port_register_history.len(), @@ -224,14 +218,8 @@ fn client_cback_calls_port_registered() { #[test] fn client_cback_calls_port_unregistered() { let ac = active_test_client("client_cback_cpr"); - let pa = ac - .as_client() - .register_port("pa", AudioIn::default()) - .unwrap(); - let pb = ac - .as_client() - .register_port("pb", AudioIn::default()) - .unwrap(); + let pa = ac.as_client().register_port("pa", AudioIn).unwrap(); + let pb = ac.as_client().register_port("pb", AudioIn).unwrap(); ac.as_client().unregister_port(pa).unwrap(); ac.as_client().unregister_port(pb).unwrap(); let counter = ac.deactivate().unwrap().1; diff --git a/src/port/audio.rs b/src/port/audio.rs index 07c5f2ff..1509a65c 100644 --- a/src/port/audio.rs +++ b/src/port/audio.rs @@ -107,10 +107,10 @@ mod test { #[test] fn port_audio_can_read_write() { let c = open_test_client("port_audio_crw"); - let in_a = c.register_port("ia", AudioIn::default()).unwrap(); - let in_b = c.register_port("ib", AudioIn::default()).unwrap(); - let mut out_a = c.register_port("oa", AudioOut::default()).unwrap(); - let mut out_b = c.register_port("ob", AudioOut::default()).unwrap(); + let in_a = c.register_port("ia", AudioIn).unwrap(); + let in_b = c.register_port("ib", AudioIn).unwrap(); + let mut out_a = c.register_port("oa", AudioOut).unwrap(); + let mut out_b = c.register_port("ob", AudioOut).unwrap(); let (signal_succeed, did_succeed) = bounded(1_000); let process_callback = move |_: &Client, ps: &ProcessScope| -> Control { let exp_a = 0.312_443; diff --git a/src/port/midi.rs b/src/port/midi.rs index d4cb0a48..4d29623a 100644 --- a/src/port/midi.rs +++ b/src/port/midi.rs @@ -275,8 +275,8 @@ mod test { stream, collected: Vec::new(), collector, - midi_in: client.register_port("in", MidiIn::default()).unwrap(), - midi_out: client.register_port("out", MidiOut::default()).unwrap(), + midi_in: client.register_port("in", MidiIn).unwrap(), + midi_out: client.register_port("out", MidiOut).unwrap(), } } @@ -307,10 +307,10 @@ mod test { fn port_midi_can_read_write() { // open clients and ports let c = open_test_client("port_midi_crw"); - let in_a = c.register_port("ia", MidiIn::default()).unwrap(); - let in_b = c.register_port("ib", MidiIn::default()).unwrap(); - let mut out_a = c.register_port("oa", MidiOut::default()).unwrap(); - let mut out_b = c.register_port("ob", MidiOut::default()).unwrap(); + let in_a = c.register_port("ia", MidiIn).unwrap(); + let in_b = c.register_port("ib", MidiIn).unwrap(); + let mut out_a = c.register_port("oa", MidiOut).unwrap(); + let mut out_b = c.register_port("ob", MidiOut).unwrap(); // set callback routine let (signal_succeed, did_succeed) = bounded(1_000); @@ -366,7 +366,7 @@ mod test { fn port_midi_can_get_max_event_size() { // open clients and ports let c = open_test_client("port_midi_cglc"); - let mut out_p = c.register_port("op", MidiOut::default()).unwrap(); + let mut out_p = c.register_port("op", MidiOut).unwrap(); // set callback routine let process_callback = move |_: &Client, ps: &ProcessScope| -> Control { @@ -393,7 +393,7 @@ mod test { fn port_midi_cant_exceed_max_event_size() { // open clients and ports let c = open_test_client("port_midi_cglc"); - let mut out_p = c.register_port("op", MidiOut::default()).unwrap(); + let mut out_p = c.register_port("op", MidiOut).unwrap(); // set callback routine let process_callback = move |_: &Client, ps: &ProcessScope| -> Control { @@ -437,8 +437,8 @@ mod test { fn port_midi_iter() { // open clients and ports let c = open_test_client("port_midi_iter"); - let in_p = c.register_port("ip", MidiIn::default()).unwrap(); - let mut out_p = c.register_port("op", MidiOut::default()).unwrap(); + let in_p = c.register_port("ip", MidiIn).unwrap(); + let mut out_p = c.register_port("op", MidiOut).unwrap(); // set callback routine let process_callback = move |_: &Client, ps: &ProcessScope| -> Control { diff --git a/src/port/test_client.rs b/src/port/test_client.rs index 16efd79c..0aa13a26 100644 --- a/src/port/test_client.rs +++ b/src/port/test_client.rs @@ -17,16 +17,16 @@ fn open_test_client(name: &str) -> Client { #[test] fn client_port_can_register_port() { let c = open_test_client("cp_can_register_port"); - c.register_port("cpcrp_a", AudioIn::default()).unwrap(); + c.register_port("cpcrp_a", AudioIn).unwrap(); } #[test] fn client_port_register_port_enforces_unique_names() { let pname = "cprpeun_a"; let c = open_test_client("cp_can_register_port"); - c.register_port(pname, AudioIn::default()).unwrap(); + c.register_port(pname, AudioIn).unwrap(); assert_eq!( - c.register_port(pname, AudioIn::default()).err(), + c.register_port(pname, AudioIn).err(), Some(Error::PortRegistrationError(pname.to_string())) ); } @@ -39,7 +39,7 @@ fn client_port_register_port_enforces_name_length() { .collect::>() .join("_"); assert_eq!( - c.register_port(&pname, AudioIn::default()).err(), + c.register_port(&pname, AudioIn).err(), Some(Error::PortRegistrationError(pname.to_string())) ); } @@ -47,7 +47,7 @@ fn client_port_register_port_enforces_name_length() { #[test] fn client_port_can_request_monitor_by_name() { let c = open_test_client("cp_can_request_monitor_by_name"); - let p = c.register_port("cpcrmbn_a", AudioIn::default()).unwrap(); + let p = c.register_port("cpcrmbn_a", AudioIn).unwrap(); c.request_monitor_by_name(&p.name().unwrap(), true).unwrap(); c.request_monitor_by_name(&p.name().unwrap(), false) .unwrap(); @@ -56,7 +56,7 @@ fn client_port_can_request_monitor_by_name() { #[test] fn client_port_can_get_port_by_name() { let c = open_test_client("cp_can_get_port_by_name"); - let p = c.register_port("named_port", AudioIn::default()).unwrap(); + let p = c.register_port("named_port", AudioIn).unwrap(); let _p = c.port_by_name(&p.name().unwrap()).unwrap(); } @@ -87,10 +87,7 @@ fn client_port_can_get_port_by_id() { let ac = c.activate_async(h, ()).unwrap(); // Register port - let _pa = ac - .as_client() - .register_port(port_name, AudioIn::default()) - .unwrap(); + let _pa = ac.as_client().register_port(port_name, AudioIn).unwrap(); // Get by id let c = ac.deactivate().unwrap().0; @@ -113,7 +110,7 @@ fn client_port_can_get_port_by_id() { #[test] fn client_port_fails_to_nonexistant_port() { let c = open_test_client("cp_can_request_monitor_by_name"); - let p = c.register_port("cpcrmbn_a", AudioIn::default()).unwrap(); + let p = c.register_port("cpcrmbn_a", AudioIn).unwrap(); let _p = c.port_by_name(&p.name().unwrap()).unwrap(); } @@ -121,8 +118,8 @@ fn client_port_fails_to_nonexistant_port() { fn client_port_recognizes_my_ports() { let ca = open_test_client("cp_cprmp_ca"); let cb = open_test_client("cp_cprmp_cb"); - let first = ca.register_port("cpcprmp_pa", AudioIn::default()).unwrap(); - let second = cb.register_port("cpcprmp_pb", AudioIn::default()).unwrap(); + let first = ca.register_port("cpcprmp_pa", AudioIn).unwrap(); + let second = cb.register_port("cpcprmp_pb", AudioIn).unwrap(); let first_alt = ca.port_by_name(&first.name().unwrap()).unwrap(); let second_alt = ca.port_by_name(&second.name().unwrap()).unwrap(); assert!(ca.is_mine(&first)); @@ -136,8 +133,8 @@ fn client_port_can_connect_ports() { let client = open_test_client("client_port_ccp"); // initialize ports - let in_p = client.register_port("inp", AudioIn::default()).unwrap(); - let out_p = client.register_port("outp", AudioOut::default()).unwrap(); + let in_p = client.register_port("inp", AudioIn).unwrap(); + let out_p = client.register_port("outp", AudioOut).unwrap(); // start client let client = client.activate_async((), ()).unwrap(); @@ -151,8 +148,8 @@ fn client_port_can_connect_ports_by_name() { let client = open_test_client("client_port_ccpbn"); // initialize ports - let _in_p = client.register_port("inp", AudioIn::default()).unwrap(); - let _out_p = client.register_port("outp", AudioOut::default()).unwrap(); + let _in_p = client.register_port("inp", AudioIn).unwrap(); + let _out_p = client.register_port("outp", AudioOut).unwrap(); // start client let client = client.activate_async((), ()).unwrap(); @@ -170,8 +167,8 @@ fn client_port_can_connect_unowned_ports() { let connector = open_test_client("client_port_ccup_conn"); // initialize ports - let _in_p = client.register_port("inp", AudioIn::default()).unwrap(); - let _out_p = client.register_port("outp", AudioOut::default()).unwrap(); + let _in_p = client.register_port("inp", AudioIn).unwrap(); + let _out_p = client.register_port("outp", AudioOut).unwrap(); // start client let _client = client.activate_async((), ()).unwrap(); @@ -188,13 +185,9 @@ fn client_port_cant_connect_inactive_client() { let other = open_test_client("client_port_ccic_other"); // initialize ports - let in_p = other - .register_port("inp", AudioIn::default()) - .unwrap() - .name() - .unwrap(); + let in_p = other.register_port("inp", AudioIn).unwrap().name().unwrap(); let out_p = other - .register_port("outp", AudioOut::default()) + .register_port("outp", AudioOut) .unwrap() .name() .unwrap(); @@ -216,8 +209,8 @@ fn client_port_recognizes_already_connected_ports() { let client = open_test_client("client_port_racp"); // initialize ports - let in_p = client.register_port("conna", AudioIn::default()).unwrap(); - let out_p = client.register_port("connb", AudioOut::default()).unwrap(); + let in_p = client.register_port("conna", AudioIn).unwrap(); + let out_p = client.register_port("connb", AudioOut).unwrap(); // start client let client = client.activate_async((), ()).unwrap(); @@ -254,8 +247,8 @@ fn client_port_can_disconnect_port_from_all() { let client = open_test_client("client_port_cdpfa"); // initialize ports - let in_p = client.register_port("conna", AudioIn::default()).unwrap(); - let out_p = client.register_port("connb", AudioOut::default()).unwrap(); + let in_p = client.register_port("conna", AudioIn).unwrap(); + let out_p = client.register_port("connb", AudioOut).unwrap(); // start client let client = client.activate_async((), ()).unwrap(); @@ -270,8 +263,8 @@ fn client_port_can_disconnect_ports() { let client = open_test_client("client_port_cdp"); // initialize ports - let in_p = client.register_port("conna", AudioIn::default()).unwrap(); - let out_p = client.register_port("connb", AudioOut::default()).unwrap(); + let in_p = client.register_port("conna", AudioIn).unwrap(); + let out_p = client.register_port("connb", AudioOut).unwrap(); // start client let client = client.activate_async((), ()).unwrap(); @@ -286,8 +279,8 @@ fn client_port_can_disconnect_ports_by_name() { let client = open_test_client("client_port_cdpbn"); // initialize ports - let in_p = client.register_port("conna", AudioIn::default()).unwrap(); - let out_p = client.register_port("connb", AudioOut::default()).unwrap(); + let in_p = client.register_port("conna", AudioIn).unwrap(); + let out_p = client.register_port("connb", AudioOut).unwrap(); // start client let client = client.activate_async((), ()).unwrap(); @@ -309,8 +302,8 @@ fn client_port_can_disconnect_unowned_ports() { let disconnector = open_test_client("client_port_cdup_disc"); // initialize ports - let in_p = client.register_port("conna", AudioIn::default()).unwrap(); - let out_p = client.register_port("connb", AudioOut::default()).unwrap(); + let in_p = client.register_port("conna", AudioIn).unwrap(); + let out_p = client.register_port("connb", AudioOut).unwrap(); // start client let client = client.activate_async((), ()).unwrap(); @@ -331,8 +324,8 @@ fn client_port_can_get_existing_ports() { let port_getter = open_test_client("client_port_cgep_getter"); // initialize ports - let in_p = client.register_port("conna", AudioIn::default()).unwrap(); - let out_p = client.register_port("connb", AudioOut::default()).unwrap(); + let in_p = client.register_port("conna", AudioIn).unwrap(); + let out_p = client.register_port("connb", AudioOut).unwrap(); // retrieve let known_ports = [ @@ -377,7 +370,7 @@ fn client_port_can_get_port_by_type_pattern() { let client = open_test_client(c_name); // register port with type name, like midi - let _p = client.register_port(p_name, MidiIn::default()); + let _p = client.register_port(p_name, MidiIn); thread::sleep(time::Duration::from_millis(400)); // retrieve diff --git a/src/port/test_port.rs b/src/port/test_port.rs index 3e86aeb7..82ce24b4 100644 --- a/src/port/test_port.rs +++ b/src/port/test_port.rs @@ -13,7 +13,7 @@ fn open_test_client(name: &str) -> Client { fn open_client_with_port(client: &str, port: &str) -> (Client, Port) { let c = open_test_client(client); - let p = c.register_port(port, AudioIn::default()).unwrap(); + let p = c.register_port(port, AudioIn).unwrap(); (c, p) } @@ -52,10 +52,10 @@ fn port_can_rename() { #[test] fn port_connected_count() { let c = open_test_client("port_connected_count"); - let pa = c.register_port("pa", AudioIn::default()).unwrap(); - let pb = c.register_port("pb", AudioOut::default()).unwrap(); - let pc = c.register_port("pc", AudioOut::default()).unwrap(); - let pd = c.register_port("pd", AudioOut::default()).unwrap(); + let pa = c.register_port("pa", AudioIn).unwrap(); + let pb = c.register_port("pb", AudioOut).unwrap(); + let pc = c.register_port("pc", AudioOut).unwrap(); + let pd = c.register_port("pd", AudioOut).unwrap(); let c = c.activate_async((), ()).unwrap(); c.as_client().connect_ports(&pb, &pa).unwrap(); c.as_client().connect_ports(&pc, &pa).unwrap(); @@ -68,10 +68,10 @@ fn port_connected_count() { #[test] fn port_knows_connections() { let c = open_test_client("port_knows_connections"); - let pa = c.register_port("pa", AudioIn::default()).unwrap(); - let pb = c.register_port("pb", AudioOut::default()).unwrap(); - let pc = c.register_port("pc", AudioOut::default()).unwrap(); - let pd = c.register_port("pd", AudioOut::default()).unwrap(); + let pa = c.register_port("pa", AudioIn).unwrap(); + let pb = c.register_port("pb", AudioOut).unwrap(); + let pc = c.register_port("pc", AudioOut).unwrap(); + let pd = c.register_port("pd", AudioOut).unwrap(); let c = c.activate_async((), ()).unwrap(); c.as_client().connect_ports(&pb, &pa).unwrap(); c.as_client().connect_ports(&pc, &pa).unwrap(); @@ -155,18 +155,18 @@ fn port_can_unset_alias() { #[test] fn port_unowned_no_port_type() { - assert_eq!("", Unowned::default().jack_port_type()); + assert_eq!("", Unowned.jack_port_type()); } #[test] fn port_unowned_no_port_flags() { - assert_eq!(PortFlags::empty(), Unowned::default().jack_flags()); + assert_eq!(PortFlags::empty(), Unowned.jack_flags()); } #[test] #[should_panic] fn port_unowned_no_port_size() { - Unowned::default().jack_buffer_size(); + Unowned.jack_buffer_size(); } #[test] diff --git a/src/transport.rs b/src/transport.rs index 6b6e3339..900d5275 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -1,5 +1,5 @@ -///! JACK transport wrappers. -///! See the [transport design api docs](https://jackaudio.org/api/transport-design.html) for more info. +//! JACK transport wrappers. +//! See the [transport design api docs](https://jackaudio.org/api/transport-design.html) for more info. use crate::{Frames, Time}; use jack_sys as j; use std::sync::Weak;