Skip to content

Commit

Permalink
Improvements of data formation support
Browse files Browse the repository at this point in the history
  • Loading branch information
millennIumAMbiguity committed May 4, 2021
1 parent bc40908 commit 85f67f5
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 71 deletions.
20 changes: 13 additions & 7 deletions Formatting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -28,14 +32,16 @@ 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):

midi_key_down_id
\/
8323216,2,66 <- key_action //in this case 'b'
/\
key_indedification
keyAddon_indedification
2 changes: 1 addition & 1 deletion MIDI-Keyboard/miscellaneous/Miscellaneous.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 4 additions & 10 deletions MIDI-Keyboard/programChapter/OutViewerVisual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
53 changes: 26 additions & 27 deletions MIDI-Keyboard/programChapter/run/KeyMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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];
Expand All @@ -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);
}
}
}
}
132 changes: 106 additions & 26 deletions MIDI-Keyboard/programChapter/run/LoadData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 85f67f5

Please sign in to comment.