forked from RustAudio/rust-jack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate PortSpec and Port wrapping datatypes
Previously, a port is registered and associated with a specific datatype that ends up wrapping it. The wrapping was done by: `my_registered_port.data(...)`. Changed it so that ports are now registered with a `PortSpec` while wrappers can be created independent. EX: ``` rust /// I allow safe access to port data. pub struct MySafeWrapper {port: &Port<ThePortSpec>, ps: &ProcessScope}; ```
- Loading branch information
Showing
14 changed files
with
347 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
# Start the dummy JACK server | ||
|
||
jackd -r -ddummy -r44100 -p1024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,52 @@ | ||
use std::io::{Write, stderr}; | ||
use std::ffi; | ||
use std::sync::{Once, ONCE_INIT}; | ||
use jack_sys as j; | ||
|
||
fn to_stdout(msg: &str) { | ||
println!("{}", msg); | ||
} | ||
|
||
fn to_stderr(msg: &str) { | ||
writeln!(&mut stderr(), "{}", msg).unwrap(); | ||
} | ||
fn to_nothing(_: &str) {} | ||
|
||
static mut info_fn: fn(&str) = to_stdout; | ||
static mut error_fn: fn(&str) = to_stderr; | ||
static mut INFO_FN: fn(&str) = to_nothing; | ||
static mut ERROR_FN: fn(&str) = to_nothing; | ||
|
||
unsafe extern "C" fn error_wrapper(msg: *const i8) { | ||
let msg = ffi::CStr::from_ptr(msg).to_str().unwrap(); | ||
error_fn(msg); | ||
ERROR_FN(msg); | ||
} | ||
|
||
unsafe extern "C" fn info_wrapper(msg: *const i8) { | ||
let msg = ffi::CStr::from_ptr(msg).to_str().unwrap(); | ||
info_fn(msg) | ||
INFO_FN(msg) | ||
} | ||
|
||
static IS_INFO_CALLBACK_SET: Once = ONCE_INIT; | ||
/// Set the global JACK info callback. | ||
/// | ||
/// # Example | ||
/// ```rust | ||
/// fn info_log(msg: &str) { | ||
/// println!("{}", msg); | ||
/// } | ||
/// jack::set_info_callback(info_log); | ||
/// ``` | ||
pub fn set_info_callback(info: fn(&str)) { | ||
unsafe { | ||
INFO_FN = info; | ||
} | ||
IS_INFO_CALLBACK_SET.call_once(|| unsafe { j::jack_set_info_function(Some(info_wrapper)) }) | ||
} | ||
|
||
static ARE_CALLBACKS_SET: Once = ONCE_INIT; | ||
/// TODO: Provide better API for this functionality | ||
pub fn set_info_callbacks(info: Option<fn(&str)>, error: Option<fn(&str)>) { | ||
static IS_ERROR_CALLBACK_SET: Once = ONCE_INIT; | ||
/// Set the global JACK error callback. | ||
/// | ||
/// # Example | ||
/// ```rust | ||
/// fn error_log(msg: &str) { | ||
/// println!("{}", msg); | ||
/// } | ||
/// jack::set_error_callback(error_log); | ||
/// ``` | ||
pub fn set_error_callback(error: fn(&str)) { | ||
unsafe { | ||
info_fn = info.unwrap_or(to_stdout); | ||
error_fn = error.unwrap_or(to_stderr); | ||
}; | ||
ARE_CALLBACKS_SET.call_once(|| unsafe { | ||
j::jack_set_error_function(Some(error_wrapper)); | ||
j::jack_set_info_function(Some(info_wrapper)); | ||
}); | ||
ERROR_FN = error; | ||
} | ||
IS_ERROR_CALLBACK_SET.call_once(|| unsafe { j::jack_set_error_function(Some(error_wrapper)) }) | ||
} |
Oops, something went wrong.