Skip to content

Commit

Permalink
Merge branch 'latency_handling'
Browse files Browse the repository at this point in the history
  • Loading branch information
Windfisch committed Jun 28, 2020
2 parents 9fa757d + bb6e9db commit a343b47
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/jack_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ pub enum LatencyType {
Playback,
}

impl LatencyType {
pub fn to_ffi(self) -> libc::c_uint {
match self {
LatencyType::Playback => jack_sys::JackPlaybackLatency,
LatencyType::Capture => jack_sys::JackCaptureLatency,
}
}
}

/// Specify an option, either to continue processing, or to stop.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Control {
Expand Down
29 changes: 28 additions & 1 deletion src/port/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::marker::Sized;
use std::sync::Weak;
use std::{ffi, fmt, iter};

use crate::{Error, Frames, PortFlags};
use crate::{Error, Frames, LatencyType, PortFlags};

lazy_static! {
/// The maximum string length for port names.
Expand Down Expand Up @@ -273,6 +273,33 @@ impl<PS> Port<PS> {
j::jack_port_get_buffer(self.port_ptr, n_frames)
}

/// Set the minimum and maximum latencies defined by mode for port, in frames.
/// The `range` argument is a tuple of `(min, max)`.
///
/// See [Managing and determining latency](https://jackaudio.org/api/group__LatencyFunctions.html)
/// for a description of what the latency values mean and some best practices. This function should
/// **only** be used inside a latency callback.
#[inline(always)]
pub fn set_latency_range(&self, mode: LatencyType, range: (Frames, Frames)) {
let mut ffi_range = j::Struct__jack_latency_range {
min: range.0,
max: range.1,
};
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.
///
/// See [Managing and determining latency](https://jackaudio.org/api/group__LatencyFunctions.html)
/// for a description of what the latency values mean and some best practices. This is normally
/// 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 = j::Struct__jack_latency_range { min: 0, max: 0 };
unsafe { j::jack_port_set_latency_range(self.port_ptr, mode.to_ffi(), &mut ffi_range) };
return (ffi_range.min, ffi_range.max);
}

fn check_client_life(&self) -> Result<(), Error> {
self.client_life
.upgrade()
Expand Down

0 comments on commit a343b47

Please sign in to comment.