pub struct Client<'a> { /* private fields */ }
Expand description
A jack client connected to a jack server
TODO example
Implementations§
Source§impl<'a> Client<'a>
impl<'a> Client<'a>
Sourcepub fn open(name: &str, opts: Options) -> Result<(Self, String), Status>
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?
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
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 }
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}
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}
Sourcepub fn open_connection_to(
clientname: &str,
servername: &str,
opts: Options,
) -> Result<(Self, String), Status>
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?
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 }
Sourcepub fn get_name(&self) -> String
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?
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}
Sourcepub fn register_input_audio_port(
&mut self,
name: &str,
) -> Result<InputPortHandle<DefaultAudioSample>, Status>
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?
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}
Sourcepub fn register_input_midi_port(
&mut self,
name: &str,
) -> Result<InputPortHandle<MidiEvent>, Status>
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?
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}
Sourcepub fn register_output_audio_port(
&mut self,
name: &str,
) -> Result<OutputPortHandle<DefaultAudioSample>, Status>
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?
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
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}
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}
Sourcepub fn unregister_port<T: Port>(&mut self, port: T) -> Result<(), Status>
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.
pub fn get_port_by_name(&self, name: &str) -> Option<UnknownPortHandle>
Sourcepub fn get_port_by_id(&self, id: PortId) -> Option<UnknownPortHandle>
pub fn get_port_by_id(&self, id: PortId) -> Option<UnknownPortHandle>
Examples found in repository?
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 }
Sourcepub fn connect_ports(&mut self, port1: &str, port2: &str) -> Result<(), Status>
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
Sourcepub fn disconnect_ports(
&mut self,
port1: &str,
port2: &str,
) -> Result<(), Status>
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
Sourcepub fn set_process_handler<T: ProcessHandler + 'a>(
&mut self,
handler: T,
) -> Result<(), Status>
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?
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
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}
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}
Sourcepub fn set_metadata_handler<T: MetadataHandler + 'a>(
&mut self,
handler: T,
) -> Result<(), Status>
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?
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
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}
Sourcepub fn activate(&self) -> Result<(), Status>
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?
More examples
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}
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}
Sourcepub fn close(&mut self) -> Result<(), &str>
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?
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
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}
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}