From bdb4a0148719308420bfc21f2a709a43209232c3 Mon Sep 17 00:00:00 2001 From: Dennis Date: Mon, 26 Nov 2018 13:11:51 +0100 Subject: [PATCH] Added append key feature By adding this feature, all initially planned functionality is now covered by the application. --- src/main.rs | 4 ++++ src/pedal_operations.rs | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/main.rs b/src/main.rs index 7914622..e979f19 100644 --- a/src/main.rs +++ b/src/main.rs @@ -225,7 +225,11 @@ fn main() { match cmd { Append::AppendKey { pedal, input } => { + check_length(&pedal, &input); + for (i, pedal) in pedal.iter().enumerate() { + pedals.append_key(*pedal as usize, input[i].as_str()); + } }, Append::AppendString { pedal, input } => { diff --git a/src/pedal_operations.rs b/src/pedal_operations.rs index 6ea97b1..15f397f 100644 --- a/src/pedal_operations.rs +++ b/src/pedal_operations.rs @@ -264,6 +264,20 @@ impl Pedals { } } + pub fn append_key(& mut self, ped:usize, key:&str) { + if let Some(encoded_key) = key_operations::encode_byte(key) { + self.set_type(ped, Type::String); + + let mut key = Vec::new(); + key.push(encoded_key); + + self.compile_string_data(ped,key); + } + else { + error!("Key '{}' is not recognized! Please provide a valid key, listed in './footswitch-rs --listkeys 4'", key); + } + } + pub fn set_modifier(& mut self, ped:usize, modifier:&str) { let modifier = match key_operations::Modifier::str_to_enum(modifier) { Some(x) => x, @@ -403,6 +417,16 @@ impl Pedals { }, Some(Type::String) => { self.set_type(*ped as usize, Type::String); + + // Start byte should be 2 + let mut key_vec = Vec::new(); + for (i, c) in key_value.iter().enumerate() { + if i >= 2 && *c != 0 { + key_vec.push(*c); + } + } + + self.compile_string_data(*ped as usize, key_vec); }, None => error!("The key type which was returned by the pedal was invalid!"),