Struct Client

Source
pub struct Client<'a> { /* private fields */ }
Expand description

A jack client connected to a jack server

TODO example

Implementations§

Source§

impl<'a> Client<'a>

Source

pub fn open(name: &str, opts: Options) -> Result<(Self, String), Status>

Creates a new client and connects it to the default jack server. The client will use the name given. If the name is not unique, the behavior depends on the options provided via opts.

If the option to force a unique name is given (USE_EXACT_NAME) and the exact name can not be given, Err will be returned. Otherwise Returns the client and the name assigned to the client.

TODO client_name_size details in docs and in code

Examples found in repository?
examples/simple_client.rs (line 113)
112    fn new() -> Result<Self, jack::status::Status> {
113        let client = jack::Client::open("simple", jack::options::NO_START_SERVER);
114        let mut client = match client {
115            Ok((client, _)) => client,
116            Err(code)       => return Err(code),
117        };
118
119        // get some ports
120        let right = client.register_output_audio_port("output1").unwrap();
121        let left  = client.register_output_audio_port("output2").unwrap();
122
123        // create a channel pair we can use to communicate with
124        let (tx, rx) = mpsc::sync_channel(1);
125
126        // create a client, set it up as an audio processing handler
127        let handler = AudioHandler::new(SimpleClient::compute_sine(0.2), right, left, rx);
128        client.set_process_handler(handler).unwrap();
129
130        Ok(SimpleClient {
131            client: client,
132            sender: tx,
133        })
134    }
More examples
Hide additional examples
examples/connect.rs (line 40)
35    fn new(servername: Option<String>) -> Result<Self, jack::status::Status> {
36        // we don't want to start a server if none is already started
37        let opts   = jack::options::NO_START_SERVER;
38        let myname = "connector";
39        let client = match servername {
40            None             => jack::Client::open(myname, opts),
41            Some(servername) => jack::Client::open_connection_to(myname, &*servername, opts),
42        };
43
44        let client = match client {
45            Ok((cl, _)) => cl,
46            Err(code)   => return Err(code)
47        };
48
49        // create our channel to communicate with the handler
50        let (tx, rx) = mpsc::channel();
51
52        // create the handler and give it the transmission end of the channel
53        let handler = ConnectorHandler { outgoing: tx };
54
55        // create an instance of the Connector, then set up the handler
56        let mut conn = Connector { client: client, incoming: rx };
57        conn.client.set_metadata_handler(handler).unwrap();
58
59        Ok(conn)
60    }
examples/midi_sine.rs (line 163)
150fn main() {
151    // register a signal handler (see comments at top of file)
152    let action = signal::SigAction::new(
153        signal::SigHandler::Handler(handle_sigint),
154        signal::SaFlags::empty(),
155        signal::SigSet::empty());
156
157    unsafe { signal::sigaction(signal::Signal::SIGINT, &action) }.unwrap();
158
159    // set our global atomic to true
160    RUNNING.store(true, atomic::Ordering::SeqCst);
161
162
163    let mut c = jack::Client::open("midi_sine", jack::options::NO_START_SERVER).unwrap().0;
164    let i = c.register_input_midi_port("midi_in").unwrap();
165    let o = c.register_output_audio_port("audio_out").unwrap();
166
167    let (tx, rx) = mpsc::sync_channel(1);
168
169    let handler = AudioHandler::new(i, o, rx);
170    c.set_process_handler(handler).unwrap();
171
172    let handler = MetadataHandler::new(tx);
173    c.set_metadata_handler(handler).unwrap();
174
175    c.activate().unwrap();
176
177    while RUNNING.load(atomic::Ordering::SeqCst) {
178        thread::sleep(Duration::from_millis(1000));
179    }
180    println!("tearing down");
181    c.close().unwrap();
182}
examples/thru.rs (line 63)
50fn main() {
51    // register a signal handler (see comments at top of file)
52    let action = signal::SigAction::new(
53        signal::SigHandler::Handler(handle_sigint),
54        signal::SaFlags::empty(),
55        signal::SigSet::empty());
56
57    unsafe { signal::sigaction(signal::Signal::SIGINT, &action) }.unwrap();
58
59    // set our global atomic to true
60    RUNNING.store(true, atomic::Ordering::SeqCst);
61
62    let mut jack_client =
63        jack::Client::open("testclient", jack::options::NO_START_SERVER).unwrap().0;
64
65    println!("client created named: {}", jack_client.get_name());
66
67    // 2 in, 2 out
68    let input1 = jack_client.register_input_audio_port("input1").unwrap();
69    let input2 = jack_client.register_input_audio_port("input2").unwrap();
70    let output1 = jack_client.register_output_audio_port("output1").unwrap();
71    let output2 = jack_client.register_output_audio_port("output2").unwrap();
72
73    let handler = Connector::new(vec![input1, input2], vec![output1, output2]);
74    jack_client.set_process_handler(handler).unwrap();
75
76    // start everything up
77    jack_client.activate().unwrap();
78
79    // wait to get a SIGINT
80    // jack will do all of its magic in other threads
81    while RUNNING.load(atomic::Ordering::SeqCst) {
82        thread::sleep(Duration::from_millis(1000));
83    }
84
85    // now we can clean everything up
86    // the library doesn't handle this for us because it would be rather confusing, especially
87    // given how the underlying jack api actually works
88    println!("tearing down");
89
90    // closing the client unregisters all of the ports
91    // unregistering the ports after the client is closed is an error
92    jack_client.close().unwrap();
93}
Source

pub fn open_connection_to( clientname: &str, servername: &str, opts: Options, ) -> Result<(Self, String), Status>

Attempts to open a client connecting to a server with a specified name

Examples found in repository?
examples/connect.rs (line 41)
35    fn new(servername: Option<String>) -> Result<Self, jack::status::Status> {
36        // we don't want to start a server if none is already started
37        let opts   = jack::options::NO_START_SERVER;
38        let myname = "connector";
39        let client = match servername {
40            None             => jack::Client::open(myname, opts),
41            Some(servername) => jack::Client::open_connection_to(myname, &*servername, opts),
42        };
43
44        let client = match client {
45            Ok((cl, _)) => cl,
46            Err(code)   => return Err(code)
47        };
48
49        // create our channel to communicate with the handler
50        let (tx, rx) = mpsc::channel();
51
52        // create the handler and give it the transmission end of the channel
53        let handler = ConnectorHandler { outgoing: tx };
54
55        // create an instance of the Connector, then set up the handler
56        let mut conn = Connector { client: client, incoming: rx };
57        conn.client.set_metadata_handler(handler).unwrap();
58
59        Ok(conn)
60    }
Source

pub fn get_name(&self) -> String

Returns the actual name of the client. This is useful when USE_EXACT_NAME is not specified, because the jack server might assign some other name to your client to ensure that it is unique.

Returns a copy of the actual string returned the JACK C API

Examples found in repository?
examples/thru.rs (line 65)
50fn main() {
51    // register a signal handler (see comments at top of file)
52    let action = signal::SigAction::new(
53        signal::SigHandler::Handler(handle_sigint),
54        signal::SaFlags::empty(),
55        signal::SigSet::empty());
56
57    unsafe { signal::sigaction(signal::Signal::SIGINT, &action) }.unwrap();
58
59    // set our global atomic to true
60    RUNNING.store(true, atomic::Ordering::SeqCst);
61
62    let mut jack_client =
63        jack::Client::open("testclient", jack::options::NO_START_SERVER).unwrap().0;
64
65    println!("client created named: {}", jack_client.get_name());
66
67    // 2 in, 2 out
68    let input1 = jack_client.register_input_audio_port("input1").unwrap();
69    let input2 = jack_client.register_input_audio_port("input2").unwrap();
70    let output1 = jack_client.register_output_audio_port("output1").unwrap();
71    let output2 = jack_client.register_output_audio_port("output2").unwrap();
72
73    let handler = Connector::new(vec![input1, input2], vec![output1, output2]);
74    jack_client.set_process_handler(handler).unwrap();
75
76    // start everything up
77    jack_client.activate().unwrap();
78
79    // wait to get a SIGINT
80    // jack will do all of its magic in other threads
81    while RUNNING.load(atomic::Ordering::SeqCst) {
82        thread::sleep(Duration::from_millis(1000));
83    }
84
85    // now we can clean everything up
86    // the library doesn't handle this for us because it would be rather confusing, especially
87    // given how the underlying jack api actually works
88    println!("tearing down");
89
90    // closing the client unregisters all of the ports
91    // unregistering the ports after the client is closed is an error
92    jack_client.close().unwrap();
93}
Source

pub fn register_input_audio_port( &mut self, name: &str, ) -> Result<InputPortHandle<DefaultAudioSample>, Status>

Helper function which registers an input audio port with a given name.

Examples found in repository?
examples/thru.rs (line 68)
50fn main() {
51    // register a signal handler (see comments at top of file)
52    let action = signal::SigAction::new(
53        signal::SigHandler::Handler(handle_sigint),
54        signal::SaFlags::empty(),
55        signal::SigSet::empty());
56
57    unsafe { signal::sigaction(signal::Signal::SIGINT, &action) }.unwrap();
58
59    // set our global atomic to true
60    RUNNING.store(true, atomic::Ordering::SeqCst);
61
62    let mut jack_client =
63        jack::Client::open("testclient", jack::options::NO_START_SERVER).unwrap().0;
64
65    println!("client created named: {}", jack_client.get_name());
66
67    // 2 in, 2 out
68    let input1 = jack_client.register_input_audio_port("input1").unwrap();
69    let input2 = jack_client.register_input_audio_port("input2").unwrap();
70    let output1 = jack_client.register_output_audio_port("output1").unwrap();
71    let output2 = jack_client.register_output_audio_port("output2").unwrap();
72
73    let handler = Connector::new(vec![input1, input2], vec![output1, output2]);
74    jack_client.set_process_handler(handler).unwrap();
75
76    // start everything up
77    jack_client.activate().unwrap();
78
79    // wait to get a SIGINT
80    // jack will do all of its magic in other threads
81    while RUNNING.load(atomic::Ordering::SeqCst) {
82        thread::sleep(Duration::from_millis(1000));
83    }
84
85    // now we can clean everything up
86    // the library doesn't handle this for us because it would be rather confusing, especially
87    // given how the underlying jack api actually works
88    println!("tearing down");
89
90    // closing the client unregisters all of the ports
91    // unregistering the ports after the client is closed is an error
92    jack_client.close().unwrap();
93}
Source

pub fn register_input_midi_port( &mut self, name: &str, ) -> Result<InputPortHandle<MidiEvent>, Status>

Helper function which registers an input midi port with a given name.

Examples found in repository?
examples/midi_sine.rs (line 164)
150fn main() {
151    // register a signal handler (see comments at top of file)
152    let action = signal::SigAction::new(
153        signal::SigHandler::Handler(handle_sigint),
154        signal::SaFlags::empty(),
155        signal::SigSet::empty());
156
157    unsafe { signal::sigaction(signal::Signal::SIGINT, &action) }.unwrap();
158
159    // set our global atomic to true
160    RUNNING.store(true, atomic::Ordering::SeqCst);
161
162
163    let mut c = jack::Client::open("midi_sine", jack::options::NO_START_SERVER).unwrap().0;
164    let i = c.register_input_midi_port("midi_in").unwrap();
165    let o = c.register_output_audio_port("audio_out").unwrap();
166
167    let (tx, rx) = mpsc::sync_channel(1);
168
169    let handler = AudioHandler::new(i, o, rx);
170    c.set_process_handler(handler).unwrap();
171
172    let handler = MetadataHandler::new(tx);
173    c.set_metadata_handler(handler).unwrap();
174
175    c.activate().unwrap();
176
177    while RUNNING.load(atomic::Ordering::SeqCst) {
178        thread::sleep(Duration::from_millis(1000));
179    }
180    println!("tearing down");
181    c.close().unwrap();
182}
Source

pub fn register_output_audio_port( &mut self, name: &str, ) -> Result<OutputPortHandle<DefaultAudioSample>, Status>

Helper function which registers an output audio port with a given name.

Examples found in repository?
examples/simple_client.rs (line 120)
112    fn new() -> Result<Self, jack::status::Status> {
113        let client = jack::Client::open("simple", jack::options::NO_START_SERVER);
114        let mut client = match client {
115            Ok((client, _)) => client,
116            Err(code)       => return Err(code),
117        };
118
119        // get some ports
120        let right = client.register_output_audio_port("output1").unwrap();
121        let left  = client.register_output_audio_port("output2").unwrap();
122
123        // create a channel pair we can use to communicate with
124        let (tx, rx) = mpsc::sync_channel(1);
125
126        // create a client, set it up as an audio processing handler
127        let handler = AudioHandler::new(SimpleClient::compute_sine(0.2), right, left, rx);
128        client.set_process_handler(handler).unwrap();
129
130        Ok(SimpleClient {
131            client: client,
132            sender: tx,
133        })
134    }
More examples
Hide additional examples
examples/midi_sine.rs (line 165)
150fn main() {
151    // register a signal handler (see comments at top of file)
152    let action = signal::SigAction::new(
153        signal::SigHandler::Handler(handle_sigint),
154        signal::SaFlags::empty(),
155        signal::SigSet::empty());
156
157    unsafe { signal::sigaction(signal::Signal::SIGINT, &action) }.unwrap();
158
159    // set our global atomic to true
160    RUNNING.store(true, atomic::Ordering::SeqCst);
161
162
163    let mut c = jack::Client::open("midi_sine", jack::options::NO_START_SERVER).unwrap().0;
164    let i = c.register_input_midi_port("midi_in").unwrap();
165    let o = c.register_output_audio_port("audio_out").unwrap();
166
167    let (tx, rx) = mpsc::sync_channel(1);
168
169    let handler = AudioHandler::new(i, o, rx);
170    c.set_process_handler(handler).unwrap();
171
172    let handler = MetadataHandler::new(tx);
173    c.set_metadata_handler(handler).unwrap();
174
175    c.activate().unwrap();
176
177    while RUNNING.load(atomic::Ordering::SeqCst) {
178        thread::sleep(Duration::from_millis(1000));
179    }
180    println!("tearing down");
181    c.close().unwrap();
182}
examples/thru.rs (line 70)
50fn main() {
51    // register a signal handler (see comments at top of file)
52    let action = signal::SigAction::new(
53        signal::SigHandler::Handler(handle_sigint),
54        signal::SaFlags::empty(),
55        signal::SigSet::empty());
56
57    unsafe { signal::sigaction(signal::Signal::SIGINT, &action) }.unwrap();
58
59    // set our global atomic to true
60    RUNNING.store(true, atomic::Ordering::SeqCst);
61
62    let mut jack_client =
63        jack::Client::open("testclient", jack::options::NO_START_SERVER).unwrap().0;
64
65    println!("client created named: {}", jack_client.get_name());
66
67    // 2 in, 2 out
68    let input1 = jack_client.register_input_audio_port("input1").unwrap();
69    let input2 = jack_client.register_input_audio_port("input2").unwrap();
70    let output1 = jack_client.register_output_audio_port("output1").unwrap();
71    let output2 = jack_client.register_output_audio_port("output2").unwrap();
72
73    let handler = Connector::new(vec![input1, input2], vec![output1, output2]);
74    jack_client.set_process_handler(handler).unwrap();
75
76    // start everything up
77    jack_client.activate().unwrap();
78
79    // wait to get a SIGINT
80    // jack will do all of its magic in other threads
81    while RUNNING.load(atomic::Ordering::SeqCst) {
82        thread::sleep(Duration::from_millis(1000));
83    }
84
85    // now we can clean everything up
86    // the library doesn't handle this for us because it would be rather confusing, especially
87    // given how the underlying jack api actually works
88    println!("tearing down");
89
90    // closing the client unregisters all of the ports
91    // unregistering the ports after the client is closed is an error
92    jack_client.close().unwrap();
93}
Source

pub fn unregister_port<T: Port>(&mut self, port: T) -> Result<(), Status>

Removes the port from the client and invalidates the port and all Handles relating to the port.

The server disconnects everything that was previously connected to the port.

Source

pub fn get_port_by_name(&self, name: &str) -> Option<UnknownPortHandle>

Source

pub fn get_port_by_id(&self, id: PortId) -> Option<UnknownPortHandle>

Examples found in repository?
examples/connect.rs (line 76)
74    fn wait_and_shutdown(self) {
75        let (a, b, stat) = self.incoming.recv().unwrap();
76        let n1 = self.client.get_port_by_id(a).unwrap().get_name();
77        let n2 = self.client.get_port_by_id(b).unwrap().get_name();
78
79        match stat {
80            jack::PortConnectStatus::PortsConnected =>
81                println!("ports connected: {} and {}", n1, n2),
82
83            jack::PortConnectStatus::PortsDisconnected =>
84                println!("ports disconnected: {} and {}", n1, n2)
85        }
86    }
Source

pub fn connect_ports(&mut self, port1: &str, port2: &str) -> Result<(), Status>

Attempts to connect the ports with the given names Note that this method calls directly into the jack api. It does not perform lookups for the names before making the call

Examples found in repository?
examples/connect.rs (line 67)
66    fn connect(&mut self, port1: &str, port2: &str) -> Result<(), jack::status::Status> {
67        self.client.connect_ports(port1, port2)
68    }
Source

pub fn disconnect_ports( &mut self, port1: &str, port2: &str, ) -> Result<(), Status>

Attempts to disconnect the ports with the given names Note that this method calls directly into the jack api. It does not perform lookups for the names before making the call

Examples found in repository?
examples/connect.rs (line 71)
70    fn disconnect(&mut self, port1: &str, port2: &str) -> Result<(), jack::status::Status> {
71        self.client.disconnect_ports(port1, port2)
72    }
Source

pub fn set_process_handler<T: ProcessHandler + 'a>( &mut self, handler: T, ) -> Result<(), Status>

Set the client’s process callback handler. The client takes ownership of the handler, so be sure to set up any messaging queues before passing the handler off to the client See the docs for the ProcessHandler struct for more details

Examples found in repository?
examples/simple_client.rs (line 128)
112    fn new() -> Result<Self, jack::status::Status> {
113        let client = jack::Client::open("simple", jack::options::NO_START_SERVER);
114        let mut client = match client {
115            Ok((client, _)) => client,
116            Err(code)       => return Err(code),
117        };
118
119        // get some ports
120        let right = client.register_output_audio_port("output1").unwrap();
121        let left  = client.register_output_audio_port("output2").unwrap();
122
123        // create a channel pair we can use to communicate with
124        let (tx, rx) = mpsc::sync_channel(1);
125
126        // create a client, set it up as an audio processing handler
127        let handler = AudioHandler::new(SimpleClient::compute_sine(0.2), right, left, rx);
128        client.set_process_handler(handler).unwrap();
129
130        Ok(SimpleClient {
131            client: client,
132            sender: tx,
133        })
134    }
More examples
Hide additional examples
examples/midi_sine.rs (line 170)
150fn main() {
151    // register a signal handler (see comments at top of file)
152    let action = signal::SigAction::new(
153        signal::SigHandler::Handler(handle_sigint),
154        signal::SaFlags::empty(),
155        signal::SigSet::empty());
156
157    unsafe { signal::sigaction(signal::Signal::SIGINT, &action) }.unwrap();
158
159    // set our global atomic to true
160    RUNNING.store(true, atomic::Ordering::SeqCst);
161
162
163    let mut c = jack::Client::open("midi_sine", jack::options::NO_START_SERVER).unwrap().0;
164    let i = c.register_input_midi_port("midi_in").unwrap();
165    let o = c.register_output_audio_port("audio_out").unwrap();
166
167    let (tx, rx) = mpsc::sync_channel(1);
168
169    let handler = AudioHandler::new(i, o, rx);
170    c.set_process_handler(handler).unwrap();
171
172    let handler = MetadataHandler::new(tx);
173    c.set_metadata_handler(handler).unwrap();
174
175    c.activate().unwrap();
176
177    while RUNNING.load(atomic::Ordering::SeqCst) {
178        thread::sleep(Duration::from_millis(1000));
179    }
180    println!("tearing down");
181    c.close().unwrap();
182}
examples/thru.rs (line 74)
50fn main() {
51    // register a signal handler (see comments at top of file)
52    let action = signal::SigAction::new(
53        signal::SigHandler::Handler(handle_sigint),
54        signal::SaFlags::empty(),
55        signal::SigSet::empty());
56
57    unsafe { signal::sigaction(signal::Signal::SIGINT, &action) }.unwrap();
58
59    // set our global atomic to true
60    RUNNING.store(true, atomic::Ordering::SeqCst);
61
62    let mut jack_client =
63        jack::Client::open("testclient", jack::options::NO_START_SERVER).unwrap().0;
64
65    println!("client created named: {}", jack_client.get_name());
66
67    // 2 in, 2 out
68    let input1 = jack_client.register_input_audio_port("input1").unwrap();
69    let input2 = jack_client.register_input_audio_port("input2").unwrap();
70    let output1 = jack_client.register_output_audio_port("output1").unwrap();
71    let output2 = jack_client.register_output_audio_port("output2").unwrap();
72
73    let handler = Connector::new(vec![input1, input2], vec![output1, output2]);
74    jack_client.set_process_handler(handler).unwrap();
75
76    // start everything up
77    jack_client.activate().unwrap();
78
79    // wait to get a SIGINT
80    // jack will do all of its magic in other threads
81    while RUNNING.load(atomic::Ordering::SeqCst) {
82        thread::sleep(Duration::from_millis(1000));
83    }
84
85    // now we can clean everything up
86    // the library doesn't handle this for us because it would be rather confusing, especially
87    // given how the underlying jack api actually works
88    println!("tearing down");
89
90    // closing the client unregisters all of the ports
91    // unregistering the ports after the client is closed is an error
92    jack_client.close().unwrap();
93}
Source

pub fn set_metadata_handler<T: MetadataHandler + 'a>( &mut self, handler: T, ) -> Result<(), Status>

Set the client’s sample rate change handler.

Examples found in repository?
examples/connect.rs (line 57)
35    fn new(servername: Option<String>) -> Result<Self, jack::status::Status> {
36        // we don't want to start a server if none is already started
37        let opts   = jack::options::NO_START_SERVER;
38        let myname = "connector";
39        let client = match servername {
40            None             => jack::Client::open(myname, opts),
41            Some(servername) => jack::Client::open_connection_to(myname, &*servername, opts),
42        };
43
44        let client = match client {
45            Ok((cl, _)) => cl,
46            Err(code)   => return Err(code)
47        };
48
49        // create our channel to communicate with the handler
50        let (tx, rx) = mpsc::channel();
51
52        // create the handler and give it the transmission end of the channel
53        let handler = ConnectorHandler { outgoing: tx };
54
55        // create an instance of the Connector, then set up the handler
56        let mut conn = Connector { client: client, incoming: rx };
57        conn.client.set_metadata_handler(handler).unwrap();
58
59        Ok(conn)
60    }
More examples
Hide additional examples
examples/midi_sine.rs (line 173)
150fn main() {
151    // register a signal handler (see comments at top of file)
152    let action = signal::SigAction::new(
153        signal::SigHandler::Handler(handle_sigint),
154        signal::SaFlags::empty(),
155        signal::SigSet::empty());
156
157    unsafe { signal::sigaction(signal::Signal::SIGINT, &action) }.unwrap();
158
159    // set our global atomic to true
160    RUNNING.store(true, atomic::Ordering::SeqCst);
161
162
163    let mut c = jack::Client::open("midi_sine", jack::options::NO_START_SERVER).unwrap().0;
164    let i = c.register_input_midi_port("midi_in").unwrap();
165    let o = c.register_output_audio_port("audio_out").unwrap();
166
167    let (tx, rx) = mpsc::sync_channel(1);
168
169    let handler = AudioHandler::new(i, o, rx);
170    c.set_process_handler(handler).unwrap();
171
172    let handler = MetadataHandler::new(tx);
173    c.set_metadata_handler(handler).unwrap();
174
175    c.activate().unwrap();
176
177    while RUNNING.load(atomic::Ordering::SeqCst) {
178        thread::sleep(Duration::from_millis(1000));
179    }
180    println!("tearing down");
181    c.close().unwrap();
182}
Source

pub fn activate(&self) -> Result<(), Status>

tells the JACK server that the client is read to start processing audio This will initiate callbacks into the CallbackHandler provided.

Examples found in repository?
examples/connect.rs (line 63)
62    fn activate(&mut self) -> Result<(), jack::status::Status> {
63        self.client.activate()
64    }
More examples
Hide additional examples
examples/simple_client.rs (line 137)
136    fn activate(&mut self) -> Result<(), jack::status::Status> {
137        self.client.activate()
138    }
examples/midi_sine.rs (line 175)
150fn main() {
151    // register a signal handler (see comments at top of file)
152    let action = signal::SigAction::new(
153        signal::SigHandler::Handler(handle_sigint),
154        signal::SaFlags::empty(),
155        signal::SigSet::empty());
156
157    unsafe { signal::sigaction(signal::Signal::SIGINT, &action) }.unwrap();
158
159    // set our global atomic to true
160    RUNNING.store(true, atomic::Ordering::SeqCst);
161
162
163    let mut c = jack::Client::open("midi_sine", jack::options::NO_START_SERVER).unwrap().0;
164    let i = c.register_input_midi_port("midi_in").unwrap();
165    let o = c.register_output_audio_port("audio_out").unwrap();
166
167    let (tx, rx) = mpsc::sync_channel(1);
168
169    let handler = AudioHandler::new(i, o, rx);
170    c.set_process_handler(handler).unwrap();
171
172    let handler = MetadataHandler::new(tx);
173    c.set_metadata_handler(handler).unwrap();
174
175    c.activate().unwrap();
176
177    while RUNNING.load(atomic::Ordering::SeqCst) {
178        thread::sleep(Duration::from_millis(1000));
179    }
180    println!("tearing down");
181    c.close().unwrap();
182}
examples/thru.rs (line 77)
50fn main() {
51    // register a signal handler (see comments at top of file)
52    let action = signal::SigAction::new(
53        signal::SigHandler::Handler(handle_sigint),
54        signal::SaFlags::empty(),
55        signal::SigSet::empty());
56
57    unsafe { signal::sigaction(signal::Signal::SIGINT, &action) }.unwrap();
58
59    // set our global atomic to true
60    RUNNING.store(true, atomic::Ordering::SeqCst);
61
62    let mut jack_client =
63        jack::Client::open("testclient", jack::options::NO_START_SERVER).unwrap().0;
64
65    println!("client created named: {}", jack_client.get_name());
66
67    // 2 in, 2 out
68    let input1 = jack_client.register_input_audio_port("input1").unwrap();
69    let input2 = jack_client.register_input_audio_port("input2").unwrap();
70    let output1 = jack_client.register_output_audio_port("output1").unwrap();
71    let output2 = jack_client.register_output_audio_port("output2").unwrap();
72
73    let handler = Connector::new(vec![input1, input2], vec![output1, output2]);
74    jack_client.set_process_handler(handler).unwrap();
75
76    // start everything up
77    jack_client.activate().unwrap();
78
79    // wait to get a SIGINT
80    // jack will do all of its magic in other threads
81    while RUNNING.load(atomic::Ordering::SeqCst) {
82        thread::sleep(Duration::from_millis(1000));
83    }
84
85    // now we can clean everything up
86    // the library doesn't handle this for us because it would be rather confusing, especially
87    // given how the underlying jack api actually works
88    println!("tearing down");
89
90    // closing the client unregisters all of the ports
91    // unregistering the ports after the client is closed is an error
92    jack_client.close().unwrap();
93}
Source

pub fn close(&mut self) -> Result<(), &str>

Disconnects the client from the JACK server. This will also disconnect and destroy any of the ports which the client registered

Examples found in repository?
examples/simple_client.rs (line 159)
140    fn run(mut self) {
141        let mut i = 0;
142        while RUNNING.load(atomic::Ordering::SeqCst) {
143            let newsine = SimpleClient::compute_sine(i as f32 / 10.0);
144
145            match self.sender.send(newsine) {
146                Ok(_)  => (),
147                Err(_) => (),
148            };
149
150            i += 1;
151            if i > 10 {
152                i = 0
153            }
154
155            thread::sleep(Duration::from_millis(1000));
156        }
157
158        println!("tearing down");
159        self.client.close().unwrap();
160    }
More examples
Hide additional examples
examples/midi_sine.rs (line 181)
150fn main() {
151    // register a signal handler (see comments at top of file)
152    let action = signal::SigAction::new(
153        signal::SigHandler::Handler(handle_sigint),
154        signal::SaFlags::empty(),
155        signal::SigSet::empty());
156
157    unsafe { signal::sigaction(signal::Signal::SIGINT, &action) }.unwrap();
158
159    // set our global atomic to true
160    RUNNING.store(true, atomic::Ordering::SeqCst);
161
162
163    let mut c = jack::Client::open("midi_sine", jack::options::NO_START_SERVER).unwrap().0;
164    let i = c.register_input_midi_port("midi_in").unwrap();
165    let o = c.register_output_audio_port("audio_out").unwrap();
166
167    let (tx, rx) = mpsc::sync_channel(1);
168
169    let handler = AudioHandler::new(i, o, rx);
170    c.set_process_handler(handler).unwrap();
171
172    let handler = MetadataHandler::new(tx);
173    c.set_metadata_handler(handler).unwrap();
174
175    c.activate().unwrap();
176
177    while RUNNING.load(atomic::Ordering::SeqCst) {
178        thread::sleep(Duration::from_millis(1000));
179    }
180    println!("tearing down");
181    c.close().unwrap();
182}
examples/thru.rs (line 92)
50fn main() {
51    // register a signal handler (see comments at top of file)
52    let action = signal::SigAction::new(
53        signal::SigHandler::Handler(handle_sigint),
54        signal::SaFlags::empty(),
55        signal::SigSet::empty());
56
57    unsafe { signal::sigaction(signal::Signal::SIGINT, &action) }.unwrap();
58
59    // set our global atomic to true
60    RUNNING.store(true, atomic::Ordering::SeqCst);
61
62    let mut jack_client =
63        jack::Client::open("testclient", jack::options::NO_START_SERVER).unwrap().0;
64
65    println!("client created named: {}", jack_client.get_name());
66
67    // 2 in, 2 out
68    let input1 = jack_client.register_input_audio_port("input1").unwrap();
69    let input2 = jack_client.register_input_audio_port("input2").unwrap();
70    let output1 = jack_client.register_output_audio_port("output1").unwrap();
71    let output2 = jack_client.register_output_audio_port("output2").unwrap();
72
73    let handler = Connector::new(vec![input1, input2], vec![output1, output2]);
74    jack_client.set_process_handler(handler).unwrap();
75
76    // start everything up
77    jack_client.activate().unwrap();
78
79    // wait to get a SIGINT
80    // jack will do all of its magic in other threads
81    while RUNNING.load(atomic::Ordering::SeqCst) {
82        thread::sleep(Duration::from_millis(1000));
83    }
84
85    // now we can clean everything up
86    // the library doesn't handle this for us because it would be rather confusing, especially
87    // given how the underlying jack api actually works
88    println!("tearing down");
89
90    // closing the client unregisters all of the ports
91    // unregistering the ports after the client is closed is an error
92    jack_client.close().unwrap();
93}

Auto Trait Implementations§

§

impl<'a> Freeze for Client<'a>

§

impl<'a> !RefUnwindSafe for Client<'a>

§

impl<'a> !Send for Client<'a>

§

impl<'a> !Sync for Client<'a>

§

impl<'a> Unpin for Client<'a>

§

impl<'a> !UnwindSafe for Client<'a>

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.