diff --git a/Formatting.txt b/Formatting.txt index be4f843..827cfb2 100644 --- a/Formatting.txt +++ b/Formatting.txt @@ -12,12 +12,16 @@ midi_key_down_id \/ 8323216,0,65 <- key_action //this would output "a" /\ - key_indedification + keymode_indedification -Alternativity you could type the following for the same result: -8323216, 0, 'a' -8323216, 0, " " -8323216, 0, a +Alternativity, you could type the following for the same result: +8323216, 0, 'a' <- character +8323216, 0, "a" <- string +8323216, a <- simple character + +Spaces between commas are optional. +If the intended mode is '0', then you can skip writing it as the program will use that mode as standard as long its not a string formation. +String are standards as macro and will assume that mode when the second variable is a string. Macro actions: @@ -28,9 +32,11 @@ midi_key_down_id /\ macro_indedification -A macro is identified by having the midi_key_up_id set to 0. A positive ID is key_down and a negative is key_up. +Alternatively, you can use a string format to more easily achieve this: +8323216,1,"abc" //types abc + Single key action with 'F24' as addon key (useful when using this program together with AutoHotkey): @@ -38,4 +44,4 @@ midi_key_down_id \/ 8323216,2,66 <- key_action //in this case 'b' /\ - key_indedification \ No newline at end of file + keyAddon_indedification \ No newline at end of file diff --git a/MIDI-Keyboard/miscellaneous/Miscellaneous.cs b/MIDI-Keyboard/miscellaneous/Miscellaneous.cs index a68be09..9de8d56 100644 --- a/MIDI-Keyboard/miscellaneous/Miscellaneous.cs +++ b/MIDI-Keyboard/miscellaneous/Miscellaneous.cs @@ -7,7 +7,7 @@ internal static class Miscellaneous public static int GetId(char c) { int cId = c; - if (c > 106 && c < 123) + if (c > 96 && c < 123) cId -= 32; return cId; diff --git a/MIDI-Keyboard/programChapter/OutViewerVisual.cs b/MIDI-Keyboard/programChapter/OutViewerVisual.cs index fa21e31..4def544 100644 --- a/MIDI-Keyboard/programChapter/OutViewerVisual.cs +++ b/MIDI-Keyboard/programChapter/OutViewerVisual.cs @@ -39,27 +39,21 @@ public static bool OutViewerVisual_(bool runOutViewerVisual_) int[][] linesInt; { + //list available profiles string profilePath = Settings.data.visual_profiles_path; - - bool exists = Directory.Exists(profilePath); + bool exists = Directory.Exists(profilePath); if (!exists) Directory.CreateDirectory(profilePath); - string[] files = Directory.GetFiles(profilePath); - Console.ForegroundColor = ConsoleColor.Black; for (int i = 0; i < files.Length; i++) { - if (i % 2 == 0) - Console.BackgroundColor = ConsoleColor.Gray; - else - Console.BackgroundColor = ConsoleColor.White; - + Console.BackgroundColor = i % 2 == 0 ? ConsoleColor.Gray : ConsoleColor.White; Console.WriteLine(i + ".\t" + files[i].Split('\\')[1].PadRight(32, ' ')); } Console.ResetColor(); int.TryParse(Console.ReadLine(), out int datat); - profilePath = files[datat]; + profilePath = files[datat]; //get profile path string[] lines = File.ReadAllLines(profilePath, Encoding.UTF8); diff --git a/MIDI-Keyboard/programChapter/run/KeyMode.cs b/MIDI-Keyboard/programChapter/run/KeyMode.cs index 9fc227b..7660154 100644 --- a/MIDI-Keyboard/programChapter/run/KeyMode.cs +++ b/MIDI-Keyboard/programChapter/run/KeyMode.cs @@ -26,14 +26,14 @@ private static string AddonButton(bool keyStatus) return " + " + addonButtonKey; } - public static void Key(int id, string valueHex) + public static void Key(int id, string valueHex) //id: 0 { var sb = new StringBuilder(); var key = (VirtualKeyCode) Program.values[id][2]; - if (valueHex.Length > 4) { + if (valueHex.Length > 4) { //on key down sb.Append("Key_Down '"); IS.Keyboard.KeyDown(key); - } else { + } else { //on key up sb.Append("Key_Up '"); IS.Keyboard.KeyUp(key); } @@ -43,7 +43,29 @@ public static void Key(int id, string valueHex) Console.WriteLine(sb); } - public static void Addonkey(int id, string valueHex) + public static void Macro(int id, string valueHex) //id: 1 + { + if (valueHex.Length <= 4) return; //only run macro on midi key down. + var sb = new StringBuilder("macro '"); + for (int k = 2; k < Program.values[id].Length; k++) + if (Program.values[id][k] > 0) { + var key = (VirtualKeyCode) Program.values[id][k]; + IS.Keyboard.KeyDown(key); + sb.Append("+"); + sb.Append(key.ToString()); + sb.Append('\''); + } else { + var key = (VirtualKeyCode) (-Program.values[id][k]); + IS.Keyboard.KeyUp(key); + sb.Append(key.ToString()); + sb.Append('\''); + } + + sb.Append(" on:"); + Console.WriteLine(sb); + } + + public static void Addonkey(int id, string valueHex) //id: 2 { var sb = new StringBuilder(); var key = (VirtualKeyCode) Program.values[id][2]; @@ -62,28 +84,5 @@ public static void Addonkey(int id, string valueHex) sb.Append("' on:"); Console.WriteLine(sb); } - - public static void Macro(int id, string valueHex) - { - if (valueHex.Length > 4) { - var sb = new StringBuilder("macro '"); - for (int k = 2; k < Program.values[id].Length; k++) - if (Program.values[id][k] > 0) { - var key = (VirtualKeyCode) Program.values[id][k]; - IS.Keyboard.KeyDown(key); - sb.Append("+"); - sb.Append(key.ToString()); - sb.Append('\''); - } else { - var key = (VirtualKeyCode) (-Program.values[id][k]); - IS.Keyboard.KeyUp(key); - sb.Append(key.ToString()); - sb.Append('\''); - } - - sb.Append(" on:"); - Console.WriteLine(sb); - } - } } } \ No newline at end of file diff --git a/MIDI-Keyboard/programChapter/run/LoadData.cs b/MIDI-Keyboard/programChapter/run/LoadData.cs index dd65e8e..dbd86dd 100644 --- a/MIDI-Keyboard/programChapter/run/LoadData.cs +++ b/MIDI-Keyboard/programChapter/run/LoadData.cs @@ -75,55 +75,135 @@ private static bool LoadKeyData() Console.WriteLine("loading from file..."); int chanel = int.Parse(rawData[0].Split(',')[0]); - for (int lineID = 1; lineID < rawData.Length; lineID++) - if (rawData[lineID] != string.Concat(chanel)) { - string[] loadedValues = rawData[lineID].Split(','); - int[] tempValues = new int[loadedValues.Length]; - var log = new StringBuilder(); - bool error = false; + for (int lineId = 1; lineId < rawData.Length; lineId++) + if (rawData[lineId] != string.Concat(chanel)) { + string[] loadedValues = rawData[lineId].Split(','); + if (loadedValues.Length == 2) //add missing mode id + loadedValues = new[] + {loadedValues[0], loadedValues[1].Contains("\"") ? "1" : "0", loadedValues[1]}; + else if (loadedValues[1].Contains("\"")) { //if mode is a string, assume it as a macro argument + string[] newLoadedValues = new string[loadedValues.Length + 1]; + newLoadedValues[0] = loadedValues[0]; + newLoadedValues[1] = "1"; + for (int i = 1; i < loadedValues.Length; i++) + newLoadedValues[i + 1] = loadedValues[i]; + } + + int[] tempValues = new int[loadedValues.Length]; + var log = new StringBuilder(); + bool error = false; for (int i = 0; i < tempValues.Length; i++) { string value = loadedValues[i].Trim(); if (!int.TryParse(value, out tempValues[i])) { + if (i < 2) { + noErrors = false; + error = true; + Error( + "Error at line {0} -> \"{1}\", Value must be a full number: \"{2}\".", lineId, + rawData[lineId], value); + break; + } + string[] convertValue; if ((convertValue = value.Split('\'')).Length > 1) { //'a' -> GetId("a") tempValues[i] = GetId(convertValue[1][0]); if (convertValue[0][convertValue[0].Length - 1] == '-') { - if (i < 2 || tempValues[1] != 1) { + if (tempValues[1] != 1) { noErrors = false; error = true; Error( - "Error at line {0} -> \"{1}\", Negativ value not allowed: \"{2}\".", lineID, - rawData[lineID], value); + "Error at line {0} -> \"{1}\", Negative value not allowed: \"{2}\".", + lineId, + rawData[lineId], value); break; } tempValues[i] = -tempValues[i]; } - } else if ((convertValue = value.Split('"')).Length > 1) { //"a" -> GetId("a") - tempValues[i] = GetId(convertValue[1][0]); - if (convertValue[0][convertValue[0].Length - 1] == '-') { - if (i < 2 || tempValues[1] != 1) { + } else if ((convertValue = value.Split('"')).Length > 1) { + //"a" -> GetId("a") //"abc" -> GetId("a"), GetId("b"), GetId("c") + + if (convertValue.Length > 4) { + noErrors = false; + error = true; + Error( + "Error at line {0} -> \"{1}\", Multiple strings not allowed: \"{2}\".", lineId, + rawData[lineId], value); + break; + } + + if (tempValues[1] != 1) { + if (convertValue[0].Length != 0) { noErrors = false; error = true; Error( - "Error at line {0} -> \"{1}\", Negativ value not allowed: \"{2}\".", lineID, - rawData[lineID], value); + "Error at line {0} -> \"{1}\", Unexpected character{2}: \"{3}\".", lineId, + rawData[lineId], convertValue[0].Length > 1 ? "s" : "", convertValue[0]); break; } - tempValues[i] = -tempValues[i]; + if (convertValue[1].Length == 1) { tempValues[i] = GetId(convertValue[1][0]); } + } else { + if (convertValue[0].Length > 1 || (convertValue[0].Length != 0 && + (convertValue[0][0] != '-' && + convertValue[0][0] != '+'))) { + noErrors = false; + error = true; + Error( + "Error at line {0} -> \"{1}\", Unexpected character{2}: \"{3}\".", lineId, + rawData[lineId], convertValue[0].Length > 1 ? "s" : "", convertValue[0]); + break; + } + + if (convertValue[0].Length == 1 && convertValue[1].Length == 1) { + tempValues[i] = GetId(convertValue[1][0]); + if (convertValue[0][0] != '-') + tempValues[i] = -tempValues[i]; + } else { + int length = convertValue[0].Length == 1 + ? convertValue[1].Length - 1 + : convertValue[1].Length + convertValue[1].Length - 1; + + //copy old values to new array with a gap for the new values. + int[] newTempV = new int[tempValues.Length + length]; + for (int j = 0; j < tempValues.Length; j++) { + if (j < i) { newTempV[j] = tempValues[j]; } else if (j > i) { + newTempV[j + length] = tempValues[j]; + } + } + + // insert new values + if (convertValue[0].Length == 1) { + if (convertValue[0][0] == '-') + for (int j = 0; j < convertValue[1].Length; j++) { + newTempV[j + i] = -GetId(convertValue[1][j]); + } + else + for (int j = 0; j < convertValue[1].Length; j++) { + newTempV[j + i] = GetId(convertValue[1][j]); + } + } else + for (int j = 0; j < convertValue[1].Length; j++) { + newTempV[j * 2 + i] = GetId(convertValue[1][j]); + newTempV[j * 2 + i + 1] = -GetId(convertValue[1][j]); + } + + //apply new values + tempValues = newTempV; + i += length; + } } } else if (value.Length == 1) //a -> GetId("a") tempValues[i] = GetId(value[0]); - else { + else { //-a -> -GetId("a") if (value.Length == 2 && value[0] == '-') tempValues[i] = -GetId(value[1]); else { noErrors = false; error = true; Error( - "Error at line {0} -> \"{1}\", Unexpected character{2}: \"{3}\".", lineID, - rawData[lineID], value.Length > 1 ? "s" : "", value); + "Error at line {0} -> \"{1}\", Unexpected character{2}: \"{3}\".", lineId, + rawData[lineId], value.Length > 1 ? "s" : "", value); break; } } @@ -135,13 +215,13 @@ private static bool LoadKeyData() if (!error) Program.values.Add(tempValues); - - log.Append("-> "); - foreach (int item in tempValues) { - log.Append(item); - log.Append(' '); - } - + + log.Append("-> "); + foreach (int item in tempValues) { + log.Append(item); + log.Append(' '); + } + Console.WriteLine(log); }