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>
impl<T> JackConnection<T>
pub fn as_ptr(&self) -> *const jack_client_t
Sourcepub fn sample_rate(&self) -> jack_nframes_t
pub fn sample_rate(&self) -> jack_nframes_t
Get the sample rate of the JACK server.
Sourcepub fn buffer_size(&self) -> jack_nframes_t
pub fn buffer_size(&self) -> jack_nframes_t
Get the buffer size passed to the process() callback.
Sourcepub fn set_buffer_size(&mut self, bufsize: jack_nframes_t) -> JackResult<()>
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 twoUnknownErrorCode
Sourcepub fn connect_ports(
&mut self,
from: &JackPort,
to: &JackPort,
) -> JackResult<()>
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 identicalInvalidPortFlags: when the flags do not satisfy the preconditions aboveUnknownErrorCode
Examples found in repository?
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
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}Sourcepub fn disconnect_ports(
&mut self,
from: &JackPort,
to: &JackPort,
) -> JackResult<()>
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 identicalInvalidPortFlags: when the flags do not satisfy the preconditions aboveUnknownErrorCode
Sourcepub fn get_port_by_name(&self, name: &str) -> JackResult<JackPort>
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 foundNulError: if any&strargument contains a NUL byte (\0).
Sourcepub fn get_ports(
&self,
port_filter: Option<&str>,
type_filter: Option<&str>,
flags_filter: Option<JackPortFlags>,
) -> JackResult<Vec<JackPort>>
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&strargument contains a NUL byte (\0).ProgrammerError: if I’ve made a mistake, or your program is utterly degenerate
Examples found in repository?
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
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}Sourcepub fn register_port(
&mut self,
name: &str,
ty: JackPortFlags,
) -> JackResult<JackPort>
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&strargument contains a NUL byte (\0).PortRegistrationFailed: if port registration failed (TODO: why could this happen?)
Examples found in repository?
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
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}Sourcepub fn unregister_port(&mut self, port: JackPort) -> JackResult<()>
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 ownInvalidPortUnknownErrorCode
Source§impl JackConnection<Deactivated>
impl JackConnection<Deactivated>
Sourcepub fn connect(
client_name: &str,
opts: Option<JackOpenOptions>,
) -> JackResult<Self>
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 aJackStatusdetailing what went wrong.NulError: if any&strargument contains a NUL byte (\0).
Examples found in repository?
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
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}Sourcepub fn set_handler<F>(&mut self, handler: F) -> JackResult<()>where
F: JackHandler,
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?
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
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}Sourcepub fn activate(self) -> Result<JackConnection<Activated>, (Self, JackError)>
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?
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
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}