JackConnection

Struct JackConnection 

Source
pub struct JackConnection<T> { /* private fields */ }
Expand description

A connection to a JACK server (known as a “client” in the JACK docs).

Exists in two types: JackConnection<Activated> when activate() has been called (i.e. audio is being processed), and <Deactivated> when this has not happened, or deactivate() has been called.

Implementations§

Source§

impl<T> JackConnection<T>

Source

pub fn as_ptr(&self) -> *const jack_client_t

Source

pub fn sample_rate(&self) -> jack_nframes_t

Get the sample rate of the JACK server.

Source

pub fn cpu_load(&self) -> c_float

Get the CPU load of the JACK server.

Source

pub fn buffer_size(&self) -> jack_nframes_t

Get the buffer size passed to the process() callback.

Source

pub fn set_buffer_size(&mut self, bufsize: jack_nframes_t) -> JackResult<()>

Change the buffer size passed to the process() callback.

This operation stops the JACK engine process cycle, then calls all registered bufsize_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.

§Parameters
  • bufsize: new buffer size. Must be a power of two.
§Errors
  • NotPowerOfTwo: if the new buffer size isn’t a power of two
  • UnknownErrorCode
Source

pub fn connect_ports( &mut self, from: &JackPort, to: &JackPort, ) -> JackResult<()>

Establish a connection between two ports.

When a connection exists, data written to the source port will be available to be read at the destination port.

§Preconditions
  • The port types must be identical.
  • The JackPortFlags of the source_port must include PORT_IS_OUTPUT.
  • The JackPortFlags of the destination_port must include PORT_IS_INPUT.
§Errors
  • InvalidPortType: when the types are not identical
  • InvalidPortFlags: when the flags do not satisfy the preconditions above
  • UnknownErrorCode
Examples found in repository?
examples/sawtooth.rs (line 43)
26fn run() -> JackResult<()> {
27    let mut conn = JackConnection::connect("Very Annoying Sawtooth Generator", None)?;
28    let out1 = conn.register_port("output_1", PORT_IS_OUTPUT)?;
29    let out2 = conn.register_port("output_2", PORT_IS_OUTPUT)?;
30    let data = Sawtooth {
31        out1: out1,
32        out2: out2,
33        left_saw: 0.0,
34        right_saw: 0.0
35    };
36    conn.set_handler(data)?;
37    let mut conn = match conn.activate() {
38        Ok(nc) => nc,
39        Err((_, err)) => return Err(err)
40    };
41    let ports = conn.get_ports(None, None, Some(PORT_IS_INPUT | PORT_IS_PHYSICAL))?;
42    if ports.len() >= 2 {
43        conn.connect_ports(&out1, &ports[0])?;
44        conn.connect_ports(&out2, &ports[1])?;
45    }
46    thread::sleep(::std::time::Duration::new(5, 0));
47    Ok(())
48}
More examples
Hide additional examples
examples/simple_client.rs (line 34)
19fn run() -> JackResult<()> {
20    let mut conn = JackConnection::connect("simple_client", None)?;
21    let inp = conn.register_port("input", PORT_IS_INPUT)?;
22    let out = conn.register_port("output", PORT_IS_OUTPUT)?;
23    let ports = Ports {
24        inp: inp,
25        out: out
26    };
27    conn.set_handler(ports)?;
28    let mut conn = match conn.activate() {
29        Ok(nc) => nc,
30        Err((_, err)) => return Err(err)
31    };
32    let ports = conn.get_ports(None, None, Some(PORT_IS_INPUT | PORT_IS_PHYSICAL))?;
33    if ports.len() >= 1 {
34        conn.connect_ports(&out, &ports[0])?;
35        println!("Connected output port to {}", ports[0].get_name(false)?);
36    }
37    let ports = conn.get_ports(None, None, Some(PORT_IS_OUTPUT | PORT_IS_PHYSICAL))?;
38    if ports.len() >= 1 {
39        conn.connect_ports(&ports[0], &inp)?;
40        println!("Connected input port to {}", ports[0].get_name(false)?);
41    }
42    thread::sleep(::std::time::Duration::new(60 * 60, 0));
43    Ok(())
44}
Source

pub fn disconnect_ports( &mut self, from: &JackPort, to: &JackPort, ) -> JackResult<()>

Remove a connection between two ports.

When a connection exists, data written to the source port will be available to be read at the destination port.

§Preconditions
  • The port types must be identical.
  • The JackPortFlags of the source_port must include PORT_IS_OUTPUT.
  • The JackPortFlags of the destination_port must include PORT_IS_INPUT.
§Errors
  • InvalidPortType: when the types are not identical
  • InvalidPortFlags: when the flags do not satisfy the preconditions above
  • UnknownErrorCode
Source

pub fn get_port_by_name(&self, name: &str) -> JackResult<JackPort>

Get a port from the JACK server by its name.

§Errors
  • PortNotFound: if no port with that name was found
  • NulError: if any &str argument contains a NUL byte (\0).
Source

pub fn get_ports( &self, port_filter: Option<&str>, type_filter: Option<&str>, flags_filter: Option<JackPortFlags>, ) -> JackResult<Vec<JackPort>>

Get all (or a selection of) ports available in the JACK server.

§Parameters
  • port_filter: A regular expression used to select ports by name. If None, no selection based on name will be carried out.
  • type_filter: A regular expression used to select ports by type. If None, no selection based on type will be carried out.
  • flags_filter: A value used to select ports by their flags. If None, no selection based on flags will be carried out.
§Errors
  • NulError: if any &str argument contains a NUL byte (\0).
  • ProgrammerError: if I’ve made a mistake, or your program is utterly degenerate
Examples found in repository?
examples/sawtooth.rs (line 41)
26fn run() -> JackResult<()> {
27    let mut conn = JackConnection::connect("Very Annoying Sawtooth Generator", None)?;
28    let out1 = conn.register_port("output_1", PORT_IS_OUTPUT)?;
29    let out2 = conn.register_port("output_2", PORT_IS_OUTPUT)?;
30    let data = Sawtooth {
31        out1: out1,
32        out2: out2,
33        left_saw: 0.0,
34        right_saw: 0.0
35    };
36    conn.set_handler(data)?;
37    let mut conn = match conn.activate() {
38        Ok(nc) => nc,
39        Err((_, err)) => return Err(err)
40    };
41    let ports = conn.get_ports(None, None, Some(PORT_IS_INPUT | PORT_IS_PHYSICAL))?;
42    if ports.len() >= 2 {
43        conn.connect_ports(&out1, &ports[0])?;
44        conn.connect_ports(&out2, &ports[1])?;
45    }
46    thread::sleep(::std::time::Duration::new(5, 0));
47    Ok(())
48}
More examples
Hide additional examples
examples/simple_client.rs (line 32)
19fn run() -> JackResult<()> {
20    let mut conn = JackConnection::connect("simple_client", None)?;
21    let inp = conn.register_port("input", PORT_IS_INPUT)?;
22    let out = conn.register_port("output", PORT_IS_OUTPUT)?;
23    let ports = Ports {
24        inp: inp,
25        out: out
26    };
27    conn.set_handler(ports)?;
28    let mut conn = match conn.activate() {
29        Ok(nc) => nc,
30        Err((_, err)) => return Err(err)
31    };
32    let ports = conn.get_ports(None, None, Some(PORT_IS_INPUT | PORT_IS_PHYSICAL))?;
33    if ports.len() >= 1 {
34        conn.connect_ports(&out, &ports[0])?;
35        println!("Connected output port to {}", ports[0].get_name(false)?);
36    }
37    let ports = conn.get_ports(None, None, Some(PORT_IS_OUTPUT | PORT_IS_PHYSICAL))?;
38    if ports.len() >= 1 {
39        conn.connect_ports(&ports[0], &inp)?;
40        println!("Connected input port to {}", ports[0].get_name(false)?);
41    }
42    thread::sleep(::std::time::Duration::new(60 * 60, 0));
43    Ok(())
44}
Source

pub fn register_port( &mut self, name: &str, ty: JackPortFlags, ) -> JackResult<JackPort>

Create a new port for the client.

This is an object used for moving data of any type in or out of the client. Ports may be connected in various ways.

Each port has a short name. The port’s full name contains the name of the client concatenated with a colon (:) followed by its short name. The jack_port_name_size() is the maximum length of this full name. Exceeding that will cause the port registration to fail and return ProgrammerError.

The port_name must be unique among all ports owned by this client. If the name is not unique, the registration will fail.

All ports have a type, which may be any non-NULL and non-zero length string, passed as an argument. Some port types are built into the JACK API, like JACK_DEFAULT_AUDIO_TYPE or JACK_DEFAULT_MIDI_TYPE. [By default, sqa-jack makes a JACK_DEFAULT_AUDIO_TYPE port - this will be changeable in later releases.]

§Errors
  • NulError: if any &str argument contains a NUL byte (\0).
  • PortRegistrationFailed: if port registration failed (TODO: why could this happen?)
Examples found in repository?
examples/sawtooth.rs (line 28)
26fn run() -> JackResult<()> {
27    let mut conn = JackConnection::connect("Very Annoying Sawtooth Generator", None)?;
28    let out1 = conn.register_port("output_1", PORT_IS_OUTPUT)?;
29    let out2 = conn.register_port("output_2", PORT_IS_OUTPUT)?;
30    let data = Sawtooth {
31        out1: out1,
32        out2: out2,
33        left_saw: 0.0,
34        right_saw: 0.0
35    };
36    conn.set_handler(data)?;
37    let mut conn = match conn.activate() {
38        Ok(nc) => nc,
39        Err((_, err)) => return Err(err)
40    };
41    let ports = conn.get_ports(None, None, Some(PORT_IS_INPUT | PORT_IS_PHYSICAL))?;
42    if ports.len() >= 2 {
43        conn.connect_ports(&out1, &ports[0])?;
44        conn.connect_ports(&out2, &ports[1])?;
45    }
46    thread::sleep(::std::time::Duration::new(5, 0));
47    Ok(())
48}
More examples
Hide additional examples
examples/simple_client.rs (line 21)
19fn run() -> JackResult<()> {
20    let mut conn = JackConnection::connect("simple_client", None)?;
21    let inp = conn.register_port("input", PORT_IS_INPUT)?;
22    let out = conn.register_port("output", PORT_IS_OUTPUT)?;
23    let ports = Ports {
24        inp: inp,
25        out: out
26    };
27    conn.set_handler(ports)?;
28    let mut conn = match conn.activate() {
29        Ok(nc) => nc,
30        Err((_, err)) => return Err(err)
31    };
32    let ports = conn.get_ports(None, None, Some(PORT_IS_INPUT | PORT_IS_PHYSICAL))?;
33    if ports.len() >= 1 {
34        conn.connect_ports(&out, &ports[0])?;
35        println!("Connected output port to {}", ports[0].get_name(false)?);
36    }
37    let ports = conn.get_ports(None, None, Some(PORT_IS_OUTPUT | PORT_IS_PHYSICAL))?;
38    if ports.len() >= 1 {
39        conn.connect_ports(&ports[0], &inp)?;
40        println!("Connected input port to {}", ports[0].get_name(false)?);
41    }
42    thread::sleep(::std::time::Duration::new(60 * 60, 0));
43    Ok(())
44}
Source

pub fn unregister_port(&mut self, port: JackPort) -> JackResult<()>

Remove the port from the client, disconnecting any existing connections.

§Errors
  • PortNotMine: if you deregister a port that this client doesn’t own
  • InvalidPort
  • UnknownErrorCode
Source§

impl JackConnection<Deactivated>

Source

pub fn connect( client_name: &str, opts: Option<JackOpenOptions>, ) -> JackResult<Self>

Open an external client session with a JACK server, optionally specifying a number of JackOpenOptions.

§Errors
  • JackOpenFailed(status): if the connection could not be opened. Contains a JackStatus detailing what went wrong.
  • NulError: if any &str argument contains a NUL byte (\0).
Examples found in repository?
examples/sawtooth.rs (line 27)
26fn run() -> JackResult<()> {
27    let mut conn = JackConnection::connect("Very Annoying Sawtooth Generator", None)?;
28    let out1 = conn.register_port("output_1", PORT_IS_OUTPUT)?;
29    let out2 = conn.register_port("output_2", PORT_IS_OUTPUT)?;
30    let data = Sawtooth {
31        out1: out1,
32        out2: out2,
33        left_saw: 0.0,
34        right_saw: 0.0
35    };
36    conn.set_handler(data)?;
37    let mut conn = match conn.activate() {
38        Ok(nc) => nc,
39        Err((_, err)) => return Err(err)
40    };
41    let ports = conn.get_ports(None, None, Some(PORT_IS_INPUT | PORT_IS_PHYSICAL))?;
42    if ports.len() >= 2 {
43        conn.connect_ports(&out1, &ports[0])?;
44        conn.connect_ports(&out2, &ports[1])?;
45    }
46    thread::sleep(::std::time::Duration::new(5, 0));
47    Ok(())
48}
More examples
Hide additional examples
examples/simple_client.rs (line 20)
19fn run() -> JackResult<()> {
20    let mut conn = JackConnection::connect("simple_client", None)?;
21    let inp = conn.register_port("input", PORT_IS_INPUT)?;
22    let out = conn.register_port("output", PORT_IS_OUTPUT)?;
23    let ports = Ports {
24        inp: inp,
25        out: out
26    };
27    conn.set_handler(ports)?;
28    let mut conn = match conn.activate() {
29        Ok(nc) => nc,
30        Err((_, err)) => return Err(err)
31    };
32    let ports = conn.get_ports(None, None, Some(PORT_IS_INPUT | PORT_IS_PHYSICAL))?;
33    if ports.len() >= 1 {
34        conn.connect_ports(&out, &ports[0])?;
35        println!("Connected output port to {}", ports[0].get_name(false)?);
36    }
37    let ports = conn.get_ports(None, None, Some(PORT_IS_OUTPUT | PORT_IS_PHYSICAL))?;
38    if ports.len() >= 1 {
39        conn.connect_ports(&ports[0], &inp)?;
40        println!("Connected input port to {}", ports[0].get_name(false)?);
41    }
42    thread::sleep(::std::time::Duration::new(60 * 60, 0));
43    Ok(())
44}
Source

pub fn set_handler<F>(&mut self, handler: F) -> JackResult<()>
where F: JackHandler,

Register a handler (a struct that implements JackHandler).

§Safety

Warning: Your handler will never be deallocated / Dropped.

§Errors
  • UnknownErrorCode
Examples found in repository?
examples/sawtooth.rs (line 36)
26fn run() -> JackResult<()> {
27    let mut conn = JackConnection::connect("Very Annoying Sawtooth Generator", None)?;
28    let out1 = conn.register_port("output_1", PORT_IS_OUTPUT)?;
29    let out2 = conn.register_port("output_2", PORT_IS_OUTPUT)?;
30    let data = Sawtooth {
31        out1: out1,
32        out2: out2,
33        left_saw: 0.0,
34        right_saw: 0.0
35    };
36    conn.set_handler(data)?;
37    let mut conn = match conn.activate() {
38        Ok(nc) => nc,
39        Err((_, err)) => return Err(err)
40    };
41    let ports = conn.get_ports(None, None, Some(PORT_IS_INPUT | PORT_IS_PHYSICAL))?;
42    if ports.len() >= 2 {
43        conn.connect_ports(&out1, &ports[0])?;
44        conn.connect_ports(&out2, &ports[1])?;
45    }
46    thread::sleep(::std::time::Duration::new(5, 0));
47    Ok(())
48}
More examples
Hide additional examples
examples/simple_client.rs (line 27)
19fn run() -> JackResult<()> {
20    let mut conn = JackConnection::connect("simple_client", None)?;
21    let inp = conn.register_port("input", PORT_IS_INPUT)?;
22    let out = conn.register_port("output", PORT_IS_OUTPUT)?;
23    let ports = Ports {
24        inp: inp,
25        out: out
26    };
27    conn.set_handler(ports)?;
28    let mut conn = match conn.activate() {
29        Ok(nc) => nc,
30        Err((_, err)) => return Err(err)
31    };
32    let ports = conn.get_ports(None, None, Some(PORT_IS_INPUT | PORT_IS_PHYSICAL))?;
33    if ports.len() >= 1 {
34        conn.connect_ports(&out, &ports[0])?;
35        println!("Connected output port to {}", ports[0].get_name(false)?);
36    }
37    let ports = conn.get_ports(None, None, Some(PORT_IS_OUTPUT | PORT_IS_PHYSICAL))?;
38    if ports.len() >= 1 {
39        conn.connect_ports(&ports[0], &inp)?;
40        println!("Connected input port to {}", ports[0].get_name(false)?);
41    }
42    thread::sleep(::std::time::Duration::new(60 * 60, 0));
43    Ok(())
44}
Source

pub fn activate(self) -> Result<JackConnection<Activated>, (Self, JackError)>

Tell the Jack server that the program is ready to start processing audio.

§Returns

Returns the Activated connection type on success, or the current structure and an error on failure.

§Errors
  • UnknownErrorCode
Examples found in repository?
examples/sawtooth.rs (line 37)
26fn run() -> JackResult<()> {
27    let mut conn = JackConnection::connect("Very Annoying Sawtooth Generator", None)?;
28    let out1 = conn.register_port("output_1", PORT_IS_OUTPUT)?;
29    let out2 = conn.register_port("output_2", PORT_IS_OUTPUT)?;
30    let data = Sawtooth {
31        out1: out1,
32        out2: out2,
33        left_saw: 0.0,
34        right_saw: 0.0
35    };
36    conn.set_handler(data)?;
37    let mut conn = match conn.activate() {
38        Ok(nc) => nc,
39        Err((_, err)) => return Err(err)
40    };
41    let ports = conn.get_ports(None, None, Some(PORT_IS_INPUT | PORT_IS_PHYSICAL))?;
42    if ports.len() >= 2 {
43        conn.connect_ports(&out1, &ports[0])?;
44        conn.connect_ports(&out2, &ports[1])?;
45    }
46    thread::sleep(::std::time::Duration::new(5, 0));
47    Ok(())
48}
More examples
Hide additional examples
examples/simple_client.rs (line 28)
19fn run() -> JackResult<()> {
20    let mut conn = JackConnection::connect("simple_client", None)?;
21    let inp = conn.register_port("input", PORT_IS_INPUT)?;
22    let out = conn.register_port("output", PORT_IS_OUTPUT)?;
23    let ports = Ports {
24        inp: inp,
25        out: out
26    };
27    conn.set_handler(ports)?;
28    let mut conn = match conn.activate() {
29        Ok(nc) => nc,
30        Err((_, err)) => return Err(err)
31    };
32    let ports = conn.get_ports(None, None, Some(PORT_IS_INPUT | PORT_IS_PHYSICAL))?;
33    if ports.len() >= 1 {
34        conn.connect_ports(&out, &ports[0])?;
35        println!("Connected output port to {}", ports[0].get_name(false)?);
36    }
37    let ports = conn.get_ports(None, None, Some(PORT_IS_OUTPUT | PORT_IS_PHYSICAL))?;
38    if ports.len() >= 1 {
39        conn.connect_ports(&ports[0], &inp)?;
40        println!("Connected input port to {}", ports[0].get_name(false)?);
41    }
42    thread::sleep(::std::time::Duration::new(60 * 60, 0));
43    Ok(())
44}
Source§

impl JackConnection<Activated>

Source

pub fn deactivate( self, ) -> Result<JackConnection<Deactivated>, (Self, JackError)>

Tell the Jack server to remove this client from the process graph. Also, disconnect all ports belonging to it, since inactive clients have no port connections.

§Returns

Returns the Dectivated connection type on success, or the current structure and an error on failure.

§Errors
  • UnknownErrorCode

Trait Implementations§

Source§

impl<T> Drop for JackConnection<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for JackConnection<T>

§

impl<T> RefUnwindSafe for JackConnection<T>
where T: RefUnwindSafe,

§

impl<T> !Send for JackConnection<T>

§

impl<T> !Sync for JackConnection<T>

§

impl<T> Unpin for JackConnection<T>
where T: Unpin,

§

impl<T> UnwindSafe for JackConnection<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.