From 9c608c77f950f871cb6abe5c0ffed99b8e70393d Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 23 Mar 2022 17:37:40 +0100 Subject: [PATCH] Add formatters for bypass parameters --- src/formatters.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/formatters.rs b/src/formatters.rs index f2b51322..0b13f187 100644 --- a/src/formatters.rs +++ b/src/formatters.rs @@ -137,3 +137,29 @@ pub fn from_i32_note_formatter() -> Arc Option + Send + Syn Some((octave + 1) + (12 * note_id)) }) } + +/// Display 'Bypassed' or 'Not Bypassed' depending on whether the parameter is true or false. +/// 'Enabled' would have also been a possibilty here, but that could be a bit confusing. +pub fn bool_bypass() -> Arc String + Send + Sync> { + Arc::new(move |value| { + if value { + String::from("Bypassed") + } else { + String::from("Not Bypassed") + } + }) +} + +/// Parse a string in the same format as [`bool_bypass`]. +pub fn from_bool_bypass() -> Arc Option + Send + Sync> { + Arc::new(|string| { + let string = string.trim(); + if string.eq_ignore_ascii_case("bypass") { + Some(true) + } else if string.eq_ignore_ascii_case("not bypassed") { + Some(false) + } else { + None + } + }) +}