summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMinijackson <minijackson@riseup.net>2018-09-04 12:33:44 +0200
committerMinijackson <minijackson@riseup.net>2018-09-04 12:33:44 +0200
commit515870c9e8ff833e50f5253ec6e6d43de97519ed (patch)
tree996a665bebfe847fe8c2ebdb371b3f15f3ce332f
parenta903881e79f30f73d0008f88c4b245defbe5b5c1 (diff)
downloadset_eq-515870c9e8ff833e50f5253ec6e6d43de97519ed.tar.gz
set_eq-515870c9e8ff833e50f5253ec6e6d43de97519ed.zip
Rust stable compatibility + use amplitude decibel conversion
-rw-r--r--Cargo.lock36
-rw-r--r--Cargo.toml3
-rw-r--r--src/main.rs17
-rw-r--r--src/parsing/equalizer_apo.lalrpop2
-rw-r--r--src/parsing/equalizer_apo.rs4
-rw-r--r--src/utils.rs2
6 files changed, 21 insertions, 43 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 46a6dd4..3e0b2fa 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -125,22 +125,6 @@ dependencies = [
125] 125]
126 126
127[[package]] 127[[package]]
128name = "clap"
129version = "3.0.0-alpha.1"
130source = "git+https://github.com/kbknapp/clap-rs?branch=v3-master#eaa0700e7ed76f37d245a6878deb3b8e81754d6c"
131dependencies = [
132 "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
133 "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
134 "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
135 "clap_derive 0.3.0 (git+https://github.com/clap-rs/clap_derive)",
136 "indexmap 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
137 "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
138 "textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
139 "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
140 "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
141]
142
143[[package]]
144name = "clap-log-flag" 128name = "clap-log-flag"
145version = "0.1.0" 129version = "0.1.0"
146source = "registry+https://github.com/rust-lang/crates.io-index" 130source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -164,16 +148,6 @@ dependencies = [
164] 148]
165 149
166[[package]] 150[[package]]
167name = "clap_derive"
168version = "0.3.0"
169source = "git+https://github.com/clap-rs/clap_derive#2fad2c8ae4b5c61a2bf343b4eed636d60bb161bf"
170dependencies = [
171 "proc-macro2 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)",
172 "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
173 "syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)",
174]
175
176[[package]]
177name = "cloudabi" 151name = "cloudabi"
178version = "0.0.3" 152version = "0.0.3"
179source = "registry+https://github.com/rust-lang/crates.io-index" 153source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -298,11 +272,6 @@ dependencies = [
298] 272]
299 273
300[[package]] 274[[package]]
301name = "indexmap"
302version = "1.0.1"
303source = "registry+https://github.com/rust-lang/crates.io-index"
304
305[[package]]
306name = "itertools" 275name = "itertools"
307version = "0.7.8" 276version = "0.7.8"
308source = "registry+https://github.com/rust-lang/crates.io-index" 277source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -602,7 +571,7 @@ dependencies = [
602name = "set_eq" 571name = "set_eq"
603version = "0.1.0" 572version = "0.1.0"
604dependencies = [ 573dependencies = [
605 "clap 3.0.0-alpha.1 (git+https://github.com/kbknapp/clap-rs?branch=v3-master)", 574 "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
606 "clap-log-flag 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 575 "clap-log-flag 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
607 "clap-verbosity-flag 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 576 "clap-verbosity-flag 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
608 "dbus 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", 577 "dbus 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -865,10 +834,8 @@ dependencies = [
865"checksum cc 1.0.23 (registry+https://github.com/rust-lang/crates.io-index)" = "c37f0efaa4b9b001fa6f02d4b644dee4af97d3414df07c51e3e4f015f3a3e131" 834"checksum cc 1.0.23 (registry+https://github.com/rust-lang/crates.io-index)" = "c37f0efaa4b9b001fa6f02d4b644dee4af97d3414df07c51e3e4f015f3a3e131"
866"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3" 835"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3"
867"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" 836"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
868"checksum clap 3.0.0-alpha.1 (git+https://github.com/kbknapp/clap-rs?branch=v3-master)" = "<none>"
869"checksum clap-log-flag 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b05213138aad9c0f820773c51e829eae4189986435aa5c115a6465b385892a5" 837"checksum clap-log-flag 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b05213138aad9c0f820773c51e829eae4189986435aa5c115a6465b385892a5"
870"checksum clap-verbosity-flag 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bda14f5323b2b747f52908c5b7b8af7790784088bc7c2957a11695e39ad476dc" 838"checksum clap-verbosity-flag 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bda14f5323b2b747f52908c5b7b8af7790784088bc7c2957a11695e39ad476dc"
871"checksum clap_derive 0.3.0 (git+https://github.com/clap-rs/clap_derive)" = "<none>"
872"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" 839"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
873"checksum dbus 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3e34c238dfb3f5881d46ad301403cd8f8ecf946e2a4e89bdd1166728b68b5008" 840"checksum dbus 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3e34c238dfb3f5881d46ad301403cd8f8ecf946e2a4e89bdd1166728b68b5008"
874"checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a" 841"checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a"
@@ -885,7 +852,6 @@ dependencies = [
885"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" 852"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
886"checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d" 853"checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d"
887"checksum humantime 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0484fda3e7007f2a4a0d9c3a703ca38c71c54c55602ce4660c419fd32e188c9e" 854"checksum humantime 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0484fda3e7007f2a4a0d9c3a703ca38c71c54c55602ce4660c419fd32e188c9e"
888"checksum indexmap 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08173ba1e906efb6538785a8844dd496f5d34f0a2d88038e95195172fc667220"
889"checksum itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)" = "f58856976b776fedd95533137617a02fb25719f40e7d9b01c7043cd65474f450" 855"checksum itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)" = "f58856976b776fedd95533137617a02fb25719f40e7d9b01c7043cd65474f450"
890"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" 856"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
891"checksum lalrpop 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ba451f7bd819b7afc99d4cf4bdcd5a4861e64955ba9680ac70df3a50625ad6cf" 857"checksum lalrpop 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ba451f7bd819b7afc99d4cf4bdcd5a4861e64955ba9680ac70df3a50625ad6cf"
diff --git a/Cargo.toml b/Cargo.toml
index 7a9cbb3..e60c8dd 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,7 +9,8 @@ lalrpop = "0.15.2"
9[dependencies] 9[dependencies]
10dbus = "0.6.2" 10dbus = "0.6.2"
11 11
12clap = { git = "https://github.com/kbknapp/clap-rs", branch = "v3-master" } 12#clap = { git = "https://github.com/kbknapp/clap-rs", branch = "v3-master" }
13clap = "*"
13clap-verbosity-flag = "0.2" 14clap-verbosity-flag = "0.2"
14clap-log-flag = "0.1" 15clap-log-flag = "0.1"
15structopt = "0.2" 16structopt = "0.2"
diff --git a/src/main.rs b/src/main.rs
index 171fe3c..8edc760 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,6 +9,7 @@ extern crate failure;
9extern crate clap; 9extern crate clap;
10extern crate clap_log_flag; 10extern crate clap_log_flag;
11extern crate clap_verbosity_flag; 11extern crate clap_verbosity_flag;
12#[macro_use]
12extern crate structopt; 13extern crate structopt;
13 14
14mod dbus_api; 15mod dbus_api;
@@ -109,7 +110,17 @@ impl Filter {
109 } 110 }
110} 111}
111 112
112fn main() -> Result<(), Error> { 113fn main() {
114 match start() {
115 Ok(()) => (),
116 Err(err) => {
117 eprintln!("Error: {}", err);
118 std::process::exit(-1);
119 }
120 }
121}
122
123fn start() -> Result<(), Error> {
113 let args = Cli::from_args(); 124 let args = Cli::from_args();
114 args.log.log_all(args.verbose.log_level())?; 125 args.log.log_all(args.verbose.log_level())?;
115 126
@@ -142,8 +153,8 @@ fn load(args: LoadCli) -> Result<(), Error> {
142 153
143 let filter = if args.file == "-" { 154 let filter = if args.file == "-" {
144 let stdin = io::stdin(); 155 let stdin = io::stdin();
145 let mut lock = stdin.lock(); 156 let mut handle = stdin.lock();
146 read_filter(&mut lock)? 157 read_filter(&mut handle)?
147 } else { 158 } else {
148 let mut file = File::open(args.file)?; 159 let mut file = File::open(args.file)?;
149 read_filter(&mut file)? 160 read_filter(&mut file)?
diff --git a/src/parsing/equalizer_apo.lalrpop b/src/parsing/equalizer_apo.lalrpop
index b1faad9..39dda67 100644
--- a/src/parsing/equalizer_apo.lalrpop
+++ b/src/parsing/equalizer_apo.lalrpop
@@ -6,7 +6,7 @@ grammar;
6 6
7pub Main: Filter = { 7pub Main: Filter = {
8 <preamp: Preamp> <eq: Eq> => { 8 <preamp: Preamp> <eq: Eq> => {
9 let coefficients: Vec<_> = eq.1.iter().map(|decibel| 10f64.powf(decibel / 10f64)).collect(); 9 let coefficients: Vec<_> = eq.1.iter().map(|decibel| 10f64.powf(decibel / 10f64).sqrt()).collect();
10 // TODO: add decibel_to_ratio conversion function 10 // TODO: add decibel_to_ratio conversion function
11 let preamp = 10f64.powf(preamp / 10f64); 11 let preamp = 10f64.powf(preamp / 10f64);
12 Filter { preamp, frequencies: eq.0, coefficients } 12 Filter { preamp, frequencies: eq.0, coefficients }
diff --git a/src/parsing/equalizer_apo.rs b/src/parsing/equalizer_apo.rs
index 3fab396..a24cf99 100644
--- a/src/parsing/equalizer_apo.rs
+++ b/src/parsing/equalizer_apo.rs
@@ -1,5 +1,5 @@
1// auto-generated: "lalrpop 0.15.2" 1// auto-generated: "lalrpop 0.15.2"
2// sha256: 81b6fa5856d7887b20715c2c7f6137db1927ece087e2db9f4bf1fcd8943365c5 2// sha256: a735e8f9bd5cf5f3aac915d12b24752d366481c3952258e22871eef395f44
3use ::Filter; 3use ::Filter;
4use std::str::FromStr; 4use std::str::FromStr;
5#[allow(unused_extern_crates)] 5#[allow(unused_extern_crates)]
@@ -880,7 +880,7 @@ fn __action1<
880) -> Filter 880) -> Filter
881{ 881{
882 { 882 {
883 let coefficients: Vec<_> = eq.1.iter().map(|decibel| 10f64.powf(decibel / 10f64)).collect(); 883 let coefficients: Vec<_> = eq.1.iter().map(|decibel| 10f64.powf(decibel / 10f64).sqrt()).collect();
884 // TODO: add decibel_to_ratio conversion function 884 // TODO: add decibel_to_ratio conversion function
885 let preamp = 10f64.powf(preamp / 10f64); 885 let preamp = 10f64.powf(preamp / 10f64);
886 Filter { preamp, frequencies: eq.0, coefficients } 886 Filter { preamp, frequencies: eq.0, coefficients }
diff --git a/src/utils.rs b/src/utils.rs
index 6d7ae58..66ccae4 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -46,7 +46,7 @@ pub fn send_filter(conn_sink: &ConnPath<&Connection>, filter: Filter) -> Result<
46 Ok(()) 46 Ok(())
47} 47}
48 48
49pub fn read_filter(file: &mut impl io::Read) -> Result<Filter, Error> { 49pub fn read_filter<T>(file: &mut T) -> Result<Filter, Error> where T: io::Read {
50 let mut buffer = String::new(); 50 let mut buffer = String::new();
51 51
52 info!("Reading filter in GraphicEQ format from the command line"); 52 info!("Reading filter in GraphicEQ format from the command line");