From 6966d00dd7140bbf29a0ad9ba3cbd35e3717ebbb Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sat, 12 Nov 2022 01:28:47 +0100 Subject: [PATCH] Fix cents in s2v_f32_hz_then_khz() The trimming was not done correctly, and cents were treated as partial octaves. --- src/formatters.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/formatters.rs b/src/formatters.rs index d8413857..08bebd7e 100644 --- a/src/formatters.rs +++ b/src/formatters.rs @@ -183,15 +183,15 @@ pub fn s2v_f32_hz_then_khz() -> Arc Option + Send + Sync> { if let Some((midi_note_number_str, cents_str)) = string.split_once(',') { // If it contains a comma we'll also try parsing cents let cents_str = cents_str - .trim_start_matches([' ', '+', 'c', 'e', 'n', 't', 's', '.']) - .trim_end(); + .trim_start_matches([' ', '+']) + .trim_end_matches([' ', 'C', 'c', 'E', 'e', 'N', 'n', 'T', 't', 'S', 's', '.']); if let (Some(midi_note_number), Ok(cents)) = ( note_formatter(midi_note_number_str), cents_str.parse::(), ) { let plain_note_freq = util::f32_midi_note_to_freq(midi_note_number as f32); - let cents_multiplier = 2.0f32.powf(cents as f32 / 100.0); + let cents_multiplier = 2.0f32.powf(cents as f32 / 100.0 / 12.0); return Some(plain_note_freq * cents_multiplier); } } else if let Some(midi_note_number) = note_formatter(string) {