-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathplayback_capture.rs
130 lines (114 loc) · 3.85 KB
/
playback_capture.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//! Takes 2 audio inputs and outputs them to 2 audio outputs.
//! All JACK notifications are also printed out.
use std::io;
fn main() {
// Create client
let (client, _status) =
jack::Client::new("rust_jack_simple", jack::ClientOptions::NO_START_SERVER).unwrap();
// Register ports. They will be used in a callback that will be
// called when new data is available.
let in_a = client
.register_port("rust_in_l", jack::AudioIn::default())
.unwrap();
let in_b = client
.register_port("rust_in_r", jack::AudioIn::default())
.unwrap();
let mut out_a = client
.register_port("rust_out_l", jack::AudioOut::default())
.unwrap();
let mut out_b = client
.register_port("rust_out_r", jack::AudioOut::default())
.unwrap();
let process_callback = move |_: &jack::Client, ps: &jack::ProcessScope| -> jack::Control {
let out_a_p = out_a.as_mut_slice(ps);
let out_b_p = out_b.as_mut_slice(ps);
let in_a_p = in_a.as_slice(ps);
let in_b_p = in_b.as_slice(ps);
out_a_p.clone_from_slice(in_a_p);
out_b_p.clone_from_slice(in_b_p);
jack::Control::Continue
};
let process = jack::ClosureProcessHandler::new(process_callback);
// Activate the client, which starts the processing.
let active_client = client.activate_async(Notifications, process).unwrap();
// Wait for user input to quit
println!("Press enter/return to quit...");
let mut user_input = String::new();
io::stdin().read_line(&mut user_input).ok();
active_client.deactivate().unwrap();
}
struct Notifications;
impl jack::NotificationHandler for Notifications {
fn thread_init(&mut self, _: &jack::Client) {
println!("JACK: thread init");
}
fn shutdown(&mut self, status: jack::ClientStatus, reason: &str) {
println!(
"JACK: shutdown with status {:?} because \"{}\"",
status, reason
);
}
fn freewheel(&mut self, _: &jack::Client, is_enabled: bool) {
println!(
"JACK: freewheel mode is {}",
if is_enabled { "on" } else { "off" }
);
}
fn sample_rate(&mut self, _: &jack::Client, srate: jack::Frames) -> jack::Control {
println!("JACK: sample rate changed to {}", srate);
jack::Control::Continue
}
fn client_registration(&mut self, _: &jack::Client, name: &str, is_reg: bool) {
println!(
"JACK: {} client with name \"{}\"",
if is_reg { "registered" } else { "unregistered" },
name
);
}
fn port_registration(&mut self, _: &jack::Client, port_id: jack::PortId, is_reg: bool) {
println!(
"JACK: {} port with id {}",
if is_reg { "registered" } else { "unregistered" },
port_id
);
}
fn port_rename(
&mut self,
_: &jack::Client,
port_id: jack::PortId,
old_name: &str,
new_name: &str,
) -> jack::Control {
println!(
"JACK: port with id {} renamed from {} to {}",
port_id, old_name, new_name
);
jack::Control::Continue
}
fn ports_connected(
&mut self,
_: &jack::Client,
port_id_a: jack::PortId,
port_id_b: jack::PortId,
are_connected: bool,
) {
println!(
"JACK: ports with id {} and {} are {}",
port_id_a,
port_id_b,
if are_connected {
"connected"
} else {
"disconnected"
}
);
}
fn graph_reorder(&mut self, _: &jack::Client) -> jack::Control {
println!("JACK: graph reordered");
jack::Control::Continue
}
fn xrun(&mut self, _: &jack::Client) -> jack::Control {
println!("JACK: xrun occurred");
jack::Control::Continue
}
}