Skip to content

Commit

Permalink
Improved readability
Browse files Browse the repository at this point in the history
  • Loading branch information
millennIumAMbiguity committed Jan 15, 2021
1 parent 7f63710 commit a16a0ce
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 80 deletions.
36 changes: 14 additions & 22 deletions MIDI-Keyboard/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace keyBordL
namespace MIDIKeyboard
{
// Token: 0x02000002 RID: 2
internal class Program
Expand All @@ -14,36 +14,30 @@ internal class Program
private static void Main(string[] args)
{
if (args.Length > 0 && args[0] == "run") {
Program.runPogram = true;
Program.runProgram = true;
}

Console.Title = "MIDI KEYS";

while (Program.runForm)
{
while (runForm) {
Console.Clear();
if (Program.runFastSetup)
{
if (runFastSetup) {
FastSetup.FastSetup_(runFastSetup);
runFastSetup = false;
}
if (Program.runPogram)
{
Run.Run_(runPogram);
runPogram = false;
if (runProgram) {
Run.Run.Run_(runProgram);
runProgram = false;
}
if (Program.runViewer)
{
if (runViewer) {
Viewer.Viewer_(runViewer);
runViewer = false;
}
if (Program.runOutViewer)
{
if (runOutViewer) {
OutViewer.OutViewer_(runOutViewer);
runOutViewerVisual = false;
}
if (Program.runOutViewerVisual)
{
if (runOutViewerVisual) {
OutViewerVisual.OutViewerVisual_(runOutViewerVisual);
runOutViewerVisual = false;
}
Expand All @@ -57,8 +51,7 @@ private static void Main(string[] args)
Console.Write("2. setup\n3. visual setup");
Console.ResetColor();
Console.Write("\n4. run\n5. viewer\n6. viewer output\n7. viewer output visual\n8. quit\n");
switch (Console.ReadKey().Key)
{
switch (Console.ReadKey().Key) {
case ConsoleKey.D1:
Program.runFastSetup = true;
break;
Expand All @@ -69,7 +62,7 @@ private static void Main(string[] args)
Program.runVisualSetup = true;
break;
case ConsoleKey.D4:
Program.runPogram = true;
Program.runProgram = true;
break;
case ConsoleKey.D5:
Program.runViewer = true;
Expand All @@ -91,8 +84,7 @@ private static void Main(string[] args)
public static int GetTeken()
{
Program.teken++;
switch (Program.teken)
{
switch (Program.teken) {
case 1:
return 9;
case 2:
Expand Down Expand Up @@ -270,7 +262,7 @@ public static int GetTeken()
private static bool runVisualSetup = false;
#pragma warning restore IDE0052 // Remove unread private members

private static bool runPogram = false;
private static bool runProgram = false;

private static bool runViewer = false;
private static bool runOutViewer = false;
Expand Down
2 changes: 1 addition & 1 deletion MIDI-Keyboard/dataFolder/midi.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Runtime.InteropServices;

namespace keyBordL.dataFolder
namespace MIDIKeyboard.dataFolder
{
public class InputPort
{
Expand Down
25 changes: 24 additions & 1 deletion MIDI-Keyboard/miscellaneous/Miscellaneous.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace MIDIKeyboard.miscellaneous
using System;

namespace MIDIKeyboard.miscellaneous
{
static class Miscellaneous
{
Expand All @@ -10,5 +12,26 @@ static public int GetID(char c)

return cId;
}

public static void Error(string s)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(s);
Console.ResetColor();
Console.WriteLine("Press any key to ignore and continue...");
Console.ReadKey();
}
public static void Error(string s, object[] os)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(s, os);
Console.ResetColor();
Console.WriteLine("Press any key to ignore and continue...");
Console.ReadKey();
}
public static void Error(string s, object o1) => Error(s, new object[] { o1 });
public static void Error(string s, object o1, object o2) => Error(s, new object[] { o1, o2 });
public static void Error(string s, object o1, object o2, object o3) => Error(s, new object[] { o1, o2, o3 });
public static void Error(string s, object o1, object o2, object o3, object o4) => Error(s, new object[] { o1, o2, o3, o4 });
}
}
4 changes: 2 additions & 2 deletions MIDI-Keyboard/programChapter/FastSetup.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using keyBordL.dataFolder;
using MIDIKeyboard.dataFolder;

namespace keyBordL
namespace MIDIKeyboard
{
class FastSetup
{
Expand Down
4 changes: 2 additions & 2 deletions MIDI-Keyboard/programChapter/OutViewer.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using keyBordL.dataFolder;
using MIDIKeyboard.dataFolder;

namespace keyBordL
namespace MIDIKeyboard
{
class OutViewer
{
Expand Down
4 changes: 2 additions & 2 deletions MIDI-Keyboard/programChapter/OutViewerVisual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using keyBordL.dataFolder;
using MIDIKeyboard.dataFolder;

namespace keyBordL
namespace MIDIKeyboard
{
class OutViewerVisual
{
Expand Down
43 changes: 15 additions & 28 deletions MIDI-Keyboard/programChapter/Viewer.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System;
using System.Text;
using keyBordL.dataFolder;
using MIDIKeyboard.dataFolder;

namespace keyBordL
namespace MIDIKeyboard
{
class Viewer
{

private static InputPort midi = new InputPort();
private static readonly InputPort midi = new InputPort();

public static bool Viewer_(bool runViewer)
{
Expand All @@ -16,8 +16,7 @@ public static bool Viewer_(bool runViewer)
Console.WriteLine("what midi port do you whant to use");
{
Console.ForegroundColor = ConsoleColor.Black;
for (int i = 0; i < midi.InputCount(); i++)
{
for (int i = 0; i < midi.InputCount(); i++) {
if (i % 2 == 0)
Console.BackgroundColor = ConsoleColor.Gray;
else
Expand All @@ -28,24 +27,18 @@ public static bool Viewer_(bool runViewer)
Console.ResetColor();
}
Console.Write("port: ");
int resultat2;
int.TryParse(Console.ReadLine(), out resultat2);
int.TryParse(Console.ReadLine(), out int resultat2);
Console.WriteLine("value set to " + resultat2);
Console.WriteLine("press ESC to exit");
int chanel = resultat2;
midi.Open(chanel);
midi.Start();
int old = 0;
int value = 0;
string valueHex = "";
string hex4 = "0000";
bool sw = false;


while (runViewer)
{
if (Console.KeyAvailable)
{
while (runViewer) {
if (Console.KeyAvailable) {

StringBuilder sb = new StringBuilder();

Expand All @@ -67,10 +60,8 @@ public static bool Viewer_(bool runViewer)
byte bkey = (byte)key.KeyChar;
if (bkey > 96 && bkey < 123)
bkey -= 32;
else
{
switch (key.Key)
{
else {
switch (key.Key) {
case ConsoleKey.Backspace:
bkey = 8;
break;
Expand Down Expand Up @@ -411,30 +402,26 @@ public static bool Viewer_(bool runViewer)


}
value = midi.p;
if (old != value)
{
int value = midi.p;
if (old != value) {


sw = false;

valueHex = midi.pS;
string valueHex = midi.pS;

hex4 = valueHex.Substring(valueHex.Length - 4);
string hex4 = valueHex.Substring(valueHex.Length - 4);


if (hex4.Substring(hex4.Length - 2) == "D0")
{
if (hex4.Substring(hex4.Length - 2) == "D0") {
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write(valueHex.PadLeft(6, ' ').Substring(0, 4));
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("D0 ");
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine(value);
Console.ForegroundColor = ConsoleColor.White;
}
else
{
} else {
/*
if (valueHex.Length > 4)
{
Expand Down
103 changes: 103 additions & 0 deletions MIDI-Keyboard/programChapter/run/LoadData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;
using System.IO;
using System.Text;
using MIDIKeyboard.dataFolder;
using static MIDIKeyboard.miscellaneous.Miscellaneous;

namespace MIDIKeyboard.Run
{
class LoadData
{
public static bool Load() => LoadFile() && SendOutputData() & LoadKeyData();

static string[] array;

static bool LoadFile(string path = "data.txt")
{
Console.Write("Loading data from path \"{0}\"...", path);
if (File.Exists(path) && (array = File.ReadAllLines(path)).Length > 2) {
Console.WriteLine(" Done.");
return true;
}
Console.WriteLine(" Error.");
Error("Error -> No data.");
return false;
}

static bool SendOutputData()
{
if (array[0].Split(',').Length > 1) {
Console.Write("Sending output data...");
string[] ColorArray = array[0].Split(',');

InputPort midiOut = new InputPort();
midiOut.OpenOut(int.Parse(ColorArray[1].Trim()));

//send output
for (int i = 2; i + 1 < ColorArray.Length; i += 2) {
midiOut.MidiOutMsg((byte)int.Parse(ColorArray[i].Trim()), (byte)int.Parse(ColorArray[i + 1].Trim()));
}

midiOut.CloseOut();
Console.WriteLine(" Done.");
return true;
}
Console.WriteLine("No output data detected.");
return true;
}

static bool LoadKeyData()
{
bool noErrors = true;
Console.WriteLine("loading from file...");
int chanel = int.Parse(array[0].Split(',')[0]);

for (int lineID = 0; lineID < array.Length; lineID++) {
if (array[lineID] != string.Concat(chanel)) {
string[] loadedValues = array[lineID].Split(new char[] { ',' });
int[] tempValues = new int[loadedValues.Length];
StringBuilder log = new StringBuilder();
for (int i = 0; i < tempValues.Length; i++) {
string value = loadedValues[i].Trim();
if (!int.TryParse(value, out tempValues[i])) {
string[] convertValue;
if ((convertValue = value.Split('\'')).Length > 1) {
tempValues[i] = GetID(convertValue[1][0]);
if (convertValue[0][convertValue[0].Length - 1] == '-') {
if (i < 2 || i > 1 && tempValues[1] != 1) {
noErrors = false;
Error("Error at line {0} -> \"{1}\", Negativ value not allowed: \"{2}\".", lineID, array[lineID], value);
} else
tempValues[i] = -tempValues[i];
}
} else if ((convertValue = value.Split('"')).Length > 1) {
tempValues[i] = GetID(convertValue[1][0]);
if (convertValue[0][convertValue[0].Length - 1] == '-') {
if (i < 2 || i > 1 && tempValues[1] != 1) {
noErrors = false;
Error("Error at line {0} -> \"{1}\", Negativ value not allowed: \"{2}\".", lineID, array[lineID], value);
} else
tempValues[i] = -tempValues[i];
}
} else if (value.Length == 1) {
tempValues[i] = GetID(value[0]);
} else {
if (value.Length == 2 && value[0] == '-') {
tempValues[i] = -GetID(value[1]);
} else {
noErrors = false;
Error("Error at line {0} -> \"{1}\", Unexpected character{2}: \"{3}\".", lineID, array[lineID], value.Length > 1 ? "s" : "", value);
}
}
}
log.Append(value);
log.Append(' ');
}
Program.values.Add(tempValues);
Console.WriteLine(log);
}
}
return noErrors;
}
}
}
Loading

0 comments on commit a16a0ce

Please sign in to comment.