Skip to content

Commit b3accfa

Browse files
committed
Fix clippy and rustfmt findings
Rename Pair::from_fixed to shift_from_fixed, since a from_* method taking self trips wrong_self_convention, and gate the tuning playground's global state behind the wasm feature, which is all that uses it, so the crate builds without that feature and without dead-code errors.
1 parent 87c8210 commit b3accfa

4 files changed

Lines changed: 14 additions & 9 deletions

File tree

‎crates/recursive_ji_core/src/lib.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ const JUST_INTONATION: TuningSystem = TuningSystem::FiveLimit;
2222
const MAJOR_INTERVALS: &[i32] = &[0, 4, 7];
2323
const DOMINANT_INTERVALS: &[i32] = &[0, 4, 7, 10];
2424

25-
const TWELVE_TET: AnyTuningSystem =
26-
AnyTuningSystem::Fixed(TuningSystem::EQUAL_TEMPERAMENT);
25+
const TWELVE_TET: AnyTuningSystem = AnyTuningSystem::Fixed(TuningSystem::EQUAL_TEMPERAMENT);
2726

2827
const FIXED_C_JUST: AnyTuningSystem = AnyTuningSystem::Fixed(TuningSystem::FiveLimit);
2928

‎wasm/tuningplayground/src/lib.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! keyboard layout, and the name of the last chord engraved -- because the
88
//! page has one of each.
99
10+
#[cfg(feature = "wasm")]
1011
use std::sync::LazyLock;
1112
use std::sync::Mutex;
1213
#[cfg(feature = "wasm")]
@@ -18,12 +19,16 @@ pub mod scale;
1819

1920
use music21_rs::Pitch;
2021
use music21_rs::chord::Chord;
22+
#[cfg(any(feature = "wasm", test))]
2123
use scale::Scale;
2224

25+
#[cfg(feature = "wasm")]
2326
static CURRENT: LazyLock<Mutex<Scale>> = LazyLock::new(|| Mutex::new(Scale::default_scale()));
27+
#[cfg(feature = "wasm")]
2428
static KEYMAP: Mutex<KeyMap> = Mutex::new(KeyMap::Us);
2529
static CHORD_NAME: Mutex<String> = Mutex::new(String::new());
2630

31+
#[cfg(feature = "wasm")]
2732
fn current() -> std::sync::MutexGuard<'static, Scale> {
2833
CURRENT.lock().expect("couldn't lock the scale")
2934
}
@@ -133,6 +138,7 @@ pub const KEY_ROWS: [&[&str]; 4] = [
133138
],
134139
];
135140

141+
#[cfg(feature = "wasm")]
136142
fn to_json<T: serde::Serialize>(value: &T) -> String {
137143
serde_json::to_string(value).expect("the playground's types serialise")
138144
}
@@ -361,6 +367,7 @@ pub fn chord_details_core(input: &str) -> Result<String, String> {
361367
))
362368
}
363369

370+
#[cfg(any(feature = "wasm", test))]
364371
fn tuning_marked_hash_core(keys: &str) -> String {
365372
let mut keys = keys
366373
.split(',')

‎wasm/tuningplayground/src/recursive.rs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ impl Pair {
177177
global.root_hz * ratio_at(global, nearest_step(global, cents))
178178
}
179179

180-
fn from_fixed(&self, root: i64, step: i64) -> f64 {
180+
/// How far the recursive tuning moves a note from what the global scale plays for it, in cents.
181+
fn shift_from_fixed(&self, root: i64, step: i64) -> f64 {
181182
cents_of(self.frequency(root, step) / self.fixed_frequency(root, step))
182183
}
183184

@@ -233,7 +234,7 @@ impl Pair {
233234
let cells = (0..=columns_drawn)
234235
.map(|step| {
235236
let frequency = self.frequency(root, step);
236-
let from_fixed = self.from_fixed(root, step);
237+
let from_fixed = self.shift_from_fixed(root, step);
237238
largest_shift = largest_shift.max(from_fixed.abs());
238239
Cell {
239240
step,
@@ -387,8 +388,8 @@ mod tests {
387388
);
388389
}
389390
}
390-
assert!((just.from_fixed(4, 4) + 41.059).abs() < 1e-3);
391-
assert!((just.from_fixed(2, 7) - 21.506).abs() < 1e-3);
391+
assert!((just.shift_from_fixed(4, 4) + 41.059).abs() < 1e-3);
392+
assert!((just.shift_from_fixed(2, 7) - 21.506).abs() < 1e-3);
392393
}
393394

394395
/// A step of an equal division over a step is the step of their sum, so

‎wasm/tuningplayground/src/scale.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,7 @@ pub fn realize(id: &str, root_hz: f64) -> Result<Scale, String> {
381381
root_hz,
382382
);
383383
}
384-
let tuning: TuningSystem = id
385-
.parse()
386-
.map_err(|_| format!("no tuning is named {id}"))?;
384+
let tuning: TuningSystem = id.parse().map_err(|_| format!("no tuning is named {id}"))?;
387385
Ok(built_in(tuning, root_hz))
388386
}
389387

0 commit comments

Comments
 (0)