diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 92d926e9..4e3773f2 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -25,19 +25,11 @@ jobs: - name: Lint (No Features) run: cargo clippy --all-targets --no-default-features -- -D clippy::all - - name: Lint (All Features) - run: cargo clippy --all-targets --no-default-features --features dlopen,metadata -- -D clippy::all - - name: Lint (dlopen) - run: cargo clippy --all-targets --no-default-features --features dlopen -- -D clippy::all - name: Lint (metadata) run: cargo clippy --all-targets --no-default-features --features metadata -- -D clippy::all - name: Build (No Features) run: cargo build --verbose --no-default-features - - name: Build (All Features) - run: cargo build --verbose --no-default-features --features dlopen,metadata - - name: Build (dlopen) - run: cargo build --verbose --no-default-features --features dlopen - name: Build (metadata) run: cargo build --verbose --no-default-features --features metadata diff --git a/Cargo.toml b/Cargo.toml index e2f01d1a..89ce80e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,12 +8,11 @@ license = "MIT" name = "jack" readme = "README.md" repository = "https://github.com/RustAudio/rust-jack" -version = "0.9.2" +version = "0.10.0" [dependencies] bitflags = "1" -dlib = "0.5" -jack-sys = {path = "./jack-sys", version = "0.3.4"} +jack-sys = {version = "0.4", path = "./jack-sys"} lazy_static = "1.4" libc = "0.2" log = "0.4" @@ -22,6 +21,5 @@ log = "0.4" crossbeam-channel = "0.5" [features] -default = ["dlopen"] -dlopen = ["jack-sys/dlopen"] +default = [] metadata = [] diff --git a/jack-sys/Cargo.toml b/jack-sys/Cargo.toml index 31523402..61d2e6cd 100644 --- a/jack-sys/Cargo.toml +++ b/jack-sys/Cargo.toml @@ -6,19 +6,13 @@ license = "MIT OR Apache-2.0" links = "jack" name = "jack-sys" repository = "https://github.com/RustAudio/rust-jack/tree/main/jack-sys" -version = "0.3.4" +version = "0.4.0" [dependencies] -dlib = "0.5" -dlopen = {version = "0.1", optional = true} lazy_static = "1.4" libc = "0.2" libloading = "0.7" [build-dependencies] +bitflags = "1" pkg-config = "0.3" - -[features] -# If dlopen is set, then dlib must be used to call jack-sys functions. See -# https://github.com/vberger/dlib. -default = [] diff --git a/jack-sys/build.rs b/jack-sys/build.rs index f3a9a71b..f37e1ea5 100644 --- a/jack-sys/build.rs +++ b/jack-sys/build.rs @@ -1,14 +1,2010 @@ +use bitflags::bitflags; + +use std::io::Write; + +bitflags! { + struct FunctionFlags: u8 { + const NONE = 0b00000000; + const WEAK = 0b00000001; + } +} + fn main() { - println!("cargo:rerun-if-env-changed=RUST_JACK_DLOPEN"); - let dlopen = std::env::var("RUST_JACK_DLOPEN").is_ok(); - if dlopen { - println!("cargo:rustc-cfg=feature=\"dlopen\""); + let out_dir = std::env::var_os("OUT_DIR").unwrap(); + let target_os = std::env::var("CARGO_CFG_TARGET_OS"); + match target_os.as_ref().map(|x| &**x) { + Ok("linux") => { + pkg_config::find_library("jack").unwrap(); + }, + _ => { + let _ = pkg_config::find_library("jack"); + }, + }; + let dest_path = std::path::Path::new(&out_dir).join("functions.rs"); + write_src(&dest_path, FUNCTIONS); + println!("cargo:rerun-if-changed=build.rs"); +} + +fn write_src(path: &std::path::Path, fns: &[Function]) { + let mut out = std::fs::File::create(path).unwrap(); + writeln!(out, "use crate::types::*;").unwrap(); + writeln!(out, "use lazy_static::lazy_static;").unwrap(); + writeln!(out, "pub struct JackFunctions {{").unwrap(); + for f in fns.iter() { + if f.flags.contains(FunctionFlags::WEAK) { + writeln!(out, + " {}_impl: Option {}>,", + f.name, + f.arg_types(), + f.ret + ).unwrap(); + } else { + writeln!(out, + " {}_impl: unsafe extern \"C\" fn({}) -> {},", + f.name, + f.arg_types(), + f.ret + ).unwrap(); + } + } + writeln!(out, "}}\n").unwrap(); + + writeln!(out, "lazy_static! {{").unwrap(); + writeln!(out, " static ref FUNCTIONS: JackFunctions = unsafe {{").unwrap(); + writeln!(out, " let library = crate::library().unwrap();").unwrap(); + for f in fns.iter() { + if f.flags.contains(FunctionFlags::WEAK) { + writeln!(out, + " let {}_impl = library.get:: {}>(b\"{}\").ok();", + f.name, + f.args_full(), + f.ret, + f.name, + ).unwrap(); + writeln!(out, + " let {}_impl = {}_impl.map(|sym| sym.into_raw());", + f.name, f.name + ).unwrap(); + writeln!(out, + " let {}_impl = {}_impl.map(|sym| *sym.deref() as {});", + f.name, + f.name, + f.type_name() + ).unwrap(); + } else { + writeln!(out, + " let {}_impl = library.get:: {}>(b\"{}\").unwrap();", + f.name, + f.args_full(), + f.ret, + f.name, + ).unwrap(); + writeln!(out, " let {}_impl = {}_impl.into_raw();", f.name, f.name).unwrap(); + writeln!(out, + " let {}_impl = *{}_impl.deref() as {};", + f.name, + f.name, + f.type_name() + ).unwrap(); + } + } + writeln!(out, " JackFunctions {{").unwrap(); + for f in fns.iter() { + writeln!(out, " {}_impl,", f.name).unwrap(); + } + writeln!(out, " }}").unwrap(); + writeln!(out, " }};\n").unwrap(); + writeln!(out, "}}\n").unwrap(); + + for f in fns.iter() { + if f.flags.contains(FunctionFlags::WEAK) { + writeln!(out, + "pub unsafe fn {}({}) -> Option<{}> {{", + f.name, + f.args_full(), + f.ret + ).unwrap(); + writeln!(out, " let f = FUNCTIONS.{}_impl?;", f.name).unwrap(); + writeln!(out, " Some(f({}))", f.arg_names()).unwrap(); + } else { + writeln!(out, + "pub unsafe fn {}({}) -> {} {{", + f.name, + f.args_full(), + f.ret + ).unwrap(); + writeln!(out, " let f = FUNCTIONS.{}_impl;", f.name).unwrap(); + writeln!(out, " f({})", f.arg_names()).unwrap(); + } + writeln!(out, "}}").unwrap(); + } +} + +struct Function { + name: &'static str, + args: &'static [(&'static str, &'static str)], + ret: &'static str, + flags: FunctionFlags, +} + +impl Function { + fn args_full(&self) -> String { + let mut args = String::new(); + for &(name, ty) in self.args.iter() { + if !args.is_empty() { + args.push_str(", "); + } + if !name.is_empty() { + args.push_str(name); + args.push_str(": "); + } + args.push_str(ty); + } + args + } + + fn arg_types(&self) -> String { + let mut args = String::new(); + for &(_, ty) in self.args.iter() { + if !args.is_empty() { + args.push_str(", "); + } + args.push_str(ty); + } + args + } + + fn arg_names(&self) -> String { + let mut args = String::new(); + for &(name, _) in self.args.iter() { + if !args.is_empty() { + args.push_str(", "); + } + args.push_str(name); + } + args } - if !(dlopen || cfg!(feature = "dlopen")) { - // pkg-config is required to find PipeWire's implementation of libjack - // Refer to https://github.com/RustAudio/rust-jack/issues/142 for details. - // Do not unwrap this because linking might still work if pkg-config is - // not installed, for example on Windows. - pkg_config::find_library("jack").unwrap(); + + fn type_name(&self) -> String { + format!( + "unsafe extern \"C\" fn({}) -> {}", + self.args_full(), + self.ret + ) } } + +const FUNCTIONS: &[Function] = &[ + Function { + name: "jack_release_timebase", + args: &[("client", "*mut jack_client_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_get_cycle_times", + args: &[ + ("client", "*const jack_client_t"), + ("current_frames", "*mut jack_nframes_t"), + ("current_usecs", "*mut jack_time_t"), + ("next_usecs", "*mut jack_time_t"), + ("period_usecs", "*mut ::libc::c_float"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::WEAK, + }, + Function { + name: "jack_set_sync_callback", + args: &[ + ("client", "*mut jack_client_t"), + ("sync_callback", "JackSyncCallback"), + ("sync_arg", "*mut ::libc::c_void"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_set_sync_timeout", + args: &[("client", "*mut jack_client_t"), ("timeout", "jack_time_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_set_timebase_callback", + args: &[ + ("client", "*mut jack_client_t"), + ("conditional", "::libc::c_int"), + ("timebase_callback", "TimebaseCallback"), + ("arg", "*mut ::libc::c_void"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_transport_locate", + args: &[ + ("client", "*mut jack_client_t"), + ("frame", "jack_nframes_t"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_transport_query", + args: &[ + ("client", "*const jack_client_t"), + ("pos", "*mut jack_position_t"), + ], + ret: "jack_transport_state_t", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_get_current_transport_frame", + args: &[("client", "*const jack_client_t")], + ret: "jack_nframes_t", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_transport_reposition", + args: &[ + ("client", "*mut jack_client_t"), + ("pos", "*const jack_position_t"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_transport_start", + args: &[("client", "*mut jack_client_t")], + ret: "()", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_transport_stop", + args: &[("client", "*mut jack_client_t")], + ret: "()", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_get_transport_info", + args: &[ + ("client", "*mut jack_client_t"), + ("tinfo", "*mut jack_transport_info_t"), + ], + ret: "()", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_set_transport_info", + args: &[ + ("client", "*mut jack_client_t"), + ("tinfo", "*mut jack_transport_info_t"), + ], + ret: "()", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_client_open", + args: &[ + ("client_name", "*const ::libc::c_char"), + ("options", "jack_options_t"), + ("status", "*mut jack_status_t"), + // Varargs not supported + // ("", "..."), + ], + ret: "*mut jack_client_t", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_client_new", + args: &[("client_name", "*const ::libc::c_char")], + ret: "*mut jack_client_t", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_client_close", + args: &[("client", "*mut jack_client_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_client_name_size", + args: &[], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_get_client_name", + args: &[("client", "*mut jack_client_t")], + ret: "*mut ::libc::c_char", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_get_uuid_for_client_name", + args: &[ + ("client", "*mut jack_client_t"), + ("client_name", "*const ::libc::c_char"), + ], + ret: "*mut ::libc::c_char", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_get_client_name_by_uuid", + args: &[ + ("client", "*mut jack_client_t"), + ("client_uuid", "*const ::libc::c_char"), + ], + ret: "*mut ::libc::c_char", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_internal_client_new", + args: &[ + ("client_name", "*const ::libc::c_char"), + ("load_name", "*const ::libc::c_char"), + ("load_init", "*const ::libc::c_char"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::WEAK, + }, + Function { + name: "jack_internal_client_close", + args: &[("client_name", "*const ::libc::c_char")], + ret: "()", + flags: FunctionFlags::WEAK, + }, + Function { + name: "jack_activate", + args: &[("client", "*mut jack_client_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_deactivate", + args: &[("client", "*mut jack_client_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_get_client_pid", + args: &[("name", "*const ::libc::c_char")], + ret: "::libc::c_int", + flags: FunctionFlags::WEAK, + }, + // #[cfg(not(target_os = "windows"))] + // pub fn jack_client_thread_id(client: *mut jack_client_t) -> jack_native_thread_t; + Function { + name: "jack_is_realtime", + args: &[("client", "*mut jack_client_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_thread_wait", + args: &[ + ("client", "*mut jack_client_t"), + ("status", "::libc::c_int"), + ], + ret: "jack_nframes_t", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_cycle_wait", + args: &[("client", "*mut jack_client_t")], + ret: "jack_nframes_t", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_cycle_signal", + args: &[ + ("client", "*mut jack_client_t"), + ("status", "::libc::c_int"), + ], + ret: "()", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_set_process_thread", + args: &[ + ("client", "*mut jack_client_t"), + ("thread_callback", "JackThreadCallback"), + ("arg", "*mut ::libc::c_void"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_set_thread_init_callback", + args: &[ + ("client", "*mut jack_client_t"), + ("thread_init_callback", "JackThreadInitCallback"), + ("arg", "*mut ::libc::c_void"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_on_shutdown", + args: &[ + ("client", "*mut jack_client_t"), + ("callback", "JackShutdownCallback"), + ("arg", "*mut ::libc::c_void"), + ], + ret: "()", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_on_info_shutdown", + args: &[ + ("client", "*mut jack_client_t"), + ("callback", "JackInfoShutdownCallback"), + ("arg", "*mut ::libc::c_void"), + ], + ret: "()", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_set_process_callback", + args: &[ + ("client", "*mut jack_client_t"), + ("process_callback", "JackProcessCallback"), + ("arg", "*mut ::libc::c_void"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_set_freewheel_callback", + args: &[ + ("client", "*mut jack_client_t"), + ("freewheel_callback", "JackFreewheelCallback"), + ("arg", "*mut ::libc::c_void"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_set_buffer_size_callback", + args: &[ + ("client", "*mut jack_client_t"), + ("bufsize_callback", "JackBufferSizeCallback"), + ("arg", "*mut ::libc::c_void"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_get_sample_rate", + args: &[ + ("client", "*mut jack_client_t"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_set_sample_rate_callback", + args: &[ + ("client", "*mut jack_client_t"), + ("srate_callback", "JackSampleRateCallback"), + ("arg", "*mut ::libc::c_void"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_set_client_registration_callback", + args: &[ + ("client", "*mut jack_client_t"), + ("registration_callback", "JackClientRegistrationCallback"), + ("arg", "*mut ::libc::c_void"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_set_port_registration_callback", + args: &[ + ("client", "*mut jack_client_t"), + ("registration_callback", "JackPortRegistrationCallback"), + ("arg", "*mut ::libc::c_void"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_set_port_connect_callback", + args: &[ + ("client", "*mut jack_client_t"), + ("connect_callback", "JackPortConnectCallback"), + ("arg", "*mut ::libc::c_void"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_set_port_rename_callback", + args: &[ + ("client", "*mut jack_client_t"), + ("rename_callback", "JackPortRenameCallback"), + ("arg", "*mut ::libc::c_void"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_set_graph_order_callback", + args: &[ + ("client", "*mut jack_client_t"), + ("graph_callback", "JackGraphOrderCallback"), + ("arg", "*mut ::libc::c_void"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_set_xrun_callback", + args: &[ + ("client", "*mut jack_client_t"), + ("xrun_callback", "JackXRunCallback"), + ("arg", "*mut ::libc::c_void"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_set_latency_callback", + args: &[ + ("client", "*mut jack_client_t"), + ("latency_callback", "JackLatencyCallback"), + ("arg", "*mut ::libc::c_void"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_set_freewheel", + args: &[("client", "*mut jack_client_t"), ("onoff", "::libc::c_int")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_set_buffer_size", + args: &[ + ("client", "*mut jack_client_t"), + ("nframes", "jack_nframes_t"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_get_buffer_size", + args: &[("client", "*mut jack_client_t")], + ret: "jack_nframes_t", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_engine_takeover_timebase", + args: &[("client", "*mut jack_client_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_cpu_load", + args: &[("client", "*mut jack_client_t")], + ret: "::libc::c_float", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_register", + args: &[ + ("client", "*mut jack_client_t"), + ("port_name", "*const ::libc::c_char"), + ("port_type", "*const ::libc::c_char"), + ("flags", "::libc::c_ulong"), + ("buffer_size", "::libc::c_ulong"), + ], + ret: "*mut jack_port_t", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_unregister", + args: &[ + ("client", "*mut jack_client_t"), + ("port", "*mut jack_port_t"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_get_buffer", + args: &[("port", "*mut jack_port_t"), ("nframes", "jack_nframes_t")], + ret: "*mut ::libc::c_void", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_uuid", + args: &[("port", "*mut jack_port_t")], + ret: "jack_uuid_t", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_name", + args: &[("port", "*mut jack_port_t")], + ret: "*const ::libc::c_char", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_short_name", + args: &[("port", "*mut jack_port_t")], + ret: "*const ::libc::c_char", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_flags", + args: &[("port", "*mut jack_port_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_type", + args: &[("port", "*const jack_port_t")], + ret: "*const ::libc::c_char", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_type_id", + args: &[("port", "*const jack_port_t")], + ret: "jack_port_type_id_t", + flags: FunctionFlags::WEAK, + }, + Function { + name: "jack_port_is_mine", + args: &[ + ("client", "*const jack_client_t"), + ("port", "*const jack_port_t"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_connected", + args: &[("port", "*const jack_port_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_connected_to", + args: &[ + ("port", "*const jack_port_t"), + ("port_name", "*const ::libc::c_char"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_get_connections", + args: &[("port", "*const jack_port_t")], + ret: "*mut *const ::libc::c_char", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_get_all_connections", + args: &[ + ("client", "*const jack_client_t"), + ("port", "*const jack_port_t"), + ], + ret: "*mut *const ::libc::c_char", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_tie", + args: &[("src", "*mut jack_port_t"), ("dst", "*mut jack_port_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_untie", + args: &[("port", "*mut jack_port_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_set_name", + args: &[ + ("port", "*mut jack_port_t"), + ("port_name", "*const ::libc::c_char"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_set_alias", + args: &[ + ("port", "*mut jack_port_t"), + ("alias", "*const ::libc::c_char"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_unset_alias", + args: &[ + ("port", "*mut jack_port_t"), + ("alias", "*const ::libc::c_char"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_get_aliases", + args: &[ + ("port", "*const jack_port_t"), + ("aliases", "*mut *mut ::libc::c_char"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_request_monitor", + args: &[("port", "*mut jack_port_t"), ("onoff", "::libc::c_int")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_request_monitor_by_name", + args: &[ + ("client", "*mut jack_client_t"), + ("port_name", "*const ::libc::c_char"), + ("onoff", "::libc::c_int"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_ensure_monitor", + args: &[("port", "*mut jack_port_t"), ("onoff", "::libc::c_int")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_port_monitoring_input", + args: &[("port", "*mut jack_port_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_connect", + args: &[ + ("client", "*mut jack_client_t"), + ("source_port", "*const ::libc::c_char"), + ("destination_port", "*const ::libc::c_char"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_disconnect( + // client: *mut jack_client_t, + // source_port: *const ::libc::c_char, + // destination_port: *const ::libc::c_char, + // ) -> ::libc::c_int; + Function { + name: "jack_disconnect", + args: &[ + ("client", "*mut jack_client_t"), + ("source_port", "*const ::libc::c_char"), + ("destination_port", "*const ::libc::c_char"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_port_disconnect(client: *mut jack_client_t, port: *mut jack_port_t) -> ::libc::c_int; + Function { + name: "jack_port_disconnect", + args: &[ + ("client", "*mut jack_client_t"), + ("port", "*mut jack_port_t"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_port_name_size() -> ::libc::c_int; + Function { + name: "jack_port_name_size", + args: &[], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_port_type_size() -> ::libc::c_int; + Function { + name: "jack_port_type_size", + args: &[], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_port_type_get_buffer_size( + // client: *mut jack_client_t, + // port_type: *const ::libc::c_char, + // ) -> ::libc::size_t; + Function { + name: "jack_port_type_get_buffer_size", + args: &[ + ("client", "*mut jack_client_t"), + ("port_type", "*const ::libc::c_char"), + ], + ret: "::libc::size_t", + flags: FunctionFlags::NONE, + }, + // pub fn jack_port_set_latency(port: *mut jack_port_t, arg1: jack_nframes_t) -> (); + Function { + name: "jack_port_set_latency", + args: &[("port", "*mut jack_port_t"), ("arg1", "jack_nframes_t")], + ret: "()", + flags: FunctionFlags::NONE, + }, + // pub fn jack_port_get_latency_range( + // port: *mut jack_port_t, + // mode: jack_latency_callback_mode_t, + // range: *mut jack_latency_range_t, + // ) -> (); + Function { + name: "jack_port_get_latency_range", + args: &[ + ("port", "*mut jack_port_t"), + ("mode", "jack_latency_callback_mode_t"), + ("range", "*mut jack_latency_range_t"), + ], + ret: "()", + flags: FunctionFlags::NONE, + }, + // pub fn jack_port_set_latency_range( + // port: *mut jack_port_t, + // mode: jack_latency_callback_mode_t, + // range: *mut jack_latency_range_t, + // ) -> (); + Function { + name: "jack_port_set_latency_range", + args: &[ + ("port", "*mut jack_port_t"), + ("mode", "jack_latency_callback_mode_t"), + ("range", "*mut jack_latency_range_t"), + ], + ret: "()", + flags: FunctionFlags::NONE, + }, + // pub fn jack_recompute_total_latencies(client: *mut jack_client_t) -> ::libc::c_int; + Function { + name: "jack_recompute_total_latencies", + args: &[("client", "*mut jack_client_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_port_get_latency(port: *mut jack_port_t) -> jack_nframes_t; + Function { + name: "jack_port_get_latency", + args: &[("port", "*mut jack_port_t")], + ret: "jack_nframes_t", + flags: FunctionFlags::NONE, + }, + // pub fn jack_port_get_total_latency( + // client: *mut jack_client_t, + // port: *mut jack_port_t, + // ) -> jack_nframes_t; + Function { + name: "jack_port_get_total_latency", + args: &[ + ("client", "*mut jack_client_t"), + ("port", "*mut jack_port_t"), + ], + ret: "jack_nframes_t", + flags: FunctionFlags::NONE, + }, + // pub fn jack_recompute_total_latency( + // arg1: *mut jack_client_t, + // port: *mut jack_port_t, + // ) -> ::libc::c_int; + Function { + name: "jack_recompute_total_latency", + args: &[("arg1", "*mut jack_client_t"), ("port", "*mut jack_port_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_get_ports( + // client: *mut jack_client_t, + // port_name_pattern: *const ::libc::c_char, + // type_name_pattern: *const ::libc::c_char, + // flags: ::libc::c_ulong, + // ) -> *mut *const ::libc::c_char; + Function { + name: "jack_get_ports", + args: &[ + ("client", "*mut jack_client_t"), + ("port_name_pattern", "*const ::libc::c_char"), + ("type_name_pattern", "*const ::libc::c_char"), + ("flags", "::libc::c_ulong"), + ], + ret: "*mut *const ::libc::c_char", + flags: FunctionFlags::NONE, + }, + // pub fn jack_port_by_name( + // client: *mut jack_client_t, + // port_name: *const ::libc::c_char, + // ) -> *mut jack_port_t; + Function { + name: "jack_port_by_name", + args: &[ + ("client", "*mut jack_client_t"), + ("port_name", "*const ::libc::c_char"), + ], + ret: "*mut jack_port_t", + flags: FunctionFlags::NONE, + }, + // pub fn jack_port_by_id(client: *mut jack_client_t, port_id: jack_port_id_t) -> *mut jack_port_t; + Function { + name: "jack_port_by_id", + args: &[ + ("client", "*mut jack_client_t"), + ("port_id", "jack_port_id_t"), + ], + ret: "*mut jack_port_t", + flags: FunctionFlags::NONE, + }, + // pub fn jack_frames_since_cycle_start(arg1: *const jack_client_t) -> jack_nframes_t; + Function { + name: "jack_frames_since_cycle_start", + args: &[("arg1", "*const jack_client_t")], + ret: "jack_nframes_t", + flags: FunctionFlags::NONE, + }, + // pub fn jack_frame_time(arg1: *const jack_client_t) -> jack_nframes_t; + Function { + name: "jack_frame_time", + args: &[("arg1", "*const jack_client_t")], + ret: "jack_nframes_t", + flags: FunctionFlags::NONE, + }, + // pub fn jack_last_frame_time(client: *const jack_client_t) -> jack_nframes_t; + Function { + name: "jack_last_frame_time", + args: &[("client", "*const jack_client_t")], + ret: "jack_nframes_t", + flags: FunctionFlags::NONE, + }, + // pub fn jack_frames_to_time(client: *const jack_client_t, arg1: jack_nframes_t) -> jack_time_t; + Function { + name: "jack_frames_to_time", + args: &[ + ("client", "*const jack_client_t"), + ("arg1", "jack_nframes_t"), + ], + ret: "jack_time_t", + flags: FunctionFlags::NONE, + }, + // pub fn jack_time_to_frames(client: *const jack_client_t, arg1: jack_time_t) -> jack_nframes_t; + Function { + name: "jack_time_to_frames", + args: &[("client", "*const jack_client_t"), ("arg1", "jack_time_t")], + ret: "jack_nframes_t", + flags: FunctionFlags::NONE, + }, + // pub fn jack_get_time() -> jack_time_t; + Function { + name: "jack_get_time", + args: &[], + ret: "jack_time_t", + flags: FunctionFlags::NONE, + }, + // pub fn jack_set_error_function( + // func: ::std::option::Option ()>, + // ) -> (); + Function { + name: "jack_set_error_function", + args: &[( + "func", + "::std::option::Option ()>", + )], + ret: "()", + flags: FunctionFlags::NONE, + }, + // pub fn jack_set_info_function( + // func: ::std::option::Option ()>, + // ) -> (); + Function { + name: "jack_set_info_function", + args: &[( + "func", + "::std::option::Option ()>", + )], + ret: "()", + flags: FunctionFlags::NONE, + }, + // pub fn jack_free(ptr: *mut ::libc::c_void) -> (); + Function { + name: "jack_free", + args: &[("ptr", "*mut ::libc::c_void")], + ret: "()", + flags: FunctionFlags::NONE, + }, + // pub fn jack_client_real_time_priority(arg1: *mut jack_client_t) -> ::libc::c_int; + Function { + name: "jack_client_real_time_priority", + args: &[("arg1", "*mut jack_client_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_client_max_real_time_priority(arg1: *mut jack_client_t) -> ::libc::c_int; + Function { + name: "jack_client_max_real_time_priority", + args: &[("arg1", "*mut jack_client_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // #[cfg(not(target_os = "windows"))] + // pub fn jack_acquire_real_time_scheduling( + // thread: jack_native_thread_t, + // priority: ::libc::c_int, + // ) -> ::libc::c_int; + // #[cfg(not(target_os = "windows"))] + // pub fn jack_client_create_thread( + // client: *mut jack_client_t, + // thread: *mut jack_native_thread_t, + // priority: ::libc::c_int, + // realtime: ::libc::c_int, + // start_routine: ::std::option::Option< + // unsafe extern "C" fn(arg1: *mut ::libc::c_void) -> *mut ::libc::c_void, + // >, + // arg: *mut ::libc::c_void, + // ) -> ::libc::c_int; + // #[cfg(not(target_os = "windows"))] + // pub fn jack_drop_real_time_scheduling(thread: jack_native_thread_t) -> ::libc::c_int; + // #[cfg(not(target_os = "windows"))] + // pub fn jack_client_stop_thread( + // client: *mut jack_client_t, + // thread: jack_native_thread_t, + // ) -> ::libc::c_int; + // #[cfg(not(target_os = "windows"))] + // pub fn jack_client_kill_thread( + // client: *mut jack_client_t, + // thread: jack_native_thread_t, + // ) -> ::libc::c_int; + // #[cfg(not(target_os = "windows"))] + // pub fn jack_set_thread_creator(creator: jack_thread_creator_t) -> (); + // pub fn jack_set_session_callback( + // client: *mut jack_client_t, + // session_callback: JackSessionCallback, + // arg: *mut ::libc::c_void, + // ) -> ::libc::c_int; + Function { + name: "jack_set_session_callback", + args: &[ + ("client", "*mut jack_client_t"), + ("session_callback", "JackSessionCallback"), + ("arg", "*mut ::libc::c_void"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_session_reply( + // client: *mut jack_client_t, + // event: *mut jack_session_event_t, + // ) -> ::libc::c_int; + Function { + name: "jack_session_reply", + args: &[ + ("client", "*mut jack_client_t"), + ("event", "*mut jack_session_event_t"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_session_event_free(event: *mut jack_session_event_t) -> (); + Function { + name: "jack_session_event_free", + args: &[("event", "*mut jack_session_event_t")], + ret: "()", + flags: FunctionFlags::NONE, + }, + // pub fn jack_client_get_uuid(client: *mut jack_client_t) -> *mut ::libc::c_char; + Function { + name: "jack_client_get_uuid", + args: &[("client", "*mut jack_client_t")], + ret: "*mut ::libc::c_char", + flags: FunctionFlags::NONE, + }, + // pub fn jack_session_notify( + // client: *mut jack_client_t, + // target: *const ::libc::c_char, + // _type: jack_session_event_type_t, + // path: *const ::libc::c_char, + // ) -> *mut jack_session_command_t; + Function { + name: "jack_session_notify", + args: &[ + ("client", "*mut jack_client_t"), + ("target", "*const ::libc::c_char"), + ("_type", "jack_session_event_type_t"), + ("path", "*const ::libc::c_char"), + ], + ret: "*mut jack_session_command_t", + flags: FunctionFlags::NONE, + }, + // pub fn jack_session_commands_free(cmds: *mut jack_session_command_t) -> (); + Function { + name: "jack_session_commands_free", + args: &[("cmds", "*mut jack_session_command_t")], + ret: "()", + flags: FunctionFlags::NONE, + }, + // pub fn jack_reserve_client_name( + // client: *mut jack_client_t, + // name: *const ::libc::c_char, + // uuid: *const ::libc::c_char, + // ) -> ::libc::c_int; + Function { + name: "jack_reserve_client_name", + args: &[ + ("client", "*mut jack_client_t"), + ("name", "*const ::libc::c_char"), + ("uuid", "*const ::libc::c_char"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_client_has_session_callback( + // client: *mut jack_client_t, + // client_name: *const ::libc::c_char, + // ) -> ::libc::c_int; + Function { + name: "jack_client_has_session_callback", + args: &[ + ("client", "*mut jack_client_t"), + ("client_name", "*const ::libc::c_char"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jackctl_setup_signals(flags: ::libc::c_uint) -> *mut jackctl_sigmask_t; + Function { + name: "jackctl_setup_signals", + args: &[("flags", "::libc::c_uint")], + ret: "*mut jackctl_sigmask_t", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_wait_signals(signals: *mut jackctl_sigmask_t) -> (); + Function { + name: "jackctl_wait_signals", + args: &[("signals", "*mut jackctl_sigmask_t")], + ret: "()", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_server_create( + // on_device_acquire: ::std::option::Option< + // unsafe extern "C" fn(device_name: *const ::libc::c_char) -> u8, + // >, + // on_device_release: ::std::option::Option< + // unsafe extern "C" fn(device_name: *const ::libc::c_char) -> (), + // >, + // ) -> *mut jackctl_server_t; + Function { + name: "jackctl_server_create", + args: &[ + ("on_device_acquire", "::std::option::Option u8>"), + ("on_device_release", "::std::option::Option ()>"), + ], + ret: "*mut jackctl_server_t", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_server_destroy(server: *mut jackctl_server_t) -> (); + Function { + name: "jackctl_server_destroy", + args: &[("server", "*mut jackctl_server_t")], + ret: "()", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_server_open(server: *mut jackctl_server_t, driver: *mut jackctl_driver_t) -> u8; + Function { + name: "jackctl_server_open", + args: &[ + ("server", "*mut jackctl_server_t"), + ("driver", "*mut jackctl_driver_t"), + ], + ret: "u8", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_server_start(server: *mut jackctl_server_t) -> u8; + Function { + name: "jackctl_server_start", + args: &[("server", "*mut jackctl_server_t")], + ret: "u8", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_server_stop(server: *mut jackctl_server_t) -> u8; + Function { + name: "jackctl_server_stop", + args: &[("server", "*mut jackctl_server_t")], + ret: "u8", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_server_close(server: *mut jackctl_server_t) -> u8; + Function { + name: "jackctl_server_close", + args: &[("server", "*mut jackctl_server_t")], + ret: "u8", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_server_get_drivers_list(server: *mut jackctl_server_t) -> *const JSList; + Function { + name: "jackctl_server_get_drivers_list", + args: &[("server", "*mut jackctl_server_t")], + ret: "*const JSList", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_server_get_parameters(server: *mut jackctl_server_t) -> *const JSList; + Function { + name: "jackctl_server_get_parameters", + args: &[("server", "*mut jackctl_server_t")], + ret: "*const JSList", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_server_get_internals_list(server: *mut jackctl_server_t) -> *const JSList; + Function { + name: "jackctl_server_get_internals_list", + args: &[("server", "*mut jackctl_server_t")], + ret: "*const JSList", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_server_load_internal( + // server: *mut jackctl_server_t, + // internal: *mut jackctl_internal_t, + // ) -> u8; + Function { + name: "jackctl_server_load_internal", + args: &[ + ("server", "*mut jackctl_server_t"), + ("internal", "*mut jackctl_internal_t"), + ], + ret: "u8", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_server_unload_internal( + // server: *mut jackctl_server_t, + // internal: *mut jackctl_internal_t, + // ) -> u8; + Function { + name: "jackctl_server_unload_internal", + args: &[ + ("server", "*mut jackctl_server_t"), + ("internal", "*mut jackctl_internal_t"), + ], + ret: "u8", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_server_add_slave(server: *mut jackctl_server_t, driver: *mut jackctl_driver_t) + // -> u8; + Function { + name: "jackctl_server_add_slave", + args: &[ + ("server", "*mut jackctl_server_t"), + ("driver", "*mut jackctl_driver_t"), + ], + ret: "u8", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_server_remove_slave( + // server: *mut jackctl_server_t, + // driver: *mut jackctl_driver_t, + // ) -> u8; + Function { + name: "jackctl_server_remove_slave", + args: &[ + ("server", "*mut jackctl_server_t"), + ("driver", "*mut jackctl_driver_t"), + ], + ret: "u8", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_server_switch_master( + // server: *mut jackctl_server_t, + // driver: *mut jackctl_driver_t, + // ) -> u8; + Function { + name: "jackctl_server_switch_master", + args: &[ + ("server", "*mut jackctl_server_t"), + ("driver", "*mut jackctl_driver_t"), + ], + ret: "u8", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_driver_get_name(driver: *mut jackctl_driver_t) -> *const ::libc::c_char; + Function { + name: "jackctl_driver_get_name", + args: &[("driver", "*mut jackctl_driver_t")], + ret: "*const ::libc::c_char", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_driver_get_type(driver: *mut jackctl_driver_t) -> jackctl_driver_type_t; + Function { + name: "jackctl_driver_get_type", + args: &[("driver", "*mut jackctl_driver_t")], + ret: "jackctl_driver_type_t", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_driver_get_parameters(driver: *mut jackctl_driver_t) -> *const JSList; + Function { + name: "jackctl_driver_get_parameters", + args: &[("driver", "*mut jackctl_driver_t")], + ret: "*const JSList", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_driver_params_parse( + // driver: *mut jackctl_driver_t, + // argc: ::libc::c_int, + // argv: *mut *mut ::libc::c_char, + // ) -> ::libc::c_int; + Function { + name: "jackctl_driver_params_parse", + args: &[ + ("driver", "*mut jackctl_driver_t"), + ("argc", "::libc::c_int"), + ("argv", "*mut *mut ::libc::c_char"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_internal_get_name(internal: *mut jackctl_internal_t) -> *const ::libc::c_char; + Function { + name: "jackctl_internal_get_name", + args: &[("internal", "*mut jackctl_internal_t")], + ret: "*const ::libc::c_char", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_internal_get_parameters(internal: *mut jackctl_internal_t) -> *const JSList; + Function { + name: "jackctl_internal_get_parameters", + args: &[("internal", "*mut jackctl_internal_t")], + ret: "*const JSList", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_parameter_get_name(parameter: *mut jackctl_parameter_t) -> *const ::libc::c_char; + Function { + name: "jackctl_parameter_get_name", + args: &[("parameter", "*mut jackctl_parameter_t")], + ret: "*const ::libc::c_char", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_parameter_get_short_description( + // parameter: *mut jackctl_parameter_t, + // ) -> *const ::libc::c_char; + Function { + name: "jackctl_parameter_get_short_description", + args: &[("parameter", "*mut jackctl_parameter_t")], + ret: "*const ::libc::c_char", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_parameter_get_long_description( + // parameter: *mut jackctl_parameter_t, + // ) -> *const ::libc::c_char; + Function { + name: "jackctl_parameter_get_long_description", + args: &[("parameter", "*mut jackctl_parameter_t")], + ret: "*const ::libc::c_char", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_parameter_get_type(parameter: *mut jackctl_parameter_t) -> jackctl_param_type_t; + Function { + name: "jackctl_parameter_get_type", + args: &[("parameter", "*mut jackctl_parameter_t")], + ret: "jackctl_param_type_t", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_parameter_get_id(parameter: *mut jackctl_parameter_t) -> ::libc::c_char; + Function { + name: "jackctl_parameter_get_id", + args: &[("parameter", "*mut jackctl_parameter_t")], + ret: "::libc::c_char", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_parameter_is_set(parameter: *mut jackctl_parameter_t) -> u8; + Function { + name: "jackctl_parameter_is_set", + args: &[("parameter", "*mut jackctl_parameter_t")], + ret: "u8", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_parameter_reset(parameter: *mut jackctl_parameter_t) -> u8; + Function { + name: "jackctl_parameter_reset", + args: &[("parameter", "*mut jackctl_parameter_t")], + ret: "u8", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_parameter_get_value( + // parameter: *mut jackctl_parameter_t, + // ) -> Union_jackctl_parameter_value; + Function { + name: "jackctl_parameter_get_value", + args: &[("parameter", "*mut jackctl_parameter_t")], + ret: "Union_jackctl_parameter_value", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_parameter_set_value( + // parameter: *mut jackctl_parameter_t, + // value_ptr: *const Union_jackctl_parameter_value, + // ) -> u8; + Function { + name: "jackctl_parameter_set_value", + args: &[ + ("parameter", "*mut jackctl_parameter_t"), + ("value_ptr", "*const Union_jackctl_parameter_value"), + ], + ret: "u8", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_parameter_get_default_value( + // parameter: *mut jackctl_parameter_t, + // ) -> Union_jackctl_parameter_value; + Function { + name: "jackctl_parameter_get_default_value", + args: &[("parameter", "*mut jackctl_parameter_t")], + ret: "Union_jackctl_parameter_value", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_parameter_has_range_constraint(parameter: *mut jackctl_parameter_t) -> u8; + Function { + name: "jackctl_parameter_has_range_constraint", + args: &[("parameter", "*mut jackctl_parameter_t")], + ret: "u8", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_parameter_has_enum_constraint(parameter: *mut jackctl_parameter_t) -> u8; + Function { + name: "jackctl_parameter_has_enum_constraint", + args: &[("parameter", "*mut jackctl_parameter_t")], + ret: "u8", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_parameter_get_enum_constraints_count(parameter: *mut jackctl_parameter_t) -> u32; + Function { + name: "jackctl_parameter_get_enum_constraints_count", + args: &[("parameter", "*mut jackctl_parameter_t")], + ret: "u32", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_parameter_get_enum_constraint_value( + // parameter: *mut jackctl_parameter_t, + // index: u32, + // ) -> Union_jackctl_parameter_value; + Function { + name: "jackctl_parameter_get_enum_constraint_value", + args: &[ + ("parameter", "*mut jackctl_parameter_t"), + ("index", "u32"), + ], + ret: "Union_jackctl_parameter_value", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_parameter_get_enum_constraint_description( + // parameter: *mut jackctl_parameter_t, + // index: u32, + // ) -> *const ::libc::c_char; + Function { + name: "jackctl_parameter_get_enum_constraint_description", + args: &[ + ("parameter", "*mut jackctl_parameter_t"), + ("index", "u32"), + ], + ret: "*const ::libc::c_char", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_parameter_get_range_constraint( + // parameter: *mut jackctl_parameter_t, + // min_ptr: *mut Union_jackctl_parameter_value, + // max_ptr: *mut Union_jackctl_parameter_value, + // ) -> (); + Function { + name: "jackctl_parameter_get_range_constraint", + args: &[ + ("parameter", "*mut jackctl_parameter_t"), + ("min_ptr", "*mut Union_jackctl_parameter_value"), + ("max_ptr", "*mut Union_jackctl_parameter_value"), + ], + ret: "()", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_parameter_constraint_is_strict(parameter: *mut jackctl_parameter_t) -> u8; + Function { + name: "jackctl_parameter_constraint_is_strict", + args: &[("parameter", "*mut jackctl_parameter_t")], + ret: "u8", + flags: FunctionFlags::WEAK, + }, + // pub fn jackctl_parameter_constraint_is_fake_value(parameter: *mut jackctl_parameter_t) -> u8; + Function { + name: "jackctl_parameter_constraint_is_fake_value", + args: &[("parameter", "*mut jackctl_parameter_t")], + ret: "u8", + flags: FunctionFlags::WEAK, + }, + // pub fn jack_error(format: *const ::libc::c_char, ...) -> (); + // Function { + // name: "jack_error", + // args: &[ + // ("format", "*const ::libc::c_char"), + // // Varargs not yet supported. + // // (""..."), + // ], + // ret: "()", + // flags: FunctionFlags::NONE, + // }, + // pub fn jack_info(format: *const ::libc::c_char, ...) -> (); + // Function { + // name: "jack_info", + // args: &[ + // ("format", "*const ::libc::c_char"), + // // Varargs not yet supported. + // // ("", "..."), + // ], + // ret: "()", + // flags: FunctionFlags::NONE, + // }, + // pub fn jack_log(format: *const ::libc::c_char, ...) -> (); + // Function { + // name: "jack_log", + // args: &[ + // ("format", "*const ::libc::c_char"), + // // Varargs not yet supported. + // // ("", "..."), + // ], + // ret: "()", + // flags: FunctionFlags::NONE, + // }, + // pub fn jack_set_property( + // arg1: *mut jack_client_t, + // subject: jack_uuid_t, + // key: *const ::libc::c_char, + // value: *const ::libc::c_char, + // _type: *const ::libc::c_char, + // ) -> ::libc::c_int; + Function { + name: "jack_set_property", + args: &[ + ("arg1", "*mut jack_client_t"), + ("subject", "jack_uuid_t"), + ("key", "*const ::libc::c_char"), + ("value", "*const ::libc::c_char"), + ("_type", "*const ::libc::c_char"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_get_property( + // subject: jack_uuid_t, + // key: *const ::libc::c_char, + // value: *mut *mut ::libc::c_char, + // _type: *mut *mut ::libc::c_char, + // ) -> ::libc::c_int; + Function { + name: "jack_get_property", + args: &[ + ("subject", "jack_uuid_t"), + ("key", "*const ::libc::c_char"), + ("value", "*mut *mut ::libc::c_char"), + ("_type", "*mut *mut ::libc::c_char"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_free_description( + // desc: *mut jack_description_t, + // free_description_itself: ::libc::c_int, + // ) -> (); + Function { + name: "jack_free_description", + args: &[ + ("desc", "*mut jack_description_t"), + ("free_description_itself", "::libc::c_int"), + ], + ret: "()", + flags: FunctionFlags::NONE, + }, + // pub fn jack_get_properties(subject: jack_uuid_t, desc: *mut jack_description_t) -> ::libc::c_int; + Function { + name: "jack_get_properties", + args: &[ + ("subject", "jack_uuid_t"), + ("desc", "*mut jack_description_t"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_get_all_properties(descs: *mut *mut jack_description_t) -> ::libc::c_int; + Function { + name: "jack_get_all_properties", + args: &[("descs", "*mut *mut jack_description_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_remove_property( + // client: *mut jack_client_t, + // subject: jack_uuid_t, + // key: *const ::libc::c_char, + // ) -> ::libc::c_int; + Function { + name: "jack_remove_property", + args: &[ + ("client", "*mut jack_client_t"), + ("subject", "jack_uuid_t"), + ("key", "*const ::libc::c_char"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_remove_properties(client: *mut jack_client_t, subject: jack_uuid_t) -> ::libc::c_int; + Function { + name: "jack_remove_properties", + args: &[("client", "*mut jack_client_t"), ("subject", "jack_uuid_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_remove_all_properties(client: *mut jack_client_t) -> ::libc::c_int; + Function { + name: "jack_remove_all_properties", + args: &[("client", "*mut jack_client_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_set_property_change_callback( + // client: *mut jack_client_t, + // callback: JackPropertyChangeCallback, + // arg: *mut ::libc::c_void, + // ) -> ::libc::c_int; + Function { + name: "jack_set_property_change_callback", + args: &[ + ("client", "*mut jack_client_t"), + ("callback", "JackPropertyChangeCallback"), + ("arg", "*mut ::libc::c_void"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_get_internal_client_name( + // client: *mut jack_client_t, + // intclient: jack_intclient_t, + // ) -> *mut ::libc::c_char; + Function { + name: "jack_get_internal_client_name", + args: &[ + ("client", "*mut jack_client_t"), + ("intclient", "jack_intclient_t"), + ], + ret: "*mut ::libc::c_char", + flags: FunctionFlags::WEAK, + }, + // pub fn jack_internal_client_handle( + // client: *mut jack_client_t, + // client_name: *const ::libc::c_char, + // status: *mut jack_status_t, + // ) -> jack_intclient_t; + Function { + name: "jack_internal_client_handle", + args: &[ + ("client", "*mut jack_client_t"), + ("client_name", "*const ::libc::c_char"), + ("status", "*mut jack_status_t"), + ], + ret: "jack_intclient_t", + flags: FunctionFlags::WEAK, + }, + // pub fn jack_internal_client_load( + // client: *mut jack_client_t, + // client_name: *const ::libc::c_char, + // options: jack_options_t, + // status: *mut jack_status_t, + // ... + // ) -> jack_intclient_t; + Function { + name: "jack_internal_client_load", + args: &[ + ("client", "*mut jack_client_t"), + ("client_name", "*const ::libc::c_char"), + ("options", "jack_options_t"), + ("status", "*mut jack_status_t"), + ("load_name", "*const ::libc::c_char"), + ("load_init", "*const ::libc::c_char"), + // Varargs not supported. + // ("", "..."), + ], + ret: "jack_intclient_t", + flags: FunctionFlags::WEAK, + }, + // pub fn jack_internal_client_unload( + // client: *mut jack_client_t, + // intclient: jack_intclient_t, + // ) -> jack_status_t; + Function { + name: "jack_internal_client_unload", + args: &[ + ("client", "*mut jack_client_t"), + ("intclient", "jack_intclient_t"), + ], + ret: "jack_status_t", + flags: FunctionFlags::WEAK, + }, + // pub fn jack_get_max_delayed_usecs(client: *mut jack_client_t) -> ::libc::c_float; + Function { + name: "jack_get_max_delayed_usecs", + args: &[("client", "*mut jack_client_t")], + ret: "::libc::c_float", + flags: FunctionFlags::NONE, + }, + // pub fn jack_get_xrun_delayed_usecs(client: *mut jack_client_t) -> ::libc::c_float; + Function { + name: "jack_get_xrun_delayed_usecs", + args: &[("client", "*mut jack_client_t")], + ret: "::libc::c_float", + flags: FunctionFlags::NONE, + }, + // pub fn jack_reset_max_delayed_usecs(client: *mut jack_client_t) -> (); + Function { + name: "jack_reset_max_delayed_usecs", + args: &[("client", "*mut jack_client_t")], + ret: "()", + flags: FunctionFlags::NONE, + }, + // pub fn jack_midi_get_event_count(port_buffer: *mut ::libc::c_void) -> u32; + Function { + name: "jack_midi_get_event_count", + args: &[("port_buffer", "*mut ::libc::c_void")], + ret: "u32", + flags: FunctionFlags::NONE, + }, + // pub fn jack_midi_event_get( + // event: *mut jack_midi_event_t, + // port_buffer: *mut ::libc::c_void, + // event_index: u32, + // ) -> ::libc::c_int; + Function { + name: "jack_midi_event_get", + args: &[ + ("event", "*mut jack_midi_event_t"), + ("port_buffer", "*mut ::libc::c_void"), + ("event_index", "u32"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_midi_clear_buffer(port_buffer: *mut ::libc::c_void) -> (); + Function { + name: "jack_midi_clear_buffer", + args: &[("port_buffer", "*mut ::libc::c_void")], + ret: "()", + flags: FunctionFlags::NONE, + }, + // pub fn jack_midi_max_event_size(port_buffer: *mut ::libc::c_void) -> ::libc::size_t; + Function { + name: "jack_midi_max_event_size", + args: &[("port_buffer", "*mut ::libc::c_void")], + ret: "::libc::size_t", + flags: FunctionFlags::NONE, + }, + // pub fn jack_midi_event_reserve( + // port_buffer: *mut ::libc::c_void, + // time: jack_nframes_t, + // data_size: ::libc::size_t, + // ) -> *mut jack_midi_data_t; + Function { + name: "jack_midi_event_reserve", + args: &[ + ("port_buffer", "*mut ::libc::c_void"), + ("time", "jack_nframes_t"), + ("data_size", "::libc::size_t"), + ], + ret: "*mut jack_midi_data_t", + flags: FunctionFlags::NONE, + }, + // pub fn jack_midi_event_write( + // port_buffer: *mut ::libc::c_void, + // time: jack_nframes_t, + // data: *const jack_midi_data_t, + // data_size: ::libc::size_t, + // ) -> ::libc::c_int; + Function { + name: "jack_midi_event_write", + args: &[ + ("port_buffer", "*mut ::libc::c_void"), + ("time", "jack_nframes_t"), + ("data", "*const jack_midi_data_t"), + ("data_size", "::libc::size_t"), + ], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_midi_get_lost_event_count(port_buffer: *mut ::libc::c_void) -> u32; + Function { + name: "jack_midi_get_lost_event_count", + args: &[("port_buffer", "*mut ::libc::c_void")], + ret: "u32", + flags: FunctionFlags::NONE, + }, + // pub fn jack_ringbuffer_create(sz: ::libc::size_t) -> *mut jack_ringbuffer_t; + Function { + name: "jack_ringbuffer_create", + args: &[("sz", "::libc::size_t")], + ret: "*mut jack_ringbuffer_t", + flags: FunctionFlags::NONE, + }, + // pub fn jack_ringbuffer_free(rb: *mut jack_ringbuffer_t) -> (); + Function { + name: "jack_ringbuffer_free", + args: &[("rb", "*mut jack_ringbuffer_t")], + ret: "()", + flags: FunctionFlags::NONE, + }, + // pub fn jack_ringbuffer_get_read_vector( + // rb: *const jack_ringbuffer_t, + // vec: *mut jack_ringbuffer_data_t, + // ) -> (); + Function { + name: "jack_ringbuffer_get_read_vector", + args: &[ + ("rb", "*const jack_ringbuffer_t"), + ("vec", "*mut jack_ringbuffer_data_t"), + ], + ret: "()", + flags: FunctionFlags::NONE, + }, + // pub fn jack_ringbuffer_get_write_vector( + // rb: *const jack_ringbuffer_t, + // vec: *mut jack_ringbuffer_data_t, + // ) -> (); + Function { + name: "jack_ringbuffer_get_write_vector", + args: &[ + ("rb", "*const jack_ringbuffer_t"), + ("vec", "*mut jack_ringbuffer_data_t"), + ], + ret: "()", + flags: FunctionFlags::NONE, + }, + // pub fn jack_ringbuffer_read( + // rb: *mut jack_ringbuffer_t, + // dest: *mut ::libc::c_char, + // cnt: ::libc::size_t, + // ) -> ::libc::size_t; + Function { + name: "jack_ringbuffer_read", + args: &[ + ("rb", "*mut jack_ringbuffer_t"), + ("dest", "*mut ::libc::c_char"), + ("cnt", "::libc::size_t"), + ], + ret: "::libc::size_t", + flags: FunctionFlags::NONE, + }, + // pub fn jack_ringbuffer_peek( + // rb: *mut jack_ringbuffer_t, + // dest: *mut ::libc::c_char, + // cnt: ::libc::size_t, + // ) -> ::libc::size_t; + Function { + name: "jack_ringbuffer_peek", + args: &[ + ("rb", "*mut jack_ringbuffer_t"), + ("dest", "*mut ::libc::c_char"), + ("cnt", "::libc::size_t"), + ], + ret: "::libc::size_t", + flags: FunctionFlags::NONE, + }, + // pub fn jack_ringbuffer_read_advance(rb: *mut jack_ringbuffer_t, cnt: ::libc::size_t) -> (); + Function { + name: "jack_ringbuffer_read_advance", + args: &[("rb", "*mut jack_ringbuffer_t"), ("cnt", "::libc::size_t")], + ret: "()", + flags: FunctionFlags::NONE, + }, + // pub fn jack_ringbuffer_read_space(rb: *const jack_ringbuffer_t) -> ::libc::size_t; + Function { + name: "jack_ringbuffer_read_space", + args: &[("rb", "*const jack_ringbuffer_t")], + ret: "::libc::size_t", + flags: FunctionFlags::NONE, + }, + // pub fn jack_ringbuffer_mlock(rb: *mut jack_ringbuffer_t) -> ::libc::c_int; + Function { + name: "jack_ringbuffer_mlock", + args: &[("rb", "*mut jack_ringbuffer_t")], + ret: "::libc::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_ringbuffer_reset(rb: *mut jack_ringbuffer_t) -> (); + Function { + name: "jack_ringbuffer_reset", + args: &[("rb", "*mut jack_ringbuffer_t")], + ret: "()", + flags: FunctionFlags::NONE, + }, + // pub fn jack_ringbuffer_write( + // rb: *mut jack_ringbuffer_t, + // src: *const ::libc::c_char, + // cnt: ::libc::size_t, + // ) -> ::libc::size_t; + Function { + name: "jack_ringbuffer_write", + args: &[ + ("rb", "*mut jack_ringbuffer_t"), + ("src", "*const ::libc::c_char"), + ("cnt", "::libc::size_t"), + ], + ret: "::libc::size_t", + flags: FunctionFlags::NONE, + }, + // pub fn jack_ringbuffer_write_advance(rb: *mut jack_ringbuffer_t, cnt: ::libc::size_t) -> (); + Function { + name: "jack_ringbuffer_write_advance", + args: &[("rb", "*mut jack_ringbuffer_t"), ("cnt", "::libc::size_t")], + ret: "()", + flags: FunctionFlags::NONE, + }, + // pub fn jack_ringbuffer_write_space(rb: *const jack_ringbuffer_t) -> ::libc::size_t; + Function { + name: "jack_ringbuffer_write_space", + args: &[("rb", "*const jack_ringbuffer_t")], + ret: "::libc::size_t", + flags: FunctionFlags::NONE, + }, + + // pub fn jack_uuid_to_index(arg1: jack_uuid_t) -> u32; + Function { + name: "jack_uuid_to_index", + args: &[("arg1", "jack_uuid_t")], + ret: "u32", + flags: FunctionFlags::NONE, + }, + // pub fn jack_uuid_compare(arg1: jack_uuid_t, arg2: jack_uuid_t) -> ::std::os::raw::c_int; + Function { + name: "jack_uuid_compare", + args: &[("arg1", "jack_uuid_t"), ("arg2", "jack_uuid_t")], + ret: "::std::os::raw::c_int", + flags: FunctionFlags::NONE, + }, + // pub fn jack_uuid_copy(dst: *mut jack_uuid_t, src: jack_uuid_t); + Function { + name: "jack_uuid_copy", + args: &[("dst", "*mut jack_uuid_t"), ("src", "jack_uuid_t")], + ret: "()", + flags: FunctionFlags::NONE, + }, + // pub fn jack_uuid_clear(arg1: *mut jack_uuid_t); + Function { + name: "jack_uuid_clear", + args: &[("arg1", "*mut jack_uuid_t")], + ret: "()", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_uuid_parse", + args: &[ + ("buf", "*const ::std::os::raw::c_char"), + ("arg1", "*mut jack_uuid_t"), + ], + ret: "::std::os::raw::c_int", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_uuid_unparse", + args: &[ + ("arg1", "jack_uuid_t"), + ("buf", "*mut ::std::os::raw::c_char"), + ], + ret: "()", + flags: FunctionFlags::NONE, + }, + Function { + name: "jack_uuid_empty", + args: &[("arg1", "jack_uuid_t")], + ret: "::std::os::raw::c_int", + flags: FunctionFlags::NONE, + }, +]; diff --git a/jack-sys/src/consts.rs b/jack-sys/src/consts.rs new file mode 100644 index 00000000..1fe96021 --- /dev/null +++ b/jack-sys/src/consts.rs @@ -0,0 +1,18 @@ +/// JACK port type for 8 bit raw midi +pub static RAW_MIDI_TYPE: &str = "8 bit raw midi"; + +/// JACK port type for 32 bit float mono audio +pub static FLOAT_MONO_AUDIO: &str = "32 bit float mono audio"; + +/// The path to the jack library. +pub const JACK_LIB: &str = if cfg!(windows) { + if cfg!(target_arch = "x86") { + "libjack.dll" + } else { + "libjack64.dll" + } +} else if cfg!(target_vendor = "apple") { + "libjack.0.dylib" +} else { + "libjack.so.0" +}; diff --git a/jack-sys/src/lib.rs b/jack-sys/src/lib.rs index 3ca4a56c..1edf54fd 100644 --- a/jack-sys/src/lib.rs +++ b/jack-sys/src/lib.rs @@ -1,1139 +1,30 @@ -#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)] - -use dlib::external_library; +#![allow(non_camel_case_types, non_upper_case_globals)] use lazy_static::lazy_static; -pub const JACK_LIB: &'static str = - if cfg!(windows) { - if cfg!(target_arch = "x86") { - "libjack.dll" - } else { - "libjack64.dll" - } - } else if cfg!(target_vendor = "apple") { - "libjack.0.dylib" - } else { - "libjack.so.0" - }; - -/// JACK port type for 8 bit raw midi -pub static RAW_MIDI_TYPE: &str = "8 bit raw midi"; - -/// JACK port type for 32 bit float mono audio -pub static FLOAT_MONO_AUDIO: &str = "32 bit float mono audio"; - -/* automatically generated by rust-bindgen */ +mod consts; +mod types; -#[cfg(not(target_os = "windows"))] -pub type jack_native_thread_t = ::libc::pthread_t; -pub type jack_uuid_t = u64; -pub type jack_shmsize_t = i32; -pub type jack_nframes_t = u32; -pub type jack_time_t = u64; -pub type jack_intclient_t = u64; -pub enum Struct__jack_port {} -pub type jack_port_t = Struct__jack_port; -pub enum Struct__jack_client {} -pub type jack_client_t = Struct__jack_client; -pub type jack_port_id_t = u32; -pub type jack_port_type_id_t = u32; -pub type Enum_JackOptions = ::libc::c_uint; -pub const JackNullOption: ::libc::c_uint = 0; -pub const JackNoStartServer: ::libc::c_uint = 1; -pub const JackUseExactName: ::libc::c_uint = 2; -pub const JackServerName: ::libc::c_uint = 4; -pub const JackLoadName: ::libc::c_uint = 8; -pub const JackLoadInit: ::libc::c_uint = 16; -pub const JackSessionID: ::libc::c_uint = 32; -pub type jack_options_t = Enum_JackOptions; -pub type Enum_JackStatus = ::libc::c_uint; -pub const JackFailure: ::libc::c_uint = 1; -pub const JackInvalidOption: ::libc::c_uint = 2; -pub const JackNameNotUnique: ::libc::c_uint = 4; -pub const JackServerStarted: ::libc::c_uint = 8; -pub const JackServerFailed: ::libc::c_uint = 16; -pub const JackServerError: ::libc::c_uint = 32; -pub const JackNoSuchClient: ::libc::c_uint = 64; -pub const JackLoadFailure: ::libc::c_uint = 128; -pub const JackInitFailure: ::libc::c_uint = 256; -pub const JackShmFailure: ::libc::c_uint = 512; -pub const JackVersionError: ::libc::c_uint = 1024; -pub const JackBackendError: ::libc::c_uint = 2048; -pub const JackClientZombie: ::libc::c_uint = 4096; -pub type jack_status_t = Enum_JackStatus; -pub type Enum_JackLatencyCallbackMode = ::libc::c_uint; -pub const JackCaptureLatency: ::libc::c_uint = 0; -pub const JackPlaybackLatency: ::libc::c_uint = 1; -pub type jack_latency_callback_mode_t = Enum_JackLatencyCallbackMode; -pub type JackLatencyCallback = ::std::option::Option< - unsafe extern "C" fn(mode: jack_latency_callback_mode_t, arg: *mut ::libc::c_void) -> (), ->; -#[repr(C, packed)] -#[derive(Copy)] -pub struct Struct__jack_latency_range { - pub min: jack_nframes_t, - pub max: jack_nframes_t, -} -impl ::std::clone::Clone for Struct__jack_latency_range { - fn clone(&self) -> Self { - *self - } -} -impl ::std::default::Default for Struct__jack_latency_range { - fn default() -> Self { - unsafe { ::std::mem::zeroed() } - } -} -pub type jack_latency_range_t = Struct__jack_latency_range; -pub type JackProcessCallback = ::std::option::Option< - unsafe extern "C" fn(nframes: jack_nframes_t, arg: *mut ::libc::c_void) -> ::libc::c_int, ->; -pub type JackThreadCallback = - ::std::option::Option *mut ::libc::c_void>; -pub type JackThreadInitCallback = - ::std::option::Option ()>; -pub type JackGraphOrderCallback = - ::std::option::Option ::libc::c_int>; -pub type JackXRunCallback = - ::std::option::Option ::libc::c_int>; -pub type JackBufferSizeCallback = ::std::option::Option< - unsafe extern "C" fn(nframes: jack_nframes_t, arg: *mut ::libc::c_void) -> ::libc::c_int, ->; -pub type JackSampleRateCallback = ::std::option::Option< - unsafe extern "C" fn(nframes: jack_nframes_t, arg: *mut ::libc::c_void) -> ::libc::c_int, ->; -pub type JackPortRegistrationCallback = ::std::option::Option< - unsafe extern "C" fn(port: jack_port_id_t, arg1: ::libc::c_int, arg: *mut ::libc::c_void) -> (), ->; -pub type JackClientRegistrationCallback = ::std::option::Option< - unsafe extern "C" fn( - name: *const ::libc::c_char, - arg1: ::libc::c_int, - arg: *mut ::libc::c_void, - ) -> (), ->; -pub type JackPortConnectCallback = ::std::option::Option< - unsafe extern "C" fn( - a: jack_port_id_t, - b: jack_port_id_t, - connect: ::libc::c_int, - arg: *mut ::libc::c_void, - ) -> (), ->; -pub type JackPortRenameCallback = ::std::option::Option< - unsafe extern "C" fn( - port: jack_port_id_t, - old_name: *const ::libc::c_char, - new_name: *const ::libc::c_char, - arg: *mut ::libc::c_void, - ) -> ::libc::c_int, ->; -pub type JackFreewheelCallback = ::std::option::Option< - unsafe extern "C" fn(starting: ::libc::c_int, arg: *mut ::libc::c_void) -> (), ->; -pub type JackShutdownCallback = - ::std::option::Option ()>; -pub type JackInfoShutdownCallback = ::std::option::Option< - unsafe extern "C" fn( - code: jack_status_t, - reason: *const ::libc::c_char, - arg: *mut ::libc::c_void, - ) -> (), ->; -pub type jack_default_audio_sample_t = ::libc::c_float; -pub type Enum_JackPortFlags = ::libc::c_uint; -pub const JackPortIsInput: ::libc::c_uint = 1; -pub const JackPortIsOutput: ::libc::c_uint = 2; -pub const JackPortIsPhysical: ::libc::c_uint = 4; -pub const JackPortCanMonitor: ::libc::c_uint = 8; -pub const JackPortIsTerminal: ::libc::c_uint = 16; -pub type Enum_Unnamed1 = ::libc::c_uint; -pub const JackTransportStopped: ::libc::c_uint = 0; -pub const JackTransportRolling: ::libc::c_uint = 1; -pub const JackTransportLooping: ::libc::c_uint = 2; -pub const JackTransportStarting: ::libc::c_uint = 3; -pub const JackTransportNetStarting: ::libc::c_uint = 4; -pub type jack_transport_state_t = Enum_Unnamed1; -pub type jack_unique_t = u64; -pub type Enum_Unnamed2 = ::libc::c_uint; -pub const JackPositionBBT: ::libc::c_uint = 16; -pub const JackPositionTimecode: ::libc::c_uint = 32; -pub const JackBBTFrameOffset: ::libc::c_uint = 64; -pub const JackAudioVideoRatio: ::libc::c_uint = 128; -pub const JackVideoFrameOffset: ::libc::c_uint = 256; -pub type jack_position_bits_t = Enum_Unnamed2; -#[repr(C, packed)] -#[derive(Copy)] -pub struct Struct__jack_position { - pub unique_1: jack_unique_t, - pub usecs: jack_time_t, - pub frame_rate: jack_nframes_t, - pub frame: jack_nframes_t, - pub valid: jack_position_bits_t, - pub bar: i32, - pub beat: i32, - pub tick: i32, - pub bar_start_tick: ::libc::c_double, - pub beats_per_bar: ::libc::c_float, - pub beat_type: ::libc::c_float, - pub ticks_per_beat: ::libc::c_double, - pub beats_per_minute: ::libc::c_double, - pub frame_time: ::libc::c_double, - pub next_time: ::libc::c_double, - pub bbt_offset: jack_nframes_t, - pub audio_frames_per_video_frame: ::libc::c_float, - pub video_offset: jack_nframes_t, - pub padding: [i32; 7usize], - pub unique_2: jack_unique_t, -} -impl ::std::clone::Clone for Struct__jack_position { - fn clone(&self) -> Self { - *self - } -} -impl ::std::default::Default for Struct__jack_position { - fn default() -> Self { - unsafe { ::std::mem::zeroed() } - } -} -pub type jack_position_t = Struct__jack_position; -pub type JackSyncCallback = ::std::option::Option< - unsafe extern "C" fn( - state: jack_transport_state_t, - pos: *mut jack_position_t, - arg: *mut ::libc::c_void, - ) -> ::libc::c_int, ->; -pub type TimebaseCallback = ::std::option::Option< - unsafe extern "C" fn( - state: jack_transport_state_t, - nframes: jack_nframes_t, - pos: *mut jack_position_t, - new_pos: ::libc::c_int, - arg: *mut ::libc::c_void, - ) -> (), ->; -pub type Enum_Unnamed3 = ::libc::c_uint; -pub const JackTransportState: ::libc::c_uint = 1; -pub const JackTransportPosition: ::libc::c_uint = 2; -pub const JackTransportLoop: ::libc::c_uint = 4; -pub const JackTransportSMPTE: ::libc::c_uint = 8; -pub const JackTransportBBT: ::libc::c_uint = 16; -pub type jack_transport_bits_t = Enum_Unnamed3; -#[repr(C)] -#[derive(Copy)] -pub struct Struct_Unnamed4 { - pub frame_rate: jack_nframes_t, - pub usecs: jack_time_t, - pub valid: jack_transport_bits_t, - pub transport_state: jack_transport_state_t, - pub frame: jack_nframes_t, - pub loop_start: jack_nframes_t, - pub loop_end: jack_nframes_t, - pub smpte_offset: ::libc::c_long, - pub smpte_frame_rate: ::libc::c_float, - pub bar: ::libc::c_int, - pub beat: ::libc::c_int, - pub tick: ::libc::c_int, - pub bar_start_tick: ::libc::c_double, - pub beats_per_bar: ::libc::c_float, - pub beat_type: ::libc::c_float, - pub ticks_per_beat: ::libc::c_double, - pub beats_per_minute: ::libc::c_double, -} -impl ::std::clone::Clone for Struct_Unnamed4 { - fn clone(&self) -> Self { - *self - } -} -impl ::std::default::Default for Struct_Unnamed4 { - fn default() -> Self { - unsafe { ::std::mem::zeroed() } - } -} -pub type jack_transport_info_t = Struct_Unnamed4; -#[cfg(not(target_os = "windows"))] -pub type jack_thread_creator_t = ::std::option::Option< - unsafe extern "C" fn( - arg1: *mut ::libc::pthread_t, - arg2: *const ::libc::pthread_attr_t, - function: ::std::option::Option< - extern "C" fn(arg1: *mut ::libc::c_void) -> *mut ::libc::c_void, - >, - arg: *mut ::libc::c_void, - ) -> ::libc::c_int, ->; -pub type Enum_JackSessionEventType = ::libc::c_uint; -pub const JackSessionSave: ::libc::c_uint = 1; -pub const JackSessionSaveAndQuit: ::libc::c_uint = 2; -pub const JackSessionSaveTemplate: ::libc::c_uint = 3; -pub type jack_session_event_type_t = Enum_JackSessionEventType; -pub type Enum_JackSessionFlags = ::libc::c_uint; -pub const JackSessionSaveError: ::libc::c_uint = 1; -pub const JackSessionNeedTerminal: ::libc::c_uint = 2; -pub type jack_session_flags_t = Enum_JackSessionFlags; -#[repr(C)] -#[derive(Copy)] -pub struct Struct__jack_session_event { - pub _type: jack_session_event_type_t, - pub session_dir: *const ::libc::c_char, - pub client_uuid: *const ::libc::c_char, - pub command_line: *mut ::libc::c_char, - pub flags: jack_session_flags_t, - pub future: u32, -} -impl ::std::clone::Clone for Struct__jack_session_event { - fn clone(&self) -> Self { - *self - } -} -impl ::std::default::Default for Struct__jack_session_event { - fn default() -> Self { - unsafe { ::std::mem::zeroed() } - } -} -pub type jack_session_event_t = Struct__jack_session_event; -pub type JackSessionCallback = ::std::option::Option< - unsafe extern "C" fn(event: *mut jack_session_event_t, arg: *mut ::libc::c_void) -> (), ->; -#[repr(C)] -#[derive(Copy)] -pub struct Struct_Unnamed5 { - pub uuid: *const ::libc::c_char, - pub client_name: *const ::libc::c_char, - pub command: *const ::libc::c_char, - pub flags: jack_session_flags_t, -} -impl ::std::clone::Clone for Struct_Unnamed5 { - fn clone(&self) -> Self { - *self - } -} -impl ::std::default::Default for Struct_Unnamed5 { - fn default() -> Self { - unsafe { ::std::mem::zeroed() } - } -} -pub type jack_session_command_t = Struct_Unnamed5; -pub type JSList = Struct__JSList; -pub type JCompareFunc = ::std::option::Option< - unsafe extern "C" fn(a: *mut ::libc::c_void, b: *mut ::libc::c_void) -> ::libc::c_int, ->; -#[repr(C)] -#[derive(Copy)] -pub struct Struct__JSList { - pub data: *mut ::libc::c_void, - pub next: *mut JSList, -} -impl ::std::clone::Clone for Struct__JSList { - fn clone(&self) -> Self { - *self - } -} -impl ::std::default::Default for Struct__JSList { - fn default() -> Self { - unsafe { ::std::mem::zeroed() } - } -} -pub type Enum_Unnamed6 = ::libc::c_uint; -pub const JackParamInt: ::libc::c_uint = 1; -pub const JackParamUInt: ::libc::c_uint = 2; -pub const JackParamChar: ::libc::c_uint = 3; -pub const JackParamString: ::libc::c_uint = 4; -pub const JackParamBool: ::libc::c_uint = 5; -pub type jackctl_param_type_t = Enum_Unnamed6; -pub type Enum_Unnamed7 = ::libc::c_uint; -pub const JackMaster: ::libc::c_uint = 1; -pub const JackSlave: ::libc::c_uint = 2; -pub type jackctl_driver_type_t = Enum_Unnamed7; -#[repr(C)] -#[derive(Copy)] -pub struct Union_jackctl_parameter_value { - pub _bindgen_data_: [u32; 32usize], -} -impl Union_jackctl_parameter_value { - pub unsafe fn ui(&mut self) -> *mut u32 { - let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_); - ::std::mem::transmute(raw.offset(0)) - } - pub unsafe fn i(&mut self) -> *mut i32 { - let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_); - ::std::mem::transmute(raw.offset(0)) - } - pub unsafe fn c(&mut self) -> *mut ::libc::c_char { - let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_); - ::std::mem::transmute(raw.offset(0)) - } - pub unsafe fn str(&mut self) -> *mut [::libc::c_char; 128usize] { - let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_); - ::std::mem::transmute(raw.offset(0)) - } - pub unsafe fn b(&mut self) -> *mut u8 { - let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_); - ::std::mem::transmute(raw.offset(0)) - } -} -impl ::std::clone::Clone for Union_jackctl_parameter_value { - fn clone(&self) -> Self { - *self - } -} -impl ::std::default::Default for Union_jackctl_parameter_value { - fn default() -> Self { - unsafe { ::std::mem::zeroed() } - } +mod functions { + include!(concat!(env!("OUT_DIR"), "/functions.rs")); } -pub enum Struct_jackctl_server {} -pub type jackctl_server_t = Struct_jackctl_server; -pub enum Struct_jackctl_driver {} -pub type jackctl_driver_t = Struct_jackctl_driver; -pub enum Struct_jackctl_internal {} -pub type jackctl_internal_t = Struct_jackctl_internal; -pub enum Struct_jackctl_parameter {} -pub type jackctl_parameter_t = Struct_jackctl_parameter; -pub enum Struct_jackctl_sigmask {} -pub type jackctl_sigmask_t = Struct_jackctl_sigmask; -#[repr(C)] -#[derive(Copy)] -pub struct Struct_Unnamed8 { - pub key: *const ::libc::c_char, - pub data: *const ::libc::c_char, - pub _type: *const ::libc::c_char, -} -impl ::std::clone::Clone for Struct_Unnamed8 { - fn clone(&self) -> Self { - *self - } -} -impl ::std::default::Default for Struct_Unnamed8 { - fn default() -> Self { - unsafe { ::std::mem::zeroed() } - } -} -pub type jack_property_t = Struct_Unnamed8; -#[repr(C)] -#[derive(Copy)] -pub struct Struct_Unnamed9 { - pub subject: jack_uuid_t, - pub property_cnt: u32, - pub properties: *mut jack_property_t, - pub property_size: u32, -} -impl ::std::clone::Clone for Struct_Unnamed9 { - fn clone(&self) -> Self { - *self - } -} -impl ::std::default::Default for Struct_Unnamed9 { - fn default() -> Self { - unsafe { ::std::mem::zeroed() } - } -} -pub type jack_description_t = Struct_Unnamed9; -pub type Enum_Unnamed10 = ::libc::c_uint; -pub const PropertyCreated: ::libc::c_uint = 0; -pub const PropertyChanged: ::libc::c_uint = 1; -pub const PropertyDeleted: ::libc::c_uint = 2; -pub type jack_property_change_t = Enum_Unnamed10; -pub type JackPropertyChangeCallback = ::std::option::Option< - unsafe extern "C" fn( - subject: jack_uuid_t, - key: *const ::libc::c_char, - change: jack_property_change_t, - arg: *mut ::libc::c_void, - ) -> (), ->; -pub type jack_midi_data_t = ::libc::c_uchar; -#[repr(C)] -#[derive(Copy)] -pub struct Struct__jack_midi_event { - pub time: jack_nframes_t, - pub size: ::libc::size_t, - pub buffer: *mut jack_midi_data_t, -} -impl ::std::clone::Clone for Struct__jack_midi_event { - fn clone(&self) -> Self { - *self - } -} -impl ::std::default::Default for Struct__jack_midi_event { - fn default() -> Self { - unsafe { ::std::mem::zeroed() } - } -} -pub type jack_midi_event_t = Struct__jack_midi_event; -#[repr(C)] -#[derive(Copy)] -pub struct Struct_Unnamed11 { - pub buf: *mut ::libc::c_char, - pub len: ::libc::size_t, -} -impl ::std::clone::Clone for Struct_Unnamed11 { - fn clone(&self) -> Self { - *self - } -} -impl ::std::default::Default for Struct_Unnamed11 { - fn default() -> Self { - unsafe { ::std::mem::zeroed() } - } -} -pub type jack_ringbuffer_data_t = Struct_Unnamed11; -#[repr(C)] -#[derive(Copy)] -pub struct Struct_Unnamed12 { - pub buf: *mut ::libc::c_char, - pub write_ptr: ::libc::size_t, - pub read_ptr: ::libc::size_t, - pub size: ::libc::size_t, - pub size_mask: ::libc::size_t, - pub mlocked: ::libc::c_int, -} -impl ::std::clone::Clone for Struct_Unnamed12 { - fn clone(&self) -> Self { - *self - } -} -impl ::std::default::Default for Struct_Unnamed12 { - fn default() -> Self { - unsafe { ::std::mem::zeroed() } - } -} -pub type jack_ringbuffer_t = Struct_Unnamed12; -extern "C" {} - -external_library!( - JackMetadata, - "jack", - statics: JACK_METADATA_PRETTY_NAME: *const ::libc::c_char, - JACK_METADATA_HARDWARE: *const ::libc::c_char, - JACK_METADATA_CONNECTED: *const ::libc::c_char, - JACK_METADATA_PORT_GROUP: *const ::libc::c_char, - JACK_METADATA_ICON_SMALL: *const ::libc::c_char, - JACK_METADATA_ICON_LARGE: *const ::libc::c_char, -); -// statics: -// // jack_error_callback: -// // ::std::option::Option ()>, -// // jack_info_callback: -// // ::std::option::Option ()>, - -external_library!( - JackError, - "jack", - statics: jack_error_callback: Option ()>, - jack_info_callback: Option ()>, -); - -external_library!( - JackCtl, - "jack", - functions: - fn jackctl_setup_signals(::libc::c_uint) -> *mut jackctl_sigmask_t, - fn jackctl_wait_signals(*mut jackctl_sigmask_t) -> (), - fn jackctl_server_create( - ::std::option::Option< - unsafe extern "C" fn(*const ::libc::c_char) -> u8, - >, - ::std::option::Option< - unsafe extern "C" fn(*const ::libc::c_char) -> (), - > - ) -> *mut jackctl_server_t, - fn jackctl_server_destroy(*mut jackctl_server_t) -> (), - fn jackctl_server_open(*mut jackctl_server_t, *mut jackctl_driver_t) -> u8, - fn jackctl_server_start(*mut jackctl_server_t) -> u8, - fn jackctl_server_stop(*mut jackctl_server_t) -> u8, - fn jackctl_server_close(*mut jackctl_server_t) -> u8, - fn jackctl_server_get_drivers_list(*mut jackctl_server_t) -> *const JSList, - fn jackctl_server_get_parameters(*mut jackctl_server_t) -> *const JSList, - fn jackctl_server_get_internals_list(*mut jackctl_server_t) -> *const JSList, - fn jackctl_server_load_internal( - *mut jackctl_server_t, - *mut jackctl_internal_t - ) -> u8, - fn jackctl_server_unload_internal( - *mut jackctl_server_t, - *mut jackctl_internal_t - ) -> u8, - fn jackctl_server_add_slave( - *mut jackctl_server_t, - *mut jackctl_driver_t - ) -> u8, - fn jackctl_server_remove_slave( - *mut jackctl_server_t, - *mut jackctl_driver_t - ) -> u8, - fn jackctl_server_switch_master( - *mut jackctl_server_t, - *mut jackctl_driver_t - ) -> u8, - fn jackctl_driver_get_name( *mut jackctl_driver_t) -> *const ::libc::c_char, - fn jackctl_driver_get_type( *mut jackctl_driver_t) -> jackctl_driver_type_t, - fn jackctl_driver_get_parameters( *mut jackctl_driver_t) -> *const JSList, - fn jackctl_driver_params_parse( - *mut jackctl_driver_t, - ::libc::c_int, - *mut *mut ::libc::c_char - ) -> ::libc::c_int, - fn jackctl_internal_get_name(*mut jackctl_internal_t) -> *const ::libc::c_char, - fn jackctl_internal_get_parameters(*mut jackctl_internal_t) -> *const JSList, - fn jackctl_parameter_get_name(*mut jackctl_parameter_t) - -> *const ::libc::c_char, - fn jackctl_parameter_get_short_description( - *mut jackctl_parameter_t - ) -> *const ::libc::c_char, - fn jackctl_parameter_get_long_description( - *mut jackctl_parameter_t - ) -> *const ::libc::c_char, - fn jackctl_parameter_get_type(*mut jackctl_parameter_t) -> jackctl_param_type_t, - fn jackctl_parameter_get_id(*mut jackctl_parameter_t) -> ::libc::c_char, - fn jackctl_parameter_is_set(*mut jackctl_parameter_t) -> u8, - fn jackctl_parameter_reset(*mut jackctl_parameter_t) -> u8, - fn jackctl_parameter_get_value( - *mut jackctl_parameter_t - ) -> Union_jackctl_parameter_value, - fn jackctl_parameter_set_value( - *mut jackctl_parameter_t, - *const Union_jackctl_parameter_value - ) -> u8, - fn jackctl_parameter_get_default_value( - *mut jackctl_parameter_t - ) -> Union_jackctl_parameter_value, - fn jackctl_parameter_has_range_constraint(*mut jackctl_parameter_t) -> u8, - fn jackctl_parameter_has_enum_constraint(*mut jackctl_parameter_t) -> u8, - fn jackctl_parameter_get_enum_constraints_count(*mut jackctl_parameter_t) - -> u32, - fn jackctl_parameter_get_enum_constraint_value( - *mut jackctl_parameter_t, - u32 - ) -> Union_jackctl_parameter_value, - fn jackctl_parameter_get_enum_constraint_description( - *mut jackctl_parameter_t, - u32 - ) -> *const ::libc::c_char, - fn jackctl_parameter_get_range_constraint( - *mut jackctl_parameter_t, - *mut Union_jackctl_parameter_value, - *mut Union_jackctl_parameter_value - ) -> (), - fn jackctl_parameter_constraint_is_strict(*mut jackctl_parameter_t) -> u8, - fn jackctl_parameter_constraint_is_fake_value(*mut jackctl_parameter_t) -> u8, -); - -external_library!( - JackLib, - "jack", - functions: - fn jack_release_timebase(*mut jack_client_t) -> ::libc::c_int, - fn jack_set_sync_callback( - *mut jack_client_t, - JackSyncCallback, - *mut ::libc::c_void - ) -> ::libc::c_int, - fn jack_set_sync_timeout(*mut jack_client_t, jack_time_t) - -> ::libc::c_int, - fn jack_set_timebase_callback( - *mut jack_client_t, - ::libc::c_int, - TimebaseCallback, - *mut ::libc::c_void - ) -> ::libc::c_int, - fn jack_transport_locate( - *mut jack_client_t, - jack_nframes_t - ) -> ::libc::c_int, - fn jack_transport_query( - *const jack_client_t, - *mut jack_position_t - ) -> jack_transport_state_t, - fn jack_get_current_transport_frame(*const jack_client_t) -> jack_nframes_t, - fn jack_transport_reposition( - *mut jack_client_t, - *const jack_position_t - ) -> ::libc::c_int, - fn jack_transport_start( *mut jack_client_t) -> (), - fn jack_transport_stop( *mut jack_client_t) -> (), - fn jack_get_transport_info( - *mut jack_client_t, - *mut jack_transport_info_t - ) -> (), - fn jack_set_transport_info( - *mut jack_client_t, - *mut jack_transport_info_t - ) -> (), - fn jack_client_new( *const ::libc::c_char) -> *mut jack_client_t, - fn jack_client_close( *mut jack_client_t) -> ::libc::c_int, - fn jack_client_name_size() -> ::libc::c_int, - fn jack_get_client_name( *mut jack_client_t) -> *mut ::libc::c_char, - fn jack_get_uuid_for_client_name( - *mut jack_client_t, - *const ::libc::c_char - ) -> *mut ::libc::c_char, - fn jack_get_client_name_by_uuid( - *mut jack_client_t, - *const ::libc::c_char - ) -> *mut ::libc::c_char, - fn jack_internal_client_new( - *const ::libc::c_char, - *const ::libc::c_char, - *const ::libc::c_char - ) -> ::libc::c_int, - fn jack_internal_client_close( *const ::libc::c_char) -> (), - fn jack_activate( *mut jack_client_t) -> ::libc::c_int, - fn jack_deactivate( *mut jack_client_t) -> ::libc::c_int, - // #[cfg(not(target_os = "windows"))] - // fn jack_client_thread_id( *mut jack_client_t) -> jack_native_thread_t, - fn jack_is_realtime( *mut jack_client_t) -> ::libc::c_int, - fn jack_thread_wait( *mut jack_client_t, ::libc::c_int) -> jack_nframes_t, - fn jack_cycle_wait( *mut jack_client_t) -> jack_nframes_t, - fn jack_cycle_signal( *mut jack_client_t, ::libc::c_int) -> (), - fn jack_set_process_thread( - *mut jack_client_t, - JackThreadCallback, - *mut ::libc::c_void - ) -> ::libc::c_int, - fn jack_set_thread_init_callback( - *mut jack_client_t, - JackThreadInitCallback, - *mut ::libc::c_void - ) -> ::libc::c_int, - fn jack_on_shutdown( - *mut jack_client_t, - JackShutdownCallback, - *mut ::libc::c_void - ) -> (), - fn jack_on_info_shutdown( - *mut jack_client_t, - JackInfoShutdownCallback, - *mut ::libc::c_void - ) -> (), - fn jack_set_process_callback( - *mut jack_client_t, - JackProcessCallback, - *mut ::libc::c_void - ) -> ::libc::c_int, - fn jack_set_freewheel_callback( - *mut jack_client_t, - JackFreewheelCallback, - *mut ::libc::c_void - ) -> ::libc::c_int, - fn jack_set_buffer_size_callback( - *mut jack_client_t, - JackBufferSizeCallback, - *mut ::libc::c_void - ) -> ::libc::c_int, - fn jack_set_sample_rate_callback( - *mut jack_client_t, - JackSampleRateCallback, - *mut ::libc::c_void - ) -> ::libc::c_int, - fn jack_set_client_registration_callback( - *mut jack_client_t, - JackClientRegistrationCallback, - *mut ::libc::c_void - ) -> ::libc::c_int, - fn jack_set_port_registration_callback( - *mut jack_client_t, - JackPortRegistrationCallback, - *mut ::libc::c_void - ) -> ::libc::c_int, - fn jack_set_port_connect_callback( - *mut jack_client_t, - JackPortConnectCallback, - *mut ::libc::c_void - ) -> ::libc::c_int, - fn jack_set_port_rename_callback( - *mut jack_client_t, - JackPortRenameCallback, - *mut ::libc::c_void - ) -> ::libc::c_int, - fn jack_set_graph_order_callback( - *mut jack_client_t, - JackGraphOrderCallback, - *mut ::libc::c_void - ) -> ::libc::c_int, - fn jack_set_xrun_callback( - *mut jack_client_t, - JackXRunCallback, - *mut ::libc::c_void - ) -> ::libc::c_int, - fn jack_set_latency_callback( - *mut jack_client_t, - JackLatencyCallback, - *mut ::libc::c_void - ) -> ::libc::c_int, - fn jack_set_freewheel( *mut jack_client_t, ::libc::c_int) -> ::libc::c_int, - fn jack_set_buffer_size( - *mut jack_client_t, - jack_nframes_t - ) -> ::libc::c_int, - fn jack_get_sample_rate( *mut jack_client_t) -> jack_nframes_t, - fn jack_get_buffer_size( *mut jack_client_t) -> jack_nframes_t, - fn jack_engine_takeover_timebase( *mut jack_client_t) -> ::libc::c_int, - fn jack_cpu_load( *mut jack_client_t) -> ::libc::c_float, - fn jack_port_register( - *mut jack_client_t, - *const ::libc::c_char, - *const ::libc::c_char, - ::libc::c_ulong, - ::libc::c_ulong - ) -> *mut jack_port_t, - fn jack_port_unregister( - *mut jack_client_t, - *mut jack_port_t - ) -> ::libc::c_int, - fn jack_port_get_buffer( - *mut jack_port_t, - jack_nframes_t - ) -> *mut ::libc::c_void, - fn jack_port_uuid( *const jack_port_t) -> jack_uuid_t, - fn jack_port_name( *const jack_port_t) -> *const ::libc::c_char, - fn jack_port_short_name( *const jack_port_t) -> *const ::libc::c_char, - fn jack_port_flags( *const jack_port_t) -> ::libc::c_int, - fn jack_port_type( *const jack_port_t) -> *const ::libc::c_char, - fn jack_port_is_mine( - *const jack_client_t, - *const jack_port_t - ) -> ::libc::c_int, - fn jack_port_connected( *const jack_port_t) -> ::libc::c_int, - fn jack_port_connected_to( - *const jack_port_t, - *const ::libc::c_char - ) -> ::libc::c_int, - fn jack_port_get_connections( *const jack_port_t) -> *mut *const ::libc::c_char, - fn jack_port_get_all_connections( - *const jack_client_t, - *const jack_port_t - ) -> *mut *const ::libc::c_char, - fn jack_port_tie( *mut jack_port_t, *mut jack_port_t) -> ::libc::c_int, - fn jack_port_untie( *mut jack_port_t) -> ::libc::c_int, - fn jack_port_set_name( - *mut jack_port_t, - *const ::libc::c_char - ) -> ::libc::c_int, - fn jack_port_set_alias( - *mut jack_port_t, - *const ::libc::c_char - ) -> ::libc::c_int, - fn jack_port_unset_alias( - *mut jack_port_t, - *const ::libc::c_char - ) -> ::libc::c_int, - fn jack_port_get_aliases( - *const jack_port_t, - *mut *mut ::libc::c_char - ) -> ::libc::c_int, - fn jack_port_request_monitor( *mut jack_port_t, ::libc::c_int) - -> ::libc::c_int, - fn jack_port_request_monitor_by_name( - *mut jack_client_t, - *const ::libc::c_char, - ::libc::c_int - ) -> ::libc::c_int, - fn jack_port_ensure_monitor( *mut jack_port_t, ::libc::c_int) -> ::libc::c_int, - fn jack_port_monitoring_input( *mut jack_port_t) -> ::libc::c_int, - fn jack_connect( - *mut jack_client_t, - *const ::libc::c_char, - *const ::libc::c_char - ) -> ::libc::c_int, - fn jack_disconnect( - *mut jack_client_t, - *const ::libc::c_char, - *const ::libc::c_char - ) -> ::libc::c_int, - fn jack_port_disconnect( - *mut jack_client_t, - *mut jack_port_t - ) -> ::libc::c_int, - fn jack_port_name_size() -> ::libc::c_int, - fn jack_port_type_size() -> ::libc::c_int, - fn jack_port_type_get_buffer_size( - *mut jack_client_t, - *const ::libc::c_char - ) -> ::libc::size_t, - fn jack_port_set_latency( *mut jack_port_t, jack_nframes_t) -> (), - fn jack_port_get_latency_range( - *mut jack_port_t, - jack_latency_callback_mode_t, - *mut jack_latency_range_t - ) -> (), - fn jack_port_set_latency_range( - *mut jack_port_t, - jack_latency_callback_mode_t, - *mut jack_latency_range_t - ) -> (), - fn jack_recompute_total_latencies( *mut jack_client_t) -> ::libc::c_int, - fn jack_port_get_latency( *mut jack_port_t) -> jack_nframes_t, - fn jack_port_get_total_latency( - *mut jack_client_t, - *mut jack_port_t - ) -> jack_nframes_t, - fn jack_recompute_total_latency( - *mut jack_client_t, - *mut jack_port_t - ) -> ::libc::c_int, - fn jack_get_ports( - *mut jack_client_t, - *const ::libc::c_char, - *const ::libc::c_char, - ::libc::c_ulong - ) -> *mut *const ::libc::c_char, - fn jack_port_by_name( - *mut jack_client_t, - *const ::libc::c_char - ) -> *mut jack_port_t, - fn jack_port_by_id( *mut jack_client_t, jack_port_id_t) - -> *mut jack_port_t, - fn jack_frames_since_cycle_start( *const jack_client_t) -> jack_nframes_t, - fn jack_frame_time( *const jack_client_t) -> jack_nframes_t, - fn jack_last_frame_time( *const jack_client_t) -> jack_nframes_t, - - fn jack_frames_to_time( *const jack_client_t, jack_nframes_t) -> jack_time_t, - fn jack_time_to_frames( *const jack_client_t, jack_time_t) -> jack_nframes_t, - fn jack_get_time() -> jack_time_t, - fn jack_set_error_function( - ::std::option::Option ()> - ) -> (), - fn jack_set_info_function( - ::std::option::Option ()> - ) -> (), - fn jack_free(*mut ::libc::c_void) -> (), - fn jack_client_real_time_priority( *mut jack_client_t) -> ::libc::c_int, - fn jack_client_max_real_time_priority( *mut jack_client_t) -> ::libc::c_int, - // #[cfg(not(target_os = "windows"))] - // fn jack_acquire_real_time_scheduling( - // thread: jack_native_thread_t, - // priority: ::libc::c_int, - // ) -> ::libc::c_int, - // #[cfg(not(target_os = "windows"))] - // fn jack_client_create_thread( - // client: *mut jack_client_t, - // thread: *mut jack_native_thread_t, - // priority: ::libc::c_int, - // realtime: ::libc::c_int, - // start_routine: ::std::option::Option< - // unsafe extern "C" fn(arg1: *mut ::libc::c_void) -> *mut ::libc::c_void, - // >, - // arg: *mut ::libc::c_void, - // ) -> ::libc::c_int, - // #[cfg(not(target_os = "windows"))] - // fn jack_drop_real_time_scheduling(thread: jack_native_thread_t) -> ::libc::c_int, - // #[cfg(not(target_os = "windows"))] - // fn jack_client_stop_thread( - // client: *mut jack_client_t, - // thread: jack_native_thread_t, - // ) -> ::libc::c_int, - // #[cfg(not(target_os = "windows"))] - // fn jack_client_kill_thread( - // client: *mut jack_client_t, - // thread: jack_native_thread_t, - // ) -> ::libc::c_int, - // #[cfg(not(target_os = "windows"))] - // fn jack_set_thread_creator(creator: jack_thread_creator_t) -> (), - fn jack_set_session_callback( - *mut jack_client_t, - JackSessionCallback, - *mut ::libc::c_void - ) -> ::libc::c_int, - fn jack_session_reply( - *mut jack_client_t, - *mut jack_session_event_t - ) -> ::libc::c_int, - fn jack_session_event_free( *mut jack_session_event_t) -> (), - fn jack_client_get_uuid( *mut jack_client_t) -> *mut ::libc::c_char, - fn jack_session_notify( - *mut jack_client_t, - *const ::libc::c_char, - jack_session_event_type_t, - *const ::libc::c_char - ) -> *mut jack_session_command_t, - fn jack_session_commands_free(*mut jack_session_command_t) -> (), - fn jack_reserve_client_name( - *mut jack_client_t, - *const ::libc::c_char, - *const ::libc::c_char - ) -> ::libc::c_int, - fn jack_client_has_session_callback( - *mut jack_client_t, - *const ::libc::c_char - ) -> ::libc::c_int, - // fn jack_error(format: *const ::libc::c_char, ...) -> (), - // fn jack_info(format: *const ::libc::c_char, ...) -> (), - // fn jack_log(format: *const ::libc::c_char, ...) -> (), - fn jack_set_property( - *mut jack_client_t, - jack_uuid_t, - *const ::libc::c_char, - *const ::libc::c_char, - *const ::libc::c_char - ) -> ::libc::c_int, - fn jack_get_property( - jack_uuid_t, - *const ::libc::c_char, - *mut *mut ::libc::c_char, - *mut *mut ::libc::c_char - ) -> ::libc::c_int, - fn jack_free_description( - *mut jack_description_t, - ::libc::c_int - ) -> (), - fn jack_get_properties( - jack_uuid_t, - *mut jack_description_t - ) -> ::libc::c_int, - fn jack_get_all_properties(*mut *mut jack_description_t) -> ::libc::c_int, - fn jack_remove_property( - *mut jack_client_t, - jack_uuid_t, - *const ::libc::c_char - ) -> ::libc::c_int, - fn jack_remove_properties( - *mut jack_client_t, - jack_uuid_t - ) -> ::libc::c_int, - fn jack_remove_all_properties( *mut jack_client_t) -> ::libc::c_int, - fn jack_set_property_change_callback( - *mut jack_client_t, - JackPropertyChangeCallback, - *mut ::libc::c_void - ) -> ::libc::c_int, - fn jack_get_internal_client_name( - *mut jack_client_t, - jack_intclient_t - ) -> *mut ::libc::c_char, - fn jack_internal_client_handle( - *mut jack_client_t, - *const ::libc::c_char, - *mut jack_status_t - ) -> jack_intclient_t, - fn jack_internal_client_unload( - *mut jack_client_t, - jack_intclient_t - ) -> jack_status_t, - fn jack_get_max_delayed_usecs(*mut jack_client_t) -> ::libc::c_float, - fn jack_get_xrun_delayed_usecs( *mut jack_client_t) -> ::libc::c_float, - fn jack_reset_max_delayed_usecs( *mut jack_client_t) -> (), - fn jack_midi_get_event_count( *mut ::libc::c_void) -> u32, - fn jack_midi_event_get( - *mut jack_midi_event_t, - *mut ::libc::c_void, - u32 - ) -> ::libc::c_int, - fn jack_midi_clear_buffer(*mut ::libc::c_void) -> (), - fn jack_midi_max_event_size(*mut ::libc::c_void) -> ::libc::size_t, - fn jack_midi_event_reserve( - *mut ::libc::c_void, - jack_nframes_t, - ::libc::size_t - ) -> *mut jack_midi_data_t, - fn jack_midi_event_write( - *mut ::libc::c_void, - jack_nframes_t, - *const jack_midi_data_t, - ::libc::size_t - ) -> ::libc::c_int, - fn jack_midi_get_lost_event_count( *mut ::libc::c_void) -> u32, - fn jack_ringbuffer_create( ::libc::size_t) -> *mut jack_ringbuffer_t, - fn jack_ringbuffer_free( *mut jack_ringbuffer_t) -> (), - fn jack_ringbuffer_get_read_vector( - *const jack_ringbuffer_t, - *mut jack_ringbuffer_data_t - ) -> (), - fn jack_ringbuffer_get_write_vector( - *const jack_ringbuffer_t, - *mut jack_ringbuffer_data_t - ) -> (), - fn jack_ringbuffer_read( - *mut jack_ringbuffer_t, - *mut ::libc::c_char, - ::libc::size_t - ) -> ::libc::size_t, - fn jack_ringbuffer_peek( - *mut jack_ringbuffer_t, - *mut ::libc::c_char, - ::libc::size_t - ) -> ::libc::size_t, - fn jack_ringbuffer_read_advance(*mut jack_ringbuffer_t, ::libc::size_t) -> (), - fn jack_ringbuffer_read_space( *const jack_ringbuffer_t) -> ::libc::size_t, - fn jack_ringbuffer_mlock( *mut jack_ringbuffer_t) -> ::libc::c_int, - fn jack_ringbuffer_reset( *mut jack_ringbuffer_t) -> (), - fn jack_ringbuffer_write( - *mut jack_ringbuffer_t, - *const ::libc::c_char, - ::libc::size_t - ) -> ::libc::size_t, - fn jack_ringbuffer_write_advance( *mut jack_ringbuffer_t, ::libc::size_t) -> (), - fn jack_ringbuffer_write_space( *const jack_ringbuffer_t) -> ::libc::size_t, - varargs: - fn jack_internal_client_load( - *mut jack_client_t, - *const ::libc::c_char, - jack_options_t, - *mut jack_status_t, - jack_intclient_t - ) -> jack_intclient_t, - fn jack_client_open(*const ::libc::c_char, jack_options_t, *mut jack_status_t) -> *mut jack_client_t, -); - -external_library!( - JackUuid, - "jack", - functions: - fn jack_uuid_to_index(jack_uuid_t) -> u32, - fn jack_uuid_copy(*mut jack_uuid_t, jack_uuid_t) -> (), - fn jack_uuid_compare(jack_uuid_t, jack_uuid_t) -> ::std::os::raw::c_int, - fn jack_uuid_clear(*mut jack_uuid_t) -> (), - fn jack_uuid_parse( - *const ::std::os::raw::c_char, - *mut jack_uuid_t - ) -> ::std::os::raw::c_int, - fn jack_uuid_unparse(jack_uuid_t, *mut ::std::os::raw::c_char) -> (), - fn jack_uuid_empty(jack_uuid_t) -> ::std::os::raw::c_int, -); - -#[cfg(feature = "dlopen")] -impl std::fmt::Debug for JackLib { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("JackLib").finish() - } -} - -// The following functions are not available in some JACK versions. Use with caution. -external_library!( -JackOptional, -"jack", -functions: - fn jack_get_version( - *mut ::libc::c_int, - *mut ::libc::c_int, - *mut ::libc::c_int, - *mut ::libc::c_int - ) -> (), - fn jack_get_version_string() -> *const ::libc::c_char, - fn jack_get_client_pid( *const ::libc::c_char) -> ::libc::c_int, - fn jack_port_type_id( *const jack_port_t) -> jack_port_type_id_t, - fn jack_midi_reset_buffer(*mut ::libc::c_void) -> (), - fn jack_ringbuffer_reset_size( *mut jack_ringbuffer_t, ::libc::size_t) -> (), -); -type jack_get_cycle_times_t = unsafe extern "C" fn( - client: *const jack_client_t, - current_frames: *mut jack_nframes_t, - current_usecs: *mut jack_time_t, - next_usecs: *mut jack_time_t, - period_usecs: *mut ::libc::c_float, -) -> ::libc::c_int; +pub use consts::*; +pub use functions::*; +pub use types::*; lazy_static! { - pub static ref jack_get_cycle_times: Option = { - unsafe { libloading::Library::new(JACK_LIB) } - .ok() - .and_then(|lib| unsafe { - lib.get::(b"jack_get_cycle_times\0") - .ok() - .map(|sym| sym.into_raw()) - .map(|sym| *sym.deref() as jack_get_cycle_times_t) - }) - }; + static ref LIB_RESULT: Result = + unsafe { libloading::Library::new(JACK_LIB) }; +} + +/// Get the underlying library handle. Can be used to extract symbols from the library. +/// +/// # Example +/// ```rust +/// let symbol = library.get:: ::libc::c_int>(b"jack_release_timebase").unwrap(); +/// let raw_symbol = symbol.into_raw(); +/// let func = *raw_symbol.deref() as unsafe extern "C" fn(client: *mut jack_client_t) -> ::libc::c_int; +/// ``` +pub fn library() -> Result<&'static libloading::Library, impl std::error::Error> { + LIB_RESULT.as_ref() } diff --git a/jack-sys/src/types.rs b/jack-sys/src/types.rs new file mode 100644 index 00000000..a5ba3a7e --- /dev/null +++ b/jack-sys/src/types.rs @@ -0,0 +1,488 @@ +#[cfg(not(target_os = "windows"))] +pub type jack_native_thread_t = ::libc::pthread_t; +pub type jack_uuid_t = u64; +pub type jack_shmsize_t = i32; +pub type jack_nframes_t = u32; +pub type jack_time_t = u64; +pub type jack_intclient_t = u64; +pub enum Struct__jack_port {} +pub type jack_port_t = Struct__jack_port; +pub enum Struct__jack_client {} +pub type jack_client_t = Struct__jack_client; +pub type jack_port_id_t = u32; +pub type jack_port_type_id_t = u32; +pub type Enum_JackOptions = ::libc::c_uint; +pub const JackNullOption: ::libc::c_uint = 0; +pub const JackNoStartServer: ::libc::c_uint = 1; +pub const JackUseExactName: ::libc::c_uint = 2; +pub const JackServerName: ::libc::c_uint = 4; +pub const JackLoadName: ::libc::c_uint = 8; +pub const JackLoadInit: ::libc::c_uint = 16; +pub const JackSessionID: ::libc::c_uint = 32; +pub type jack_options_t = Enum_JackOptions; +pub type Enum_JackStatus = ::libc::c_uint; +pub const JackFailure: ::libc::c_uint = 1; +pub const JackInvalidOption: ::libc::c_uint = 2; +pub const JackNameNotUnique: ::libc::c_uint = 4; +pub const JackServerStarted: ::libc::c_uint = 8; +pub const JackServerFailed: ::libc::c_uint = 16; +pub const JackServerError: ::libc::c_uint = 32; +pub const JackNoSuchClient: ::libc::c_uint = 64; +pub const JackLoadFailure: ::libc::c_uint = 128; +pub const JackInitFailure: ::libc::c_uint = 256; +pub const JackShmFailure: ::libc::c_uint = 512; +pub const JackVersionError: ::libc::c_uint = 1024; +pub const JackBackendError: ::libc::c_uint = 2048; +pub const JackClientZombie: ::libc::c_uint = 4096; +pub type jack_status_t = Enum_JackStatus; +pub type Enum_JackLatencyCallbackMode = ::libc::c_uint; +pub const JackCaptureLatency: ::libc::c_uint = 0; +pub const JackPlaybackLatency: ::libc::c_uint = 1; +pub type jack_latency_callback_mode_t = Enum_JackLatencyCallbackMode; +pub type JackLatencyCallback = ::std::option::Option< + unsafe extern "C" fn(mode: jack_latency_callback_mode_t, arg: *mut ::libc::c_void) -> (), +>; +#[repr(C, packed)] +#[derive(Copy)] +pub struct Struct__jack_latency_range { + pub min: jack_nframes_t, + pub max: jack_nframes_t, +} +impl ::std::clone::Clone for Struct__jack_latency_range { + fn clone(&self) -> Self { + *self + } +} +impl ::std::default::Default for Struct__jack_latency_range { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type jack_latency_range_t = Struct__jack_latency_range; +pub type JackProcessCallback = ::std::option::Option< + unsafe extern "C" fn(nframes: jack_nframes_t, arg: *mut ::libc::c_void) -> ::libc::c_int, +>; +pub type JackThreadCallback = + ::std::option::Option *mut ::libc::c_void>; +pub type JackThreadInitCallback = + ::std::option::Option ()>; +pub type JackGraphOrderCallback = + ::std::option::Option ::libc::c_int>; +pub type JackXRunCallback = + ::std::option::Option ::libc::c_int>; +pub type JackBufferSizeCallback = ::std::option::Option< + unsafe extern "C" fn(nframes: jack_nframes_t, arg: *mut ::libc::c_void) -> ::libc::c_int, +>; +pub type JackSampleRateCallback = ::std::option::Option< + unsafe extern "C" fn(nframes: jack_nframes_t, arg: *mut ::libc::c_void) -> ::libc::c_int, +>; +pub type JackPortRegistrationCallback = ::std::option::Option< + unsafe extern "C" fn(port: jack_port_id_t, arg1: ::libc::c_int, arg: *mut ::libc::c_void) -> (), +>; +pub type JackClientRegistrationCallback = ::std::option::Option< + unsafe extern "C" fn( + name: *const ::libc::c_char, + arg1: ::libc::c_int, + arg: *mut ::libc::c_void, + ) -> (), +>; +pub type JackPortConnectCallback = ::std::option::Option< + unsafe extern "C" fn( + a: jack_port_id_t, + b: jack_port_id_t, + connect: ::libc::c_int, + arg: *mut ::libc::c_void, + ) -> (), +>; +pub type JackPortRenameCallback = ::std::option::Option< + unsafe extern "C" fn( + port: jack_port_id_t, + old_name: *const ::libc::c_char, + new_name: *const ::libc::c_char, + arg: *mut ::libc::c_void, + ) -> ::libc::c_int, +>; +pub type JackFreewheelCallback = ::std::option::Option< + unsafe extern "C" fn(starting: ::libc::c_int, arg: *mut ::libc::c_void) -> (), +>; +pub type JackShutdownCallback = + ::std::option::Option ()>; +pub type JackInfoShutdownCallback = ::std::option::Option< + unsafe extern "C" fn( + code: jack_status_t, + reason: *const ::libc::c_char, + arg: *mut ::libc::c_void, + ) -> (), +>; +pub type jack_default_audio_sample_t = ::libc::c_float; +pub type Enum_JackPortFlags = ::libc::c_uint; +pub const JackPortIsInput: ::libc::c_uint = 1; +pub const JackPortIsOutput: ::libc::c_uint = 2; +pub const JackPortIsPhysical: ::libc::c_uint = 4; +pub const JackPortCanMonitor: ::libc::c_uint = 8; +pub const JackPortIsTerminal: ::libc::c_uint = 16; +pub type Enum_Unnamed1 = ::libc::c_uint; +pub const JackTransportStopped: ::libc::c_uint = 0; +pub const JackTransportRolling: ::libc::c_uint = 1; +pub const JackTransportLooping: ::libc::c_uint = 2; +pub const JackTransportStarting: ::libc::c_uint = 3; +pub const JackTransportNetStarting: ::libc::c_uint = 4; +pub type jack_transport_state_t = Enum_Unnamed1; +pub type jack_unique_t = u64; +pub type Enum_Unnamed2 = ::libc::c_uint; +pub const JackPositionBBT: ::libc::c_uint = 16; +pub const JackPositionTimecode: ::libc::c_uint = 32; +pub const JackBBTFrameOffset: ::libc::c_uint = 64; +pub const JackAudioVideoRatio: ::libc::c_uint = 128; +pub const JackVideoFrameOffset: ::libc::c_uint = 256; +pub type jack_position_bits_t = Enum_Unnamed2; +#[repr(C, packed)] +#[derive(Copy)] +pub struct Struct__jack_position { + pub unique_1: jack_unique_t, + pub usecs: jack_time_t, + pub frame_rate: jack_nframes_t, + pub frame: jack_nframes_t, + pub valid: jack_position_bits_t, + pub bar: i32, + pub beat: i32, + pub tick: i32, + pub bar_start_tick: ::libc::c_double, + pub beats_per_bar: ::libc::c_float, + pub beat_type: ::libc::c_float, + pub ticks_per_beat: ::libc::c_double, + pub beats_per_minute: ::libc::c_double, + pub frame_time: ::libc::c_double, + pub next_time: ::libc::c_double, + pub bbt_offset: jack_nframes_t, + pub audio_frames_per_video_frame: ::libc::c_float, + pub video_offset: jack_nframes_t, + pub padding: [i32; 7usize], + pub unique_2: jack_unique_t, +} +impl ::std::clone::Clone for Struct__jack_position { + fn clone(&self) -> Self { + *self + } +} +impl ::std::default::Default for Struct__jack_position { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type jack_position_t = Struct__jack_position; +pub type JackSyncCallback = ::std::option::Option< + unsafe extern "C" fn( + state: jack_transport_state_t, + pos: *mut jack_position_t, + arg: *mut ::libc::c_void, + ) -> ::libc::c_int, +>; +pub type TimebaseCallback = ::std::option::Option< + unsafe extern "C" fn( + state: jack_transport_state_t, + nframes: jack_nframes_t, + pos: *mut jack_position_t, + new_pos: ::libc::c_int, + arg: *mut ::libc::c_void, + ) -> (), +>; +pub type Enum_Unnamed3 = ::libc::c_uint; +pub const JackTransportState: ::libc::c_uint = 1; +pub const JackTransportPosition: ::libc::c_uint = 2; +pub const JackTransportLoop: ::libc::c_uint = 4; +pub const JackTransportSMPTE: ::libc::c_uint = 8; +pub const JackTransportBBT: ::libc::c_uint = 16; +pub type jack_transport_bits_t = Enum_Unnamed3; +#[repr(C)] +#[derive(Copy)] +pub struct Struct_Unnamed4 { + pub frame_rate: jack_nframes_t, + pub usecs: jack_time_t, + pub valid: jack_transport_bits_t, + pub transport_state: jack_transport_state_t, + pub frame: jack_nframes_t, + pub loop_start: jack_nframes_t, + pub loop_end: jack_nframes_t, + pub smpte_offset: ::libc::c_long, + pub smpte_frame_rate: ::libc::c_float, + pub bar: ::libc::c_int, + pub beat: ::libc::c_int, + pub tick: ::libc::c_int, + pub bar_start_tick: ::libc::c_double, + pub beats_per_bar: ::libc::c_float, + pub beat_type: ::libc::c_float, + pub ticks_per_beat: ::libc::c_double, + pub beats_per_minute: ::libc::c_double, +} +impl ::std::clone::Clone for Struct_Unnamed4 { + fn clone(&self) -> Self { + *self + } +} +impl ::std::default::Default for Struct_Unnamed4 { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type jack_transport_info_t = Struct_Unnamed4; +#[cfg(not(target_os = "windows"))] +pub type jack_thread_creator_t = ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::libc::pthread_t, + arg2: *const ::libc::pthread_attr_t, + function: ::std::option::Option< + extern "C" fn(arg1: *mut ::libc::c_void) -> *mut ::libc::c_void, + >, + arg: *mut ::libc::c_void, + ) -> ::libc::c_int, +>; +pub type Enum_JackSessionEventType = ::libc::c_uint; +pub const JackSessionSave: ::libc::c_uint = 1; +pub const JackSessionSaveAndQuit: ::libc::c_uint = 2; +pub const JackSessionSaveTemplate: ::libc::c_uint = 3; +pub type jack_session_event_type_t = Enum_JackSessionEventType; +pub type Enum_JackSessionFlags = ::libc::c_uint; +pub const JackSessionSaveError: ::libc::c_uint = 1; +pub const JackSessionNeedTerminal: ::libc::c_uint = 2; +pub type jack_session_flags_t = Enum_JackSessionFlags; +#[repr(C)] +#[derive(Copy)] +pub struct Struct__jack_session_event { + pub _type: jack_session_event_type_t, + pub session_dir: *const ::libc::c_char, + pub client_uuid: *const ::libc::c_char, + pub command_line: *mut ::libc::c_char, + pub flags: jack_session_flags_t, + pub future: u32, +} +impl ::std::clone::Clone for Struct__jack_session_event { + fn clone(&self) -> Self { + *self + } +} +impl ::std::default::Default for Struct__jack_session_event { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type jack_session_event_t = Struct__jack_session_event; +pub type JackSessionCallback = ::std::option::Option< + unsafe extern "C" fn(event: *mut jack_session_event_t, arg: *mut ::libc::c_void) -> (), +>; +#[repr(C)] +#[derive(Copy)] +pub struct Struct_Unnamed5 { + pub uuid: *const ::libc::c_char, + pub client_name: *const ::libc::c_char, + pub command: *const ::libc::c_char, + pub flags: jack_session_flags_t, +} +impl ::std::clone::Clone for Struct_Unnamed5 { + fn clone(&self) -> Self { + *self + } +} +impl ::std::default::Default for Struct_Unnamed5 { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type jack_session_command_t = Struct_Unnamed5; +pub type JSList = Struct__JSList; +pub type JCompareFunc = ::std::option::Option< + unsafe extern "C" fn(a: *mut ::libc::c_void, b: *mut ::libc::c_void) -> ::libc::c_int, +>; +#[repr(C)] +#[derive(Copy)] +pub struct Struct__JSList { + pub data: *mut ::libc::c_void, + pub next: *mut JSList, +} +impl ::std::clone::Clone for Struct__JSList { + fn clone(&self) -> Self { + *self + } +} +impl ::std::default::Default for Struct__JSList { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type Enum_Unnamed6 = ::libc::c_uint; +pub const JackParamInt: ::libc::c_uint = 1; +pub const JackParamUInt: ::libc::c_uint = 2; +pub const JackParamChar: ::libc::c_uint = 3; +pub const JackParamString: ::libc::c_uint = 4; +pub const JackParamBool: ::libc::c_uint = 5; +pub type jackctl_param_type_t = Enum_Unnamed6; +pub type Enum_Unnamed7 = ::libc::c_uint; +pub const JackMaster: ::libc::c_uint = 1; +pub const JackSlave: ::libc::c_uint = 2; +pub type jackctl_driver_type_t = Enum_Unnamed7; +#[repr(C)] +#[derive(Copy)] +pub struct Union_jackctl_parameter_value { + pub _bindgen_data_: [u32; 32usize], +} +impl Union_jackctl_parameter_value { + pub unsafe fn ui(&mut self) -> *mut u32 { + let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_); + ::std::mem::transmute(raw.offset(0)) + } + pub unsafe fn i(&mut self) -> *mut i32 { + let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_); + ::std::mem::transmute(raw.offset(0)) + } + pub unsafe fn c(&mut self) -> *mut ::libc::c_char { + let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_); + ::std::mem::transmute(raw.offset(0)) + } + pub unsafe fn str(&mut self) -> *mut [::libc::c_char; 128usize] { + let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_); + ::std::mem::transmute(raw.offset(0)) + } + pub unsafe fn b(&mut self) -> *mut u8 { + let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_); + ::std::mem::transmute(raw.offset(0)) + } +} +impl ::std::clone::Clone for Union_jackctl_parameter_value { + fn clone(&self) -> Self { + *self + } +} +impl ::std::default::Default for Union_jackctl_parameter_value { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub enum Struct_jackctl_server {} +pub type jackctl_server_t = Struct_jackctl_server; +pub enum Struct_jackctl_driver {} +pub type jackctl_driver_t = Struct_jackctl_driver; +pub enum Struct_jackctl_internal {} +pub type jackctl_internal_t = Struct_jackctl_internal; +pub enum Struct_jackctl_parameter {} +pub type jackctl_parameter_t = Struct_jackctl_parameter; +pub enum Struct_jackctl_sigmask {} +pub type jackctl_sigmask_t = Struct_jackctl_sigmask; +#[repr(C)] +#[derive(Copy)] +pub struct Struct_Unnamed8 { + pub key: *const ::libc::c_char, + pub data: *const ::libc::c_char, + pub _type: *const ::libc::c_char, +} +impl ::std::clone::Clone for Struct_Unnamed8 { + fn clone(&self) -> Self { + *self + } +} +impl ::std::default::Default for Struct_Unnamed8 { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type jack_property_t = Struct_Unnamed8; +#[repr(C)] +#[derive(Copy)] +pub struct Struct_Unnamed9 { + pub subject: jack_uuid_t, + pub property_cnt: u32, + pub properties: *mut jack_property_t, + pub property_size: u32, +} +impl ::std::clone::Clone for Struct_Unnamed9 { + fn clone(&self) -> Self { + *self + } +} +impl ::std::default::Default for Struct_Unnamed9 { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type jack_description_t = Struct_Unnamed9; +pub type Enum_Unnamed10 = ::libc::c_uint; +pub const PropertyCreated: ::libc::c_uint = 0; +pub const PropertyChanged: ::libc::c_uint = 1; +pub const PropertyDeleted: ::libc::c_uint = 2; +pub type jack_property_change_t = Enum_Unnamed10; +pub type JackPropertyChangeCallback = ::std::option::Option< + unsafe extern "C" fn( + subject: jack_uuid_t, + key: *const ::libc::c_char, + change: jack_property_change_t, + arg: *mut ::libc::c_void, + ) -> (), +>; +pub type jack_midi_data_t = ::libc::c_uchar; +#[repr(C)] +#[derive(Copy)] +pub struct Struct__jack_midi_event { + pub time: jack_nframes_t, + pub size: ::libc::size_t, + pub buffer: *mut jack_midi_data_t, +} +impl ::std::clone::Clone for Struct__jack_midi_event { + fn clone(&self) -> Self { + *self + } +} +impl ::std::default::Default for Struct__jack_midi_event { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type jack_midi_event_t = Struct__jack_midi_event; +#[repr(C)] +#[derive(Copy)] +pub struct Struct_Unnamed11 { + pub buf: *mut ::libc::c_char, + pub len: ::libc::size_t, +} +impl ::std::clone::Clone for Struct_Unnamed11 { + fn clone(&self) -> Self { + *self + } +} +impl ::std::default::Default for Struct_Unnamed11 { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type jack_ringbuffer_data_t = Struct_Unnamed11; +#[repr(C)] +#[derive(Copy)] +pub struct Struct_Unnamed12 { + pub buf: *mut ::libc::c_char, + pub write_ptr: ::libc::size_t, + pub read_ptr: ::libc::size_t, + pub size: ::libc::size_t, + pub size_mask: ::libc::size_t, + pub mlocked: ::libc::c_int, +} +impl ::std::clone::Clone for Struct_Unnamed12 { + fn clone(&self) -> Self { + *self + } +} +impl ::std::default::Default for Struct_Unnamed12 { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type jack_ringbuffer_t = Struct_Unnamed12; +extern "C" { + pub static mut jack_error_callback: + ::std::option::Option ()>; + pub static mut jack_info_callback: + ::std::option::Option ()>; + pub static mut JACK_METADATA_PRETTY_NAME: *const ::libc::c_char; + pub static mut JACK_METADATA_HARDWARE: *const ::libc::c_char; + pub static mut JACK_METADATA_CONNECTED: *const ::libc::c_char; + pub static mut JACK_METADATA_PORT_GROUP: *const ::libc::c_char; + pub static mut JACK_METADATA_ICON_SMALL: *const ::libc::c_char; + pub static mut JACK_METADATA_ICON_LARGE: *const ::libc::c_char; +} diff --git a/src/client/async_client.rs b/src/client/async_client.rs index 05593c36..b1a785a8 100644 --- a/src/client/async_client.rs +++ b/src/client/async_client.rs @@ -1,8 +1,4 @@ -#[cfg(feature = "dlopen")] -use crate::LIB; -use dlib::ffi_dispatch; -#[cfg(not(feature = "dlopen"))] -use jack_sys::*; +use jack_sys as j; use std::fmt; use std::fmt::Debug; use std::mem; @@ -65,12 +61,7 @@ where }); CallbackContext::register_callbacks(&mut callback_context)?; sleep_on_test(); - let res = ffi_dispatch!( - feature = "dlopen", - LIB, - jack_activate, - callback_context.client.raw() - ); + let res = j::jack_activate(callback_context.client.raw()); for _ in 0..4 { sleep_on_test(); } @@ -125,7 +116,7 @@ impl AsyncClient { // deactivate sleep_on_test(); - if ffi_dispatch!(feature = "dlopen", LIB, jack_deactivate, client) != 0 { + if j::jack_deactivate(client) != 0 { return Err(Error::ClientDeactivationError); } diff --git a/src/client/callbacks.rs b/src/client/callbacks.rs index 0b3a9115..e7d3da70 100644 --- a/src/client/callbacks.rs +++ b/src/client/callbacks.rs @@ -1,8 +1,4 @@ -#[cfg(feature = "dlopen")] -use crate::LIB; -use dlib::ffi_dispatch; -#[cfg(not(feature = "dlopen"))] -use jack_sys::*; +use jack_sys as j; use std::ffi; use crate::{Client, ClientStatus, Control, Error, Frames, PortId, ProcessScope}; @@ -20,7 +16,7 @@ pub trait NotificationHandler: Send { /// must be written as if /// it were an asynchronous POSIX signal handler --- use only async-safe /// functions, and remember - /// that it is executed from another thread. A typical function might set a + /// that it is executed from another thread. A typical funcion might set a /// flag or write to a /// pipe so that the rest of the application knows that the JACK client /// thread has shut down. @@ -96,7 +92,7 @@ pub trait ProcessHandler: Send { /// /// It is called on the same thread as `process`, but as an exception, does /// not need to be suitable for real-time execution, so it is allowed to - /// allocate new buffers to accommodate the buffer size for example. + /// allocate new buffers to accomodate the buffer size for example. fn buffer_size(&mut self, _: &Client, _size: Frames) -> Control { Control::Continue } @@ -112,7 +108,7 @@ where } unsafe extern "C" fn shutdown( - code: jack_sys::jack_status_t, + code: j::jack_status_t, reason: *const libc::c_char, data: *mut libc::c_void, ) where @@ -260,9 +256,9 @@ where /// # TODO /// /// * Implement correctly. Freezes on my system. -pub unsafe fn clear_callbacks(_client: *mut jack_sys::jack_client_t) -> Result<(), Error> { - // jack_sys::jack_set_thread_init_callback(client, None, ptr::null_mut()); - // jack_sys::jack_set_process_callback(client, None, ptr::null_mut()); +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()); Ok(()) } @@ -296,7 +292,7 @@ where /// `Err(Error::CallbackRegistrationError)` on failure. /// /// `handler_ptr` here is a pointer to a heap-allocated pair `(T, *mut - /// jack_sys::jack_client_t)`. + /// j::jack_client_t)`. /// /// Registers `handler` with JACK. All JACK calls to `client` will be handled by /// `handler`. `handler` is consumed, but it is not deallocated. `handler` @@ -317,96 +313,23 @@ where pub unsafe fn register_callbacks(b: &mut Box) -> Result<(), Error> { let data_ptr = CallbackContext::raw(b); let client = b.client.raw(); - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_set_thread_init_callback, - client, - Some(thread_init_callback::), - data_ptr - ); - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_on_info_shutdown, - client, - Some(shutdown::), - data_ptr - ); - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_set_process_callback, - client, - Some(process::), - data_ptr - ); - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_set_freewheel_callback, - client, - Some(freewheel::), - data_ptr - ); - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_set_buffer_size_callback, - client, - Some(buffer_size::), - data_ptr - ); - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_set_sample_rate_callback, - client, - Some(sample_rate::), - data_ptr - ); - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_set_client_registration_callback, + j::jack_set_thread_init_callback(client, Some(thread_init_callback::), data_ptr); + j::jack_on_info_shutdown(client, Some(shutdown::), data_ptr); + j::jack_set_process_callback(client, Some(process::), data_ptr); + j::jack_set_freewheel_callback(client, Some(freewheel::), data_ptr); + j::jack_set_buffer_size_callback(client, Some(buffer_size::), data_ptr); + j::jack_set_sample_rate_callback(client, Some(sample_rate::), data_ptr); + j::jack_set_client_registration_callback( client, Some(client_registration::), - data_ptr - ); - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_set_port_registration_callback, - client, - Some(port_registration::), - data_ptr + data_ptr, ); + j::jack_set_port_registration_callback(client, Some(port_registration::), data_ptr); // doesn't compile for testing since it is a weak export - // jack_sys::jack_set_port_rename_callback(client, Some(port_rename::), - data_ptr - ); - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_set_graph_order_callback, - client, - Some(graph_order::), - data_ptr - ); - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_set_xrun_callback, - client, - Some(xrun::), - data_ptr - ); + // j::jack_set_port_rename_callback(client, Some(port_rename::), data_ptr); + j::jack_set_graph_order_callback(client, Some(graph_order::), data_ptr); + j::jack_set_xrun_callback(client, Some(xrun::), data_ptr); Ok(()) } } diff --git a/src/client/client_impl.rs b/src/client/client_impl.rs index f667e93f..d2be6ce5 100644 --- a/src/client/client_impl.rs +++ b/src/client/client_impl.rs @@ -1,10 +1,4 @@ -#[cfg(feature = "dlopen")] -use crate::LIB; -#[cfg(all(feature = "dlopen", feature = "metadata"))] -use crate::UUID; -use dlib::ffi_dispatch; -#[cfg(not(feature = "dlopen"))] -use jack_sys::*; +use jack_sys as j; use std::fmt::Debug; use std::sync::Arc; use std::{ffi, fmt, ptr}; @@ -34,14 +28,13 @@ use crate::{ /// }; /// ``` -pub type InternalClientID = jack_sys::jack_intclient_t; +pub type InternalClientID = j::jack_intclient_t; -#[allow(dead_code)] -pub struct Client { - inner: *mut jack_sys::jack_client_t, - life: Arc<()>, - property_change_handler: Option>, -} +pub struct Client( + *mut j::jack_client_t, + Arc<()>, + Option>, +); unsafe impl Send for Client {} unsafe impl Sync for Client {} @@ -55,50 +48,22 @@ impl Client { /// errors when attempting to opening. To access these, check the returned `ClientStatus`. pub fn new(client_name: &str, options: ClientOptions) -> Result<(Self, ClientStatus), Error> { let _m = CREATE_OR_DESTROY_CLIENT_MUTEX.lock().unwrap(); - #[cfg(feature = "dlopen")] - let lib = crate::LIB_RESULT - .as_ref() - .map_err(|e| Error::LoadLibraryError(format!("{}", e)))?; unsafe { - ffi_dispatch!( - feature = "dlopen", - lib, - jack_set_error_function, - Some(error_fn) - ); - ffi_dispatch!( - feature = "dlopen", - lib, - jack_set_info_function, - Some(info_fn) - ); + jack_sys::jack_set_error_function(Some(error_handler)); + jack_sys::jack_set_info_function(Some(info_handler)); } sleep_on_test(); let mut status_bits = 0; let client = unsafe { let client_name = ffi::CString::new(client_name).unwrap(); - ffi_dispatch!( - feature = "dlopen", - lib, - jack_client_open, - client_name.as_ptr(), - options.bits(), - &mut status_bits - ) + j::jack_client_open(client_name.as_ptr(), options.bits(), &mut status_bits) }; sleep_on_test(); let status = ClientStatus::from_bits(status_bits).unwrap_or_else(ClientStatus::empty); if client.is_null() { Err(Error::ClientError(status)) } else { - Ok(( - Client { - inner: client, - life: Arc::default(), - property_change_handler: None, - }, - status, - )) + Ok((Client(client, Arc::default(), None), status)) } } @@ -119,8 +84,7 @@ impl Client { /// The sample rate of the JACK system, as set by the user when jackd was /// started. pub fn sample_rate(&self) -> usize { - let srate = - unsafe { ffi_dispatch!(feature = "dlopen", LIB, jack_get_sample_rate, self.raw()) }; + let srate = unsafe { j::jack_get_sample_rate(self.raw()) }; srate as usize } @@ -130,7 +94,7 @@ impl Client { /// clients as a percentage of the real time available per cycle determined by the buffer size /// and sample rate. pub fn cpu_load(&self) -> f32 { - let load = unsafe { ffi_dispatch!(feature = "dlopen", LIB, jack_cpu_load, self.raw()) }; + let load = unsafe { j::jack_cpu_load(self.raw()) }; load as f32 } @@ -140,7 +104,7 @@ impl Client { /// `NAME_NOT_UNIQUE`. pub fn name(&self) -> &str { unsafe { - let ptr = ffi_dispatch!(feature = "dlopen", LIB, jack_get_client_name, self.raw()); + let ptr = j::jack_get_client_name(self.raw()); let cstr = ffi::CStr::from_ptr(ptr); cstr.to_str().unwrap() } @@ -149,7 +113,7 @@ impl Client { /// The current maximum size that will every be passed to the process /// callback. pub fn buffer_size(&self) -> Frames { - unsafe { ffi_dispatch!(feature = "dlopen", LIB, jack_get_buffer_size, self.raw()) } + unsafe { j::jack_get_buffer_size(self.raw()) } } /// Change the buffer size passed to the process callback. @@ -158,15 +122,7 @@ impl Client { /// callback functions before restarting the process cycle. This will cause a gap in the audio /// flow, so it should only be done at appropriate stopping points. pub fn set_buffer_size(&self, n_frames: Frames) -> Result<(), Error> { - let res = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_set_buffer_size, - self.raw(), - n_frames - ) - }; + let res = unsafe { j::jack_set_buffer_size(self.raw(), n_frames) }; match res { 0 => Ok(()), _ => Err(Error::SetBufferSizeError), @@ -179,13 +135,13 @@ impl Client { /// /// * Deallocates, not realtime safe. #[cfg(feature = "metadata")] - pub fn uuid(&self) -> jack_sys::jack_uuid_t { + pub fn uuid(&self) -> j::jack_uuid_t { unsafe { - let mut uuid: jack_sys::jack_uuid_t = Default::default(); - let uuid_s = ffi_dispatch!(feature = "dlopen", LIB, jack_client_get_uuid, self.raw()); + let mut uuid: j::jack_uuid_t = Default::default(); + let uuid_s = j::jack_client_get_uuid(self.raw()); assert!(!uuid_s.is_null()); - assert_eq!(0, ffi_dispatch!(UUID, jack_uuid_parse, uuid_s, &mut uuid)); - ffi_dispatch!(feature = "dlopen", LIB, jack_free, uuid_s as _); + assert_eq!(0, j::jack_uuid_parse(uuid_s, &mut uuid)); + j::jack_free(uuid_s as _); uuid } } @@ -197,26 +153,20 @@ impl Client { /// * Allocates & deallocates, not realtime safe. pub fn uuid_string(&self) -> String { unsafe { - let uuid_s = ffi_dispatch!(feature = "dlopen", LIB, jack_client_get_uuid, self.raw()); + let uuid_s = j::jack_client_get_uuid(self.raw()); assert!(!uuid_s.is_null()); let uuid = ffi::CStr::from_ptr(uuid_s) .to_str() .expect("uuid is valid string") .to_string(); - ffi_dispatch!(feature = "dlopen", LIB, jack_free, uuid_s as _); + j::jack_free(uuid_s as _); uuid } } //helper to get client name from uuid string. unsafe fn name_by_uuid_raw(&self, uuid: *const ::libc::c_char) -> Option { - let name_ptr = ffi_dispatch!( - feature = "dlopen", - LIB, - jack_get_client_name_by_uuid, - self.raw(), - uuid - ); + let name_ptr = j::jack_get_client_name_by_uuid(self.raw(), uuid); if name_ptr.is_null() { None } else { @@ -231,11 +181,10 @@ impl Client { /// Get the name of a client by its numeric uuid. #[cfg(feature = "metadata")] - pub fn name_by_uuid(&self, uuid: jack_sys::jack_uuid_t) -> Option { + pub fn name_by_uuid(&self, uuid: j::jack_uuid_t) -> Option { let mut uuid_s = ['\0' as _; 37]; //jack_uuid_unparse expects an array of length 37 - unsafe { - ffi_dispatch!(UUID, jack_uuid_unparse, uuid, uuid_s.as_mut_ptr()); + j::jack_uuid_unparse(uuid, uuid_s.as_mut_ptr()); self.name_by_uuid_raw(uuid_s.as_ptr()) } } @@ -267,16 +216,12 @@ impl Client { let port_name_pattern_cstr = ffi::CString::new(port_name_pattern.unwrap_or("")).unwrap(); let type_name_pattern_cstr = ffi::CString::new(type_name_pattern.unwrap_or("")).unwrap(); let flags = libc::c_ulong::from(flags.bits()); - let ptr = self.raw(); unsafe { - let ports = ffi_dispatch!( - feature = "dlopen", - LIB, - jack_get_ports, - ptr, + let ports = j::jack_get_ports( + self.raw(), port_name_pattern_cstr.as_ptr(), type_name_pattern_cstr.as_ptr(), - flags + flags, ); collect_strs(ports) } @@ -305,58 +250,39 @@ impl Client { let port_flags = port_spec.jack_flags().bits(); let buffer_size = port_spec.jack_buffer_size(); let pp = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_register, + j::jack_port_register( self.raw(), port_name_c.as_ptr(), port_type_c.as_ptr(), libc::c_ulong::from(port_flags), - buffer_size + buffer_size, ) }; if pp.is_null() { Err(Error::PortRegistrationError(port_name.to_string())) } else { - Ok(unsafe { Port::from_raw(port_spec, self.raw(), pp, Arc::downgrade(&self.life)) }) + Ok(unsafe { Port::from_raw(port_spec, self.raw(), pp, Arc::downgrade(&self.1)) }) } } /// Get a `Port` by its port id. pub fn port_by_id(&self, port_id: PortId) -> Option> { - let pp = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_by_id, - self.raw(), - port_id - ) - }; + let pp = unsafe { j::jack_port_by_id(self.raw(), port_id) }; if pp.is_null() { None } else { - Some(unsafe { Port::from_raw(Unowned {}, self.raw(), pp, Arc::downgrade(&self.life)) }) + Some(unsafe { Port::from_raw(Unowned {}, self.raw(), pp, Arc::downgrade(&self.1)) }) } } /// Get a `Port` by its port name. pub fn port_by_name(&self, port_name: &str) -> Option> { let port_name = ffi::CString::new(port_name).unwrap(); - let pp = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_by_name, - self.raw(), - port_name.as_ptr() - ) - }; + let pp = unsafe { j::jack_port_by_name(self.raw(), port_name.as_ptr()) }; if pp.is_null() { None } else { - Some(unsafe { Port::from_raw(Unowned {}, self.raw(), pp, Arc::downgrade(&self.life)) }) + Some(unsafe { Port::from_raw(Unowned {}, self.raw(), pp, Arc::downgrade(&self.1)) }) } } @@ -384,27 +310,26 @@ impl Client { let ffi_client_args = ffi::CString::new(client_args).unwrap(); let mut status_bits = 0; - let options: jack_sys::Enum_JackOptions = jack_sys::JackLoadName | jack_sys::JackLoadInit; + let options: j::Enum_JackOptions = j::JackLoadName | j::JackLoadInit; let intclient = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_internal_client_load, + j::jack_internal_client_load( self.raw(), ffi_client_name.as_ptr(), options, &mut status_bits, - ffi_client_bin.as_ptr() as _, - ffi_client_args.as_ptr() + ffi_client_bin.as_ptr(), + ffi_client_args.as_ptr(), ) }; - if intclient == 0 { - let status = ClientStatus::from_bits(status_bits).unwrap_or_else(ClientStatus::empty); - Err(Error::ClientError(status)) - } else { - Ok(intclient) + match intclient { + Some(0) => { + let status = ClientStatus::from_bits(status_bits).unwrap_or_else(ClientStatus::empty); + Err(Error::ClientError(status)) + }, + Some(i) => Ok(i), + None => Err(Error::WeakFunctionNotFound("jack_internal_client_load")), } } @@ -418,13 +343,10 @@ impl Client { /// It returns a ClientError on error. pub fn unload_internal_client(&self, client: InternalClientID) -> Result<(), Error> { let status = unsafe { - let status = ffi_dispatch!( - feature = "dlopen", - LIB, - jack_internal_client_unload, - self.raw(), - client - ); + let status = match j::jack_internal_client_unload(self.raw(), client) { + Some(s) => s, + None => return Err(Error::WeakFunctionNotFound("jack_internal_client_unload")), + }; ClientStatus::from_bits_unchecked(status) }; if status.is_empty() { @@ -437,14 +359,7 @@ impl Client { /// The estimated time in frames that has passed since the JACK server began the current process /// cycle. pub fn frames_since_cycle_start(&self) -> Frames { - unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_frames_since_cycle_start, - self.raw() - ) - } + unsafe { j::jack_frames_since_cycle_start(self.raw()) } } /// The estimated current time in frames. This function is intended for use in other threads @@ -455,7 +370,7 @@ impl Client { /// # TODO /// - test pub fn frame_time(&self) -> Frames { - unsafe { ffi_dispatch!(feature = "dlopen", LIB, jack_frame_time, self.raw()) } + unsafe { j::jack_frame_time(self.raw()) } } /// The estimated time in microseconds of the specified frame time @@ -463,15 +378,7 @@ impl Client { /// # TODO /// - Improve test pub fn frames_to_time(&self, n_frames: Frames) -> Time { - unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_frames_to_time, - self.raw(), - n_frames - ) - } + unsafe { j::jack_frames_to_time(self.raw(), n_frames) } } /// The estimated time in frames for the specified system time. @@ -479,23 +386,12 @@ impl Client { /// # TODO /// - Improve test pub fn time_to_frames(&self, t: Time) -> Frames { - unsafe { ffi_dispatch!(feature = "dlopen", LIB, jack_time_to_frames, self.raw(), t) } + unsafe { j::jack_time_to_frames(self.raw(), t) } } /// Returns `true` if the port `port` belongs to this client. pub fn is_mine(&self, port: &Port) -> bool { - matches!( - unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_is_mine, - self.raw(), - port.raw() - ) - }, - 1 - ) + matches!(unsafe { j::jack_port_is_mine(self.raw(), port.raw()) }, 1) } /// Toggle input monitoring for the port with name `port_name`. @@ -510,13 +406,10 @@ impl Client { ) -> Result<(), Error> { let port_name_cstr = ffi::CString::new(port_name).unwrap(); let res = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_request_monitor_by_name, + j::jack_port_request_monitor_by_name( self.raw(), port_name_cstr.as_ptr(), - if enable_monitor { 1 } else { 0 } + if enable_monitor { 1 } else { 0 }, ) }; match res { @@ -544,7 +437,7 @@ impl Client { // true => 0, // false => 1, // }; - // match unsafe { jack_sys::jack_set_freewheel(self.raw(), onoff) } { + // match unsafe { j::jack_set_freewheel(self.raw(), onoff) } { // 0 => Ok(()), // _ => Err(Error::FreewheelError), // } @@ -574,16 +467,8 @@ impl Client { let source_cstr = ffi::CString::new(source_port).unwrap(); let destination_cstr = ffi::CString::new(destination_port).unwrap(); - let res = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_connect, - self.raw(), - source_cstr.as_ptr(), - destination_cstr.as_ptr() - ) - }; + let res = + unsafe { j::jack_connect(self.raw(), source_cstr.as_ptr(), destination_cstr.as_ptr()) }; match res { 0 => Ok(()), ::libc::EEXIST => Err(Error::PortAlreadyConnected( @@ -620,15 +505,7 @@ impl Client { /// Remove all connections to/from the port. pub fn disconnect(&self, port: &Port) -> Result<(), Error> { - let res = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_disconnect, - self.raw(), - port.raw() - ) - }; + let res = unsafe { j::jack_port_disconnect(self.raw(), port.raw()) }; match res { 0 => Ok(()), _ => Err(Error::PortDisconnectionError), @@ -636,15 +513,7 @@ impl Client { } pub fn unregister_port(&self, port: Port) -> Result<(), Error> { - let res = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_unregister, - self.raw(), - port.raw() - ) - }; + let res = unsafe { j::jack_port_unregister(self.raw(), port.raw()) }; match res { 0 => Ok(()), _ => Err(Error::PortDisconnectionError), @@ -669,14 +538,7 @@ impl Client { let source_port = ffi::CString::new(source_port).unwrap(); let destination_port = ffi::CString::new(destination_port).unwrap(); let res = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_disconnect, - self.raw(), - source_port.as_ptr(), - destination_port.as_ptr() - ) + j::jack_disconnect(self.raw(), source_port.as_ptr(), destination_port.as_ptr()) }; match res { 0 => Ok(()), @@ -691,21 +553,15 @@ impl Client { /// * This function may only be called in a buffer size callback. pub unsafe fn type_buffer_size(&self, port_type: &str) -> usize { let port_type = ffi::CString::new(port_type).unwrap(); - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_type_get_buffer_size, - self.raw(), - port_type.as_ptr() - ) + j::jack_port_type_get_buffer_size(self.raw(), port_type.as_ptr()) } /// Expose the underlying ffi pointer. /// /// This is mostly for use within the jack crate itself. #[inline(always)] - pub fn raw(&self) -> *mut jack_sys::jack_client_t { - self.inner + pub fn raw(&self) -> *mut j::jack_client_t { + self.0 } /// Create a `Client` from an ffi pointer. @@ -714,12 +570,8 @@ impl Client { /// /// # Safety /// It is unsafe to create a `Client` from a raw pointer. - pub unsafe fn from_raw(p: *mut jack_sys::jack_client_t) -> Self { - Client { - inner: p, - life: Arc::default(), - property_change_handler: None, - } + pub unsafe fn from_raw(p: *mut j::jack_client_t) -> Self { + Client(p, Arc::default(), None) } /// Get a `Transport` object associated with this client. @@ -728,8 +580,8 @@ impl Client { /// * The transport methods will only work during this client's lifetime. pub fn transport(&self) -> Transport { Transport { - client_ptr: self.inner, - client_life: Arc::downgrade(&self.life), + client_ptr: self.0, + client_life: Arc::downgrade(&self.1), } } @@ -745,17 +597,14 @@ impl Client { &mut self, handler: H, ) -> Result<(), Error> { - assert!(self.property_change_handler.is_none()); + assert!(self.2.is_none()); let handler = Box::into_raw(Box::new(handler)); unsafe { - self.property_change_handler = Some(Box::from_raw(handler)); - if ffi_dispatch!( - feature = "dlopen", - LIB, - jack_set_property_change_callback, + self.2 = Some(Box::from_raw(handler)); + if j::jack_set_property_change_callback( self.raw(), Some(crate::properties::property_changed::), - std::mem::transmute::<_, _>(handler) + std::mem::transmute::<_, _>(handler), ) == 0 { Ok(()) @@ -774,10 +623,10 @@ impl Drop for Client { debug_assert!(!self.raw().is_null()); // Rep invariant // Close the client sleep_on_test(); - let res = unsafe { ffi_dispatch!(feature = "dlopen", LIB, jack_client_close, self.raw()) }; // close the client + let res = unsafe { j::jack_client_close(self.raw()) }; // close the client sleep_on_test(); assert_eq!(res, 0); - self.inner = ptr::null_mut(); + self.0 = ptr::null_mut(); } } @@ -797,7 +646,7 @@ impl Debug for Client { /// callback. #[derive(Debug)] pub struct ProcessScope { - client_ptr: *mut jack_sys::jack_client_t, + client_ptr: *mut j::jack_client_t, // Used to allow safe access to IO port buffers n_frames: Frames, @@ -814,27 +663,13 @@ impl ProcessScope { /// from the process callback, and can be used to interpret timestamps generated by /// `self.frame_time()` in other threads, with respect to the current process cycle. pub fn last_frame_time(&self) -> Frames { - unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_last_frame_time, - self.client_ptr() - ) - } + unsafe { j::jack_last_frame_time(self.client_ptr()) } } /// The estimated time in frames that has passed since the JACK server began the current process /// cycle. pub fn frames_since_cycle_start(&self) -> Frames { - unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_frames_since_cycle_start, - self.client_ptr() - ) - } + unsafe { j::jack_frames_since_cycle_start(self.client_ptr()) } } /// Provides the internal cycle timing information as used by most of the other time related @@ -851,14 +686,8 @@ impl ProcessScope { let mut next_usecs: Time = 0; let mut period_usecs: libc::c_float = 0.0; - let jack_get_cycle_times_fn = { - match *jack_sys::jack_get_cycle_times { - Some(f) => f, - None => return Err(Error::WeakFunctionNotFound), - } - }; let res = unsafe { - (jack_get_cycle_times_fn)( + (jack_sys::jack_get_cycle_times)( self.client_ptr(), &mut current_frames, &mut current_usecs, @@ -867,7 +696,8 @@ impl ProcessScope { ) }; match res { - 0 => Ok(CycleTimes { + None => Err(Error::WeakFunctionNotFound("jack_get_cycle_times")), + Some(0) => Ok(CycleTimes { current_frames, current_usecs, next_usecs, @@ -881,7 +711,7 @@ impl ProcessScope { /// /// This is mostly for use within the jack crate itself. #[inline(always)] - pub fn client_ptr(&self) -> *mut jack_sys::jack_client_t { + pub fn client_ptr(&self) -> *mut j::jack_client_t { self.client_ptr } @@ -893,7 +723,7 @@ impl ProcessScope { /// # Safety /// It is unsafe to create a `ProcessScope` since it may not be valid. For library user's, the /// `ProcessScope` is usually passed in as a parameter to a trait's method. - pub unsafe fn from_raw(n_frames: Frames, client_ptr: *mut jack_sys::jack_client_t) -> Self { + pub unsafe fn from_raw(n_frames: Frames, client_ptr: *mut j::jack_client_t) -> Self { ProcessScope { n_frames, client_ptr, @@ -910,14 +740,14 @@ pub struct CycleTimes { pub period_usecs: libc::c_float, } -unsafe extern "C" fn error_fn(msg: *const libc::c_char) { +unsafe extern "C" fn error_handler(msg: *const libc::c_char) { match std::ffi::CStr::from_ptr(msg).to_str() { Ok(msg) => log::error!("{}", msg), Err(err) => log::error!("failed to parse JACK error: {:?}", err), } } -unsafe extern "C" fn info_fn(msg: *const libc::c_char) { +unsafe extern "C" fn info_handler(msg: *const libc::c_char) { match std::ffi::CStr::from_ptr(msg).to_str() { Ok(msg) => log::info!("{}", msg), Err(err) => log::error!("failed to parse JACK error: {:?}", err), diff --git a/src/client/common.rs b/src/client/common.rs index 735e3799..dd8699f8 100644 --- a/src/client/common.rs +++ b/src/client/common.rs @@ -1,5 +1,4 @@ -#[cfg(feature = "dlopen")] -use crate::LIB; +use jack_sys as j; use lazy_static::lazy_static; use std::sync::Mutex; @@ -7,10 +6,7 @@ use std::sync::Mutex; /// into account the final `NULL` character and instead corresponds directly to `.len()`. This value /// is constant. fn client_name_size() -> usize { - #[cfg(feature = "dlopen")] - let s = unsafe { (LIB.jack_client_name_size)() } - 1; - #[cfg(not(feature = "dlopen"))] - let s = unsafe { jack_sys::jack_client_name_size() - 1 }; + let s = unsafe { j::jack_client_name_size() - 1 }; s as usize } diff --git a/src/client/test.rs b/src/client/test.rs index 0291ba2f..5fa72b67 100644 --- a/src/client/test.rs +++ b/src/client/test.rs @@ -46,15 +46,10 @@ fn client_can_activate() { #[test] fn client_can_set_buffer_size() { let (c, _) = open_test_client("client_can_set_buffer_size"); - - // 1024 - As started by dummy_jack_server.sh - let initial_size = 1024; - assert_eq!(c.buffer_size(), initial_size); - - let new_size = 2048; + let initial_size = c.buffer_size(); + let new_size = 2 * initial_size; c.set_buffer_size(new_size).unwrap(); assert_eq!(c.buffer_size(), new_size); - c.set_buffer_size(initial_size).unwrap(); assert_eq!(c.buffer_size(), initial_size); } @@ -75,6 +70,13 @@ fn client_can_deactivate() { a.deactivate().unwrap(); } +#[test] +fn client_knows_buffer_size() { + let (c, _) = open_test_client("client_knows_buffer_size"); + // 1024 - As started by dummy_jack_server.sh + assert_eq!(c.buffer_size(), 1024); +} + #[test] fn client_knows_sample_rate() { let (c, _) = open_test_client("client_knows_sample_rate"); diff --git a/src/jack_enums.rs b/src/jack_enums.rs index 50f46ee3..b4e33c1d 100644 --- a/src/jack_enums.rs +++ b/src/jack_enums.rs @@ -20,10 +20,9 @@ pub enum Error { PortRegistrationError(String), SetBufferSizeError, TimeError, - WeakFunctionNotFound, + WeakFunctionNotFound(&'static str), ClientIsNoLongerAlive, RingbufferCreateFailed, - LoadLibraryError(String), UnknownError, } diff --git a/src/jack_utils.rs b/src/jack_utils.rs index 0f968964..2175ff5b 100644 --- a/src/jack_utils.rs +++ b/src/jack_utils.rs @@ -1,8 +1,4 @@ -#[cfg(feature = "dlopen")] -use crate::LIB; -use dlib::ffi_dispatch; -#[cfg(not(feature = "dlopen"))] -use jack_sys::*; +use jack_sys as j; use std::ffi; /// Collects strings from an array of c-strings into a Rust vector of strings @@ -26,11 +22,6 @@ pub unsafe fn collect_strs(ptr: *const *const libc::c_char) -> Vec { let s = ffi::CStr::from_ptr(cstr_ptr).to_string_lossy().into_owned(); strs.push(s); } - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_free, - ptr as *mut ::libc::c_void - ); + j::jack_free(ptr as *mut ::libc::c_void); strs } diff --git a/src/lib.rs b/src/lib.rs index d5f04709..80b55720 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,40 +1,4 @@ -//! Rust bindings for JACK, a real-time audio and midi library. These bindings are compatible with -//! all implementations of JACK (Pipewire JACK, JACK1, and JACK2). -//! -//! # Linking, dynamic loading, and packaging -//! -//! libjack is shared among all clients on the system, so there must only be a single -//! system-wide version of it. Applications typically should not ship their own copy of libjack. -//! This is an issue for distributing JACK compatible applications on Windows and macOS. On Linux -//! and BSDs, this is not an issue for system packages because the application and JACK server are -//! both distributed by the system package manager. -//! -//! To handle this, use the `dlopen` Cargo feature, which is enabled by default. This feature -//! dynamically loads libjack at runtime rather than linking libjack at build time. If the -//! user does not have JACK installed at runtime, [Client::new] will return [Error::LoadLibraryError]. -//! In this case, have your application show an error message directing the user to install JACK from -//! and, if available, fall back to another audio API. -//! -//! With the `dlopen` feature, neither libjack nor the JACK pkgconfig file need to be present at build -//! time. This is convenient for automated Windows and macOS builds as well as cross compiling. -//! -//! If your application cannot be used without JACK, Linux and BSD packagers may prefer -//! to link libjack at build time. To do this, disable the `dlopen` feature by using -//! `default-features = false` in your application's Cargo.toml. For example: -//! -//! ```toml -//! [target.'cfg(any(windows, target_vendor = "apple"))'.dependencies] -//! # Load libjack at runtime. -//! jack = "0.9" -//! -//! [target.'cfg(not(any(windows, target_vendor = "apple")))'.dependencies] -//! # Link libjack at build time. -//! jack = { version = "0.9", default-features = false } -//! ``` -//! -//! You can set the environment variable `RUST_JACK_DLOPEN` to `on` to enable the `dlopen` feature -//! without needing to edit your application's Cargo.toml. This can be useful for cross compiling -//! to Linux with a different CPU architecture. +//! Rust bindings for JACK, a real-time audio and midi library. //! //! # Server //! @@ -85,8 +49,9 @@ pub use crate::transport::{ TransportStatePosition, }; -#[cfg(feature = "dlopen")] -use lazy_static::lazy_static; +/// The underlying system bindings for JACK. Can be useful for using possibly +/// experimental stuff through `jack_sys::library()`. +pub use jack_sys; //only expose metadata if enabled #[cfg(feature = "metadata")] @@ -115,46 +80,10 @@ mod transport; /// Properties mod properties; -#[cfg(feature = "dlopen")] -lazy_static! { - pub(crate) static ref LIB: &'static jack_sys::JackLib = { - let j = LIB_RESULT.as_ref().unwrap(); - j - }; - static ref LIB_RESULT: Result = - unsafe { jack_sys::JackLib::open(jack_sys::JACK_LIB) }; -} - -#[cfg(all(feature = "dlopen", feature = "metadata"))] -lazy_static! { - pub(crate) static ref METADATA: jack_sys::JackMetadata = - unsafe { jack_sys::JackMetadata::open(jack_sys::JACK_LIB).unwrap() }; -} - -#[cfg(all(feature = "dlopen", feature = "metadata"))] -lazy_static! { - pub(crate) static ref UUID: jack_sys::JackUuid = - unsafe { jack_sys::JackUuid::open(jack_sys::JACK_LIB).unwrap() }; -} - -/// Dynamically loads the JACK library. This is libjack.so on Linux and -/// libjack.dll on Windows. -#[cfg(feature = "dlopen")] -pub fn load_jack_library() -> Result<(), Error> { - LIB_RESULT - .as_ref() - .map(|_| ()) - .map_err(|e| Error::LoadLibraryError(format!("{}", e))) -} - /// Return JACK's current system time in microseconds, using the JACK clock /// source. pub fn get_time() -> primitive_types::Time { - #[cfg(feature = "dlopen")] - let t = unsafe { (LIB.jack_get_time)() }; - #[cfg(not(feature = "dlopen"))] - let t = unsafe { jack_sys::jack_get_time() }; - t + unsafe { jack_sys::jack_get_time() } } #[cfg(test)] diff --git a/src/port/midi.rs b/src/port/midi.rs index 6e64a7fb..77368b6c 100644 --- a/src/port/midi.rs +++ b/src/port/midi.rs @@ -1,8 +1,4 @@ -#[cfg(feature = "dlopen")] -use crate::LIB; -use dlib::ffi_dispatch; -#[cfg(not(feature = "dlopen"))] -use jack_sys::*; +use jack_sys as j; use std::marker::PhantomData; use std::{mem, slice}; @@ -32,7 +28,7 @@ pub struct MidiOut; unsafe impl PortSpec for MidiIn { fn jack_port_type(&self) -> &'static str { - jack_sys::RAW_MIDI_TYPE + j::RAW_MIDI_TYPE } fn jack_flags(&self) -> PortFlags { @@ -86,17 +82,8 @@ impl<'a> MidiIter<'a> { } fn absolute_nth(&self, n: u32) -> Option> { - let mut ev = mem::MaybeUninit::::uninit(); - let res = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_midi_event_get, - ev.as_mut_ptr(), - self.buffer, - n - ) - }; + let mut ev = mem::MaybeUninit::::uninit(); + let res = unsafe { j::jack_midi_event_get(ev.as_mut_ptr(), self.buffer, n) }; if res != 0 { return None; } @@ -110,14 +97,7 @@ impl<'a> MidiIter<'a> { if self.buffer.is_null() { 0 } else { - unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_midi_get_event_count, - self.buffer - ) as usize - } + unsafe { j::jack_midi_get_event_count(self.buffer) as usize } } } } @@ -157,7 +137,7 @@ impl<'a> Iterator for MidiIter<'a> { unsafe impl PortSpec for MidiOut { fn jack_port_type(&self) -> &'static str { - jack_sys::RAW_MIDI_TYPE + j::RAW_MIDI_TYPE } fn jack_flags(&self) -> PortFlags { @@ -176,7 +156,7 @@ impl Port { pub fn writer<'a>(&'a mut self, ps: &'a ProcessScope) -> MidiWriter<'a> { assert_eq!(self.client_ptr(), ps.client_ptr()); let buffer = unsafe { self.buffer(ps.n_frames()) }; - unsafe { ffi_dispatch!(feature = "dlopen", LIB, jack_midi_clear_buffer, buffer) }; + unsafe { j::jack_midi_clear_buffer(buffer) }; MidiWriter { buffer, _phantom: PhantomData, @@ -198,22 +178,12 @@ impl<'a> MidiWriter<'a> { /// realtime messages interspersed with other messagse (realtime messages are fine when they /// occur on their own, like other messages). pub fn write(&mut self, message: &RawMidi) -> Result<(), Error> { - let ev = jack_sys::jack_midi_event_t { + let ev = j::jack_midi_event_t { time: message.time, size: message.bytes.len(), buffer: message.bytes.as_ptr() as *mut u8, }; - let res = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_midi_event_write, - self.buffer, - ev.time, - ev.buffer, - ev.size - ) - }; + let res = unsafe { j::jack_midi_event_write(self.buffer, ev.time, ev.buffer, ev.size) }; match res { 0 => Ok(()), _ => Err(Error::NotEnoughSpace), @@ -225,14 +195,7 @@ impl<'a> MidiWriter<'a> { /// If the return value is greater than 0, than the buffer is full. Currently, the only way /// this can happen is if events are lost on port mixdown. pub fn lost_count(&self) -> usize { - let n = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_midi_get_lost_event_count, - self.buffer - ) - }; + let n = unsafe { j::jack_midi_get_lost_event_count(self.buffer) }; n as usize } @@ -241,14 +204,7 @@ impl<'a> MidiWriter<'a> { /// This function returns the current space available, taking into account events already stored /// in the port. pub fn max_event_size(&self) -> usize { - let n = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_midi_max_event_size, - self.buffer - ) - }; + let n = unsafe { j::jack_midi_max_event_size(self.buffer) }; n as usize } } diff --git a/src/port/port_impl.rs b/src/port/port_impl.rs index 6d0917fe..e5bc79f1 100644 --- a/src/port/port_impl.rs +++ b/src/port/port_impl.rs @@ -1,8 +1,4 @@ -#[cfg(feature = "dlopen")] -use crate::LIB; -use dlib::ffi_dispatch; -#[cfg(not(feature = "dlopen"))] -use jack_sys::*; +use jack_sys as j; use lazy_static::lazy_static; use std::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd}; use std::fmt::Debug; @@ -13,30 +9,19 @@ use std::{ffi, fmt, iter}; use crate::{Error, Frames, LatencyType, PortFlags}; -#[cfg(feature = "dlopen")] lazy_static! { /// The maximum string length for port names. - pub static ref PORT_NAME_SIZE: usize = unsafe { (crate::LIB.jack_port_name_size)() - 1 } as usize; + pub static ref PORT_NAME_SIZE: usize = unsafe { j::jack_port_name_size() - 1 } as usize; /// The maximum string length for jack type names. - pub static ref PORT_TYPE_SIZE: usize = unsafe { (crate::LIB.jack_port_type_size)() - 1 } as usize; -} - -#[cfg(not(feature = "dlopen"))] -lazy_static! { - /// The maximum string length for port names. - pub static ref PORT_NAME_SIZE: usize = unsafe { jack_sys::jack_port_name_size() - 1 } as usize; - - /// The maximum string length for jack type names. - pub static ref PORT_TYPE_SIZE: usize = unsafe { jack_sys::jack_port_type_size() - 1 } as usize; + pub static ref PORT_TYPE_SIZE: usize = unsafe { j::jack_port_type_size() - 1 } as usize; } /// Defines the configuration for a certain port to JACK, ie 32 bit floating audio input, 8 bit raw /// midi output, etc... /// /// # Safety -/// Making your own JACK type is risky. You probably want to use an existing -/// type. For new types, make sure to have a well defined spec of the behavior. +/// This trait is unsafe because it may depend on interpretting raw bytes. pub unsafe trait PortSpec: Sized { /// String used by JACK upon port creation to identify the port /// type. @@ -61,8 +46,8 @@ pub unsafe trait PortSpec: Sized { /// Also, ports can be compared and hashed using their raw pointers. pub struct Port { spec: PS, - client_ptr: *mut jack_sys::jack_client_t, - port_ptr: *mut jack_sys::jack_port_t, + client_ptr: *mut j::jack_client_t, + port_ptr: *mut j::jack_port_t, client_life: Weak<()>, } @@ -90,14 +75,9 @@ impl Port { pub fn name(&self) -> Result { self.check_client_life()?; let s = unsafe { - ffi::CStr::from_ptr(ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_name, - self.raw() - )) - .to_string_lossy() - .to_string() + ffi::CStr::from_ptr(j::jack_port_name(self.raw())) + .to_string_lossy() + .to_string() }; Ok(s) } @@ -107,14 +87,9 @@ impl Port { pub fn short_name(&self) -> Result { self.check_client_life()?; let s = unsafe { - ffi::CStr::from_ptr(ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_short_name, - self.raw() - )) - .to_string_lossy() - .to_string() + ffi::CStr::from_ptr(j::jack_port_short_name(self.raw())) + .to_string_lossy() + .to_string() }; Ok(s) } @@ -122,8 +97,8 @@ impl Port { /// The flags for the port. These are set when the port is registered with /// its client. pub fn flags(&self) -> PortFlags { - let bits = unsafe { ffi_dispatch!(feature = "dlopen", LIB, jack_port_flags, self.raw()) }; - PortFlags::from_bits(bits as jack_sys::Enum_JackPortFlags).unwrap() + let bits = unsafe { j::jack_port_flags(self.raw()) }; + PortFlags::from_bits(bits as j::Enum_JackPortFlags).unwrap() } /// The port type. JACK's built in types include `"32 bit float mono audio`" and `"8 bit raw @@ -131,14 +106,9 @@ impl Port { pub fn port_type(&self) -> Result { self.check_client_life()?; let s = unsafe { - ffi::CStr::from_ptr(ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_type, - self.raw() - )) - .to_string_lossy() - .to_string() + ffi::CStr::from_ptr(j::jack_port_type(self.raw())) + .to_string_lossy() + .to_string() }; Ok(s) } @@ -146,7 +116,7 @@ impl Port { /// Number of ports connected to/from `&self`. pub fn connected_count(&self) -> Result { self.check_client_life()?; - let n = unsafe { ffi_dispatch!(feature = "dlopen", LIB, jack_port_connected, self.raw()) }; + let n = unsafe { j::jack_port_connected(self.raw()) }; Ok(n as usize) } @@ -156,13 +126,7 @@ impl Port { self.check_client_life()?; let res = unsafe { let port_name = ffi::CString::new(port_name).unwrap(); - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_connected_to, - self.raw(), - port_name.as_ptr() - ) + j::jack_port_connected_to(self.raw(), port_name.as_ptr()) }; match res { 0 => Ok(false), @@ -179,13 +143,7 @@ impl Port { let mut b = a.clone(); unsafe { let mut ptrs: [*mut libc::c_char; 2] = [a.as_mut_ptr(), b.as_mut_ptr()]; - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_get_aliases, - self.raw(), - ptrs.as_mut_ptr() - ); + j::jack_port_get_aliases(self.raw(), ptrs.as_mut_ptr()); }; Ok([a, b] .iter() @@ -198,14 +156,7 @@ impl Port { /// Returns `true` if monitoring has been requested for `self`. pub fn is_monitoring_input(&self) -> Result { self.check_client_life()?; - match unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_monitoring_input, - self.raw() - ) - } { + match unsafe { j::jack_port_monitoring_input(self.raw()) } { 0 => Ok(false), _ => Ok(true), } @@ -217,15 +168,7 @@ impl Port { pub fn request_monitor(&self, enable_monitor: bool) -> Result<(), Error> { self.check_client_life()?; let onoff = if enable_monitor { 1 } else { 0 }; - let res = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_request_monitor, - self.raw(), - onoff - ) - }; + let res = unsafe { j::jack_port_request_monitor(self.raw(), onoff) }; match res { 0 => Ok(()), _ => Err(Error::PortMonitorError), @@ -238,15 +181,7 @@ impl Port { pub fn ensure_monitor(&self, enable_monitor: bool) -> Result<(), Error> { self.check_client_life()?; let onoff = if enable_monitor { 1 } else { 0 }; - let res = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_ensure_monitor, - self.raw(), - onoff - ) - }; + let res = unsafe { j::jack_port_ensure_monitor(self.raw(), onoff) }; match res { 0 => Ok(()), _ => Err(Error::PortMonitorError), @@ -258,15 +193,7 @@ impl Port { pub fn set_name(&mut self, short_name: &str) -> Result<(), Error> { self.check_client_life()?; let short_name = ffi::CString::new(short_name).unwrap(); - let res = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_set_name, - self.raw(), - short_name.as_ptr() - ) - }; + let res = unsafe { j::jack_port_set_name(self.raw(), short_name.as_ptr()) }; match res { 0 => Ok(()), _ => Err(Error::PortNamingError), @@ -286,15 +213,7 @@ impl Port { pub fn set_alias(&mut self, alias: &str) -> Result<(), Error> { self.check_client_life()?; let alias = ffi::CString::new(alias).unwrap(); - let res = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_set_alias, - self.raw(), - alias.as_ptr() - ) - }; + let res = unsafe { j::jack_port_set_alias(self.raw(), alias.as_ptr()) }; match res { 0 => Ok(()), _ => Err(Error::PortAliasError), @@ -307,15 +226,7 @@ impl Port { pub fn unset_alias(&mut self, alias: &str) -> Result<(), Error> { self.check_client_life()?; let alias = ffi::CString::new(alias).unwrap(); - let res = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_unset_alias, - self.raw(), - alias.as_ptr() - ) - }; + let res = unsafe { j::jack_port_unset_alias(self.raw(), alias.as_ptr()) }; match res { 0 => Ok(()), _ => Err(Error::PortAliasError), @@ -330,8 +241,8 @@ impl Port { /// It is unsafe to create a `Port` from raw pointers. pub unsafe fn from_raw( spec: PS, - client_ptr: *mut jack_sys::jack_client_t, - port_ptr: *mut jack_sys::jack_port_t, + client_ptr: *mut j::jack_client_t, + port_ptr: *mut j::jack_port_t, client_life: Weak<()>, ) -> Self { Port { @@ -346,7 +257,7 @@ impl Port { /// /// This is mostly for use within the jack crate itself. #[inline(always)] - pub fn client_ptr(&self) -> *mut jack_sys::jack_client_t { + pub fn client_ptr(&self) -> *mut j::jack_client_t { self.client_ptr } @@ -354,7 +265,7 @@ impl Port { /// /// This is mostly for use within the jack crate itself. #[inline(always)] - pub fn raw(&self) -> *mut jack_sys::jack_port_t { + pub fn raw(&self) -> *mut j::jack_port_t { self.port_ptr } @@ -370,13 +281,7 @@ impl Port { pub unsafe fn buffer(&self, n_frames: Frames) -> *mut libc::c_void { // We don't check for life to improve performance in a very hot codepath. // self.check_client_life()?; - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_get_buffer, - self.port_ptr, - n_frames - ) + j::jack_port_get_buffer(self.port_ptr, n_frames) } /// Set the minimum and maximum latencies defined by mode for port, in frames. @@ -387,20 +292,11 @@ impl Port { /// **only** be used inside a latency callback. #[inline(always)] pub fn set_latency_range(&self, mode: LatencyType, range: (Frames, Frames)) { - let mut ffi_range = jack_sys::Struct__jack_latency_range { + let mut ffi_range = j::Struct__jack_latency_range { min: range.0, max: range.1, }; - unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_set_latency_range, - self.port_ptr, - mode.to_ffi(), - &mut ffi_range - ) - }; + unsafe { j::jack_port_set_latency_range(self.port_ptr, mode.to_ffi(), &mut ffi_range) }; } /// Returns a tuple of the minimum and maximum latencies defined by mode for port, in frames. @@ -410,17 +306,8 @@ impl Port { /// used in the LatencyCallback. and therefore safe to execute from callbacks. #[inline(always)] pub fn get_latency_range(&self, mode: LatencyType) -> (Frames, Frames) { - let mut ffi_range = jack_sys::Struct__jack_latency_range { min: 0, max: 0 }; - unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_port_get_latency_range, - self.port_ptr, - mode.to_ffi(), - &mut ffi_range - ) - }; + let mut ffi_range = j::Struct__jack_latency_range { min: 0, max: 0 }; + unsafe { j::jack_port_get_latency_range(self.port_ptr, mode.to_ffi(), &mut ffi_range) }; (ffi_range.min, ffi_range.max) } diff --git a/src/properties.rs b/src/properties.rs index ba9b69cc..5df4166e 100644 --- a/src/properties.rs +++ b/src/properties.rs @@ -1,6 +1,7 @@ //! Properties, AKA [Meta Data](https://jackaudio.org/api/group__Metadata.html) //! -use jack_sys::jack_uuid_t as uuid; +use j::jack_uuid_t as uuid; +use jack_sys as j; /// A description of a Metadata change describint a creation, change or deletion, its owner /// `subject` and `key`. @@ -22,9 +23,9 @@ pub trait PropertyChangeHandler: Send { #[allow(dead_code)] //dead if we haven't enabled metadata pub(crate) unsafe extern "C" fn property_changed

( - subject: jack_sys::jack_uuid_t, + subject: j::jack_uuid_t, key: *const ::libc::c_char, - change: jack_sys::jack_property_change_t, + change: j::jack_property_change_t, arg: *mut ::libc::c_void, ) where P: PropertyChangeHandler, @@ -33,8 +34,8 @@ pub(crate) unsafe extern "C" fn property_changed

( let key_c = std::ffi::CStr::from_ptr(key); let key = key_c.to_str().expect("to convert key to valid str"); let c = match change { - jack_sys::PropertyCreated => PropertyChange::Created { subject, key }, - jack_sys::PropertyDeleted => PropertyChange::Deleted { subject, key }, + j::PropertyCreated => PropertyChange::Created { subject, key }, + j::PropertyDeleted => PropertyChange::Deleted { subject, key }, _ => PropertyChange::Changed { subject, key }, }; h.property_changed(&c); @@ -45,14 +46,8 @@ pub use metadata::*; #[cfg(feature = "metadata")] mod metadata { - use dlib::ffi_dispatch; - #[cfg(not(feature = "dlopen"))] - use jack_sys::*; - - use super::{uuid, PropertyChange, PropertyChangeHandler}; + use super::{j, uuid, PropertyChange, PropertyChangeHandler}; use crate::Error; - #[cfg(feature = "dlopen")] - use crate::LIB; use std::{collections::HashMap, ffi, mem::MaybeUninit, ptr}; use crate::Client; @@ -115,7 +110,7 @@ mod metadata { //helper to convert to an Option and free unsafe fn description_to_map_free( - description: *mut jack_sys::jack_description_t, + description: *mut j::jack_description_t, ) -> Option { if description.is_null() { None @@ -146,7 +141,7 @@ mod metadata { ), ); } - ffi_dispatch!(LIB, jack_free_description, description, 0); + j::jack_free_description(description, 0); Some(properties) } } @@ -191,14 +186,8 @@ mod metadata { let mut typ: MaybeUninit<*mut ::libc::c_char> = MaybeUninit::uninit(); unsafe { - if ffi_dispatch!( - LIB, - jack_get_property, - subject, - key.as_ptr(), - value.as_mut_ptr(), - typ.as_mut_ptr() - ) == 0 + if j::jack_get_property(subject, key.as_ptr(), value.as_mut_ptr(), typ.as_mut_ptr()) + == 0 { let value = value.assume_init(); let typ = typ.assume_init(); @@ -210,9 +199,9 @@ mod metadata { Some(ffi::CStr::from_ptr(typ).to_str().unwrap().to_string()) }, )); - ffi_dispatch!(LIB, jack_free, value as _); + j::jack_free(value as _); if !typ.is_null() { - ffi_dispatch!(LIB, jack_free, typ as _) + j::jack_free(typ as _) } r } else { @@ -231,9 +220,9 @@ mod metadata { /// /// * The Jack API calls this data a 'description'. pub fn property_get_subject(&self, subject: uuid) -> Option { - let mut description: MaybeUninit = MaybeUninit::uninit(); + let mut description: MaybeUninit = MaybeUninit::uninit(); unsafe { - let _ = ffi_dispatch!(LIB, jack_get_properties, subject, description.as_mut_ptr()); + let _ = j::jack_get_properties(subject, description.as_mut_ptr()); description_to_map_free(description.as_mut_ptr()) } } @@ -245,10 +234,9 @@ mod metadata { /// * The Jack API calls these maps 'descriptions'. pub fn property_get_all(&self) -> HashMap { let mut map = HashMap::new(); - let mut descriptions: MaybeUninit<*mut jack_sys::jack_description_t> = - MaybeUninit::uninit(); + let mut descriptions: MaybeUninit<*mut j::jack_description_t> = MaybeUninit::uninit(); unsafe { - let cnt = ffi_dispatch!(LIB, jack_get_all_properties, descriptions.as_mut_ptr()); + let cnt = j::jack_get_all_properties(descriptions.as_mut_ptr()); if cnt > 0 { let descriptions = descriptions.assume_init(); for des in std::slice::from_raw_parts_mut(descriptions, cnt as usize) { @@ -257,7 +245,7 @@ mod metadata { map.insert(uuid, dmap); } } - ffi_dispatch!(LIB, jack_free, descriptions as _); + j::jack_free(descriptions as _); } } map @@ -281,24 +269,20 @@ mod metadata { map_error(|| unsafe { if let Some(t) = property.typ() { let t = ffi::CString::new(t).unwrap(); - ffi_dispatch!( - LIB, - jack_set_property, + j::jack_set_property( self.raw(), subject, key.as_ptr(), value.as_ptr(), - t.as_ptr() + t.as_ptr(), ) } else { - ffi_dispatch!( - LIB, - jack_set_property, + j::jack_set_property( self.raw(), subject, key.as_ptr(), value.as_ptr(), - ptr::null() + ptr::null(), ) } }) @@ -312,9 +296,7 @@ mod metadata { /// * `key` - The key of the property to be removed. A URI string. pub fn property_remove(&self, subject: uuid, key: &str) -> Result<(), Error> { let key = ffi::CString::new(key).expect("to create cstring from key"); - map_error(|| unsafe { - ffi_dispatch!(LIB, jack_remove_property, self.raw(), subject, key.as_ptr()) - }) + map_error(|| unsafe { j::jack_remove_property(self.raw(), subject, key.as_ptr()) }) } /// Remove all properties from a subject. @@ -324,7 +306,7 @@ mod metadata { /// * `subject` - The subject to remove all properties from. pub fn property_remove_subject(&self, subject: uuid) -> Result<(), Error> { unsafe { - if ffi_dispatch!(LIB, jack_remove_properties, self.raw(), subject) == -1 { + if j::jack_remove_properties(self.raw(), subject) == -1 { Err(Error::UnknownError) } else { Ok(()) @@ -338,7 +320,7 @@ mod metadata { /// /// * **WARNING!!** This deletes all Metadata managed by a running JACK server. pub fn property_remove_all(&self) -> Result<(), Error> { - map_error(|| unsafe { ffi_dispatch!(LIB, jack_remove_all_properties, self.raw()) }) + map_error(|| unsafe { j::jack_remove_all_properties(self.raw()) }) } } diff --git a/src/ringbuffer.rs b/src/ringbuffer.rs index 8bfb6b83..3cc490f6 100644 --- a/src/ringbuffer.rs +++ b/src/ringbuffer.rs @@ -1,8 +1,4 @@ -#[cfg(feature = "dlopen")] -use crate::LIB; -use dlib::ffi_dispatch; -#[cfg(not(feature = "dlopen"))] -use jack_sys::*; +use jack_sys as j; use std::mem; use std::sync::atomic::{AtomicBool, Ordering}; @@ -24,14 +20,13 @@ use std::sync::atomic::{AtomicBool, Ordering}; /// let mut outbuf = [0_u8; 8]; /// let num = reader.read_buffer(&mut outbuf); /// ``` -pub struct RingBuffer(*mut jack_sys::jack_ringbuffer_t); +pub struct RingBuffer(*mut j::jack_ringbuffer_t); impl RingBuffer { /// Allocates a ringbuffer of a specified size. pub fn new(size: usize) -> Result { let insize = size as libc::size_t; - let handle = - unsafe { ffi_dispatch!(feature = "dlopen", LIB, jack_ringbuffer_create, insize) }; + let handle = unsafe { j::jack_ringbuffer_create(insize) }; if handle.is_null() { return Err(crate::Error::RingbufferCreateFailed); @@ -42,12 +37,12 @@ impl RingBuffer { /// Lock a ringbuffer data block into memory. pub fn mlock(&mut self) { - unsafe { ffi_dispatch!(feature = "dlopen", LIB, jack_ringbuffer_mlock, self.0) }; + unsafe { j::jack_ringbuffer_mlock(self.0) }; } /// Resets the ring buffer, making an empty buffer. pub fn reset(&mut self) { - unsafe { ffi_dispatch!(feature = "dlopen", LIB, jack_ringbuffer_reset, self.0) }; + unsafe { j::jack_ringbuffer_reset(self.0) }; } /// Create a reader and writer, to use the ring buffer. @@ -66,7 +61,7 @@ impl RingBuffer { pub fn from_reader_writer(r: RingBufferReader, w: RingBufferWriter) -> Self { if r.ringbuffer_handle != w.ringbuffer_handle { // drops will be valid during unwinding - assuming that all reader/writer pairs are - // consistent. + // consisitent. panic!("mismatching read and write handles!") } @@ -83,7 +78,7 @@ impl RingBuffer { impl Drop for RingBuffer { fn drop(&mut self) { if !self.0.is_null() { - unsafe { ffi_dispatch!(feature = "dlopen", LIB, jack_ringbuffer_free, self.0) }; + unsafe { j::jack_ringbuffer_free(self.0) }; } self.0 = std::ptr::null_mut(); } @@ -95,7 +90,7 @@ unsafe impl Sync for RingBuffer {} /// Read end of the ring buffer. Can only be used from one thread (can be different from the write /// thread). pub struct RingBufferReader { - ringbuffer_handle: *mut jack_sys::jack_ringbuffer_t, + ringbuffer_handle: *mut j::jack_ringbuffer_t, /// A marker to check if both halves of the ringbuffer are live. Destroying a ringbuffer is not /// a realtime operation. both_live: AtomicBool, @@ -107,7 +102,7 @@ unsafe impl Sync for RingBufferReader {} /// Write end of the ring buffer. Can only be used from one thread (can be a different from the read /// thread). pub struct RingBufferWriter { - ringbuffer_handle: *mut jack_sys::jack_ringbuffer_t, + ringbuffer_handle: *mut j::jack_ringbuffer_t, both_live: AtomicBool, } @@ -117,7 +112,7 @@ unsafe impl Sync for RingBufferWriter {} impl RingBufferReader { // safety: this method must be called as part of the splitting of the ringbuffer into 2 // channels. - unsafe fn new(raw: *mut jack_sys::jack_ringbuffer_t) -> Self { + unsafe fn new(raw: *mut j::jack_ringbuffer_t) -> Self { RingBufferReader { ringbuffer_handle: raw, both_live: AtomicBool::new(true), @@ -131,20 +126,12 @@ impl RingBufferReader { /// data that ended in the first slices. For convenience, consider using peek_iter instead. pub fn get_vector(&self) -> (&[u8], &[u8]) { let mut vec = [ - jack_sys::jack_ringbuffer_data_t::default(), - jack_sys::jack_ringbuffer_data_t::default(), + j::jack_ringbuffer_data_t::default(), + j::jack_ringbuffer_data_t::default(), ]; - let vecstart = &mut vec[0] as *mut jack_sys::jack_ringbuffer_data_t; - - unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_ringbuffer_get_read_vector, - self.ringbuffer_handle, - vecstart - ) - }; + let vecstart = &mut vec[0] as *mut j::jack_ringbuffer_data_t; + + unsafe { j::jack_ringbuffer_get_read_vector(self.ringbuffer_handle, vecstart) }; let view1 = vec[0]; let view2 = vec[1]; @@ -175,21 +162,12 @@ impl RingBufferReader { let insize: libc::size_t = buf.len() as libc::size_t; let bufstart = &mut buf[0] as *mut _ as *mut libc::c_char; - let read = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_ringbuffer_read, - self.ringbuffer_handle, - bufstart, - insize - ) - }; + let read = unsafe { j::jack_ringbuffer_read(self.ringbuffer_handle, bufstart, insize) }; read as usize } /// Read data from the ringbuffer. Opposed to read_buffer() this function does not move the read - /// pointer. Thus it's a convenient way to inspect data in the ringbuffer in a continuous + /// pointer. Thus it's a convenient way to inspect data in the ringbuffer in a continous /// fashion. The price is that the data is copied into a user provided buffer. For "raw" /// non-copy inspection of the data in the ringbuffer use get_vector() or peek_iter. Returns: /// the number of bytes read, which may range from 0 to buf.len() @@ -201,16 +179,7 @@ impl RingBufferReader { let insize: libc::size_t = buf.len() as libc::size_t; let bufstart = &mut buf[0] as *mut _ as *mut libc::c_char; - let read = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_ringbuffer_peek, - self.ringbuffer_handle, - bufstart, - insize - ) - }; + let read = unsafe { j::jack_ringbuffer_peek(self.ringbuffer_handle, bufstart, insize) }; read as usize } @@ -218,27 +187,12 @@ impl RingBufferReader { /// pointer. pub fn advance(&mut self, cnt: usize) { let incnt = cnt as libc::size_t; - unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_ringbuffer_read_advance, - self.ringbuffer_handle, - incnt - ) - }; + unsafe { j::jack_ringbuffer_read_advance(self.ringbuffer_handle, incnt) }; } /// Return the number of bytes available for reading. pub fn space(&self) -> usize { - unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_ringbuffer_read_space, - self.ringbuffer_handle - ) as usize - } + unsafe { j::jack_ringbuffer_read_space(self.ringbuffer_handle) as usize } } /// Iterator that goes over all the data available to read. @@ -274,7 +228,7 @@ impl Drop for RingBufferReader { impl RingBufferWriter { // safety: this method must be called as part of the splitting of the ringbuffer into 2 // channels. - unsafe fn new(raw: *mut jack_sys::jack_ringbuffer_t) -> Self { + unsafe fn new(raw: *mut j::jack_ringbuffer_t) -> Self { RingBufferWriter { ringbuffer_handle: raw, both_live: AtomicBool::new(true), @@ -291,16 +245,7 @@ impl RingBufferWriter { let insize: libc::size_t = buf.len() as libc::size_t; let bufstart = &buf[0] as *const _ as *const libc::c_char; - let read = unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_ringbuffer_write, - self.ringbuffer_handle, - bufstart, - insize - ) - }; + let read = unsafe { j::jack_ringbuffer_write(self.ringbuffer_handle, bufstart, insize) }; read as usize } @@ -308,27 +253,12 @@ impl RingBufferWriter { /// pointer. pub fn advance(&mut self, cnt: usize) { let incnt = cnt as libc::size_t; - unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_ringbuffer_write_advance, - self.ringbuffer_handle, - incnt - ) - }; + unsafe { j::jack_ringbuffer_write_advance(self.ringbuffer_handle, incnt) }; } /// Return the number of bytes available for writing. pub fn space(&mut self) -> usize { - unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_ringbuffer_write_space, - self.ringbuffer_handle - ) as usize - } + unsafe { j::jack_ringbuffer_write_space(self.ringbuffer_handle) as usize } } /// Return a pair of slices of the current writable space in the ringbuffer. two slices are @@ -336,20 +266,12 @@ impl RingBufferWriter { /// ringbuffer. consider using peek_iter for convenience. pub fn get_vector(&mut self) -> (&mut [u8], &mut [u8]) { let mut vec = [ - jack_sys::jack_ringbuffer_data_t::default(), - jack_sys::jack_ringbuffer_data_t::default(), + j::jack_ringbuffer_data_t::default(), + j::jack_ringbuffer_data_t::default(), ]; - let vecstart = &mut vec[0] as *mut jack_sys::jack_ringbuffer_data_t; - - unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_ringbuffer_get_write_vector, - self.ringbuffer_handle, - vecstart - ) - }; + let vecstart = &mut vec[0] as *mut j::jack_ringbuffer_data_t; + + unsafe { j::jack_ringbuffer_get_write_vector(self.ringbuffer_handle, vecstart) }; let view1 = vec[0]; let view2 = vec[1]; diff --git a/src/transport.rs b/src/transport.rs index 66a72046..f736a636 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -1,24 +1,20 @@ ///! JACK transport wrappers. ///! See the [transport design api docs](https://jackaudio.org/api/transport-design.html) for more info. -#[cfg(feature = "dlopen")] -use crate::LIB; use crate::{Frames, Time}; -use dlib::ffi_dispatch; -#[cfg(not(feature = "dlopen"))] -use jack_sys::*; +use jack_sys as j; use std::sync::Weak; pub type Result = ::std::result::Result; /// A structure for querying and manipulating the JACK transport. pub struct Transport { - pub(crate) client_ptr: *mut jack_sys::jack_client_t, + pub(crate) client_ptr: *mut j::jack_client_t, pub(crate) client_life: Weak<()>, } /// A structure representing the transport position. #[repr(transparent)] -pub struct TransportPosition(jack_sys::jack_position_t); +pub struct TransportPosition(j::jack_position_t); /// A representation of transport state. #[derive(Debug, Clone, Copy, PartialEq)] @@ -90,7 +86,7 @@ impl std::fmt::Display for TransportBBTValidationError { impl std::error::Error for TransportBBTValidationError {} impl Transport { - fn with_client R, R>(&self, func: F) -> Result { + fn with_client R, R>(&self, func: F) -> Result { if self.client_life.upgrade().is_some() { Ok(func(self.client_ptr)) } else { @@ -108,7 +104,7 @@ impl Transport { /// * This function is realtime-safe. pub fn start(&self) -> Result<()> { self.with_client(|ptr| unsafe { - ffi_dispatch!(feature = "dlopen", LIB, jack_transport_start, ptr); + j::jack_transport_start(ptr); }) } @@ -121,7 +117,7 @@ impl Transport { /// * This function is realtime-safe. pub fn stop(&self) -> Result<()> { self.with_client(|ptr| unsafe { - ffi_dispatch!(feature = "dlopen", LIB, jack_transport_stop, ptr); + j::jack_transport_stop(ptr); }) } @@ -140,14 +136,9 @@ impl Transport { pub fn reposition(&self, pos: &TransportPosition) -> Result<()> { Self::result_from_ffi( self.with_client(|ptr| unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_transport_reposition, + j::jack_transport_reposition( ptr, - std::mem::transmute::<&TransportPosition, *const jack_sys::jack_position_t>( - pos, - ) + std::mem::transmute::<&TransportPosition, *const j::jack_position_t>(pos), ) }), (), @@ -168,18 +159,16 @@ impl Transport { /// * This function is realtime-safe. pub fn locate(&self, frame: Frames) -> Result<()> { Self::result_from_ffi( - self.with_client(|ptr| unsafe { - ffi_dispatch!(feature = "dlopen", LIB, jack_transport_locate, ptr, frame) - }), + self.with_client(|ptr| unsafe { j::jack_transport_locate(ptr, frame) }), (), ) } //helper to convert to TransportState - fn state_from_ffi(state: jack_sys::jack_transport_state_t) -> TransportState { + fn state_from_ffi(state: j::jack_transport_state_t) -> TransportState { match state { - jack_sys::JackTransportStopped => TransportState::Stopped, - jack_sys::JackTransportStarting => TransportState::Starting, + j::JackTransportStopped => TransportState::Stopped, + j::JackTransportStarting => TransportState::Starting, //the JackTransportLooping state is no longer used _ => TransportState::Rolling, } @@ -204,12 +193,9 @@ impl Transport { self.with_client(|ptr| { let mut pos: std::mem::MaybeUninit = std::mem::MaybeUninit::zeroed(); let state = Self::state_from_ffi(unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_transport_query, + j::jack_transport_query( ptr, - pos.as_mut_ptr() as *mut jack_sys::Struct__jack_position + pos.as_mut_ptr() as *mut jack_sys::Struct__jack_position, ) }); TransportStatePosition { @@ -227,15 +213,7 @@ impl Transport { /// * If called from the process thread, the state returned is valid for the entire cycle. pub fn query_state(&self) -> Result { self.with_client(|ptr| { - Self::state_from_ffi(unsafe { - ffi_dispatch!( - feature = "dlopen", - LIB, - jack_transport_query, - ptr, - std::ptr::null_mut() - ) - }) + Self::state_from_ffi(unsafe { j::jack_transport_query(ptr, std::ptr::null_mut()) }) }) } } @@ -247,28 +225,28 @@ unsafe impl Sync for Transport {} impl TransportPosition { /// Query to see if the BarBeatsTick data is valid. pub fn valid_bbt(&self) -> bool { - (self.0.valid & jack_sys::JackPositionBBT) != 0 + (self.0.valid & j::JackPositionBBT) != 0 } /// Query to see if the frame offset of BarBeatsTick data is valid. pub fn valid_bbt_frame_offset(&self) -> bool { - (self.0.valid & jack_sys::JackBBTFrameOffset) != 0 + (self.0.valid & j::JackBBTFrameOffset) != 0 } /* /// Query to see if the Timecode data is valid. pub fn valid_timecode(&self) -> bool { - (self.0.valid & jack_sys::JackPositionTimecode) != 0 + (self.0.valid & j::JackPositionTimecode) != 0 } /// Query to see if the Audio/Video ratio is valid. pub fn valid_avr(&self) -> bool { - (self.0.valid & jack_sys::JackAudioVideoRatio) != 0 + (self.0.valid & j::JackAudioVideoRatio) != 0 } /// Query to see if the Video frame offset is valid. pub fn valid_video_frame_offset(&self) -> bool { - (self.0.valid & jack_sys::JackVideoFrameOffset) != 0 + (self.0.valid & j::JackVideoFrameOffset) != 0 } */ @@ -307,7 +285,7 @@ impl TransportPosition { /// * The absolute value is implementation-dependent (i.e. it could be wall-clock, time since /// jack started, uptime, etc). pub fn usecs(&self) -> Option