diff --git a/src/lib.rs b/src/lib.rs index bbf7a6f..327d6e2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -241,7 +241,7 @@ impl GlobalParams { }, ) .with_value_to_string(Del2::v2s_f32_ms_then_s(3)) - .with_string_to_value(Del2::s2v_f32_ms_then_s()), + .with_string_to_value(Del2::s2v_f32_s_or_ms_if_bigger_than(5_000.0)), release_ms: FloatParam::new( "Release", 13.0, @@ -252,7 +252,7 @@ impl GlobalParams { }, ) .with_value_to_string(Del2::v2s_f32_ms_then_s(3)) - .with_string_to_value(Del2::s2v_f32_ms_then_s()), + .with_string_to_value(Del2::s2v_f32_s_or_ms_if_bigger_than(20_000.0)), min_tap_milliseconds: FloatParam::new( "min tap", 13.0, @@ -263,7 +263,7 @@ impl GlobalParams { }, ) .with_value_to_string(Del2::v2s_f32_ms_then_s(3)) - .with_string_to_value(Del2::s2v_f32_ms_then_s()), + .with_string_to_value(Del2::s2v_f32_s_or_ms_if_bigger_than(1000.0)), max_tap_ms: FloatParam::new( "max tap", 3030.0, @@ -274,7 +274,9 @@ impl GlobalParams { }, ) .with_value_to_string(Del2::v2s_f32_ms_then_s(3)) - .with_string_to_value(Del2::s2v_f32_ms_then_s()), + .with_string_to_value(Del2::s2v_f32_s_or_ms_if_bigger_than( + MAX_TAP_SECONDS as f32 * 1000.0, + )), channel: IntParam::new( "channel", @@ -1529,6 +1531,48 @@ impl Del2 { }) } + // TODO: test, when skia vizia fixes the bug where it won't go into text mode + fn s2v_f32_s_or_ms_if_bigger_than( + max_val: f32, + ) -> Arc Option + Send + Sync> { + Arc::new(move |string| { + let string = string.trim().to_lowercase(); + + if let Some(ms_value_str) = string + .strip_suffix("ms") + .or_else(|| string.strip_suffix(" ms")) + { + // Explicitly specified as milliseconds + return ms_value_str.trim().parse::().ok(); + } + + if let Some(s_value_str) = string + .strip_suffix("s") + .or_else(|| string.strip_suffix(" s")) + { + // Explicitly specified as seconds + return s_value_str.trim().parse::().ok().map(|s| { + let ms_value = s * 1000.0; + if ms_value > max_val { + ms_value // Treat it as milliseconds + } else { + s // Keep as seconds if the milliseconds value isn't greater than max_val + } + }); + } + + // If no specification, interpret as seconds and check + string.parse::().ok().map(|val| { + let ms_value = val * 1000.0; + if ms_value > max_val { + ms_value // Treat it as milliseconds + } else { + val // Keep as seconds + } + }) + }) + } + fn s2v_f32_ms_then_s() -> Arc Option + Send + Sync> { Arc::new(move |string| { let string = string.trim().to_lowercase();