diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/dbus_api/equalizing_manager.rs | 291 | ||||
-rw-r--r-- | src/dbus_api/mod.rs | 3 | ||||
-rw-r--r-- | src/dbus_api/server_lookup.rs | 188 | ||||
-rw-r--r-- | src/dbus_api/sink.rs | 1128 | ||||
-rw-r--r-- | src/main.rs | 132 | ||||
-rw-r--r-- | src/parsing/equalizer_apo.lalrpop | 42 | ||||
-rw-r--r-- | src/parsing/equalizer_apo.rs | 1164 | ||||
-rw-r--r-- | src/parsing/mod.rs | 3 | ||||
-rw-r--r-- | src/utils.rs | 71 |
9 files changed, 3022 insertions, 0 deletions
diff --git a/src/dbus_api/equalizing_manager.rs b/src/dbus_api/equalizing_manager.rs new file mode 100644 index 0000000..5f6574f --- /dev/null +++ b/src/dbus_api/equalizing_manager.rs | |||
@@ -0,0 +1,291 @@ | |||
1 | // This code was autogenerated with dbus-codegen-rust, see https://github.com/diwic/dbus-rs | ||
2 | |||
3 | #![allow(dead_code)] | ||
4 | use dbus as dbus; | ||
5 | use dbus::arg; | ||
6 | use dbus::tree; | ||
7 | |||
8 | pub trait OrgPulseAudioExtEqualizing1Manager { | ||
9 | type Err; | ||
10 | fn remove_profile(&self, name: &str) -> Result<(), Self::Err>; | ||
11 | fn get_interface_revision(&self) -> Result<u32, Self::Err>; | ||
12 | fn get_equalized_sinks(&self) -> Result<Vec<dbus::Path<'static>>, Self::Err>; | ||
13 | fn get_profiles(&self) -> Result<Vec<String>, Self::Err>; | ||
14 | } | ||
15 | |||
16 | impl<'a, C: ::std::ops::Deref<Target=dbus::Connection>> OrgPulseAudioExtEqualizing1Manager for dbus::ConnPath<'a, C> { | ||
17 | type Err = dbus::Error; | ||
18 | |||
19 | fn remove_profile(&self, name: &str) -> Result<(), Self::Err> { | ||
20 | let mut m = try!(self.method_call_with_args(&"org.PulseAudio.Ext.Equalizing1.Manager".into(), &"RemoveProfile".into(), |msg| { | ||
21 | let mut i = arg::IterAppend::new(msg); | ||
22 | i.append(name); | ||
23 | })); | ||
24 | try!(m.as_result()); | ||
25 | Ok(()) | ||
26 | } | ||
27 | |||
28 | fn get_interface_revision(&self) -> Result<u32, Self::Err> { | ||
29 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Ext.Equalizing1.Manager", "InterfaceRevision") | ||
30 | } | ||
31 | |||
32 | fn get_equalized_sinks(&self) -> Result<Vec<dbus::Path<'static>>, Self::Err> { | ||
33 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Ext.Equalizing1.Manager", "EqualizedSinks") | ||
34 | } | ||
35 | |||
36 | fn get_profiles(&self) -> Result<Vec<String>, Self::Err> { | ||
37 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Ext.Equalizing1.Manager", "Profiles") | ||
38 | } | ||
39 | } | ||
40 | |||
41 | pub fn org_pulse_audio_ext_equalizing1_manager_server<F, T, D>(factory: &tree::Factory<tree::MTFn<D>, D>, data: D::Interface, f: F) -> tree::Interface<tree::MTFn<D>, D> | ||
42 | where | ||
43 | D: tree::DataType, | ||
44 | D::Method: Default, | ||
45 | D::Property: Default, | ||
46 | T: OrgPulseAudioExtEqualizing1Manager<Err=tree::MethodErr>, | ||
47 | F: 'static + for <'z> Fn(& 'z tree::MethodInfo<tree::MTFn<D>, D>) -> & 'z T, | ||
48 | { | ||
49 | let i = factory.interface("org.PulseAudio.Ext.Equalizing1.Manager", data); | ||
50 | let f = ::std::sync::Arc::new(f); | ||
51 | let fclone = f.clone(); | ||
52 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
53 | let mut i = minfo.msg.iter_init(); | ||
54 | let name: &str = try!(i.read()); | ||
55 | let d = fclone(minfo); | ||
56 | try!(d.remove_profile(name)); | ||
57 | let rm = minfo.msg.method_return(); | ||
58 | Ok(vec!(rm)) | ||
59 | }; | ||
60 | let m = factory.method("RemoveProfile", Default::default(), h); | ||
61 | let m = m.in_arg(("name", "s")); | ||
62 | let i = i.add_m(m); | ||
63 | |||
64 | let p = factory.property::<u32, _>("InterfaceRevision", Default::default()); | ||
65 | let p = p.access(tree::Access::Read); | ||
66 | let fclone = f.clone(); | ||
67 | let p = p.on_get(move |a, pinfo| { | ||
68 | let minfo = pinfo.to_method_info(); | ||
69 | let d = fclone(&minfo); | ||
70 | a.append(try!(d.get_interface_revision())); | ||
71 | Ok(()) | ||
72 | }); | ||
73 | let i = i.add_p(p); | ||
74 | |||
75 | let p = factory.property::<Vec<dbus::Path>, _>("EqualizedSinks", Default::default()); | ||
76 | let p = p.access(tree::Access::Read); | ||
77 | let fclone = f.clone(); | ||
78 | let p = p.on_get(move |a, pinfo| { | ||
79 | let minfo = pinfo.to_method_info(); | ||
80 | let d = fclone(&minfo); | ||
81 | a.append(try!(d.get_equalized_sinks())); | ||
82 | Ok(()) | ||
83 | }); | ||
84 | let i = i.add_p(p); | ||
85 | |||
86 | let p = factory.property::<Vec<&str>, _>("Profiles", Default::default()); | ||
87 | let p = p.access(tree::Access::Read); | ||
88 | let fclone = f.clone(); | ||
89 | let p = p.on_get(move |a, pinfo| { | ||
90 | let minfo = pinfo.to_method_info(); | ||
91 | let d = fclone(&minfo); | ||
92 | a.append(try!(d.get_profiles())); | ||
93 | Ok(()) | ||
94 | }); | ||
95 | let i = i.add_p(p); | ||
96 | i | ||
97 | } | ||
98 | |||
99 | #[derive(Debug, Default)] | ||
100 | pub struct OrgPulseAudioExtEqualizing1ManagerSinkAdded { | ||
101 | pub sink: dbus::Path<'static>, | ||
102 | } | ||
103 | |||
104 | impl dbus::SignalArgs for OrgPulseAudioExtEqualizing1ManagerSinkAdded { | ||
105 | const NAME: &'static str = "SinkAdded"; | ||
106 | const INTERFACE: &'static str = "org.PulseAudio.Ext.Equalizing1.Manager"; | ||
107 | fn append(&self, i: &mut arg::IterAppend) { | ||
108 | (&self.sink as &arg::RefArg).append(i); | ||
109 | } | ||
110 | fn get(&mut self, i: &mut arg::Iter) -> Result<(), arg::TypeMismatchError> { | ||
111 | self.sink = try!(i.read()); | ||
112 | Ok(()) | ||
113 | } | ||
114 | } | ||
115 | |||
116 | #[derive(Debug, Default)] | ||
117 | pub struct OrgPulseAudioExtEqualizing1ManagerSinkRemoved { | ||
118 | pub sink: dbus::Path<'static>, | ||
119 | } | ||
120 | |||
121 | impl dbus::SignalArgs for OrgPulseAudioExtEqualizing1ManagerSinkRemoved { | ||
122 | const NAME: &'static str = "SinkRemoved"; | ||
123 | const INTERFACE: &'static str = "org.PulseAudio.Ext.Equalizing1.Manager"; | ||
124 | fn append(&self, i: &mut arg::IterAppend) { | ||
125 | (&self.sink as &arg::RefArg).append(i); | ||
126 | } | ||
127 | fn get(&mut self, i: &mut arg::Iter) -> Result<(), arg::TypeMismatchError> { | ||
128 | self.sink = try!(i.read()); | ||
129 | Ok(()) | ||
130 | } | ||
131 | } | ||
132 | |||
133 | #[derive(Debug, Default)] | ||
134 | pub struct OrgPulseAudioExtEqualizing1ManagerProfilesChanged { | ||
135 | } | ||
136 | |||
137 | impl dbus::SignalArgs for OrgPulseAudioExtEqualizing1ManagerProfilesChanged { | ||
138 | const NAME: &'static str = "ProfilesChanged"; | ||
139 | const INTERFACE: &'static str = "org.PulseAudio.Ext.Equalizing1.Manager"; | ||
140 | fn append(&self, _: &mut arg::IterAppend) { | ||
141 | } | ||
142 | fn get(&mut self, _: &mut arg::Iter) -> Result<(), arg::TypeMismatchError> { | ||
143 | Ok(()) | ||
144 | } | ||
145 | } | ||
146 | |||
147 | pub trait OrgFreedesktopDBusIntrospectable { | ||
148 | type Err; | ||
149 | fn introspect(&self) -> Result<String, Self::Err>; | ||
150 | } | ||
151 | |||
152 | impl<'a, C: ::std::ops::Deref<Target=dbus::Connection>> OrgFreedesktopDBusIntrospectable for dbus::ConnPath<'a, C> { | ||
153 | type Err = dbus::Error; | ||
154 | |||
155 | fn introspect(&self) -> Result<String, Self::Err> { | ||
156 | let mut m = try!(self.method_call_with_args(&"org.freedesktop.DBus.Introspectable".into(), &"Introspect".into(), |_| { | ||
157 | })); | ||
158 | try!(m.as_result()); | ||
159 | let mut i = m.iter_init(); | ||
160 | let data: String = try!(i.read()); | ||
161 | Ok(data) | ||
162 | } | ||
163 | } | ||
164 | |||
165 | pub fn org_freedesktop_dbus_introspectable_server<F, T, D>(factory: &tree::Factory<tree::MTFn<D>, D>, data: D::Interface, f: F) -> tree::Interface<tree::MTFn<D>, D> | ||
166 | where | ||
167 | D: tree::DataType, | ||
168 | D::Method: Default, | ||
169 | T: OrgFreedesktopDBusIntrospectable<Err=tree::MethodErr>, | ||
170 | F: 'static + for <'z> Fn(& 'z tree::MethodInfo<tree::MTFn<D>, D>) -> & 'z T, | ||
171 | { | ||
172 | let i = factory.interface("org.freedesktop.DBus.Introspectable", data); | ||
173 | let f = ::std::sync::Arc::new(f); | ||
174 | let fclone = f.clone(); | ||
175 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
176 | let d = fclone(minfo); | ||
177 | let data = try!(d.introspect()); | ||
178 | let rm = minfo.msg.method_return(); | ||
179 | let rm = rm.append1(data); | ||
180 | Ok(vec!(rm)) | ||
181 | }; | ||
182 | let m = factory.method("Introspect", Default::default(), h); | ||
183 | let m = m.out_arg(("data", "s")); | ||
184 | let i = i.add_m(m); | ||
185 | i | ||
186 | } | ||
187 | |||
188 | pub trait OrgFreedesktopDBusProperties { | ||
189 | type Err; | ||
190 | fn get(&self, interface_name: &str, property_name: &str) -> Result<arg::Variant<Box<arg::RefArg>>, Self::Err>; | ||
191 | fn set(&self, interface_name: &str, property_name: &str, value: arg::Variant<Box<arg::RefArg>>) -> Result<(), Self::Err>; | ||
192 | fn get_all(&self, interface_name: &str) -> Result<::std::collections::HashMap<String, arg::Variant<Box<arg::RefArg>>>, Self::Err>; | ||
193 | } | ||
194 | |||
195 | impl<'a, C: ::std::ops::Deref<Target=dbus::Connection>> OrgFreedesktopDBusProperties for dbus::ConnPath<'a, C> { | ||
196 | type Err = dbus::Error; | ||
197 | |||
198 | fn get(&self, interface_name: &str, property_name: &str) -> Result<arg::Variant<Box<arg::RefArg>>, Self::Err> { | ||
199 | let mut m = try!(self.method_call_with_args(&"org.freedesktop.DBus.Properties".into(), &"Get".into(), |msg| { | ||
200 | let mut i = arg::IterAppend::new(msg); | ||
201 | i.append(interface_name); | ||
202 | i.append(property_name); | ||
203 | })); | ||
204 | try!(m.as_result()); | ||
205 | let mut i = m.iter_init(); | ||
206 | let value: arg::Variant<Box<arg::RefArg>> = try!(i.read()); | ||
207 | Ok(value) | ||
208 | } | ||
209 | |||
210 | fn set(&self, interface_name: &str, property_name: &str, value: arg::Variant<Box<arg::RefArg>>) -> Result<(), Self::Err> { | ||
211 | let mut m = try!(self.method_call_with_args(&"org.freedesktop.DBus.Properties".into(), &"Set".into(), |msg| { | ||
212 | let mut i = arg::IterAppend::new(msg); | ||
213 | i.append(interface_name); | ||
214 | i.append(property_name); | ||
215 | i.append(value); | ||
216 | })); | ||
217 | try!(m.as_result()); | ||
218 | Ok(()) | ||
219 | } | ||
220 | |||
221 | fn get_all(&self, interface_name: &str) -> Result<::std::collections::HashMap<String, arg::Variant<Box<arg::RefArg>>>, Self::Err> { | ||
222 | let mut m = try!(self.method_call_with_args(&"org.freedesktop.DBus.Properties".into(), &"GetAll".into(), |msg| { | ||
223 | let mut i = arg::IterAppend::new(msg); | ||
224 | i.append(interface_name); | ||
225 | })); | ||
226 | try!(m.as_result()); | ||
227 | let mut i = m.iter_init(); | ||
228 | let props: ::std::collections::HashMap<String, arg::Variant<Box<arg::RefArg>>> = try!(i.read()); | ||
229 | Ok(props) | ||
230 | } | ||
231 | } | ||
232 | |||
233 | pub fn org_freedesktop_dbus_properties_server<F, T, D>(factory: &tree::Factory<tree::MTFn<D>, D>, data: D::Interface, f: F) -> tree::Interface<tree::MTFn<D>, D> | ||
234 | where | ||
235 | D: tree::DataType, | ||
236 | D::Method: Default, | ||
237 | T: OrgFreedesktopDBusProperties<Err=tree::MethodErr>, | ||
238 | F: 'static + for <'z> Fn(& 'z tree::MethodInfo<tree::MTFn<D>, D>) -> & 'z T, | ||
239 | { | ||
240 | let i = factory.interface("org.freedesktop.DBus.Properties", data); | ||
241 | let f = ::std::sync::Arc::new(f); | ||
242 | let fclone = f.clone(); | ||
243 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
244 | let mut i = minfo.msg.iter_init(); | ||
245 | let interface_name: &str = try!(i.read()); | ||
246 | let property_name: &str = try!(i.read()); | ||
247 | let d = fclone(minfo); | ||
248 | let value = try!(d.get(interface_name, property_name)); | ||
249 | let rm = minfo.msg.method_return(); | ||
250 | let rm = rm.append1(value); | ||
251 | Ok(vec!(rm)) | ||
252 | }; | ||
253 | let m = factory.method("Get", Default::default(), h); | ||
254 | let m = m.in_arg(("interface_name", "s")); | ||
255 | let m = m.in_arg(("property_name", "s")); | ||
256 | let m = m.out_arg(("value", "v")); | ||
257 | let i = i.add_m(m); | ||
258 | |||
259 | let fclone = f.clone(); | ||
260 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
261 | let mut i = minfo.msg.iter_init(); | ||
262 | let interface_name: &str = try!(i.read()); | ||
263 | let property_name: &str = try!(i.read()); | ||
264 | let value: arg::Variant<Box<arg::RefArg>> = try!(i.read()); | ||
265 | let d = fclone(minfo); | ||
266 | try!(d.set(interface_name, property_name, value)); | ||
267 | let rm = minfo.msg.method_return(); | ||
268 | Ok(vec!(rm)) | ||
269 | }; | ||
270 | let m = factory.method("Set", Default::default(), h); | ||
271 | let m = m.in_arg(("interface_name", "s")); | ||
272 | let m = m.in_arg(("property_name", "s")); | ||
273 | let m = m.in_arg(("value", "v")); | ||
274 | let i = i.add_m(m); | ||
275 | |||
276 | let fclone = f.clone(); | ||
277 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
278 | let mut i = minfo.msg.iter_init(); | ||
279 | let interface_name: &str = try!(i.read()); | ||
280 | let d = fclone(minfo); | ||
281 | let props = try!(d.get_all(interface_name)); | ||
282 | let rm = minfo.msg.method_return(); | ||
283 | let rm = rm.append1(props); | ||
284 | Ok(vec!(rm)) | ||
285 | }; | ||
286 | let m = factory.method("GetAll", Default::default(), h); | ||
287 | let m = m.in_arg(("interface_name", "s")); | ||
288 | let m = m.out_arg(("props", "a{sv}")); | ||
289 | let i = i.add_m(m); | ||
290 | i | ||
291 | } | ||
diff --git a/src/dbus_api/mod.rs b/src/dbus_api/mod.rs new file mode 100644 index 0000000..a184c55 --- /dev/null +++ b/src/dbus_api/mod.rs | |||
@@ -0,0 +1,3 @@ | |||
1 | pub mod equalizing_manager; | ||
2 | pub mod server_lookup; | ||
3 | pub mod sink; | ||
diff --git a/src/dbus_api/server_lookup.rs b/src/dbus_api/server_lookup.rs new file mode 100644 index 0000000..78ad4bd --- /dev/null +++ b/src/dbus_api/server_lookup.rs | |||
@@ -0,0 +1,188 @@ | |||
1 | // This code was autogenerated with dbus-codegen-rust, see https://github.com/diwic/dbus-rs | ||
2 | |||
3 | #![allow(dead_code)] | ||
4 | use dbus as dbus; | ||
5 | use dbus::arg; | ||
6 | use dbus::tree; | ||
7 | |||
8 | pub trait OrgPulseAudioServerLookup1 { | ||
9 | type Err; | ||
10 | fn get_address(&self) -> Result<String, Self::Err>; | ||
11 | } | ||
12 | |||
13 | impl<'a, C: ::std::ops::Deref<Target=dbus::Connection>> OrgPulseAudioServerLookup1 for dbus::ConnPath<'a, C> { | ||
14 | type Err = dbus::Error; | ||
15 | |||
16 | fn get_address(&self) -> Result<String, Self::Err> { | ||
17 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.ServerLookup1", "Address") | ||
18 | } | ||
19 | } | ||
20 | |||
21 | pub fn org_pulse_audio_server_lookup1_server<F, T, D>(factory: &tree::Factory<tree::MTFn<D>, D>, data: D::Interface, f: F) -> tree::Interface<tree::MTFn<D>, D> | ||
22 | where | ||
23 | D: tree::DataType, | ||
24 | D::Method: Default, | ||
25 | D::Property: Default, | ||
26 | T: OrgPulseAudioServerLookup1<Err=tree::MethodErr>, | ||
27 | F: 'static + for <'z> Fn(& 'z tree::MethodInfo<tree::MTFn<D>, D>) -> & 'z T, | ||
28 | { | ||
29 | let i = factory.interface("org.PulseAudio.ServerLookup1", data); | ||
30 | let f = ::std::sync::Arc::new(f); | ||
31 | let p = factory.property::<&str, _>("Address", Default::default()); | ||
32 | let p = p.access(tree::Access::Read); | ||
33 | let fclone = f.clone(); | ||
34 | let p = p.on_get(move |a, pinfo| { | ||
35 | let minfo = pinfo.to_method_info(); | ||
36 | let d = fclone(&minfo); | ||
37 | a.append(try!(d.get_address())); | ||
38 | Ok(()) | ||
39 | }); | ||
40 | let i = i.add_p(p); | ||
41 | i | ||
42 | } | ||
43 | |||
44 | pub trait OrgFreedesktopDBusIntrospectable { | ||
45 | type Err; | ||
46 | fn introspect(&self) -> Result<String, Self::Err>; | ||
47 | } | ||
48 | |||
49 | impl<'a, C: ::std::ops::Deref<Target=dbus::Connection>> OrgFreedesktopDBusIntrospectable for dbus::ConnPath<'a, C> { | ||
50 | type Err = dbus::Error; | ||
51 | |||
52 | fn introspect(&self) -> Result<String, Self::Err> { | ||
53 | let mut m = try!(self.method_call_with_args(&"org.freedesktop.DBus.Introspectable".into(), &"Introspect".into(), |_| { | ||
54 | })); | ||
55 | try!(m.as_result()); | ||
56 | let mut i = m.iter_init(); | ||
57 | let data: String = try!(i.read()); | ||
58 | Ok(data) | ||
59 | } | ||
60 | } | ||
61 | |||
62 | pub fn org_freedesktop_dbus_introspectable_server<F, T, D>(factory: &tree::Factory<tree::MTFn<D>, D>, data: D::Interface, f: F) -> tree::Interface<tree::MTFn<D>, D> | ||
63 | where | ||
64 | D: tree::DataType, | ||
65 | D::Method: Default, | ||
66 | T: OrgFreedesktopDBusIntrospectable<Err=tree::MethodErr>, | ||
67 | F: 'static + for <'z> Fn(& 'z tree::MethodInfo<tree::MTFn<D>, D>) -> & 'z T, | ||
68 | { | ||
69 | let i = factory.interface("org.freedesktop.DBus.Introspectable", data); | ||
70 | let f = ::std::sync::Arc::new(f); | ||
71 | let fclone = f.clone(); | ||
72 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
73 | let d = fclone(minfo); | ||
74 | let data = try!(d.introspect()); | ||
75 | let rm = minfo.msg.method_return(); | ||
76 | let rm = rm.append1(data); | ||
77 | Ok(vec!(rm)) | ||
78 | }; | ||
79 | let m = factory.method("Introspect", Default::default(), h); | ||
80 | let m = m.out_arg(("data", "s")); | ||
81 | let i = i.add_m(m); | ||
82 | i | ||
83 | } | ||
84 | |||
85 | pub trait OrgFreedesktopDBusProperties { | ||
86 | type Err; | ||
87 | fn get(&self, interface_name: &str, property_name: &str) -> Result<arg::Variant<Box<arg::RefArg>>, Self::Err>; | ||
88 | fn set(&self, interface_name: &str, property_name: &str, value: arg::Variant<Box<arg::RefArg>>) -> Result<(), Self::Err>; | ||
89 | fn get_all(&self, interface_name: &str) -> Result<::std::collections::HashMap<String, arg::Variant<Box<arg::RefArg>>>, Self::Err>; | ||
90 | } | ||
91 | |||
92 | impl<'a, C: ::std::ops::Deref<Target=dbus::Connection>> OrgFreedesktopDBusProperties for dbus::ConnPath<'a, C> { | ||
93 | type Err = dbus::Error; | ||
94 | |||
95 | fn get(&self, interface_name: &str, property_name: &str) -> Result<arg::Variant<Box<arg::RefArg>>, Self::Err> { | ||
96 | let mut m = try!(self.method_call_with_args(&"org.freedesktop.DBus.Properties".into(), &"Get".into(), |msg| { | ||
97 | let mut i = arg::IterAppend::new(msg); | ||
98 | i.append(interface_name); | ||
99 | i.append(property_name); | ||
100 | })); | ||
101 | try!(m.as_result()); | ||
102 | let mut i = m.iter_init(); | ||
103 | let value: arg::Variant<Box<arg::RefArg>> = try!(i.read()); | ||
104 | Ok(value) | ||
105 | } | ||
106 | |||
107 | fn set(&self, interface_name: &str, property_name: &str, value: arg::Variant<Box<arg::RefArg>>) -> Result<(), Self::Err> { | ||
108 | let mut m = try!(self.method_call_with_args(&"org.freedesktop.DBus.Properties".into(), &"Set".into(), |msg| { | ||
109 | let mut i = arg::IterAppend::new(msg); | ||
110 | i.append(interface_name); | ||
111 | i.append(property_name); | ||
112 | i.append(value); | ||
113 | })); | ||
114 | try!(m.as_result()); | ||
115 | Ok(()) | ||
116 | } | ||
117 | |||
118 | fn get_all(&self, interface_name: &str) -> Result<::std::collections::HashMap<String, arg::Variant<Box<arg::RefArg>>>, Self::Err> { | ||
119 | let mut m = try!(self.method_call_with_args(&"org.freedesktop.DBus.Properties".into(), &"GetAll".into(), |msg| { | ||
120 | let mut i = arg::IterAppend::new(msg); | ||
121 | i.append(interface_name); | ||
122 | })); | ||
123 | try!(m.as_result()); | ||
124 | let mut i = m.iter_init(); | ||
125 | let props: ::std::collections::HashMap<String, arg::Variant<Box<arg::RefArg>>> = try!(i.read()); | ||
126 | Ok(props) | ||
127 | } | ||
128 | } | ||
129 | |||
130 | pub fn org_freedesktop_dbus_properties_server<F, T, D>(factory: &tree::Factory<tree::MTFn<D>, D>, data: D::Interface, f: F) -> tree::Interface<tree::MTFn<D>, D> | ||
131 | where | ||
132 | D: tree::DataType, | ||
133 | D::Method: Default, | ||
134 | T: OrgFreedesktopDBusProperties<Err=tree::MethodErr>, | ||
135 | F: 'static + for <'z> Fn(& 'z tree::MethodInfo<tree::MTFn<D>, D>) -> & 'z T, | ||
136 | { | ||
137 | let i = factory.interface("org.freedesktop.DBus.Properties", data); | ||
138 | let f = ::std::sync::Arc::new(f); | ||
139 | let fclone = f.clone(); | ||
140 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
141 | let mut i = minfo.msg.iter_init(); | ||
142 | let interface_name: &str = try!(i.read()); | ||
143 | let property_name: &str = try!(i.read()); | ||
144 | let d = fclone(minfo); | ||
145 | let value = try!(d.get(interface_name, property_name)); | ||
146 | let rm = minfo.msg.method_return(); | ||
147 | let rm = rm.append1(value); | ||
148 | Ok(vec!(rm)) | ||
149 | }; | ||
150 | let m = factory.method("Get", Default::default(), h); | ||
151 | let m = m.in_arg(("interface_name", "s")); | ||
152 | let m = m.in_arg(("property_name", "s")); | ||
153 | let m = m.out_arg(("value", "v")); | ||
154 | let i = i.add_m(m); | ||
155 | |||
156 | let fclone = f.clone(); | ||
157 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
158 | let mut i = minfo.msg.iter_init(); | ||
159 | let interface_name: &str = try!(i.read()); | ||
160 | let property_name: &str = try!(i.read()); | ||
161 | let value: arg::Variant<Box<arg::RefArg>> = try!(i.read()); | ||
162 | let d = fclone(minfo); | ||
163 | try!(d.set(interface_name, property_name, value)); | ||
164 | let rm = minfo.msg.method_return(); | ||
165 | Ok(vec!(rm)) | ||
166 | }; | ||
167 | let m = factory.method("Set", Default::default(), h); | ||
168 | let m = m.in_arg(("interface_name", "s")); | ||
169 | let m = m.in_arg(("property_name", "s")); | ||
170 | let m = m.in_arg(("value", "v")); | ||
171 | let i = i.add_m(m); | ||
172 | |||
173 | let fclone = f.clone(); | ||
174 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
175 | let mut i = minfo.msg.iter_init(); | ||
176 | let interface_name: &str = try!(i.read()); | ||
177 | let d = fclone(minfo); | ||
178 | let props = try!(d.get_all(interface_name)); | ||
179 | let rm = minfo.msg.method_return(); | ||
180 | let rm = rm.append1(props); | ||
181 | Ok(vec!(rm)) | ||
182 | }; | ||
183 | let m = factory.method("GetAll", Default::default(), h); | ||
184 | let m = m.in_arg(("interface_name", "s")); | ||
185 | let m = m.out_arg(("props", "a{sv}")); | ||
186 | let i = i.add_m(m); | ||
187 | i | ||
188 | } | ||
diff --git a/src/dbus_api/sink.rs b/src/dbus_api/sink.rs new file mode 100644 index 0000000..6bd1756 --- /dev/null +++ b/src/dbus_api/sink.rs | |||
@@ -0,0 +1,1128 @@ | |||
1 | // This code was autogenerated with dbus-codegen-rust, see https://github.com/diwic/dbus-rs | ||
2 | |||
3 | #![allow(dead_code)] | ||
4 | use dbus as dbus; | ||
5 | use dbus::arg; | ||
6 | use dbus::tree; | ||
7 | |||
8 | pub trait OrgPulseAudioExtEqualizing1Equalizer { | ||
9 | type Err; | ||
10 | fn filter_at_points(&self, channel: u32, xs: Vec<u32>) -> Result<(Vec<f64>, f64), Self::Err>; | ||
11 | fn seed_filter(&self, channel: u32, xs: Vec<u32>, ys: Vec<f64>, preamp: f64) -> Result<(), Self::Err>; | ||
12 | fn save_profile(&self, channel: u32, name: &str) -> Result<(), Self::Err>; | ||
13 | fn load_profile(&self, channel: u32, name: &str) -> Result<(), Self::Err>; | ||
14 | fn set_filter(&self, channel: u32, ys: Vec<f64>, preamp: f64) -> Result<(), Self::Err>; | ||
15 | fn get_filter(&self, channel: u32) -> Result<(Vec<f64>, f64), Self::Err>; | ||
16 | fn save_state(&self) -> Result<(), Self::Err>; | ||
17 | fn base_profile(&self, channel: u32) -> Result<String, Self::Err>; | ||
18 | fn get_interface_revision(&self) -> Result<u32, Self::Err>; | ||
19 | fn get_sample_rate(&self) -> Result<u32, Self::Err>; | ||
20 | fn get_filter_sample_rate(&self) -> Result<u32, Self::Err>; | ||
21 | fn get_nfilter_coefficients(&self) -> Result<u32, Self::Err>; | ||
22 | fn get_nchannels(&self) -> Result<u32, Self::Err>; | ||
23 | } | ||
24 | |||
25 | impl<'a, C: ::std::ops::Deref<Target=dbus::Connection>> OrgPulseAudioExtEqualizing1Equalizer for dbus::ConnPath<'a, C> { | ||
26 | type Err = dbus::Error; | ||
27 | |||
28 | fn filter_at_points(&self, channel: u32, xs: Vec<u32>) -> Result<(Vec<f64>, f64), Self::Err> { | ||
29 | let mut m = try!(self.method_call_with_args(&"org.PulseAudio.Ext.Equalizing1.Equalizer".into(), &"FilterAtPoints".into(), |msg| { | ||
30 | let mut i = arg::IterAppend::new(msg); | ||
31 | i.append(channel); | ||
32 | i.append(xs); | ||
33 | })); | ||
34 | try!(m.as_result()); | ||
35 | let mut i = m.iter_init(); | ||
36 | let ys: Vec<f64> = try!(i.read()); | ||
37 | let preamp: f64 = try!(i.read()); | ||
38 | Ok((ys, preamp)) | ||
39 | } | ||
40 | |||
41 | fn seed_filter(&self, channel: u32, xs: Vec<u32>, ys: Vec<f64>, preamp: f64) -> Result<(), Self::Err> { | ||
42 | let mut m = try!(self.method_call_with_args(&"org.PulseAudio.Ext.Equalizing1.Equalizer".into(), &"SeedFilter".into(), |msg| { | ||
43 | let mut i = arg::IterAppend::new(msg); | ||
44 | i.append(channel); | ||
45 | i.append(xs); | ||
46 | i.append(ys); | ||
47 | i.append(preamp); | ||
48 | })); | ||
49 | try!(m.as_result()); | ||
50 | Ok(()) | ||
51 | } | ||
52 | |||
53 | fn save_profile(&self, channel: u32, name: &str) -> Result<(), Self::Err> { | ||
54 | let mut m = try!(self.method_call_with_args(&"org.PulseAudio.Ext.Equalizing1.Equalizer".into(), &"SaveProfile".into(), |msg| { | ||
55 | let mut i = arg::IterAppend::new(msg); | ||
56 | i.append(channel); | ||
57 | i.append(name); | ||
58 | })); | ||
59 | try!(m.as_result()); | ||
60 | Ok(()) | ||
61 | } | ||
62 | |||
63 | fn load_profile(&self, channel: u32, name: &str) -> Result<(), Self::Err> { | ||
64 | let mut m = try!(self.method_call_with_args(&"org.PulseAudio.Ext.Equalizing1.Equalizer".into(), &"LoadProfile".into(), |msg| { | ||
65 | let mut i = arg::IterAppend::new(msg); | ||
66 | i.append(channel); | ||
67 | i.append(name); | ||
68 | })); | ||
69 | try!(m.as_result()); | ||
70 | Ok(()) | ||
71 | } | ||
72 | |||
73 | fn set_filter(&self, channel: u32, ys: Vec<f64>, preamp: f64) -> Result<(), Self::Err> { | ||
74 | let mut m = try!(self.method_call_with_args(&"org.PulseAudio.Ext.Equalizing1.Equalizer".into(), &"SetFilter".into(), |msg| { | ||
75 | let mut i = arg::IterAppend::new(msg); | ||
76 | i.append(channel); | ||
77 | i.append(ys); | ||
78 | i.append(preamp); | ||
79 | })); | ||
80 | try!(m.as_result()); | ||
81 | Ok(()) | ||
82 | } | ||
83 | |||
84 | fn get_filter(&self, channel: u32) -> Result<(Vec<f64>, f64), Self::Err> { | ||
85 | let mut m = try!(self.method_call_with_args(&"org.PulseAudio.Ext.Equalizing1.Equalizer".into(), &"GetFilter".into(), |msg| { | ||
86 | let mut i = arg::IterAppend::new(msg); | ||
87 | i.append(channel); | ||
88 | })); | ||
89 | try!(m.as_result()); | ||
90 | let mut i = m.iter_init(); | ||
91 | let ys: Vec<f64> = try!(i.read()); | ||
92 | let preamp: f64 = try!(i.read()); | ||
93 | Ok((ys, preamp)) | ||
94 | } | ||
95 | |||
96 | fn save_state(&self) -> Result<(), Self::Err> { | ||
97 | let mut m = try!(self.method_call_with_args(&"org.PulseAudio.Ext.Equalizing1.Equalizer".into(), &"SaveState".into(), |_| { | ||
98 | })); | ||
99 | try!(m.as_result()); | ||
100 | Ok(()) | ||
101 | } | ||
102 | |||
103 | fn base_profile(&self, channel: u32) -> Result<String, Self::Err> { | ||
104 | let mut m = try!(self.method_call_with_args(&"org.PulseAudio.Ext.Equalizing1.Equalizer".into(), &"BaseProfile".into(), |msg| { | ||
105 | let mut i = arg::IterAppend::new(msg); | ||
106 | i.append(channel); | ||
107 | })); | ||
108 | try!(m.as_result()); | ||
109 | let mut i = m.iter_init(); | ||
110 | let name: String = try!(i.read()); | ||
111 | Ok(name) | ||
112 | } | ||
113 | |||
114 | fn get_interface_revision(&self) -> Result<u32, Self::Err> { | ||
115 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Ext.Equalizing1.Equalizer", "InterfaceRevision") | ||
116 | } | ||
117 | |||
118 | fn get_sample_rate(&self) -> Result<u32, Self::Err> { | ||
119 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Ext.Equalizing1.Equalizer", "SampleRate") | ||
120 | } | ||
121 | |||
122 | fn get_filter_sample_rate(&self) -> Result<u32, Self::Err> { | ||
123 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Ext.Equalizing1.Equalizer", "FilterSampleRate") | ||
124 | } | ||
125 | |||
126 | fn get_nfilter_coefficients(&self) -> Result<u32, Self::Err> { | ||
127 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Ext.Equalizing1.Equalizer", "NFilterCoefficients") | ||
128 | } | ||
129 | |||
130 | fn get_nchannels(&self) -> Result<u32, Self::Err> { | ||
131 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Ext.Equalizing1.Equalizer", "NChannels") | ||
132 | } | ||
133 | } | ||
134 | |||
135 | pub fn org_pulse_audio_ext_equalizing1_equalizer_server<F, T, D>(factory: &tree::Factory<tree::MTFn<D>, D>, data: D::Interface, f: F) -> tree::Interface<tree::MTFn<D>, D> | ||
136 | where | ||
137 | D: tree::DataType, | ||
138 | D::Method: Default, | ||
139 | D::Property: Default, | ||
140 | T: OrgPulseAudioExtEqualizing1Equalizer<Err=tree::MethodErr>, | ||
141 | F: 'static + for <'z> Fn(& 'z tree::MethodInfo<tree::MTFn<D>, D>) -> & 'z T, | ||
142 | { | ||
143 | let i = factory.interface("org.PulseAudio.Ext.Equalizing1.Equalizer", data); | ||
144 | let f = ::std::sync::Arc::new(f); | ||
145 | let fclone = f.clone(); | ||
146 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
147 | let mut i = minfo.msg.iter_init(); | ||
148 | let channel: u32 = try!(i.read()); | ||
149 | let xs: Vec<u32> = try!(i.read()); | ||
150 | let d = fclone(minfo); | ||
151 | let (ys, preamp) = try!(d.filter_at_points(channel, xs)); | ||
152 | let rm = minfo.msg.method_return(); | ||
153 | let rm = rm.append1(ys); | ||
154 | let rm = rm.append1(preamp); | ||
155 | Ok(vec!(rm)) | ||
156 | }; | ||
157 | let m = factory.method("FilterAtPoints", Default::default(), h); | ||
158 | let m = m.in_arg(("channel", "u")); | ||
159 | let m = m.in_arg(("xs", "au")); | ||
160 | let m = m.out_arg(("ys", "ad")); | ||
161 | let m = m.out_arg(("preamp", "d")); | ||
162 | let i = i.add_m(m); | ||
163 | |||
164 | let fclone = f.clone(); | ||
165 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
166 | let mut i = minfo.msg.iter_init(); | ||
167 | let channel: u32 = try!(i.read()); | ||
168 | let xs: Vec<u32> = try!(i.read()); | ||
169 | let ys: Vec<f64> = try!(i.read()); | ||
170 | let preamp: f64 = try!(i.read()); | ||
171 | let d = fclone(minfo); | ||
172 | try!(d.seed_filter(channel, xs, ys, preamp)); | ||
173 | let rm = minfo.msg.method_return(); | ||
174 | Ok(vec!(rm)) | ||
175 | }; | ||
176 | let m = factory.method("SeedFilter", Default::default(), h); | ||
177 | let m = m.in_arg(("channel", "u")); | ||
178 | let m = m.in_arg(("xs", "au")); | ||
179 | let m = m.in_arg(("ys", "ad")); | ||
180 | let m = m.in_arg(("preamp", "d")); | ||
181 | let i = i.add_m(m); | ||
182 | |||
183 | let fclone = f.clone(); | ||
184 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
185 | let mut i = minfo.msg.iter_init(); | ||
186 | let channel: u32 = try!(i.read()); | ||
187 | let name: &str = try!(i.read()); | ||
188 | let d = fclone(minfo); | ||
189 | try!(d.save_profile(channel, name)); | ||
190 | let rm = minfo.msg.method_return(); | ||
191 | Ok(vec!(rm)) | ||
192 | }; | ||
193 | let m = factory.method("SaveProfile", Default::default(), h); | ||
194 | let m = m.in_arg(("channel", "u")); | ||
195 | let m = m.in_arg(("name", "s")); | ||
196 | let i = i.add_m(m); | ||
197 | |||
198 | let fclone = f.clone(); | ||
199 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
200 | let mut i = minfo.msg.iter_init(); | ||
201 | let channel: u32 = try!(i.read()); | ||
202 | let name: &str = try!(i.read()); | ||
203 | let d = fclone(minfo); | ||
204 | try!(d.load_profile(channel, name)); | ||
205 | let rm = minfo.msg.method_return(); | ||
206 | Ok(vec!(rm)) | ||
207 | }; | ||
208 | let m = factory.method("LoadProfile", Default::default(), h); | ||
209 | let m = m.in_arg(("channel", "u")); | ||
210 | let m = m.in_arg(("name", "s")); | ||
211 | let i = i.add_m(m); | ||
212 | |||
213 | let fclone = f.clone(); | ||
214 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
215 | let mut i = minfo.msg.iter_init(); | ||
216 | let channel: u32 = try!(i.read()); | ||
217 | let ys: Vec<f64> = try!(i.read()); | ||
218 | let preamp: f64 = try!(i.read()); | ||
219 | let d = fclone(minfo); | ||
220 | try!(d.set_filter(channel, ys, preamp)); | ||
221 | let rm = minfo.msg.method_return(); | ||
222 | Ok(vec!(rm)) | ||
223 | }; | ||
224 | let m = factory.method("SetFilter", Default::default(), h); | ||
225 | let m = m.in_arg(("channel", "u")); | ||
226 | let m = m.in_arg(("ys", "ad")); | ||
227 | let m = m.in_arg(("preamp", "d")); | ||
228 | let i = i.add_m(m); | ||
229 | |||
230 | let fclone = f.clone(); | ||
231 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
232 | let mut i = minfo.msg.iter_init(); | ||
233 | let channel: u32 = try!(i.read()); | ||
234 | let d = fclone(minfo); | ||
235 | let (ys, preamp) = try!(d.get_filter(channel)); | ||
236 | let rm = minfo.msg.method_return(); | ||
237 | let rm = rm.append1(ys); | ||
238 | let rm = rm.append1(preamp); | ||
239 | Ok(vec!(rm)) | ||
240 | }; | ||
241 | let m = factory.method("GetFilter", Default::default(), h); | ||
242 | let m = m.in_arg(("channel", "u")); | ||
243 | let m = m.out_arg(("ys", "ad")); | ||
244 | let m = m.out_arg(("preamp", "d")); | ||
245 | let i = i.add_m(m); | ||
246 | |||
247 | let fclone = f.clone(); | ||
248 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
249 | let d = fclone(minfo); | ||
250 | try!(d.save_state()); | ||
251 | let rm = minfo.msg.method_return(); | ||
252 | Ok(vec!(rm)) | ||
253 | }; | ||
254 | let m = factory.method("SaveState", Default::default(), h); | ||
255 | let i = i.add_m(m); | ||
256 | |||
257 | let fclone = f.clone(); | ||
258 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
259 | let mut i = minfo.msg.iter_init(); | ||
260 | let channel: u32 = try!(i.read()); | ||
261 | let d = fclone(minfo); | ||
262 | let name = try!(d.base_profile(channel)); | ||
263 | let rm = minfo.msg.method_return(); | ||
264 | let rm = rm.append1(name); | ||
265 | Ok(vec!(rm)) | ||
266 | }; | ||
267 | let m = factory.method("BaseProfile", Default::default(), h); | ||
268 | let m = m.in_arg(("channel", "u")); | ||
269 | let m = m.out_arg(("name", "s")); | ||
270 | let i = i.add_m(m); | ||
271 | |||
272 | let p = factory.property::<u32, _>("InterfaceRevision", Default::default()); | ||
273 | let p = p.access(tree::Access::Read); | ||
274 | let fclone = f.clone(); | ||
275 | let p = p.on_get(move |a, pinfo| { | ||
276 | let minfo = pinfo.to_method_info(); | ||
277 | let d = fclone(&minfo); | ||
278 | a.append(try!(d.get_interface_revision())); | ||
279 | Ok(()) | ||
280 | }); | ||
281 | let i = i.add_p(p); | ||
282 | |||
283 | let p = factory.property::<u32, _>("SampleRate", Default::default()); | ||
284 | let p = p.access(tree::Access::Read); | ||
285 | let fclone = f.clone(); | ||
286 | let p = p.on_get(move |a, pinfo| { | ||
287 | let minfo = pinfo.to_method_info(); | ||
288 | let d = fclone(&minfo); | ||
289 | a.append(try!(d.get_sample_rate())); | ||
290 | Ok(()) | ||
291 | }); | ||
292 | let i = i.add_p(p); | ||
293 | |||
294 | let p = factory.property::<u32, _>("FilterSampleRate", Default::default()); | ||
295 | let p = p.access(tree::Access::Read); | ||
296 | let fclone = f.clone(); | ||
297 | let p = p.on_get(move |a, pinfo| { | ||
298 | let minfo = pinfo.to_method_info(); | ||
299 | let d = fclone(&minfo); | ||
300 | a.append(try!(d.get_filter_sample_rate())); | ||
301 | Ok(()) | ||
302 | }); | ||
303 | let i = i.add_p(p); | ||
304 | |||
305 | let p = factory.property::<u32, _>("NFilterCoefficients", Default::default()); | ||
306 | let p = p.access(tree::Access::Read); | ||
307 | let fclone = f.clone(); | ||
308 | let p = p.on_get(move |a, pinfo| { | ||
309 | let minfo = pinfo.to_method_info(); | ||
310 | let d = fclone(&minfo); | ||
311 | a.append(try!(d.get_nfilter_coefficients())); | ||
312 | Ok(()) | ||
313 | }); | ||
314 | let i = i.add_p(p); | ||
315 | |||
316 | let p = factory.property::<u32, _>("NChannels", Default::default()); | ||
317 | let p = p.access(tree::Access::Read); | ||
318 | let fclone = f.clone(); | ||
319 | let p = p.on_get(move |a, pinfo| { | ||
320 | let minfo = pinfo.to_method_info(); | ||
321 | let d = fclone(&minfo); | ||
322 | a.append(try!(d.get_nchannels())); | ||
323 | Ok(()) | ||
324 | }); | ||
325 | let i = i.add_p(p); | ||
326 | i | ||
327 | } | ||
328 | |||
329 | #[derive(Debug, Default)] | ||
330 | pub struct OrgPulseAudioExtEqualizing1EqualizerFilterChanged { | ||
331 | } | ||
332 | |||
333 | impl dbus::SignalArgs for OrgPulseAudioExtEqualizing1EqualizerFilterChanged { | ||
334 | const NAME: &'static str = "FilterChanged"; | ||
335 | const INTERFACE: &'static str = "org.PulseAudio.Ext.Equalizing1.Equalizer"; | ||
336 | fn append(&self, _: &mut arg::IterAppend) { | ||
337 | } | ||
338 | fn get(&mut self, _: &mut arg::Iter) -> Result<(), arg::TypeMismatchError> { | ||
339 | Ok(()) | ||
340 | } | ||
341 | } | ||
342 | |||
343 | #[derive(Debug, Default)] | ||
344 | pub struct OrgPulseAudioExtEqualizing1EqualizerSinkReconfigured { | ||
345 | } | ||
346 | |||
347 | impl dbus::SignalArgs for OrgPulseAudioExtEqualizing1EqualizerSinkReconfigured { | ||
348 | const NAME: &'static str = "SinkReconfigured"; | ||
349 | const INTERFACE: &'static str = "org.PulseAudio.Ext.Equalizing1.Equalizer"; | ||
350 | fn append(&self, _: &mut arg::IterAppend) { | ||
351 | } | ||
352 | fn get(&mut self, _: &mut arg::Iter) -> Result<(), arg::TypeMismatchError> { | ||
353 | Ok(()) | ||
354 | } | ||
355 | } | ||
356 | |||
357 | pub trait OrgPulseAudioCore1Device { | ||
358 | type Err; | ||
359 | fn suspend(&self, suspend: bool) -> Result<(), Self::Err>; | ||
360 | fn get_port_by_name(&self, name: &str) -> Result<dbus::Path<'static>, Self::Err>; | ||
361 | fn get_index(&self) -> Result<u32, Self::Err>; | ||
362 | fn get_name(&self) -> Result<String, Self::Err>; | ||
363 | fn get_driver(&self) -> Result<String, Self::Err>; | ||
364 | fn get_owner_module(&self) -> Result<dbus::Path<'static>, Self::Err>; | ||
365 | fn get_card(&self) -> Result<dbus::Path<'static>, Self::Err>; | ||
366 | fn get_sample_format(&self) -> Result<u32, Self::Err>; | ||
367 | fn get_sample_rate(&self) -> Result<u32, Self::Err>; | ||
368 | fn get_channels(&self) -> Result<Vec<u32>, Self::Err>; | ||
369 | fn get_volume(&self) -> Result<Vec<u32>, Self::Err>; | ||
370 | fn set_volume(&self, value: Vec<u32>) -> Result<(), Self::Err>; | ||
371 | fn get_has_flat_volume(&self) -> Result<bool, Self::Err>; | ||
372 | fn get_has_convertible_to_decibel_volume(&self) -> Result<bool, Self::Err>; | ||
373 | fn get_base_volume(&self) -> Result<u32, Self::Err>; | ||
374 | fn get_volume_steps(&self) -> Result<u32, Self::Err>; | ||
375 | fn get_mute(&self) -> Result<bool, Self::Err>; | ||
376 | fn set_mute(&self, value: bool) -> Result<(), Self::Err>; | ||
377 | fn get_has_hardware_volume(&self) -> Result<bool, Self::Err>; | ||
378 | fn get_has_hardware_mute(&self) -> Result<bool, Self::Err>; | ||
379 | fn get_configured_latency(&self) -> Result<u64, Self::Err>; | ||
380 | fn get_has_dynamic_latency(&self) -> Result<bool, Self::Err>; | ||
381 | fn get_latency(&self) -> Result<u64, Self::Err>; | ||
382 | fn get_is_hardware_device(&self) -> Result<bool, Self::Err>; | ||
383 | fn get_is_network_device(&self) -> Result<bool, Self::Err>; | ||
384 | fn get_state(&self) -> Result<u32, Self::Err>; | ||
385 | fn get_ports(&self) -> Result<Vec<dbus::Path<'static>>, Self::Err>; | ||
386 | fn get_active_port(&self) -> Result<dbus::Path<'static>, Self::Err>; | ||
387 | fn set_active_port(&self, value: dbus::Path<'static>) -> Result<(), Self::Err>; | ||
388 | fn get_property_list(&self) -> Result<::std::collections::HashMap<String, Vec<u8>>, Self::Err>; | ||
389 | } | ||
390 | |||
391 | impl<'a, C: ::std::ops::Deref<Target=dbus::Connection>> OrgPulseAudioCore1Device for dbus::ConnPath<'a, C> { | ||
392 | type Err = dbus::Error; | ||
393 | |||
394 | fn suspend(&self, suspend: bool) -> Result<(), Self::Err> { | ||
395 | let mut m = try!(self.method_call_with_args(&"org.PulseAudio.Core1.Device".into(), &"Suspend".into(), |msg| { | ||
396 | let mut i = arg::IterAppend::new(msg); | ||
397 | i.append(suspend); | ||
398 | })); | ||
399 | try!(m.as_result()); | ||
400 | Ok(()) | ||
401 | } | ||
402 | |||
403 | fn get_port_by_name(&self, name: &str) -> Result<dbus::Path<'static>, Self::Err> { | ||
404 | let mut m = try!(self.method_call_with_args(&"org.PulseAudio.Core1.Device".into(), &"GetPortByName".into(), |msg| { | ||
405 | let mut i = arg::IterAppend::new(msg); | ||
406 | i.append(name); | ||
407 | })); | ||
408 | try!(m.as_result()); | ||
409 | let mut i = m.iter_init(); | ||
410 | let port: dbus::Path<'static> = try!(i.read()); | ||
411 | Ok(port) | ||
412 | } | ||
413 | |||
414 | fn get_index(&self) -> Result<u32, Self::Err> { | ||
415 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "Index") | ||
416 | } | ||
417 | |||
418 | fn get_name(&self) -> Result<String, Self::Err> { | ||
419 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "Name") | ||
420 | } | ||
421 | |||
422 | fn get_driver(&self) -> Result<String, Self::Err> { | ||
423 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "Driver") | ||
424 | } | ||
425 | |||
426 | fn get_owner_module(&self) -> Result<dbus::Path<'static>, Self::Err> { | ||
427 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "OwnerModule") | ||
428 | } | ||
429 | |||
430 | fn get_card(&self) -> Result<dbus::Path<'static>, Self::Err> { | ||
431 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "Card") | ||
432 | } | ||
433 | |||
434 | fn get_sample_format(&self) -> Result<u32, Self::Err> { | ||
435 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "SampleFormat") | ||
436 | } | ||
437 | |||
438 | fn get_sample_rate(&self) -> Result<u32, Self::Err> { | ||
439 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "SampleRate") | ||
440 | } | ||
441 | |||
442 | fn get_channels(&self) -> Result<Vec<u32>, Self::Err> { | ||
443 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "Channels") | ||
444 | } | ||
445 | |||
446 | fn get_volume(&self) -> Result<Vec<u32>, Self::Err> { | ||
447 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "Volume") | ||
448 | } | ||
449 | |||
450 | fn get_has_flat_volume(&self) -> Result<bool, Self::Err> { | ||
451 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "HasFlatVolume") | ||
452 | } | ||
453 | |||
454 | fn get_has_convertible_to_decibel_volume(&self) -> Result<bool, Self::Err> { | ||
455 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "HasConvertibleToDecibelVolume") | ||
456 | } | ||
457 | |||
458 | fn get_base_volume(&self) -> Result<u32, Self::Err> { | ||
459 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "BaseVolume") | ||
460 | } | ||
461 | |||
462 | fn get_volume_steps(&self) -> Result<u32, Self::Err> { | ||
463 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "VolumeSteps") | ||
464 | } | ||
465 | |||
466 | fn get_mute(&self) -> Result<bool, Self::Err> { | ||
467 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "Mute") | ||
468 | } | ||
469 | |||
470 | fn get_has_hardware_volume(&self) -> Result<bool, Self::Err> { | ||
471 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "HasHardwareVolume") | ||
472 | } | ||
473 | |||
474 | fn get_has_hardware_mute(&self) -> Result<bool, Self::Err> { | ||
475 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "HasHardwareMute") | ||
476 | } | ||
477 | |||
478 | fn get_configured_latency(&self) -> Result<u64, Self::Err> { | ||
479 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "ConfiguredLatency") | ||
480 | } | ||
481 | |||
482 | fn get_has_dynamic_latency(&self) -> Result<bool, Self::Err> { | ||
483 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "HasDynamicLatency") | ||
484 | } | ||
485 | |||
486 | fn get_latency(&self) -> Result<u64, Self::Err> { | ||
487 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "Latency") | ||
488 | } | ||
489 | |||
490 | fn get_is_hardware_device(&self) -> Result<bool, Self::Err> { | ||
491 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "IsHardwareDevice") | ||
492 | } | ||
493 | |||
494 | fn get_is_network_device(&self) -> Result<bool, Self::Err> { | ||
495 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "IsNetworkDevice") | ||
496 | } | ||
497 | |||
498 | fn get_state(&self) -> Result<u32, Self::Err> { | ||
499 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "State") | ||
500 | } | ||
501 | |||
502 | fn get_ports(&self) -> Result<Vec<dbus::Path<'static>>, Self::Err> { | ||
503 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "Ports") | ||
504 | } | ||
505 | |||
506 | fn get_active_port(&self) -> Result<dbus::Path<'static>, Self::Err> { | ||
507 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "ActivePort") | ||
508 | } | ||
509 | |||
510 | fn get_property_list(&self) -> Result<::std::collections::HashMap<String, Vec<u8>>, Self::Err> { | ||
511 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Device", "PropertyList") | ||
512 | } | ||
513 | |||
514 | fn set_volume(&self, value: Vec<u32>) -> Result<(), Self::Err> { | ||
515 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::set(&self, "org.PulseAudio.Core1.Device", "Volume", value) | ||
516 | } | ||
517 | |||
518 | fn set_mute(&self, value: bool) -> Result<(), Self::Err> { | ||
519 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::set(&self, "org.PulseAudio.Core1.Device", "Mute", value) | ||
520 | } | ||
521 | |||
522 | fn set_active_port(&self, value: dbus::Path<'static>) -> Result<(), Self::Err> { | ||
523 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::set(&self, "org.PulseAudio.Core1.Device", "ActivePort", value) | ||
524 | } | ||
525 | } | ||
526 | |||
527 | pub fn org_pulse_audio_core1_device_server<F, T, D>(factory: &tree::Factory<tree::MTFn<D>, D>, data: D::Interface, f: F) -> tree::Interface<tree::MTFn<D>, D> | ||
528 | where | ||
529 | D: tree::DataType, | ||
530 | D::Method: Default, | ||
531 | D::Property: Default, | ||
532 | T: OrgPulseAudioCore1Device<Err=tree::MethodErr>, | ||
533 | F: 'static + for <'z> Fn(& 'z tree::MethodInfo<tree::MTFn<D>, D>) -> & 'z T, | ||
534 | { | ||
535 | let i = factory.interface("org.PulseAudio.Core1.Device", data); | ||
536 | let f = ::std::sync::Arc::new(f); | ||
537 | let fclone = f.clone(); | ||
538 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
539 | let mut i = minfo.msg.iter_init(); | ||
540 | let suspend: bool = try!(i.read()); | ||
541 | let d = fclone(minfo); | ||
542 | try!(d.suspend(suspend)); | ||
543 | let rm = minfo.msg.method_return(); | ||
544 | Ok(vec!(rm)) | ||
545 | }; | ||
546 | let m = factory.method("Suspend", Default::default(), h); | ||
547 | let m = m.in_arg(("suspend", "b")); | ||
548 | let i = i.add_m(m); | ||
549 | |||
550 | let fclone = f.clone(); | ||
551 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
552 | let mut i = minfo.msg.iter_init(); | ||
553 | let name: &str = try!(i.read()); | ||
554 | let d = fclone(minfo); | ||
555 | let port = try!(d.get_port_by_name(name)); | ||
556 | let rm = minfo.msg.method_return(); | ||
557 | let rm = rm.append1(port); | ||
558 | Ok(vec!(rm)) | ||
559 | }; | ||
560 | let m = factory.method("GetPortByName", Default::default(), h); | ||
561 | let m = m.in_arg(("name", "s")); | ||
562 | let m = m.out_arg(("port", "o")); | ||
563 | let i = i.add_m(m); | ||
564 | |||
565 | let p = factory.property::<u32, _>("Index", Default::default()); | ||
566 | let p = p.access(tree::Access::Read); | ||
567 | let fclone = f.clone(); | ||
568 | let p = p.on_get(move |a, pinfo| { | ||
569 | let minfo = pinfo.to_method_info(); | ||
570 | let d = fclone(&minfo); | ||
571 | a.append(try!(d.get_index())); | ||
572 | Ok(()) | ||
573 | }); | ||
574 | let i = i.add_p(p); | ||
575 | |||
576 | let p = factory.property::<&str, _>("Name", Default::default()); | ||
577 | let p = p.access(tree::Access::Read); | ||
578 | let fclone = f.clone(); | ||
579 | let p = p.on_get(move |a, pinfo| { | ||
580 | let minfo = pinfo.to_method_info(); | ||
581 | let d = fclone(&minfo); | ||
582 | a.append(try!(d.get_name())); | ||
583 | Ok(()) | ||
584 | }); | ||
585 | let i = i.add_p(p); | ||
586 | |||
587 | let p = factory.property::<&str, _>("Driver", Default::default()); | ||
588 | let p = p.access(tree::Access::Read); | ||
589 | let fclone = f.clone(); | ||
590 | let p = p.on_get(move |a, pinfo| { | ||
591 | let minfo = pinfo.to_method_info(); | ||
592 | let d = fclone(&minfo); | ||
593 | a.append(try!(d.get_driver())); | ||
594 | Ok(()) | ||
595 | }); | ||
596 | let i = i.add_p(p); | ||
597 | |||
598 | let p = factory.property::<dbus::Path, _>("OwnerModule", Default::default()); | ||
599 | let p = p.access(tree::Access::Read); | ||
600 | let fclone = f.clone(); | ||
601 | let p = p.on_get(move |a, pinfo| { | ||
602 | let minfo = pinfo.to_method_info(); | ||
603 | let d = fclone(&minfo); | ||
604 | a.append(try!(d.get_owner_module())); | ||
605 | Ok(()) | ||
606 | }); | ||
607 | let i = i.add_p(p); | ||
608 | |||
609 | let p = factory.property::<dbus::Path, _>("Card", Default::default()); | ||
610 | let p = p.access(tree::Access::Read); | ||
611 | let fclone = f.clone(); | ||
612 | let p = p.on_get(move |a, pinfo| { | ||
613 | let minfo = pinfo.to_method_info(); | ||
614 | let d = fclone(&minfo); | ||
615 | a.append(try!(d.get_card())); | ||
616 | Ok(()) | ||
617 | }); | ||
618 | let i = i.add_p(p); | ||
619 | |||
620 | let p = factory.property::<u32, _>("SampleFormat", Default::default()); | ||
621 | let p = p.access(tree::Access::Read); | ||
622 | let fclone = f.clone(); | ||
623 | let p = p.on_get(move |a, pinfo| { | ||
624 | let minfo = pinfo.to_method_info(); | ||
625 | let d = fclone(&minfo); | ||
626 | a.append(try!(d.get_sample_format())); | ||
627 | Ok(()) | ||
628 | }); | ||
629 | let i = i.add_p(p); | ||
630 | |||
631 | let p = factory.property::<u32, _>("SampleRate", Default::default()); | ||
632 | let p = p.access(tree::Access::Read); | ||
633 | let fclone = f.clone(); | ||
634 | let p = p.on_get(move |a, pinfo| { | ||
635 | let minfo = pinfo.to_method_info(); | ||
636 | let d = fclone(&minfo); | ||
637 | a.append(try!(d.get_sample_rate())); | ||
638 | Ok(()) | ||
639 | }); | ||
640 | let i = i.add_p(p); | ||
641 | |||
642 | let p = factory.property::<Vec<u32>, _>("Channels", Default::default()); | ||
643 | let p = p.access(tree::Access::Read); | ||
644 | let fclone = f.clone(); | ||
645 | let p = p.on_get(move |a, pinfo| { | ||
646 | let minfo = pinfo.to_method_info(); | ||
647 | let d = fclone(&minfo); | ||
648 | a.append(try!(d.get_channels())); | ||
649 | Ok(()) | ||
650 | }); | ||
651 | let i = i.add_p(p); | ||
652 | |||
653 | let p = factory.property::<Vec<u32>, _>("Volume", Default::default()); | ||
654 | let p = p.access(tree::Access::ReadWrite); | ||
655 | let fclone = f.clone(); | ||
656 | let p = p.on_get(move |a, pinfo| { | ||
657 | let minfo = pinfo.to_method_info(); | ||
658 | let d = fclone(&minfo); | ||
659 | a.append(try!(d.get_volume())); | ||
660 | Ok(()) | ||
661 | }); | ||
662 | let fclone = f.clone(); | ||
663 | let p = p.on_set(move |iter, pinfo| { | ||
664 | let minfo = pinfo.to_method_info(); | ||
665 | let d = fclone(&minfo); | ||
666 | try!(d.set_volume(try!(iter.read()))); | ||
667 | Ok(()) | ||
668 | }); | ||
669 | let i = i.add_p(p); | ||
670 | |||
671 | let p = factory.property::<bool, _>("HasFlatVolume", Default::default()); | ||
672 | let p = p.access(tree::Access::Read); | ||
673 | let fclone = f.clone(); | ||
674 | let p = p.on_get(move |a, pinfo| { | ||
675 | let minfo = pinfo.to_method_info(); | ||
676 | let d = fclone(&minfo); | ||
677 | a.append(try!(d.get_has_flat_volume())); | ||
678 | Ok(()) | ||
679 | }); | ||
680 | let i = i.add_p(p); | ||
681 | |||
682 | let p = factory.property::<bool, _>("HasConvertibleToDecibelVolume", Default::default()); | ||
683 | let p = p.access(tree::Access::Read); | ||
684 | let fclone = f.clone(); | ||
685 | let p = p.on_get(move |a, pinfo| { | ||
686 | let minfo = pinfo.to_method_info(); | ||
687 | let d = fclone(&minfo); | ||
688 | a.append(try!(d.get_has_convertible_to_decibel_volume())); | ||
689 | Ok(()) | ||
690 | }); | ||
691 | let i = i.add_p(p); | ||
692 | |||
693 | let p = factory.property::<u32, _>("BaseVolume", Default::default()); | ||
694 | let p = p.access(tree::Access::Read); | ||
695 | let fclone = f.clone(); | ||
696 | let p = p.on_get(move |a, pinfo| { | ||
697 | let minfo = pinfo.to_method_info(); | ||
698 | let d = fclone(&minfo); | ||
699 | a.append(try!(d.get_base_volume())); | ||
700 | Ok(()) | ||
701 | }); | ||
702 | let i = i.add_p(p); | ||
703 | |||
704 | let p = factory.property::<u32, _>("VolumeSteps", Default::default()); | ||
705 | let p = p.access(tree::Access::Read); | ||
706 | let fclone = f.clone(); | ||
707 | let p = p.on_get(move |a, pinfo| { | ||
708 | let minfo = pinfo.to_method_info(); | ||
709 | let d = fclone(&minfo); | ||
710 | a.append(try!(d.get_volume_steps())); | ||
711 | Ok(()) | ||
712 | }); | ||
713 | let i = i.add_p(p); | ||
714 | |||
715 | let p = factory.property::<bool, _>("Mute", Default::default()); | ||
716 | let p = p.access(tree::Access::ReadWrite); | ||
717 | let fclone = f.clone(); | ||
718 | let p = p.on_get(move |a, pinfo| { | ||
719 | let minfo = pinfo.to_method_info(); | ||
720 | let d = fclone(&minfo); | ||
721 | a.append(try!(d.get_mute())); | ||
722 | Ok(()) | ||
723 | }); | ||
724 | let fclone = f.clone(); | ||
725 | let p = p.on_set(move |iter, pinfo| { | ||
726 | let minfo = pinfo.to_method_info(); | ||
727 | let d = fclone(&minfo); | ||
728 | try!(d.set_mute(try!(iter.read()))); | ||
729 | Ok(()) | ||
730 | }); | ||
731 | let i = i.add_p(p); | ||
732 | |||
733 | let p = factory.property::<bool, _>("HasHardwareVolume", Default::default()); | ||
734 | let p = p.access(tree::Access::Read); | ||
735 | let fclone = f.clone(); | ||
736 | let p = p.on_get(move |a, pinfo| { | ||
737 | let minfo = pinfo.to_method_info(); | ||
738 | let d = fclone(&minfo); | ||
739 | a.append(try!(d.get_has_hardware_volume())); | ||
740 | Ok(()) | ||
741 | }); | ||
742 | let i = i.add_p(p); | ||
743 | |||
744 | let p = factory.property::<bool, _>("HasHardwareMute", Default::default()); | ||
745 | let p = p.access(tree::Access::Read); | ||
746 | let fclone = f.clone(); | ||
747 | let p = p.on_get(move |a, pinfo| { | ||
748 | let minfo = pinfo.to_method_info(); | ||
749 | let d = fclone(&minfo); | ||
750 | a.append(try!(d.get_has_hardware_mute())); | ||
751 | Ok(()) | ||
752 | }); | ||
753 | let i = i.add_p(p); | ||
754 | |||
755 | let p = factory.property::<u64, _>("ConfiguredLatency", Default::default()); | ||
756 | let p = p.access(tree::Access::Read); | ||
757 | let fclone = f.clone(); | ||
758 | let p = p.on_get(move |a, pinfo| { | ||
759 | let minfo = pinfo.to_method_info(); | ||
760 | let d = fclone(&minfo); | ||
761 | a.append(try!(d.get_configured_latency())); | ||
762 | Ok(()) | ||
763 | }); | ||
764 | let i = i.add_p(p); | ||
765 | |||
766 | let p = factory.property::<bool, _>("HasDynamicLatency", Default::default()); | ||
767 | let p = p.access(tree::Access::Read); | ||
768 | let fclone = f.clone(); | ||
769 | let p = p.on_get(move |a, pinfo| { | ||
770 | let minfo = pinfo.to_method_info(); | ||
771 | let d = fclone(&minfo); | ||
772 | a.append(try!(d.get_has_dynamic_latency())); | ||
773 | Ok(()) | ||
774 | }); | ||
775 | let i = i.add_p(p); | ||
776 | |||
777 | let p = factory.property::<u64, _>("Latency", Default::default()); | ||
778 | let p = p.access(tree::Access::Read); | ||
779 | let fclone = f.clone(); | ||
780 | let p = p.on_get(move |a, pinfo| { | ||
781 | let minfo = pinfo.to_method_info(); | ||
782 | let d = fclone(&minfo); | ||
783 | a.append(try!(d.get_latency())); | ||
784 | Ok(()) | ||
785 | }); | ||
786 | let i = i.add_p(p); | ||
787 | |||
788 | let p = factory.property::<bool, _>("IsHardwareDevice", Default::default()); | ||
789 | let p = p.access(tree::Access::Read); | ||
790 | let fclone = f.clone(); | ||
791 | let p = p.on_get(move |a, pinfo| { | ||
792 | let minfo = pinfo.to_method_info(); | ||
793 | let d = fclone(&minfo); | ||
794 | a.append(try!(d.get_is_hardware_device())); | ||
795 | Ok(()) | ||
796 | }); | ||
797 | let i = i.add_p(p); | ||
798 | |||
799 | let p = factory.property::<bool, _>("IsNetworkDevice", Default::default()); | ||
800 | let p = p.access(tree::Access::Read); | ||
801 | let fclone = f.clone(); | ||
802 | let p = p.on_get(move |a, pinfo| { | ||
803 | let minfo = pinfo.to_method_info(); | ||
804 | let d = fclone(&minfo); | ||
805 | a.append(try!(d.get_is_network_device())); | ||
806 | Ok(()) | ||
807 | }); | ||
808 | let i = i.add_p(p); | ||
809 | |||
810 | let p = factory.property::<u32, _>("State", Default::default()); | ||
811 | let p = p.access(tree::Access::Read); | ||
812 | let fclone = f.clone(); | ||
813 | let p = p.on_get(move |a, pinfo| { | ||
814 | let minfo = pinfo.to_method_info(); | ||
815 | let d = fclone(&minfo); | ||
816 | a.append(try!(d.get_state())); | ||
817 | Ok(()) | ||
818 | }); | ||
819 | let i = i.add_p(p); | ||
820 | |||
821 | let p = factory.property::<Vec<dbus::Path>, _>("Ports", Default::default()); | ||
822 | let p = p.access(tree::Access::Read); | ||
823 | let fclone = f.clone(); | ||
824 | let p = p.on_get(move |a, pinfo| { | ||
825 | let minfo = pinfo.to_method_info(); | ||
826 | let d = fclone(&minfo); | ||
827 | a.append(try!(d.get_ports())); | ||
828 | Ok(()) | ||
829 | }); | ||
830 | let i = i.add_p(p); | ||
831 | |||
832 | let p = factory.property::<dbus::Path, _>("ActivePort", Default::default()); | ||
833 | let p = p.access(tree::Access::ReadWrite); | ||
834 | let fclone = f.clone(); | ||
835 | let p = p.on_get(move |a, pinfo| { | ||
836 | let minfo = pinfo.to_method_info(); | ||
837 | let d = fclone(&minfo); | ||
838 | a.append(try!(d.get_active_port())); | ||
839 | Ok(()) | ||
840 | }); | ||
841 | let fclone = f.clone(); | ||
842 | let p = p.on_set(move |iter, pinfo| { | ||
843 | let minfo = pinfo.to_method_info(); | ||
844 | let d = fclone(&minfo); | ||
845 | try!(d.set_active_port(try!(iter.read()))); | ||
846 | Ok(()) | ||
847 | }); | ||
848 | let i = i.add_p(p); | ||
849 | |||
850 | let p = factory.property::<::std::collections::HashMap<&str, Vec<u8>>, _>("PropertyList", Default::default()); | ||
851 | let p = p.access(tree::Access::Read); | ||
852 | let fclone = f.clone(); | ||
853 | let p = p.on_get(move |a, pinfo| { | ||
854 | let minfo = pinfo.to_method_info(); | ||
855 | let d = fclone(&minfo); | ||
856 | a.append(try!(d.get_property_list())); | ||
857 | Ok(()) | ||
858 | }); | ||
859 | let i = i.add_p(p); | ||
860 | i | ||
861 | } | ||
862 | |||
863 | #[derive(Debug, Default)] | ||
864 | pub struct OrgPulseAudioCore1DeviceVolumeUpdated { | ||
865 | pub volume: Vec<u32>, | ||
866 | } | ||
867 | |||
868 | impl dbus::SignalArgs for OrgPulseAudioCore1DeviceVolumeUpdated { | ||
869 | const NAME: &'static str = "VolumeUpdated"; | ||
870 | const INTERFACE: &'static str = "org.PulseAudio.Core1.Device"; | ||
871 | fn append(&self, i: &mut arg::IterAppend) { | ||
872 | (&self.volume as &arg::RefArg).append(i); | ||
873 | } | ||
874 | fn get(&mut self, i: &mut arg::Iter) -> Result<(), arg::TypeMismatchError> { | ||
875 | self.volume = try!(i.read()); | ||
876 | Ok(()) | ||
877 | } | ||
878 | } | ||
879 | |||
880 | #[derive(Debug, Default)] | ||
881 | pub struct OrgPulseAudioCore1DeviceMuteUpdated { | ||
882 | pub muted: bool, | ||
883 | } | ||
884 | |||
885 | impl dbus::SignalArgs for OrgPulseAudioCore1DeviceMuteUpdated { | ||
886 | const NAME: &'static str = "MuteUpdated"; | ||
887 | const INTERFACE: &'static str = "org.PulseAudio.Core1.Device"; | ||
888 | fn append(&self, i: &mut arg::IterAppend) { | ||
889 | (&self.muted as &arg::RefArg).append(i); | ||
890 | } | ||
891 | fn get(&mut self, i: &mut arg::Iter) -> Result<(), arg::TypeMismatchError> { | ||
892 | self.muted = try!(i.read()); | ||
893 | Ok(()) | ||
894 | } | ||
895 | } | ||
896 | |||
897 | #[derive(Debug, Default)] | ||
898 | pub struct OrgPulseAudioCore1DeviceStateUpdated { | ||
899 | pub state: u32, | ||
900 | } | ||
901 | |||
902 | impl dbus::SignalArgs for OrgPulseAudioCore1DeviceStateUpdated { | ||
903 | const NAME: &'static str = "StateUpdated"; | ||
904 | const INTERFACE: &'static str = "org.PulseAudio.Core1.Device"; | ||
905 | fn append(&self, i: &mut arg::IterAppend) { | ||
906 | (&self.state as &arg::RefArg).append(i); | ||
907 | } | ||
908 | fn get(&mut self, i: &mut arg::Iter) -> Result<(), arg::TypeMismatchError> { | ||
909 | self.state = try!(i.read()); | ||
910 | Ok(()) | ||
911 | } | ||
912 | } | ||
913 | |||
914 | #[derive(Debug, Default)] | ||
915 | pub struct OrgPulseAudioCore1DeviceActivePortUpdated { | ||
916 | pub port: dbus::Path<'static>, | ||
917 | } | ||
918 | |||
919 | impl dbus::SignalArgs for OrgPulseAudioCore1DeviceActivePortUpdated { | ||
920 | const NAME: &'static str = "ActivePortUpdated"; | ||
921 | const INTERFACE: &'static str = "org.PulseAudio.Core1.Device"; | ||
922 | fn append(&self, i: &mut arg::IterAppend) { | ||
923 | (&self.port as &arg::RefArg).append(i); | ||
924 | } | ||
925 | fn get(&mut self, i: &mut arg::Iter) -> Result<(), arg::TypeMismatchError> { | ||
926 | self.port = try!(i.read()); | ||
927 | Ok(()) | ||
928 | } | ||
929 | } | ||
930 | |||
931 | #[derive(Debug, Default)] | ||
932 | pub struct OrgPulseAudioCore1DevicePropertyListUpdated { | ||
933 | pub property_list: ::std::collections::HashMap<String, Vec<u8>>, | ||
934 | } | ||
935 | |||
936 | impl dbus::SignalArgs for OrgPulseAudioCore1DevicePropertyListUpdated { | ||
937 | const NAME: &'static str = "PropertyListUpdated"; | ||
938 | const INTERFACE: &'static str = "org.PulseAudio.Core1.Device"; | ||
939 | fn append(&self, i: &mut arg::IterAppend) { | ||
940 | (&self.property_list as &arg::RefArg).append(i); | ||
941 | } | ||
942 | fn get(&mut self, i: &mut arg::Iter) -> Result<(), arg::TypeMismatchError> { | ||
943 | self.property_list = try!(i.read()); | ||
944 | Ok(()) | ||
945 | } | ||
946 | } | ||
947 | |||
948 | pub trait OrgPulseAudioCore1Sink { | ||
949 | type Err; | ||
950 | fn get_monitor_source(&self) -> Result<dbus::Path<'static>, Self::Err>; | ||
951 | } | ||
952 | |||
953 | impl<'a, C: ::std::ops::Deref<Target=dbus::Connection>> OrgPulseAudioCore1Sink for dbus::ConnPath<'a, C> { | ||
954 | type Err = dbus::Error; | ||
955 | |||
956 | fn get_monitor_source(&self) -> Result<dbus::Path<'static>, Self::Err> { | ||
957 | <Self as dbus::stdintf::org_freedesktop_dbus::Properties>::get(&self, "org.PulseAudio.Core1.Sink", "MonitorSource") | ||
958 | } | ||
959 | } | ||
960 | |||
961 | pub fn org_pulse_audio_core1_sink_server<F, T, D>(factory: &tree::Factory<tree::MTFn<D>, D>, data: D::Interface, f: F) -> tree::Interface<tree::MTFn<D>, D> | ||
962 | where | ||
963 | D: tree::DataType, | ||
964 | D::Method: Default, | ||
965 | D::Property: Default, | ||
966 | T: OrgPulseAudioCore1Sink<Err=tree::MethodErr>, | ||
967 | F: 'static + for <'z> Fn(& 'z tree::MethodInfo<tree::MTFn<D>, D>) -> & 'z T, | ||
968 | { | ||
969 | let i = factory.interface("org.PulseAudio.Core1.Sink", data); | ||
970 | let f = ::std::sync::Arc::new(f); | ||
971 | let p = factory.property::<dbus::Path, _>("MonitorSource", Default::default()); | ||
972 | let p = p.access(tree::Access::Read); | ||
973 | let fclone = f.clone(); | ||
974 | let p = p.on_get(move |a, pinfo| { | ||
975 | let minfo = pinfo.to_method_info(); | ||
976 | let d = fclone(&minfo); | ||
977 | a.append(try!(d.get_monitor_source())); | ||
978 | Ok(()) | ||
979 | }); | ||
980 | let i = i.add_p(p); | ||
981 | i | ||
982 | } | ||
983 | |||
984 | pub trait OrgFreedesktopDBusIntrospectable { | ||
985 | type Err; | ||
986 | fn introspect(&self) -> Result<String, Self::Err>; | ||
987 | } | ||
988 | |||
989 | impl<'a, C: ::std::ops::Deref<Target=dbus::Connection>> OrgFreedesktopDBusIntrospectable for dbus::ConnPath<'a, C> { | ||
990 | type Err = dbus::Error; | ||
991 | |||
992 | fn introspect(&self) -> Result<String, Self::Err> { | ||
993 | let mut m = try!(self.method_call_with_args(&"org.freedesktop.DBus.Introspectable".into(), &"Introspect".into(), |_| { | ||
994 | })); | ||
995 | try!(m.as_result()); | ||
996 | let mut i = m.iter_init(); | ||
997 | let data: String = try!(i.read()); | ||
998 | Ok(data) | ||
999 | } | ||
1000 | } | ||
1001 | |||
1002 | pub fn org_freedesktop_dbus_introspectable_server<F, T, D>(factory: &tree::Factory<tree::MTFn<D>, D>, data: D::Interface, f: F) -> tree::Interface<tree::MTFn<D>, D> | ||
1003 | where | ||
1004 | D: tree::DataType, | ||
1005 | D::Method: Default, | ||
1006 | T: OrgFreedesktopDBusIntrospectable<Err=tree::MethodErr>, | ||
1007 | F: 'static + for <'z> Fn(& 'z tree::MethodInfo<tree::MTFn<D>, D>) -> & 'z T, | ||
1008 | { | ||
1009 | let i = factory.interface("org.freedesktop.DBus.Introspectable", data); | ||
1010 | let f = ::std::sync::Arc::new(f); | ||
1011 | let fclone = f.clone(); | ||
1012 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
1013 | let d = fclone(minfo); | ||
1014 | let data = try!(d.introspect()); | ||
1015 | let rm = minfo.msg.method_return(); | ||
1016 | let rm = rm.append1(data); | ||
1017 | Ok(vec!(rm)) | ||
1018 | }; | ||
1019 | let m = factory.method("Introspect", Default::default(), h); | ||
1020 | let m = m.out_arg(("data", "s")); | ||
1021 | let i = i.add_m(m); | ||
1022 | i | ||
1023 | } | ||
1024 | |||
1025 | pub trait OrgFreedesktopDBusProperties { | ||
1026 | type Err; | ||
1027 | fn get(&self, interface_name: &str, property_name: &str) -> Result<arg::Variant<Box<arg::RefArg>>, Self::Err>; | ||
1028 | fn set(&self, interface_name: &str, property_name: &str, value: arg::Variant<Box<arg::RefArg>>) -> Result<(), Self::Err>; | ||
1029 | fn get_all(&self, interface_name: &str) -> Result<::std::collections::HashMap<String, arg::Variant<Box<arg::RefArg>>>, Self::Err>; | ||
1030 | } | ||
1031 | |||
1032 | impl<'a, C: ::std::ops::Deref<Target=dbus::Connection>> OrgFreedesktopDBusProperties for dbus::ConnPath<'a, C> { | ||
1033 | type Err = dbus::Error; | ||
1034 | |||
1035 | fn get(&self, interface_name: &str, property_name: &str) -> Result<arg::Variant<Box<arg::RefArg>>, Self::Err> { | ||
1036 | let mut m = try!(self.method_call_with_args(&"org.freedesktop.DBus.Properties".into(), &"Get".into(), |msg| { | ||
1037 | let mut i = arg::IterAppend::new(msg); | ||
1038 | i.append(interface_name); | ||
1039 | i.append(property_name); | ||
1040 | })); | ||
1041 | try!(m.as_result()); | ||
1042 | let mut i = m.iter_init(); | ||
1043 | let value: arg::Variant<Box<arg::RefArg>> = try!(i.read()); | ||
1044 | Ok(value) | ||
1045 | } | ||
1046 | |||
1047 | fn set(&self, interface_name: &str, property_name: &str, value: arg::Variant<Box<arg::RefArg>>) -> Result<(), Self::Err> { | ||
1048 | let mut m = try!(self.method_call_with_args(&"org.freedesktop.DBus.Properties".into(), &"Set".into(), |msg| { | ||
1049 | let mut i = arg::IterAppend::new(msg); | ||
1050 | i.append(interface_name); | ||
1051 | i.append(property_name); | ||
1052 | i.append(value); | ||
1053 | })); | ||
1054 | try!(m.as_result()); | ||
1055 | Ok(()) | ||
1056 | } | ||
1057 | |||
1058 | fn get_all(&self, interface_name: &str) -> Result<::std::collections::HashMap<String, arg::Variant<Box<arg::RefArg>>>, Self::Err> { | ||
1059 | let mut m = try!(self.method_call_with_args(&"org.freedesktop.DBus.Properties".into(), &"GetAll".into(), |msg| { | ||
1060 | let mut i = arg::IterAppend::new(msg); | ||
1061 | i.append(interface_name); | ||
1062 | })); | ||
1063 | try!(m.as_result()); | ||
1064 | let mut i = m.iter_init(); | ||
1065 | let props: ::std::collections::HashMap<String, arg::Variant<Box<arg::RefArg>>> = try!(i.read()); | ||
1066 | Ok(props) | ||
1067 | } | ||
1068 | } | ||
1069 | |||
1070 | pub fn org_freedesktop_dbus_properties_server<F, T, D>(factory: &tree::Factory<tree::MTFn<D>, D>, data: D::Interface, f: F) -> tree::Interface<tree::MTFn<D>, D> | ||
1071 | where | ||
1072 | D: tree::DataType, | ||
1073 | D::Method: Default, | ||
1074 | T: OrgFreedesktopDBusProperties<Err=tree::MethodErr>, | ||
1075 | F: 'static + for <'z> Fn(& 'z tree::MethodInfo<tree::MTFn<D>, D>) -> & 'z T, | ||
1076 | { | ||
1077 | let i = factory.interface("org.freedesktop.DBus.Properties", data); | ||
1078 | let f = ::std::sync::Arc::new(f); | ||
1079 | let fclone = f.clone(); | ||
1080 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
1081 | let mut i = minfo.msg.iter_init(); | ||
1082 | let interface_name: &str = try!(i.read()); | ||
1083 | let property_name: &str = try!(i.read()); | ||
1084 | let d = fclone(minfo); | ||
1085 | let value = try!(d.get(interface_name, property_name)); | ||
1086 | let rm = minfo.msg.method_return(); | ||
1087 | let rm = rm.append1(value); | ||
1088 | Ok(vec!(rm)) | ||
1089 | }; | ||
1090 | let m = factory.method("Get", Default::default(), h); | ||
1091 | let m = m.in_arg(("interface_name", "s")); | ||
1092 | let m = m.in_arg(("property_name", "s")); | ||
1093 | let m = m.out_arg(("value", "v")); | ||
1094 | let i = i.add_m(m); | ||
1095 | |||
1096 | let fclone = f.clone(); | ||
1097 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
1098 | let mut i = minfo.msg.iter_init(); | ||
1099 | let interface_name: &str = try!(i.read()); | ||
1100 | let property_name: &str = try!(i.read()); | ||
1101 | let value: arg::Variant<Box<arg::RefArg>> = try!(i.read()); | ||
1102 | let d = fclone(minfo); | ||
1103 | try!(d.set(interface_name, property_name, value)); | ||
1104 | let rm = minfo.msg.method_return(); | ||
1105 | Ok(vec!(rm)) | ||
1106 | }; | ||
1107 | let m = factory.method("Set", Default::default(), h); | ||
1108 | let m = m.in_arg(("interface_name", "s")); | ||
1109 | let m = m.in_arg(("property_name", "s")); | ||
1110 | let m = m.in_arg(("value", "v")); | ||
1111 | let i = i.add_m(m); | ||
1112 | |||
1113 | let fclone = f.clone(); | ||
1114 | let h = move |minfo: &tree::MethodInfo<tree::MTFn<D>, D>| { | ||
1115 | let mut i = minfo.msg.iter_init(); | ||
1116 | let interface_name: &str = try!(i.read()); | ||
1117 | let d = fclone(minfo); | ||
1118 | let props = try!(d.get_all(interface_name)); | ||
1119 | let rm = minfo.msg.method_return(); | ||
1120 | let rm = rm.append1(props); | ||
1121 | Ok(vec!(rm)) | ||
1122 | }; | ||
1123 | let m = factory.method("GetAll", Default::default(), h); | ||
1124 | let m = m.in_arg(("interface_name", "s")); | ||
1125 | let m = m.out_arg(("props", "a{sv}")); | ||
1126 | let i = i.add_m(m); | ||
1127 | i | ||
1128 | } | ||
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..10c9434 --- /dev/null +++ b/src/main.rs | |||
@@ -0,0 +1,132 @@ | |||
1 | extern crate dbus; | ||
2 | |||
3 | #[macro_use] | ||
4 | extern crate log; | ||
5 | #[macro_use] | ||
6 | extern crate failure; | ||
7 | |||
8 | extern crate clap; | ||
9 | extern crate clap_log_flag; | ||
10 | extern crate clap_verbosity_flag; | ||
11 | extern crate structopt; | ||
12 | |||
13 | use structopt::StructOpt; | ||
14 | |||
15 | use failure::Error; | ||
16 | |||
17 | //use dbus::stdintf::org_freedesktop_dbus::Properties; | ||
18 | use dbus::Connection; | ||
19 | |||
20 | use dbus_api::sink::OrgPulseAudioExtEqualizing1Equalizer; | ||
21 | |||
22 | mod dbus_api; | ||
23 | mod parsing; | ||
24 | mod utils; | ||
25 | |||
26 | use utils::*; | ||
27 | |||
28 | #[derive(StructOpt, Debug)] | ||
29 | enum Command { | ||
30 | #[structopt(name = "load")] | ||
31 | Load(LoadCli), | ||
32 | #[structopt(name = "reset")] | ||
33 | Reset(ResetCli), | ||
34 | } | ||
35 | |||
36 | #[derive(StructOpt, Debug)] | ||
37 | struct LoadCli { | ||
38 | } | ||
39 | |||
40 | #[derive(StructOpt, Debug)] | ||
41 | struct ResetCli { | ||
42 | } | ||
43 | |||
44 | #[derive(StructOpt, Debug)] | ||
45 | struct Cli { | ||
46 | #[structopt(flatten)] | ||
47 | verbose: clap_verbosity_flag::Verbosity, | ||
48 | #[structopt(flatten)] | ||
49 | log: clap_log_flag::Log, | ||
50 | #[structopt(subcommand)] | ||
51 | cmd: Command, | ||
52 | } | ||
53 | |||
54 | #[derive(Fail, Debug)] | ||
55 | #[fail(display = "No equalized sink found")] | ||
56 | struct NoEqualizedSink; | ||
57 | |||
58 | #[derive(Debug)] | ||
59 | pub struct Filter { | ||
60 | preamp: f64, | ||
61 | frequencies: Vec<u32>, | ||
62 | coefficients: Vec<f64>, | ||
63 | } | ||
64 | |||
65 | impl Filter { | ||
66 | fn pad(self, filter_rate: u32) -> Self { | ||
67 | Filter { | ||
68 | preamp: self.preamp, | ||
69 | frequencies: vec![0u32] | ||
70 | .into_iter() | ||
71 | .chain(self.frequencies.into_iter()) | ||
72 | .chain(vec![filter_rate / 2u32]) | ||
73 | .collect(), | ||
74 | coefficients: vec![1f64] | ||
75 | .into_iter() | ||
76 | .chain(self.coefficients.into_iter()) | ||
77 | .chain(vec![1f64]) | ||
78 | .collect(), | ||
79 | } | ||
80 | } | ||
81 | } | ||
82 | |||
83 | fn main() -> Result<(), Error> { | ||
84 | let args = Cli::from_args(); | ||
85 | args.log.log_all(args.verbose.log_level())?; | ||
86 | |||
87 | use Command::*; | ||
88 | |||
89 | match args.cmd { | ||
90 | Load(args) => load(args), | ||
91 | Reset(args)=> reset(args), | ||
92 | } | ||
93 | } | ||
94 | |||
95 | fn reset(args: ResetCli) -> Result<(), Error> { | ||
96 | let conn = connect()?; | ||
97 | let conn_sink = get_equalized_sink(&conn)?; | ||
98 | let filter_rate = conn_sink.get_filter_sample_rate()?; | ||
99 | let filter = Filter { | ||
100 | preamp: 1f64, | ||
101 | frequencies: vec![], | ||
102 | coefficients: vec![], | ||
103 | }.pad(filter_rate); | ||
104 | |||
105 | send_filter(&conn_sink, filter)?; | ||
106 | |||
107 | Ok(()) | ||
108 | } | ||
109 | |||
110 | fn load(args: LoadCli) -> Result<(), Error> { | ||
111 | let conn = connect()?; | ||
112 | let conn_sink = get_equalized_sink(&conn)?; | ||
113 | let filter = read_filter()?; | ||
114 | let filter_rate = conn_sink.get_filter_sample_rate()?; | ||
115 | send_filter(&conn_sink, filter.pad(filter_rate))?; | ||
116 | |||
117 | Ok(()) | ||
118 | } | ||
119 | |||
120 | /* | ||
121 | fn introspect(conn: &dbus::ConnPath<&Connection>) { | ||
122 | let mut thing = conn | ||
123 | .method_call_with_args( | ||
124 | &"org.freedesktop.DBus.Introspectable".into(), | ||
125 | &"Introspect".into(), | ||
126 | |_| {}, | ||
127 | ).unwrap(); | ||
128 | thing.as_result().unwrap(); | ||
129 | |||
130 | println!("{}", thing.iter_init().read::<String>().unwrap()); | ||
131 | } | ||
132 | */ | ||
diff --git a/src/parsing/equalizer_apo.lalrpop b/src/parsing/equalizer_apo.lalrpop new file mode 100644 index 0000000..b1faad9 --- /dev/null +++ b/src/parsing/equalizer_apo.lalrpop | |||
@@ -0,0 +1,42 @@ | |||
1 | use ::Filter; | ||
2 | |||
3 | use std::str::FromStr; | ||
4 | |||
5 | grammar; | ||
6 | |||
7 | pub Main: Filter = { | ||
8 | <preamp: Preamp> <eq: Eq> => { | ||
9 | let coefficients: Vec<_> = eq.1.iter().map(|decibel| 10f64.powf(decibel / 10f64)).collect(); | ||
10 | // TODO: add decibel_to_ratio conversion function | ||
11 | let preamp = 10f64.powf(preamp / 10f64); | ||
12 | Filter { preamp, frequencies: eq.0, coefficients } | ||
13 | } | ||
14 | } | ||
15 | |||
16 | Preamp: f64 = { | ||
17 | "Preamp:" <Decibel> | ||
18 | } | ||
19 | |||
20 | Eq: (Vec<u32>, Vec<f64>) = { | ||
21 | "GraphicEQ:" <values:(<(Integer Float)> ";")+> <end:(Integer Float)> => { | ||
22 | let mut values = values; | ||
23 | values.push(end); | ||
24 | values.into_iter().unzip() | ||
25 | } | ||
26 | } | ||
27 | |||
28 | Decibel: f64 = { | ||
29 | <Float> "dB" | ||
30 | } | ||
31 | |||
32 | Float: f64 = { | ||
33 | <RawFloat>, | ||
34 | <SignedInteger> => <> as f64, | ||
35 | <Integer> => <> as f64, | ||
36 | } | ||
37 | |||
38 | RawFloat: f64 = r"-?[0-9]*\.[0-9]+" => f64::from_str(<>).unwrap(); | ||
39 | SignedInteger: i32 = r"-[0-9]+" => i32::from_str(<>).unwrap(); | ||
40 | Integer: u32 = r"[0-9]+"=> u32::from_str(<>).unwrap(); | ||
41 | |||
42 | // vim: ft=rust | ||
diff --git a/src/parsing/equalizer_apo.rs b/src/parsing/equalizer_apo.rs new file mode 100644 index 0000000..3fab396 --- /dev/null +++ b/src/parsing/equalizer_apo.rs | |||
@@ -0,0 +1,1164 @@ | |||
1 | // auto-generated: "lalrpop 0.15.2" | ||
2 | // sha256: 81b6fa5856d7887b20715c2c7f6137db1927ece087e2db9f4bf1fcd8943365c5 | ||
3 | use ::Filter; | ||
4 | use std::str::FromStr; | ||
5 | #[allow(unused_extern_crates)] | ||
6 | extern crate lalrpop_util as __lalrpop_util; | ||
7 | |||
8 | #[cfg_attr(rustfmt, rustfmt_skip)] | ||
9 | mod __parse__Main { | ||
10 | #![allow(non_snake_case, non_camel_case_types, unused_mut, unused_variables, unused_imports, unused_parens)] | ||
11 | |||
12 | use ::Filter; | ||
13 | use std::str::FromStr; | ||
14 | #[allow(unused_extern_crates)] | ||
15 | extern crate lalrpop_util as __lalrpop_util; | ||
16 | use super::__intern_token::Token; | ||
17 | #[allow(dead_code)] | ||
18 | pub enum __Symbol<'input> | ||
19 | { | ||
20 | Variant0(&'input str), | ||
21 | Variant1((u32, f64)), | ||
22 | Variant2(::std::vec::Vec<(u32, f64)>), | ||
23 | Variant3(f64), | ||
24 | Variant4((Vec<u32>, Vec<f64>)), | ||
25 | Variant5(u32), | ||
26 | Variant6(Filter), | ||
27 | Variant7(i32), | ||
28 | } | ||
29 | const __ACTION: &'static [i8] = &[ | ||
30 | // State 0 | ||
31 | 0, 0, 4, 0, 0, 0, 0, | ||
32 | // State 1 | ||
33 | 0, 0, 0, 0, 0, 0, 0, | ||
34 | // State 2 | ||
35 | 0, 6, 0, 0, 0, 0, 0, | ||
36 | // State 3 | ||
37 | 0, 0, 0, 0, 12, 13, 14, | ||
38 | // State 4 | ||
39 | 0, 0, 0, 0, 0, 0, 0, | ||
40 | // State 5 | ||
41 | 0, 0, 0, 0, 0, 0, 14, | ||
42 | // State 6 | ||
43 | 0, -12, 0, 0, 0, 0, 0, | ||
44 | // State 7 | ||
45 | 0, 0, 0, 17, 0, 0, 0, | ||
46 | // State 8 | ||
47 | -9, 0, 0, -9, 0, 0, 0, | ||
48 | // State 9 | ||
49 | -7, 0, 0, -7, 0, 0, 0, | ||
50 | // State 10 | ||
51 | -8, 0, 0, -8, 0, 0, 0, | ||
52 | // State 11 | ||
53 | -13, 0, 0, -13, 0, 0, 0, | ||
54 | // State 12 | ||
55 | -14, 0, 0, -14, 0, 0, 0, | ||
56 | // State 13 | ||
57 | -10, 0, 0, -10, -10, -10, -10, | ||
58 | // State 14 | ||
59 | 0, 0, 0, 0, 0, 0, 14, | ||
60 | // State 15 | ||
61 | 0, 0, 0, 0, 12, 13, 14, | ||
62 | // State 16 | ||
63 | 0, -5, 0, 0, 0, 0, 0, | ||
64 | // State 17 | ||
65 | 0, 0, 0, 0, 12, 13, 14, | ||
66 | // State 18 | ||
67 | 21, 0, 0, 0, 0, 0, 0, | ||
68 | // State 19 | ||
69 | 22, 0, 0, 0, 0, 0, 0, | ||
70 | // State 20 | ||
71 | 0, 0, 0, 0, 0, 0, -2, | ||
72 | // State 21 | ||
73 | 0, 0, 0, 0, 0, 0, -3, | ||
74 | ]; | ||
75 | const __EOF_ACTION: &'static [i8] = &[ | ||
76 | // State 0 | ||
77 | 0, | ||
78 | // State 1 | ||
79 | -15, | ||
80 | // State 2 | ||
81 | 0, | ||
82 | // State 3 | ||
83 | 0, | ||
84 | // State 4 | ||
85 | -11, | ||
86 | // State 5 | ||
87 | 0, | ||
88 | // State 6 | ||
89 | 0, | ||
90 | // State 7 | ||
91 | 0, | ||
92 | // State 8 | ||
93 | -9, | ||
94 | // State 9 | ||
95 | -7, | ||
96 | // State 10 | ||
97 | -8, | ||
98 | // State 11 | ||
99 | -13, | ||
100 | // State 12 | ||
101 | -14, | ||
102 | // State 13 | ||
103 | -10, | ||
104 | // State 14 | ||
105 | 0, | ||
106 | // State 15 | ||
107 | 0, | ||
108 | // State 16 | ||
109 | 0, | ||
110 | // State 17 | ||
111 | 0, | ||
112 | // State 18 | ||
113 | 0, | ||
114 | // State 19 | ||
115 | -6, | ||
116 | // State 20 | ||
117 | 0, | ||
118 | // State 21 | ||
119 | 0, | ||
120 | ]; | ||
121 | const __GOTO: &'static [i8] = &[ | ||
122 | // State 0 | ||
123 | 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, | ||
124 | // State 1 | ||
125 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
126 | // State 2 | ||
127 | 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, | ||
128 | // State 3 | ||
129 | 0, 0, 0, 7, 0, 8, 9, 0, 0, 10, 11, 0, | ||
130 | // State 4 | ||
131 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
132 | // State 5 | ||
133 | 0, 15, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, | ||
134 | // State 6 | ||
135 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
136 | // State 7 | ||
137 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
138 | // State 8 | ||
139 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
140 | // State 9 | ||
141 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
142 | // State 10 | ||
143 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
144 | // State 11 | ||
145 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
146 | // State 12 | ||
147 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
148 | // State 13 | ||
149 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
150 | // State 14 | ||
151 | 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, | ||
152 | // State 15 | ||
153 | 0, 0, 0, 0, 0, 19, 9, 0, 0, 10, 11, 0, | ||
154 | // State 16 | ||
155 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
156 | // State 17 | ||
157 | 0, 0, 0, 0, 0, 20, 9, 0, 0, 10, 11, 0, | ||
158 | // State 18 | ||
159 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
160 | // State 19 | ||
161 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
162 | // State 20 | ||
163 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
164 | // State 21 | ||
165 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
166 | ]; | ||
167 | fn __expected_tokens(__state: usize) -> Vec<::std::string::String> { | ||
168 | const __TERMINAL: &'static [&'static str] = &[ | ||
169 | r###"";""###, | ||
170 | r###""GraphicEQ:""###, | ||
171 | r###""Preamp:""###, | ||
172 | r###""dB""###, | ||
173 | r###"r#"-?[0-9]*\\.[0-9]+"#"###, | ||
174 | r###"r#"-[0-9]+"#"###, | ||
175 | r###"r#"[0-9]+"#"###, | ||
176 | ]; | ||
177 | __ACTION[(__state * 7)..].iter().zip(__TERMINAL).filter_map(|(&state, terminal)| { | ||
178 | if state == 0 { | ||
179 | None | ||
180 | } else { | ||
181 | Some(terminal.to_string()) | ||
182 | } | ||
183 | }).collect() | ||
184 | } | ||
185 | pub struct MainParser { | ||
186 | builder: super::__intern_token::__MatcherBuilder, | ||
187 | _priv: (), | ||
188 | } | ||
189 | |||
190 | impl MainParser { | ||
191 | pub fn new() -> MainParser { | ||
192 | let __builder = super::__intern_token::__MatcherBuilder::new(); | ||
193 | MainParser { | ||
194 | builder: __builder, | ||
195 | _priv: (), | ||
196 | } | ||
197 | } | ||
198 | |||
199 | #[allow(dead_code)] | ||
200 | pub fn parse< | ||
201 | 'input, | ||
202 | >( | ||
203 | &self, | ||
204 | input: &'input str, | ||
205 | ) -> Result<Filter, __lalrpop_util::ParseError<usize, Token<'input>, &'static str>> | ||
206 | { | ||
207 | let mut __tokens = self.builder.matcher(input); | ||
208 | let mut __states = vec![0_i8]; | ||
209 | let mut __symbols = vec![]; | ||
210 | let mut __integer; | ||
211 | let mut __lookahead; | ||
212 | let __last_location = &mut Default::default(); | ||
213 | '__shift: loop { | ||
214 | __lookahead = match __tokens.next() { | ||
215 | Some(Ok(v)) => v, | ||
216 | None => break '__shift, | ||
217 | Some(Err(e)) => return Err(e), | ||
218 | }; | ||
219 | *__last_location = __lookahead.2.clone(); | ||
220 | __integer = match __lookahead.1 { | ||
221 | Token(3, _) if true => 0, | ||
222 | Token(4, _) if true => 1, | ||
223 | Token(5, _) if true => 2, | ||
224 | Token(6, _) if true => 3, | ||
225 | Token(0, _) if true => 4, | ||
226 | Token(1, _) if true => 5, | ||
227 | Token(2, _) if true => 6, | ||
228 | _ => { | ||
229 | let __state = *__states.last().unwrap() as usize; | ||
230 | let __error = __lalrpop_util::ParseError::UnrecognizedToken { | ||
231 | token: Some(__lookahead), | ||
232 | expected: __expected_tokens(__state), | ||
233 | }; | ||
234 | return Err(__error); | ||
235 | } | ||
236 | }; | ||
237 | '__inner: loop { | ||
238 | let __state = *__states.last().unwrap() as usize; | ||
239 | let __action = __ACTION[__state * 7 + __integer]; | ||
240 | if __action > 0 { | ||
241 | let __symbol = match __integer { | ||
242 | 0 => match __lookahead.1 { | ||
243 | Token(3, __tok0) => __Symbol::Variant0((__tok0)), | ||
244 | _ => unreachable!(), | ||
245 | }, | ||
246 | 1 => match __lookahead.1 { | ||
247 | Token(4, __tok0) => __Symbol::Variant0((__tok0)), | ||
248 | _ => unreachable!(), | ||
249 | }, | ||
250 | 2 => match __lookahead.1 { | ||
251 | Token(5, __tok0) => __Symbol::Variant0((__tok0)), | ||
252 | _ => unreachable!(), | ||
253 | }, | ||
254 | 3 => match __lookahead.1 { | ||
255 | Token(6, __tok0) => __Symbol::Variant0((__tok0)), | ||
256 | _ => unreachable!(), | ||
257 | }, | ||
258 | 4 => match __lookahead.1 { | ||
259 | Token(0, __tok0) => __Symbol::Variant0((__tok0)), | ||
260 | _ => unreachable!(), | ||
261 | }, | ||
262 | 5 => match __lookahead.1 { | ||
263 | Token(1, __tok0) => __Symbol::Variant0((__tok0)), | ||
264 | _ => unreachable!(), | ||
265 | }, | ||
266 | 6 => match __lookahead.1 { | ||
267 | Token(2, __tok0) => __Symbol::Variant0((__tok0)), | ||
268 | _ => unreachable!(), | ||
269 | }, | ||
270 | _ => unreachable!(), | ||
271 | }; | ||
272 | __states.push(__action - 1); | ||
273 | __symbols.push((__lookahead.0, __symbol, __lookahead.2)); | ||
274 | continue '__shift; | ||
275 | } else if __action < 0 { | ||
276 | if let Some(r) = __reduce(input, __action, Some(&__lookahead.0), &mut __states, &mut __symbols, ::std::marker::PhantomData::<()>) { | ||
277 | if r.is_err() { | ||
278 | return r; | ||
279 | } | ||
280 | return Err(__lalrpop_util::ParseError::ExtraToken { token: __lookahead }); | ||
281 | } | ||
282 | } else { | ||
283 | let mut __err_lookahead = Some(__lookahead); | ||
284 | let mut __err_integer: Option<usize> = Some(__integer); | ||
285 | let __state = *__states.last().unwrap() as usize; | ||
286 | let __error = __lalrpop_util::ParseError::UnrecognizedToken { | ||
287 | token: __err_lookahead, | ||
288 | expected: __expected_tokens(__state), | ||
289 | }; | ||
290 | return Err(__error) | ||
291 | } | ||
292 | } | ||
293 | } | ||
294 | loop { | ||
295 | let __state = *__states.last().unwrap() as usize; | ||
296 | let __action = __EOF_ACTION[__state]; | ||
297 | if __action < 0 { | ||
298 | if let Some(r) = __reduce(input, __action, None, &mut __states, &mut __symbols, ::std::marker::PhantomData::<()>) { | ||
299 | return r; | ||
300 | } | ||
301 | } else { | ||
302 | let mut __err_lookahead = None; | ||
303 | let mut __err_integer: Option<usize> = None; | ||
304 | let __state = *__states.last().unwrap() as usize; | ||
305 | let __error = __lalrpop_util::ParseError::UnrecognizedToken { | ||
306 | token: __err_lookahead, | ||
307 | expected: __expected_tokens(__state), | ||
308 | }; | ||
309 | return Err(__error) | ||
310 | } | ||
311 | } | ||
312 | } | ||
313 | } | ||
314 | pub(crate) fn __reduce< | ||
315 | 'input, | ||
316 | >( | ||
317 | input: &'input str, | ||
318 | __action: i8, | ||
319 | __lookahead_start: Option<&usize>, | ||
320 | __states: &mut ::std::vec::Vec<i8>, | ||
321 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, | ||
322 | _: ::std::marker::PhantomData<()>, | ||
323 | ) -> Option<Result<Filter,__lalrpop_util::ParseError<usize, Token<'input>, &'static str>>> | ||
324 | { | ||
325 | let (__pop_states, __symbol, __nonterminal) = match -__action { | ||
326 | 1 => { | ||
327 | __reduce1(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) | ||
328 | } | ||
329 | 2 => { | ||
330 | __reduce2(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) | ||
331 | } | ||
332 | 3 => { | ||
333 | __reduce3(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) | ||
334 | } | ||
335 | 4 => { | ||
336 | __reduce4(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) | ||
337 | } | ||
338 | 5 => { | ||
339 | __reduce5(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) | ||
340 | } | ||
341 | 6 => { | ||
342 | __reduce6(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) | ||
343 | } | ||
344 | 7 => { | ||
345 | __reduce7(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) | ||
346 | } | ||
347 | 8 => { | ||
348 | __reduce8(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) | ||
349 | } | ||
350 | 9 => { | ||
351 | __reduce9(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) | ||
352 | } | ||
353 | 10 => { | ||
354 | __reduce10(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) | ||
355 | } | ||
356 | 11 => { | ||
357 | __reduce11(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) | ||
358 | } | ||
359 | 12 => { | ||
360 | __reduce12(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) | ||
361 | } | ||
362 | 13 => { | ||
363 | __reduce13(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) | ||
364 | } | ||
365 | 14 => { | ||
366 | __reduce14(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) | ||
367 | } | ||
368 | 15 => { | ||
369 | // __Main = Main => ActionFn(0); | ||
370 | let __sym0 = __pop_Variant6(__symbols); | ||
371 | let __start = __sym0.0.clone(); | ||
372 | let __end = __sym0.2.clone(); | ||
373 | let __nt = super::__action0::<>(input, __sym0); | ||
374 | return Some(Ok(__nt)); | ||
375 | } | ||
376 | _ => panic!("invalid action code {}", __action) | ||
377 | }; | ||
378 | let __states_len = __states.len(); | ||
379 | __states.truncate(__states_len - __pop_states); | ||
380 | __symbols.push(__symbol); | ||
381 | let __state = *__states.last().unwrap() as usize; | ||
382 | let __next_state = __GOTO[__state * 12 + __nonterminal] - 1; | ||
383 | __states.push(__next_state); | ||
384 | None | ||
385 | } | ||
386 | fn __pop_Variant4< | ||
387 | 'input, | ||
388 | >( | ||
389 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> | ||
390 | ) -> (usize, (Vec<u32>, Vec<f64>), usize) | ||
391 | { | ||
392 | match __symbols.pop().unwrap() { | ||
393 | (__l, __Symbol::Variant4(__v), __r) => (__l, __v, __r), | ||
394 | _ => panic!("symbol type mismatch") | ||
395 | } | ||
396 | } | ||
397 | fn __pop_Variant1< | ||
398 | 'input, | ||
399 | >( | ||
400 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> | ||
401 | ) -> (usize, (u32, f64), usize) | ||
402 | { | ||
403 | match __symbols.pop().unwrap() { | ||
404 | (__l, __Symbol::Variant1(__v), __r) => (__l, __v, __r), | ||
405 | _ => panic!("symbol type mismatch") | ||
406 | } | ||
407 | } | ||
408 | fn __pop_Variant6< | ||
409 | 'input, | ||
410 | >( | ||
411 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> | ||
412 | ) -> (usize, Filter, usize) | ||
413 | { | ||
414 | match __symbols.pop().unwrap() { | ||
415 | (__l, __Symbol::Variant6(__v), __r) => (__l, __v, __r), | ||
416 | _ => panic!("symbol type mismatch") | ||
417 | } | ||
418 | } | ||
419 | fn __pop_Variant3< | ||
420 | 'input, | ||
421 | >( | ||
422 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> | ||
423 | ) -> (usize, f64, usize) | ||
424 | { | ||
425 | match __symbols.pop().unwrap() { | ||
426 | (__l, __Symbol::Variant3(__v), __r) => (__l, __v, __r), | ||
427 | _ => panic!("symbol type mismatch") | ||
428 | } | ||
429 | } | ||
430 | fn __pop_Variant7< | ||
431 | 'input, | ||
432 | >( | ||
433 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> | ||
434 | ) -> (usize, i32, usize) | ||
435 | { | ||
436 | match __symbols.pop().unwrap() { | ||
437 | (__l, __Symbol::Variant7(__v), __r) => (__l, __v, __r), | ||
438 | _ => panic!("symbol type mismatch") | ||
439 | } | ||
440 | } | ||
441 | fn __pop_Variant5< | ||
442 | 'input, | ||
443 | >( | ||
444 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> | ||
445 | ) -> (usize, u32, usize) | ||
446 | { | ||
447 | match __symbols.pop().unwrap() { | ||
448 | (__l, __Symbol::Variant5(__v), __r) => (__l, __v, __r), | ||
449 | _ => panic!("symbol type mismatch") | ||
450 | } | ||
451 | } | ||
452 | fn __pop_Variant2< | ||
453 | 'input, | ||
454 | >( | ||
455 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> | ||
456 | ) -> (usize, ::std::vec::Vec<(u32, f64)>, usize) | ||
457 | { | ||
458 | match __symbols.pop().unwrap() { | ||
459 | (__l, __Symbol::Variant2(__v), __r) => (__l, __v, __r), | ||
460 | _ => panic!("symbol type mismatch") | ||
461 | } | ||
462 | } | ||
463 | fn __pop_Variant0< | ||
464 | 'input, | ||
465 | >( | ||
466 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> | ||
467 | ) -> (usize, &'input str, usize) | ||
468 | { | ||
469 | match __symbols.pop().unwrap() { | ||
470 | (__l, __Symbol::Variant0(__v), __r) => (__l, __v, __r), | ||
471 | _ => panic!("symbol type mismatch") | ||
472 | } | ||
473 | } | ||
474 | pub(crate) fn __reduce1< | ||
475 | 'input, | ||
476 | >( | ||
477 | input: &'input str, | ||
478 | __action: i8, | ||
479 | __lookahead_start: Option<&usize>, | ||
480 | __states: &mut ::std::vec::Vec<i8>, | ||
481 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, | ||
482 | _: ::std::marker::PhantomData<()>, | ||
483 | ) -> (usize, (usize,__Symbol<'input>,usize), usize) | ||
484 | { | ||
485 | // (<(Integer Float)> ";") = Integer, Float, ";" => ActionFn(15); | ||
486 | let __sym2 = __pop_Variant0(__symbols); | ||
487 | let __sym1 = __pop_Variant3(__symbols); | ||
488 | let __sym0 = __pop_Variant5(__symbols); | ||
489 | let __start = __sym0.0.clone(); | ||
490 | let __end = __sym2.2.clone(); | ||
491 | let __nt = super::__action15::<>(input, __sym0, __sym1, __sym2); | ||
492 | let __symbol = (__start, __Symbol::Variant1(__nt), __end); | ||
493 | (3, __symbol, 0) | ||
494 | } | ||
495 | pub(crate) fn __reduce2< | ||
496 | 'input, | ||
497 | >( | ||
498 | input: &'input str, | ||
499 | __action: i8, | ||
500 | __lookahead_start: Option<&usize>, | ||
501 | __states: &mut ::std::vec::Vec<i8>, | ||
502 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, | ||
503 | _: ::std::marker::PhantomData<()>, | ||
504 | ) -> (usize, (usize,__Symbol<'input>,usize), usize) | ||
505 | { | ||
506 | // (<(Integer Float)> ";")+ = Integer, Float, ";" => ActionFn(17); | ||
507 | let __sym2 = __pop_Variant0(__symbols); | ||
508 | let __sym1 = __pop_Variant3(__symbols); | ||
509 | let __sym0 = __pop_Variant5(__symbols); | ||
510 | let __start = __sym0.0.clone(); | ||
511 | let __end = __sym2.2.clone(); | ||
512 | let __nt = super::__action17::<>(input, __sym0, __sym1, __sym2); | ||
513 | let __symbol = (__start, __Symbol::Variant2(__nt), __end); | ||
514 | (3, __symbol, 1) | ||
515 | } | ||
516 | pub(crate) fn __reduce3< | ||
517 | 'input, | ||
518 | >( | ||
519 | input: &'input str, | ||
520 | __action: i8, | ||
521 | __lookahead_start: Option<&usize>, | ||
522 | __states: &mut ::std::vec::Vec<i8>, | ||
523 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, | ||
524 | _: ::std::marker::PhantomData<()>, | ||
525 | ) -> (usize, (usize,__Symbol<'input>,usize), usize) | ||
526 | { | ||
527 | // (<(Integer Float)> ";")+ = (<(Integer Float)> ";")+, Integer, Float, ";" => ActionFn(18); | ||
528 | let __sym3 = __pop_Variant0(__symbols); | ||
529 | let __sym2 = __pop_Variant3(__symbols); | ||
530 | let __sym1 = __pop_Variant5(__symbols); | ||
531 | let __sym0 = __pop_Variant2(__symbols); | ||
532 | let __start = __sym0.0.clone(); | ||
533 | let __end = __sym3.2.clone(); | ||
534 | let __nt = super::__action18::<>(input, __sym0, __sym1, __sym2, __sym3); | ||
535 | let __symbol = (__start, __Symbol::Variant2(__nt), __end); | ||
536 | (4, __symbol, 1) | ||
537 | } | ||
538 | pub(crate) fn __reduce4< | ||
539 | 'input, | ||
540 | >( | ||
541 | input: &'input str, | ||
542 | __action: i8, | ||
543 | __lookahead_start: Option<&usize>, | ||
544 | __states: &mut ::std::vec::Vec<i8>, | ||
545 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, | ||
546 | _: ::std::marker::PhantomData<()>, | ||
547 | ) -> (usize, (usize,__Symbol<'input>,usize), usize) | ||
548 | { | ||
549 | // (Integer Float) = Integer, Float => ActionFn(14); | ||
550 | let __sym1 = __pop_Variant3(__symbols); | ||
551 | let __sym0 = __pop_Variant5(__symbols); | ||
552 | let __start = __sym0.0.clone(); | ||
553 | let __end = __sym1.2.clone(); | ||
554 | let __nt = super::__action14::<>(input, __sym0, __sym1); | ||
555 | let __symbol = (__start, __Symbol::Variant1(__nt), __end); | ||
556 | (2, __symbol, 2) | ||
557 | } | ||
558 | pub(crate) fn __reduce5< | ||
559 | 'input, | ||
560 | >( | ||
561 | input: &'input str, | ||
562 | __action: i8, | ||
563 | __lookahead_start: Option<&usize>, | ||
564 | __states: &mut ::std::vec::Vec<i8>, | ||
565 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, | ||
566 | _: ::std::marker::PhantomData<()>, | ||
567 | ) -> (usize, (usize,__Symbol<'input>,usize), usize) | ||
568 | { | ||
569 | // Decibel = Float, "dB" => ActionFn(4); | ||
570 | let __sym1 = __pop_Variant0(__symbols); | ||
571 | let __sym0 = __pop_Variant3(__symbols); | ||
572 | let __start = __sym0.0.clone(); | ||
573 | let __end = __sym1.2.clone(); | ||
574 | let __nt = super::__action4::<>(input, __sym0, __sym1); | ||
575 | let __symbol = (__start, __Symbol::Variant3(__nt), __end); | ||
576 | (2, __symbol, 3) | ||
577 | } | ||
578 | pub(crate) fn __reduce6< | ||
579 | 'input, | ||
580 | >( | ||
581 | input: &'input str, | ||
582 | __action: i8, | ||
583 | __lookahead_start: Option<&usize>, | ||
584 | __states: &mut ::std::vec::Vec<i8>, | ||
585 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, | ||
586 | _: ::std::marker::PhantomData<()>, | ||
587 | ) -> (usize, (usize,__Symbol<'input>,usize), usize) | ||
588 | { | ||
589 | // Eq = "GraphicEQ:", (<(Integer Float)> ";")+, Integer, Float => ActionFn(16); | ||
590 | let __sym3 = __pop_Variant3(__symbols); | ||
591 | let __sym2 = __pop_Variant5(__symbols); | ||
592 | let __sym1 = __pop_Variant2(__symbols); | ||
593 | let __sym0 = __pop_Variant0(__symbols); | ||
594 | let __start = __sym0.0.clone(); | ||
595 | let __end = __sym3.2.clone(); | ||
596 | let __nt = super::__action16::<>(input, __sym0, __sym1, __sym2, __sym3); | ||
597 | let __symbol = (__start, __Symbol::Variant4(__nt), __end); | ||
598 | (4, __symbol, 4) | ||
599 | } | ||
600 | pub(crate) fn __reduce7< | ||
601 | 'input, | ||
602 | >( | ||
603 | input: &'input str, | ||
604 | __action: i8, | ||
605 | __lookahead_start: Option<&usize>, | ||
606 | __states: &mut ::std::vec::Vec<i8>, | ||
607 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, | ||
608 | _: ::std::marker::PhantomData<()>, | ||
609 | ) -> (usize, (usize,__Symbol<'input>,usize), usize) | ||
610 | { | ||
611 | // Float = RawFloat => ActionFn(5); | ||
612 | let __sym0 = __pop_Variant3(__symbols); | ||
613 | let __start = __sym0.0.clone(); | ||
614 | let __end = __sym0.2.clone(); | ||
615 | let __nt = super::__action5::<>(input, __sym0); | ||
616 | let __symbol = (__start, __Symbol::Variant3(__nt), __end); | ||
617 | (1, __symbol, 5) | ||
618 | } | ||
619 | pub(crate) fn __reduce8< | ||
620 | 'input, | ||
621 | >( | ||
622 | input: &'input str, | ||
623 | __action: i8, | ||
624 | __lookahead_start: Option<&usize>, | ||
625 | __states: &mut ::std::vec::Vec<i8>, | ||
626 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, | ||
627 | _: ::std::marker::PhantomData<()>, | ||
628 | ) -> (usize, (usize,__Symbol<'input>,usize), usize) | ||
629 | { | ||
630 | // Float = SignedInteger => ActionFn(6); | ||
631 | let __sym0 = __pop_Variant7(__symbols); | ||
632 | let __start = __sym0.0.clone(); | ||
633 | let __end = __sym0.2.clone(); | ||
634 | let __nt = super::__action6::<>(input, __sym0); | ||
635 | let __symbol = (__start, __Symbol::Variant3(__nt), __end); | ||
636 | (1, __symbol, 5) | ||
637 | } | ||
638 | pub(crate) fn __reduce9< | ||
639 | 'input, | ||
640 | >( | ||
641 | input: &'input str, | ||
642 | __action: i8, | ||
643 | __lookahead_start: Option<&usize>, | ||
644 | __states: &mut ::std::vec::Vec<i8>, | ||
645 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, | ||
646 | _: ::std::marker::PhantomData<()>, | ||
647 | ) -> (usize, (usize,__Symbol<'input>,usize), usize) | ||
648 | { | ||
649 | // Float = Integer => ActionFn(7); | ||
650 | let __sym0 = __pop_Variant5(__symbols); | ||
651 | let __start = __sym0.0.clone(); | ||
652 | let __end = __sym0.2.clone(); | ||
653 | let __nt = super::__action7::<>(input, __sym0); | ||
654 | let __symbol = (__start, __Symbol::Variant3(__nt), __end); | ||
655 | (1, __symbol, 5) | ||
656 | } | ||
657 | pub(crate) fn __reduce10< | ||
658 | 'input, | ||
659 | >( | ||
660 | input: &'input str, | ||
661 | __action: i8, | ||
662 | __lookahead_start: Option<&usize>, | ||
663 | __states: &mut ::std::vec::Vec<i8>, | ||
664 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, | ||
665 | _: ::std::marker::PhantomData<()>, | ||
666 | ) -> (usize, (usize,__Symbol<'input>,usize), usize) | ||
667 | { | ||
668 | // Integer = r#"[0-9]+"# => ActionFn(10); | ||
669 | let __sym0 = __pop_Variant0(__symbols); | ||
670 | let __start = __sym0.0.clone(); | ||
671 | let __end = __sym0.2.clone(); | ||
672 | let __nt = super::__action10::<>(input, __sym0); | ||
673 | let __symbol = (__start, __Symbol::Variant5(__nt), __end); | ||
674 | (1, __symbol, 6) | ||
675 | } | ||
676 | pub(crate) fn __reduce11< | ||
677 | 'input, | ||
678 | >( | ||
679 | input: &'input str, | ||
680 | __action: i8, | ||
681 | __lookahead_start: Option<&usize>, | ||
682 | __states: &mut ::std::vec::Vec<i8>, | ||
683 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, | ||
684 | _: ::std::marker::PhantomData<()>, | ||
685 | ) -> (usize, (usize,__Symbol<'input>,usize), usize) | ||
686 | { | ||
687 | // Main = Preamp, Eq => ActionFn(1); | ||
688 | let __sym1 = __pop_Variant4(__symbols); | ||
689 | let __sym0 = __pop_Variant3(__symbols); | ||
690 | let __start = __sym0.0.clone(); | ||
691 | let __end = __sym1.2.clone(); | ||
692 | let __nt = super::__action1::<>(input, __sym0, __sym1); | ||
693 | let __symbol = (__start, __Symbol::Variant6(__nt), __end); | ||
694 | (2, __symbol, 7) | ||
695 | } | ||
696 | pub(crate) fn __reduce12< | ||
697 | 'input, | ||
698 | >( | ||
699 | input: &'input str, | ||
700 | __action: i8, | ||
701 | __lookahead_start: Option<&usize>, | ||
702 | __states: &mut ::std::vec::Vec<i8>, | ||
703 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, | ||
704 | _: ::std::marker::PhantomData<()>, | ||
705 | ) -> (usize, (usize,__Symbol<'input>,usize), usize) | ||
706 | { | ||
707 | // Preamp = "Preamp:", Decibel => ActionFn(2); | ||
708 | let __sym1 = __pop_Variant3(__symbols); | ||
709 | let __sym0 = __pop_Variant0(__symbols); | ||
710 | let __start = __sym0.0.clone(); | ||
711 | let __end = __sym1.2.clone(); | ||
712 | let __nt = super::__action2::<>(input, __sym0, __sym1); | ||
713 | let __symbol = (__start, __Symbol::Variant3(__nt), __end); | ||
714 | (2, __symbol, 8) | ||
715 | } | ||
716 | pub(crate) fn __reduce13< | ||
717 | 'input, | ||
718 | >( | ||
719 | input: &'input str, | ||
720 | __action: i8, | ||
721 | __lookahead_start: Option<&usize>, | ||
722 | __states: &mut ::std::vec::Vec<i8>, | ||
723 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, | ||
724 | _: ::std::marker::PhantomData<()>, | ||
725 | ) -> (usize, (usize,__Symbol<'input>,usize), usize) | ||
726 | { | ||
727 | // RawFloat = r#"-?[0-9]*\\.[0-9]+"# => ActionFn(8); | ||
728 | let __sym0 = __pop_Variant0(__symbols); | ||
729 | let __start = __sym0.0.clone(); | ||
730 | let __end = __sym0.2.clone(); | ||
731 | let __nt = super::__action8::<>(input, __sym0); | ||
732 | let __symbol = (__start, __Symbol::Variant3(__nt), __end); | ||
733 | (1, __symbol, 9) | ||
734 | } | ||
735 | pub(crate) fn __reduce14< | ||
736 | 'input, | ||
737 | >( | ||
738 | input: &'input str, | ||
739 | __action: i8, | ||
740 | __lookahead_start: Option<&usize>, | ||
741 | __states: &mut ::std::vec::Vec<i8>, | ||
742 | __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, | ||
743 | _: ::std::marker::PhantomData<()>, | ||
744 | ) -> (usize, (usize,__Symbol<'input>,usize), usize) | ||
745 | { | ||
746 | // SignedInteger = r#"-[0-9]+"# => ActionFn(9); | ||
747 | let __sym0 = __pop_Variant0(__symbols); | ||
748 | let __start = __sym0.0.clone(); | ||
749 | let __end = __sym0.2.clone(); | ||
750 | let __nt = super::__action9::<>(input, __sym0); | ||
751 | let __symbol = (__start, __Symbol::Variant7(__nt), __end); | ||
752 | (1, __symbol, 10) | ||
753 | } | ||
754 | } | ||
755 | pub use self::__parse__Main::MainParser; | ||
756 | #[cfg_attr(rustfmt, rustfmt_skip)] | ||
757 | mod __intern_token { | ||
758 | #![allow(unused_imports)] | ||
759 | use ::Filter; | ||
760 | use std::str::FromStr; | ||
761 | #[allow(unused_extern_crates)] | ||
762 | extern crate lalrpop_util as __lalrpop_util; | ||
763 | extern crate regex as __regex; | ||
764 | use std::fmt as __fmt; | ||
765 | |||
766 | #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] | ||
767 | pub struct Token<'input>(pub usize, pub &'input str); | ||
768 | impl<'a> __fmt::Display for Token<'a> { | ||
769 | fn fmt(&self, formatter: &mut __fmt::Formatter) -> Result<(), __fmt::Error> { | ||
770 | __fmt::Display::fmt(self.1, formatter) | ||
771 | } | ||
772 | } | ||
773 | |||
774 | pub struct __MatcherBuilder { | ||
775 | regex_set: __regex::RegexSet, | ||
776 | regex_vec: Vec<__regex::Regex>, | ||
777 | } | ||
778 | |||
779 | impl __MatcherBuilder { | ||
780 | pub fn new() -> __MatcherBuilder { | ||
781 | let __strs: &[&str] = &[ | ||
782 | "^((?u:\\-)?(?u:[0-9])*(?u:\\.)(?u:[0-9])+)", | ||
783 | "^((?u:\\-)(?u:[0-9])+)", | ||
784 | "^((?u:[0-9])+)", | ||
785 | "^((?u:;))", | ||
786 | "^((?u:GraphicEQ:))", | ||
787 | "^((?u:Preamp:))", | ||
788 | "^((?u:dB))", | ||
789 | ]; | ||
790 | let __regex_set = __regex::RegexSet::new(__strs).unwrap(); | ||
791 | let __regex_vec = vec![ | ||
792 | __regex::Regex::new("^((?u:\\-)?(?u:[0-9])*(?u:\\.)(?u:[0-9])+)").unwrap(), | ||
793 | __regex::Regex::new("^((?u:\\-)(?u:[0-9])+)").unwrap(), | ||
794 | __regex::Regex::new("^((?u:[0-9])+)").unwrap(), | ||
795 | __regex::Regex::new("^((?u:;))").unwrap(), | ||
796 | __regex::Regex::new("^((?u:GraphicEQ:))").unwrap(), | ||
797 | __regex::Regex::new("^((?u:Preamp:))").unwrap(), | ||
798 | __regex::Regex::new("^((?u:dB))").unwrap(), | ||
799 | ]; | ||
800 | __MatcherBuilder { regex_set: __regex_set, regex_vec: __regex_vec } | ||
801 | } | ||
802 | pub fn matcher<'input, 'builder>(&'builder self, s: &'input str) -> __Matcher<'input, 'builder> { | ||
803 | __Matcher { | ||
804 | text: s, | ||
805 | consumed: 0, | ||
806 | regex_set: &self.regex_set, | ||
807 | regex_vec: &self.regex_vec, | ||
808 | } | ||
809 | } | ||
810 | } | ||
811 | |||
812 | pub struct __Matcher<'input, 'builder> { | ||
813 | text: &'input str, | ||
814 | consumed: usize, | ||
815 | regex_set: &'builder __regex::RegexSet, | ||
816 | regex_vec: &'builder Vec<__regex::Regex>, | ||
817 | } | ||
818 | |||
819 | impl<'input, 'builder> Iterator for __Matcher<'input, 'builder> { | ||
820 | type Item = Result<(usize, Token<'input>, usize), __lalrpop_util::ParseError<usize,Token<'input>,&'static str>>; | ||
821 | |||
822 | fn next(&mut self) -> Option<Self::Item> { | ||
823 | let __text = self.text.trim_left(); | ||
824 | let __whitespace = self.text.len() - __text.len(); | ||
825 | let __start_offset = self.consumed + __whitespace; | ||
826 | if __text.is_empty() { | ||
827 | self.text = __text; | ||
828 | self.consumed = __start_offset; | ||
829 | None | ||
830 | } else { | ||
831 | let __matches = self.regex_set.matches(__text); | ||
832 | if !__matches.matched_any() { | ||
833 | Some(Err(__lalrpop_util::ParseError::InvalidToken { | ||
834 | location: __start_offset, | ||
835 | })) | ||
836 | } else { | ||
837 | let mut __longest_match = 0; | ||
838 | let mut __index = 0; | ||
839 | for __i in 0 .. 7 { | ||
840 | if __matches.matched(__i) { | ||
841 | let __match = self.regex_vec[__i].find(__text).unwrap(); | ||
842 | let __len = __match.end(); | ||
843 | if __len >= __longest_match { | ||
844 | __longest_match = __len; | ||
845 | __index = __i; | ||
846 | } | ||
847 | } | ||
848 | } | ||
849 | let __result = &__text[..__longest_match]; | ||
850 | let __remaining = &__text[__longest_match..]; | ||
851 | let __end_offset = __start_offset + __longest_match; | ||
852 | self.text = __remaining; | ||
853 | self.consumed = __end_offset; | ||
854 | Some(Ok((__start_offset, Token(__index, __result), __end_offset))) | ||
855 | } | ||
856 | } | ||
857 | } | ||
858 | } | ||
859 | } | ||
860 | pub use self::__intern_token::Token; | ||
861 | |||
862 | #[allow(unused_variables)] | ||
863 | fn __action0< | ||
864 | 'input, | ||
865 | >( | ||
866 | input: &'input str, | ||
867 | (_, __0, _): (usize, Filter, usize), | ||
868 | ) -> Filter | ||
869 | { | ||
870 | (__0) | ||
871 | } | ||
872 | |||
873 | #[allow(unused_variables)] | ||
874 | fn __action1< | ||
875 | 'input, | ||
876 | >( | ||
877 | input: &'input str, | ||
878 | (_, preamp, _): (usize, f64, usize), | ||
879 | (_, eq, _): (usize, (Vec<u32>, Vec<f64>), usize), | ||
880 | ) -> Filter | ||
881 | { | ||
882 | { | ||
883 | let coefficients: Vec<_> = eq.1.iter().map(|decibel| 10f64.powf(decibel / 10f64)).collect(); | ||
884 | // TODO: add decibel_to_ratio conversion function | ||
885 | let preamp = 10f64.powf(preamp / 10f64); | ||
886 | Filter { preamp, frequencies: eq.0, coefficients } | ||
887 | } | ||
888 | } | ||
889 | |||
890 | #[allow(unused_variables)] | ||
891 | fn __action2< | ||
892 | 'input, | ||
893 | >( | ||
894 | input: &'input str, | ||
895 | (_, _, _): (usize, &'input str, usize), | ||
896 | (_, __0, _): (usize, f64, usize), | ||
897 | ) -> f64 | ||
898 | { | ||
899 | (__0) | ||
900 | } | ||
901 | |||
902 | #[allow(unused_variables)] | ||
903 | fn __action3< | ||
904 | 'input, | ||
905 | >( | ||
906 | input: &'input str, | ||
907 | (_, _, _): (usize, &'input str, usize), | ||
908 | (_, values, _): (usize, ::std::vec::Vec<(u32, f64)>, usize), | ||
909 | (_, end, _): (usize, (u32, f64), usize), | ||
910 | ) -> (Vec<u32>, Vec<f64>) | ||
911 | { | ||
912 | { | ||
913 | let mut values = values; | ||
914 | values.push(end); | ||
915 | values.into_iter().unzip() | ||
916 | } | ||
917 | } | ||
918 | |||
919 | #[allow(unused_variables)] | ||
920 | fn __action4< | ||
921 | 'input, | ||
922 | >( | ||
923 | input: &'input str, | ||
924 | (_, __0, _): (usize, f64, usize), | ||
925 | (_, _, _): (usize, &'input str, usize), | ||
926 | ) -> f64 | ||
927 | { | ||
928 | (__0) | ||
929 | } | ||
930 | |||
931 | #[allow(unused_variables)] | ||
932 | fn __action5< | ||
933 | 'input, | ||
934 | >( | ||
935 | input: &'input str, | ||
936 | (_, __0, _): (usize, f64, usize), | ||
937 | ) -> f64 | ||
938 | { | ||
939 | (__0) | ||
940 | } | ||
941 | |||
942 | #[allow(unused_variables)] | ||
943 | fn __action6< | ||
944 | 'input, | ||
945 | >( | ||
946 | input: &'input str, | ||
947 | (_, __0, _): (usize, i32, usize), | ||
948 | ) -> f64 | ||
949 | { | ||
950 | __0 as f64 | ||
951 | } | ||
952 | |||
953 | #[allow(unused_variables)] | ||
954 | fn __action7< | ||
955 | 'input, | ||
956 | >( | ||
957 | input: &'input str, | ||
958 | (_, __0, _): (usize, u32, usize), | ||
959 | ) -> f64 | ||
960 | { | ||
961 | __0 as f64 | ||
962 | } | ||
963 | |||
964 | #[allow(unused_variables)] | ||
965 | fn __action8< | ||
966 | 'input, | ||
967 | >( | ||
968 | input: &'input str, | ||
969 | (_, __0, _): (usize, &'input str, usize), | ||
970 | ) -> f64 | ||
971 | { | ||
972 | f64::from_str(__0).unwrap() | ||
973 | } | ||
974 | |||
975 | #[allow(unused_variables)] | ||
976 | fn __action9< | ||
977 | 'input, | ||
978 | >( | ||
979 | input: &'input str, | ||
980 | (_, __0, _): (usize, &'input str, usize), | ||
981 | ) -> i32 | ||
982 | { | ||
983 | i32::from_str(__0).unwrap() | ||
984 | } | ||
985 | |||
986 | #[allow(unused_variables)] | ||
987 | fn __action10< | ||
988 | 'input, | ||
989 | >( | ||
990 | input: &'input str, | ||
991 | (_, __0, _): (usize, &'input str, usize), | ||
992 | ) -> u32 | ||
993 | { | ||
994 | u32::from_str(__0).unwrap() | ||
995 | } | ||
996 | |||
997 | #[allow(unused_variables)] | ||
998 | fn __action11< | ||
999 | 'input, | ||
1000 | >( | ||
1001 | input: &'input str, | ||
1002 | (_, __0, _): (usize, (u32, f64), usize), | ||
1003 | ) -> ::std::vec::Vec<(u32, f64)> | ||
1004 | { | ||
1005 | vec![__0] | ||
1006 | } | ||
1007 | |||
1008 | #[allow(unused_variables)] | ||
1009 | fn __action12< | ||
1010 | 'input, | ||
1011 | >( | ||
1012 | input: &'input str, | ||
1013 | (_, v, _): (usize, ::std::vec::Vec<(u32, f64)>, usize), | ||
1014 | (_, e, _): (usize, (u32, f64), usize), | ||
1015 | ) -> ::std::vec::Vec<(u32, f64)> | ||
1016 | { | ||
1017 | { let mut v = v; v.push(e); v } | ||
1018 | } | ||
1019 | |||
1020 | #[allow(unused_variables)] | ||
1021 | fn __action13< | ||
1022 | 'input, | ||
1023 | >( | ||
1024 | input: &'input str, | ||
1025 | (_, __0, _): (usize, (u32, f64), usize), | ||
1026 | (_, _, _): (usize, &'input str, usize), | ||
1027 | ) -> (u32, f64) | ||
1028 | { | ||
1029 | (__0) | ||
1030 | } | ||
1031 | |||
1032 | #[allow(unused_variables)] | ||
1033 | fn __action14< | ||
1034 | 'input, | ||
1035 | >( | ||
1036 | input: &'input str, | ||
1037 | (_, __0, _): (usize, u32, usize), | ||
1038 | (_, __1, _): (usize, f64, usize), | ||
1039 | ) -> (u32, f64) | ||
1040 | { | ||
1041 | (__0, __1) | ||
1042 | } | ||
1043 | |||
1044 | #[allow(unused_variables)] | ||
1045 | fn __action15< | ||
1046 | 'input, | ||
1047 | >( | ||
1048 | input: &'input str, | ||
1049 | __0: (usize, u32, usize), | ||
1050 | __1: (usize, f64, usize), | ||
1051 | __2: (usize, &'input str, usize), | ||
1052 | ) -> (u32, f64) | ||
1053 | { | ||
1054 | let __start0 = __0.0.clone(); | ||
1055 | let __end0 = __1.2.clone(); | ||
1056 | let __temp0 = __action14( | ||
1057 | input, | ||
1058 | __0, | ||
1059 | __1, | ||
1060 | ); | ||
1061 | let __temp0 = (__start0, __temp0, __end0); | ||
1062 | __action13( | ||
1063 | input, | ||
1064 | __temp0, | ||
1065 | __2, | ||
1066 | ) | ||
1067 | } | ||
1068 | |||
1069 | #[allow(unused_variables)] | ||
1070 | fn __action16< | ||
1071 | 'input, | ||
1072 | >( | ||
1073 | input: &'input str, | ||
1074 | __0: (usize, &'input str, usize), | ||
1075 | __1: (usize, ::std::vec::Vec<(u32, f64)>, usize), | ||
1076 | __2: (usize, u32, usize), | ||
1077 | __3: (usize, f64, usize), | ||
1078 | ) -> (Vec<u32>, Vec<f64>) | ||
1079 | { | ||
1080 | let __start0 = __2.0.clone(); | ||
1081 | let __end0 = __3.2.clone(); | ||
1082 | let __temp0 = __action14( | ||
1083 | input, | ||
1084 | __2, | ||
1085 | __3, | ||
1086 | ); | ||
1087 | let __temp0 = (__start0, __temp0, __end0); | ||
1088 | __action3( | ||
1089 | input, | ||
1090 | __0, | ||
1091 | __1, | ||
1092 | __temp0, | ||
1093 | ) | ||
1094 | } | ||
1095 | |||
1096 | #[allow(unused_variables)] | ||
1097 | fn __action17< | ||
1098 | 'input, | ||
1099 | >( | ||
1100 | input: &'input str, | ||
1101 | __0: (usize, u32, usize), | ||
1102 | __1: (usize, f64, usize), | ||
1103 | __2: (usize, &'input str, usize), | ||
1104 | ) -> ::std::vec::Vec<(u32, f64)> | ||
1105 | { | ||
1106 | let __start0 = __0.0.clone(); | ||
1107 | let __end0 = __2.2.clone(); | ||
1108 | let __temp0 = __action15( | ||
1109 | input, | ||
1110 | __0, | ||
1111 | __1, | ||
1112 | __2, | ||
1113 | ); | ||
1114 | let __temp0 = (__start0, __temp0, __end0); | ||
1115 | __action11( | ||
1116 | input, | ||
1117 | __temp0, | ||
1118 | ) | ||
1119 | } | ||
1120 | |||
1121 | #[allow(unused_variables)] | ||
1122 | fn __action18< | ||
1123 | 'input, | ||
1124 | >( | ||
1125 | input: &'input str, | ||
1126 | __0: (usize, ::std::vec::Vec<(u32, f64)>, usize), | ||
1127 | __1: (usize, u32, usize), | ||
1128 | __2: (usize, f64, usize), | ||
1129 | __3: (usize, &'input str, usize), | ||
1130 | ) -> ::std::vec::Vec<(u32, f64)> | ||
1131 | { | ||
1132 | let __start0 = __1.0.clone(); | ||
1133 | let __end0 = __3.2.clone(); | ||
1134 | let __temp0 = __action15( | ||
1135 | input, | ||
1136 | __1, | ||
1137 | __2, | ||
1138 | __3, | ||
1139 | ); | ||
1140 | let __temp0 = (__start0, __temp0, __end0); | ||
1141 | __action12( | ||
1142 | input, | ||
1143 | __0, | ||
1144 | __temp0, | ||
1145 | ) | ||
1146 | } | ||
1147 | |||
1148 | pub trait __ToTriple<'input, > { | ||
1149 | type Error; | ||
1150 | fn to_triple(value: Self) -> Result<(usize,Token<'input>,usize),Self::Error>; | ||
1151 | } | ||
1152 | |||
1153 | impl<'input, > __ToTriple<'input, > for (usize, Token<'input>, usize) { | ||
1154 | type Error = &'static str; | ||
1155 | fn to_triple(value: Self) -> Result<(usize,Token<'input>,usize),&'static str> { | ||
1156 | Ok(value) | ||
1157 | } | ||
1158 | } | ||
1159 | impl<'input, > __ToTriple<'input, > for Result<(usize, Token<'input>, usize),&'static str> { | ||
1160 | type Error = &'static str; | ||
1161 | fn to_triple(value: Self) -> Result<(usize,Token<'input>,usize),&'static str> { | ||
1162 | value | ||
1163 | } | ||
1164 | } | ||
diff --git a/src/parsing/mod.rs b/src/parsing/mod.rs new file mode 100644 index 0000000..b613585 --- /dev/null +++ b/src/parsing/mod.rs | |||
@@ -0,0 +1,3 @@ | |||
1 | pub mod equalizer_apo; | ||
2 | |||
3 | pub use self::equalizer_apo::MainParser as EqualizerApoParser; | ||
diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..5aae29d --- /dev/null +++ b/src/utils.rs | |||
@@ -0,0 +1,71 @@ | |||
1 | use ::{Filter, NoEqualizedSink}; | ||
2 | |||
3 | use parsing::EqualizerApoParser; | ||
4 | |||
5 | use ::dbus_api::equalizing_manager::OrgPulseAudioExtEqualizing1Manager; | ||
6 | use ::dbus_api::server_lookup::OrgPulseAudioServerLookup1; | ||
7 | use ::dbus_api::sink::OrgPulseAudioExtEqualizing1Equalizer; | ||
8 | |||
9 | use dbus::{BusType, Connection, ConnPath}; | ||
10 | use failure::{Error, ResultExt}; | ||
11 | |||
12 | use std::io::{self, Read}; | ||
13 | |||
14 | pub fn connect() -> Result<Connection, Error> { | ||
15 | let pulse_sock_path = | ||
16 | get_pulse_dbus_sock().context("While looking up PulseAudio's D-Bus socket path")?; | ||
17 | info!("PulseAudio's D-Bus socket path is: {}", pulse_sock_path); | ||
18 | |||
19 | trace!("Connecting to PulseAudio's D-Bus socket"); | ||
20 | Ok(Connection::open_private(&pulse_sock_path)?) | ||
21 | } | ||
22 | |||
23 | pub fn get_equalized_sink<'a>(conn: &'a Connection) -> Result<ConnPath<'a, &'a Connection>, Error> { | ||
24 | let conn_manager = conn.with_path("org.PulseAudio.Core1", "/org/pulseaudio/equalizing1", 2000); | ||
25 | |||
26 | // TODO: make that a command-line option | ||
27 | trace!("Getting (one of) the equalized sink(s)"); | ||
28 | let mut sinks = conn_manager.get_equalized_sinks()?; | ||
29 | let sink_path = sinks.pop().ok_or(NoEqualizedSink {})?; | ||
30 | info!("Using equalized sink: {:?}", sink_path.as_cstr()); | ||
31 | |||
32 | trace!("Connecting to equalized sink"); | ||
33 | Ok(conn.with_path("org.PulseAudio.Core1", sink_path, 2000)) | ||
34 | } | ||
35 | |||
36 | pub fn send_filter(conn_sink: &ConnPath<&Connection>, filter: Filter) -> Result<(), Error> { | ||
37 | let channel = conn_sink.get_nchannels()?; | ||
38 | info!("Using channel: {}", channel); | ||
39 | trace!("Sending filter"); | ||
40 | conn_sink.seed_filter( | ||
41 | channel, | ||
42 | filter.frequencies, | ||
43 | filter.coefficients, | ||
44 | filter.preamp, | ||
45 | )?; | ||
46 | Ok(()) | ||
47 | } | ||
48 | |||
49 | pub fn read_filter() -> Result<Filter, Error> { | ||
50 | let mut buffer = String::new(); | ||
51 | let stdin = io::stdin(); | ||
52 | let mut handle = stdin.lock(); | ||
53 | |||
54 | info!("Reading filter in GraphicEQ format from the command line"); | ||
55 | handle.read_to_string(&mut buffer)?; | ||
56 | |||
57 | // TODO: lifetime issue when "throwing" parse error | ||
58 | let filter = EqualizerApoParser::new().parse(&buffer).unwrap(); | ||
59 | info!("Parsed filter: {:?}", filter); | ||
60 | |||
61 | Ok(filter) | ||
62 | } | ||
63 | |||
64 | fn get_pulse_dbus_sock() -> Result<String, Error> { | ||
65 | trace!("Connecting to the D-Bus' session bus"); | ||
66 | let conn = Connection::get_private(BusType::Session)?; | ||
67 | let conn = conn.with_path("org.PulseAudio1", "/org/pulseaudio/server_lookup1", 2000); | ||
68 | |||
69 | trace!("Checking PulseAudio's D-Bus socket path"); | ||
70 | Ok(conn.get_address()?) | ||
71 | } | ||