Skip to content

Commit

Permalink
update dependencies, bump version
Browse files Browse the repository at this point in the history
- bump to 2021 edition.
- bump dependencies.
- fix most clippy warnings.
- refactor modules.
- rustfmt.
  • Loading branch information
joseluis committed Dec 17, 2021
1 parent 46041c9 commit 6c8fce3
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 97 deletions.
41 changes: 31 additions & 10 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
[alias]

# CHECK
cl = "clippy"

# DOC
d = "doc --no-deps"
do = "doc --no-deps --open"
dd = "doc"
ddo = "doc --open"

# BUILD
b = "build"
br = "build --release"
bb = "build --bin"
be = "build --example"
bq = "build --quiet"
br = "build --release"
bqb = "build --quiet --bin"
bqe = "build --quiet --example"
brb = "build --release --bin"
bre = "build --release --example"
brqb = "build --release --quiet --bin"
brqe = "build --release --quiet --example"

# RUN
r = "run"
rr = "run --release"
rq = "run --quiet"
rb = "run --bin"
re = "run --example"
rq = "run --quiet"
rr = "run --release"
rqb = "run --quiet --bin"
rqe = "run --quiet --example"
req = "rqe"

# DOC
d = "doc --no-deps"
do = "doc --no-deps --open"
rrb = "run --release --bin"
rre = "run --release --example"
rrqb = "run --release --quiet --bin"
rrqe = "run --release --quiet --example"

# TEST
t = "test -- --test-threads 1 --nocapture"
#t = "test -- --nocapture"
t = "test -- --nocapture"
t1 = "test -- --test-threads 1 --nocapture"

[build]
# rustdocflags = [ "--html-in-header", "./src/docs-header.html"]
13 changes: 6 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "sofiza"
description = "SFZ format parser"
version = "0.2.2"
edition = "2018"
version = "0.2.3"
edition = "2021"
authors = ["José Luis Cruz <[email protected]>"]
repository = "https://github.com/andamira/sofiza"
license = "MIT/Apache-2.0"
Expand All @@ -18,17 +18,16 @@ categories = ["parser-implementations", "multimedia::audio"]
keywords = ["parser", "audio", "virtual", "music", "instrument"]

[dependencies]
logos = "0.12"
logos = "^0.12"
regex = "1"

phf = { version = "0.8", features = ["macros"] }
phf = { version = "^0.10", features = ["macros"] }

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

thiserror = "1.0"

thiserror = "^1.0"

[dev-dependencies]
anyhow = "1.0"
anyhow = "^1.0"
8 changes: 2 additions & 6 deletions src/sfz/group.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::HashMap;
use std::fmt::Debug;

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

impl Group {
pub fn new() -> Self {
Self {
opcodes: HashMap::new(),
label: String::new(),
}
Self::default()
}

pub fn add_opcode(&mut self, o: &Opcode) {
Expand Down
20 changes: 14 additions & 6 deletions src/sfz/instrument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ pub struct Instrument {
last_header_created: Header,
}

impl Default for Instrument {
fn default() -> Self {
Self::new()
}
}

// constructors:
// - new
// - from_file
Expand Down Expand Up @@ -107,7 +113,7 @@ impl Instrument {
let mut status = InstrumentParsingStatus::init();

// parser loop
let lex = SfzToken::lexer(&sfz);
let lex = SfzToken::lexer(sfz);
for t in lex {
match &t {
SfzToken::Header(h) => {
Expand Down Expand Up @@ -152,9 +158,8 @@ impl Instrument {

// an opcode for <control>
} else if status.is_header_control {
match o {
Opcode::default_path(p) => instrument.default_path.push(p),
_ => (),
if let Opcode::default_path(p) = o {
instrument.default_path.push(p)
}
} else {
// an opcode for the <region>
Expand Down Expand Up @@ -199,7 +204,10 @@ impl Instrument {
///
pub fn add_opcode(&mut self, opcode: &Opcode) -> Result<()> {
match self.last_header_created {
Header::Global => Ok(self.add_opcode_global(opcode)),
Header::Global => {
self.add_opcode_global(opcode);
Ok(())
}
Header::Group => self.add_opcode_to_group(opcode, self.groups() - 1),
Header::Region => self.add_opcode_to_region(opcode, self.regions() - 1),
_ => Err(Error::Generic),
Expand Down Expand Up @@ -329,7 +337,7 @@ impl Instrument {
}

// TODO:
pub fn groups_iter(&self) -> () {}
pub fn groups_iter(&self) {}
}

/// The current status of the parsing of the instrument
Expand Down
File renamed without changes.
File renamed without changes.
97 changes: 45 additions & 52 deletions src/sfz/opcodes/parse.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::path::PathBuf;

use logos::{Lexer, Logos};
use regex::Regex;

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

// Tries to find numeric parameters embedded in the name
let lex_numbers = OpcodeParameter::lexer(&name);
let lex_numbers = OpcodeParameter::lexer(name);
for (n, span) in lex_numbers.spanned() {
match &n {
// If a parameter is found
OpcodeParameter::Parameter(p) => {
// constructs the new name of the opcode,
// with the numeric parameters being substituted by
// the N, X, Y chars, in that order.

let split_idx = span.start; // the index of current parameter in original name
// If a parameter is found
if let OpcodeParameter::Parameter(p) = &n {
// constructs the new name of the opcode,
// with the numeric parameters being substituted by
// the N, X, Y chars, in that order.

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

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

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

//println!("{} ({}) remainder: {}", &new_name, previous_span_end, remainder); // DEBUG

// TODO: check for numeric boundaries
//
// TODO NOTE
// 1. all opcodes ending in ccN has N = 0..=127 (or ccX when N is already used)
// (except some sfz2 and aria extensions, see:
// https://sfzformat.com/extensions/midi_ccs
//
// 2. each of these has N = 1..=3 (and X = 0..=127)
// eqN_bw
// eqN_bwccX
// eqN_freq
// eqN_freqccX
// eqN_vel2freq
// eqN_gain
// eqN_gainccX
// eqN_vel2gain

// Stores the numeric parameter
params.push(*p as u8);

par_num += 1;
previous_span_end = span.end;
// then handle the rest of the cases
} else {
new_name += &format!("{}{}", &first[previous_span_end..], par_char[par_num]);
}
_ => (),

//println!("{} ({}) remainder: {}", &new_name, previous_span_end, remainder); // DEBUG

// TODO: check for numeric boundaries
//
// TODO NOTE
// 1. all opcodes ending in ccN has N = 0..=127 (or ccX when N is already used)
// (except some sfz2 and aria extensions, see:
// https://sfzformat.com/extensions/midi_ccs
//
// 2. each of these has N = 1..=3 (and X = 0..=127)
// eqN_bw
// eqN_bwccX
// eqN_freq
// eqN_freqccX
// eqN_vel2freq
// eqN_gain
// eqN_gainccX
// eqN_vel2gain

// Stores the numeric parameter
params.push(*p as u8);

par_num += 1;
previous_span_end = span.end;
}
}

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

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

Expand Down Expand Up @@ -140,7 +134,7 @@ impl Opcode {

let slice = lex.slice();

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

Expand Down Expand Up @@ -206,9 +200,7 @@ impl Opcode {
utils::check_u16_between(value, 0, 9600).map(Opcode::pitch_random)
}
("rt_decay", _) => utils::check_f32_between(value, 0., 200.).map(Opcode::rt_decay),
("sample", _) => Some(Opcode::sample(PathBuf::from(utils::fix_path_separators(
value,
)))),
("sample", _) => Some(Opcode::sample(utils::fix_path_separators(value))),
("seq_lenght", _) => utils::check_u8_between(value, 1, 100).map(Opcode::seq_length),
("seq_position", _) => utils::check_u8_between(value, 1, 100).map(Opcode::seq_position),
("trigger", _) => trigger::from_str(value).map(Opcode::trigger),
Expand Down Expand Up @@ -298,6 +290,7 @@ pub(crate) enum OpcodeParameter {
mod tests_opcodes {
use super::*;
use logos::Logos;
use std::path::PathBuf;

#[test]
fn test_opcode_ampeg_attack() {
Expand Down
7 changes: 2 additions & 5 deletions src/sfz/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::sfz::{Opcode, OpcodeMap};
/// All Input Controls defined in a region act using the AND boolean operator.
/// Consequently, all conditions must be matched for the region to play.
///
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Region {
/// The opcodes of this group are applied and will override the defaults.
pub group: Option<usize>,
Expand All @@ -31,10 +31,7 @@ pub struct Region {

impl Region {
pub fn new() -> Self {
Self {
group: None,
opcodes: HashMap::new(),
}
Self::default()
}

// FIXME (add group at posteriori)
Expand Down
File renamed without changes.
Loading

0 comments on commit 6c8fce3

Please sign in to comment.