Skip to content

Commit 6c8fce3

Browse files
committed
update dependencies, bump version
- bump to 2021 edition. - bump dependencies. - fix most clippy warnings. - refactor modules. - rustfmt.
1 parent 46041c9 commit 6c8fce3

File tree

10 files changed

+111
-97
lines changed

10 files changed

+111
-97
lines changed

.cargo/config.toml

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,43 @@
11
[alias]
22

3+
# CHECK
4+
cl = "clippy"
5+
6+
# DOC
7+
d = "doc --no-deps"
8+
do = "doc --no-deps --open"
9+
dd = "doc"
10+
ddo = "doc --open"
11+
312
# BUILD
413
b = "build"
5-
br = "build --release"
14+
bb = "build --bin"
15+
be = "build --example"
616
bq = "build --quiet"
17+
br = "build --release"
18+
bqb = "build --quiet --bin"
19+
bqe = "build --quiet --example"
20+
brb = "build --release --bin"
21+
bre = "build --release --example"
22+
brqb = "build --release --quiet --bin"
23+
brqe = "build --release --quiet --example"
724

825
# RUN
926
r = "run"
10-
rr = "run --release"
11-
rq = "run --quiet"
27+
rb = "run --bin"
1228
re = "run --example"
29+
rq = "run --quiet"
30+
rr = "run --release"
31+
rqb = "run --quiet --bin"
1332
rqe = "run --quiet --example"
14-
req = "rqe"
15-
16-
# DOC
17-
d = "doc --no-deps"
18-
do = "doc --no-deps --open"
33+
rrb = "run --release --bin"
34+
rre = "run --release --example"
35+
rrqb = "run --release --quiet --bin"
36+
rrqe = "run --release --quiet --example"
1937

2038
# TEST
21-
t = "test -- --test-threads 1 --nocapture"
22-
#t = "test -- --nocapture"
39+
t = "test -- --nocapture"
40+
t1 = "test -- --test-threads 1 --nocapture"
41+
42+
[build]
43+
# rustdocflags = [ "--html-in-header", "./src/docs-header.html"]

Cargo.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "sofiza"
33
description = "SFZ format parser"
4-
version = "0.2.2"
5-
edition = "2018"
4+
version = "0.2.3"
5+
edition = "2021"
66
authors = ["José Luis Cruz <joseluis@andamira.net>"]
77
repository = "https://github.com/andamira/sofiza"
88
license = "MIT/Apache-2.0"
@@ -18,17 +18,16 @@ categories = ["parser-implementations", "multimedia::audio"]
1818
keywords = ["parser", "audio", "virtual", "music", "instrument"]
1919

2020
[dependencies]
21-
logos = "0.12"
21+
logos = "^0.12"
2222
regex = "1"
2323

24-
phf = { version = "0.8", features = ["macros"] }
24+
phf = { version = "^0.10", features = ["macros"] }
2525

2626
# change for the `!` type when it stabilizes:
2727
# https://github.com/rust-lang/rust/issues/35121
2828
never = "0.1"
2929

30-
thiserror = "1.0"
31-
30+
thiserror = "^1.0"
3231

3332
[dev-dependencies]
34-
anyhow = "1.0"
33+
anyhow = "^1.0"

src/sfz/group.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::collections::HashMap;
21
use std::fmt::Debug;
32

43
use crate::sfz::{Opcode, OpcodeMap};
@@ -8,7 +7,7 @@ use crate::sfz::{Opcode, OpcodeMap};
87
/// A group is defined with the <group> opcode, and the parameters enumerated
98
/// on it last till the next group opcode, or till the end of the file.
109
///
11-
#[derive(Debug)]
10+
#[derive(Debug, Default)]
1211
pub struct Group {
1312
/// This list of opcodes overwrites the default ones.
1413
pub opcodes: OpcodeMap,
@@ -19,10 +18,7 @@ pub struct Group {
1918

2019
impl Group {
2120
pub fn new() -> Self {
22-
Self {
23-
opcodes: HashMap::new(),
24-
label: String::new(),
25-
}
21+
Self::default()
2622
}
2723

2824
pub fn add_opcode(&mut self, o: &Opcode) {

src/sfz/instrument.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ pub struct Instrument {
4545
last_header_created: Header,
4646
}
4747

48+
impl Default for Instrument {
49+
fn default() -> Self {
50+
Self::new()
51+
}
52+
}
53+
4854
// constructors:
4955
// - new
5056
// - from_file
@@ -107,7 +113,7 @@ impl Instrument {
107113
let mut status = InstrumentParsingStatus::init();
108114

109115
// parser loop
110-
let lex = SfzToken::lexer(&sfz);
116+
let lex = SfzToken::lexer(sfz);
111117
for t in lex {
112118
match &t {
113119
SfzToken::Header(h) => {
@@ -152,9 +158,8 @@ impl Instrument {
152158

153159
// an opcode for <control>
154160
} else if status.is_header_control {
155-
match o {
156-
Opcode::default_path(p) => instrument.default_path.push(p),
157-
_ => (),
161+
if let Opcode::default_path(p) = o {
162+
instrument.default_path.push(p)
158163
}
159164
} else {
160165
// an opcode for the <region>
@@ -199,7 +204,10 @@ impl Instrument {
199204
///
200205
pub fn add_opcode(&mut self, opcode: &Opcode) -> Result<()> {
201206
match self.last_header_created {
202-
Header::Global => Ok(self.add_opcode_global(opcode)),
207+
Header::Global => {
208+
self.add_opcode_global(opcode);
209+
Ok(())
210+
}
203211
Header::Group => self.add_opcode_to_group(opcode, self.groups() - 1),
204212
Header::Region => self.add_opcode_to_region(opcode, self.regions() - 1),
205213
_ => Err(Error::Generic),
@@ -329,7 +337,7 @@ impl Instrument {
329337
}
330338

331339
// TODO:
332-
pub fn groups_iter(&self) -> () {}
340+
pub fn groups_iter(&self) {}
333341
}
334342

335343
/// The current status of the parsing of the instrument
File renamed without changes.

src/sfz/opcodes/parse.rs

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::path::PathBuf;
2-
31
use logos::{Lexer, Logos};
42
use regex::Regex;
53

@@ -36,57 +34,53 @@ impl Opcode {
3634
let mut remainder = String::new(); // the remainder opcode name after the current parameter
3735

3836
// Tries to find numeric parameters embedded in the name
39-
let lex_numbers = OpcodeParameter::lexer(&name);
37+
let lex_numbers = OpcodeParameter::lexer(name);
4038
for (n, span) in lex_numbers.spanned() {
41-
match &n {
42-
// If a parameter is found
43-
OpcodeParameter::Parameter(p) => {
44-
// constructs the new name of the opcode,
45-
// with the numeric parameters being substituted by
46-
// the N, X, Y chars, in that order.
47-
48-
let split_idx = span.start; // the index of current parameter in original name
39+
// If a parameter is found
40+
if let OpcodeParameter::Parameter(p) = &n {
41+
// constructs the new name of the opcode,
42+
// with the numeric parameters being substituted by
43+
// the N, X, Y chars, in that order.
4944

50-
let (first, last) = name.split_at(split_idx);
51-
remainder = last[span.end - span.start..].to_string();
45+
let split_idx = span.start; // the index of current parameter in original name
5246

53-
// first handle the special case of 4 opcodes with an "NN" parameter:
54-
// (varNN_mod, varNN_onccX, varNN_curveccX, varNN_target)
55-
if par_num == 0 && Regex::new(r"^var").unwrap().is_match(&name) {
56-
new_name += &format!("{}NN", &first[previous_span_end..]);
47+
let (first, last) = name.split_at(split_idx);
48+
remainder = last[span.end - span.start..].to_string();
5749

58-
// then handle the rest of the cases
59-
} else {
60-
new_name +=
61-
&format!("{}{}", &first[previous_span_end..], par_char[par_num]);
62-
}
50+
// first handle the special case of 4 opcodes with an "NN" parameter:
51+
// (varNN_mod, varNN_onccX, varNN_curveccX, varNN_target)
52+
if par_num == 0 && Regex::new(r"^var").unwrap().is_match(name) {
53+
new_name += &format!("{}NN", &first[previous_span_end..]);
6354

64-
//println!("{} ({}) remainder: {}", &new_name, previous_span_end, remainder); // DEBUG
65-
66-
// TODO: check for numeric boundaries
67-
//
68-
// TODO NOTE
69-
// 1. all opcodes ending in ccN has N = 0..=127 (or ccX when N is already used)
70-
// (except some sfz2 and aria extensions, see:
71-
// https://sfzformat.com/extensions/midi_ccs
72-
//
73-
// 2. each of these has N = 1..=3 (and X = 0..=127)
74-
// eqN_bw
75-
// eqN_bwccX
76-
// eqN_freq
77-
// eqN_freqccX
78-
// eqN_vel2freq
79-
// eqN_gain
80-
// eqN_gainccX
81-
// eqN_vel2gain
82-
83-
// Stores the numeric parameter
84-
params.push(*p as u8);
85-
86-
par_num += 1;
87-
previous_span_end = span.end;
55+
// then handle the rest of the cases
56+
} else {
57+
new_name += &format!("{}{}", &first[previous_span_end..], par_char[par_num]);
8858
}
89-
_ => (),
59+
60+
//println!("{} ({}) remainder: {}", &new_name, previous_span_end, remainder); // DEBUG
61+
62+
// TODO: check for numeric boundaries
63+
//
64+
// TODO NOTE
65+
// 1. all opcodes ending in ccN has N = 0..=127 (or ccX when N is already used)
66+
// (except some sfz2 and aria extensions, see:
67+
// https://sfzformat.com/extensions/midi_ccs
68+
//
69+
// 2. each of these has N = 1..=3 (and X = 0..=127)
70+
// eqN_bw
71+
// eqN_bwccX
72+
// eqN_freq
73+
// eqN_freqccX
74+
// eqN_vel2freq
75+
// eqN_gain
76+
// eqN_gainccX
77+
// eqN_vel2gain
78+
79+
// Stores the numeric parameter
80+
params.push(*p as u8);
81+
82+
par_num += 1;
83+
previous_span_end = span.end;
9084
}
9185
}
9286

@@ -95,7 +89,7 @@ impl Opcode {
9589
new_name = name.to_string();
9690

9791
// In case there's a remainder after the last parameter, append it
98-
} else if remainder.len() > 0 {
92+
} else if !remainder.is_empty() {
9993
new_name += &remainder;
10094
}
10195

@@ -140,7 +134,7 @@ impl Opcode {
140134

141135
let slice = lex.slice();
142136

143-
let kv: Vec<&str> = slice.splitn(2, "=").collect();
137+
let kv: Vec<&str> = slice.splitn(2, '=').collect();
144138
let (opcode, value) = (kv[0], kv[1]);
145139
let value = value.trim(); // remove possible remaining CRLF chars
146140

@@ -206,9 +200,7 @@ impl Opcode {
206200
utils::check_u16_between(value, 0, 9600).map(Opcode::pitch_random)
207201
}
208202
("rt_decay", _) => utils::check_f32_between(value, 0., 200.).map(Opcode::rt_decay),
209-
("sample", _) => Some(Opcode::sample(PathBuf::from(utils::fix_path_separators(
210-
value,
211-
)))),
203+
("sample", _) => Some(Opcode::sample(utils::fix_path_separators(value))),
212204
("seq_lenght", _) => utils::check_u8_between(value, 1, 100).map(Opcode::seq_length),
213205
("seq_position", _) => utils::check_u8_between(value, 1, 100).map(Opcode::seq_position),
214206
("trigger", _) => trigger::from_str(value).map(Opcode::trigger),
@@ -298,6 +290,7 @@ pub(crate) enum OpcodeParameter {
298290
mod tests_opcodes {
299291
use super::*;
300292
use logos::Logos;
293+
use std::path::PathBuf;
301294

302295
#[test]
303296
fn test_opcode_ampeg_attack() {

src/sfz/region.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::sfz::{Opcode, OpcodeMap};
2020
/// All Input Controls defined in a region act using the AND boolean operator.
2121
/// Consequently, all conditions must be matched for the region to play.
2222
///
23-
#[derive(Debug)]
23+
#[derive(Debug, Default)]
2424
pub struct Region {
2525
/// The opcodes of this group are applied and will override the defaults.
2626
pub group: Option<usize>,
@@ -31,10 +31,7 @@ pub struct Region {
3131

3232
impl Region {
3333
pub fn new() -> Self {
34-
Self {
35-
group: None,
36-
opcodes: HashMap::new(),
37-
}
34+
Self::default()
3835
}
3936

4037
// FIXME (add group at posteriori)
File renamed without changes.

0 commit comments

Comments
 (0)