Skip to content

Commit 6ecfec4

Browse files
authored
Bump Jack to v0.12 (#910)
* Bump to version 0.12. * Fix some cargo clippy lints. * Partially revert temp_buffer_to_data to be closer to original. * Suppress too many arguments lint.
1 parent cc8ba75 commit 6ecfec4

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ num-traits = { version = "0.2.6", optional = true }
4545
[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd"))'.dependencies]
4646
alsa = "0.9"
4747
libc = "0.2"
48-
jack = { version = "0.11", optional = true }
48+
jack = { version = "0.12", optional = true }
4949

5050
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
5151
core-foundation-sys = "0.8.2" # For linking to CoreFoundation.framework and handling device name `CFString`s.

src/host/jack/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,8 @@ fn get_client(name: &str, client_options: jack::ClientOptions) -> Result<jack::C
170170
} else if status.intersects(jack::ClientStatus::INVALID_OPTION) {
171171
return Err(String::from("Error connecting to JACK server: The operation contained an invalid or unsupported option!"));
172172
}
173-
174-
return Ok(client);
175-
}
176-
Err(e) => {
177-
return Err(format!("Failed to open client because of error: {:?}", e));
173+
Ok(client)
178174
}
175+
Err(e) => Err(format!("Failed to open client because of error: {:?}", e)),
179176
}
180177
}

src/host/jack/stream.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Stream {
3737
let mut port_names: Vec<String> = vec![];
3838
// Create ports
3939
for i in 0..channels {
40-
let port_try = client.register_port(&format!("in_{}", i), jack::AudioIn::default());
40+
let port_try = client.register_port(&format!("in_{}", i), jack::AudioIn);
4141
match port_try {
4242
Ok(port) => {
4343
// Get the port name in order to later connect it automatically
@@ -102,7 +102,7 @@ impl Stream {
102102
let mut port_names: Vec<String> = vec![];
103103
// Create ports
104104
for i in 0..channels {
105-
let port_try = client.register_port(&format!("out_{}", i), jack::AudioOut::default());
105+
let port_try = client.register_port(&format!("out_{}", i), jack::AudioOut);
106106
match port_try {
107107
Ok(port) => {
108108
// Get the port name in order to later connect it automatically
@@ -218,15 +218,18 @@ impl StreamTrait for Stream {
218218
}
219219
}
220220

221+
type InputDataCallback = Box<dyn FnMut(&Data, &InputCallbackInfo) + Send + 'static>;
222+
type OutputDataCallback = Box<dyn FnMut(&mut Data, &OutputCallbackInfo) + Send + 'static>;
223+
221224
struct LocalProcessHandler {
222225
/// No new ports are allowed to be created after the creation of the LocalProcessHandler as that would invalidate the buffer sizes
223226
out_ports: Vec<jack::Port<jack::AudioOut>>,
224227
in_ports: Vec<jack::Port<jack::AudioIn>>,
225228

226229
sample_rate: SampleRate,
227230
buffer_size: usize,
228-
input_data_callback: Option<Box<dyn FnMut(&Data, &InputCallbackInfo) + Send + 'static>>,
229-
output_data_callback: Option<Box<dyn FnMut(&mut Data, &OutputCallbackInfo) + Send + 'static>>,
231+
input_data_callback: Option<InputDataCallback>,
232+
output_data_callback: Option<OutputDataCallback>,
230233

231234
// JACK audio samples are 32-bit float (unless you do some custom dark magic)
232235
temp_input_buffer: Vec<f32>,
@@ -238,15 +241,14 @@ struct LocalProcessHandler {
238241
}
239242

240243
impl LocalProcessHandler {
244+
#[allow(too_many_arguments)]
241245
fn new(
242246
out_ports: Vec<jack::Port<jack::AudioOut>>,
243247
in_ports: Vec<jack::Port<jack::AudioIn>>,
244248
sample_rate: SampleRate,
245249
buffer_size: usize,
246-
input_data_callback: Option<Box<dyn FnMut(&Data, &InputCallbackInfo) + Send + 'static>>,
247-
output_data_callback: Option<
248-
Box<dyn FnMut(&mut Data, &OutputCallbackInfo) + Send + 'static>,
249-
>,
250+
input_data_callback: Option<InputDataCallback>,
251+
output_data_callback: Option<OutputDataCallback>,
250252
playing: Arc<AtomicBool>,
251253
error_callback_ptr: ErrorCallbackPtr,
252254
) -> Self {
@@ -270,12 +272,11 @@ impl LocalProcessHandler {
270272
}
271273
}
272274

273-
fn temp_buffer_to_data(temp_input_buffer: &mut Vec<f32>, total_buffer_size: usize) -> Data {
274-
let slice = &temp_input_buffer[0..total_buffer_size];
275-
let data = slice.as_ptr() as *mut ();
275+
fn temp_buffer_to_data(temp_input_buffer: &mut [f32], total_buffer_size: usize) -> Data {
276+
let slice = &mut temp_input_buffer[0..total_buffer_size];
277+
let data: *mut () = slice.as_mut_ptr().cast();
276278
let len = total_buffer_size;
277-
let data = unsafe { Data::from_parts(data, len, JACK_SAMPLE_FORMAT) };
278-
data
279+
unsafe { Data::from_parts(data, len, JACK_SAMPLE_FORMAT) }
279280
}
280281

281282
impl jack::ProcessHandler for LocalProcessHandler {

0 commit comments

Comments
 (0)